Skip to content

Commit

Permalink
Deprecate sumabs, sumabs2, minabs, maxabs
Browse files Browse the repository at this point in the history
  • Loading branch information
ararslan committed Dec 15, 2016
1 parent 38ff38c commit 937c970
Show file tree
Hide file tree
Showing 13 changed files with 76 additions and 188 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ Deprecated or removed

* `cummin` and `cummax` have been deprecated in favor of `accumulate`.

* `sumabs` and `sumabs2` have been deprecated in favor of `sum(abs, x)` and `sum(abs2, x)`, respectively.
`maxabs` and `minabs` have similarly been deprecated in favor of `maximum(abs, x)` and `minimum(abs, x)`.
Likewise for the in-place counterparts of these functions ([#19598]).

Julia v0.5.0 Release Notes
==========================

Expand Down
18 changes: 18 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1134,4 +1134,22 @@ end)
@deprecate cummin(A, dim=1) accumulate(min, A, dim=1)
@deprecate cummax(A, dim=1) accumulate(max, A, dim=1)

# #19598
@deprecate sumabs(x) sum(abs, x)
@deprecate sumabs(A, region) sum(abs, A, region)
@deprecate sumabs2(x) sum(abs2, x)
@deprecate sumabs2(A, region) sum(abs2, A, region)
@deprecate minabs(x) minimum(abs, x)
@deprecate minabs(A, region) minimum(abs, A, region)
@deprecate maxabs(x) maximum(abs, x)
@deprecate maxabs(A, region) maximum(abs, A, region)
@deprecate sumabs!(r, A) sum!(abs, r, A)
@deprecate sumabs!(r, A; init=false) sum!(abs, r, A; init=false)
@deprecate sumabs2!(r, A) sum!(abs2, r, A)
@deprecate sumabs2!(r, A; init=false) sum!(abs2, r, A; init=false)
@deprecate minabs!(r, A) minimum!(abs, r, A)
@deprecate minabs!(r, A; init=false) minimum!(abs, r, A; init=false)
@deprecate maxabs!(r, A) maximum!(abs, r, A)
@deprecate maxabs!(r, A; init=false) maximum!(abs, r, A; init=false)

# End deprecations scheduled for 0.6
58 changes: 0 additions & 58 deletions base/docs/helpdb/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,6 @@ Cumulative minimum along a dimension. The dimension defaults to 1.
"""
cummin

"""
minabs!(r, A)
Compute the minimum absolute values over the singleton dimensions of `r`, and write values to `r`.
"""
minabs!

"""
eigfact!(A, [B])
Expand Down Expand Up @@ -530,13 +523,6 @@ Convert `y` to the type of `x` (`convert(typeof(x), y)`).
"""
oftype

"""
maxabs!(r, A)
Compute the maximum absolute values over the singleton dimensions of `r`, and write values to `r`.
"""
maxabs!

"""
isfinite(f) -> Bool
Expand Down Expand Up @@ -727,13 +713,6 @@ Show every part of the representation of a value.
"""
dump

"""
sumabs(A, dims)
Sum absolute values of elements of an array over the given dimensions.
"""
sumabs(A, dims)

"""
consume(task, values...)
Expand Down Expand Up @@ -1308,13 +1287,6 @@ Compute the inverse error complementary function of a real `x`, defined by
"""
erfcinv

"""
minabs(A, dims)
Compute the minimum absolute values over given dimensions.
"""
minabs(A, dims)

"""
popdisplay()
popdisplay(d::Display)
Expand Down Expand Up @@ -1531,14 +1503,6 @@ Byte-swap an integer.
"""
bswap

"""
sumabs2!(r, A)
Sum squared absolute values of elements of `A` over the singleton dimensions of `r`, and
write results to `r`.
"""
sumabs2!

"""
tanh(x)
Expand Down Expand Up @@ -1850,14 +1814,6 @@ false
"""
isempty

"""
sumabs!(r, A)
Sum absolute values of elements of `A` over the singleton dimensions of `r`, and write
results to `r`.
"""
sumabs!

"""
hex2num(str)
Expand Down Expand Up @@ -2589,13 +2545,6 @@ it for new types as appropriate.
"""
promote_rule

"""
sumabs2(A, dims)
Sum squared absolute values of elements of an array over the given dimensions.
"""
sumabs2(A,dims)

"""
showall(x)
Expand Down Expand Up @@ -2656,13 +2605,6 @@ Compute cosine of `x`, where `x` is in radians.
"""
cos

"""
maxabs(A, dims)
Compute the maximum absolute values over given dimensions.
"""
maxabs(A,dims)

"""
done(iter, state) -> Bool
Expand Down
8 changes: 0 additions & 8 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,9 @@ export
logspace,
mapslices,
max,
maxabs,
maxabs!,
maximum!,
maximum,
min,
minabs,
minabs!,
minimum!,
minimum,
minmax,
Expand Down Expand Up @@ -601,10 +597,6 @@ export
sub2ind,
sum!,
sum,
sumabs!,
sumabs,
sumabs2!,
sumabs2,
sum_kbn,
vcat,
vec,
Expand Down
38 changes: 0 additions & 38 deletions base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -350,20 +350,6 @@ Returns the sum of all elements in a collection.
sum(a) = mapreduce(identity, +, a)
sum(a::AbstractArray{Bool}) = countnz(a)

"""
sumabs(itr)
Sum absolute values of all elements in a collection. This is equivalent to `sum(abs(itr))` but faster.
"""
sumabs(a) = mapreduce(abs, +, a)

"""
sumabs2(itr)
Sum squared absolute values of all elements in a collection.
This is equivalent to `sum(abs2(itr))` but faster.
"""
sumabs2(a) = mapreduce(abs2, +, a)

# Kahan (compensated) summation: O(1) error growth, at the expense
# of a considerable increase in computational expense.
Expand Down Expand Up @@ -463,30 +449,6 @@ julia> minimum([1,2,3])
"""
minimum(a) = mapreduce(identity, scalarmin, a)

"""
maxabs(itr)
Compute the maximum absolute value of a collection of values.
```jldoctest
julia> maxabs([-1, 3, 4*im])
4.0
```
"""
maxabs(a) = mapreduce(abs, scalarmax, a)

"""
minabs(itr)
Compute the minimum absolute value of a collection of values.
```jldoctest
julia> minabs([-1, 3, 4*im])
1.0
```
"""
minabs(a) = mapreduce(abs, scalarmin, a)

## extrema

extrema(r::Range) = (minimum(r), maximum(r))
Expand Down
13 changes: 0 additions & 13 deletions base/reducedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,6 @@ for (fname, op) in [(:sum, :+), (:prod, :*),
end
end

for (fname, fbase, fun) in [(:sumabs, :sum, :abs),
(:sumabs2, :sum, :abs2),
(:maxabs, :maximum, :abs),
(:minabs, :minimum, :abs)]
fname! = Symbol(fname, '!')
fbase! = Symbol(fbase, '!')
@eval begin
$(fname!)(r::AbstractArray, A::AbstractArray; init::Bool=true) =
$(fbase!)($(fun), r, A; init=init)
$(fname)(A::AbstractArray, region) = $(fbase)($(fun), A, region)
end
end


##### findmin & findmax #####

Expand Down
4 changes: 2 additions & 2 deletions base/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import Base: @get!, acos, acosd, acot, acotd, acsch, asech, asin, asind, asinh,
atan, atand, atanh, broadcast!, chol, conj!, cos, cosc, cosd, cosh, cospi, cot,
cotd, coth, countnz, csc, cscd, csch, ctranspose!, diag, diff, done, dot, eig,
exp10, exp2, eye, findn, floor, hash, indmin, inv, issymmetric, istril, istriu,
log10, log2, lu, maxabs, minabs, next, sec, secd, sech, show, sin,
sinc, sind, sinh, sinpi, squeeze, start, sum, sumabs, sumabs2, summary, tan,
log10, log2, lu, next, sec, secd, sech, show, sin,
sinc, sind, sinh, sinpi, squeeze, start, sum, summary, tan,
tand, tanh, trace, transpose!, tril!, triu!, trunc, vecnorm, abs, abs2,
broadcast, ceil, complex, cond, conj, convert, copy, copy!, ctranspose, diagm,
exp, expm1, factorize, find, findmax, findmin, findnz, float, full, getindex,
Expand Down
14 changes: 9 additions & 5 deletions base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1284,8 +1284,6 @@ end
### Reduction

sum(x::AbstractSparseVector) = sum(nonzeros(x))
sumabs(x::AbstractSparseVector) = sumabs(nonzeros(x))
sumabs2(x::AbstractSparseVector) = sumabs2(nonzeros(x))

function maximum{T<:Real}(x::AbstractSparseVector{T})
n = length(x)
Expand All @@ -1305,8 +1303,14 @@ function minimum{T<:Real}(x::AbstractSparseVector{T})
min(zero(T), minimum(nonzeros(x))))::T
end

maxabs{T<:Number}(x::AbstractSparseVector{T}) = maxabs(nonzeros(x))
minabs{T<:Number}(x::AbstractSparseVector{T}) = nnz(x) < length(x) ? abs(zero(T)) : minabs(nonzeros(x))
for f in [:sum, :maximum, :minimum], op in [:abs, :abs2]
SV = :AbstractSparseVector
if f == :minimum
@eval ($f){T<:Number}(::typeof($op), x::$SV{T}) = nnz(x) < length(x) ? ($op)(zero(T)) : ($f)($op, nonzeros(x))
else
@eval ($f)(::typeof($op), x::$SV) = ($f)($op, nonzeros(x))
end
end

vecnorm(x::AbstractSparseVector, p::Real=2) = vecnorm(nonzeros(x), p)

Expand Down Expand Up @@ -1421,7 +1425,7 @@ function _spdot(f::Function,
end

function dot{Tx<:Number,Ty<:Number}(x::AbstractSparseVector{Tx}, y::AbstractSparseVector{Ty})
x === y && return sumabs2(x)
x === y && return sum(abs2, x)
n = length(x)
length(y) == n || throw(DimensionMismatch())

Expand Down
10 changes: 5 additions & 5 deletions base/statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ var{T}(A::AbstractArray{T}; corrected::Bool=true, mean=nothing) =
Compute the sample variance of a vector or array `v`, optionally along dimensions in
`region`. The algorithm will return an estimator of the generative distribution's variance
under the assumption that each entry of `v` is an IID drawn from that generative
distribution. This computation is equivalent to calculating `sumabs2(v - mean(v)) /
distribution. This computation is equivalent to calculating `sum(abs2, v - mean(v)) /
(length(v) - 1)`. If `corrected` is `true`, then the sum is scaled with `n-1`,
whereas the sum is scaled with `n` if `corrected` is `false` where `n = length(x)`.
The mean `mean` over the region may be provided.
Expand Down Expand Up @@ -296,7 +296,7 @@ _vmean(x::AbstractMatrix, vardim::Int) = mean(x, vardim)

# core functions

unscaled_covzm(x::AbstractVector) = sumabs2(x)
unscaled_covzm(x::AbstractVector) = sum(abs2, x)
unscaled_covzm(x::AbstractMatrix, vardim::Int) = (vardim == 1 ? _conj(x'x) : x * x')

unscaled_covzm(x::AbstractVector, y::AbstractVector) = dot(x, y)
Expand Down Expand Up @@ -436,11 +436,11 @@ function corzm(x::AbstractMatrix, vardim::Int=1)
return cov2cor!(c, sqrt!(diag(c)))
end
corzm(x::AbstractVector, y::AbstractMatrix, vardim::Int=1) =
cov2cor!(unscaled_covzm(x, y, vardim), sqrt(sumabs2(x)), sqrt!(sumabs2(y, vardim)))
cov2cor!(unscaled_covzm(x, y, vardim), sqrt(sum(abs2, x)), sqrt!(sum(abs2, y, vardim)))
corzm(x::AbstractMatrix, y::AbstractVector, vardim::Int=1) =
cov2cor!(unscaled_covzm(x, y, vardim), sqrt!(sumabs2(x, vardim)), sqrt(sumabs2(y)))
cov2cor!(unscaled_covzm(x, y, vardim), sqrt!(sum(abs2, x, vardim)), sqrt(sum(abs2, y)))
corzm(x::AbstractMatrix, y::AbstractMatrix, vardim::Int=1) =
cov2cor!(unscaled_covzm(x, y, vardim), sqrt!(sumabs2(x, vardim)), sqrt!(sumabs2(y, vardim)))
cov2cor!(unscaled_covzm(x, y, vardim), sqrt!(sum(abs2, x, vardim)), sqrt!(sum(abs2, y, vardim)))

# corm

Expand Down
21 changes: 0 additions & 21 deletions test/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,6 @@ z = [-4, -3, 2, 5]
fz = float(z)
a = randn(32) # need >16 elements to trigger BLAS code path
b = complex(randn(32), randn(32))
@test sumabs(Float64[]) === 0.0
@test sumabs([Int8(-2)]) === Int32(2)
@test sumabs(z) === 14
@test sumabs(fz) === 14.0
@test sumabs(a) sum(abs.(a))
@test sumabs(b) sum(abs.(b))

@test sumabs2(Float64[]) === 0.0
@test sumabs2([Int8(-2)]) === Int32(4)
@test sumabs2(z) === 54
@test sumabs2(fz) === 54.0
@test sumabs2(a) sum(abs2.(a))
@test sumabs2(b) sum(abs2.(b))

# check variants of summation for type-stability and other issues (#6069)
sum2(itr) = invoke(sum, Tuple{Any}, itr)
Expand Down Expand Up @@ -152,14 +139,6 @@ prod2(itr) = invoke(prod, Tuple{Any}, itr)
@test isnan(minimum([4., 3., NaN, 5., 2.]))
@test isequal(extrema([4., 3., NaN, 5., 2.]), (NaN,NaN))

@test maxabs(Int[]) == 0
@test_throws ArgumentError Base.minabs(Int[])

@test maxabs(-2) == 2
@test minabs(-2) == 2
@test maxabs([1, -2, 3, -4]) == 4
@test minabs([-1, 2, -3, 4]) == 1

@test maximum(abs2, 3:7) == 49
@test minimum(abs2, 3:7) == 9

Expand Down
Loading

0 comments on commit 937c970

Please sign in to comment.