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

SparseMatrix InsertBack

Tags: None
(comma "," separated)
tmensink
Registered Member
Posts
3
Karma
0

SparseMatrix InsertBack

Wed May 11, 2011 1:05 am
Hi,

I have a problem with using InsertBack.
If I try
Code: Select all
   
SparseMatrix<float> S1(nrN,nrN);
   for(int j=0;j<nrN;j++){
      for(int i=0;i<nrN;i++){
         printf("(%d,%d)",i,j);fflush(stdout);
         S1.insertBack(i,j) = 1;
      }
   }


I get the following output with error:
(0,0)(1,0)(2,0)(3,0)(4,0)(5,0)(6,0)(7,0)(8,0)(9,0)(0,1)
assertion failed: size_t(m_outerIndex[outer+1]) == m_data.size() && "Invalid ordered insertion (invalid outer index)"
in function typename Eigen::internal::traits<Eigen::SparseMatrix<_Scalar, _Options, _Index> >::Scalar& Eigen::SparseMatrix<_Scalar, _Flags, _Index>::insertBackByOuterInner(typename Eigen::internal::traits<Eigen::SparseMatrix<_Scalar, _Options, _Index> >::Index, typename Eigen::internal::traits<Eigen::SparseMatrix<_Scalar, _Options, _Index> >::Index) [with _Scalar = float, int _Options = 0, _Index = int] at Eigen/src/Sparse/SparseMatrix.h:179


If I try to swap the two indices:

Code: Select all
   
SparseMatrix<float> S1(nrN,nrN);
   for(int i=0;i<nrN;i++){
      for(int j=0;j<nrN;j++){
         printf("(%d,%d)",i,j);fflush(stdout);
         S1.insertBack(i,j) = 1;
      }
   }


I get the same error but sooner:
(0,0)(0,1)
assertion failed: size_t(m_outerIndex[outer+1]) == m_data.size() && "Invalid ordered insertion (invalid outer index)"


I'm clearly not understanding the working of insertBack, what do I miss?
I'm using eigen3 on a MacOSX.

Cheers, Thomas
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS

Re: SparseMatrix InsertBack

Wed May 11, 2011 6:19 am
hi, the insertBack function is aimed to be as fast as possible and it is therefore a low level function: as explained in its documentation:

"Before filling a given inner vector you must call the statVec(Index) function"

"After an insertion session, you should call the finalize() function."

So here is the correct version:

Code: Select all
SparseMatrix<float> S1(nrN,nrN);
   for(int j=0;j<nrN;j++){
      S1.startVec(j);
      for(int i=0;i<nrN;i++){
         S1.insertBack(i,j) = 1;
      }
   }
S1.finalize();


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], q.ignora