-
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.
bug[next]: Bound args kwargs edit (#1411)
* edits for BoundArgs with kwargs in correct order
- Loading branch information
1 parent
6283ac9
commit 3edf21e
Showing
3 changed files
with
75 additions
and
26 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
64 changes: 64 additions & 0 deletions
64
tests/next_tests/integration_tests/feature_tests/ffront_tests/test_bound_args.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,64 @@ | ||
# -*- coding: utf-8 -*- | ||
# GT4Py - GridTools Framework | ||
# | ||
# Copyright (c) 2014-2023, ETH Zurich | ||
# All rights reserved. | ||
# | ||
# This file is part of the GT4Py project and the GridTools framework. | ||
# GT4Py is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License as published by the | ||
# Free Software Foundation, either version 3 of the License, or any later | ||
# version. See the LICENSE.txt file at the top-level directory of this | ||
# distribution for a copy of the license or check <https://www.gnu.org/licenses/>. | ||
# | ||
# SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
import numpy as np | ||
|
||
import gt4py.next as gtx | ||
from gt4py.next import int32 | ||
|
||
from next_tests.integration_tests import cases | ||
from next_tests.integration_tests.cases import cartesian_case | ||
from next_tests.integration_tests.feature_tests.ffront_tests.ffront_test_utils import ( | ||
fieldview_backend, | ||
reduction_setup, | ||
) | ||
|
||
|
||
def test_with_bound_args(cartesian_case): | ||
@gtx.field_operator | ||
def fieldop_bound_args(a: cases.IField, scalar: int32, condition: bool) -> cases.IField: | ||
if not condition: | ||
scalar = 0 | ||
return a + scalar | ||
|
||
@gtx.program | ||
def program_bound_args(a: cases.IField, scalar: int32, condition: bool, out: cases.IField): | ||
fieldop_bound_args(a, scalar, condition, out=out) | ||
|
||
a = cases.allocate(cartesian_case, program_bound_args, "a")() | ||
scalar = int32(1) | ||
ref = a + scalar | ||
out = cases.allocate(cartesian_case, program_bound_args, "out")() | ||
|
||
prog_bounds = program_bound_args.with_bound_args(scalar=scalar, condition=True) | ||
cases.verify(cartesian_case, prog_bounds, a, out, inout=out, ref=ref) | ||
|
||
|
||
def test_with_bound_args_order_args(cartesian_case): | ||
@gtx.field_operator | ||
def fieldop_args(a: cases.IField, condition: bool, scalar: int32) -> cases.IField: | ||
scalar = 0 if not condition else scalar | ||
return a + scalar | ||
|
||
@gtx.program(backend=cartesian_case.backend) | ||
def program_args(a: cases.IField, condition: bool, scalar: int32, out: cases.IField): | ||
fieldop_args(a, condition, scalar, out=out) | ||
|
||
a = cases.allocate(cartesian_case, program_args, "a")() | ||
out = cases.allocate(cartesian_case, program_args, "out")() | ||
|
||
prog_bounds = program_args.with_bound_args(condition=True) | ||
prog_bounds(a=a, scalar=int32(1), out=out, offset_provider={}) | ||
np.allclose(out.asnumpy(), a.asnumpy() + int32(1)) |
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