Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 553531b

Browse files
authored
Merge pull request josdejong#1093 from harrysarson/sep-tests
Separate tests that depend on node
2 parents 0abdfbe + 4e56faa commit 553531b

8 files changed

Lines changed: 285 additions & 215 deletions

File tree

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
var approx = require('../../../../tools/approx'),
2+
math = require('../../../../index'),
3+
market = require('../../../../tools/matrixmarket');
4+
5+
describe('slu - matrix market', function () {
6+
it('should decompose matrix, 48 x 48, natural ordering (order=0), full pivoting, matrix market', function (done) {
7+
// import matrix
8+
market.import('tools/matrices/bcsstk01.tar.gz', ['bcsstk01/bcsstk01.mtx'])
9+
.then(function (matrices) {
10+
// matrix
11+
var m = matrices[0];
12+
13+
// full pivoting
14+
var r = math.slu(m, 0, 0.001);
15+
16+
// verify M[p,q]=L*U
17+
approx.deepEqual(_permute(m, r.p, r.q).valueOf(), math.multiply(r.L, r.U).valueOf());
18+
19+
// indicate test has completed
20+
done();
21+
})
22+
.fail(function (error) {
23+
// indicate test has completed
24+
done(error);
25+
});
26+
});
27+
28+
it('should decompose matrix, 48 x 48, amd(A+A\') (order=1), full pivoting, matrix market', function (done) {
29+
// import matrix
30+
market.import('tools/matrices/bcsstk01.tar.gz', ['bcsstk01/bcsstk01.mtx'])
31+
.then(function (matrices) {
32+
// matrix
33+
var m = matrices[0];
34+
35+
// full pivoting
36+
var r = math.slu(m, 1, 0.001);
37+
38+
// verify M[p,q]=L*U
39+
approx.deepEqual(_permute(m, r.p, r.q).valueOf(), math.multiply(r.L, r.U).valueOf());
40+
41+
// indicate test has completed
42+
done();
43+
})
44+
.fail(function (error) {
45+
// indicate test has completed
46+
done(error);
47+
});
48+
});
49+
50+
it('should decompose matrix, 48 x 48, amd(A\'*A) (order=2), full pivoting, matrix market', function (done) {
51+
// import matrix
52+
market.import('tools/matrices/bcsstk01.tar.gz', ['bcsstk01/bcsstk01.mtx'])
53+
.then(function (matrices) {
54+
// matrix
55+
var m = matrices[0];
56+
57+
// full pivoting
58+
var r = math.slu(m, 2, 0.001);
59+
60+
// verify M[p,q]=L*U
61+
approx.deepEqual(_permute(m, r.p, r.q).valueOf(), math.multiply(r.L, r.U).valueOf());
62+
63+
// indicate test has completed
64+
done();
65+
})
66+
.fail(function (error) {
67+
// indicate test has completed
68+
done(error);
69+
});
70+
});
71+
72+
it('should decompose matrix, 48 x 48, amd(A\'*A) (order=3), full pivoting, matrix market', function (done) {
73+
// import matrix
74+
market.import('tools/matrices/bcsstk01.tar.gz', ['bcsstk01/bcsstk01.mtx'])
75+
.then(function (matrices) {
76+
// matrix
77+
var m = matrices[0];
78+
79+
// full pivoting
80+
var r = math.slu(m, 3, 0.001);
81+
82+
// verify M[p,q]=L*U
83+
approx.deepEqual(_permute(m, r.p, r.q).valueOf(), math.multiply(r.L, r.U).valueOf());
84+
85+
// indicate test has completed
86+
done();
87+
})
88+
.fail(function (error) {
89+
// indicate test has completed
90+
done(error);
91+
});
92+
});
93+
94+
/**
95+
* C = A(p,q) where p is the row permutation vector and q the column permutation vector.
96+
*/
97+
var _permute = function (A, pinv, q) {
98+
// matrix arrays
99+
var values = A._values;
100+
var index = A._index;
101+
var ptr = A._ptr;
102+
var size = A._size;
103+
// columns
104+
var n = size[1];
105+
// c arrays
106+
var cvalues = [];
107+
var cindex = [];
108+
var cptr = [];
109+
// loop columns
110+
for (var k = 0 ; k < n ; k++) {
111+
cptr[k] = cindex.length;
112+
// column in C
113+
var j = q ? (q[k]) : k;
114+
// values in column j
115+
for (var t = ptr[j]; t < ptr[j + 1]; t++) {
116+
cvalues.push(values[t]);
117+
cindex.push(pinv ? (pinv[index[t]]) : index[t]);
118+
}
119+
}
120+
cptr[n] = cindex.length;
121+
// return matrix
122+
return new math.type.SparseMatrix({
123+
values: cvalues,
124+
index: cindex,
125+
ptr: cptr,
126+
size: size,
127+
datatype: A._datatype
128+
});
129+
};
130+
});

test/function/algebra/sparse/cs_amd.test.js renamed to node-test/function/alegbra/sparse/cs_amd.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var assert = require('assert');
22
var approx = require('../../../../tools/approx');
33
var market = require('../../../../tools/matrixmarket');
4-
var math = require('../../../../index');
4+
var math = require('../../../../index').create();
55
math.import(require('../../../../lib/function/algebra/sparse/cs_amd'));
66

