cuda - thrust::sequence - how to increase the step after each N elements -


i using

thrust::sequence(myvector.begin(), myvector.end(), 0, 1) 

and achieve ordered list like:

0, 1, 2, 3, 4 

my question how can achieve such list below (the best way?)

0, 0, 0, 1, 1, 1, 2, 2 ,2, 3, 3, 3 

i know how make functors, please not try answer functor. want learn if there optimized way in thrust, or missing simple way..

something this:

thrust::device_vector<int> myvector(n);  thrust::transform( thrust::make_counting_iterator(0),                    thrust::make_counting_iterator(n),                    thrust::make_constant_iterator(3),                    myvector.begin(),                    thrust::divides<int>() ); 

(disclaimer, written in browser, never compiled or tested, use @ own risk)

should give sequence looking computing [0..n]//3 , outputting result on myvector.


seeing having trouble compiling version, here complete example compiles , runs:

#include <thrust/device_vector.h> #include <thrust/transform.h> #include <thrust/functional.h> #include <thrust/iterator/counting_iterator.h> #include <thrust/iterator/constant_iterator.h> #include <cstdio>  int main(void) {     const int n = 18, m = 3;     thrust::device_vector<int> myvector(n);      thrust::transform(  thrust::make_counting_iterator(0),                         thrust::make_counting_iterator(n),                         thrust::make_constant_iterator(m),                         myvector.begin(),                         thrust::divides<int>() );      for(int i=0; i<n; i++) {         int val = myvector[i];         printf("%d %d\n", i, val);     }     return 0; } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -