-
-
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
Simplify nz2nz_z2z-class sparse unary broadcast (and fix #18974) #19065
Conversation
is the view necessary? |
Not strictly, no. The view preserves the method's existing behavior, but so would
Thanks for reviewing! Best! |
You can have extra space in the nzval array, but there may be places that use nnz and |
The |
be5732e
to
437b041
Compare
…st machinery rather than reimplement it poorly.
437b041
to
3de4e7d
Compare
Switched to the |
broadcast{TTv}(::typeof(abs2), A::SparseMatrixCSC{Complex{TTv}}) = _broadcast_unary_nz2nz_z2z_T(abs2, A, TTv) | ||
broadcast{TTv}(::typeof(abs), A::SparseMatrixCSC{Complex{TTv}}) = _broadcast_unary_nz2nz_z2z_T(abs, A, TTv) | ||
broadcast{TTv<:Integer}(::typeof(abs), A::SparseMatrixCSC{Complex{TTv}}) = _broadcast_unary_nz2nz_z2z_T(abs, A, Float64) | ||
broadcast{TTv<:BigInt}(::typeof(abs), A::SparseMatrixCSC{Complex{TTv}}) = _broadcast_unary_nz2nz_z2z_T(abs, A, BigFloat) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to delete the specialized broadcast
methods for abs
and abs2
on sparse matrices?
(Eventually I think these should go away in favor of a more general mechanism, but that seems like a matter for another PR?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deletion was intentional: The (revised) unspecialized broadcast
method appears to provide the behavior of the specializations for abs
and abs2
(per a little testing at the REPL). More than happy to restore those specializations and nix them elsewhere though if you prefer? Thanks for reviewing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused, was there already a PR that updated the unspecialized broadcast for unary operations on sparse arrays?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the confusion. Clarification: The macro call
@_enumerate_childmethods(_broadcast_unary_nz2nz_z2z,
log1p, expm1, abs, abs2, conj)
defines methods
broadcast(::typeof(abs), A::SparseMatrixCSC) = _broadcast_unary_nz2nz_z2z(abs, A)
broadcast(::typeof(abs2), A::SparseMatrixCSC) = _broadcast_unary_nz2nz_z2z(abs2, A)
which, with _broadcast_unary_nz2nz_z2z
using Bnzval = broadcast(f, A.nzval)
to determine output type on this branch, seem to provide the behavior of the removed methods,
broadcast{TTv}(::typeof(abs2), A::SparseMatrixCSC{Complex{TTv}}) = _broadcast_unary_nz2nz_z2z_T(abs2, A, TTv)
broadcast{TTv}(::typeof(abs), A::SparseMatrixCSC{Complex{TTv}}) = _broadcast_unary_nz2nz_z2z_T(abs, A, TTv)
broadcast{TTv<:Integer}(::typeof(abs), A::SparseMatrixCSC{Complex{TTv}}) = broadcast_unary_nz2nz_z2z_T(abs, A, Float64)
broadcast{TTv<:BigInt}(::typeof(abs), A::SparseMatrixCSC{Complex{TTv}}) = broadcast_unary_nz2nz_z2z_T(abs, A, BigFloat)
Does that clarify? Best!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah good.
PS. Can you file a performance issue with a test case illustrating the slowdown if you omit the |
|
dunno if we have benchmarks for this, but may as well @nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @jrevels |
The possible performance regressions look like noise. |
Yup, they are not things that could have been affected by this. |
Thanks for reviewing / merging! |
…ver a sparse matrix) from closed PR JuliaLang#18975 that was missed in PR JuliaLang#19065.
…ver a sparse matrix) from closed PR JuliaLang#18975 that was missed in PR JuliaLang#19065.
…ver a sparse matrix) from closed PR JuliaLang#18975 that was missed in PR JuliaLang#19065.
…st machinery rather than reimplement it poorly. (JuliaLang#19065)
Following
@stevengj
's suggestion in #18975, this pull request makes nz2nz_z2z-class sparse unary broadcast leverage existing broadcast machinery rather than reimplement it. Also fixes #18974.This implementation is slightly slower than the existing implementation due to the view in
Bnzval = broadcast(f, view(A.nzval, 1:nnz(A)))
; removing the view (Bnzval = broadcast(f, A.nzval)
) eliminates the performance gap.Bnzval = broadcast(f, A.nzval); resize!(Bnzval, nnz(A))
might be a reasonable alternative. For discussion of performance (and particularly the apparent need for forcing function-type specialization), see #18975. Best!