Skip to content

Commit c169110

Browse files
authored
add isdisk method (#213)
* add isdisk method * test isdisk
1 parent 6fffd5d commit c169110

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/diskarray.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ n-dimensional (hyper)-rectangles.
77
"""
88
abstract type AbstractDiskArray{T,N} <: AbstractArray{T,N} end
99

10+
"""
11+
isdisk(a::AbstractArray)
12+
13+
Return `true` if `a` is a `AbstractDiskArray` or follows
14+
the DiskArrays.jl interface via macros. Otherwise `false`.
15+
"""
16+
isdisk(a::AbstractDiskArray) = true
17+
isdisk(a::AbstractArray) = false
18+
1019
"""
1120
readblock!(A::AbstractDiskArray, A_ret, r::AbstractUnitRange...)
1221
@@ -367,6 +376,7 @@ include("chunks.jl")
367376
macro implement_getindex(t)
368377
t = esc(t)
369378
quote
379+
isdisk(a::$t) = true
370380
Base.getindex(a::$t, i...) = getindex_disk(a, i...)
371381
@inline Base.getindex(a::$t, i::ChunkIndex{<:Any,OneBasedChunks}) =
372382
a[eachchunk(a)[i.I]...]

test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ end
3535
@test a[CartesianIndex(1,2),3] == 15
3636
@test a[CartesianIndex(1,2,3)] == 15
3737
end
38+
@testset "isdisk" begin
39+
a = reshape(1:24, 2, 3, 4)
40+
da = AccessCountDiskArray(a; chunksize=(2, 2, 2))
41+
@test DiskArrays.isdisk(da)
42+
@test !DiskArrays.isdisk(a)
43+
end
3844

3945
@testset "getindex with empty array" begin
4046
a = AccessCountDiskArray(reshape(1:24,2,3,4),chunksize=(2,2,2))

0 commit comments

Comments
 (0)