Skip to content
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
4 changes: 4 additions & 0 deletions src/SamplingInterface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ struct SequentialSampler{S}
end
Base.iterate(s::SequentialSampler) = iterate(s.s)
Base.iterate(s::SequentialSampler, state) = iterate(s.s, state)
Base.IteratorEltype(::SequentialSampler) = Base.HasEltype()
Base.eltype(::SequentialSampler) = Int
Base.IteratorSize(::SequentialSampler) = Base.HasLength()
Base.length(s::SequentialSampler) = s.s.n

"""
itsample([rng], iter, method = AlgRSWRSKIP())
Expand Down
11 changes: 9 additions & 2 deletions src/SamplingReduction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,18 @@ function reduce_samples(t::Union{TypeS,TypeUnion}, ss::BinaryHeap...)
end
function reduce_samples(ps::AbstractArray, rngs, t::Union{TypeS,TypeUnion}, ss::AbstractArray...)
nt = length(ss)
v = Vector{Vector{get_type_rs(t, ss...)}}(undef, nt)
T = get_type_rs(t, ss...)
v = Vector{Vector{T}}(undef, nt)
n = minimum(length.(ss))
ns = rand(extract_rng(rngs, 1), Multinomial(n, ps))
Threads.@threads for i in 1:nt
v[i] = sample(extract_rng(rngs, i), ss[i], ns[i]; replace = false)
s = ss[i]
vi = Vector{T}(undef, ns[i])
@inbounds for (q, j) in enumerate(SequentialSampler(extract_rng(rngs, i),
ns[i], length(s), AlgHiddenShuffle()))
vi[q] = s[j]
end
v[i] = vi
end
return reduce(vcat, v)
end
Expand Down
Loading