나는 R에서 중복을 찾는 빠른 검색을 찾으려고 노력하고 있습니다. 코드의 목적은 행렬의 행 번호를 사용하여 행렬을 Rcpp에 전달한 다음 찾고있는 전체 행렬을 반복합니다 그 행에 대한 일치. 문제의 행렬은 1000 행과 250 행을 갖는 논리 행렬입니다.중복 검색 Rcpp를 사용하여
소리는 간단하지만 아래 코드는 동일한 벡터 행을 감지하지 못합니다. equals() 함수 또는 행렬 또는 벡터 정의 방법에 문제가 있는지 확실하지 않습니다.
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::plugins]]
#include <cstddef> // std:size_t
#include <iterator> // std:begin, std::end
#include <vector> // std::vector
#include <iostream>
#include <string>
// [[Rcpp::export]]
bool dupCheckRcpp (int nVector,
LogicalMatrix bigMatrix) {
// initialize
int i, j, nrow, ncol;
nrow = bigMatrix.nrow();
ncol = bigMatrix.ncol();
LogicalVector vec(ncol); // holds vector of interest
LogicalVector vecMatrix(ncol); // temp vector for loop through bigMatrix
nVector = nVector - 1;
// copy bigMatrix data into vec based on nVector row
for (j = 0; j < ncol; ++j) {
vec(j) = bigMatrix(nVector,j);
}
// check loop: check vecTeam against each row in allMatrix
for (i = 0; i < nrow; ++i) {
// copy bigMatrix data into vecMatrix
for (j = 0; j < ncol; ++j) {
vecMatrix(j) = bigMatrix(i,j);
}
// check for equality
if (i != nVector) { // skip if nVector row
// compare vecTeam to vecMatrix
if (std::equal(vec.begin(),vec.end(),vecMatrix.begin())) {
return true;
}
}
} // close check loop
return false;
}
당신은'거의 그 모든 시간이 이미 쉽지 않을 수도 있습니다 빨리 만들기 C.에서 실행 paste''에 소요되는 매트릭스에서 호출 duplicated'의 호출 스택을 보면 . – alistaire
'(colSums (t (mat) == mat [20,]) == ncol (mat))'은 내 시스템에서 약 1.5ms 걸립니다. 너무 느린가요? – Roland
또한 'tmp = tcrossprod (mat); which ((tmp == rowSums (mat)) & lower.tri (tmp), TRUE)'는 앞에서 all을 계산할 수 있다면 _all_와 일치하는 행을 반환합니다. 그리고 중간의 행렬은 크기가 1e3 * 1e3입니다. 이것은 관리가 잘된 것 같습니다. –