Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug[next]: Bound args kwargs edit #1411

Merged
merged 6 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/gt4py/next/ffront/decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -453,11 +453,16 @@ def _process_args(self, args: tuple, kwargs: dict):
) from err

full_args = [*args]
full_kwargs = list(kwargs.items())
for index, param in enumerate(self.past_node.params):
if param.id in self.bound_args.keys():
full_args.insert(index, self.bound_args[param.id])
if index < len(full_args):
full_args.insert(index, self.bound_args[param.id])
else:
pos = list(self.past_node.type.definition.pos_or_kw_args).index(str(param.id))
full_kwargs.insert(pos, (str(param.id), self.bound_args[param.id]))
nfarabullini marked this conversation as resolved.
Show resolved Hide resolved

return super()._process_args(tuple(full_args), kwargs)
return super()._process_args(tuple(full_args), dict(full_kwargs))

@functools.cached_property
def itir(self):
Expand All @@ -472,8 +477,9 @@ def itir(self):
new_clos.inputs.pop(index)
new_args = [ref(inp.id) for inp in new_clos.inputs]
params = [sym(inp.id) for inp in new_clos.inputs]
for value in self.bound_args.values():
new_args.append(promote_to_const_iterator(literal_from_value(value)))
for key, value in self.bound_args.items():
pos = list(self.past_node.type.definition.pos_or_kw_args).index(key)
new_args.insert(pos, promote_to_const_iterator(literal_from_value(value)))
nfarabullini marked this conversation as resolved.
Show resolved Hide resolved
expr = itir.FunCall(
fun=new_clos.stencil,
args=new_args,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -918,6 +918,26 @@ def program_bound_args(a: cases.IField, scalar: int32, condition: bool, out: cas
cases.verify(cartesian_case, prog_bounds, a, out, inout=out, ref=ref)


def test_with_bound_args_order_args(cartesian_case):
nfarabullini marked this conversation as resolved.
Show resolved Hide resolved
@gtx.field_operator
def fieldop_args(a: cases.IField, condition: bool, scalar: int32) -> cases.IField:
if not condition:
scalar = 0
return a + scalar
nfarabullini marked this conversation as resolved.
Show resolved Hide resolved

@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")()
scalar = int32(1)
ref = a.asnumpy() + scalar
out = cases.allocate(cartesian_case, program_args, "out")()

prog_bounds = program_args.with_bound_args(condition=True)
prog_bounds(a=a, scalar=scalar, out=out, offset_provider={})
np.allclose(out.asnumpy(), ref)

def test_domain(cartesian_case):
@gtx.field_operator
def fieldop_domain(a: cases.IField) -> cases.IField:
Expand Down
Loading