Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/reductions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -724,8 +724,10 @@ function _findr(op, A::AbstractSparseMatrixCSC{Tv}, region) where {Tv}
end
end

_isless_fm(a, b) = b == b && ( a != a || isless(a, b) )
_isgreater_fm(a, b) = b == b && ( a != a || isless(b, a) )
# whether `a` replaces the best value so far `b`, by the test of Base's dense `findmin` and
# `findmax`, so that the result agrees with dense on `NaN`, `missing` and signed zeros
_isless_fm(a, b) = Base.isgreater(b, a)
_isgreater_fm(a, b) = isless(b, a)

findmin(A::AbstractSparseMatrixCSC{Tv}, region::Union{Integer,Tuple{Integer},NTuple{2,Integer}}) where {Tv} =
_findr(_isless_fm, A, region)
Expand Down
4 changes: 4 additions & 0 deletions test/reductions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ end
@test isequal(m(Z, dims=region), m(Array(Z), dims=region))
end
end
# `missing`, which dense ranks above `NaN`
D = Union{Missing,Float64}[NaN missing; 0.0 2.0]
@test isequal(findmin(sparse(D)), findmin(D))
@test isequal(findmax(sparse(D), dims=1), findmax(D, dims=1))
end
for m in [findmax, findmin]
@test_throws ArgumentError m(S, (4, 3))
Expand Down
Loading