Skip to content

Commit

Permalink
Fix std(::AbstractArray{<:AbstractFloat}) (#26186)
Browse files Browse the repository at this point in the history
Issue #25989 accidentally broke `std(rand(10))`.  This fixes it.
  • Loading branch information
mbauman authored and KristofferC committed Feb 24, 2018
1 parent a61ed85 commit 2174801
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion base/statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
14 changes: 12 additions & 2 deletions test/statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2174801

Please sign in to comment.