learner
Registered Member

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)
The problem comes in the last line. Thanks in advance 
ggael
Moderator

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

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

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 
ggael
Moderator

Is it really guaranteed that the entries are sorted? Moreover, Eigen is 0index based, while MatLab is 1index based, so you have to adjust the index buffers (decrement them, do the work, increment them back).

learner
Registered Member

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
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 
ggael
Moderator

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

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
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
This small code crashes. Thanks again 
ggael
Moderator

What are mat.rows() and mat.cols() ? If 2x2 then xx should be 0,1,0,1.

learner
Registered Member

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 !!! 
Registered users: alfaflo, alistairmagee, andreas_k, Artmessiah, Baidu [Spider], Bing [Bot], dajkiry, davidemme, Exabot [Bot], fbouchard, fernan82, Google [Bot], google01103, LukasT.dev, nickan, pmoreau, TheraHedwig, veqz, Yahoo [Bot]