[英]Rcpp using a sparse matrix in C++
Overwhelmed with starting with RCCP. 从RCCP开始不知所措。 How would I be able to use (index,read and assign values) a sparse matrix as defined in the code the same way as I can do with the 'standard' matrix?
如何使用代码中定义的稀疏矩阵(索引,读取和分配值),就像使用“标准”矩阵一样?
library('Matrix')
library(Rcpp)
library(inline)
r <- matrix(seq(1,9,1),ncol=3,nrow=3)
i <- Matrix(0, nrow = nrow(r) * ncol(r), ncol = nrow(r)*ncol(r), sparse=TRUE)
fx <- cxxfunction( signature( x_ = "matrix" ,y_="dsCMatrix"), '
NumericMatrix x(x_) ;
int nr = x.nrow(), nc = x.ncol() ;
for (int i = 0; i < nr; i++) {
for (int j = 1; j < nc; j++) {
x(i,j) = 1;
}
}
return wrap( x ) ;
', plugin = "Rcpp" )
fx( r,i)
Your best bet may be 你最好的选择可能是
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.