Skip to content

Commit

Permalink
Added default impls for filldist and arraydist (#264)
Browse files Browse the repository at this point in the history
* added default impls for `filldist` and `arraydist`

* Apply suggestions from code review

Co-authored-by: David Widmann <devmotion@users.noreply.github.com>

* Update filldist.jl (#265)

---------

Co-authored-by: David Widmann <devmotion@users.noreply.github.com>
  • Loading branch information
torfjelde and devmotion committed Apr 17, 2024
1 parent b8c3d82 commit e3f8a67
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
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

2 comments on commit e3f8a67

@yebai
Copy link
Member

@yebai yebai commented on e3f8a67 Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/105101

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.6.55 -m "<description of version>" e3f8a67ada079bea6748db34e41febab53051e37
git push origin v0.6.55

Please sign in to comment.