Re: [eigen] Forcing a conversion to ColMajor

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Hi,

you could do something like:

typename Eigen::internal::conditional<T::IsRowMajor,
  Eigen::Matrix<typename T::Scalar,
T::RowsAtCompileTime,T::ColsAtCompileTime,ColMajor>,
  const T&>::type objCopy(obj);

and then use objCopy instead. If T is column major, then objCopy will
just be an alias (const ref).

gael

On Fri, Jul 27, 2012 at 6:31 PM, Douglas Bates <bates@xxxxxxxxxxxxx> wrote:
> 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?
>
>



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/