Make zero on array of arrays etc apply recursively#51458
Make zero on array of arrays etc apply recursively#51458vtjnash merged 6 commits intoJuliaLang:masterfrom
Conversation
|
|
||
| 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.
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.
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.
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.