77
var cs_amd = math.sparse.cs_amd;
@@ -95,4 +95,4 @@ describe('cs_amd', function () {
9595
done(error);
9696
});
9797
});
98-
});
98+
});
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
var assert = require('assert');
2+
var approx = require('../../../../tools/approx');
3+
var market = require('../../../../tools/matrixmarket');
4+
var math = require('../../../../index').create();
5+
6+
math.import(require('../../../../lib/function/algebra/sparse/cs_permute'));
7+
math.import(require('../../../../lib/function/algebra/sparse/cs_lu'));
8+
math.import(require('../../../../lib/function/algebra/sparse/cs_sqr'));
9+
10+
var cs_permute = math.sparse.cs_permute;
11+
var cs_lu = math.sparse.cs_lu;
12+
var cs_sqr = math.sparse.cs_sqr;
13+
14+
describe('cs_lu', function () {
15+
16+
it('should decompose matrix, 48 x 48, natural ordering (order=0), full pivoting, matrix market', function (done) {
17+
// import matrix
18+
market.import('tools/matrices/bcsstk01.tar.gz', ['bcsstk01/bcsstk01.mtx'])
19+
.then(function (matrices) {
20+
// matrix
21+
var m = matrices[0];
22+
23+
// symbolic ordering and analysis, order = 0
24+
var s = cs_sqr(0, m, false);
25+
26+
// full pivoting
27+
var r = cs_lu(m, s, 0.001);
28+
29+
// verify
30+
approx.deepEqual(cs_permute(m, r.pinv, s.q, true).valueOf(), math.multiply(r.L, r.U).valueOf());
31+
32+
// indicate test has completed
33+
done();
34+
})
35+
.fail(function (error) {
36+
// indicate test has completed
37+
done(error);
38+
});
39+
});
40+
41+
it('should decompose matrix, 48 x 48, amd(A+A\') (order=1), full pivoting, matrix market', function (done) {
42+
// import matrix
43+
market.import('tools/matrices/bcsstk01.tar.gz', ['bcsstk01/bcsstk01.mtx'])
44+
.then(function (matrices) {
45+
// matrix
46+
var m = matrices[0];
47+
48+
// symbolic ordering and analysis, order = 1
49+
var s = cs_sqr(1, m, false);
50+
51+
// full pivoting
52+
var r = cs_lu(m, s, 0.001);
53+
54+
// verify
55+
approx.deepEqual(cs_permute(m, r.pinv, s.q, true).valueOf(), math.multiply(r.L, r.U).valueOf());
56+
57+
// indicate test has completed
58+
done();
59+
})
60+
.fail(function (error) {
61+
// indicate test has completed
62+
done(error);
63+
});
64+
});
65+
66+
it('should decompose matrix, 48 x 48, amd(A\'*A) (order=2), full pivoting, matrix market', function (done) {
67+
// import matrix
68+
market.import('tools/matrices/bcsstk01.tar.gz', ['bcsstk01/bcsstk01.mtx'])
69+
.then(function (matrices) {
70+
// matrix
71+
var m = matrices[0];
72+
73+
// symbolic ordering and analysis, order = 2
74+
var s = cs_sqr(2, m, false);
75+
76+
// full pivoting
77+
var r = cs_lu(m, s, 0.001);
78+
79+
// verify
80+
approx.deepEqual(cs_permute(m, r.pinv, s.q, true).valueOf(), math.multiply(r.L, r.U).valueOf());
81+
82+
// indicate test has completed
83+
done();
84+
})
85+
.fail(function (error) {
86+
// indicate test has completed
87+
done(error);
88+
});
89+
});
90+
91+
it('should decompose matrix, 48 x 48, amd(A\'*A) (order=3), full pivoting, matrix market', function (done) {
92+
// import matrix
93+
market.import('tools/matrices/bcsstk01.tar.gz', ['bcsstk01/bcsstk01.mtx'])
94+
.then(function (matrices) {
95+
// matrix
96+
var m = matrices[0];
97+
98+
// symbolic ordering and analysis, order = 3
99+
var s = cs_sqr(3, m, false);
100+
101+
// full pivoting
102+
var r = cs_lu(m, s, 0.001);
103+
104+
// verify
105+
approx.deepEqual(cs_permute(m, r.pinv, s.q, true).valueOf(), math.multiply(r.L, r.U).valueOf());
106+
107+
// indicate test has completed
108+
done();
109+
})
110+
.fail(function (error) {
111+
// indicate test has completed
112+
done(error);
113+
});
114+
});
115+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// test multiply
2+
var assert = require('assert'),
3+
math = require('../../../index'),
4+
approx = require('../../../tools/approx'),
5+
market = require('../../../tools/matrixmarket'),
6+
multiply = math.multiply,
7+
divide = math.divide,
8+
matrix = math.matrix,
9+
complex = math.complex,
10+
bignumber = math.bignumber,
11+
i = math.i,
12+
unit = math.unit;
13+
14+
describe('multiply', function() {
15+
describe('Matrix Market', function () {
16+
17+
it('should multiply matrix x matrix 1220 x 1220, Matrix Market, sparse x sparse', function (done) {
18+
// import matrix
19+
market.import('tools/matrices/fpga_dcop_01.tar.gz', ['fpga_dcop_01/fpga_dcop_01.mtx'])
20+
.then(function (matrices) {
21+
// matrix
22+
var m = matrices[0];
23+
// multiply matrices, used to compare performance in different implementations
24+
math.multiply(m, m);
25+
// indicate test has completed
26+
done();
27+
})
28+
.fail(function (error) {
29+
// indicate test has completed
30+
done(error);
31+
});
32+
});
33+
});
34+
35+
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@
134134
"build": "gulp",
135135
"watch": "gulp watch",
136136
"docs": "gulp docs",
137-
"test": "mocha test --recursive",
137+
"test": "mocha test node-test --recursive",
138138
"coverage": "istanbul cover _mocha -- test --recursive; echo \"\nCoverage report is available at ./coverage/lcov-report/index.html\"",
139139
"prepublishOnly": "npm run build && npm test"
140140
},

0 commit comments

Comments
 (0)