Reply to topic

SPARSELU returns Invalid ordered insertion

learner
Registered Member
Posts
10
Karma
0
Hi everybody !!

I am new using eigen, and I have a mex function where i obtain a sparse matrix from matlab
and i want to calculate the LU decomposition (just to try). But I get the following error:

Invalid ordered insertion (invalid inner index)

Code: Select all
   MappedSparseMatrix<double,ColMajor> mat (mxGetM(in[0]), mxGetM(in[0]), mxGetNzmax(in[0]), (int*)mxGetJc(in[0]), (int*)mxGetIr(in[0]), mxGetPr(in[0]));

   VectorXd bb, xx;
   // fill b
   // solve Ax = b
   SparseLU< MappedSparseMatrix<double,ColMajor>> solver;
   solver.compute(mat);


The problem comes in the last line.

Thanks in advance
User avatar ggael
Moderator
Posts
2793
Karma
18
OS
Which Eigen version? Maybe the entries of mat are not sorted? You can sort them by copying it to a SparseMatrix<double,RowMajor>.
learner
Registered Member
Posts
10
Karma
0
I use the last version and i get the pointers from the mex function obtained by matlab. So the matrix is sorted according to matlab.This is the reason why i use the mapped version of the sparsematrix class. So how could i sort it out if i create the matrix with the mex pointers. Or how could i sort it out if it is the mapped sparse class.

Thank you very much for your help
learner
Registered Member
Posts
10
Karma
0
I would prefer not to do it by copying point by point in another matrix because it is a huge matrix and i would like to have only one matrix.

Thank you very much
User avatar ggael
Moderator
Posts
2793
Karma
18
OS
Is it really guaranteed that the entries are sorted? Moreover, Eigen is 0-index based, while MatLab is 1-index based, so you have to adjust the index buffers (decrement them, do the work, increment them back).
learner
Registered Member
Posts
10
Karma
0
Hi,

thank you very much for your answer. I think i have a problem of concept so i made a short example to see what i am doing wrong

Code: Select all
 MappedSparseMatrix<double,ColMajor> mat (mxGetM(in[0]), mxGetM(in[0]), mxGetNzmax(in[0]), (int*)yy, (int*)xx, (double*)mxGetPr(in[0]));


yy: are the indexs to rows
xx are the indexs to columns

matrix is
[2,1
4,1]

and xx
xx[0] 0
xx[1] 1
xx[2] 0
xx[3] 1
and yy
yy[0] 0
yy[1] 0
yy[2] 1
yy[3] 1

so it is column major. Am i doing something wrong?.

Thanks again
User avatar ggael
Moderator
Posts
2793
Karma
18
OS
the yy index vector does not correspond to what Eigen expects. In your example it should be :

yy[] = [0,2,4]

see http://eigen.tuxfamily.org/dox/group__T ... parse.html, "compressed" exemple.
learner
Registered Member
Posts
10
Karma
0
Thanks for your answer. I also tried like this but it seems this function has a bug because there is no way to make it work even for simple
examples

Code: Select all
 MappedSparseMatrix<double,ColMajor> mat (mxGetM(in[0]), mxGetM(in[0]), mxGetNzmax(in[0]), (int*)yy, (int*)xx, (double*)L);


where
yy[0] 0
yy[1] 2
yy[2] 4
xx[0] 0
xx[1] 1
xx[2] 2
xx[3] 3
L[0] 2
L[1] 4
L[2] 1
L[3] 1

even this small example does not work. It does not get the indexes correctly. I cannot even read it

Code: Select all
         for (int k=0; k<mat.outerSize(); ++k){

   for (MappedSparseMatrix<double>::InnerIterator it(mat,k); it; ++it)
   {
   int a = it.value();
   a = it.row(); // row index
   a = it.col(); // col index (here it is equal to k)
   a = it.index(); // inner index, here it is equal to it.row()
   }
   }


This small code crashes.

Thanks again
User avatar ggael
Moderator
Posts
2793
Karma
18
OS
What are mat.rows() and mat.cols() ? If 2x2 then xx should be 0,1,0,1.
learner
Registered Member
Posts
10
Karma
0
Thank you very much. Yeah it is right I was writing wrong the indices and I also had an error casting of the pointers !!!. With this I solve my problem.
Thank you so much for helping me understand the indexes to the sparse matrix. It works excellent now for my problem !!!!

See you !!!

 
Reply to topic

Bookmarks



Who is online

Registered users: Artmessiah, arucard, Baidu [Spider], Bing [Bot], cgehman, dalishi, Exabot [Bot], Google [Bot], lueck, Majestic-12 [Bot], ramskulls, sammieray, sparhawk, supaiku, Yahoo [Bot]