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

Getting started with SparseLU

Tags: None
(comma "," separated)
kairohmer
Registered Member
Posts
2
Karma
0

Getting started with SparseLU

Wed Jun 18, 2014 12:03 pm
Hey I'm not sure what is wrong with my code. Factorization is not working for me so I created a small mini sample:
I tried to factorize the matrix of the PartialPivLU sample and after that a simple identity always getting errors :/

Edit: I tried using SparseQR instead which worked fine. Can somebody explain where the problem with LU is?
It requires a squared and invertible matrix, right? Some other properties?

Code: Select all
#include <iostream>
#include "Eigen/Sparse"

typedef Eigen::SparseMatrix<double, Eigen::ColMajor, int> SparseMatrixXd;
typedef Eigen::SparseLU<SparseMatrixXd, Eigen::COLAMDOrdering<int> > SparseSolverXd;        // does not work
// typedef Eigen::SparseQR<SparseMatrixXd, Eigen::COLAMDOrdering<int> > SparseSolverXd;    // works

int main(int argc, char *argv[])
{
    // Setup System Matrix A
    SparseMatrixXd A(3,3);
    A.reserve(9);

    A.insert(0,0) =   0.68; A.insert(0,1) =  0.597; A.insert(0,2) =  -0.33;
    A.insert(1,0) = -0.211; A.insert(1,1) =  0.823; A.insert(1,2) =  0.536;
    A.insert(2,0) =  0.566; A.insert(2,1) = -0.605; A.insert(2,2) = -0.444;

    // A.insert(0,0) = 1.0;
    // A.insert(1,1) = 1.0;
    // A.insert(2,2) = 1.0;

    A.makeCompressed();

    // Setup RHS
    SparseMatrixXd b(3, 2);
    A.reserve(6);

    b.insert(0,0) =   0.108;    b.insert(0,1) =  -0.27;
    b.insert(1,0) = -0.0452;    b.insert(1,1) = 0.0268;
    b.insert(2,0) =   0.258;    b.insert(2,1) =  0.904;

    b.makeCompressed();

    // factorize A
    SparseSolverXd solver;

    solver.compute(A);
    if(solver.info() != Eigen::Success)
        std::cout << "Compute failed: " << solver.info() << std::endl;

    // solve Ax=b
    SparseMatrixXd x = solver.solve(b);
    std::cout << x << std::endl;

    system ("pause");
    return 0;
}


and this is the output:
Code: Select all
Analysis failed: 15860296
Factorization failed: 15860296
Assertion failed!

Program: D:\Projects\Qt\Eigen\build-EigenTests-Desktop_Qt_5_3_0_MinGW_32bit-Debug\debug\EigenTests.exe
File: ..\EigenTests\Eigen/src/SparseLU/SparseLU.h, Line 180

Expression: m_factorizationIsOk && "SparseLU is not initialized."
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Works for me:
Code: Select all
g++ -O2 splu.cpp  -I ../eigen3.2 -o splu && ./splu
Nonzero entries:
(0.609073,0) (-0.230929,1) (0.510016,2) (2.67396,0) (-1.56241,1) (3.50162,2)

Outer pointers:
0 3  $

0.609073 2.67396
-0.230929 -1.56241
0.510016 3.50162

(A*x-b).norm() / b.norm() = 1.67704e-16


What's your compiler? compiler version? compiler flags? Eigen version?

Make sure your are using the latest 3.2.1 release.
kairohmer
Registered Member
Posts
2
Karma
0

Re: Getting started with SparseLU

Thu Jun 19, 2014 9:23 am
ggael wrote:Make sure your are using the latest 3.2.1 release.

noticed that i was working with an outdated version.. sorry for bothering..
maxlem
Registered Member
Posts
4
Karma
0

Re: Getting started with SparseLU

Thu Sep 11, 2014 4:57 pm
I'm having trouble compiling the following code:

Code: Select all
typedef Eigen::SparseMatrix<double, Eigen::ColMajor, int> Matrix;
Matrix matrix(n,n);
... fill the matrix
matrix.makeCompressed();
Eigen::SparseLU<Matrix, Eigen::COLAMDOrdering<int>> solver; //EDIT: was SparseQR, which works
solver.compute(matrix);
.... solve


  • Error 6 error C2039: 'type' : is not a member of 'Eigen::internal::enable_if' c:\...\eigen\src\Core\Ref.h 195 1
  • Error 7 error C2143: syntax error : missing ',' before '*' c:\...\eigen\src\Core\Ref.h 195 1
  • Error 9 error C2275: 'Eigen::internal::traits<Derived>::match<Derived>::MatchAtCompileTime' : illegal use of this type as an expression c:\...\eigen\src\Core\Ref.h 201 1 QmlGeometryUtil
  • Error 13 error C2664: 'int Eigen::internal::SparseLUImpl<double,int>::column_bmod(const Index,const Index,Eigen::Ref<Eigen::Matrix<double,-1,1,0,-1,1>,0,Eigen::InnerStride<1>>,Eigen::Matrix<double,-1,1,0,-1,1> &,Eigen::Ref<Eigen::Matrix<int,-1,1,0,-1,1>,0,Eigen::InnerStride<1>>,Eigen::Ref<Eigen::Matrix<int,-1,1,0,-1,1>,0,Eigen::InnerStride<1>>,Index,Eigen::internal::LU_GlobalLU_t<Eigen::Matrix<int,-1,1,0,-1,1>,Eigen::Matrix<double,-1,1,0,-1,1>> &)' : cannot convert argument 3 from 'Eigen::VectorBlock<Derived,-1>' to 'Eigen::Ref<Eigen::Matrix<double,-1,1,0,-1,1>,0,Eigen::InnerStride<1>>' c:\...\eigen\src\SparseLU\SparseLU.h 591 1 QmlGeometryUtil
  • other stuff
  • Error 5 error C2993: 'bool (traits<Derived>::match<Derived>::MatchAtCompileTime)' : illegal type for non-type template parameter 'Condition' c:\users\eigen\eigen\src\Core\Ref.h 195 1 QmlGeometryUtil

Using head of brach 3.2.0 (node 5e8f592c3314) and MSVC2013
Edit: try with real head (forgot to update Eigen subrepo) same problem with node c57e23d06e4b

The same code with SparseQR works.
maxlem
Registered Member
Posts
4
Karma
0

Re: Getting started with SparseLU

Fri Sep 12, 2014 2:00 pm
I also tried to compile the code of the first post, I get similar compile error.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: Getting started with SparseLU

Mon Sep 15, 2014 6:00 am
Do you have the same compilation error with the default branch? I do see compilation issues with MSVC, but not the ones you are reporting. Also, what about the official 3.2.2 release? (that one has been checked with MSVC)
maxlem
Registered Member
Posts
4
Karma
0

Re: Getting started with SparseLU

Mon Sep 15, 2014 3:22 pm
Just tried nodes a8e0d153fc5e (default) and b442b2312b69 (3.2.2 tag). Same result.

I can PM you the compile error details.
maxlem
Registered Member
Posts
4
Karma
0

Re: Getting started with SparseLU

Mon Sep 15, 2014 5:00 pm
Ah! I just installed visual s't'idiot update 3 (was update 2). it appear to have solved the problem.

Désolé,
Maxime


Bookmarks



Who is online

Registered users: Bing [Bot], claydoh, Google [Bot], rblackwell, Yahoo [Bot]