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
7 changes: 6 additions & 1 deletion src/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1434,7 +1434,12 @@ for (fun, comp, word) in ((:findmin, :(<), "minimum"), (:findmax, :(>), "maximum
# we try to avoid findfirst(iszero, x)
sindex = findfirst(iszero, nzvals) # first stored zero, if any
zindex = findfirst(i -> i < nzinds[i], eachindex(nzinds)) # first non-stored zero
index = isnothing(sindex) ? zindex : min(sindex, zindex)
index = if isnothing(sindex)
# non-stored zero are contiguous and at the end
isnothing(zindex) && last(nzinds) < lastindex(x) ? last(nzinds) + 1 : zindex
else
min(sindex, zindex)
end
return zeroval, index
end
end
Expand Down
18 changes: 18 additions & 0 deletions test/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -898,6 +898,24 @@ end
@test_throws ArgumentError findmin(x)
@test_throws ArgumentError findmax(x)
end

let v = spzeros(3) #Julia #44978
v[1] = 2
@test argmin(v) == 2
@test argmax(v) == 1
v[2] = 2
@test argmin(v) == 3
v[1] = 0
v[2] = 0
v[3] = 2
@test argmin(v) == 1
@test argmax(v) == 3
end

let v = spzeros(3) #Julia #44978
v[3] = 2
@test argmax(v) == 3
end
end

### linalg
Expand Down