Re: [eigen] why does the result of the col member function behave so different? |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
On 05/06/2011 10:14:38 PM, Gael Guennebaud wrote:
> Hi,
>
> regarding: A.col(1)= A.col(0).square(); this is because there is no
> square() method in the matrix world, otherwise it would mean A.col(0)
> * A.col(0) with "*" the matrix product operator...
>
> So you have to write:
>
> A.col(1)= A.col(0).array().square();
Yes, thanks. But wouldn't there be any ambiguity offering methods like
square, cube, ... for a (single) column vector, as well.
>
> The other issue, Inp >> A.col(0);, is a C++ limitation. The problem
> is that A.col(0) is a temporary object and it cannot be passed as a
> non const reference to a function (or operator). So you have to name
> it:
>
> MatrixXd::ColXpr A0(A.col(0));
> Inp >> A0;
>
> Another ugly solution is to declare your operator >> with a const
> ref:
>
> std::istream & operator >>(std::istream & s, const
> Eigen::MatrixBase<Derived> & m)
>
> and const_cast m... yes very ugly and not safe.
>
Yes, but how did you write operator= then? (It works for a column
temporary!)
By the way, I did "solve" this problem in my own matrix class by having
a special L_Vector class which is returned by slicing functions/
operators. This L_Vector class represents a temporary Lvalue, it has no
own storage but refers to storage elsewhere (like a column of a matrix)
Now, I do have
istream& operator>>(istream&, const L_Vector&)
but that's no problem, since it matches such Lvalue vectors (or
L_Matrix, rsp) only. I have used the same with my operator= .
Regards,
Helmut.