Skip to content

Commit

Permalink
Merge pull request #43 from invenia/mz/var
Browse files Browse the repository at this point in the history
fix var for distributions backed by KeyedArrays
  • Loading branch information
mzgubic authored Nov 3, 2022
2 parents 4411448 + cf028f8 commit 479bf73
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "KeyedDistributions"
uuid = "2576fb08-064d-4cab-b15d-8dda7fcb9a6d"
authors = ["Invenia Technical Computing Corporation"]
version = "0.1.10"
version = "0.1.11"

[deps]
AutoHashEquals = "15f4f7f2-30c1-5605-9d31-71845cf9641f"
Expand Down
3 changes: 2 additions & 1 deletion src/KeyedDistributions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,8 @@ function Distributions.mean(d::KeyedDistribution)
end

function Distributions.var(d::KeyedDistribution)
KeyedArray(NamedDimsArray(var(distribution(d)), dimnames(d)), axiskeys(d))
v = AxisKeys.keyless_unname(var(distribution(d)))
KeyedArray(NamedDimsArray(v, dimnames(d)), axiskeys(d))
end

for f in (:cov, :cor)
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -378,4 +378,12 @@ using Test
@test ks == d
@test d == ks
end

@testset "mean and var when distribution is backed by KeyedArray" begin
ka = KeyedArray(rand(3), down=["a", "b", "c"])
kd1 = KeyedDistribution(MvNormal(ka), down=["a", "b", "c"])
kd2 = KeyedDistribution(MvNormal(AxisKeys.keyless_unname(ka)), down=["a", "b", "c"])
@test mean(kd1) == mean(kd2)
@test var(kd1) == var(kd2)
end
end

2 comments on commit 479bf73

@mzgubic
Copy link
Collaborator Author

@mzgubic mzgubic commented on 479bf73 Nov 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/71559

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.1.11 -m "<description of version>" 479bf739835f055cc96f753cfc0aa8b1b47cc3d6
git push origin v0.1.11

Please sign in to comment.