diff --git a/NEWS.md b/NEWS.md index 0f939ddc5286a..b34673db3c74c 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 ========================== diff --git a/base/deprecated.jl b/base/deprecated.jl index 1df19712e226d..25ebc5fbac01d 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1134,4 +1134,24 @@ 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) + +for (dep, f, op) in [(:sumabs!, :sum!, :abs), + (:sumabs2!, :sum!, :abs2), + (:minabs!, :minimum!, :abs), + (:maxabs!, :maximum!, :abs)] + @eval function ($dep)(r, A; init=true) + Base.depwarn("$dep(r, A; init=$init) is deprecated, use $f($op, r, A; init=$init) instead.", Symbol($dep)) + ($f)($op, r, A; init=init) + end +end + # End deprecations scheduled for 0.6 diff --git a/base/docs/helpdb/Base.jl b/base/docs/helpdb/Base.jl index 0ad868983f4c6..545bfac1bd37e 100644 --- a/base/docs/helpdb/Base.jl +++ b/base/docs/helpdb/Base.jl @@ -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]) @@ -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 @@ -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...) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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 diff --git a/base/exports.jl b/base/exports.jl index 81e68387f2c2b..a3a58c8ec737a 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -541,13 +541,9 @@ export logspace, mapslices, max, - maxabs, - maxabs!, maximum!, maximum, min, - minabs, - minabs!, minimum!, minimum, minmax, @@ -601,10 +597,6 @@ export sub2ind, sum!, sum, - sumabs!, - sumabs, - sumabs2!, - sumabs2, sum_kbn, vcat, vec, diff --git a/base/reduce.jl b/base/reduce.jl index 78a7ee3ccf5e6..1d6517891b1f8 100644 --- a/base/reduce.jl +++ b/base/reduce.jl @@ -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. @@ -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)) diff --git a/base/reducedim.jl b/base/reducedim.jl index 86c7048edcec7..c0599cd3680e4 100644 --- a/base/reducedim.jl +++ b/base/reducedim.jl @@ -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 ##### diff --git a/base/sparse/sparse.jl b/base/sparse/sparse.jl index 25bc8906a947f..a1b86b7fa3f9e 100644 --- a/base/sparse/sparse.jl +++ b/base/sparse/sparse.jl @@ -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, diff --git a/base/sparse/sparsevector.jl b/base/sparse/sparsevector.jl index 38707df8eedaf..4574733208805 100644 --- a/base/sparse/sparsevector.jl +++ b/base/sparse/sparsevector.jl @@ -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) @@ -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) @@ -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()) diff --git a/base/statistics.jl b/base/statistics.jl index e3766ef5cecaa..98dad40d1b9cd 100644 --- a/base/statistics.jl +++ b/base/statistics.jl @@ -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. @@ -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) @@ -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 diff --git a/doc/src/stdlib/collections.md b/doc/src/stdlib/collections.md index 573332a7617c5..ea91c833fe5e1 100644 --- a/doc/src/stdlib/collections.md +++ b/doc/src/stdlib/collections.md @@ -102,20 +102,8 @@ Base.findmin(::Any) Base.findmin(::AbstractArray, ::Any) Base.findmax! Base.findmin! -Base.maxabs(::Any) -Base.maxabs(::Any, ::Any) -Base.maxabs! -Base.minabs(::Any) -Base.minabs(::Any, ::Any) -Base.minabs! Base.sum(::Any) Base.sum! -Base.sumabs(::Any) -Base.sumabs(::Any, ::Any) -Base.sumabs! -Base.sumabs2(::Any) -Base.sumabs2(::Any, ::Any) -Base.sumabs2! Base.prod(::Any) Base.prod(::Any, ::Any) Base.prod! diff --git a/test/reduce.jl b/test/reduce.jl index 207e57684a95a..70ad0753bb9ab 100644 --- a/test/reduce.jl +++ b/test/reduce.jl @@ -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) @@ -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 diff --git a/test/reducedim.jl b/test/reducedim.jl index a7a63ad642032..77a9dc537b5a5 100644 --- a/test/reducedim.jl +++ b/test/reducedim.jl @@ -25,10 +25,10 @@ for region in Any[ @test prod!(r, Areduc) ≈ safe_prod(Areduc, region) @test maximum!(r, Areduc) ≈ safe_maximum(Areduc, region) @test minimum!(r, Areduc) ≈ safe_minimum(Areduc, region) - @test sumabs!(r, Areduc) ≈ safe_sumabs(Areduc, region) - @test sumabs2!(r, Areduc) ≈ safe_sumabs2(Areduc, region) - @test maxabs!(r, Areduc) ≈ safe_maxabs(Areduc, region) - @test minabs!(r, Areduc) ≈ safe_minabs(Areduc, region) + @test sum!(abs, r, Areduc) ≈ safe_sumabs(Areduc, region) + @test sum!(abs2, r, Areduc) ≈ safe_sumabs2(Areduc, region) + @test maximum!(abs, r, Areduc) ≈ safe_maxabs(Areduc, region) + @test minimum!(abs, r, Areduc) ≈ safe_minabs(Areduc, region) # With init=false r2 = similar(r) @@ -41,22 +41,22 @@ for region in Any[ fill!(r, -0.2) @test minimum!(r, Areduc, init=false) ≈ fill!(r2, -0.2) fill!(r, 8.1) - @test sumabs!(r, Areduc, init=false) ≈ safe_sumabs(Areduc, region)+8.1 + @test sum!(abs, r, Areduc, init=false) ≈ safe_sumabs(Areduc, region)+8.1 fill!(r, 8.1) - @test sumabs2!(r, Areduc, init=false) ≈ safe_sumabs2(Areduc, region)+8.1 + @test sum!(abs2, r, Areduc, init=false) ≈ safe_sumabs2(Areduc, region)+8.1 fill!(r, 1.5) - @test maxabs!(r, Areduc, init=false) ≈ fill!(r2, 1.5) + @test maximum!(abs, r, Areduc, init=false) ≈ fill!(r2, 1.5) fill!(r, -1.5) - @test minabs!(r, Areduc, init=false) ≈ fill!(r2, -1.5) + @test minimum!(abs, r, Areduc, init=false) ≈ fill!(r2, -1.5) @test sum(Areduc, region) ≈ safe_sum(Areduc, region) @test prod(Areduc, region) ≈ safe_prod(Areduc, region) @test maximum(Areduc, region) ≈ safe_maximum(Areduc, region) @test minimum(Areduc, region) ≈ safe_minimum(Areduc, region) - @test sumabs(Areduc, region) ≈ safe_sumabs(Areduc, region) - @test sumabs2(Areduc, region) ≈ safe_sumabs2(Areduc, region) - @test maxabs(Areduc, region) ≈ safe_maxabs(Areduc, region) - @test minabs(Areduc, region) ≈ safe_minabs(Areduc, region) + @test sum(abs, Areduc, region) ≈ safe_sumabs(Areduc, region) + @test sum(abs2, Areduc, region) ≈ safe_sumabs2(Areduc, region) + @test maximum(abs, Areduc, region) ≈ safe_maxabs(Areduc, region) + @test minimum(abs, Areduc, region) ≈ safe_minabs(Areduc, region) end # Test reduction along first dimension; this is special-cased for @@ -64,18 +64,18 @@ end Breduc = rand(64, 3) r = fill(NaN, map(length, Base.reduced_indices(indices(Breduc), 1))) @test sum!(r, Breduc) ≈ safe_sum(Breduc, 1) -@test sumabs!(r, Breduc) ≈ safe_sumabs(Breduc, 1) -@test sumabs2!(r, Breduc) ≈ safe_sumabs2(Breduc, 1) +@test sum!(abs, r, Breduc) ≈ safe_sumabs(Breduc, 1) +@test sum!(abs2, r, Breduc) ≈ safe_sumabs2(Breduc, 1) @test sum(Breduc, 1) ≈ safe_sum(Breduc, 1) -@test sumabs(Breduc, 1) ≈ safe_sumabs(Breduc, 1) -@test sumabs2(Breduc, 1) ≈ safe_sumabs2(Breduc, 1) +@test sum(abs, Breduc, 1) ≈ safe_sumabs(Breduc, 1) +@test sum(abs2, Breduc, 1) ≈ safe_sumabs2(Breduc, 1) fill!(r, 4.2) @test sum!(r, Breduc, init=false) ≈ safe_sum(Breduc, 1)+4.2 fill!(r, -6.3) -@test sumabs!(r, Breduc, init=false) ≈ safe_sumabs(Breduc, 1)-6.3 +@test sum!(abs, r, Breduc, init=false) ≈ safe_sumabs(Breduc, 1)-6.3 fill!(r, -1.1) -@test sumabs2!(r, Breduc, init=false) ≈ safe_sumabs2(Breduc, 1)-1.1 +@test sum!(abs2, r, Breduc, init=false) ≈ safe_sumabs2(Breduc, 1)-1.1 # Small arrays with init=false A = reshape(1:15, 3, 5) @@ -93,8 +93,8 @@ A = reshape(1:6, 3, 2) # Complex types @test typeof(@inferred(sum([1.0+1.0im], 1))) == Vector{Complex128} -@test typeof(@inferred(Base.sumabs([1.0+1.0im], 1))) == Vector{Float64} -@test typeof(@inferred(Base.sumabs2([1.0+1.0im], 1))) == Vector{Float64} +@test typeof(@inferred(Base.sum(abs, [1.0+1.0im], 1))) == Vector{Float64} +@test typeof(@inferred(Base.sum(abs2, [1.0+1.0im], 1))) == Vector{Float64} @test typeof(@inferred(prod([1.0+1.0im], 1))) == Vector{Complex128} @test typeof(@inferred(Base.prod(abs, [1.0+1.0im], 1))) == Vector{Float64} @test typeof(@inferred(Base.prod(abs2, [1.0+1.0im], 1))) == Vector{Float64} @@ -149,8 +149,8 @@ for region in Any[-1, 0, (-1, 2), [0, 1], (1,-2,3), [0 1; @test_throws ArgumentError prod(Areduc, region) @test_throws ArgumentError maximum(Areduc, region) @test_throws ArgumentError minimum(Areduc, region) - @test_throws ArgumentError sumabs(Areduc, region) - @test_throws ArgumentError sumabs2(Areduc, region) - @test_throws ArgumentError maxabs(Areduc, region) - @test_throws ArgumentError minabs(Areduc, region) + @test_throws ArgumentError sum(abs, Areduc, region) + @test_throws ArgumentError sum(abs2, Areduc, region) + @test_throws ArgumentError maximum(abs, Areduc, region) + @test_throws ArgumentError minimum(abs, Areduc, region) end diff --git a/test/sparse/sparsevector.jl b/test/sparse/sparsevector.jl index 11d49640c1843..96046216ba012 100644 --- a/test/sparse/sparsevector.jl +++ b/test/sparse/sparsevector.jl @@ -669,12 +669,12 @@ end ### Reduction -# sum, sumabs, sumabs2, vecnorm +# sum, vecnorm let x = spv_x1 @test sum(x) == 4.0 - @test sumabs(x) == 5.5 - @test sumabs2(x) == 14.375 + @test sum(abs, x) == 5.5 + @test sum(abs2, x) == 14.375 @test vecnorm(x) == sqrt(14.375) @test vecnorm(x, 1) == 5.5 @@ -682,13 +682,13 @@ let x = spv_x1 @test vecnorm(x, Inf) == 3.5 end -# maximum, minimum, maxabs, minabs +# maximum, minimum let x = spv_x1 @test maximum(x) == 3.5 @test minimum(x) == -0.75 - @test maxabs(x) == 3.5 - @test minabs(x) == 0.0 + @test maximum(abs, x) == 3.5 + @test minimum(abs, x) == 0.0 end let x = abs.(spv_x1) @@ -704,15 +704,15 @@ end let x = SparseVector(3, [1, 2, 3], [-4.5, 2.5, 3.5]) @test maximum(x) == 3.5 @test minimum(x) == -4.5 - @test maxabs(x) == 4.5 - @test minabs(x) == 2.5 + @test maximum(abs, x) == 4.5 + @test minimum(abs, x) == 2.5 end let x = spzeros(Float64, 8) @test maximum(x) == 0.0 @test minimum(x) == 0.0 - @test maxabs(x) == 0.0 - @test minabs(x) == 0.0 + @test maximum(abs, x) == 0.0 + @test minimum(abs, x) == 0.0 end @@ -759,8 +759,8 @@ let x = sprand(16, 0.5), x2 = sprand(16, 0.4) # dot let dv = dot(xf, xf2) - @test dot(x, x) == sumabs2(x) - @test dot(x2, x2) == sumabs2(x2) + @test dot(x, x) == sum(abs2, x) + @test dot(x2, x2) == sum(abs2, x2) @test dot(x, x2) ≈ dv @test dot(x2, x) ≈ dv @test dot(Array(x), x2) ≈ dv diff --git a/test/statistics.jl b/test/statistics.jl index 6a16cb599dbb6..bf99490759f87 100644 --- a/test/statistics.jl +++ b/test/statistics.jl @@ -337,12 +337,12 @@ y = [0.40003674665581906,0.4085630862624367,0.41662034698690303,0.41662034698690 # variance of complex arrays (#13309) let z = rand(Complex128, 10) - @test var(z) ≈ invoke(var, (Any,), z) ≈ cov(z) ≈ var(z,1)[1] ≈ sumabs2(z - mean(z))/9 + @test var(z) ≈ invoke(var, (Any,), z) ≈ cov(z) ≈ var(z,1)[1] ≈ sum(abs2, z - mean(z))/9 @test isa(var(z), Float64) @test isa(invoke(var, (Any,), z), Float64) @test isa(cov(z), Float64) @test isa(var(z,1), Vector{Float64}) - @test varm(z, 0.0) ≈ invoke(varm, (Any,Float64), z, 0.0) ≈ sumabs2(z)/9 + @test varm(z, 0.0) ≈ invoke(varm, (Any,Float64), z, 0.0) ≈ sum(abs2, z)/9 @test isa(varm(z, 0.0), Float64) @test isa(invoke(varm, (Any,Float64), z, 0.0), Float64) @test cor(z) === 1.0