请考虑以下简单代码:
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];
}
我预计输出是这段代码的 0,1,1,3;但是,输出为 0,1,1。谁能让我知道我错过了什么?注意: 的内容copyListOfNgramCounteachdoc
是 0,1,1,1,1,3 。的类型copyListOfNgramCounteachdoc
也是thrust::device_vector<int>
.
编辑:
end.first = storeNcCounts.begin();
end.second = storeCompactedPositions.begin();
int indexToWriteForIndexesarr = 0;
for(int i =0 ; i < numDocs; i++){
iter = end.first;
end = thrust::unique_by_key_copy(copyListOfNgramCounteachdoc.begin() + (i*numUniqueNgrams), copyListOfNgramCounteachdoc.begin()+(i*numUniqueNgrams)+ numUniqueNgrams,positions.begin() + (i*numUniqueNgrams),end.first,end.second);
int numElementsCopied = (end.first - iter);
endIndex = beginIndex + numElementsCopied - 1;
storeBeginIndexEndIndexSCNCtoRead[indexToWriteForIndexesarr++] = beginIndex;
storeBeginIndexEndIndexSCNCtoRead[indexToWriteForIndexesarr++] = endIndex;
beginIndex = endIndex + 1;
}