Skip to content

Commit

Permalink
refactor[next]: Frontend test refactoring part 3 (GridTools#1274)
Browse files Browse the repository at this point in the history
* moved cases.py
* changed dimensions definitions to imports
  • Loading branch information
nfarabullini authored Jun 21, 2023
1 parent 8a7e3c5 commit 5303c0b
Show file tree
Hide file tree
Showing 19 changed files with 53 additions and 75 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from gt4py.next.ffront.fbuiltins import int64
from gt4py.next.program_processors.runners import gtfn_cpu

from next_tests.integration_tests.feature_tests import cases
from next_tests.integration_tests.feature_tests.cases import (
from next_tests.integration_tests import cases
from next_tests.integration_tests.cases import (
IDim,
IField,
IJKField,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,15 @@
from gt4py.next.ffront.foast_passes.type_deduction import FieldOperatorTypeDeductionError
from gt4py.next.program_processors.runners import gtfn_cpu

from next_tests.integration_tests.feature_tests import cases
from next_tests.integration_tests.feature_tests.cases import (
from next_tests.integration_tests import cases
from next_tests.integration_tests.cases import (
C2E,
E2V,
V2E,
E2VDim,
Edge,
IDim,
Ioff,
JDim,
Joff,
KDim,
Koff,
V2EDim,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@
from gt4py.next import int32, neighbor_sum
from gt4py.next.program_processors.runners import gtfn_cpu

from next_tests.integration_tests.feature_tests import cases
from next_tests.integration_tests.feature_tests.cases import (
V2E,
Edge,
V2EDim,
Vertex,
unstructured_case,
)
from next_tests.integration_tests import cases
from next_tests.integration_tests.cases import V2E, Edge, V2EDim, Vertex, unstructured_case
from next_tests.integration_tests.feature_tests.ffront_tests.ffront_test_utils import (
fieldview_backend,
reduction_setup,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from gt4py.next import broadcast, float64, int32, int64, max_over, min_over, neighbor_sum, where
from gt4py.next.program_processors.runners import gtfn_cpu

from next_tests.integration_tests.feature_tests import cases
from next_tests.integration_tests.feature_tests.cases import (
from next_tests.integration_tests import cases
from next_tests.integration_tests.cases import (
V2E,
Edge,
IDim,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@
from gt4py.next.ffront.foast_passes.type_deduction import FieldOperatorTypeDeduction
from gt4py.next.type_system import type_translation

from next_tests.integration_tests.feature_tests import cases
from next_tests.integration_tests.feature_tests.cases import IDim, cartesian_case, unstructured_case
from next_tests.integration_tests.feature_tests.ffront_tests.ffront_test_utils import *
from next_tests.integration_tests import cases
from next_tests.integration_tests.cases import IDim, cartesian_case, unstructured_case
from next_tests.integration_tests.feature_tests.ffront_tests.ffront_test_utils import (
fieldview_backend,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
)
from gt4py.next.program_processors.runners import gtfn_cpu

from next_tests.integration_tests.feature_tests import cases
from next_tests.integration_tests.feature_tests.cases import IDim, cartesian_case, unstructured_case
from next_tests.integration_tests import cases
from next_tests.integration_tests.cases import IDim, cartesian_case, unstructured_case
from next_tests.integration_tests.feature_tests.ffront_tests.ffront_test_utils import (
fieldview_backend,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,8 @@
from gt4py.next.common import GTTypeError
from gt4py.next.ffront.past_passes.type_deduction import ProgramTypeError

from next_tests.integration_tests.feature_tests import cases
from next_tests.integration_tests.feature_tests.cases import (
IDim,
Ioff,
JDim,
cartesian_case,
fieldview_backend,
)
from next_tests.integration_tests import cases
from next_tests.integration_tests.cases import IDim, Ioff, JDim, cartesian_case, fieldview_backend
from next_tests.past_common_fixtures import (
copy_program_def,
copy_restrict_program_def,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from gt4py.next.ffront.foast_passes.type_deduction import FieldOperatorTypeDeductionError
from gt4py.next.program_processors.runners import gtfn_cpu

from next_tests.integration_tests.feature_tests import cases
from next_tests.integration_tests.feature_tests.cases import (
from next_tests.integration_tests import cases
from next_tests.integration_tests.cases import (
E2V,
V2E,
E2VDim,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
from gt4py.next.iterator.runtime import fundef
from gt4py.next.program_processors.runners import roundtrip


IDim = gtx.Dimension("IDim")
from next_tests.integration_tests.cases import IDim


def test_constant():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
)
from gt4py.next.program_processors.runners.gtfn_cpu import run_gtfn, run_gtfn_imperative

from next_tests.integration_tests.cases import IDim
from next_tests.unit_tests.conftest import program_processor, run_processor


Expand All @@ -52,9 +53,6 @@ def conditional_indirection(inp, cond):
return deref(compute_shift(cond)(inp))


IDim = gtx.Dimension("IDim")


def test_simple_indirection(program_processor):
program_processor, validate = program_processor

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import gt4py.next as gtx
from gt4py.next.iterator.builtins import cartesian_domain, deref, lift, named_range, scan, shift
from gt4py.next.iterator.runtime import fundef, offset
from gt4py.next.program_processors.codegens.gtfn import gtfn_backend

from next_tests.integration_tests.cases import IDim, KDim
from next_tests.unit_tests.conftest import lift_mode, program_processor, run_processor


Expand All @@ -27,8 +27,6 @@ def test_scan_in_stencil(program_processor, lift_mode):

isize = 1
ksize = 3
IDim = gtx.Dimension("I")
KDim = gtx.Dimension("K")
Koff = offset("Koff")
inp = gtx.np_as_located_field(IDim, KDim)(np.ones((isize, ksize)))
out = gtx.np_as_located_field(IDim, KDim)(np.zeros((isize, ksize)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@
from gt4py.next.iterator.runtime import closure, fendef, fundef, offset
from gt4py.next.program_processors.runners.gtfn_cpu import run_gtfn

from next_tests.integration_tests.cases import IDim, JDim, KDim
from next_tests.unit_tests.conftest import lift_mode, program_processor, run_processor


I = offset("I")
J = offset("J")
K = offset("K")

IDim = gtx.Dimension("IDim")
JDim = gtx.Dimension("JDim")
KDim = gtx.Dimension("KDim", kind=gtx.DimensionKind.VERTICAL)


@fundef
def foo(foo_inp):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
from gt4py.next import common
from gt4py.next.program_processors.runners import roundtrip

from next_tests.integration_tests.feature_tests import cases
from next_tests.integration_tests.feature_tests.cases import ( # noqa: F401 # fixtures
from next_tests.integration_tests import cases
from next_tests.integration_tests.cases import ( # noqa: F401 # fixtures
cartesian_case,
fieldview_backend,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@

import gt4py.next as gtx


IDim = gtx.Dimension("IDim")
JDim = gtx.Dimension("JDim")

Ioff = gtx.FieldOffset("Ioff", source=IDim, target=(IDim,))
Joff = gtx.FieldOffset("Joff", source=JDim, target=(JDim,))
from next_tests.integration_tests import cases
from next_tests.integration_tests.cases import IDim, Ioff, JDim, Joff, cartesian_case
from next_tests.integration_tests.feature_tests.ffront_tests.ffront_test_utils import (
fieldview_backend,
)


@gtx.field_operator
Expand Down Expand Up @@ -61,15 +60,27 @@ def lap_ref(inp):
return -4.0 * inp[1:-1, 1:-1] + inp[:-2, 1:-1] + inp[2:, 1:-1] + inp[1:-1, :-2] + inp[1:-1, 2:]


def test_ffront_lap():
shape = (20, 20)
as_ij = gtx.np_as_located_field(IDim, JDim)
inp = as_ij(np.fromfunction(lambda x, y: x**2 + y**2, shape))
def test_ffront_lap(cartesian_case):
in_field = cases.allocate(cartesian_case, lap_program, "in_field")()
out_field = cases.allocate(cartesian_case, lap_program, "out_field")()

result_lap = as_ij(np.zeros_like(inp))
lap_program(inp, result_lap, offset_provider={"Ioff": IDim, "Joff": JDim})
assert np.allclose(np.asarray(result_lap)[1:-1, 1:-1], lap_ref(np.asarray(inp)))
cases.verify(
cartesian_case,
lap_program,
in_field,
out_field,
inout=out_field.array()[1:-1, 1:-1],
ref=lap_ref(np.asarray(in_field)),
)

result_laplap = as_ij(np.zeros_like(inp))
laplap_program(inp, result_laplap, offset_provider={"Ioff": IDim, "Joff": JDim})
assert np.allclose(np.asarray(result_laplap)[2:-2, 2:-2], lap_ref(lap_ref(np.asarray(inp))))
in_field = cases.allocate(cartesian_case, laplap_program, "in_field")()
out_field = cases.allocate(cartesian_case, laplap_program, "out_field")()

cases.verify(
cartesian_case,
laplap_program,
in_field,
out_field,
inout=out_field.array()[2:-2, 2:-2],
ref=lap_ref(lap_ref(np.asarray(in_field))),
)
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
)
from gt4py.next.program_processors.runners.gtfn_cpu import run_gtfn, run_gtfn_imperative

from next_tests.integration_tests.cases import IDim, KDim
from next_tests.unit_tests.conftest import lift_mode, program_processor, run_processor


I = offset("I")
K = offset("K")

KDim = gtx.Dimension("KDim")
IDim = gtx.Dimension("IDim")


@fundef
def add_scalar(inp):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from gt4py.next.iterator.runtime import closure, fendef, fundef, offset
from gt4py.next.program_processors.runners.gtfn_cpu import run_gtfn, run_gtfn_imperative

from next_tests.integration_tests.cases import IDim, JDim
from next_tests.integration_tests.multi_feature_tests.iterator_tests.hdiff_reference import (
hdiff_reference,
)
Expand All @@ -29,9 +30,6 @@
I = offset("I")
J = offset("J")

IDim = gtx.Dimension("IDim")
JDim = gtx.Dimension("JDim")


@fundef
def laplacian(inp):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
)
from gt4py.next.program_processors.runners.gtfn_cpu import run_gtfn, run_gtfn_imperative

from next_tests.integration_tests.cases import IDim, JDim, KDim
from next_tests.unit_tests.conftest import lift_mode, program_processor, run_processor


Expand Down Expand Up @@ -85,11 +86,6 @@ def tridiag_reference():
return a, b, c, d, x


IDim = gtx.Dimension("IDim")
JDim = gtx.Dimension("JDim")
KDim = gtx.Dimension("KDim")


@fendef
def fen_solve_tridiag(i_size, j_size, k_size, a, b, c, d, x):
closure(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
import gt4py.next as gtx
from gt4py.next.program_processors.runners import gtfn_cpu


IDim = gtx.Dimension("IDim")
JDim = gtx.Dimension("JDim")
from next_tests.integration_tests.cases import IDim, JDim


def test_different_buffer_sizes():
Expand Down

0 comments on commit 5303c0b

Please sign in to comment.