Skip to content

Commit

Permalink
Relax Gamma Sampler types (#957)
Browse files Browse the repository at this point in the history
* Relax Gamma Sampler types (#956)

*relax T into Real in gamma sampler

* Fixed to keep the T type dispatch, also added a test in dirichlet.

* Update src/samplers/gamma.jl

Co-Authored-By: Mathieu Besançon <[email protected]>
  • Loading branch information
dinarior and matbesancon committed Aug 22, 2019
1 parent 4cd28a8 commit d493ab5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/samplers/gamma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function GammaGDSampler(g::Gamma{T}) where {T}
c = 0.1515/s
end

GammaGDSampler(a,s2,s,i2s,d,q0,T(b),T(σ),T(c),scale(g))
GammaGDSampler(T(a), T(s2), T(s), T(i2s), T(d), T(q0), T(b), T(σ), T(c), scale(g))
end

function calc_q(s::GammaGDSampler, t)
Expand Down
14 changes: 14 additions & 0 deletions test/dirichlet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,23 @@ x = func[2](d, 10)
@test isa(x, Matrix{Float64})
@test size(x) == (3, 10)

v = [2.0, 1.0, 3.0]
d = Dirichlet(Float32.(v))

x = func[1](d)
@test isa(x, Vector{Float32})
@test length(x) == 3

x = func[2](d, 10)
@test isa(x, Matrix{Float32})
@test size(x) == (3, 10)


# Test MLE

v = [2.0, 1.0, 3.0]
d = Dirichlet(v)

n = 10000
x = func[2](d, n)
x = x ./ sum(x, dims=1)
Expand Down

0 comments on commit d493ab5

Please sign in to comment.