SparseMatrix is equal to the dense one #2830
Replies: 3 comments 7 replies
-
Hmm, this is odd. A SparseMatrix should only store entries |
Beta Was this translation helpful? Give feedback.
-
I see, I will check if that's right and do that !
Le mar. 1 nov. 2022 à 15:30, Glen Whitney ***@***.***> a
écrit :
… The problem may be in the set method of SparseMatrix. See SparseMatrix.js
in /src/type/matrix. The guts are:
// find value index
const k = _getValueIndex(i, this._ptr[j], this._ptr[j + 1], this._index)
// check k is prior to next column k and it is in the correct row
if (k < this._ptr[j + 1] && this._index[k] === i) {
// check value != 0
if (!eq(v, zero)) {
// update value
this._values[k] = v
} else {
// remove value from matrix
_remove(k, j, this._values, this._index, this._ptr)
}
} else {
// insert value @ (i, j)
_insert(k, i, j, v, this._values, this._index, this._ptr)
}
You see in the top-level "else" block there is never a check for zero, so
it seems to me that .set() may be calling _insert with zero values,
"polluting" the compression of the SparseMatrix. If that's correct, a fix
might be to simply change the else to else if (!eq(v, zero)) since there
is no point inserting a zero into a SparseMatrix. Sorry I don't at the
moment have time to try this, but if you do and it works, a PR with the fix
and a test for this problem (maybe just like your fiddle but with smaller
matrices) would be welcome.
—
Reply to this email directly, view it on GitHub
<#2830 (reply in thread)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AVXFULQ46QFS2DIHC2FWNULWGESPRANCNFSM6AAAAAARS5W6K4>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
This issue has been fixed now in v11.3.3. Thanks @AlexandreAlvesDB . |
Beta Was this translation helpful? Give feedback.
-
Hello everyone,
i'm trying to implement a solver for the least square problem and I'm running into an issue.
I want a compressed version of a matrix which is full of zeros so I used mathjs.sparse
But what is returned is a square matrix with zero values, maybe I understood it wrong.
If someone could help me on this one, I'd be grateful !
Beta Was this translation helpful? Give feedback.
All reactions