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

Inserting zeros into sparsematrix increase nonZeros?

Tags: None
(comma "," separated)
matriza
Registered Member
Posts
17
Karma
0
Hi,

Why does inserting a zero into a sparse matrix increase it nonZeros count? I'm using version 3.1.2.

Code: Select all
#include <Eigen/Core>
#include <Eigen/Dense>
#include <Eigen/Sparse>
#include <Eigen/Eigenvalues>

using namespace Eigen;

int main(void)
{
   SparseMatrix<double> Z(10, 10);
   Z.coeffRef(0, 0) = 0.0;
   std::cout << Z.rows() << " " << Z.cols() << " " << Z.nonZeros() << std::endl;
   return 0;
}


Code: Select all
g++ -IEigen -o t t.cpp
$ ./t
10 10 1
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
That's on purpose. Explicitly inserted zero are explicitly stored. This is required in many configurations where it is important to preserve the structure in case of zeros appearing by accident. If you don't want explicit zeros, then do not insert them! You can also prune them afterwards. See the prune () function.


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot], Yahoo [Bot]