Skip to content

Commit c6b613c

Browse files
authored
Simplify minimum/maximum on sparse vectors (#42845)
1 parent e6b6bad commit c6b613c

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/sparsevector.jl

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,7 +1372,7 @@ end
13721372

13731373
### Reduction
13741374

1375-
function _sum(f, x::AbstractSparseVector)
1375+
function sum(f, x::AbstractSparseVector)
13761376
n = length(x)
13771377
n > 0 || return sum(f, nonzeros(x)) # return zero() of proper type
13781378
m = nnz(x)
@@ -1381,11 +1381,9 @@ function _sum(f, x::AbstractSparseVector)
13811381
Base.add_sum((n - m) * f(zero(eltype(x))), sum(f, nonzeros(x))))
13821382
end
13831383

1384-
sum(f::Union{Function, Type}, x::AbstractSparseVector) = _sum(f, x) # resolve ambiguity
1385-
sum(f, x::AbstractSparseVector) = _sum(f, x)
13861384
sum(x::AbstractSparseVector) = sum(nonzeros(x))
13871385

1388-
function _maximum(f, x::AbstractSparseVector)
1386+
function maximum(f, x::AbstractSparseVector)
13891387
n = length(x)
13901388
if n == 0
13911389
if f === abs || f === abs2
@@ -1400,11 +1398,9 @@ function _maximum(f, x::AbstractSparseVector)
14001398
max(f(zero(eltype(x))), maximum(f, nonzeros(x))))
14011399
end
14021400

1403-
maximum(f::Union{Function, Type}, x::AbstractSparseVector) = _maximum(f, x) # resolve ambiguity
1404-
maximum(f, x::AbstractSparseVector) = _maximum(f, x)
14051401
maximum(x::AbstractSparseVector) = maximum(identity, x)
14061402

1407-
function _minimum(f, x::AbstractSparseVector)
1403+
function minimum(f, x::AbstractSparseVector)
14081404
n = length(x)
14091405
n > 0 || throw(ArgumentError("minimum over an empty array is not allowed."))
14101406
m = nnz(x)
@@ -1413,8 +1409,6 @@ function _minimum(f, x::AbstractSparseVector)
14131409
min(f(zero(eltype(x))), minimum(f, nonzeros(x))))
14141410
end
14151411

1416-
minimum(f::Union{Function, Type}, x::AbstractSparseVector) = _minimum(f, x) # resolve ambiguity
1417-
minimum(f, x::AbstractSparseVector) = _minimum(f, x)
14181412
minimum(x::AbstractSparseVector) = minimum(identity, x)
14191413

14201414
norm(x::SparseVectorUnion, p::Real=2) = norm(nonzeros(x), p)

0 commit comments

Comments
 (0)