Skip to content

Commit 3f9b6fb

Browse files
authored
fix findmin/findmax with nan (#722)
Closes #714
1 parent 85f7b74 commit 3f9b6fb

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

src/sparsevector.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1704,7 +1704,7 @@ for (fun, comp, word) in ((:findmin, :(<), "minimum"), (:findmax, :(>), "maximum
17041704
m == n && return val, index
17051705
nzinds = nonzeroinds(x)
17061706
zeroval = f(zero(T))
1707-
$comp(val, zeroval) && return val, nzinds[index]
1707+
($comp(val, zeroval) || isnan(val)) && return val, nzinds[index]
17081708
# we need to find the first zero, which could be stored or implicit
17091709
# we try to avoid findfirst(iszero, x)
17101710
sindex = findfirst(_iszero, nzvals) # first stored zero, if any

test/sparsevector.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,11 @@ end
10521052
@test all(!iszero, v)
10531053
@test !any(iszero, v)
10541054
end
1055+
1056+
let v = sparse([0, NaN]) #issue #714
1057+
@test findmin(v) === (NaN, 2)
1058+
@test findmax(v) === (NaN, 2)
1059+
end
10551060
end
10561061

10571062
### linalg

0 commit comments

Comments
 (0)