Re: [eigen] Forcing a conversion to ColMajor |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] Forcing a conversion to ColMajor
- From: Gael Guennebaud <gael.guennebaud@xxxxxxxxx>
- Date: Sat, 28 Jul 2012 09:52:52 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=MYVJk6RgQhizFgOFSqS7op/mGmfWuvgr6NDnFxuDYrs=; b=iouNvzsc3PAh2hegz5EU8Hwajokb8e0YhWtUlBaOR0BzVYEEdEFxewBqHjMLQyDWIi UPUgQHp48OXb75TUWgMhWUTm5TlznRbBcTpLUaijfrYGjI6kwAIYEfHm6TETl4pQLR0K SWtYGigM1OMZeUM7tvKMovWcv7qfY4xME7ugK1S2+ai5JPS1PK73jdRXR5HW9tH8OLZc xf1O5+B4irTvwai4GD7CXfmsAeU3G+EqirVRfIoMU8gk7JWcbfzKnhyrSjver5glPUap x9y7VzjzlEGBesnKqBVL5mcg6o0qxnXO8umDQISNrv8OTgFJEvpLfhA9pdf0KrLCpm8c DqvQ==
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?
>
>