Skip to content

Commit

Permalink
Fix missing stdm method with dims argument (#81)
Browse files Browse the repository at this point in the history
`stdm` is missing a "dims" argument which is documented but has not actually been added.
  • Loading branch information
ParadaCarleton authored Feb 7, 2022
1 parent 2048f5b commit 61a021b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/Statistics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,6 @@ function sqrt!(A::AbstractArray)
A
end

stdm(A::AbstractArray, m; corrected::Bool=true) =
sqrt.(varm(A, m; corrected=corrected))

"""
std(itr; corrected::Bool=true, mean=nothing[, dims])
Expand Down Expand Up @@ -467,7 +464,7 @@ std(iterable; corrected::Bool=true, mean=nothing) =
sqrt(var(iterable, corrected=corrected, mean=mean))

"""
stdm(itr, mean; corrected::Bool=true)
stdm(itr, mean; corrected::Bool=true[, dims])
Compute the sample standard deviation of collection `itr`, with known mean(s) `mean`.
Expand All @@ -490,8 +487,11 @@ over dimensions. In that case, `mean` must be an array with the same shape as
Use the [`skipmissing`](@ref) function to omit `missing` entries and compute the
standard deviation of non-missing values.
"""
stdm(A::AbstractArray, m::AbstractArray; corrected::Bool=true, dims=:) =
_std(A, corrected, m, dims)

stdm(iterable, m; corrected::Bool=true) =
std(iterable, corrected=corrected, mean=m)
sqrt(var(iterable, corrected=corrected, mean=m))


###### covariance ######
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ end
@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 stdm([1.0,2,3], [0]; dims=1, 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)
Expand All @@ -270,6 +271,8 @@ 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 2 3 4 5; 6 7 8 9 10], [3.0,8.0], dims=2) sqrt.([2.5 2.5]')
@test stdm([1 2 3 4 5; 6 7 8 9 10], [3.0,8.0], dims=2; corrected=false) sqrt.([2.0 2.0]')
@test std([1 2 3 4 5; 6 7 8 9 10], dims=2) sqrt.([2.5 2.5]')
@test std([1 2 3 4 5; 6 7 8 9 10], dims=2; corrected=false) sqrt.([2.0 2.0]')

Expand Down

0 comments on commit 61a021b

Please sign in to comment.