[Rd] Problem using F77_CALL(dgemm) in a package
Dirk Eddelbuettel
edd at debian.org
Sun Feb 20 17:11:21 CET 2011
On 20 February 2011 at 09:50, Dirk Eddelbuettel wrote:
| There is of course merit in working through the barebones API but in case you
| would consider a higher-level alternative, consider these few lines based on
| RcppArmadillo (which end up calling dgemm() for you via R's linkage to the BLAS)
PS I always forget that we have direct support in Rcpp::as<> for Armadillo
matrices. The examples reduces to three lines in C++, and you never need to
worry about row or column dimension, or memory allocation or deallocation:
R> suppressMessages(library(inline))
R> txt <- '
+ arma::mat Am = Rcpp::as< arma::mat >(A);
+ arma::mat Bm = Rcpp::as< arma::mat >(B);
+ return Rcpp::wrap( Am * Bm );
+ '
R> mmult <- cxxfunction(signature(A="numeric", B="numeric"),
+ body=txt,
+ plugin="RcppArmadillo")
R> A <- matrix(1:9, 3, 3)
R> B <- matrix(9:1, 3, 3)
R> C <- mmult(A, B)
R> print(C)
[,1] [,2] [,3]
[1,] 90 54 18
[2,] 114 69 24
[3,] 138 84 30
R>
Matrices A and B from directly initialise Armadillo matrices, and the result
can be returned directly.
Hth, Dirk
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the R-devel
mailing list