Reordering with Accelerate framework

277 views Asked by At

I would like to use the Accelerate Framework libraries for sorting data (pairs of x and y values).

I used the function vDSP_vsorti to find the vector with the ordering indices of the x data. Now I should reorder the y data accordingly to the x sorting indices order.

How I could do it? Does exist a function in Accelerate Framework to reorder the vector?

1

There are 1 answers

0
D. Donley On

Can you use vDSP_vgathr? This APIs grabs values from a vector using another vector of indices.

https://developer.apple.com/library/mac/documentation/Accelerate/Reference/vDSPRef/index.html#//apple_ref/c/func/vDSP_vgathr

Here is a summary: Single-Vector Gathering The functions in this group use either indices or pointers stored within one source vector to generate a new vector containing the chosen elements from either a second source vector or from memory.

vDSP_vgathr Vector gather; single precision.

Declaration SWIFT

func vDSP_vgathr(_ __vDSP_A: UnsafePointer<Float>, _ __vDSP_B: UnsafePointer<vDSP_Length>, _ __vDSP_J: vDSP_Stride, _ __vDSP_C: UnsafeMutablePointer<Float>, _ __vDSP_K: vDSP_Stride, _ __vDSP_N: vDSP_Length)

OBJECTIVE-C

void vDSP_vgathr ( const float *__vDSP_A, const vDSP_Length *__vDSP_B, vDSP_Stride __vDSP_IB, float *__vDSP_C, vDSP_Stride __vDSP_IC, vDSP_Length __vDSP_N ); Parameters __vDSP_A
Single-precision real input vector __vDSP_B
Integer vector containing indices __vDSP_J
Stride for B __vDSP_C
Single-precision real output vector __vDSP_K
Stride for C __vDSP_N
The number of elements to process Discussion Performs the following operation:

Uses elements of vector B as indices to copy selected elements of vector A to sequential locations in vector C. Note that 1, not zero, is treated as the first location in the input vector when evaluating indices. This function can only be done out of place.