[Rcpp-devel] How to figure out the signature of cxxfunction is a matrix or vector?

Peng Yu pengyu.ut at gmail.com
Wed Aug 22 04:43:02 CEST 2012


Hi,

"numeric" is specified as the signature. But it does not say whether
it should be a matrix or a vector. The following example just assume
the input is matrix. But should there be some checking to make sure
the input is indeed a matrix before the conversion to NumericMatrix?
Or the check has to be before "fun" is called?

Thanks!

library(inline)
src='
Rcpp::NumericVector mat =
Rcpp::clone<Rcpp::NumericMatrix>(mx);
std::transform(mat.begin(), mat.end(),
  mat.begin(), ::sqrt);
return mat;
'
fun=cxxfunction(signature(mx="numeric"), src,
  plugin="Rcpp")
orig=matrix(1:9, 3, 3)
fun(orig)


-- 
Regards,
Peng


More information about the Rcpp-devel mailing list