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

Large matrix inverse

Tags: None
(comma "," separated)
donnss
Registered Member
Posts
7
Karma
0

Large matrix inverse

Wed Mar 16, 2016 11:26 am
I have a matrix of 3600 x 3600 and want to find its inverse. I used the matrix.inverse() method but it takes too long. How to do it faster? If you can, please provide an example.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Large matrix inverse

Wed Mar 16, 2016 2:16 pm
What is "too long" for you and what would be a reasonable amount of time?
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Large matrix inverse

Wed Mar 16, 2016 2:33 pm
Here it takes 4s (Eigen 3.3-beta1, -O3 -mfma, double precision, i7 2.6GHz)
donnss
Registered Member
Posts
7
Karma
0

Re: Large matrix inverse

Wed Mar 16, 2016 2:44 pm
Wow, mine is around 15min with i5, 1.6GHz... Maybe there is something I do wrong...

Code: Select all
float alpha = 0.1f;
float beta = 0.4f;
float gamma = 0.1f;
int w = 3600;
int h = 3600;
 //====================================================================================
// set pentadiagonal matrix
//====================================================================================
double a = 1 - gamma * (2 * alpha + 6 * beta);
double b = -gamma * (-alpha - 4 * beta);
double c = -gamma * beta;

Matrix<double, Eigen::Dynamic, Eigen::Dynamic> coeff;
coeff.resize(w, h);
coeff.setZero();

coeff.diagonal().setConstant(a);
coeff.diagonal(1).setConstant(b);
coeff.diagonal(-1).setConstant(b);
coeff.diagonal(2).setConstant(c);
coeff.diagonal(-2).setConstant(c);
coeff.diagonal(w-2).setConstant(c);
coeff.diagonal(2-h).setConstant(c);
coeff.diagonal(w-1).setConstant(b);
coeff.diagonal(1-w).setConstant(b);
//====================================================================================
//inverse matrix
//====================================================================================
Matrix<double, Eigen::Dynamic, Eigen::Dynamic> inverse;
inverse = coeff.inverse();
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Large matrix inverse

Wed Mar 16, 2016 4:15 pm
What's your compiler? Make sure to enable compiler optimizations. (e.g., -O3).
donnss
Registered Member
Posts
7
Karma
0

Re: Large matrix inverse

Wed Mar 16, 2016 4:35 pm
MSVC 14 but Visual Studio 2015 somehow doesn't support compiler optimizations.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], ourcraft