From Vector-Scalar Linear Algebra Functions (from vectorOps.h)
https://developer.apple.com/reference/accelerate/1546030-visamax
func vIsamax(_ count: Int32,
_ x: OpaquePointer) -> Int32)
UnsafeRawPointer
withUnsafePointer
MemoryLayout
vIsamax
takes a vector of vFloat
aka float4
elements as argument.
(Each float4
holds 4 floating point numbers.)
The C declaration is
int32_t vIsamax(int32_t count, const vFloat *x);
which should be mapped to Swift as
public func vIsamax(_ count: Int32, _ x: UnsafePointer<vFloat>) -> Int32
instead of
public func vIsamax(_ count: Int32, _ x: OpaquePointer) -> Int32
But you can simply pass an vFloat
/float4
array, as shown in this
small example:
import Swift
import Accelerate
import simd
let values = [ float4(-1.0, -2.0, -3.0, -4.0), float4(4.0, 3.0, 2.0, 1.0) ]
let idx = vIsamax(Int32(4 * values.count), values)
print(idx) // 3