I am currently studying the Accelerate library by referring to Apple documentation.
Here is the link to the referenced document: https://developer.apple.com/documentation/accelerate/veclib/vforce
When I executed the sample code provided at the bottom of the document, I found a case where the results were different.
let n = 10_000
let x = (0..<n).map { _ in
Float.random(in: 1 ... 10_000)
}
let y = x.map {
return sqrt($0)
}
and
let y = [Float](unsafeUninitializedCapacity: n) { buffer, initializedCount in
vForce.sqrt(x,
result: &buffer)
initializedCount = n
}
The code below is provided to observe the issue described above.
import Accelerate
Task {
let n = 1//10_000
let x = (0..<n).map { _ in
Float(6737.015)//Float.random(in: 1 ... 10_000)
}
let y = x.map {
return sqrt($0)
}
try? await Task.sleep(nanoseconds: 1_000_000_000)
let z = [Float](unsafeUninitializedCapacity: n) { buffer, initializedCount in
vForce.sqrt(x, result: &buffer)
initializedCount = n
}
}
For a value of 6737.015 when calculating the square root:
Using the sqrt(_:) function gives the result 82.07932,
While using the vForce.sqrt(_:result:) function gives the result 82.07933.
Using a calculator, the value comes out as 82.07932139, which shows that the result from vForce is incorrect.
Could you explain the reason behind this difference?