Skip to content

Commit

Permalink
Added the offset kwarg to domainview()
Browse files Browse the repository at this point in the history
  • Loading branch information
smillerc committed Sep 30, 2022
1 parent 354c23f commit 3502fe3
Show file tree
Hide file tree
Showing 3 changed files with 30 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.4"
version = "0.4.5"

[deps]
EllipsisNotation = "da5c29d0-fa7d-589e-88eb-ea29b0a81949"
Expand Down
14 changes: 13 additions & 1 deletion src/BlockHaloArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,22 @@ end
Get the SubArray view of the domain region of a block in the BlockHaloArray.
"""
function domainview(A::BlockHaloArray, blockid::Integer)
function domainview(A::BlockHaloArray, blockid::Integer;offset=0)

if offset > A.nhalo
error("offset must be <= nhalo")
end

if offset < 0
error("offset must be > 0")
end

_, _, lo_dom_start, _ = lo_indices(A.blocks[blockid], A.nhalo)
_, hi_dom_end, _, _ = hi_indices(A.blocks[blockid], A.nhalo)

lo_dom_start = lo_dom_start .- offset
hi_dom_end = hi_dom_end .+ offset

idx_range = UnitRange.(lo_dom_start, hi_dom_end)
idx_range_vec = collect(idx_range)
for dim in eachindex(idx_range_vec)
Expand Down
16 changes: 16 additions & 0 deletions test/unit/test_util_funcs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
@test size(haloview(A, 1, :jhi)) == (25, 2)
end

@testitem "domainview" begin
include("common.jl")
nhalo = 3
nblocks = 4
dims = (40,40)
A = BlockHaloArray(dims, nhalo, nblocks)

blockid = 1
@test size(domainview(A, blockid)) == (20, 20)
@test size(domainview(A, blockid; offset=1)) == (22, 22)
@test size(domainview(A, blockid; offset=2)) == (24, 24)
@test size(domainview(A, blockid; offset=3)) == (26, 26)
@test_throws ErrorException domainview(A, blockid; offset=4)
@test_throws ErrorException domainview(A, blockid; offset=-1)
end

@testitem "nblocks" begin
include("common.jl")
A = BlockHaloArray((50,50), 2, 4)
Expand Down

2 comments on commit 3502fe3

@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/69285

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.5 -m "<description of version>" 3502fe3a63ca12bfdc0c3a9c7e207270b5e71c9e
git push origin v0.4.5

Please sign in to comment.