Skip to content

Commit

Permalink
Bugfix for 1D block indexing
Browse files Browse the repository at this point in the history
  • Loading branch information
smillerc committed Sep 28, 2022
1 parent 719ea1d commit f1d6e71
Show file tree
Hide file tree
Showing 3 changed files with 32 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 = "BlockHaloArrays"
uuid = "8029ca6b-11ad-4a59-88a2-2e6eee4ef8a2"
authors = ["Sam Miller <[email protected]> and contributors"]
version = "0.4.1"
version = "0.4.2"

[deps]
EllipsisNotation = "da5c29d0-fa7d-589e-88eb-ea29b0a81949"
Expand Down
2 changes: 1 addition & 1 deletion src/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions test/unit/test_util_funcs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

2 comments on commit f1d6e71

@smillerc
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/69150

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.4.2 -m "<description of version>" f1d6e7164d5bbd37fa399fad3a6305be4f7f732f
git push origin v0.4.2

Please sign in to comment.