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

SparseMatrix's coeffRef(i,j) method problem

Tags: None
(comma "," separated)
eigenlearner
Registered Member
Posts
17
Karma
0
I found a strange behavior of SparseMatrix's method coeffRef(i,j).

When an sparse matrix m is initialized with some non zeros, anytime I used m.coeffRef(i,j) but not assign any value to it, it will add an entry of m(i,j) with 0 if it is not previously assigned.

For example, if m(0,0) is not initialized and if I use

if (m.coeffRef(0,0) > 1)

in a statement, the result will be that m(0,0) is initialized as 0 after the call, which should not be added.

This is strange.
eigenlearner
Registered Member
Posts
17
Karma
0
I got the answer. Simply replace coeffRef with coeff method to avoid unintended insertion.

eigenlearner wrote:I found a strange behavior of SparseMatrix's method coeffRef(i,j).

When an sparse matrix m is initialized with some non zeros, anytime I used m.coeffRef(i,j) but not assign any value to it, it will add an entry of m(i,j) with 0 if it is not previously assigned.

For example, if m(0,0) is not initialized and if I use

if (m.coeffRef(0,0) > 1)

in a statement, the result will be that m(0,0) is initialized as 0 after the call, which should not be added.

This is strange.


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot]