-
-
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
reduce with &/| over empty arrays #31837
Comments
+1 to making them both an error.
feels pretty nonsensical to me. |
On second thoughts, that would be even weirder, since then we would break the distributive law: julia> (true | 0) & 2
0
julia> (true & 2) | (0 & 2)
2 we could resolve that by defining (|)(b::Bool, x::Integer) = b ? reinterpret(typeof(x), typemax(unsigned(x))) : x (i.e. |
Same issue but for mapreduce: #31635 |
Seems fixed?
@simonbyrne can be closed? |
Looks like it. |
As pointed out by @oxinabox, calling
reduce(&, X)
is inconsistent whenX
is an empty collection:this is caused by defining it differently depending on whether the element type is known or not:
julia/base/reduce.jl
Lines 262 to 265 in 93c9ae4
Two possible solutions:
mapreduce_empty_iter
definitions for&
and|
(so both examples above would error), orreduce_empty(::typeof(&), T) = true
andreduce_empty(::typeof(|), T) = false
(so both examples above would returntrue
). The main problem with this is thattrue
isn't strictly the identity element under&
, sincewe could of course resolve this by redefining
but that might be even more complicated
The text was updated successfully, but these errors were encountered: