This question was answered on SO.
Adding Martin R’s answer with his permission:
You can use withUnsafeBufferPointer() to pass the address of the slice's element storage to the vDSP function:
sliceOfBuffer.withUnsafeBufferPointer { bp in
vDSP_vsortiD(
bp.baseAddress!,
sortedIndices,
nil,
UInt(sliceOfBuffer.count),
vDSP.SortOrder.descending.rawValue
)
}
With respect to slicing the indices: It seems that one can pass sortedIndices + sliceOfBuffer.startIndex to the vDSP function. However, the documentation states that the indices must be initialized starting at zero, so I would not rely on that.
Topic:
Programming Languages
SubTopic:
Swift
Tags: