1

I have a for-loop to do indexing:

for (int i=0; i<N; i++){
    a[i] = b[c[i]]
}

c are the indices of interest and are int *, while b and a are float * and the manipulated values.

But, this takes a long time (and it can't take that long). I'd like to have some vectorizing version, most likely found in BLAS/LAPLACK/etc.

I'm looking for nested_indexing(float * output_vector, float * input_vector, int * input_indices).

I've tried looking through the docs, but have not found anything.

Scott
  • 2,568
  • 1
  • 27
  • 39
  • What you need is a gather instruction - http://stackoverflow.com/questions/16193434/avx2-gather-instructions-load-address-calculation . Not sure if there are supporting libs – Leeor Nov 05 '13 at 23:02
  • Have you looked at `?lapmt` and `?laswp` from LAPACK? They do something similar (if you don't mind the fact that the matrix is permuted in-place, not copied.) – finnw Nov 05 '13 at 23:30

1 Answers1

1

vDSP_vgathr does exactly this. It takes in two float *'s and one int *. It does the equivalent of for (i=0; i<N; i++) a[i] = b[c[i]].

The wording they used was

Uses elements of vector B as indices to copy selected elements of vector A to sequential locations in vector C

It could be sequential indexing too, perhaps. I've noticed that the hardest part about finding these obscure functions is finding the right words to use in your searches.

Scott
  • 2,568
  • 1
  • 27
  • 39