class TestHeatEquation_FTCS_3D(gt_testing.StencilTestSuite): dtypes = (np.float_,) domain_range = [(1, 15), (1, 15), (1, 15)] backends = INTERNAL_BACKENDS_NAMES symbols = dict( u=gt_testing.field(in_range=(-10, 10), extent=[(-1, 1), (0, 0), (0, 0)]), v=gt_testing.field(in_range=(-10, 10), extent=[(0, 0), (-1, 1), (0, 0)]), u_new=gt_testing.field(in_range=(-10, 10), extent=[(0, 0), (0, 0), (0, 0)]), v_new=gt_testing.field(in_range=(-10, 10), extent=[(0, 0), (0, 0), (0, 0)]), ru=gt_testing.parameter(in_range=(0, 0.5)), rv=gt_testing.parameter(in_range=(0, 0.5)), ) def definition(u, v, u_new, v_new, *, ru, rv): with computation(PARALLEL), interval(...): u_new = u[0, 0, 0] + ru * ( # noqa: F841 # Local name is assigned to but never used u[1, 0, 0] - 2 * u[0, 0, 0] + u[-1, 0, 0] ) v_new = v[0, 0, 0] + rv * ( # noqa: F841 # Local name is assigned to but never used v[0, 1, 0] - 2 * v[0, 0, 0] + v[0, -1, 0] ) def validation(u, v, u_new, v_new, *, ru, rv, domain, origin, **kwargs): u_new[...] = u[1:-1, :, :] + ru * (u[2:, :, :] - 2 * u[1:-1, :, :] + u[:-2, :, :]) v_new[...] = v[:, 1:-1, :] + rv * (v[:, 2:, :] - 2 * v[:, 1:-1, :] + v[:, :-2, :])
class TestDiagonalKOffset(gt_testing.StencilTestSuite): dtypes = { "field_in": np.float64, "field_out": np.float64, } domain_range = [(2, 2), (2, 2), (2, 8)] backends = INTERNAL_BACKENDS symbols = { "field_in": gt_testing.field(in_range=(0.1, 10), axes="IJK", boundary=[(0, 0), (1, 0), (0, 1)]), "field_out": gt_testing.field(in_range=(0.1, 10), axes="IJK", boundary=[(0, 0), (0, 0), (0, 0)]), } def definition(field_in, field_out): with computation(PARALLEL), interval(...): field_out = field_in[0, 0, 1] with computation(PARALLEL), interval(0, -1): field_out += field_in[0, -1, 1] def validation(field_in, field_out, *, domain, origin): field_out[:, :, :] = field_in[:, 1:, 1:] field_out[:, :, :-1] += field_in[:, :-1, 1:-1]
class TestHorizontalRegions(gt_testing.StencilTestSuite): dtypes = { "field_in": np.float32, "field_out": np.float32, } domain_range = [(4, 4), (4, 4), (2, 2)] backends = INTERNAL_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=(-10, 10), axes="IJK", boundary=[(0, 0), (0, 0), (0, 0)]), } def definition(field_in, field_out): with computation(PARALLEL), interval(...): field_out = ( # noqa: F841 # local variable 'field_out' is assigned to but never used field_in) with horizontal(region[I[0], :], region[I[-1], :]): field_out = ( # noqa: F841 # local variable 'field_out' is assigned to but never used field_in + 1.0) with horizontal(region[:, J[0]], region[:, J[-1]]): field_out = ( # noqa: F841 # local variable 'field_out' is assigned to but never used field_in - 1.0) def validation(field_in, field_out, *, domain, origin): field_out[:, :, :] = field_in[:, :, :] 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 TestVariableKRead(gt_testing.StencilTestSuite): dtypes = { "field_in": np.float32, "field_out": np.float32, "index": np.int32, } domain_range = [(2, 2), (2, 2), (2, 8)] backends = INTERNAL_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=(-10, 10), axes="IJK", boundary=[(0, 0), (0, 0), (0, 0)]), "index": gt_testing.field(in_range=(-1, 0), axes="K", boundary=[(0, 0), (0, 0), (0, 0)]), } def definition(field_in, field_out, index): with computation(PARALLEL), interval(1, None): field_out = field_in[ # noqa: F841 # Local name is assigned to but never used 0, 0, index] def validation(field_in, field_out, index, *, domain, origin): field_out[:, :, 1:] = field_in[:, :, (np.arange(field_in.shape[-1]) + index)[1:]]
class TestHeatEquation_FTCS_3D(gt_testing.StencilTestSuite): dtypes = (np.float_, ) domain_range = [(1, 15), (1, 15), (1, 15)] backends = ["debug", "numpy", "gtx86"] symbols = dict( u=gt_testing.field(in_range=(-10, 10), extent=[(-1, 1), (0, 0), (0, 0)]), v=gt_testing.field(in_range=(-10, 10), extent=[(0, 0), (-1, 1), (0, 0)]), u_new=gt_testing.field(in_range=(-10, 10), extent=[(0, 0), (0, 0), (0, 0)]), v_new=gt_testing.field(in_range=(-10, 10), extent=[(0, 0), (0, 0), (0, 0)]), ru=gt_testing.parameter(in_range=(0, 0.5)), rv=gt_testing.parameter(in_range=(0, 0.5)), ) def definition(u, v, u_new, v_new, *, ru, rv): with computation(PARALLEL), interval(...): u_new = u[0, 0, 0] + ru * (u[1, 0, 0] - 2 * u[0, 0, 0] + u[-1, 0, 0]) v_new = v[0, 0, 0] + rv * (v[0, 1, 0] - 2 * v[0, 0, 0] + v[0, -1, 0]) def validation(u, v, u_new, v_new, *, ru, rv, domain, origin, **kwargs): u_new[...] = u[1:-1, :, :] + ru * (u[2:, :, :] - 2 * u[1:-1, :, :] + u[:-2, :, :]) v_new[...] = v[:, 1:-1, :] + rv * (v[:, 2:, :] - 2 * v[:, 1:-1, :] + v[:, :-2, :])
class TestOptionalField(gt_testing.StencilTestSuite): dtypes = (np.float_, ) domain_range = [(1, 32), (1, 32), (1, 32)] backends = INTERNAL_BACKENDS symbols = dict( PHYS_TEND=gt_testing.global_name(one_of=(False, True)), in_field=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), out_field=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), dyn_tend=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), phys_tend=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), dt=gt_testing.parameter(in_range=(0, 100)), ) definition = optional_field def validation(in_field, out_field, dyn_tend, phys_tend=None, *, dt, domain, origin, **kwargs): out_field[...] = in_field + dt * dyn_tend if PHYS_TEND: # noqa: F821 # Undefined name out_field += dt * phys_tend
class TestReadOutsideKInterval3(gt_testing.StencilTestSuite): dtypes = { "field_in": np.float64, "field_out": np.float64, } domain_range = [(4, 4), (4, 4), (4, 4)] backends = INTERNAL_BACKENDS symbols = { "field_in": gt_testing.field(in_range=(-10, 10), axes="IJK", boundary=[(0, 0), (0, 0), (1, 0)]), "field_out": gt_testing.field(in_range=(-10, 10), axes="IJK", boundary=[(0, 0), (0, 0), (0, 0)]), } def definition(field_in, field_out): with computation(PARALLEL), interval(0, 1): field_out = field_in[ 0, 0, -1] # noqa: F841 # Local name is assigned to but never used def validation(field_in, field_out, *, domain, origin): field_out[:, :, 0] = field_in[:, :, 0]
class TestHorizontalDiffusionSubroutines(gt_testing.StencilTestSuite): """Diffusion in a horizontal 2D plane .""" dtypes = (np.float_,) domain_range = [(1, 15), (1, 15), (1, 15)] backends = INTERNAL_BACKENDS_NAMES symbols = dict( fwd_diff=gt_testing.global_name(singleton=wrap1arg2return), u=gt_testing.field(in_range=(-10, 10), boundary=[(2, 2), (2, 2), (0, 0)]), diffusion=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), weight=gt_testing.parameter(in_range=(0, 0.5)), ) def definition(u, diffusion, *, weight): from __externals__ import fwd_diff with computation(PARALLEL), interval(...): laplacian = lap_op(u=u) flux_i, flux_j = fwd_diff(field=laplacian) diffusion = u[ # noqa: F841 # Local name is assigned to but never used 0, 0, 0 ] - weight * (flux_i[0, 0, 0] - flux_i[-1, 0, 0] + flux_j[0, 0, 0] - flux_j[0, -1, 0]) def validation(u, diffusion, *, weight, domain, origin, **kwargs): laplacian = 4.0 * u[1:-1, 1:-1, :] - ( u[2:, 1:-1, :] + u[:-2, 1:-1, :] + u[1:-1, 2:, :] + u[1:-1, :-2, :] ) flux_i = laplacian[1:, 1:-1, :] - laplacian[:-1, 1:-1, :] flux_j = laplacian[1:-1, 1:, :] - laplacian[1:-1, :-1, :] diffusion[...] = u[2:-2, 2:-2, :] - weight * ( flux_i[1:, :, :] - flux_i[:-1, :, :] + flux_j[:, 1:, :] - flux_j[:, :-1, :] )
class TestHorizontalDiffusion(gt_testing.StencilTestSuite): """Diffusion in a horizontal 2D plane .""" dtypes = (np.float_, ) domain_range = [(1, 15), (1, 15), (1, 15)] backends = INTERNAL_BACKENDS symbols = dict( u=gt_testing.field(in_range=(-10, 10), boundary=[(2, 2), (2, 2), (0, 0)]), diffusion=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), weight=gt_testing.parameter(in_range=(0, 0.5)), ) def definition(u, diffusion, *, weight): with computation(PARALLEL), interval(...): laplacian = 4.0 * u[0, 0, 0] - (u[1, 0, 0] + u[-1, 0, 0] + u[0, 1, 0] + u[0, -1, 0]) flux_i = laplacian[1, 0, 0] - laplacian[0, 0, 0] flux_j = laplacian[0, 1, 0] - laplacian[0, 0, 0] diffusion = u[ # noqa: F841 # Local name is assigned to but never used 0, 0, 0] - weight * (flux_i[0, 0, 0] - flux_i[-1, 0, 0] + flux_j[0, 0, 0] - flux_j[0, -1, 0]) def validation(u, diffusion, *, weight, domain, origin, **kwargs): laplacian = 4.0 * u[1:-1, 1:-1, :] - (u[2:, 1:-1, :] + u[:-2, 1:-1, :] + u[1:-1, 2:, :] + u[1:-1, :-2, :]) flux_i = laplacian[1:, 1:-1, :] - laplacian[:-1, 1:-1, :] flux_j = laplacian[1:-1, 1:, :] - laplacian[1:-1, :-1, :] diffusion[...] = u[ 2:-2, 2:-2, :] - weight * (flux_i[1:, :, :] - flux_i[:-1, :, :] + flux_j[:, 1:, :] - flux_j[:, :-1, :])
class TestRuntimeIfNestedDataDependent(gt_testing.StencilTestSuite): dtypes = (np.float_,) domain_range = [(3, 3), (3, 3), (3, 3)] backends = INTERNAL_BACKENDS symbols = dict( factor=gt_testing.parameter(in_range=(-100, 100)), field_a=gt_testing.field(in_range=(-1, 1), boundary=[(0, 0), (0, 0), (0, 0)]), field_b=gt_testing.field(in_range=(-1, 1), boundary=[(0, 0), (0, 0), (0, 0)]), field_c=gt_testing.field(in_range=(-1, 1), boundary=[(0, 0), (0, 0), (0, 0)]), ) def definition(field_a, field_b, field_c, *, factor): with computation(PARALLEL), interval(...): if factor > 0: if field_a < 0: field_b = -field_a else: field_b = field_a # noqa: F841 # Local name is assigned to but never used else: if field_a < 0: field_c = -field_a else: field_c = field_a # noqa: F841 # Local name is assigned to but never used field_a = add_one(field_a) def validation(field_a, field_b, field_c, *, factor, domain, origin, **kwargs): if factor > 0: field_b[...] = np.abs(field_a) else: field_c[...] = np.abs(field_a) field_a += 1
class TestHorizontalDiffusionSubroutines3(gt_testing.StencilTestSuite): """Diffusion in a horizontal 2D plane . """ dtypes = (np.float_, ) domain_range = [(1, 15), (1, 15), (1, 15)] backends = ["debug", "numpy", "gtx86"] symbols = dict( fwd_diff=gt_testing.global_name(singleton=fwd_diff_op_xy_varargin), BRANCH=gt_testing.global_name(one_of=(False, )), u=gt_testing.field(in_range=(-10, 10), boundary=[(2, 2), (2, 2), (0, 0)]), diffusion=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), weight=gt_testing.parameter(in_range=(0, 0.5)), ) def definition(u, diffusion, *, weight): """ Horizontal diffusion stencil. Parameters ---------- u : 3D float field, input diffusion : 3D float field, output weight : diffusion coefficient """ from __externals__ import fwd_diff, BRANCH with computation(PARALLEL), interval(...): laplacian = lap_op(u=u) laplacian2 = lap_op(u=u) if __INLINED(BRANCH): flux_i, flux_j = fwd_diff(field1=laplacian, field2=laplacian2) else: flux_i = fwd_diff(field1=laplacian) flux_j = fwd_diff_op_y(field=laplacian) diffusion = u[0, 0, 0] - weight * (flux_i[0, 0, 0] - flux_i[-1, 0, 0] + flux_j[0, 0, 0] - flux_j[0, -1, 0]) def validation(u, diffusion, *, weight, domain, origin, **kwargs): laplacian = 4.0 * u[1:-1, 1:-1, :] - (u[2:, 1:-1, :] + u[:-2, 1:-1, :] + u[1:-1, 2:, :] + u[1:-1, :-2, :]) flux_i = laplacian[1:, 1:-1, :] - laplacian[:-1, 1:-1, :] flux_j = laplacian[1:-1, 1:, :] - laplacian[1:-1, :-1, :] diffusion[...] = u[ 2:-2, 2:-2, :] - weight * (flux_i[1:, :, :] - flux_i[:-1, :, :] + flux_j[:, 1:, :] - flux_j[:, :-1, :])
class TestParametricMix(gt_testing.StencilTestSuite): """Linear combination of input fields using several parameters. """ dtypes = { ("USE_ALPHA", ): np.int_, ("field_a", "field_b", "field_c"): np.float64, ("field_out", ): np.float32, ("weight", "alpha_factor"): np.float_, } domain_range = [(1, 15), (1, 15), (1, 15)] backends = ["debug", "numpy", "gtx86"] symbols = dict( USE_ALPHA=gt_testing.global_name(one_of=(True, False)), field_a=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), field_b=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), field_c=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), field_out=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), weight=gt_testing.parameter(in_range=(-10, 10)), alpha_factor=gt_testing.parameter(in_range=(-1, 1)), ) def definition(field_a, field_b, field_c, field_out, *, weight, alpha_factor): from __externals__ import USE_ALPHA with computation(PARALLEL), interval(...): factor = field_a # TODO remove once scalar assignment issue is fixed if USE_ALPHA: factor = alpha_factor else: factor = 1.0 + 0.0 * ( alpha_factor) # ?? won't compile for just factor = 0.0 field_out = factor * field_a[0, 0, 0] - (1 - factor) * ( field_b[0, 0, 0] - weight * field_c[0, 0, 0]) def validation(field_a, field_b, field_c, field_out, *, weight, alpha_factor, domain, origin, **kwargs): if USE_ALPHA: factor = alpha_factor else: factor = 1.0 field_out[...] = (factor * field_a[:, :, :] ) - (1 - factor) * (field_b[:, :, :] - (weight * field_c[:, :, :]))
class TestParametricMix(gt_testing.StencilTestSuite): """Linear combination of input fields using several parameters.""" dtypes = { ("USE_ALPHA", ): np.int_, ("field_a", "field_b", "field_c"): np.float64, ("field_out", ): np.float32, ("weight", "alpha_factor"): np.float_, } domain_range = [(1, 15), (1, 15), (1, 15)] backends = INTERNAL_BACKENDS symbols = dict( USE_ALPHA=gt_testing.global_name(one_of=(True, False)), field_a=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), field_b=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), field_c=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), field_out=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), weight=gt_testing.parameter(in_range=(-10, 10)), alpha_factor=gt_testing.parameter(in_range=(-1, 1)), ) def definition(field_a, field_b, field_c, field_out, *, weight, alpha_factor): from __externals__ import USE_ALPHA from __gtscript__ import __INLINED with computation(PARALLEL), interval(...): if __INLINED(USE_ALPHA): factor = alpha_factor else: factor = 1.0 field_out = factor * field_a[ # noqa: F841 # Local name is assigned to but never used 0, 0, 0] - (1 - factor) * (field_b[0, 0, 0] - weight * field_c[0, 0, 0]) def validation(field_a, field_b, field_c, field_out, *, weight, alpha_factor, domain, origin, **kwargs): if USE_ALPHA: # noqa: F821 # Undefined name factor = alpha_factor else: factor = 1.0 field_out[...] = (factor * field_a[:, :, :] ) - (1 - factor) * (field_b[:, :, :] - (weight * field_c[:, :, :]))
class TestRuntimeIfNested(gt_testing.StencilTestSuite): """Tests nested runtime ifs """ dtypes = (np.float_, ) domain_range = [(1, 15), (1, 15), (1, 15)] backends = ["debug", "numpy", "gtx86"] symbols = dict(outfield=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), ) def definition(outfield): with computation(PARALLEL), interval(...): if 1: if 0: outfield = 1 else: outfield = 2 else: outfield = 3 def validation(outfield, *, domain, origin, **kwargs): outfield[...] = 2
class TestTernaryOp(gt_testing.StencilTestSuite): dtypes = (np.float_,) domain_range = [(1, 15), (2, 15), (1, 15)] backends = CPU_BACKENDS symbols = dict( infield=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 1), (0, 0)]), outfield=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), ) def definition(infield, outfield): with computation(PARALLEL), interval(...): outfield = (infield > 0.0) * infield + (infield <= 0.0) * (-infield[0, 1, 0]) def validation(infield, outfield, *, domain, origin, **kwargs): outfield[...] = np.choose(infield[:, :-1, :] > 0, [-infield[:, 1:, :], infield[:, :-1, :]])
class TestCopy(gt_testing.StencilTestSuite): """Copy stencil.""" dtypes = (np.float_,) domain_range = [(1, 25), (1, 25), (1, 25)] backends = CPU_BACKENDS symbols = dict( field_a=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), field_b=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), ) def definition(field_a, field_b): with computation(PARALLEL), interval(...): field_b = field_a def validation(field_a, field_b, domain=None, origin=None): field_b[...] = field_a
class TestConstantFolding(gt_testing.StencilTestSuite): dtypes = {("outfield",): np.float64, ("cond",): np.float64} domain_range = [(15, 15), (15, 15), (15, 15)] backends = INTERNAL_BACKENDS_NAMES symbols = dict( outfield=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), cond=gt_testing.field(in_range=(1, 10), boundary=[(0, 0), (0, 0), (0, 0)]), ) def definition(outfield, cond): with computation(PARALLEL), interval(...): if cond != 0: tmp = 1 outfield = tmp # noqa: F841 # local variable assigned to but never used def validation(outfield, cond, *, domain, origin, **kwargs): outfield[np.array(cond, dtype=np.bool_)] = 1
class TestCopy(gt_testing.StencilTestSuite): """Copy stencil.""" dtypes = (np.float_,) domain_range = [(1, 25), (1, 25), (1, 25)] backends = INTERNAL_BACKENDS_NAMES symbols = dict( field_a=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), field_b=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), ) def definition(field_a, field_b): with computation(PARALLEL), interval(...): field_b = field_a # noqa: F841 # Local name is assigned to but never used def validation(field_a, field_b, domain=None, origin=None): field_b[...] = field_a
class TestAugAssign(gt_testing.StencilTestSuite): """Increment by one stencil.""" dtypes = (np.float_,) domain_range = [(1, 25), (1, 25), (1, 25)] backends = CPU_BACKENDS symbols = dict( field_a=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), field_b=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), ) def definition(field_a, field_b): with computation(PARALLEL), interval(...): field_a += 1.0 field_a *= 2.0 field_b -= 1.0 field_b /= 2.0 def validation(field_a, field_b, domain=None, origin=None): field_a[...] = (field_a[...] + 1.0) * 2.0 field_b[...] = (field_b[...] - 1.0) / 2.0
class TestTernaryOp(gt_testing.StencilTestSuite): dtypes = (np.float_, ) domain_range = [(1, 15), (2, 15), (1, 15)] backends = INTERNAL_BACKENDS symbols = dict( infield=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 1), (0, 0)]), outfield=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), ) def definition(infield, outfield): with computation(PARALLEL), interval(...): outfield = ( # noqa: F841 # Local name is assigned to but never used infield if infield > 0.0 else -infield[0, 1, 0]) def validation(infield, outfield, *, domain, origin, **kwargs): outfield[...] = (infield[:, :-1, :] > 0.0) * infield[:, :-1, :] + ( infield[:, :-1, :] <= 0.0) * (-infield[:, 1:, :])
class TestTwoOptionalFields(gt_testing.StencilTestSuite): dtypes = (np.float_, ) domain_range = [(1, 32), (1, 32), (1, 32)] backends = INTERNAL_BACKENDS symbols = dict( PHYS_TEND_A=gt_testing.global_name(one_of=(False, True)), PHYS_TEND_B=gt_testing.global_name(one_of=(False, True)), in_a=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), in_b=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), out_a=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), out_b=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), dyn_tend_a=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), dyn_tend_b=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), phys_tend_a=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), phys_tend_b=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), dt=gt_testing.parameter(in_range=(0, 100)), ) definition = two_optional_fields def validation( in_a, in_b, out_a, out_b, dyn_tend_a, dyn_tend_b, phys_tend_a=None, phys_tend_b=None, *, dt, domain, origin, **kwargs, ): out_a[...] = in_a + dt * dyn_tend_a out_b[...] = in_b + dt * dyn_tend_b if PHYS_TEND_A: # noqa: F821 # Undefined name out_a += dt * phys_tend_a if PHYS_TEND_B: # noqa: F821 # Undefined name out_b += dt * phys_tend_b
class TestRuntimeIfNestedDataDependent(gt_testing.StencilTestSuite): dtypes = (np.float_, ) domain_range = [(3, 3), (3, 3), (3, 3)] backends = CPU_BACKENDS symbols = dict( # factor=gt_testing.global_name(one_of=(-1., 0., 1.)), factor=gt_testing.parameter(in_range=(-100, 100)), field_a=gt_testing.field(in_range=(-1, 1), boundary=[(0, 0), (0, 0), (0, 0)]), field_b=gt_testing.field(in_range=(-1, 1), boundary=[(0, 0), (0, 0), (0, 0)]), field_c=gt_testing.field(in_range=(-1, 1), boundary=[(0, 0), (0, 0), (0, 0)]), ) def definition(field_a, field_b, field_c, *, factor): # from __externals__ import factor with computation(PARALLEL), interval(...): if factor > 0: if field_a < 0: field_b = -field_a else: field_b = field_a else: if field_a < 0: field_c = -field_a else: field_c = field_a field_a = add_one(field_a) def validation(field_a, field_b, field_c, *, factor, domain, origin, **kwargs): if factor > 0: field_b[...] = np.abs(field_a) else: field_c[...] = np.abs(field_a) field_a += 1
class TestHorizontalDiffusionSubroutines2(gt_testing.StencilTestSuite): """Diffusion in a horizontal 2D plane .""" dtypes = (np.float_, ) domain_range = [(1, 15), (1, 15), (1, 15)] backends = CPU_BACKENDS symbols = dict( fwd_diff=gt_testing.global_name(singleton=fwd_diff_op_xy), BRANCH=gt_testing.global_name(one_of=(True, False)), u=gt_testing.field(in_range=(-10, 10), boundary=[(2, 2), (2, 2), (0, 0)]), diffusion=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), weight=gt_testing.parameter(in_range=(0, 0.5)), ) def definition(u, diffusion, *, weight): from __externals__ import BRANCH, fwd_diff with computation(PARALLEL), interval(...): laplacian = lap_op(u=u) if __INLINED(BRANCH): flux_i = fwd_diff_op_x(field=laplacian) flux_j = fwd_diff_op_y(field=laplacian) else: flux_i, flux_j = fwd_diff_op_xy(field=laplacian) diffusion = u[0, 0, 0] - weight * (flux_i[0, 0, 0] - flux_i[-1, 0, 0] + flux_j[0, 0, 0] - flux_j[0, -1, 0]) def validation(u, diffusion, *, weight, domain, origin, **kwargs): laplacian = 4.0 * u[1:-1, 1:-1, :] - (u[2:, 1:-1, :] + u[:-2, 1:-1, :] + u[1:-1, 2:, :] + u[1:-1, :-2, :]) flux_i = laplacian[1:, 1:-1, :] - laplacian[:-1, 1:-1, :] flux_j = laplacian[1:-1, 1:, :] - laplacian[1:-1, :-1, :] diffusion[...] = u[ 2:-2, 2:-2, :] - weight * (flux_i[1:, :, :] - flux_i[:-1, :, :] + flux_j[:, 1:, :] - flux_j[:, :-1, :])
class TestVariableKAndReadOutside(gt_testing.StencilTestSuite): dtypes = { "field_in": np.float64, "field_out": np.float64, "index": np.int32, } domain_range = [(2, 2), (2, 2), (2, 8)] # exclude "numpy" due to #624 backends = [ backend for backend in INTERNAL_BACKENDS if backend.values[0] != "numpy" ] symbols = { "field_in": gt_testing.field(in_range=(0.1, 10), axes="IJK", boundary=[(0, 0), (0, 0), (1, 0)]), "field_out": gt_testing.field(in_range=(0.1, 10), axes="IJK", boundary=[(0, 0), (0, 0), (0, 0)]), "index": gt_testing.field(in_range=(-1, 0), axes="K", boundary=[(0, 0), (0, 0), (0, 0)]), } def definition(field_in, field_out, index): with computation(PARALLEL), interval(1, None): field_out[0, 0, 0] = ( field_in[ 0, 0, index] # noqa: F841 # Local name is assigned to but never used + field_in[0, 0, -2]) def validation(field_in, field_out, index, *, domain, origin): idx = 1 + (np.arange(domain[-1]) + index)[1:] field_out[:, :, 1:] = field_in[:, :, idx] field_out[:, :, 1:] += field_in[:, :, :-2]
class TestIdentity(gt_testing.StencilTestSuite): """Identity stencil.""" dtypes = {("field_a",): (np.float64, np.float32)} domain_range = [(1, 25), (1, 25), (1, 25)] backends = CPU_BACKENDS symbols = dict(field_a=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)])) def definition(field_a): with computation(PARALLEL), interval(...): field_a = field_a # TODO need 'pass' def validation(field_a, domain=None, origin=None): pass
class TestParametricScale(gt_testing.StencilTestSuite): """Scale stencil using a parameter.""" dtypes = (np.float_,) domain_range = [(1, 15), (1, 15), (1, 15)] backends = CPU_BACKENDS symbols = dict( field_a=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)]), scale=gt_testing.parameter(in_range=(-100, 100)), ) def definition(field_a, *, scale): with computation(PARALLEL), interval(...): field_a = scale * field_a def validation(field_a, *, scale, domain, origin, **kwargs): field_a[...] = scale * field_a
class TestRuntimeIfFlat(gt_testing.StencilTestSuite): """Tests runtime ifs.""" dtypes = (np.float_,) domain_range = [(1, 15), (1, 15), (1, 15)] backends = INTERNAL_BACKENDS_NAMES symbols = dict(outfield=gt_testing.field(in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)])) def definition(outfield): with computation(PARALLEL), interval(...): if True: outfield = 1 else: outfield = 2 # noqa: F841 # Local name is assigned to but never used def validation(outfield, *, domain, origin, **kwargs): outfield[...] = 1
class Test3FoldNestedIf(gt_testing.StencilTestSuite): dtypes = (np.float_,) domain_range = [(3, 3), (3, 3), (3, 3)] backends = ["debug", "numpy", "gtx86"] symbols = dict(field_a=gt_testing.field(in_range=(-1, 1), boundary=[(0, 0), (0, 0), (0, 0)])) def definition(field_a): with computation(PARALLEL), interval(...): if field_a >= 0.0: field_a = 0.0 if field_a > 1: field_a = 1 if field_a > 2: field_a = 2 def validation(field_a, domain, origin): for v in range(3): field_a[np.where(field_a > v)] = v
class TestGlobalScale(gt_testing.StencilTestSuite): """Scale stencil using a global global_name.""" dtypes = (np.float_,) domain_range = [(1, 15), (1, 15), (1, 15)] backends = CPU_BACKENDS symbols = dict( SCALE_FACTOR=gt_testing.global_name(one_of=(1.0, 1e3, 1e6)), field_a=gt_testing.field(in_range=(-1, 1), boundary=[(0, 0), (0, 0), (0, 0)]), ) def definition(field_a): from __externals__ import SCALE_FACTOR with computation(PARALLEL), interval(...): field_a = SCALE_FACTOR * field_a[0, 0, 0] def validation(field_a, domain, origin, **kwargs): field_a[...] = SCALE_FACTOR * field_a
class TestRuntimeIfFlat(gt_testing.StencilTestSuite): """Tests runtime ifs.""" dtypes = (np.float_, ) domain_range = [(1, 15), (1, 15), (1, 15)] backends = CPU_BACKENDS symbols = dict(outfield=gt_testing.field( in_range=(-10, 10), boundary=[(0, 0), (0, 0), (0, 0)])) def definition(outfield): with computation(PARALLEL), interval(...): if 1: outfield = 1 else: outfield = 2 def validation(outfield, *, domain, origin, **kwargs): outfield[...] = 1