-
-
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
Make zero on array of arrays etc apply recursively #51458
Conversation
@@ -1198,7 +1198,8 @@ function copymutable(a::AbstractArray) | |||
end | |||
copymutable(itr) = collect(itr) | |||
|
|||
zero(x::AbstractArray{T}) where {T} = fill!(similar(x, typeof(zero(T))), zero(T)) | |||
zero(x::AbstractArray{T}) where {T<:Number} = fill!(similar(x, typeof(zero(T))), zero(T)) | |||
zero(x::AbstractArray) = map(zero, x) |
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.
Should this use broadcasting instead, as custom sparse arrays might define their own broadcast styles and don't need to iterate over the entire array?
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.
maybe? idk
Custom sparse arrays should probably be implementing their own zero
function outright.
Since they likely have their own opinions about whether or not to store structural zeros etc (the SparseArrays stdlib does this).
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.
It's also a whole lot easier to define a single-argument map(f, ::CustomArray)
than it is to define your own broadcast style. I think the map is fine; it's straightforward and obvious and even enables the laser-focused map(::typeof(zero), ::CustomArray)
.
I do not understand the whitespace failure
Does it want trailing new lines or not? D |
one thing this does not handle is if the original array has |
this functionality was asked for on slack possible for 1.11? |
I don't forsee an issue with this, so let's merge |
I think it is great that this is fixed. Nonetheless, I would like to advertise https://github.com/Jutho/VectorInterface.jl which on his README lists some other potential issues (https://github.com/Jutho/VectorInterface.jl?tab=readme-ov-file#current-situation-and-problems-in-julia). My apologies if this is out of place. |
Closes #38064
I wonder if this breaks things, in practice. It shouldn't. Since old code behavior errored for the cases I am aware of.
As discussed in #38064, this definition is needed to be consistent with our other linear algebra operations,
and with us considering a vector of vectors etc as a vector space.