-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Boolean operators don't have specialized versions for sparse matrices #13024
Comments
EDIT: disregard, issue was updated I tried function other(a::SparseMatrixCSC, b::SparseMatrixCSC)
(m,n) = size(a)
resultmx = spzeros(Bool,m,n)
for c = 1:n
for r in _column(a,n)
# info("row $r, col $c")
resultmx[r,c] = a[r,c] & !b[r,c]
end
end
return resultmx
end and got
|
This is on
|
@IainNZ ah - that seems to imply that the problem with & is when it's used with sparse matrices, not with bools. |
julia> @which (&)(sprand(5,5,0.1), sprand(5,5,0.1))
&{S,T}(A::AbstractArray{S,N}, B::AbstractArray{T,N}) at arraymath.jl:96 |
so it looks like there's no method on |
Same as in #12118, can probably just add julia/base/sparse/sparsematrix.jl Line 887 in bffe239
& is zero-preserving (result is zero if either input is zero) slightly fancier things could be done for it, but we don't have distinct scalar & vs broadcasting .& like we do for most other operators so probably not worth dealing with that right now.
edit: actually I think |
Yes, this is true for much of the sparse matrix functionality, simply because no one has had the time or use case to warrant implementing them. PR welcomed although it probably will go into 0.5. It might be as simple as extending this loop to include |
There's actually a bug there,
May as well fix both issues now. If anyone were relying on the present behavior they probably would have complained and asked to change it already. |
@tkelman - Sorry - it's late. Why is that a bug? (is it because it's being converted to Int, when |
I think because |
I opened up #13029 to track the performance of |
My preference is to have these things go to 0.5. However, it is not a problem to get them into 0.4.x if someone really needs it (perhaps @sbromberger does), since this will not break the 0.4 API. |
I'm happy to work on a PR. Obviously it won't go into -release. I've been looking at the underlying code and it will take time for me to understand it fully. :) Edit to add: I do really need this functionality, actually. It puzzles me that nobody's brought this issue up before: are sparse matrices not widely used? |
Sparse matrices are increasingly getting widely used. :-) |
Sparse matrices of Float64s with Int64 indices get used extensively, but anything else, not as often. Hence #12984 and this |
I'll open a PR that fixes this today. Won't be hard, and no reason to wait on fixing this since the current behavior is slow and incorrect. |
also fix eltype promotion in sparse max and min
Thanks. Glad to see it uncovered a few things despite the bugs in my code that prompted the issue. |
Thank you (again) very much - this results in orders of magnitude more efficient random graph generation. |
Ref https://groups.google.com/d/msg/julia-users/bo6YMXzWPdA/jKEWz_rfAQAJ
The following code runs in ~15 seconds:
Replacing
@time z = a ⊅ b
with@time z = a & b
results in a > 10 minute execution (I stopped it after 10 minutes or so).Interestingly enough, substituting the ⊅-equivalent
resultmx[r,c] = !b[r,c]
within the function itself also causes poor performance relative to the above code.The text was updated successfully, but these errors were encountered: