Reply to topic

Inserting zeros into sparsematrix increase nonZeros?

matriza
Registered Member
Posts
15
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
2194
Karma
15
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.

 
Reply to topic

Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], cristian.onet, Exabot [Bot], garthecho, Google [Bot], Hans, ingwa, koriun, madcoucal, newtonnickel, ooker, pedrorodriguez, rulet111, Yahoo [Bot]