Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Officially allow/document overriding distribution support type #699

Merged
merged 1 commit into from
Oct 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
struct Discrete <: ValueSupport end
struct Continuous <: ValueSupport end

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

## Sampleable

"""
Expand Down Expand Up @@ -50,7 +47,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 @@ -485,7 +485,7 @@ function _cwise_logpdf!(r::AbstractMatrix, d::AbstractMixtureModel, X)
if d isa UnivariateMixture
view(r,:,i) .= logpdf.(Ref(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