diff --git a/docs/src/index.md b/docs/src/index.md index b93e05d..f0f7005 100644 --- a/docs/src/index.md +++ b/docs/src/index.md @@ -21,7 +21,7 @@ julia> import Pkg; Pkg.add("ChunkSplitters") The main interface is the `chunks` iterator, and the enumeration of chunks, with `enumerate`. ```julia -chunks(array::AbstractArray; n::Int=Threads.nthreads(), distribution::Symbol=:batch) +chunks(array::AbstractArray; n::Int, distribution::Symbol=:batch) ``` This iterator returns a vector of ranges which indicates the range of indices of the input `array` for each given chunk. The `distribution` parameter is optional. If `distribution == :batch`, the ranges are consecutive (default behavior). If `distribution == :scatter`, the range is scattered over the array. diff --git a/src/ChunkSplitters.jl b/src/ChunkSplitters.jl index 1e3f9cc..2f9c884 100644 --- a/src/ChunkSplitters.jl +++ b/src/ChunkSplitters.jl @@ -5,7 +5,7 @@ using TestItems export chunks, getchunk """ - chunks(array::AbstractArray; n::Int=Threads.nthreads(), distribution::Symbol=:batch) + chunks(array::AbstractArray; n::Int, distribution::Symbol=:batch) Returns an iterator that splits the *indices* of `array` into `n`-many chunks. The iterator can be used to process chunks of `array` one after another or in parallel (e.g. with `@threads`). @@ -63,7 +63,7 @@ struct Chunk{T<:AbstractArray} end # Constructor for the chunks -function chunks(x::AbstractArray; n::Int=Threads.nthreads(), distribution::Symbol=:batch) +function chunks(x::AbstractArray; n::Int, distribution::Symbol=:batch) n >= 1 || throw(ArgumentError("n must be >= 1")) (distribution in distribution_types) || throw(ArgumentError("distribution must be one of $distribution")) Chunk{typeof(x)}(x, min(length(x), n), distribution)