Skip to content

Commit 9a587b1

Browse files
authored
Merge pull request #19616 from ararslan/aa/deprecate-sumabs-et-al
Deprecate sumabs, sumabs2, minabs, maxabs
2 parents b730db2 + 53cc79a commit 9a587b1

14 files changed

+78
-200
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ Deprecated or removed
9898

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

101+
* `sumabs` and `sumabs2` have been deprecated in favor of `sum(abs, x)` and `sum(abs2, x)`, respectively.
102+
`maxabs` and `minabs` have similarly been deprecated in favor of `maximum(abs, x)` and `minimum(abs, x)`.
103+
Likewise for the in-place counterparts of these functions ([#19598]).
104+
101105
Julia v0.5.0 Release Notes
102106
==========================
103107

base/deprecated.jl

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,4 +1134,24 @@ end)
11341134
@deprecate cummin(A, dim=1) accumulate(min, A, dim=1)
11351135
@deprecate cummax(A, dim=1) accumulate(max, A, dim=1)
11361136

1137+
# #19598
1138+
@deprecate sumabs(x) sum(abs, x)
1139+
@deprecate sumabs(A, region) sum(abs, A, region)
1140+
@deprecate sumabs2(x) sum(abs2, x)
1141+
@deprecate sumabs2(A, region) sum(abs2, A, region)
1142+
@deprecate minabs(x) minimum(abs, x)
1143+
@deprecate minabs(A, region) minimum(abs, A, region)
1144+
@deprecate maxabs(x) maximum(abs, x)
1145+
@deprecate maxabs(A, region) maximum(abs, A, region)
1146+
1147+
for (dep, f, op) in [(:sumabs!, :sum!, :abs),
1148+
(:sumabs2!, :sum!, :abs2),
1149+
(:minabs!, :minimum!, :abs),
1150+
(:maxabs!, :maximum!, :abs)]
1151+
@eval function ($dep)(r, A; init=true)
1152+
Base.depwarn("$dep(r, A; init=$init) is deprecated, use $f($op, r, A; init=$init) instead.", Symbol($dep))
1153+
($f)($op, r, A; init=init)
1154+
end
1155+
end
1156+
11371157
# End deprecations scheduled for 0.6

base/docs/helpdb/Base.jl

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,6 @@ Cumulative minimum along a dimension. The dimension defaults to 1.
112112
"""
113113
cummin
114114

115-
"""
116-
minabs!(r, A)
117-
118-
Compute the minimum absolute values over the singleton dimensions of `r`, and write values to `r`.
119-
"""
120-
minabs!
121-
122115
"""
123116
eigfact!(A, [B])
124117
@@ -530,13 +523,6 @@ Convert `y` to the type of `x` (`convert(typeof(x), y)`).
530523
"""
531524
oftype
532525

533-
"""
534-
maxabs!(r, A)
535-
536-
Compute the maximum absolute values over the singleton dimensions of `r`, and write values to `r`.
537-
"""
538-
maxabs!
539-
540526
"""
541527
isfinite(f) -> Bool
542528
@@ -727,13 +713,6 @@ Show every part of the representation of a value.
727713
"""
728714
dump
729715

730-
"""
731-
sumabs(A, dims)
732-
733-
Sum absolute values of elements of an array over the given dimensions.
734-
"""
735-
sumabs(A, dims)
736-
737716
"""
738717
consume(task, values...)
739718
@@ -1308,13 +1287,6 @@ Compute the inverse error complementary function of a real `x`, defined by
13081287
"""
13091288
erfcinv
13101289

1311-
"""
1312-
minabs(A, dims)
1313-
1314-
Compute the minimum absolute values over given dimensions.
1315-
"""
1316-
minabs(A, dims)
1317-
13181290
"""
13191291
popdisplay()
13201292
popdisplay(d::Display)
@@ -1531,14 +1503,6 @@ Byte-swap an integer.
15311503
"""
15321504
bswap
15331505

1534-
"""
1535-
sumabs2!(r, A)
1536-
1537-
Sum squared absolute values of elements of `A` over the singleton dimensions of `r`, and
1538-
write results to `r`.
1539-
"""
1540-
sumabs2!
1541-
15421506
"""
15431507
tanh(x)
15441508
@@ -1850,14 +1814,6 @@ false
18501814
"""
18511815
isempty
18521816

1853-
"""
1854-
sumabs!(r, A)
1855-
1856-
Sum absolute values of elements of `A` over the singleton dimensions of `r`, and write
1857-
results to `r`.
1858-
"""
1859-
sumabs!
1860-
18611817
"""
18621818
hex2num(str)
18631819
@@ -2589,13 +2545,6 @@ it for new types as appropriate.
25892545
"""
25902546
promote_rule
25912547

2592-
"""
2593-
sumabs2(A, dims)
2594-
2595-
Sum squared absolute values of elements of an array over the given dimensions.
2596-
"""
2597-
sumabs2(A,dims)
2598-
25992548
"""
26002549
showall(x)
26012550
@@ -2656,13 +2605,6 @@ Compute cosine of `x`, where `x` is in radians.
26562605
"""
26572606
cos
26582607

2659-
"""
2660-
maxabs(A, dims)
2661-
2662-
Compute the maximum absolute values over given dimensions.
2663-
"""
2664-
maxabs(A,dims)
2665-
26662608
"""
26672609
done(iter, state) -> Bool
26682610

base/exports.jl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -541,13 +541,9 @@ export
541541
logspace,
542542
mapslices,
543543
max,
544-
maxabs,
545-
maxabs!,
546544
maximum!,
547545
maximum,
548546
min,
549-
minabs,
550-
minabs!,
551547
minimum!,
552548
minimum,
553549
minmax,
@@ -601,10 +597,6 @@ export
601597
sub2ind,
602598
sum!,
603599
sum,
604-
sumabs!,
605-
sumabs,
606-
sumabs2!,
607-
sumabs2,
608600
sum_kbn,
609601
vcat,
610602
vec,

base/reduce.jl

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -350,20 +350,6 @@ Returns the sum of all elements in a collection.
350350
sum(a) = mapreduce(identity, +, a)
351351
sum(a::AbstractArray{Bool}) = countnz(a)
352352

353-
"""
354-
sumabs(itr)
355-
356-
Sum absolute values of all elements in a collection. This is equivalent to `sum(abs(itr))` but faster.
357-
"""
358-
sumabs(a) = mapreduce(abs, +, a)
359-
360-
"""
361-
sumabs2(itr)
362-
363-
Sum squared absolute values of all elements in a collection.
364-
This is equivalent to `sum(abs2(itr))` but faster.
365-
"""
366-
sumabs2(a) = mapreduce(abs2, +, a)
367353

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

466-
"""
467-
maxabs(itr)
468-
469-
Compute the maximum absolute value of a collection of values.
470-
471-
```jldoctest
472-
julia> maxabs([-1, 3, 4*im])
473-
4.0
474-
```
475-
"""
476-
maxabs(a) = mapreduce(abs, scalarmax, a)
477-
478-
"""
479-
minabs(itr)
480-
481-
Compute the minimum absolute value of a collection of values.
482-
483-
```jldoctest
484-
julia> minabs([-1, 3, 4*im])
485-
1.0
486-
```
487-
"""
488-
minabs(a) = mapreduce(abs, scalarmin, a)
489-
490452
## extrema
491453

492454
extrema(r::Range) = (minimum(r), maximum(r))

base/reducedim.jl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -294,19 +294,6 @@ for (fname, op) in [(:sum, :+), (:prod, :*),
294294
end
295295
end
296296

297-
for (fname, fbase, fun) in [(:sumabs, :sum, :abs),
298-
(:sumabs2, :sum, :abs2),
299-
(:maxabs, :maximum, :abs),
300-
(:minabs, :minimum, :abs)]
301-
fname! = Symbol(fname, '!')
302-
fbase! = Symbol(fbase, '!')
303-
@eval begin
304-
$(fname!)(r::AbstractArray, A::AbstractArray; init::Bool=true) =
305-
$(fbase!)($(fun), r, A; init=init)
306-
$(fname)(A::AbstractArray, region) = $(fbase)($(fun), A, region)
307-
end
308-
end
309-
310297

311298
##### findmin & findmax #####
312299

base/sparse/sparse.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ import Base: @get!, acos, acosd, acot, acotd, acsch, asech, asin, asind, asinh,
1616
atan, atand, atanh, broadcast!, chol, conj!, cos, cosc, cosd, cosh, cospi, cot,
1717
cotd, coth, countnz, csc, cscd, csch, ctranspose!, diag, diff, done, dot, eig,
1818
exp10, exp2, eye, findn, floor, hash, indmin, inv, issymmetric, istril, istriu,
19-
log10, log2, lu, maxabs, minabs, next, sec, secd, sech, show, sin,
20-
sinc, sind, sinh, sinpi, squeeze, start, sum, sumabs, sumabs2, summary, tan,
19+
log10, log2, lu, next, sec, secd, sech, show, sin,
20+
sinc, sind, sinh, sinpi, squeeze, start, sum, summary, tan,
2121
tand, tanh, trace, transpose!, tril!, triu!, trunc, vecnorm, abs, abs2,
2222
broadcast, ceil, complex, cond, conj, convert, copy, copy!, ctranspose, diagm,
2323
exp, expm1, factorize, find, findmax, findmin, findnz, float, full, getindex,

base/sparse/sparsevector.jl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,8 +1284,6 @@ end
12841284
### Reduction
12851285

12861286
sum(x::AbstractSparseVector) = sum(nonzeros(x))
1287-
sumabs(x::AbstractSparseVector) = sumabs(nonzeros(x))
1288-
sumabs2(x::AbstractSparseVector) = sumabs2(nonzeros(x))
12891287

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

1308-
maxabs{T<:Number}(x::AbstractSparseVector{T}) = maxabs(nonzeros(x))
1309-
minabs{T<:Number}(x::AbstractSparseVector{T}) = nnz(x) < length(x) ? abs(zero(T)) : minabs(nonzeros(x))
1306+
for f in [:sum, :maximum, :minimum], op in [:abs, :abs2]
1307+
SV = :AbstractSparseVector
1308+
if f == :minimum
1309+
@eval ($f){T<:Number}(::typeof($op), x::$SV{T}) = nnz(x) < length(x) ? ($op)(zero(T)) : ($f)($op, nonzeros(x))
1310+
else
1311+
@eval ($f)(::typeof($op), x::$SV) = ($f)($op, nonzeros(x))
1312+
end
1313+
end
13101314

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

@@ -1421,7 +1425,7 @@ function _spdot(f::Function,
14211425
end
14221426

14231427
function dot{Tx<:Number,Ty<:Number}(x::AbstractSparseVector{Tx}, y::AbstractSparseVector{Ty})
1424-
x === y && return sumabs2(x)
1428+
x === y && return sum(abs2, x)
14251429
n = length(x)
14261430
length(y) == n || throw(DimensionMismatch())
14271431

base/statistics.jl

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

297297
# core functions
298298

299-
unscaled_covzm(x::AbstractVector) = sumabs2(x)
299+
unscaled_covzm(x::AbstractVector) = sum(abs2, x)
300300
unscaled_covzm(x::AbstractMatrix, vardim::Int) = (vardim == 1 ? _conj(x'x) : x * x')
301301

302302
unscaled_covzm(x::AbstractVector, y::AbstractVector) = dot(x, y)
@@ -436,11 +436,11 @@ function corzm(x::AbstractMatrix, vardim::Int=1)
436436
return cov2cor!(c, sqrt!(diag(c)))
437437
end
438438
corzm(x::AbstractVector, y::AbstractMatrix, vardim::Int=1) =
439-
cov2cor!(unscaled_covzm(x, y, vardim), sqrt(sumabs2(x)), sqrt!(sumabs2(y, vardim)))
439+
cov2cor!(unscaled_covzm(x, y, vardim), sqrt(sum(abs2, x)), sqrt!(sum(abs2, y, vardim)))
440440
corzm(x::AbstractMatrix, y::AbstractVector, vardim::Int=1) =
441-
cov2cor!(unscaled_covzm(x, y, vardim), sqrt!(sumabs2(x, vardim)), sqrt(sumabs2(y)))
441+
cov2cor!(unscaled_covzm(x, y, vardim), sqrt!(sum(abs2, x, vardim)), sqrt(sum(abs2, y)))
442442
corzm(x::AbstractMatrix, y::AbstractMatrix, vardim::Int=1) =
443-
cov2cor!(unscaled_covzm(x, y, vardim), sqrt!(sumabs2(x, vardim)), sqrt!(sumabs2(y, vardim)))
443+
cov2cor!(unscaled_covzm(x, y, vardim), sqrt!(sum(abs2, x, vardim)), sqrt!(sum(abs2, y, vardim)))
444444

445445
# corm
446446

doc/src/stdlib/collections.md

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,8 @@ Base.findmin(::Any)
102102
Base.findmin(::AbstractArray, ::Any)
103103
Base.findmax!
104104
Base.findmin!
105-
Base.maxabs(::Any)
106-
Base.maxabs(::Any, ::Any)
107-
Base.maxabs!
108-
Base.minabs(::Any)
109-
Base.minabs(::Any, ::Any)
110-
Base.minabs!
111105
Base.sum(::Any)
112106
Base.sum!
113-
Base.sumabs(::Any)
114-
Base.sumabs(::Any, ::Any)
115-
Base.sumabs!
116-
Base.sumabs2(::Any)
117-
Base.sumabs2(::Any, ::Any)
118-
Base.sumabs2!
119107
Base.prod(::Any)
120108
Base.prod(::Any, ::Any)
121109
Base.prod!

test/reduce.jl

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,6 @@ z = [-4, -3, 2, 5]
6161
fz = float(z)
6262
a = randn(32) # need >16 elements to trigger BLAS code path
6363
b = complex(randn(32), randn(32))
64-
@test sumabs(Float64[]) === 0.0
65-
@test sumabs([Int8(-2)]) === Int32(2)
66-
@test sumabs(z) === 14
67-
@test sumabs(fz) === 14.0
68-
@test sumabs(a) sum(abs.(a))
69-
@test sumabs(b) sum(abs.(b))
70-
71-
@test sumabs2(Float64[]) === 0.0
72-
@test sumabs2([Int8(-2)]) === Int32(4)
73-
@test sumabs2(z) === 54
74-
@test sumabs2(fz) === 54.0
75-
@test sumabs2(a) sum(abs2.(a))
76-
@test sumabs2(b) sum(abs2.(b))
7764

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

155-
@test maxabs(Int[]) == 0
156-
@test_throws ArgumentError Base.minabs(Int[])
157-
158-
@test maxabs(-2) == 2
159-
@test minabs(-2) == 2
160-
@test maxabs([1, -2, 3, -4]) == 4
161-
@test minabs([-1, 2, -3, 4]) == 1
162-
163142
@test maximum(abs2, 3:7) == 49
164143
@test minimum(abs2, 3:7) == 9
165144

0 commit comments

Comments
 (0)