sparse_matrices.js (664B)
1 // load math.js (using node.js) 2 const { identity, multiply, transpose, complex } = require('..') 3 4 // create a sparse matrix 5 console.log('creating a 1000x1000 sparse matrix...') 6 const a = identity(1000, 1000, 'sparse') 7 8 // do operations with a sparse matrix 9 console.log('doing some operations on the sparse matrix...') 10 const b = multiply(a, a) 11 const c = multiply(b, complex(2, 2)) 12 const d = transpose(c) 13 const e = multiply(d, a) 14 console.log('size(e)=', e.size()) 15 16 // we will not print the output, but doing the same operations 17 // with a dense matrix are very slow, try it for yourself. 18 console.log('already done') 19 console.log('now try this with a dense matrix :)')