Ask Your Question
1

Multiplying sparse matrices

asked 2018-10-18 20:49:55 +0100

PW gravatar image

updated 2023-01-09 23:59:47 +0100

tmonteil gravatar image

Can Sage multiply sparse matrices? If so, does it require some special syntax? I've been trying to run the following code:

M = Matrix(QQ, 1000001, 1000001, {(3,2): 27, (2,98): 71})
M2 = M*M

and it hasn't been working. If M is being converted to a dense matrix for multiplication then of course I wouldn't expect this to run. But it shouldn't be hard to do as sparse matrices, right?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
1

answered 2018-10-18 21:13:44 +0100

nbruin gravatar image

I think the relevant code is here: https://github.com/sagemath/sage/blob...

The algorithm does take into account the sparse nature, but it does have a triple-nested for-loop, enumerating all the indices. It may be that for moderate sparsity this is faster than just enumerating the non-zero entries, but especially for your example it's pretty clear a much more efficient implementation is possible.

edit flag offensive delete link more
1

answered 2018-10-23 12:35:12 +0100

tmonteil gravatar image

Thanks for reporting, this is now trac ticket 26532.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-10-18 20:49:55 +0100

Seen: 422 times

Last updated: Oct 23 '18