- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
avoid calling zero
in reduce
when possible
#21097
Comments
I think you need to define |
That doesn't fix the issue. In any case, what is expected should be documented. It's not clear to me what a |
Ah, this case ( After looking into it a bit more, I'd summarize this as a quasi-bug in |
Hopefully this will be changed before 1.0. It would be good to have a |
What looks like a bug to me is that |
Now that |
Note that in the present case the issue isn't that the zero isn't of type |
I'm fine with that being a requirement, it just needs to be documented |
For non-empty collections, it would be good if |
zero{T<:Number}(::T)
must now be promotable to T
zero
in reduce
when possible
This now works for plain julia> struct Infinity <: Number end
julia> Base.:+(::Infinity,::Infinity) = Infinity()
julia> reduce(+,[Infinity(),Infinity()])
Infinity()
julia> zero(Infinity())
ERROR: MethodError: no method matching Infinity(::Int64) But not for julia> reduce(+,[Infinity(),Infinity()], dims=1)
ERROR: MethodError: no method matching Infinity(::Int64) |
See discussion https://discourse.julialang.org/t/interface-for-number/2723/5
I recently ran into an issue overriding
zero
for my ownNumber
:The issue appears to be that
zero{T<:Number}(::T)
needs is expected to be convertible toT
.Is this a bug? Otherwise, this should be documented somewhere (e.g., a description of the interface for
Number
)The text was updated successfully, but these errors were encountered: