Skip to content

Commit

Permalink
Remove strict coupling between continuous/discrete distributions and …
Browse files Browse the repository at this point in the history
…support types
  • Loading branch information
Gord Stephen committed Dec 24, 2017
1 parent b785e28 commit dce5af4
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/src/extends.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Whereas this package already provides a large collection of common distributions

Generally, you don't have to implement every API method listed in the documentation. This package provides a series of generic functions that turn a small number of internal methods into user-end API methods. What you need to do is to implement this small set of internal methods for your distributions.

By default, `Discrete` sampleables have support of type `Int` while `Continuous` sampleables have support of type `Float64`. If this assumption does not hold for your new distribution or sampler, or its `ValueSupport` is neither `Discrete` nor `Continuous`, you should implement the `eltype` method in addition to the other methods listed below.

**Note:** the methods need to be implemented are different for distributions of different variate forms.


Expand Down
2 changes: 1 addition & 1 deletion docs/src/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ It has two type parameters that define the kind of samples that can be drawn the
--- | --- |---
`Univariate` | a scalar number | A numeric array of arbitrary shape, each element being a sample
`Multivariate` | a numeric vector | A matrix, each column being a sample
`Matrixvariate` | a numeric matrix | An array of matrices, each element being a sample matrix
`Matrixvariate` | a numeric matrix | An array of matrices, each element being a sample matrix

### ValueSupport

Expand Down
4 changes: 0 additions & 4 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ abstract type ValueSupport end
mutable struct Discrete <: ValueSupport end
mutable struct Continuous <: ValueSupport end

Base.eltype(::Type{Discrete}) = Int
Base.eltype(::Type{Continuous}) = Float64

## Sampleable

abstract type Sampleable{F<:VariateForm,S<:ValueSupport} end
Expand Down Expand Up @@ -42,7 +39,6 @@ The default element type of a sample. This is the type of elements of the sample
by the `rand` method. However, one can provide an array of different element types to
store the samples using `rand!`.
"""
Base.eltype(s::Sampleable{F,S}) where {F,S} = eltype(S)
Base.eltype(s::Sampleable{F,Discrete}) where {F} = Int
Base.eltype(s::Sampleable{F,Continuous}) where {F} = Float64

Expand Down
2 changes: 1 addition & 1 deletion src/mixtures/mixturemodel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ function _cwise_logpdf!(r::AbstractMatrix, d::AbstractMixtureModel, X)
if d isa UnivariateMixture
view(r,:,i) .= logpdf.(component(d, i), X)
else
logpdf!(view(r,:,i), component(d, i), X)
logpdf!(view(r,:,i), component(d, i), X)
end
end
r
Expand Down

0 comments on commit dce5af4

Please sign in to comment.