gao*_*shu 1 r matrix-multiplication rcpp
我试图用RcppArmadillo做一些矩阵乘法.但是,我的代码显示RcppArmadillo不会变得更快.
我使用Windows_10_Pro和R 3.2.4,以及RcppArmadillo 0.6.600.4.0
例如:
library(RcppArmadillo)
library(inline)
MCplus <- cxxfunction(signature(X_="numeric", Y_="numeric"),body ='
arma::mat X = Rcpp::as<arma::mat>(X_);
arma::mat Y = Rcpp::as<arma::mat>(Y_);
arma::mat ans = X * Y * X;
return(wrap(ans));
', plugin="RcppArmadillo")
A <- matrix(1:16000000,4000,4000)
C <- matrix(2:16000001,4000,4000)
R_M <- proc.time()
ans_R <- A%*%C%*%A # test with R
proc.time() - R_M
C_M <- proc.time()
ans_C <- MCplus(A,C) # test with RcppArmadillo
proc.time() - C_M
Run Code Online (Sandbox Code Playgroud)
R输出:
user system elapsed
106.75 0.24 106.98
Run Code Online (Sandbox Code Playgroud)
而RcppArmadillo输出:
user system elapsed
108.28 0.23 108.56
Run Code Online (Sandbox Code Playgroud)
有什么东西可以改善吗?
提前致谢!