-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix[next]: gtfn with offset name != local dimension name (#1789)
- Loading branch information
Showing
7 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
tests/next_tests/regression_tests/ffront_tests/test_offset_dimensions_names.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
# GT4Py - GridTools Framework | ||
# | ||
# Copyright (c) 2014-2024, ETH Zurich | ||
# All rights reserved. | ||
# | ||
# Please, refer to the LICENSE file in the root directory. | ||
# SPDX-License-Identifier: BSD-3-Clause | ||
|
||
import pytest | ||
|
||
from gt4py import next as gtx | ||
from gt4py.next import Dims, Field, common | ||
|
||
from next_tests import definitions as test_defs | ||
from next_tests.integration_tests import cases | ||
from next_tests.integration_tests.feature_tests.ffront_tests import ffront_test_utils | ||
|
||
|
||
V = gtx.Dimension("V") | ||
E = gtx.Dimension("E") | ||
Neigh = gtx.Dimension("Neigh", kind=common.DimensionKind.LOCAL) | ||
Off = gtx.FieldOffset("Off", source=E, target=(V, Neigh)) | ||
|
||
|
||
@pytest.fixture | ||
def case(): | ||
mesh = ffront_test_utils.simple_mesh() | ||
exec_alloc_descriptor = test_defs.ProgramBackendId.GTFN_CPU.load() | ||
v2e_arr = mesh.offset_provider["V2E"].ndarray | ||
return cases.Case( | ||
exec_alloc_descriptor, | ||
offset_provider={ | ||
"Off": common._connectivity( | ||
v2e_arr, | ||
codomain=E, | ||
domain={V: v2e_arr.shape[0], Neigh: 4}, | ||
skip_value=None, | ||
), | ||
}, | ||
default_sizes={ | ||
V: mesh.num_vertices, | ||
E: mesh.num_edges, | ||
}, | ||
grid_type=common.GridType.UNSTRUCTURED, | ||
allocator=exec_alloc_descriptor.allocator, | ||
) | ||
|
||
|
||
def test_offset_dimension_name_differ(case): | ||
""" | ||
Ensure that gtfn works with offset name that differs from the name of the local dimension. | ||
If the value of the `NeighborConnectivityType.neighbor_dim` did not match the `FieldOffset` value, | ||
gtfn would silently ignore the neighbor index, see https://github.com/GridTools/gridtools/pull/1814. | ||
""" | ||
|
||
@gtx.field_operator | ||
def foo(a: Field[Dims[E], float]) -> Field[Dims[V], float]: | ||
return a(Off[1]) | ||
|
||
cases.verify_with_default_data( | ||
case, foo, lambda a: a[case.offset_provider["Off"].ndarray[:, 1]] | ||
) |