Skip to content

Commit 9659b25

Browse files
committed
fix dummy args
1 parent 8cad2c7 commit 9659b25

1 file changed

Lines changed: 17 additions & 19 deletions

File tree

frontend/catalyst/decomposition/type_utils.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,30 +119,28 @@ def handle_item(item):
119119

120120
def get_dummy_values_for_arg(arg):
121121
"""
122-
Given a dictionary of python or MLIR types, replace the types with corresponding dummy values.
122+
Given a container of python or MLIR types, replace the types with corresponding dummy values.
123123
124-
Each item in the dictionary must be representable as an MLIR tensor with at most one layer of
124+
Each item in the container must be representible as an MLIR tensor with at most one layer of
125125
nesting, i.e. cannot be nested and all elements must be of the same type.
126126
Ex.
127127
[[float, float], [int, int, int], [int32, int32, int32, int32]]
128128
"""
129-
130-
def handle_item(item):
131-
if isinstance(item, (list, tuple)):
132-
return jnp.zeros(len(item), dtype=handle_item(item[0]).dtype)
133-
if isinstance(item, ShapedArray):
134-
return jnp.zeros(item.shape[0], dtype=item.dtype)
135-
elif isinstance(item, str):
136-
return jnp.zeros((), dtype=_MLIR_DTYPES_TO_PY_DTYPES[item])
137-
elif isinstance(item, (type, jnp.dtype)):
138-
try:
139-
return jnp.zeros((), jnp.dtype(item))
140-
except TypeError:
141-
raise TypeError(
142-
f"Unexpected type in container when creating dummy values: {type(item)}"
143-
)
144-
145-
return {k: handle_item(v) for k, v in dictionary.items()}
129+
if isinstance(arg, str):
130+
return jnp.zeros((), dtype=_MLIR_DTYPES_TO_PY_DTYPES[arg])
131+
elif isinstance(arg, (list, tuple)):
132+
return jnp.zeros(len(arg), dtype=get_dummy_values_for_arg(arg[0]).dtype)
133+
elif isinstance(arg, ShapedArray):
134+
return jnp.zeros(arg.shape[0], dtype=arg.dtype)
135+
elif isinstance(arg, str):
136+
return jnp.zeros((), dtype=_MLIR_DTYPES_TO_PY_DTYPES[arg])
137+
elif isinstance(arg, (type, jnp.dtype)):
138+
try:
139+
return jnp.zeros((), jnp.dtype(arg))
140+
except TypeError:
141+
pass
142+
143+
raise TypeError(f"Unexpected type in container when creating dummy values: {type(arg)}")
146144

147145

148146
def replace_abstract_wires_with_concrete_wires(node):

0 commit comments

Comments
 (0)