
Ublas : 
Subject: Re: [ublas] Matrix view over a bunch of ublas::vector's
From: Andrea Cassioli (cassioliandre_at_[hidden])
Date: 20100624 13:20:17
On 6/24/10, Jesse Manning <manning.jesse_at_[hidden]> wrote:
> Since matrix_row and matrix_column both implement the vector_expression
> concept just like ublas::vector does then the same code should be able to
> operate on both transparently as long as the functions are coded to do work
> on vector_expression objects instead of ublas::vector objects.
>
>
> On Thu, Jun 24, 2010 at 12:11 PM, dariomt <dariomt_at_[hidden]> wrote:
>
>> > On Thu, Jun 24, 2010 at 13:21, <dariomt <at> gmail.com> wrote:
>> > Hi list,Suppose I have an algorithm that works over a matrix
>> > expression.I
>> also
>> have a bunch of M ublas::vector's all of size N, each representing a row
>> of
>> a
>> matrix.Is it possible to create a 'view' over those vectors to pass it to
>> the
>> algo as a MxN matrix expression?In this context a 'view' means that I
>> don't
>> need
>> to copy the data in the vectors into a ublas::matrixAlso N >> M, both
>> determined
>> at runtime (i.e. N and M are not compile time constants).Thanks!
>>
>>
>> Jesse Manning <manning.jesse <at> gmail.com> writes:
>>
>> >
>> >
>> > I'm not sure the exact layout of your code but as an alternative you
>> could
>> store your vectors as a matrix instead of individual vectors. This will
>> allow
>> you to work on the matrix as a whole easily and you could use
>> matrix_row/matrix_column view classes to operate on the individual vectors
>> inside the matrix when needed since both of these implement the
>> vector_expression concept. This is essentially what I am doing in one of
>> my
>> projects and it seems to work well.
>>
>> I already thought about that, but it means that those parts of code must
>> work
>> with storage coming from an ublas::vector or from a row in a
>> ublas::matrix,
>> and
>> that is not possible at the moment.
>>
>> Thanks anyway!
>>
>> _______________________________________________
>> ublas mailing list
>> ublas_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/ublas
>> Sent to: manning.jesse_at_[hidden]
>>
>
Hi guys,
boost::ublas::assignement might not be an efficient choice, for it is
meant to copy the values, if I'm not mistaken. If, as I have
understood, the question is how to avoid the copy of this bunch of
vectors, then I guess the solution is a suitable matrix adaptor that
onthefly acts as a view.
A similar issues arises whenever a plain double* array has to be
converted on a boost::ublas::vector. In that case an adaptor is
available (I guess not yet in the official distribution). Similarly, I
suspect that the code should be something like:
matrix_from_vectors< vect_type > m(n_vectors, a_list_of_vectors)
Eventually, a storage specifier could say if the vectors are intended
by rows or by columns. If the vectors are not stored toghether, it may
look like:
matrix_from_vectors< vect_type > m(n_vectors);
m.row(0)=&v0;
m.row(1)=&v1;
...
so that internally only a pointer to the vector is stored. I think
that the question is really interesting and a good solution might be
useful for many.
Andrea
 Andrea Cassioli