|
| 1 | +import { SparseMatrix } from '../index'; |
| 2 | + |
| 3 | +describe('Sparse Matrix', () => { |
| 4 | + it('getNonZeros', () => { |
| 5 | + let m2 = new SparseMatrix( |
| 6 | + [ |
| 7 | + [0, 0, 0, 0, 0, 0], |
| 8 | + [1, 0, 0, 2, 1, 1], |
| 9 | + [0, 3, 0, 0, 5, 5], |
| 10 | + [0, 0, 0, 0, 0, 0], |
| 11 | + [1, 0, 0, 1, 9, 9], |
| 12 | + ], |
| 13 | + { initialCapacity: 12 }, |
| 14 | + ); |
| 15 | + |
| 16 | + // Default (coordinate list) |
| 17 | + expect(m2.getNonZeros()).toEqual({ |
| 18 | + rows: Float64Array.from([4, 1, 4, 1, 1, 1, 4, 2, 4, 2, 2]), |
| 19 | + columns: Float64Array.from([0, 0, 3, 3, 4, 5, 5, 1, 4, 4, 5]), |
| 20 | + values: Float64Array.from([1, 1, 1, 2, 1, 1, 9, 3, 9, 5, 5]), |
| 21 | + }); |
| 22 | + |
| 23 | + // CSR format |
| 24 | + expect(m2.getNonZeros({ format: 'csr' })).toEqual({ |
| 25 | + rows: Float64Array.from([0, 0, 4, 7, 7, 11]), |
| 26 | + columns: Float64Array.from([0, 3, 4, 5, 1, 4, 5, 0, 3, 4, 5]), |
| 27 | + values: Float64Array.from([1, 2, 1, 1, 3, 5, 5, 1, 1, 9, 9]), |
| 28 | + }); |
| 29 | + |
| 30 | + //CSC format |
| 31 | + expect(m2.getNonZeros({ format: 'csc' })).toEqual({ |
| 32 | + rows: Float64Array.from([1, 4, 2, 1, 4, 1, 2, 4, 1, 2, 4]), |
| 33 | + columns: Float64Array.from([0, 2, 3, 3, 5, 8, 11]), |
| 34 | + values: Float64Array.from([1, 1, 3, 2, 1, 1, 5, 9, 1, 5, 9]), |
| 35 | + }); |
| 36 | + }); |
| 37 | +}); |
0 commit comments