
Ublas : 
Subject: Re: [ublas] matrix_row fails with symmetric matrix
From: Andrea Cassioli (cassioliandre_at_[hidden])
Date: 20100518 03:14:44
Hi David,
I see your point, but mine it's slightly different! What I'm concerned
is that the matrix_row adaptor does not actually behave as a vector.
For people coming from an STLlike style, this can be a mess!
Moreover, the matrix_row (but I now suspect the same applies to the
matrix_col) miss much of its appeal if such limitations or pitfalls
take place.
To overcome the problem I can assign the vector and then resize to a
bigger dimension, but this is quite an overhead. In a more complete
example (that I attach), such resizing operations are a waste of time.
Compiling with a simple 'g++ DNDEBUG test.cpp', the first commented
version hits a 0.110sec against 0.09 of the other one (which uses a
very raw copy).
I think that, apart for the possibility to fix the problem temporary,
a deeper check of theadaptor behavior should be done. I'm gonna check
also the column adaptor and post the results.
Andrea
On 5/18/10, David Bellot <david.bellot_at_[hidden]> wrote:
> by the way, I sent my previous message too fast and forgot to tell you you
> can directly use a matrix_row as a vector in any expression.
>
> In my previous example, there is a hard copy induced by the assignment,
> however in an expression, you can avoid this memory overhead substituting
> the vector by its initial declaration too, if it makes sense in your case,
> like that:
>
> matrix_row<symm_mat> row0(mat,0);
> matrix_row<symm_mat> lastrow(mat,mat.size1()1);
>
> std::cout<<"this is the matrix:\n "<<mat<<std::endl;
> std::cout<<"is this the first row?\n"<<row0<<std::endl;
> std::cout<<"is this the last row?\n"<<lastrow<<std::endl;
>
> it works well too.
> David
>
> On Mon, May 17, 2010 at 23:03, Andrea Cassioli
> <cassioliandre_at_[hidden]>wrote:
>
>> Hi guys,
>> I've just experienced a quite silly bug. I'm currently using a
>> symmetric matrix to perform some linear algebra calculations, after
>> that I need to copy one row at the time in a bigger vector. Till now I
>> have been performing row copying by means of simple handmade loops.
>>
>> Now I would like to clean the code, so I 've decided to use matrix_row
>> adaptors to iterate among all matrix row and use std::copy to perform
>> the copy operation.
>>
>> It sounds clean and simple but surprise it does not work! I've write
>> down a very simple example, which is attached to the message. In fact
>> the copy is performed accessing the underlying triangular matrix used
>> to store the symmetric one.
>>
>> I'm pretty sure I'm doing something wrong, but I would expect the
>> matrix_row adaptor to behave as a normal vector, that is I would like
>> to play with it seamlessly.
>>
>> Am I wrong or it is a bug??
>>
>> Best Regards,
>> Andrea Cassioli
>>
>> _______________________________________________
>> ublas mailing list
>> ublas_at_[hidden]
>> http://lists.boost.org/mailman/listinfo.cgi/ublas
>> Sent to: david.bellot_at_[hidden]
>>
>
>
>
> 
> David Bellot, PhD
> david.bellot_at_[hidden]
> http://david.bellot.free.fr
>
 Andrea Cassioli