Description
The Base.mapreduce
based implementation of Base.any
and Base.all
Base.any(A::GPUArray{Bool}) = mapreduce(identity, |, A; init = false)
currently has slightly different semantics from the implementation in Base
, in two ways:
-
The base implementation specifies that
any
andall
are short-circuiting reductions. Their semantics can differ if the predicate applied is side-effecting (noteany(p, itr)
which is implemented in SupportTranspose
andAdjoint
in broadcast better #148 ). Would retaining the difference and clarifying it in documentation be reasonable? -
The base implementation implements three-valued logic if the input iterable contains
missing
values. We might well implement it with something like:
function any(p, itr::GPUArray)
v, m = mapreduce(
x -> begin
b = p(x)
ismissing(b) ? (false, true) : (b::Bool, false)
end,
((v1, m1), (v2, m2)) ->
(v1 || v2, m1 || m2),
itr,
init = (false, false)
)
v || (m ? missing : false)
end
function all(p, itr::GPUArray)
v, m = mapreduce(
x -> begin
b = p(x)
ismissing(b) ? (true, true) : (b::Bool, false)
end,
((v1, m1), (v2, m2)) ->
(v1 && v2, m1 || m2),
itr,
init = (true, false)
)
v && (m ? missing : true)
end
However, currently CuArrays
doesn't handle missing values correctly yet (~~~I'll write an issue there as well~~~ see issue here). I don't know if it makes sense to implement this in GPUArrays
and make CuArrays
fail the test.