以下の簡単なコードを検討してください。
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;
}