Skip to content

Commit

Permalink
Improve api by passing more keywords items (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tortar authored Jan 13, 2024
1 parent df49c4b commit 18cfa11
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
10 changes: 5 additions & 5 deletions src/IteratorSampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export itsample

"""
reservoir_sample(rng, iter)
reservoir_sample(rng, iter, n, replace, ordered)
reservoir_sample(rng, iter, n; replace = false, ordered = false)
Reservoir sampling algorithm with and without replacement.
Expand All @@ -61,11 +61,11 @@ export reservoir_sample

"""
sortedindices_sample(rng, iter)
sortedindices_sample(rng, iter, n, replace, ordered)
sortedindices_sample(rng, iter, n; replace = false, ordered = false)
Faster algorithm than reservoir sampling employed when the number of elements
in the iterable is known. It generates sorted random indices which are used to
retrieve the sample from the iterable.
Algorithm which generates sorted random indices used to retrieve the sample
from the iterable. The number of elements in the iterable needs to be known
before starting the sampling.
"""
function sortedindices_sample end

Expand Down
4 changes: 2 additions & 2 deletions src/UnweightedSamplingMulti.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function itsample(rng::AbstractRNG, iter, n::Int;
if Base.IteratorSize(iter) isa Base.SizeUnknown
reservoir_sample(rng, iter, n; replace, ordered)::Vector{iter_type}
else
sortedindices_sample(rng, iter, n, replace, ordered)::Vector{iter_type}
sortedindices_sample(rng, iter, n; replace, ordered)::Vector{iter_type}
end
end

Expand Down Expand Up @@ -118,7 +118,7 @@ function choose(n, p, q, z)
return quantile(b, q)
end

function sortedindices_sample(rng, iter, n::Int, replace, ordered)
function sortedindices_sample(rng, iter, n::Int; replace = false, ordered = false)
N = length(iter)
if N <= n
reservoir = collect(iter)
Expand Down

0 comments on commit 18cfa11

Please sign in to comment.