-
Notifications
You must be signed in to change notification settings - Fork 53
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
Common abstractions for nonstructural indicies between Dense and Sparse Matrices #50
Comments
Somewhat related is JuliaLang/julia#15648, but I like how this turns the problem on its head: instead of trying to wedge sparse matrices into a generic API, we simply "lift" dense array support onto abstract sparse APIs. This seems far more tractable. Some of this abstract sparse API is already in place for broadcasting; it'd be interesting to see what the performance difference would be were we to emulate sparse APIs for structured and dense matrices instead of converting them to actual AbstractSparseArrays. |
Oh I think this is row I think |
I think what I ment to have is:
|
That API seems to be tied pretty closely to CSC layout. How about an So the following should be reasonably efficient and leave B = zeros(size(A))
for i in each_nonstructural_index(A)
B[LinearIndices(A)[i]] = A[i]
end |
you're right, my proposal would not work for say CRC. Take a look at the example of use in the Chinese Whisphers clustering. (I've not thought too hard if it does or not. I think it does not -- at least not that simply) |
This was my eventual hope with the sparse broadcast infrastructure. Perhaps in a few months... :) |
For what it's worth, I came up with the same idea/need when trying to implement efficient sparse-sparse, dense-sparse, and sparse-dense outer products for my own needs (and tried to make an attempt at something committable in JuliaLang/julia#24980, but that's obviously fallen far behind in all the linear algebra and broadcasting changes since then). So I guess with respect to
I'm in favor of having a portable way of doing CSC-like operations on dense arrays given the fact that CSC-aware algorithms can easily consume dense arrays that way for free (and then a more generic sparse infrastructure can be added later). |
I guess we can have
|
indices
is our abstraction for getting the indices so one can iterate the index of a matrix.It works great for dense matrices.
However, for sparse matrices, it is almost never what you want to do.
You instread only want to iterate the indicies of the nonstructural elements.
(because there are less of them)
That is done using
rowvals
, andnzrange
In a dense matrix one can say that all the elements are nonstructural.
So in a circumstance when you only want to iterate through the nonstructural elements,
you want to iterate through all the elements in a dense matrix.
More generally with a matrix of unknown type, you want to iterate through all the elements.
I thus propose that we should have an abstraction for getting the nonstructural indicies,
which falls back to getting all the indiices,
to make it easier to write code that works efficiently on spare matricies, and also works (as fast as is possible) on other types.
Some thing like
(bikeshed on names pending)
There is also a similar relationship between
nonzeros
(sparse) andvec
(dense/fallback).I was discussing this on slack with @mbauman and @StefanKarpinski the other day,
and wanted to put it on GitHub before it was lost to the ages
The text was updated successfully, but these errors were encountered: