

Sparse matrix multiplication using SQL - mindprince
http://notes.mindprince.in/2013/06/07/sparse-matrix-multiplication-using-sql.html

======
platz
Sparse matrix multiplication using SQL was also a homework assignment in the
latest coursera course "Introduction to Data Science" by Bill Howe

------
thauck
Correct me if I'm wrong, but the only reason the matrix being sparse is
mentioned is because the author stuck a bunch of 0s in the matrices... this
solution should work regardless of the sparsity.

~~~
siddboots
Not sure if I completely understand what you mean, but the benefit of a sparse
matrix is that zero-valued elements are made implicit by the absence of that
(row, column) relation in the database. The drawback is that you need to store
a (row, column) for every non-zero-value.

It would be wasteful to use this approach for non-sparse matrices, but it
would still "work".

------
Irishsteve
Any idea how fast this is compared to java / python ?

~~~
siddboots
Depends on the application really. The operation itself would surely be slower
than a specialised mmul, but there can be big advantages to keeping it inside
your database if you can phrase most of your problems in terms of simple
linear algebra operations.

In other words, numpy is damn-fine with matrices, but if you can replace
DBMS->network->ORM->numpy->ORM->network->DBMS with just some SQL, it's pretty
clear which will be faster.

On the other hand, if your data isn't already in an RDBMS in matrix-like
tables, there is little point in moving it to one just so you can use tricks
like the one mentioned in this article.

