New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiplication of sparse matrix #450

Closed
buharov opened this Issue Sep 2, 2015 · 1 comment

Comments

Projects
None yet
3 participants
@buharov

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
@rjbaucells

This comment has been minimized.

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...

rjbaucells added a commit to rjbaucells/mathjs that referenced this issue Sep 3, 2015

@josdejong josdejong closed this Oct 29, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment