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

Added default impls for filldist and arraydist #264

Merged
merged 3 commits into from
Apr 17, 2024
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: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "DistributionsAD"
uuid = "ced4e74d-a319-5a8a-b0ac-84af2272839c"
version = "0.6.54"
version = "0.6.55"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
7 changes: 7 additions & 0 deletions src/arraydist.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
"""
arraydist(dists)

Create a distribution from an array of distributions.
"""
arraydist(dists::AbstractArray{<:Distribution}) = product_distribution(dists)

# Univariate

const VectorOfUnivariate = Distributions.Product
Expand Down
11 changes: 10 additions & 1 deletion src/filldist.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Default implementation just defers to Distributions.jl.
"""
filldist(d::Distribution, ns...)

Create a product distribution using `FillArrays.Fill` as the array type.
"""
filldist(d::Distribution, n1::Int, ns::Int...) = product_distribution(Fill(d, n1, ns...))

# Univariate

# TODO: Do we even need these? Probably should benchmark to be sure.
const FillVectorOfUnivariate{
S <: ValueSupport,
T <: UnivariateDistribution{S},
Expand Down Expand Up @@ -59,7 +68,7 @@ const FillMatrixOfUnivariate{
Tdists <: Fill{T, 2},
} = MatrixOfUnivariate{S, T, Tdists}

function filldist(dist::UnivariateDistribution, N1::Integer, N2::Integer)
function filldist(dist::UnivariateDistribution, N1::Int, N2::Int)
return MatrixOfUnivariate(Fill(dist, N1, N2))
end
function Distributions._logpdf(dist::FillMatrixOfUnivariate, x::AbstractMatrix{<:Real})
Expand Down
Loading