Skip to content

Commit

Permalink
Make input mismatch TypeError in make_node more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardo committed Nov 5, 2021
1 parent 7c32fc4 commit d210d4f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion aesara/graph/op.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,17 @@ def make_node(self, *inputs: Variable) -> Apply:
f"We expected {len(self.itypes)} inputs but got {len(inputs)}."
)
if not all(inp.type == it for inp, it in zip(inputs, self.itypes)):
n_inputs = len(inputs)
raise TypeError(
f"We expected inputs of types '{str(self.itypes)}' but got types '{str([inp.type for inp in inputs])}'"
f"Invalid input types for Op {self}:\n"
+ "\n".join(
f"Input {i}/{n_inputs}: Expected {inp}, got {out}"
for i, (inp, out) in enumerate(
zip(self.itypes, (inp.type for inp in inputs)),
start=1,
)
if inp != out
)
)
return Apply(self, inputs, [o() for o in self.otypes])

Expand Down

0 comments on commit d210d4f

Please sign in to comment.