From f1d6e7164d5bbd37fa399fad3a6305be4f7f732f Mon Sep 17 00:00:00 2001 From: Sam Miller Date: Wed, 28 Sep 2022 14:01:26 -0400 Subject: [PATCH] Bugfix for 1D block indexing --- Project.toml | 2 +- src/indexing.jl | 2 +- test/unit/test_util_funcs.jl | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index bc92b41..ad7a6e3 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "BlockHaloArrays" uuid = "8029ca6b-11ad-4a59-88a2-2e6eee4ef8a2" authors = ["Sam Miller and contributors"] -version = "0.4.1" +version = "0.4.2" [deps] EllipsisNotation = "da5c29d0-fa7d-589e-88eb-ea29b0a81949" diff --git a/src/indexing.jl b/src/indexing.jl index 849ef8b..1cf74ac 100644 --- a/src/indexing.jl +++ b/src/indexing.jl @@ -55,7 +55,7 @@ since the actual data within the BlockHaloArray is a series of separate blocks. the array in this manner will be slower due to the additional arithmetic need to find the global to local index conversion for each block. """ -function Base.getindex(A::BlockHaloArray{T,N,NH,NBL,AA}, global_idx::Vararg{Int,N}) where {T,N,NH,NBL,AA} +function Base.getindex(A::BlockHaloArray{T,N,NH,NBL,AA}, global_idx::NTuple{N,Int}) where {T,N,NH,NBL,AA} block_idx = ntuple(i -> get_block_idx(global_idx[A.halodims[i]], A._cummulative_blocksize_per_dim, diff --git a/test/unit/test_util_funcs.jl b/test/unit/test_util_funcs.jl index 9ee23a4..de18109 100644 --- a/test/unit/test_util_funcs.jl +++ b/test/unit/test_util_funcs.jl @@ -78,3 +78,33 @@ end @test onboundary(A, 6, :jlo) == false @test onboundary(A, 6, :jhi) == true end + +@testitem "1D Indexing" begin + include("common.jl") + x = rand(50) + nhalo = 2 + nblocks = 4 + A = BlockHaloArray(x, nhalo, nblocks) + + @test all(A[1] .== A.blocks[1]) +end + +@testitem "n-D Indexing" begin + include("common.jl") + x = rand(40, 40) + y = rand(4, 40, 40) + + nhalo = 2 + nblocks = 4 + A = BlockHaloArray(x, nhalo, nblocks) + + halodims = (2, 3) + B = BlockHaloArray(y, halodims, nhalo, nblocks) + + @test A[1] == A.blocks[1] + @test size(A[1]) == (24, 24) + @test A[1][3,3] == x[1,1] + + @test B[1][1,3,3] == y[1,1,1] + @test B[1][:,3,3] == y[:,1,1] +end