mirror of
https://github.com/josdejong/mathjs.git
synced 2026-01-18 14:59:29 +00:00
115 lines
3.4 KiB
JavaScript
115 lines
3.4 KiB
JavaScript
const assert = require('assert')
|
|
const approx = require('../../../../tools/approx')
|
|
const market = require('../../../../tools/matrixmarket')
|
|
const math = require('../../../../src/main').create()
|
|
|
|
math.import(require('../../../../src/function/algebra/sparse/cs_permute'))
|
|
math.import(require('../../../../src/function/algebra/sparse/cs_lu'))
|
|
math.import(require('../../../../src/function/algebra/sparse/cs_sqr'))
|
|
|
|
const cs_permute = math.sparse.cs_permute
|
|
const cs_lu = math.sparse.cs_lu
|
|
const cs_sqr = math.sparse.cs_sqr
|
|
|
|
describe('cs_lu', function () {
|
|
it('should decompose matrix, 48 x 48, natural ordering (order=0), full pivoting, matrix market', function (done) {
|
|
// import matrix
|
|
market.import('tools/matrices/bcsstk01.tar.gz', ['bcsstk01/bcsstk01.mtx'])
|
|
.then(function (matrices) {
|
|
// matrix
|
|
const m = matrices[0]
|
|
|
|
// symbolic ordering and analysis, order = 0
|
|
const s = cs_sqr(0, m, false)
|
|
|
|
// full pivoting
|
|
const r = cs_lu(m, s, 0.001)
|
|
|
|
// verify
|
|
approx.deepEqual(cs_permute(m, r.pinv, s.q, true).valueOf(), math.multiply(r.L, r.U).valueOf())
|
|
|
|
// indicate test has completed
|
|
done()
|
|
})
|
|
.fail(function (error) {
|
|
// indicate test has completed
|
|
done(error)
|
|
})
|
|
})
|
|
|
|
it('should decompose matrix, 48 x 48, amd(A+A\') (order=1), full pivoting, matrix market', function (done) {
|
|
// import matrix
|
|
market.import('tools/matrices/bcsstk01.tar.gz', ['bcsstk01/bcsstk01.mtx'])
|
|
.then(function (matrices) {
|
|
// matrix
|
|
const m = matrices[0]
|
|
|
|
// symbolic ordering and analysis, order = 1
|
|
const s = cs_sqr(1, m, false)
|
|
|
|
// full pivoting
|
|
const r = cs_lu(m, s, 0.001)
|
|
|
|
// verify
|
|
approx.deepEqual(cs_permute(m, r.pinv, s.q, true).valueOf(), math.multiply(r.L, r.U).valueOf())
|
|
|
|
// indicate test has completed
|
|
done()
|
|
})
|
|
.fail(function (error) {
|
|
// indicate test has completed
|
|
done(error)
|
|
})
|
|
})
|
|
|
|
it('should decompose matrix, 48 x 48, amd(A\'*A) (order=2), full pivoting, matrix market', function (done) {
|
|
// import matrix
|
|
market.import('tools/matrices/bcsstk01.tar.gz', ['bcsstk01/bcsstk01.mtx'])
|
|
.then(function (matrices) {
|
|
// matrix
|
|
const m = matrices[0]
|
|
|
|
// symbolic ordering and analysis, order = 2
|
|
const s = cs_sqr(2, m, false)
|
|
|
|
// full pivoting
|
|
const r = cs_lu(m, s, 0.001)
|
|
|
|
// verify
|
|
approx.deepEqual(cs_permute(m, r.pinv, s.q, true).valueOf(), math.multiply(r.L, r.U).valueOf())
|
|
|
|
// indicate test has completed
|
|
done()
|
|
})
|
|
.fail(function (error) {
|
|
// indicate test has completed
|
|
done(error)
|
|
})
|
|
})
|
|
|
|
it('should decompose matrix, 48 x 48, amd(A\'*A) (order=3), full pivoting, matrix market', function (done) {
|
|
// import matrix
|
|
market.import('tools/matrices/bcsstk01.tar.gz', ['bcsstk01/bcsstk01.mtx'])
|
|
.then(function (matrices) {
|
|
// matrix
|
|
const m = matrices[0]
|
|
|
|
// symbolic ordering and analysis, order = 3
|
|
const s = cs_sqr(3, m, false)
|
|
|
|
// full pivoting
|
|
const r = cs_lu(m, s, 0.001)
|
|
|
|
// verify
|
|
approx.deepEqual(cs_permute(m, r.pinv, s.q, true).valueOf(), math.multiply(r.L, r.U).valueOf())
|
|
|
|
// indicate test has completed
|
|
done()
|
|
})
|
|
.fail(function (error) {
|
|
// indicate test has completed
|
|
done(error)
|
|
})
|
|
})
|
|
})
|