Skip to content
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
19 changes: 19 additions & 0 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: format-check

on:
push:
branches:
- 'master'
- 'main'
- 'release-'
tags: '*'
pull_request:

jobs:
runic:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: fredrikekre/runic-action@v1
with:
version: '1'
24 changes: 12 additions & 12 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
using LightweightStats
using Documenter

DocMeta.setdocmeta!(LightweightStats, :DocTestSetup, :(using LightweightStats); recursive=true)
DocMeta.setdocmeta!(LightweightStats, :DocTestSetup, :(using LightweightStats); recursive = true)

makedocs(;
modules=[LightweightStats],
authors="ChrisRackauckas <contact@chrisrackauckas.com>",
sitename="LightweightStats.jl",
format=Documenter.HTML(;
canonical="https://SciML.github.io/LightweightStats.jl",
edit_link="main",
assets=String[],
modules = [LightweightStats],
authors = "ChrisRackauckas <contact@chrisrackauckas.com>",
sitename = "LightweightStats.jl",
format = Documenter.HTML(;
canonical = "https://SciML.github.io/LightweightStats.jl",
edit_link = "main",
assets = String[],
),
pages=[
pages = [
"Home" => "index.md",
"API Reference" => "api.md",
],
)

deploydocs(;
repo="github.com/SciML/LightweightStats.jl",
devbranch="main",
)
repo = "github.com/SciML/LightweightStats.jl",
devbranch = "main",
)
22 changes: 11 additions & 11 deletions src/LightweightStats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ For uncorrected variance:
function var(A::AbstractArray; corrected::Bool = true, mean = nothing, dims = :)
if dims === (:)
n = length(A)
isempty(A) && return oftype(real(zero(eltype(A)))/1, NaN)
isempty(A) && return oftype(real(zero(eltype(A))) / 1, NaN)
m = mean === nothing ? LightweightStats.mean(A) : mean
s = sum(x -> abs2(x - m), A)
return corrected ? s / (n - 1) : s / n
Expand Down Expand Up @@ -304,7 +304,7 @@ julia> std(A; dims=1)
"""
function std(A::AbstractArray; corrected::Bool = true, mean = nothing, dims = :)
return dims === (:) ? sqrt(var(A; corrected = corrected, mean = mean)) :
sqrt.(var(A; corrected = corrected, mean = mean, dims = dims))
sqrt.(var(A; corrected = corrected, mean = mean, dims = dims))
end

"""
Expand Down Expand Up @@ -343,7 +343,7 @@ Throws `DimensionMismatch` if vectors have different lengths.
function cov(x::AbstractVector, y::AbstractVector; corrected::Bool = true)
n = length(x)
length(y) == n || throw(DimensionMismatch("x and y must have the same length"))
n == 0 && return oftype(real(zero(eltype(x)))/1, NaN)
n == 0 && return oftype(real(zero(eltype(x))) / 1, NaN)

xmean = mean(x)
ymean = mean(y)
Expand Down Expand Up @@ -423,11 +423,11 @@ Throws `ArgumentError` if dims is not 1 or 2.
function cov(X::AbstractMatrix; dims::Int = 1, corrected::Bool = true)
if dims == 1
n, p = size(X)
n == 0 && return fill(oftype(real(zero(eltype(X)))/1, NaN), p, p)
n == 0 && return fill(oftype(real(zero(eltype(X))) / 1, NaN), p, p)

means = vec(mean(X; dims = 1))
C = zeros(float(real(eltype(X))), p, p)

# Center the data once using broadcasting
X_centered = X .- means'

Expand All @@ -444,11 +444,11 @@ function cov(X::AbstractMatrix; dims::Int = 1, corrected::Bool = true)
return C
elseif dims == 2
n, p = size(X')
n == 0 && return fill(oftype(real(zero(eltype(X)))/1, NaN), p, p)
n == 0 && return fill(oftype(real(zero(eltype(X))) / 1, NaN), p, p)

means = vec(mean(X; dims = 2))
C = zeros(float(real(eltype(X))), p, p)

# Center the data once using broadcasting
X_centered = X .- means

Expand Down Expand Up @@ -515,7 +515,7 @@ function cor(x::AbstractVector, y::AbstractVector)
sx = std(x; corrected = false)
sy = std(y; corrected = false)

(sx == 0 || sy == 0) && return oftype(real(zero(eltype(x)))/1, NaN)
(sx == 0 || sy == 0) && return oftype(real(zero(eltype(x))) / 1, NaN)

return cov(x, y; corrected = false) / (sx * sy)
end
Expand Down Expand Up @@ -569,11 +569,11 @@ function cor(X::AbstractMatrix; dims::Int = 1)
# Use broadcasting to compute correlation matrix
# Create outer product of standard deviations
s_outer = s * s'

# Handle zero variance cases with broadcasting
R = similar(C)
zero_mask = (s_outer .== 0)
R[zero_mask] .= oftype(real(zero(eltype(X)))/1, NaN)
R[zero_mask] .= oftype(real(zero(eltype(X))) / 1, NaN)
R[.!zero_mask] = C[.!zero_mask] ./ s_outer[.!zero_mask]

return R
Expand Down Expand Up @@ -810,4 +810,4 @@ using PrecompileTools: @compile_workload
cor(X)
end

end
end
Loading
Loading