Skip to content
This repository has been archived by the owner on Apr 26, 2023. It is now read-only.

Commit

Permalink
added sampletype for sparsecat
Browse files Browse the repository at this point in the history
  • Loading branch information
zsunberg committed Oct 13, 2017
1 parent 276847b commit c4236f5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/distributions/sparse_cat.jl
Expand Up @@ -68,6 +68,7 @@ Base.done(d::SparseCat{V,P}, state::Integer) where {V<:AbstractArray, P<:Abstrac

Base.length(d::SparseCat) = min(length(d.vals), length(d.probs))
Base.eltype(D::Type{SparseCat{V,P}}) where {V, P} = Pair{eltype(V), eltype(P)}
sampletype(D::Type{SparseCat{V,P}}) where {V, P} = eltype(V)

function Base.mean(d::SparseCat)
vsum = zero(eltype(d.vals))
Expand Down
2 changes: 2 additions & 0 deletions test/test_sparse_cat.jl
Expand Up @@ -5,6 +5,8 @@ let
@test pdf(d, :c) == 0.0
@test pdf(d, :a) == 0.4
@test mode(d) == :b
@test sampletype(d) == Symbol
@test sampletype(typeof(d)) == Symbol
@inferred rand(Base.GLOBAL_RNG, d)

rng = MersenneTwister(14)
Expand Down

0 comments on commit c4236f5

Please sign in to comment.