thrust::unique_by_key eating up last element
- by Programmer
Please consider the below simple code:
thrust::device_vector<int> positions(6);
thrust::sequence(positions.begin(), positions.end());
thrust::pair<thrust::device_vector<int>::iterator, thrust::device_vector<int>::iterator > end;
//copyListOfNgramCounteachdoc contains: 0,1,1,1,1,3
end.first = copyListOfNgramCounteachdoc.begin();
end.second = positions.begin();
for(int i =0 ; i < numDocs; i++){
end= thrust::unique_by_key(end.first, end.first + 3,end.second);
}
int length = end.first - copyListOfNgramCounteachdoc.begin() ;
cout<<"the value of end -s is: "<<length;
for(int i =0 ; i< length ; i++){
cout<<copyListOfNgramCounteachdoc[i];
}
I expected the output to be 0,1,1,3 of this code; however, the output is 0,1,1. Can anyone let me know what I am missing? Note: the contents of copyListOfNgramCounteachdoc is 0,1,1,1,1,3 . Also the type of copyListOfNgramCounteachdoc is thrust::device_vector<int>.