Recommended SIMD dot product in Swift 5?

Do we have to import simd to get dot product (between eg two SIMD3<Float>)?

I couldn't find anything about it in SE-0229 or elsewhere.

Are all SIMD related changes summarized somewhere?

Yes. Dot product and other geometric operations are something that we're looking into adding in the future, but there's a design question of whether they should be defined on SIMD where Scalar : FloatingPoint or on some sort of Vector type that wraps it and presents a more geometry-focused interface. There's also a question of whether these things should be free functions or methods, and whether they should go in the stdlib or another module. We had to rush a bit to get the SIMD types into Swift 5 because of ABI lockdown, so this design discussion--and hence the operations themselves--had to wait.

Importing simd is your best option on Apple platforms for now.

Note that the importer in 5.0 can only import 2, 3, and 4 element vectors of UInt32, Int32, Float or Double; I recently landed an importer fix on master that allows any clang vector type to be imported as the corresponding SIMDn if it exists, so that will expose the full Apple simd module to Swift starting in 5.1, and make it easier to work with similar API on other platforms.

2 Likes
Terms of Service

Privacy Policy

Cookie Policy