greenkeeper[bot] c5971b371a Update standard to the latest version 🚀 (#1226)
* chore(package): update standard to version 12.0.0

* update to new lint version with --fix

I believe this mainly adds whitespace to `{}`'s.

* Replace assert.equal with assert.strictEqual

This breaks a lot of tests which I will endevour to fix in the next
commits.

* Fix most errors due to assert.strictEquals

Some instances of `strictEquals` are replaced by `deepEquals`.
`toString` has been used to make some string comparisions explicit.
Tests will still fail untill #1236 and #1237 are fixed.

* Fix assertion erros due to -0

With node 10, assert.strictEqual no longer considers `0 === -0`.
I missed these first time round as I was using node 8.

* Put toString correct side of bracket

I was converting the constructor to a string rather
than the result of the computation. Oops.

* Fixed #1236: quantileSeq has inconsistant return

* Update package-lock

* Fixed #1237: norm sometimes returning a complex number instead of number

* Fix cli tests

* More changes for standardjs, and fixes in unit tests
2018-09-08 16:33:58 +02:00

106 lines
2.9 KiB
JavaScript

const assert = require('assert')
const approx = require('../../../../tools/approx')
const math = require('../../../../src/main').create()
math.import(require('../../../../src/function/algebra/sparse/csPermute'))
math.import(require('../../../../src/function/algebra/sparse/csLu'))
math.import(require('../../../../src/function/algebra/sparse/csSqr'))
const csPermute = math.algebra.sparse.csPermute
const csLu = math.algebra.sparse.csLu
const csSqr = math.algebra.sparse.csSqr
describe('csLu', function () {
it('should decompose matrix, 2 x 2, no symbolic ordering and analysis, partial pivoting', function () {
const m = math.sparse([[2, 1], [1, 4]])
// partial pivoting
const r = csLu(m, null, 1)
// L
assert.deepStrictEqual(r.L.valueOf(), [[1, 0], [0.5, 1]])
// U
assert.deepStrictEqual(r.U.valueOf(), [[2, 1], [0, 3.5]])
// P
assert.deepStrictEqual(r.pinv, [0, 1])
// verify
approx.deepEqual(csPermute(m, r.pinv, null, true), math.multiply(r.L, r.U))
})
it('should decompose matrix, 4 x 4, natural ordering (order=0), partial pivoting', function () {
const m = math.sparse(
[
[4.5, 0, 3.2, 0],
[3.1, 2.9, 0, 0.9],
[0, 1.7, 3, 0],
[3.5, 0.4, 0, 1]
])
// symbolic ordering and analysis, order = 0
const s = csSqr(0, m, false)
// partial pivoting
const r = csLu(m, s, 1)
// verify
approx.deepEqual(csPermute(m, r.pinv, s.q, true).valueOf(), math.multiply(r.L, r.U).valueOf())
})
it('should decompose matrix, 4 x 4, amd(A+A\') (order=1), partial pivoting', function () {
const m = math.sparse(
[
[4.5, 0, 3.2, 0],
[3.1, 2.9, 0, 0.9],
[0, 1.7, 3, 0],
[3.5, 0.4, 0, 1]
])
// symbolic ordering and analysis, order = 1
const s = csSqr(1, m, false)
// partial pivoting
const r = csLu(m, s, 1)
// verify
approx.deepEqual(csPermute(m, r.pinv, s.q, true).valueOf(), math.multiply(r.L, r.U).valueOf())
})
it('should decompose matrix, 4 x 4, amd(A\'*A) (order=2), partial pivoting', function () {
const m = math.sparse(
[
[4.5, 0, 3.2, 0],
[3.1, 2.9, 0, 0.9],
[0, 1.7, 3, 0],
[3.5, 0.4, 0, 1]
])
// symbolic ordering and analysis, order = 2
const s = csSqr(2, m, false)
// partial pivoting
const r = csLu(m, s, 1)
// verify
approx.deepEqual(csPermute(m, r.pinv, s.q, true).valueOf(), math.multiply(r.L, r.U).valueOf())
})
it('should decompose matrix, 4 x 4, amd(A\'*A) (order=3), partial pivoting', function () {
const m = math.sparse(
[
[4.5, 0, 3.2, 0],
[3.1, 2.9, 0, 0.9],
[0, 1.7, 3, 0],
[3.5, 0.4, 0, 1]
])
// symbolic ordering and analysis, order = 3
const s = csSqr(3, m, false)
// partial pivoting
const r = csLu(m, s, 1)
// verify
approx.deepEqual(csPermute(m, r.pinv, s.q, true).valueOf(), math.multiply(r.L, r.U).valueOf())
})
})