@@ -38,31 +38,17 @@ julia> var(d) # var of marginals
38
38
(x = 1.0, y = [0.031746031746031744, 0.031746031746031744])
39
39
```
40
40
"""
41
- struct ProductNamedTupleDistribution{Tnames,Tdists,S<: ValueSupport ,eltypes } < :
41
+ struct ProductNamedTupleDistribution{Tnames,Tdists,S<: ValueSupport } < :
42
42
Distribution{NamedTupleVariate{Tnames},S}
43
43
dists:: NamedTuple{Tnames,Tdists}
44
44
end
45
45
function ProductNamedTupleDistribution (
46
46
dists:: NamedTuple{K,V}
47
47
) where {K,V<: Tuple{Distribution,Vararg{Distribution}} }
48
48
vs = _product_valuesupport (values (dists))
49
- eltypes = _product_namedtuple_eltype (values (dists))
50
- return ProductNamedTupleDistribution {K,V,vs,eltypes} (dists)
49
+ return ProductNamedTupleDistribution {K,V,vs} (dists)
51
50
end
52
51
53
- _gentype (d:: UnivariateDistribution ) = eltype (d)
54
- _gentype (d:: Distribution{<:ArrayLikeVariate{S}} ) where {S} = Array{eltype (d),S}
55
- function _gentype (d:: Distribution{CholeskyVariate} )
56
- T = eltype (d)
57
- return LinearAlgebra. Cholesky{T,Matrix{T}}
58
- end
59
- function _gentype (d:: ProductNamedTupleDistribution{K} ) where {K}
60
- return NamedTuple{K,Tuple{map (_gentype, values (d. dists))... }}
61
- end
62
- _gentype (:: Distribution ) = Any
63
-
64
- _product_namedtuple_eltype (dists) = typejoin (map (_gentype, dists)... )
65
-
66
52
function Base. show (io:: IO , d:: ProductNamedTupleDistribution )
67
53
return show_multline (io, d, collect (pairs (d. dists)))
68
54
end
88
74
89
75
# Properties
90
76
91
- Base. eltype (:: Type{<:ProductNamedTupleDistribution{<:Any,<:Any,<:Any,T}} ) where {T} = T
92
-
93
77
Base. minimum (d:: ProductNamedTupleDistribution ) = map (minimum, d. dists)
94
78
95
79
Base. maximum (d:: ProductNamedTupleDistribution ) = map (maximum, d. dists)
166
150
function Base. rand (
167
151
rng:: AbstractRNG , d:: ProductNamedTupleDistribution{K} , dims:: Dims
168
152
) where {K}
169
- return convert (AbstractArray{ <: NamedTuple{K} }, _rand ( rng, sampler (d), dims) )
153
+ return rand ( rng, sampler (d), dims)
170
154
end
171
155
172
- function _rand ! (rng:: AbstractRNG , d:: ProductNamedTupleDistribution , xs:: AbstractArray )
173
- return _rand ! (rng, sampler (d), xs)
156
+ Base . @propagate_inbounds function Base . rand ! (rng:: AbstractRNG , d:: ProductNamedTupleDistribution , xs:: AbstractArray )
157
+ return rand ! (rng, sampler (d), xs)
174
158
end
0 commit comments