Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix std(::AbstractArray{<:AbstractFloat}) #26186

Merged
merged 1 commit into from
Feb 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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