覆盖RCPP Armadillo中稀疏矩阵的所有值
我开始使用RCPP,不确定如何将代码的一部分转换为C ++
我的过程使用稀疏的矩阵,其中元素全部作为向量操作,然后将其插入稀疏的矩阵中。在RI中可以使用
sparse_mat@x <- new_entries
sparess_mat
是DSCMATRIX(基于列的对称矩阵),而new_entries
是订购的值的向量,以匹配它们正在插入的矩阵。
使用RCPP Armadillo或eigen可能会覆盖这样的过程吗?我希望能够这样做,因为其余的操作只是矢量操作,这要快得多。
到目前为止,我试图做的就是以下内容。该函数应该用向量替换稀疏矩阵中的所有值(这仅是用于测试实际函数),
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
using namespace Rcpp;
// [[Rcpp::export]]
arma::sp_mat sqrt2_(arma::sp_mat X, Rcpp::NumericVector a) {
// In order to access the internal arrays of the SpMat class
//X.sync();
std::copy(a.begin(), a.end(), arma::access::rwp(X.values));
return sqrt(X);
}
但它会产生和错误“ ELF_DYNAMIC_ARRAY_READER”和“找不到标签”。
我正在使用.sync
方法,因为建议在这里作为访问矩阵内部的一种方式。
I'm getting started with rcpp and am not sure how to convert a portion of my code to c++
My process uses sparse matrices in which the elements are all operated on as vectors then inserted back into a sparse matrix. In R I can use
sparse_mat@x <- new_entries
Where sparse_mat
is a dsCMatrix (columns based symmetric matrix) and new_entries
is a vector of values ordered so as to match the matrix they are being inserted into.
Is such an overwriting process possible using rcpp Armadillo or Eigen? I want to be able to do it this way as then the rest of the operations are simply vector manipulation which is much faster.
What I have tried to do so far is the following. The function is supposed to replace all the values in the sparse matrix with a vector (this is just for testing not the real function)
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
using namespace Rcpp;
// [[Rcpp::export]]
arma::sp_mat sqrt2_(arma::sp_mat X, Rcpp::NumericVector a) {
// In order to access the internal arrays of the SpMat class
//X.sync();
std::copy(a.begin(), a.end(), arma::access::rwp(X.values));
return sqrt(X);
}
But it produces and error "elf_dynamic_array_reader" and "tag not found".
I am using the .sync
method becuase it is suggested here as a way to access the matrix internals.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论