JuliaGPU / JuliaGPU/GPUArrays.jl
`Base.any` has different semantics from base implementation
- Dominant language
- Julia
- Stars
- 450
- Forks
- 104
- Avg merge
- 1d 4h
- Merged PRs (30d)
- 10
Description
The `Base.mapreduce` based [implementation](https://github.com/JuliaGPU/GPUArrays.jl/blob/712790f27c7c3110b02e446484e8e25e32222f97/src/mapreduce.jl#L6) of `Base.any` and `Base.all`
> ```julia
> Base.any(A::GPUArray{Bool}) = mapreduce(identity, |, A; init = false)
> ```
currently has slightly different semantics [from the implementation in `Base`](https://github.com/JuliaLang/julia/blob/09bfc83f724874af2d7eefe925436848c7b1038f/base/reduce.jl#L503), in two ways:
1. The base implementation specifies that `any` and `all` are short-circuiting reductions. Their semantics can differ if the predicate applied is side-effecting (note `any(p, itr)` which is implemented in #148 ). Would retaining the difference and clarifying it in documentation be reasonable?
2. The base implementation implements three-valued logic if the input iterable contains `missing` values. We might well implement it with something like:
```julia
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](https://github.com/JuliaGPU/CuArrays.jl/issues/125)). I don't know if it makes sense to implement this in `GPUArrays` and make `CuArrays` fail the test.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.