相关疑难解决方法(0)

使用Rcpp的R fast cbind矩阵

cbind在R中,在重复调用中相对耗时,但它对于各种数据类型也是强大的.我编写的代码比cbind绑定两个矩阵快3倍.但bind_colsdplyr包装仅仅是100X的速度比cbind.遗憾的是它不能将矩阵作为输入.有人可以使下面的代码更快.另外,如何快速绑定稀疏矩阵?这是我使用的代码:

require( Rcpp )

func <- 'NumericMatrix mmult(NumericMatrix a,NumericMatrix b) {
    //the colnumber of first matrix
    int acoln=a.ncol();
    //the colnumber of second matrix
    int bcoln=b.ncol();
    //build a new matrix, the dim is a.nrow() and acoln+bcoln
    NumericMatrix out(a.nrow(),acoln+bcoln) ;
    for (int j = 0; j < acoln + bcoln; j++) {
        if (j < acoln) {
            out(_,j) = a(_,j);
        } else {
            //put the context in the second matrix to the new …
Run Code Online (Sandbox Code Playgroud)

c++ r rcpp cbind

9
推荐指数
1
解决办法
1884
查看次数

标签 统计

c++ ×1

cbind ×1

r ×1

rcpp ×1