This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Compiling error for:V.asDiagnoal()-V'*V/V.sum()

Tags: None
(comma "," separated)
zhanxw
Registered Member
Posts
17
Karma
0
Hi,

I am trying to understand a compling error with this simple code:
Code: Select all
 
    Eigen::MatrixXf P0;
    Eigen::VectorXf v;
    P0 = v.asDiagonal() - v * v.transpose() / v.sum();


The above code does not compile, so I have to write like this:
Code: Select all
 
    Eigen::MatrixXf P0;
    Eigen::VectorXf v;
    P0 = v.asDiagonal();
    P0 -= v * v.transpose() / v.sum();


My questions is why the first code does not compile and the second code works....
I did search the forum but cannot find helpful information.

The long compiling errors are pasted below:

g++ -MMD -ggdb -O0 -D__STDC_LIMIT_MACROS -c Skat.cpp -I../libsrc -I../third/eigen -I../third/gsl/include
Skat.cpp: In member function ‘int Skat::Fit(Vector&, Vector&, Matrix&, Matrix&, Vector&)’:
Skat.cpp:44:53: error: no match for ‘operator-’ in ‘((Eigen::MatrixBase<Eigen::Matrix<float, -0x00000000000000001, 1> >*)(& v))->Eigen::MatrixBase<Derived>::asDiagonal [with Derived = Eigen::Matrix<float, -0x00000000000000001, 1>]() - Eigen::MatrixBase<Derived>::operator/(const Scalar&) const [with Derived = Eigen::GeneralProduct<Eigen::Matrix<float, -0x00000000000000001, 1>, Eigen::Transpose<Eigen::Matrix<float, -0x00000000000000001, 1> >, 2>, typename Eigen::internal::traits<T>::Scalar = float, Eigen::MatrixBase<Derived>::Scalar = float]((* &((Eigen::DenseBase<Eigen::Matrix<float, -0x00000000000000001, 1> >*)(& v))->Eigen::DenseBase<Derived>::sum [with Derived = Eigen::Matrix<float, -0x00000000000000001, 1>, typename Eigen::internal::traits<T>::Scalar = float]()))’
make: *** [Skat.o] Error 1
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
This is because diagonal_matrix - dense_matrix is not a supported operator yet. Recall that v.asDiagonal() returns an expression of a diagonal matrix, not a dense matrix. Thanks to the upcoming 'evaluators', we will soon be able to automatically evaluate your initial expression as:

P0 = v * v.transpose() / (-v.sum());
P0.diagonal() += v;

which is more efficient than your second approach.
zhanxw
Registered Member
Posts
17
Karma
0
Thanks, Eigen master :)


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot]