Boost logo

Ublas :

Subject: Re: [ublas] pointer to matrix structure
From: Marcel Rehberg (Marcel.Rehberg_at_[hidden])
Date: 2011-08-08 05:20:07


On Mon, 08 Aug 2011 11:03:20 +0200, Kraus Philipp
<philipp.kraus_at_[hidden]> wrote:

>
> Am 08.08.2011 um 10:37 schrieb Marcel Rehberg:
>>
>> You could use
>>
>> ublas::matrix<T,ublas::column_major> X
>>
>> as your main matrix type. I use it to interface lapack which also
>> expects column orientation.
>
> I use ublas;;row_major matrices primary. Do I need convert the matrix
> like:
>
> ublas::<T, ublas::column_major> x = my_row_major_matrix;
> write( &(x.data()[0]) ...)
>
> ?
>
> Because on this the copy-constructor will be called and I create a full
> matrix clone. My matrix is large (around 10^7 - 10^9 (non-zero) elements
> so I wouln't copy the data)

Right, this would copy the data. What I meant was to use
ublas::<T,ublas::column_major> for your original matrix, right from the
beginning.

It does not make a difference from the ublas interface point of view. So
it wouldn't require any code changes except in the definition of the
matrices*. To make things easier you could use a typedef like

typedef myMatrixType ublas::matrix<T,ublas::column_major>;

and use myMatrixType whenever you need an ublas matrix. In that way you
also could easily change back to row major if needed.

Regards
Marcel

*(Except you also use library methods that expect row major, but then I
guess you'll end up copying anyway)