Skip to content
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
Closed

Multiplication of sparse matrix #450

buharov opened this issue Sep 2, 2015 · 1 comment

Comments

@buharov
Copy link

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants