Skip to content

Commit d9462c3

Browse files
sethaxenasinghvi17
andauthored
Fix iteration for 0-dimensional disk arrays (#293)
* test: Add breaking iter test for 0-dim arrays * fix: Fix iteration for 0-dim arrays * chore: Increment patch number * fix: Model iteration on method for Arrays * fix: remove Tuple type param from chunked _iterate_disk to resolve ambiguity * chore: Increment patch number * Update src/iterator.jl Co-authored-by: Anshul Singhvi <anshulsinghvi@gmail.com> --------- Co-authored-by: Anshul Singhvi <anshulsinghvi@gmail.com>
1 parent bfca243 commit d9462c3

3 files changed

Lines changed: 16 additions & 7 deletions

File tree

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "DiskArrays"
22
uuid = "3c3547ce-8d99-4f5e-a174-61eb10b00ae3"
33
authors = ["Fabian Gans <fgans@bgc-jena.mpg.de>"]
4-
version = "0.4.21"
4+
version = "0.4.22"
55

66
[deps]
77
ConstructionBase = "187b0558-2788-49d3-abe0-74a17ed4e7c9"

src/iterator.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ end
6161
# Implementaion macros
6262

6363
# Nested iteration over chunks
64-
@noinline function _iterate_disk(
65-
a::AbstractArray{T}, i::I
66-
) where {T,I<:Tuple{A,B,C}} where {A,B,C}
64+
@noinline function _iterate_disk(a::AbstractArray{T}, i::I) where {T, I}
6765
# Split the data, block indices and state from the iterator
68-
currentdata::A, blockinds::B, state::C = i
66+
currentdata, blockinds, state = i
6967
# And split the block stat into the chunk iterator and inner indices
7068
(chunkstate, innerstate) = state
7169
# Need to check now as state will be updated
@@ -84,13 +82,15 @@ end
8482
newchunk = newinnerstate.itr.indices
8583
# Get a new chunk of data
8684
newdata = OffsetArray(a[newchunk...], newinnerstate.itr)
87-
return newdata[i]::T, (newdata, blockinds, newstate)::I
85+
return newdata[i]::T, (newdata, blockinds, newstate)
8886
else
8987
# Current chunk still has values left to iterate over
90-
return currentdata[i]::T, (currentdata, blockinds, newstate)::I
88+
return currentdata[i]::T, (currentdata, blockinds, newstate)
9189
end
9290
end
9391
end
92+
_iterate_disk(a::AbstractArray{<:Any,0}, i=1) = i == 1 ? (@inbounds a[i], 2) : nothing
93+
9494
@noinline function _iterate_disk(a)
9595
# Get the indices for each chunk of data
9696
blockinds = BlockedIndices(eachchunk(a))

test/runtests.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,15 @@ end
387387
end
388388
end
389389

390+
# https://github.com/JuliaIO/DiskArrays.jl/issues/289
391+
@testset "iteration works for 0-dimensional arrays" begin
392+
a = UnchunkedDiskArray(fill(42))
393+
@test iterate(a) == (42, 2)
394+
@test iterate(a, 1) == (42, 2)
395+
@test iterate(a, 2) === nothing
396+
@test collect(a) == fill(42)
397+
end
398+
390399
@testset "Views" begin
391400
a = AccessCountDiskArray(zeros(Int, 4, 5, 1))
392401
test_view(a)

0 commit comments

Comments
 (0)