Skip to content

Commit

Permalink
Fix some small issues in multivariate sfuncs. Fix sample type from Di…
Browse files Browse the repository at this point in the history
…stributions.jl. Add a few tests.
  • Loading branch information
Michael Harradon committed Sep 16, 2024
1 parent 69a8aee commit 235e40f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/sfuncs/dist/distributions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ export DistributionsSF
struct DistributionsSF{D <: Distributions.Distribution, O} <: Dist{O}
dist::D
function DistributionsSF(dist::D) where {D <: Distributions.Distribution}
O = eltype(D)
#O = eltype(D)
# Why?
# E.g. https://github.com/JuliaStats/Distributions.jl/issues/1402
O = typeof(rand(dist))
return new{D, O}(dist)
end
function DistributionsSF{D}(params...) where {D <: Distributions.Distribution}
Expand Down
5 changes: 5 additions & 0 deletions test/test_sfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,11 @@ end

@test isapprox(expectation(sf, ()), expectation(fit_normal, ()), atol=0.1)
@test isapprox(variance(sf, ()), variance(fit_normal, ()), atol=0.1)

d = Distributions.MvNormal([1.0, 1.0], [1.0 0.5; 0.5 1.0])
mv_sfunc = DistributionsSF(d)
sample(mv_sfunc, ())
sumsfs((mv_sfunc, mv_sfunc))
end

end

0 comments on commit 235e40f

Please sign in to comment.