Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Alexander-Barth/DiskArrays.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Barth committed Oct 20, 2023
2 parents 9dbf080 + 7d297f8 commit e407f6a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DiskArrays"
uuid = "3c3547ce-8d99-4f5e-a174-61eb10b00ae3"
authors = ["Fabian Gans <[email protected]>"]
version = "0.3.20"
version = "0.3.22"

[deps]
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
Expand Down
11 changes: 11 additions & 0 deletions src/chunks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ struct RegularChunks <: ChunkType
cs::Int
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"))
s >= 0 || throw(ArgumentError("Negative dimension lengths are not allowed"))
new(Int(cs), Int(offset), Int(s))
end
end

# Base methods
Expand Down Expand Up @@ -76,6 +82,11 @@ Defines chunks along a dimension where chunk sizes are not constant but arbitrar
"""
struct IrregularChunks <: ChunkType
offsets::Vector{Int}
function IrregularChunks(offsets::Vector{Int})
first(offsets)==0 || throw(ArgumentError("First Offset of an Irregularchunk must be 0"))
all(i->offsets[i]<offsets[i+1],1:(length(offsets)-1)) || throw(ArgumentError("Offsets of an Irregularchunk must be strictly ordered"))
new(offsets)
end
end

"""
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,10 @@ end
@test size(a2) == (10,)
@test_throws BoundsError a2[0]
@test_throws BoundsError a2[11]
@test_throws ArgumentError RegularChunks(0,2,10)
@test_throws ArgumentError RegularChunks(2,-1,10)
@test_throws ArgumentError RegularChunks(2,2,10)
@test_throws ArgumentError RegularChunks(5,2,-1)
b1 = IrregularChunks(; chunksizes=[3, 3, 4, 3, 3])
@test b1[1] == 1:3
@test b1[2] == 4:6
Expand All @@ -267,6 +271,10 @@ end
@test DiskArrays.approx_chunksize(gridc) == (5, 2, 3)
@test DiskArrays.grid_offset(gridc) == (2, 0, 0)
@test DiskArrays.max_chunksize(gridc) == (5, 2, 4)
@test_throws ArgumentError IrregularChunks([1,2,3])
@test_throws ArgumentError IrregularChunks([0,5,4])
# Make sure mixed Integer types work
@test RegularChunks(Int32(5), 2, UInt32(10)) == RegularChunks(5, 2, 10)
end

@testset "SubsetChunks" begin
Expand Down

0 comments on commit e407f6a

Please sign in to comment.