JuliaArrays / JuliaArrays/StaticArrays.jl
Statistics extension for var and std
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 844
- Forks
- 159
- Avg merge
- 3d 21h
- Merged PRs (30d)
- 3
Description
Currently, the Statistics extension only extends the mean function. The var and std of a StaticMatrix still returns a regular Matrix.
a = @SMatrix(rand(3,4))
mean(a, dims=2) # 3×1 SMatrix
var(a, dims=2) # 3×1 Matrix
std(a, dims=2) # 3×1 Matrix
I provide a preliminary extension for var and std as follows. Attaching them to the end of StaticArraysStatisticsExt.jl should work.
using Statistics
import Statistics: var, std
@inline var(a::StaticArray;corrected::Bool=true, mean=nothing, dims=:) = begin
m = isnothing(mean) ? Statistics.mean(a; dims=dims) : mean
denom = _mean_denom(a, dims) - (corrected ? 1 : 0)
_reduce(+, (a.-m).^2, dims) / denom
end
@inline std(a::SArray; corrected::Bool=true, mean=nothing, dims=:) = sqrt.(var(a; corrected=corrected, mean=mean, dims=dims))
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with ext/StaticArraysStatisticsExt.jl and inspect how the existing mean extension handles StaticArray results. Use the issue's StaticMatrix examples to check var and std with dims=2, including corrected and supplied-mean cases. Done means these operations return statically sized results rather than regular Matrix values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- data
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100