Skip to content

Commit

Permalink
Fix views of unchunked diskarrays (#52)
Browse files Browse the repository at this point in the history
* Fix views of unchunked diskarrays

* Bump version
  • Loading branch information
meggart authored Feb 15, 2022
1 parent e3886ce commit 39a2de3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
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.0"
version = "0.3.1"

[compat]
julia = "1.6"
Expand Down
2 changes: 1 addition & 1 deletion src/subarrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ function eachchunk_view(::Chunked, vv)
newchunks = [subsetchunks(chunksparent.chunks[i], pinds[i]) for i in 1:length(pinds) if !in(i,iomit)]
GridChunks(newchunks...)
end
eachchunk_view(::Unchunked, a) = GridChunks(a,estimate_chunksize(a))
eachchunk_view(::Unchunked, a) = estimate_chunksize(a)
haschunks(a::SubDiskArray) = haschunks(parent(a.v))
20 changes: 20 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ function DiskArrays.writeblock!(a::_DiskArray,v,i::AbstractUnitRange...)
view(a.parent,i...) .= v
end

struct UnchunkedDiskArray{T,N,P<:AbstractArray{T,N}} <: AbstractDiskArray{T,N}
p::P
end
DiskArrays.haschunks(::UnchunkedDiskArray) = DiskArrays.Unchunked()
Base.size(a::UnchunkedDiskArray) = size(a.p)
function DiskArrays.readblock!(a::UnchunkedDiskArray,aout,i::AbstractUnitRange...)
ndims(a) == length(i) || error("Number of indices is not correct")
all(r->isa(r,AbstractUnitRange),i) || error("Not all indices are unit ranges")
#println("reading from indices ", join(string.(i)," "))
aout .= a.p[i...]
end


function test_getindex(a)
@test a[2,3,1] == 10
@test a[2,3] == 10
Expand Down Expand Up @@ -204,6 +217,13 @@ end
@test DiskArrays.max_chunksize(gridc) == (5,2,4)
end

@testset "Unchunked DiskArrays" begin
a = UnchunkedDiskArray(reshape(1:1000,(10,20,5)))
v = view(a,1:2,1,1:3)
@test v == [1 201 401; 2 202 402]
end


@testset "Index interpretation" begin
import DiskArrays: DimsDropper, Reshaper
a = zeros(3,3,1)
Expand Down

2 comments on commit 39a2de3

@meggart
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/54693

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.3.1 -m "<description of version>" 39a2de3a2cc11e9932164a790bf28987777c3d6a
git push origin v0.3.1

Please sign in to comment.