-
Notifications
You must be signed in to change notification settings - Fork 56
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
Feature request - specialized arithmetic for views of sparse matrices #56
Comments
There's a framework underway for this kind of thing in https://github.com/timholy/ArrayIteration.jl, but that can't be very efficient until we have JuliaLang/julia#12205 (it creates about a zillion array wrappers, sometimes of fairly small regions, and it would be expensive to heap-allocate them all). |
That sounds amazing, thanks a lot for the response. |
|
I've got some functions for views into sparse matrices (currently here https://github.com/EcoJulia/SpatialEcology.jl/blob/master/src/Sparse_matrixfunctions.jl ), not mostly coded by me, though, but based on answers from @perrutquist and @getzdan . Would it be interesting for Base to have more functionality for (views into) sparse matrices? alternatively: |
I think we should have better support for this is base. At least |
As an addition to this, using SparseArrays
c = sprand(Bool,6000,18000, 0.01)
d = view(c, 1:6000, rand(1:18000, 1800))
copy(d);
@time copy(d)
2.626470 seconds (12 allocations: 18.557 MiB, 0.42% gc time) 2.6 seconds to generate a 6000x1800 sized matrix, a very realistically sized array seems really excessive. I saw recent PRs (JuliaLang/julia#30531) made progress on copying Sparse Vectors, but this does not seem to help this case. |
This comment has been minimized.
This comment has been minimized.
In terms of the copy issue described above, defining simply mycopy(A::SubArray{R,S,T}) where R where S where T <: SparseMatrixCSC = d.parent[d.indices...] makes it possible to do using SparseArrays
c = sprand(Bool,6000,18000, 0.01);
d = view(c, 1:6000, rand(1:18000, 1800));
c1 = copy(d);
@time copy(d)
2.456731 seconds (12 allocations: 18.556 MiB)
c2 = mycopy(d);
@time mycopy(d)
0.000564 seconds (12 allocations: 962.156 KiB)
c2 == c1
true Which is 3000 times faster (at least with |
Not naive at all. I could even get behind doing that for all |
I posted this originally as a question here https://discourse.julialang.org/t/slow-arithmetic-on-views-of-sparse-matrices/3644 and got some useful feedback. It seems though that this functionality could be built into julia proper.
Arithmetic on views of sparse matrices fall back on general methods and are thus slow. Here is an example:
Specialized functions for these operations should fix this.
This appears to be related to (but not identical to?) JuliaLang/julia#13438
The text was updated successfully, but these errors were encountered: