From e0d3b144f294d763d4248566439fc42d09188355 Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Fri, 23 Feb 2018 17:41:30 -0500 Subject: [PATCH] Fix std(::AbstractArray{<:AbstractFloat}) Issue #25989 accidentally broke `std(rand(10))`. This fixes it. --- base/statistics.jl | 2 +- test/statistics.jl | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/base/statistics.jl b/base/statistics.jl index e358e197d6cad..cf681b6d45fc6 100644 --- a/base/statistics.jl +++ b/base/statistics.jl @@ -296,7 +296,7 @@ _std(A::AbstractArray{<:AbstractFloat}, corrected::Bool, mean, dims) = sqrt!(var(A; corrected=corrected, mean=mean, dims=dims)) _std(A::AbstractArray{<:AbstractFloat}, corrected::Bool, mean, ::Colon) = - sqrt!(var(A; corrected=corrected, mean=mean)) + sqrt.(var(A; corrected=corrected, mean=mean)) std(iterable; corrected::Bool=true, mean=nothing) = sqrt(var(iterable, corrected=corrected, mean=mean)) diff --git a/test/statistics.jl b/test/statistics.jl index a9868c8b2e1ed..3d7f2c846c8f5 100644 --- a/test/statistics.jl +++ b/test/statistics.jl @@ -155,6 +155,17 @@ end @test std([1,2,3]; mean=0) ≈ sqrt(7.0) @test std([1,2,3]; mean=0, corrected=false) ≈ sqrt(14.0/3) + @test stdm([1.0,2,3], 2) ≈ 1. + @test std([1.0,2,3]) ≈ 1. + @test std([1.0,2,3]; corrected=false) ≈ sqrt(2.0/3) + @test std([1.0,2,3]; mean=0) ≈ sqrt(7.0) + @test std([1.0,2,3]; mean=0, corrected=false) ≈ sqrt(14.0/3) + + @test std([1.0,2,3]; dims=1)[] ≈ 1. + @test std([1.0,2,3]; dims=1, corrected=false)[] ≈ sqrt(2.0/3) + @test std([1.0,2,3]; dims=1, mean=[0])[] ≈ sqrt(7.0) + @test std([1.0,2,3]; dims=1, mean=[0], corrected=false)[] ≈ sqrt(14.0/3) + @test stdm((1,2,3), 2) ≈ 1. @test std((1,2,3)) ≈ 1. @test std((1,2,3); corrected=false) ≈ sqrt(2.0/3) @@ -409,9 +420,8 @@ end @testset "Issue #17153 and PR #17154" begin a = rand(10,10) - b = deepcopy(a) + b = copy(a) x = median(a, dims=1) - @test b == a x = median(a, dims=2) @test b == a