Fix extrema(x; dims) for inputs with NaN/missing#43604
Fix extrema(x; dims) for inputs with NaN/missing#43604tkf merged 25 commits intoJuliaLang:masterfrom
extrema(x; dims) for inputs with NaN/missing#43604Conversation
Co-authored-by: Milan Bouchet-Valat <nalimilan@club.fr>
Co-authored-by: Tim Holy <tim.holy@gmail.com>
19ce317 to
66d2a81
Compare
e09c63d to
e015b3e
Compare
|
I like #36265, but it doesn't seem to solve the issue with |
I missed the following: julia/base/multidimensional.jl Lines 1754 to 1762 in 5669d63 So it seems that PR also didn't solve But the julia> @btime extrema($a)
1.222 μs (0 allocations: 0 bytes)
(-3.8158492176948755, 4.389900419602923)
julia> @btime extrema(Float64,$a)
616.500 μs (12298 allocations: 320.52 KiB)
(-3.8158492176948755, 4.389900419602923) |
This optimization gives wrong result, if `NaN` and `missing` both exist. add missing test
Add TODO apply suggestions Update NEWS.md Co-Authored-By: Takafumi Arakaki <takafumi.a@gmail.com> Co-Authored-By: Takafumi Arakaki <29282+tkf@users.noreply.github.com>
|
I followed https://julialang.github.io/BumpStdlibs.jl/dev/usage/ and triggered the bump https://github.com/JuliaLang/BumpStdlibs.jl/runs/4835402987?check_suite_focus=true It looks like the magic worked #43833 |
|
Local test shows no problem $ make -C test SparseArrays
make: Entering directory '/cygdrive/c/Users/MYJ/Documents/GitHub/julia/test'
JULIA test/SparseArrays
Test (Worker) | Time (s) | GC (s) | GC % | Alloc (MB) | RSS (MB)
SparseArrays/sparsevector (4) | started at 2022-01-17T01:38:57.142
SparseArrays/sparse (3) | started at 2022-01-17T01:38:57.262
SparseArrays/higherorderfns (2) | started at 2022-01-17T01:38:57.358
SparseArrays/higherorderfns (2) | 94.64 | 2.66 | 2.8 | 11985.15 | 562.00
SparseArrays/sparsevector (4) | 164.82 | 4.87 | 3.0 | 24421.82 | 876.65
SparseArrays/sparse (3) | 263.28 | 23.08 | 8.8 | 27776.47 | 953.35
Test Summary: | Pass Broken Total Time
Overall | 21792 5 21797 4m26.2s
SUCCESSThe above suggestion will be adopted together with the update of |
Update reducedim.jl
tkf
left a comment
There was a problem hiding this comment.
LGTM! Thanks for addressing a lot of fix requests!
* Define `extrema` using `mapreduce`; support `init` * Fix tests for SparseArrays * API clean and export `extrema!` * Re-implement `reducedim_init` for extrema * Merge `master` to pull in JuliaSparse/SparseArrays.jl#63 * Mark `BigInt` tests as broken Co-authored-by: Milan Bouchet-Valat <nalimilan@club.fr> Co-authored-by: Simeon Schaub <simeondavidschaub99@gmail.com> Co-authored-by: Takafumi Arakaki <aka.tkf@gmail.com> Co-authored-by: Tim Holy <tim.holy@gmail.com>
* Define `extrema` using `mapreduce`; support `init` * Fix tests for SparseArrays * API clean and export `extrema!` * Re-implement `reducedim_init` for extrema * Merge `master` to pull in JuliaSparse/SparseArrays.jl#63 * Mark `BigInt` tests as broken Co-authored-by: Milan Bouchet-Valat <nalimilan@club.fr> Co-authored-by: Simeon Schaub <simeondavidschaub99@gmail.com> Co-authored-by: Takafumi Arakaki <aka.tkf@gmail.com> Co-authored-by: Tim Holy <tim.holy@gmail.com>
* Define `extrema` using `mapreduce`; support `init` * Fix tests for SparseArrays * API clean and export `extrema!` * Re-implement `reducedim_init` for extrema * Merge `master` to pull in JuliaSparse/SparseArrays.jl#63 * Mark `BigInt` tests as broken Co-authored-by: Milan Bouchet-Valat <nalimilan@club.fr> Co-authored-by: Simeon Schaub <simeondavidschaub99@gmail.com> Co-authored-by: Takafumi Arakaki <aka.tkf@gmail.com> Co-authored-by: Tim Holy <tim.holy@gmail.com>
|
Sorry if it's not appropriate to comment on this long-merged PR. In the docstring it says
However, one very important use-case of this PR could be to compute extrema iteratively (e.g. update bounds as new data come in). julia> x = 0:10
0:10
julia> y = -1:5
-1:5
julia> extrema(x)
(0, 10)
julia> extrema(y)
(-1, 5)
julia> extrema(y, init=extrema(x)) == extrema(x ∪ y) == (-1, 10)
trueThe docstring makes me wonder if this is a valid use of the function, because it says Would you be open to a PR that adds my example to the docstring and the tests? |
|
I believe @tkf followed minimum/maximum's docstring, as for And we have the following in However, your use case is valid (and intuitive) under current implemenation. |
|
Great! I've prepared #44819 with updates for |
The original goal of this PR is to Fix #43599. But I find some more cases whose result is inconsistent with the definition.
The behaviour changes are summarized as follows:
extrema(x; dims)now respects-0,0/0.0(i.e.extrema([-0.0;0.0]; dims = 1) == [(-0.0, 0.0)])extrema(x; dims)now respectsNaNextrema(x; dims)can handle inputs withmissingextrema(x; dims)disallows empty reduction likeminimunandmaximum.minimum(x)andmaximum(x)give correct result if the input contains bothNaNandmissingThe last one is used in test so I fix it in this PR by limiting the related optimizaiton to
Floatonly cases. (see 76637c7)