Simon,
You (in my eyes needlessly) complicate matters further with the S4 wrapping.
The base case is simple, shown/used in src/fastLm.cpp right in the middle of
RcppArmadillo and discussed a million times:
extern "C" SEXP fastLm(SEXP Xs, SEXP ys) {
try {
Rcpp::NumericVector yr(ys); // creates Rcpp vector
from SEXP
Rcpp::NumericMatrix Xr(Xs); // creates Rcpp matrix
from SEXP
int n = Xr.nrow(), k = Xr.ncol();
arma::mat X(Xr.begin(), n, k, false); // reuses memory and
avoids extra copy
arma::colvec y(yr.begin(), yr.size(), false);
We use two operations to go from SEXP to Rcpp::Numeric{Vector,Matrix} and
then to arma::{colvec,mat}. This is marginally faster than doing a single
as<arma::mat*>(Xs) cast.
The case for integer vectors and matrices is identical.
It might be a good idea for you to time alternative approaches.
Dirk
--
Dirk Eddelbuettel | [email protected] | http://dirk.eddelbuettel.com
_______________________________________________
Rcpp-devel mailing list
[email protected]
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel