|
96 | 96 | @make_array_container(BitArray) |
97 | 97 |
|
98 | 98 |
|
99 | | -## dicts |
| 99 | +## sets/dicts |
100 | 100 |
|
101 | | -# again same inference bug |
102 | | -# TODO: extend to AbstractDict ? (needs to work-around the inderence bug) |
103 | | -default_sampling(::Type{<:Dict{K,V}}) where {K,V} = Pair{K,V} |
104 | | -default_sampling(D::Type{<:Dict}) = throw(ArgumentError("under-specified scalar type for $D")) |
105 | | - |
106 | | -rand!(A::AbstractDict{K,V}, dist::Union{Type{<:Pair},Distribution{<:Pair}}=make(Pair, K, V)) where {K,V} = |
107 | | - rand!(GLOBAL_RNG, A, dist) |
108 | | - |
109 | | -rand!(rng::AbstractRNG, A::AbstractDict{K,V}, |
110 | | - dist::Union{Type{<:Pair},Distribution{<:Pair}}=make(Pair, K, V)) where {K,V} = |
111 | | - rand!(rng, A, Sampler(rng, dist)) |
112 | | - |
113 | | -function _rand!(rng::AbstractRNG, A::Union{AbstractDict,AbstractSet}, n::Integer, sp::Sampler) |
| 101 | +function _rand!(rng::AbstractRNG, A::SetDict, n::Integer, sp::Sampler) |
114 | 102 | empty!(A) |
115 | 103 | while length(A) < n |
116 | 104 | push!(A, rand(rng, sp)) |
117 | 105 | end |
118 | 106 | A |
119 | 107 | end |
120 | 108 |
|
121 | | -rand!(rng::AbstractRNG, A::AbstractDict{K,V}, sp::Sampler) where {K,V} = _rand!(rng, A, length(A), sp) |
122 | | - |
123 | | -rand(rng::AbstractRNG, dist::Distribution{P}, ::Type{T}, n::Integer) where {P<:Pair,T<:AbstractDict} = |
124 | | - _rand!(rng, deduce_type(T, fieldtype(P, 1), fieldtype(P, 2))(), n, Sampler(rng, dist)) |
125 | | - |
126 | | -rand(rng::AbstractRNG, ::Type{P}, ::Type{T}, n::Integer) where {P<:Pair,T<:AbstractDict} = rand(rng, Uniform(P), T, n) |
127 | | - |
128 | | -rand(rng::AbstractRNG, ::Type{T}, n::Integer) where {T<:AbstractDict} = rand(rng, default_sampling(T), T, n) |
129 | | - |
130 | | -rand(u::Distribution{<:Pair}, ::Type{T}, n::Integer) where {T<:AbstractDict} = rand(GLOBAL_RNG, u, T, n) |
131 | | - |
132 | | -rand(::Type{P}, ::Type{T}, n::Integer) where {P<:Pair,T<:AbstractDict} = rand(GLOBAL_RNG, Uniform(P), T, n) |
133 | | - |
134 | | -rand(::Type{T}, n::Integer) where {T<:AbstractDict} = rand(GLOBAL_RNG, default_sampling(T), T, n) |
135 | | - |
136 | | - |
137 | | -## sets |
138 | | - |
139 | | -rand!( A::AbstractSet{T}, X) where {T} = rand!(GLOBAL_RNG, A, X) |
140 | | -rand!(rng::AbstractRNG, A::AbstractSet, X) = _rand!(rng, A, length(A), sampler(rng, X)) |
141 | | -rand!( A::AbstractSet{T}, ::Type{X}=default_sampling(A)) where {T,X} = rand!(GLOBAL_RNG, A, X) |
142 | | -rand!(rng::AbstractRNG, A::AbstractSet{T}, ::Type{X}=default_sampling(A)) where {T,X} = rand!(rng, A, Sampler(rng, X)) |
| 109 | +rand!( A::SetDict, X) = rand!(GLOBAL_RNG, A, X) |
| 110 | +rand!(rng::AbstractRNG, A::SetDict, X) = _rand!(rng, A, length(A), sampler(rng, X)) |
| 111 | +rand!( A::SetDict, ::Type{X}=default_sampling(A)) where {X} = rand!(GLOBAL_RNG, A, X) |
| 112 | +rand!(rng::AbstractRNG, A::SetDict, ::Type{X}=default_sampling(A)) where {X} = rand!(rng, A, Sampler(rng, X)) |
143 | 113 |
|
144 | | -@make_container(T::Type{<:AbstractSet}, n::Integer) |
| 114 | +@make_container(T::Type{<:SetDict}, n::Integer) |
0 commit comments