Search code examples
iosswiftaccelerate-framework

How to compute the square root of a vector elementwise using vDSP / Accelerate in swift for iOS


I have a vector similar to [Float](repeating: 1.0, count: 42000), and I would like to compute the square root of each element using the Accelerate framework, but no vDSP_vsqrt function exists contrary to what is stated in Apple Accelerate Framework scale and normalize a vector. How should I do it?


Solution

  • The vForce Swift overlay makes the syntax a little simpler:

    vForce.sqrt(vector: AccelerateBuffer)
    

    Take a look at: https://github.com/apple/swift/blob/master/stdlib/public/Darwin/Accelerate/vForce_Operations.swift

    ...and...

    https://developer.apple.com/videos/play/wwdc2019/718/