++ 함수 아래와 같이순회 비제 소자 매트릭스 클래스 dgCMatrix 속하는 R.에서 고유 I는 C로 (테스트) 적은 희소 행렬을 통과하고
5 x 5 sparse Matrix of class "dgCMatrix"
[1,] . . . . .
[2,] 1 1 . . .
[3,] . . . . .
[4,] . . 1 . .
[5,] . 1 . . .
I를 반복하고 이 행렬은 설명서 here에서 언급 한 것과 같습니다. 내 함수는 반복자와 행 인덱스, 열 인덱스의 값을 출력합니다.
함수는 C가 ++ 아래 정의된다 : 다음의 결과를 상기 주어진 행렬
#include <RcppEigen.h>
// [[Rcpp::depends(RcppEigen)]]
using Eigen::MappedSparseMatrix;
using Eigen::SparseMatrix;
using Eigen::VectorXi;
using Eigen::Map;
using namespace Rcpp;
using namespace std;
// [[Rcpp::export]]
void createRec(RObject sparse_mat, IntegerVector sparse_vec) {
const MappedSparseMatrix<int> spmat(as<MappedSparseMatrix<int> >(sparse_mat));
long int nrow = spmat.rows();
long int ncol = spmat.cols();
NumericVector sim(nrow);
for(int k=0;k<spmat.outerSize();k++){
for(SparseMatrix<int,Eigen::ColMajor>::InnerIterator it(spmat,k);it;++it){
cout<<"k="<<k<<endl;
cout<<"value="<<it.value()<<endl;
cout<<"it.row="<<it.row()<<endl;
cout<<"it.col="<<it.col()<<endl;
cout<<"index="<<it.index()<<endl;
}
}
}
인쇄된다 : k = 0으로 대응하는 값
k=0
value=156148016
it.row=66211520
it.col=0
index=66211520
k=1
value=0
it.row=0
it.col=1
index=0
k=1
value=1
it.row=4
it.col=1
index=4
k=2
value=1
it.row=3
it.col=2
index=3
1) 상관 설명? 이것들이 행렬을 잘못 전달했기 때문일 수 있습니까?
2.) k는 outerSize에 대해 5를 반복하며, k = 3,4에 대해 iterating하지 않는 이유는 무엇입니까? 스파 스 매트릭스 (sparseMatrix)라고 생각하면이 동작은 반복기에서 예상됩니다.
spmat의 선언을 다음과 같이 변경합니다. const SparseMatrix spmat (> (sparse_mat)); 이 문제는 k = 0에 대해 해결되었습니다. 그러나 나는 아직도 그 이유를 모른다. –
TUSHAr