Skip to content

allow empty chunks #220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
14 changes: 10 additions & 4 deletions src/chunks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ struct RegularChunks <: ChunkType
offset::Int
s::Int
function RegularChunks(cs::Integer, offset::Integer, s::Integer)
cs>0 || throw(ArgumentError("Chunk sizes must be strictly positive"))
-1 < offset < cs || throw(ArgumentError("Offsets must be positive and smaller than the chunk size"))
cs >= 0 || throw(ArgumentError("Chunk sizes must be strictly positive"))
(cs == 0 && offset == 0) || (-1 < offset < cs) ||
throw(ArgumentError("Offsets must be positive and smaller than the chunk size"))
s >= 0 || throw(ArgumentError("Negative dimension lengths are not allowed"))
new(Int(cs), Int(offset), Int(s))
end
Expand All @@ -33,10 +34,15 @@ end
# Base methods

function Base.getindex(r::RegularChunks, i::Int)
@boundscheck checkbounds(r, i)
return max((i - 1) * r.cs + 1 - r.offset, 1):min(i * r.cs - r.offset, r.s)
end
Base.size(r::RegularChunks, _) = div(r.s + r.offset - 1, r.cs) + 1
function Base.size(r::RegularChunks, n)
if r.cs == 0 || r.s == 0
0
else
div(r.s + r.offset - 1, r.cs) + 1
end
end
Base.size(r::RegularChunks) = (size(r, 1),)

# DiskArrays interface
Expand Down
Loading