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