-
-
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
Handle zero on arrays of unions of number types and missings #53602
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1218,6 +1218,7 @@ end | |
copymutable(itr) = collect(itr) | ||
|
||
zero(x::AbstractArray{T}) where {T<:Number} = fill!(similar(x, typeof(zero(T))), zero(T)) | ||
zero(x::AbstractArray{S}) where {T<:Number, S<:Union{Missing, T}} = fill!(similar(x, typeof(zero(S))), zero(S)) | ||
vtjnash marked this conversation as resolved.
Show resolved
Hide resolved
|
||
zero(x::AbstractArray) = map(zero, x) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could we make this a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could. |
||
|
||
## iteration support for arrays by iterating over `eachindex` in the array ## | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1972,6 +1972,16 @@ end | |
|
||
@test zero([[2,2], [3,3,3]]) isa Vector{Vector{Int}} | ||
@test zero([[2,2], [3,3,3]]) == [[0,0], [0, 0, 0]] | ||
|
||
|
||
@test zero(Union{Float64, Missing}[missing]) == [0.0] | ||
struct CustomNumber <: Number | ||
val::Float64 | ||
end | ||
Base.zero(::Type{CustomNumber}) = CustomNumber(0.0) | ||
@test zero([CustomNumber(5.0)]) == [CustomNumber(0.0)] | ||
@test zero(Union{CustomNumber, Missing}[missing]) == [CustomNumber(0.0)] | ||
Comment on lines
+1978
to
+1983
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. arguably we do not need this, since the error is replicated with just the |
||
@test zero(Vector{Union{CustomNumber, Missing}}(undef, 1)) == [CustomNumber(0.0)] | ||
end | ||
|
||
@testset "`_prechecked_iterate` optimization" begin | ||
|
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.
Arguably this should be:
which would mean that you continue to get back a type which can be mutated to hold
missing
s.However that is not the behavour of 1.10.
So I didn't do that.