cuda - thrust copy_if with const source -


my problem in following code:

the filter function compiles, , runs should when source not constant (the iterators adjusted accordingly). when change source const, compiler gives me following error first 2 variables of copy_if statement: "the object has type qualifiers not compatible member function".

i believe there const not const conversion error somewhere frankly have no idea where. appreciated.

#include "thrust\device_vector.h" #include "thrust\copy.h"  typedef thrust::device_vector<float>::const_iterator    dc_floatiterator; typedef thrust::device_vector<float>::iterator          d_floatiterator;  typedef thrust::device_vector<int>::const_iterator  dc_intiterator; typedef thrust::device_vector<int>::iterator        d_intiterator;  typedef thrust::tuple< dc_intiterator, dc_intiterator, dc_floatiterator> dc_listiteratortuple; typedef thrust::zip_iterator<dc_listiteratortuple>   dc_listiterator;//type of class const iterator  typedef thrust::tuple< d_intiterator, d_intiterator, d_floatiterator > d_listiteratortuple; typedef thrust::zip_iterator<d_listiteratortuple>    d_listiterator;//type of class iterator  struct selector{//selector functor copy if call const int val;  selector(int _val) : val(_val) {}  __host__ __device__ bool operator()(const int& x ) { return ( x == val );    } };  class foo{     public:     thrust::device_vector<int>      ivec1;     thrust::device_vector<int>      ivec2;     thrust::device_vector<float>    fvec1;      foo(){;}     ~foo(){;}      d_listiterator begin(){//cast of begin iterator         return d_listiterator(d_listiteratortuple( ivec1.begin(), ivec2.begin(), fvec1.begin() ));     }     d_listiterator end(){//cast of end iterator         return d_listiterator(d_listiteratortuple( ivec1.end(), ivec2.end(), fvec1.end() ));     }      dc_listiterator cbegin(){//cast of const begin iterator         return dc_listiterator(dc_listiteratortuple( ivec1.cbegin(), ivec2.cbegin(), fvec1.cbegin() ));     }     dc_listiterator cend(){//cast of const end iterator         return dc_listiterator(dc_listiteratortuple( ivec1.cend(), ivec2.cend(), fvec1.cend() ));     }      void const_filter( const foo& theother, const int& target ){//doesnt work         //this function should copy member of vectors         //the ivec2[i] == target true         thrust::copy_if(             theother.cbegin(),             theother.cend(),             theother.ivec2.cbegin(),             this->begin(),             selector(target) );     }     void filter( foo& theother, const int& target ){//works         //this function should copy member of vectors         //the ivec2[i] == target true         thrust::copy_if(             theother.begin(),             theother.end(),             theother.ivec2.cbegin(),             this->begin(),             selector(target) );     }     void insert(const int& one, const int& two,const float& 3 ){         ivec1.push_back(one);         ivec2.push_back(two);         fvec1.push_back(three);     }      int size(){         return ivec1.size();     } };  bool checkifsublistisconnected(const foo& list,const int& sublist_num){ foo tmp;  tmp.const_filter( list, sublist_num );  return (bool)tmp.size();//for symplicity, othervise here function check if                         //the edge list represents connected graph } int main(void){ foo list; bool connected; list.insert(10,2,1.0); list.insert(11,2,1.0); list.insert(12,2,1.0); list.insert(10,3,1.0); list.insert(10,3,1.0);  connected=checkifsublistisconnected(list,2);   if( connected ) return 0; else return -1; } 

i've found replacing theother.cbegin() / .cend() folowing compiler accepts it. means messed somewhere in typedef section, where?

    thrust::make_zip_iterator(         thrust::make_tuple(             theother.ivec1.cbegin(),             theother.ivec2.cbegin(),             theother.fvec1.cbegin() )) 

as comes out i've frogotten add const magic word @ definition of cend/cbegin.

dc_listiterator cbegin() const {         return dc_listiterator(dc_listiteratortuple( ivec1.cbegin(), ivec2.cbegin(), fvec1.cbegin() ));     } dc_listiterator cend() const {         return dc_listiterator(dc_listiteratortuple( ivec1.cend(), ivec2.cend(), fvec1.cend() ));     } 

Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -