-
Notifications
You must be signed in to change notification settings - Fork 78
/
uniform.jl
29 lines (22 loc) · 858 Bytes
/
uniform.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# ------------------------------------------------------------------
# Licensed under the MIT License. See LICENSE in the project root.
# ------------------------------------------------------------------
"""
UniformPartition(k, [shuffle])
A method for partitioning spatial objects uniformly into `k` subsets
of approximately equal size. Optionally `shuffle` the data (default
to `true`).
"""
struct UniformPartition <: PartitionMethod
k::Int
shuffle::Bool
end
UniformPartition(k) = UniformPartition(k, true)
function partitioninds(rng::AbstractRNG, domain::Domain, method::UniformPartition)
n = nelements(domain)
k = method.k
@assert k ≤ n "number of subsets must be smaller than number of points"
inds = method.shuffle ? shuffle(rng, 1:n) : collect(1:n)
subsets = collect(Iterators.partition(inds, n ÷ k))
subsets, Dict()
end