|
Ublas : |
Subject: Re: [ublas] Layout type
From: Gunter Winkler (guwi17_at_[hidden])
Date: 2010-05-04 17:46:23
Hello Andrea,
Andrea Arteaga schrieb:
> How can I know whether a matrix is storing its elements with
> column-major storage or with row-major?
>
> I'm writing a template function which takes as argument a
> boost::numeric::ublas::matrix and performs some computation. I have to
> know whether I must transpose the data or not:
>
> template<class MatrixType>
> void my_func(const MatrixType& matrix)
> {
> const char * data =
> reinterpret_cast<const char *>(&matrix(0, 0));
>
> /* ... */
> }
>
> I tried with typename MatrixType::layout_type, but this typedef is
> private.
You should use the matrix traits from traits.hpp (see also fwd.hpp):
// dispatcher
template<class MatrixType>
void my_func(const MatrixType& matrix)
{
my_func(matrix, typename
matrix_traits<MatrixType>::orientation_category());
}
// row major impl
template<class MatrixType>
void my_func(const MatrixType& matrix, const ublas::row_major_tag /*
unused */ )
{
const char * data =
reinterpret_cast<const char *>(&matrix(0, 0));
/* ... */
}
mfg
Gunter
__________ Hinweis von ESET NOD32 Antivirus, Signaturdatenbank-Version 5086 (20100504) __________
E-Mail wurde geprüft mit ESET NOD32 Antivirus.