Guest User

Untitled

a guest
Aug 22nd, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. How do I reorder a vector during a Thrust transformation?
  2. for (i=0;i<cA-rA;i++)
  3. sn[i]=c[n_index[i]]-sn[i];
  4.  
  5. #include <thrust/device_vector.h>
  6. #include <thrust/iterator/permutation_iterator.h>
  7. #include <thrust/transform.h>
  8. #include <thrust/sequence.h>
  9. #include <thrust/functional.h>
  10.  
  11. int main()
  12. {
  13. size_t n = 100;
  14.  
  15. // declare storage
  16. thrust::device_vector<int> sn(n);
  17. thrust::device_vector<int> n_index(n);
  18. thrust::device_vector<int> c(n);
  19.  
  20. // initialize vectors with some sequential values for demonstrative purposes
  21. thrust::sequence(sn.begin(), sn.end());
  22. thrust::sequence(n_index.begin(), n_index.end());
  23. thrust::sequence(c.begin(), c.end());
  24.  
  25. // sn[i] = c[n_index[i]] - sn[i]
  26. thrust::transform(thrust::make_permutation_iterator(c.begin(), n_index.begin()),
  27. thrust::make_permutation_iterator(c.begin(), n_index.end()),
  28. sn.begin(),
  29. sn.begin(),
  30. thrust::minus<int>());
  31.  
  32. return 0;
  33. }
Add Comment
Please, Sign In to add comment