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

Runtime error with Eigen svd

Tags: None
(comma "," separated)
tgreiner
Registered Member
Posts
4
Karma
0

Runtime error with Eigen svd

Thu Jul 30, 2015 3:33 pm
I am new to Eigen and trying to learn how to use the svd function.

My code is as follows:
Code: Select all
#include <iostream>
#include <Eigen/Dense>

int main()
{
   Eigen::MatrixXf A = Eigen::MatrixXf::Random(3, 2);
   std::cout << "A: " << A << std::endl;

   Eigen::JacobiSVD<Eigen::MatrixXf> svd(A, Eigen::ComputeFullU | Eigen::ComputeFullV);
   std::cout << "U: " << svd.matrixU() << std::endl;;
   std::cout << "V: " << svd.matrixV() << std::endl;;

}


The code compiles and when it runs it reports the matrix A.

But then the program crashes, without giving any specific error message.

Can someone help me with what I am doing wrong.

MinGW c++ compiler
Code::Blocks IDE
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Runtime error with Eigen svd

Thu Jul 30, 2015 8:09 pm
hm, probably a stack alignement issue with mingw. Which versions are you using (mingw and eigen)? The backtrace would also help a lot. Also make sure you did not compiled with -DNDEBUG (to keep runtime assertions).

You might also try with -DEIGEN_DONT_ALIGN_STATICALLY. If that helps, then that's for sure a stack alignment issue. In that case, -mstackrealign and -mpreferred-stack-boundary=4 might help.
tgreiner
Registered Member
Posts
4
Karma
0

Re: Runtime error with Eigen svd

Fri Jul 31, 2015 2:00 pm
Using Code:Blocks version 13.12
MInGW version 1.8


here is the compiler line:
mingw32-g++.exe -Wall -fexceptions -g -march=corei7-avx -Wundef -Wfloat-equal -Winline -Wmain -pedantic -std=c++11 -Wall -g -IC:\CodeBlocks\MinGW\include -IC:\GnuWin32\include -IC:\Eigen -c

I tried adding -DEIGEN_DONT_ALIGN_STATICALLY but it made no difference.

For what it is worth, I can get this to run properly if I change MatrixXf to Matrix3d (every place it appears) and start with a manually (not randomly) input 3d matrix.

Code: Select all
#include <iostream>
#include <Eigen/Dense>

int main()
{
    Eigen::Matrix3d a;
    Eigen::Matrix3d u;
    Eigen::Matrix3d v;

   a(0,0)=1; a(0,1)=2; a(0,2)=3;
   a(1,0)=4; a(1,1)=5; a(1,2)=6;
   a(2,0)=7; a(2,1)=8; a(2,2)=9;

    std::cout << "a:\n " << a<< std::endl;

    Eigen::JacobiSVD<Eigen::Matrix3d> svd(a, Eigen::ComputeFullU | Eigen::ComputeFullV);
    Eigen::Vector3d s = svd.singularValues();
    u=svd.matrixU() ;
    v=svd.matrixV() ;


    std::cout << "s:\n " << s<< std::endl;
    std::cout << "U:\n " << u << std::endl;
    std::cout << "V:\n " << v << std::endl;

}



But why this works and the original version does not is a mystery.

It is suggesting that cannot use dynamically sized matrices, which is what I want to be able to do. I would like a function that can SVD a 4x7 matrix as easily as it will a 3x3 matrix.
tgreiner
Registered Member
Posts
4
Karma
0

Re: Runtime error with Eigen svd

Mon Aug 03, 2015 3:44 pm
I've got this figured out.

I had my code set to compile with Intel Core i7 optimization. I turned off that compiler flag and now everything seems to be running just fine.

While that seems to have solved my immediate SVD problem, does anyone know why that optimization conflicts with Eigen?

Does anyone know of any other compiler optimizations that should be avoided when using Eigen??
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Runtime error with Eigen svd

Mon Aug 03, 2015 9:06 pm
A backtrace would help, and also, which Eigen version are you using?


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]