Skip to content

Commit

Permalink
Fix compile when no args are provided (#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
parthchadha authored Oct 25, 2024
1 parent 7c6997d commit 5085987
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tripy/tests/backend/api/test_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ def test_invalid_return_rejected(self, func):
with helper.raises(tp.TripyException, "Function must return 1 or more Tensors"):
tp.compile(func, args=[tp.InputInfo((2, 2), dtype=tp.float32)])

def test_no_input_network(self):
def accepts_nothing():
return tp.Tensor([1])

tp.compile(accepts_nothing, args=[])

def test_multiple_return_values(self):
compiled_func = tp.compile(
returns_multiple_tensors,
Expand Down
4 changes: 3 additions & 1 deletion tripy/tripy/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,16 +436,18 @@ def get_positional_arg_names(func, *args):
# None instead.
signature = inspect.signature(func)
arg_names = []
varargs_name = None
for name, param in signature.parameters.items():
if param.kind == inspect.Parameter.VAR_POSITIONAL:
# Positional arguments cannot follow variadic positional arguments
# (they would just be absorbed into the variadic argument).
varargs_name = name
break

arg_names.append(name)

# For all variadic positional arguments, assign the name of the variadic group.
arg_names.extend([name] * (len(args) - len(arg_names)))
arg_names.extend([varargs_name] * (len(args) - len(arg_names)))
return list(zip(arg_names, args))


Expand Down

0 comments on commit 5085987

Please sign in to comment.