# Multiplication of sparse matrix #450

Closed
opened this Issue Sep 2, 2015 · 1 comment

Projects
None yet
3 participants

### buharov commented Sep 2, 2015

 Hello, I use math.js for multiplication of sparse matrices. For example, I have this matrix and I want multiply it by yourself: [[0.375, 0, 0, 0.125, 0, 0, 0, 0, 0, 0, 0.375, 0.125, 0, 0, 0, 0], [0, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0.5, 0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0.125, 0, 0, 0.375, 0, 0, 0, 0, 0, 0, 0.375, 0.125, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0.41666666666666663, 0, 0.41666666666666663, 0, 0, 0, 0.16666666666666666, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0.41666666666666663, 0, 0.16666666666666666, 0, 0, 0, 0, 0, 0, 0.41666666666666663], [0, 0, 0, 0, 0, 0.2777777777777778, 0, 0.3888888888888889, 0, 0, 0.1111111111111111, 0.2222222222222222, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0.1111111111111111, 0, 0.3888888888888889, 0.2777777777777778, 0, 0, 0, 0, 0, 0.2222222222222222], [0, 0, 0, 0, 0, 0, 0, 0, 0.41666666666666663, 0.41666666666666663, 0, 0, 0, 0, 0, 0.16666666666666666], [0.1875, 0, 0, 0.1875, 0, 0, 0, 0.08333333333333333, 0, 0, 0.3958333333333333, 0.14583333333333331, 0, 0, 0, 0], [0.08333333333333333, 0, 0, 0.08333333333333333, 0, 0.1111111111111111, 0, 0.2222222222222222, 0, 0, 0.19444444444444442, 0.3055555555555555, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0.2777777777777778, 0, 0.2222222222222222, 0.1111111111111111, 0, 0, 0, 0, 0, 0.3888888888888889]] After, I have the sparse matrix, but elements in index array (for one row) are not sorted. And method _getValueIndex works wrong. And I have this: result.toArray()[3][3] == 0,375 math.subset(result, math.index(3, 3)) == 0
Collaborator

### rjbaucells commented Sep 2, 2015

 Yes, you are correct. Some of the algorithms that are optimized for sparse matrices do not guarantee the index array will be sorted at the end. The getValueIndex() operation was developed for the first Sparse Matrix implementation where none of those algorithms existed. There is no other option than assuming a non sorted index array. As always, Sparse Matrices are not good seeking a specific item they excel iterating and performing matrix wise operations. I will provide a fix soon...

Closed