Skip to content

Commit 491096e

Browse files
Arm backend: Convert assert to raise ValueError for comparison operators (#9931)
Asserts are converted to proper raises to ensure graph integrity. Signed-off-by: Sebastian Larsson <[email protected]>
1 parent 4224d73 commit 491096e

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

backends/arm/operators/op_eq.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ def define_node(
3434
inputs: List[TosaArg],
3535
output: TosaArg,
3636
) -> None:
37-
assert (
38-
inputs[0].dtype == inputs[1].dtype
39-
), "EQ must have the same dtypes as input"
37+
if inputs[0].dtype != inputs[1].dtype:
38+
raise TypeError(
39+
"All inputs need to have the same data type for operator EQ but got "
40+
f"{inputs[0].dtype=}, {inputs[1].dtype=}"
41+
)
4042

4143
input_nodes = inputs
4244
# Handle quantization

backends/arm/operators/op_ge.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ def define_node(
3434
inputs: List[TosaArg],
3535
output: TosaArg,
3636
) -> None:
37-
assert (
38-
inputs[0].dtype == inputs[1].dtype
39-
), "GE must have the same dtypes as input"
37+
if inputs[0].dtype != inputs[1].dtype:
38+
raise TypeError(
39+
"All inputs need to have the same data type for operator GE but got "
40+
f"{inputs[0].dtype=}, {inputs[1].dtype=}"
41+
)
4042

4143
input_nodes = inputs
4244
# Handle quantization

backends/arm/operators/op_gt.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ def define_node(
3434
inputs: List[TosaArg],
3535
output: TosaArg,
3636
) -> None:
37-
assert (
38-
inputs[0].dtype == inputs[1].dtype
39-
), "GT must have the same dtypes as input"
37+
if inputs[0].dtype != inputs[1].dtype:
38+
raise TypeError(
39+
"All inputs need to have the same data type for operator GT but got "
40+
f"{inputs[0].dtype=}, {inputs[1].dtype=}"
41+
)
4042

4143
input_nodes = inputs
4244
# Handle quantization

backends/arm/operators/op_le.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ def define_node(
3434
inputs: List[TosaArg],
3535
output: TosaArg,
3636
) -> None:
37-
assert (
38-
inputs[0].dtype == inputs[1].dtype
39-
), "LE must have the same dtypes as input"
37+
if inputs[0].dtype != inputs[1].dtype:
38+
raise TypeError(
39+
"All inputs need to have the same data type for operator LE but got "
40+
f"{inputs[0].dtype=}, {inputs[1].dtype=}"
41+
)
4042

4143
input_nodes = inputs
4244
# Handle quantization

backends/arm/operators/op_lt.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ def define_node(
3434
inputs: List[TosaArg],
3535
output: TosaArg,
3636
) -> None:
37-
assert (
38-
inputs[0].dtype == inputs[1].dtype
39-
), "LT must have the same dtypes as input"
37+
if inputs[0].dtype != inputs[1].dtype:
38+
raise TypeError(
39+
"All inputs need to have the same data type for operator LT but got "
40+
f"{inputs[0].dtype=}, {inputs[1].dtype=}"
41+
)
4042

4143
input_nodes = inputs
4244
# Handle quantization

0 commit comments

Comments
 (0)