Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
25 changes: 17 additions & 8 deletions src/DiskArrayTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -378,16 +378,25 @@ function eachchunk(aconc::ConcatDiskArray)
end

"""
ChunkedFillArray(v::T, size, chunksize)
Construct a lazy fill array with a value `v` with the n-dimensional `size` which behaves as a chunked DiskArray with chunks of the size `chunksize`.
ChunkedFillArray(value::T, size, chunks)
Construct a lazy fill array with a value `value` with the n-dimensional `size` which behaves as a chunked DiskArray with a chunking structure of `chunks`.
"""
struct ChunkedFillArray{T,N} <: AbstractDiskArray{T,N}
v::T
s::NTuple{N,Int}
chunksize::NTuple{N,Int}
value::T
arrsize::NTuple{N,Int}
chunks::GridChunks{N}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are introducing type instability here, as GridChunks{N} is an abstract type

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh ok. Then I should make the chunks a parameter of ChunkedFillArray?

ChunkedFillArray{T,N}(value, arrsize, chunksize::NTuple{N, Int}) where {T,N} = new{T,N}(value, arrsize, GridChunks(arrsize, chunksize))
ChunkedFillArray{T,N}(value, arrsize, chunks::GridChunks{N}) where {T,N} = new{T,N}(value, arrsize, chunks)
end
Base.size(x::ChunkedFillArray) = x.s
readblock!(x::ChunkedFillArray,aout,r::AbstractVector...) = aout .= x.v
eachchunk(x::ChunkedFillArray) = GridChunks(x.s,x.chunksize)

ChunkedFillArray(value::T, arrsize::NTuple{N, Int}, chunksize::NTuple{N,Int}) where {T,N} = ChunkedFillArray{T,N}(value, arrsize, GridChunks(arrsize, chunksize))
ChunkedFillArray(value::T, arrsize::NTuple{N, Int}, chunks::GridChunks{N}) where {T,N} = ChunkedFillArray{T,N}(value, arrsize, chunks)
ChunkedFillArray{T}(value, arrsize::NTuple{N, Int}, chunksize::NTuple{N,Int}) where {T,N} = ChunkedFillArray{T,N}(value, arrsize, GridChunks(arrsize, chunksize))
ChunkedFillArray{T}(value, arrsize::NTuple{N, Int}, chunks::GridChunks{N}) where {T,N} = ChunkedFillArray{T,N}(value, arrsize, chunks)


Base.size(x::ChunkedFillArray) = x.arrsize
readblock!(x::ChunkedFillArray,aout,r::AbstractVector...) = aout .= x.value
eachchunk(x::ChunkedFillArray) = x.chunks

end # module
24 changes: 24 additions & 0 deletions test/chunkedfillarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,28 @@ using DiskArrays, DiskArrayTools
@test eltype(a) == Int
@test all(==(1), a)
@test eachchunk(a) isa DiskArrays.GridChunks
afloat = ChunkedFillArray{Float64,2}(1,(100,100), (10,10))
@test eltype(afloat) == Float64
@test all(==(1.), a)
@test eachchunk(a) isa DiskArrays.GridChunks
afloat = ChunkedFillArray{Float64}(1,(100,100), (10,10))
@test eltype(afloat) == Float64
@test all(==(1.), a)
@test eachchunk(a) isa DiskArrays.GridChunks
end

@testset "Chunked Fill Array Chunks provided" begin
chunks = DiskArrays.GridChunks(DiskArrays.IrregularChunks([0,20,50,100]), DiskArrays.RegularChunks(10,0,100))
a = ChunkedFillArray(1, (100,100),chunks)
@test eltype(a) == Int
@test all(==(1), a)
@test eachchunk(a) isa DiskArrays.GridChunks
afloat = ChunkedFillArray{Float64,2}(1,(100,100), chunks)
@test eltype(afloat) == Float64
@test all(==(1.), a)
@test eachchunk(a) isa DiskArrays.GridChunks
afloat = ChunkedFillArray{Float64}(1,(100,100), chunks)
@test eltype(afloat) == Float64
@test all(==(1.), a)
@test eachchunk(a) isa DiskArrays.GridChunks
end
Loading