Skip to content

Commit

Permalink
tests[cartesian]: Increase horizontal region test coverage (#1851)
Browse files Browse the repository at this point in the history
## Description

A a test case where horizontal regions are used to write to a subset of
the field. Note that this is different from
`TestHorizontalRegionsCorners` because we have specialized optimizations
in place for corners of the cube.

Related issue: #720

## Requirements

- [x] All fixes and/or new features come with corresponding tests.
  New tests added
- [ ] Important design decisions have been documented in the appropriate
ADR inside the [docs/development/ADRs/](docs/development/ADRs/Index.md)
folder.
  N/A

Co-authored-by: Roman Cattaneo <[email protected]>
  • Loading branch information
romanc and romanc authored Feb 10, 2025
1 parent 4b566d7 commit 05b3b87
Showing 1 changed file with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,13 @@ def validation(field_in, field_out, *, domain, origin):
field_out[:, -1, :] = field_in[:, -1, :] - 1.0


class TestHorizontalRegionsCorners(gt_testing.StencilTestSuite):
class TestHorizontalRegionsPartialWrites(gt_testing.StencilTestSuite):
"""Use horizontal regions to only write to certain parts of the field.
This test is different from the corner case below because the corner
case follows a different code path (we have specific optimizations for
them)."""

dtypes = {"field_in": np.float32, "field_out": np.float32}
domain_range = [(4, 4), (4, 4), (2, 2)]
backends = ALL_BACKENDS
Expand All @@ -885,8 +891,40 @@ class TestHorizontalRegionsCorners(gt_testing.StencilTestSuite):
in_range=(-10, 10), axes="IJK", boundary=[(0, 0), (0, 0), (0, 0)]
),
"field_out": gt_testing.field(
in_range=(42, 42), axes="IJK", boundary=[(0, 0), (0, 0), (0, 0)]
),
}

def definition(field_in, field_out):
with computation(PARALLEL), interval(...):
with horizontal(region[I[0], :], region[I[-1], :]):
field_out = ( # noqa: F841 [unused-variable]
field_in + 1.0
)
with horizontal(region[:, J[0]], region[:, J[-1]]):
field_out = ( # noqa: F841 [unused-variable]
field_in - 1.0
)

def validation(field_in, field_out, *, domain, origin):
field_out[:, :, :] = 42
field_out[0, :, :] = field_in[0, :, :] + 1.0
field_out[-1, :, :] = field_in[-1, :, :] + 1.0
field_out[:, 0, :] = field_in[:, 0, :] - 1.0
field_out[:, -1, :] = field_in[:, -1, :] - 1.0


class TestHorizontalRegionsCorners(gt_testing.StencilTestSuite):
dtypes = {"field_in": np.float32, "field_out": np.float32}
domain_range = [(4, 4), (4, 4), (2, 2)]
backends = ALL_BACKENDS
symbols = {
"field_in": gt_testing.field(
in_range=(-10, 10), axes="IJK", boundary=[(0, 0), (0, 0), (0, 0)]
),
"field_out": gt_testing.field(
in_range=(42, 42), axes="IJK", boundary=[(0, 0), (0, 0), (0, 0)]
),
}

def definition(field_in, field_out):
Expand All @@ -901,6 +939,7 @@ def definition(field_in, field_out):
)

def validation(field_in, field_out, *, domain, origin):
field_out[:, :, :] = 42
field_out[0:2, 0:2, :] = field_in[0:2, 0:2, :] + 1.0
field_out[-3:-1, -3:-1, :] = field_in[-3:-1, -3:-1, :] + 1.0
field_out[0:2, -3:-1, :] = field_in[0:2, -3:-1, :] - 1.0
Expand Down

0 comments on commit 05b3b87

Please sign in to comment.