Matrix multiplication in Rcpp

后端 未结 3 1965
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-29 10:12

First of all, I am a novice user so forget my general ignorance. I am looking for a faster alternative to the %*% operator in R. Even though older posts suggest the use of R

3条回答
  •  伪装坚强ぢ
    2020-12-29 10:52

    I would encourage to try to work out your issues with RcppArmadillo. Using it is as simple as this example also created by calling RcppArmadillo.package.skeleton():

    // another simple example: outer product of a vector, 
    // returning a matrix
    //
    // [[Rcpp::export]]
    arma::mat rcpparma_outerproduct(const arma::colvec & x) {
        arma::mat m = x * x.t();
        return m;
    }
    
    // and the inner product returns a scalar
    //
    // [[Rcpp::export]]
    double rcpparma_innerproduct(const arma::colvec & x) {
        double v = arma::as_scalar(x.t() * x);
        return v;
    }
    

    There is actually more code in the example but this should give you an idea.

提交回复
热议问题