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

Sparse matrix multiplication? #1241

Closed
huyng opened this issue Feb 22, 2016 · 8 comments
Closed

Sparse matrix multiplication? #1241

huyng opened this issue Feb 22, 2016 · 8 comments
Assignees

Comments

@huyng
Copy link

huyng commented Feb 22, 2016

Hi There,

Is there currently support for sparse matrix multiplication in tensorflow?

I found this post:
http://stackoverflow.com/questions/34030140/is-sparse-tensor-multiplication-implemented-in-tensorflow

But it seems to indicate that one must first convert the sparse matrix into a dense matrix before running the multiplication.

@ebrevdo
Copy link
Contributor

ebrevdo commented Feb 23, 2016

This was recently added. See sparse_ops.sparse_tensor_dense_matmul. The first input should be a 2-D SparseTensor and the second a regular dense tensor (matrix) of the same dtype.

Backprop coming soon (at least into the dense tensor, no backprop into the SparseTensor is currently planned).

@ebrevdo
Copy link
Contributor

ebrevdo commented Feb 23, 2016

I'm closing this issue unless there's missing functionality in the op I mentioned.

@ebrevdo ebrevdo closed this as completed Feb 23, 2016
@ebrevdo
Copy link
Contributor

ebrevdo commented Feb 23, 2016

Use sparse_ops.sparse_tensor_dense_matmul. Does this do what you need?

@huyng
Copy link
Author

huyng commented Feb 23, 2016

Woah awesome! Thanks @ebrevdo . Had no idea this recently made it in. I think this will fit what I need, and will try this out tomorrow.

@tansey
Copy link

tansey commented May 19, 2016

I don't think this is sufficient to close this issue. The stackoverflow post is talking about the general case where you want something like sparse_matmul(sp_a, sp_b).

I currently have that problem: I want to calculate a graph Laplacian given a sparse oriented edge matrix, D. Every row is an edge between two nodes, with -1 for node_i and 1 for node_j; the graph Laplacian is then (D'.D). My graph in this case has something like a million nodes but only about 3 million edges, so the overall sparse D representation has about 6 million entries. This is a piece of cake to calculate using something like scipy's sparse matrix multiplication, but converting it to tensorflow requires creating a dense 1M x 1M matrix.

@ebrevdo
Copy link
Contributor

ebrevdo commented May 19, 2016

Feel free to open a new issue asking specifically for (SparseTensor, SparseTensor) matmul.

@theeluwin
Copy link

I also have similar problem to @tansey.
I know that there is a matrix solver using LU decomposition in Tensorflow, but it's supported to dense matrices only. I can calculate very sparse L, U, Linv, Uinv matrices (as a SparseTensor type) but there's no way to use it..
Using dense version for any of those blows up my memory (I'm working currently working on graphs with several million nodes).

@Corallus-Caninus
Copy link

I also need sparse@sparse matrix multiplication. Even with a_is_sparse and b_is_sparse set to true TF still load n^2 dense matrices into memory.
#3246 (comment)

it seems possible theoretically but I am unsure, are there any updates pertaining to this? Thanks.

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

5 participants