[eigen] Forcing a conversion to ColMajor |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: [eigen] Forcing a conversion to ColMajor
- From: Douglas Bates <bates@xxxxxxxxxxxxx>
- Date: Fri, 27 Jul 2012 11:31:46 -0500
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type; bh=arItH1dx7YM0PwNFHCLAXVe/07iuj+XT/+0Ye5aQvfE=; b=uDBsRXW1v4WOPyq64dv4ZEIjokkT2SWrP15MQMoma56tV2qSN1RqrQwcxpCNbEiYx2 Ok9TMOQUth/QGdx81yPQCg97Tg7/xK/25kVdz/vPTiZycF5DU4R0DOCYZVzc0nGb1vSe /MfPuHnYTaZB4zfk23+r11RIIieg+Qw7Fjr7FS1ao9gxaX077zRqzzL506Csvi4BXSLz 8knUGuxb5DAHvqWyBvVqwGlyfTIXMi0OwsZcBu+xnyXZxcd8yZs6TqV1RPptlSzwMPh5 5NSRFJqLLqEzJd+eG/o+y3eazfBytjAINZzCw0xOYuJ8fGPqDvesJcnmYXf1Depg4o1f IFqQ==
In the RcppEigen package for R (www.R-project.org) the functions that
convert an Eigen object into an R object are said to "wrap" the Eigen
object. The final destination for plain dense objects is this
function
// for plain dense objects
template <typename T>
SEXP eigen_wrap_plain_dense( const T& obj, Rcpp::traits::true_type ){
int m = obj.rows(), n = obj.cols();
SEXP ans = PROTECT(::Rcpp::wrap(obj.data(), obj.data() + m * n));
if( T::ColsAtCompileTime != 1 ) {
if (T::IsRowMajor)
throw std::invalid_argument("R requires column-major dense
matrices");
SEXP dd = PROTECT(::Rf_allocVector(INTSXP, 2));
int *d = INTEGER(dd);
d[0] = m;
d[1] = n;
::Rf_setAttrib(ans, R_DimSymbol, dd);
UNPROTECT(1);
}
UNPROTECT(1);
return ans;
}
An R matrix must be stored in column major order. At present I throw
an exception when I detect a Matrix or Array in RowMajor order. Is
there some way I can convert the object to a similar Matrix or Array
but in ColMajor order, given the information that I have in this
template?