mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
Prevent inserting zero values in SparseMatrix (#2836)
* Prevent inserting zero values in SparseMatrix As discussed in #2830 * Formatting correction * Lint correction
This commit is contained in:
parent
19ac459fbe
commit
16cdf66385
@ -510,8 +510,10 @@ export const createSparseMatrixClass = /* #__PURE__ */ factory(name, dependencie
|
||||
_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)
|
||||
if (!eq(v, zero)) {
|
||||
// insert value @ (i, j)
|
||||
_insert(k, i, j, v, this._values, this._index, this._ptr)
|
||||
}
|
||||
}
|
||||
|
||||
return this
|
||||
|
||||
@ -774,6 +774,17 @@ describe('SparseMatrix', function () {
|
||||
])
|
||||
})
|
||||
|
||||
it('should not add matrix element (zero)', function () {
|
||||
const m = new SparseMatrix([
|
||||
[0, 1],
|
||||
[0, 0]
|
||||
])
|
||||
|
||||
m.set([0, 0], 0)
|
||||
|
||||
assert.deepStrictEqual(m._values.length, 1)
|
||||
})
|
||||
|
||||
it('should update matrix element (non zero)', function () {
|
||||
const m = new SparseMatrix([
|
||||
[10, 0, 0, 0, -2, 0],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user