From 8cf1c266fdb81f9cffba34ac4884182682ccc0bd Mon Sep 17 00:00:00 2001 From: N5N3 <2642243996@qq.com> Date: Sat, 29 Jan 2022 22:25:54 +0800 Subject: [PATCH] Remove the temporary skip. (#74) --- src/sparsematrix.jl | 6 ++---- test/higherorderfns.jl | 48 ++++++++++++++++-------------------------- 2 files changed, 20 insertions(+), 34 deletions(-) diff --git a/src/sparsematrix.jl b/src/sparsematrix.jl index f1d7a792..e4547cc7 100644 --- a/src/sparsematrix.jl +++ b/src/sparsematrix.jl @@ -1921,10 +1921,8 @@ _mapreducezeros(f, op::Union{typeof(Base.mul_prod),typeof(*)},::Type{T}, nzeros: nzeros == 0 ? op(one(v0), v0) : op(f(zero(T))^nzeros, v0) _mapreducezeros(f, op::Union{typeof(min),typeof(max)}, ::Type{T}, nzeros::Integer, v0) where {T} = nzeros == 0 ? v0 : op(v0, f(zero(T))) -if isdefined(Base, :_extrema_rf) - _mapreducezeros(f::Base.ExtremaMap, op::typeof(Base._extrema_rf), ::Type{T}, nzeros::Integer, v0) where {T} = - nzeros == 0 ? v0 : op(v0, f(zero(T))) -end +_mapreducezeros(f::Base.ExtremaMap, op::typeof(Base._extrema_rf), ::Type{T}, nzeros::Integer, v0) where {T} = + nzeros == 0 ? v0 : op(v0, f(zero(T))) function Base._mapreduce(f, op::typeof(*), ::Base.IndexCartesian, A::AbstractSparseMatrixCSC{T}) where T nzeros = widelength(A)-nnz(A) diff --git a/test/higherorderfns.jl b/test/higherorderfns.jl index 6fb59a61..ef49eefa 100644 --- a/test/higherorderfns.jl +++ b/test/higherorderfns.jl @@ -709,11 +709,8 @@ end @test extrema(f, x) == extrema(f, y) @test extrema(spzeros(n, n)) == (0.0, 0.0) @test extrema(spzeros(n)) == (0.0, 0.0) - # TODO: Remove the temporary skip once https://github.com/JuliaLang/julia/pull/43604 is merged - if isdefined(Base, :_extrema_rf) - @test_throws "reducing over an empty" extrema(spzeros(0, 0)) - @test_throws "reducing over an empty" extrema(spzeros(0)) - end + @test_throws "reducing over an empty" extrema(spzeros(0, 0)) + @test_throws "reducing over an empty" extrema(spzeros(0)) @test extrema(sparse(ones(n, n))) == (1.0, 1.0) @test extrema(sparse(ones(n))) == (1.0, 1.0) @test extrema(A; dims=:) == extrema(B; dims=:) @@ -721,39 +718,30 @@ end @test extrema(A; dims=2) == extrema(B; dims=2) @test extrema(A; dims=(1,2)) == extrema(B; dims=(1,2)) @test extrema(f, A; dims=1) == extrema(f, B; dims=1) - # TODO: Remove the temporary skip once https://github.com/JuliaLang/julia/pull/43604 is merged - if isdefined(Base, :_extrema_rf) - @test_throws "reducing over an empty" extrema(sparse(C); dims=1) == extrema(C; dims=1) - end + @test_throws "reducing over an empty" extrema(sparse(C); dims=1) == extrema(C; dims=1) @test extrema(A; dims=[]) == extrema(B; dims=[]) @test extrema(x; dims=:) == extrema(y; dims=:) @test extrema(x; dims=1) == extrema(y; dims=1) @test extrema(f, x; dims=1) == extrema(f, y; dims=1) - # TODO: Remove the temporary skip once https://github.com/JuliaLang/julia/pull/43604 is merged - if isdefined(Base, :_extrema_rf) - @test_throws "reducing over an empty" extrema(sparse(z); dims=1) - end + @test_throws "reducing over an empty" extrema(sparse(z); dims=1) @test extrema(x; dims=[]) == extrema(y; dims=[]) end -# TODO: Remove the temporary skip once https://github.com/JuliaLang/julia/pull/43604 is merged -if isdefined(Base, :_extrema_rf) - function test_extrema(a; dims_test = ((), 1, 2, (1,2), 3)) - for dims in dims_test - vext = extrema(a; dims) - vmin, vmax = minimum(a; dims), maximum(a; dims) - @test all(x -> isequal(x[1], x[2:3]), zip(vext,vmin,vmax)) - end +function test_extrema(a; dims_test = ((), 1, 2, (1,2), 3)) + for dims in dims_test + vext = extrema(a; dims) + vmin, vmax = minimum(a; dims), maximum(a; dims) + @test all(x -> isequal(x[1], x[2:3]), zip(vext,vmin,vmax)) end - @testset "NaN test for sparse extrema" begin - for sz = (3, 10, 100) - A = sprand(sz, sz, 0.3) - A[rand(1:sz^2,sz)] .= NaN - test_extrema(A) - A = sprand(sz*sz, 0.3) - A[rand(1:sz^2,sz)] .= NaN - test_extrema(A; dims_test = ((), 1, 2)) - end +end +@testset "NaN test for sparse extrema" begin + for sz = (3, 10, 100) + A = sprand(sz, sz, 0.3) + A[rand(1:sz^2,sz)] .= NaN + test_extrema(A) + A = sprand(sz*sz, 0.3) + A[rand(1:sz^2,sz)] .= NaN + test_extrema(A; dims_test = ((), 1, 2)) end end