Skip to content

Commit cebe051

Browse files
Arm backend: Replace asserts with ValueError for slicing constraints (#10748)
The existing code used assertions to validate slicing parameters (e.g., size must be positive and within dimension limits). This has been changed to raise ValueError with descriptive error messages to provide clearer feedback and robustness for invalid inputs when using aten.slice_copy.Tensor. Signed-off-by: Sebastian Larsson <[email protected]>
1 parent 6932baf commit cebe051

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

backends/arm/operators/op_slice.py

+20-4
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,16 @@ def define_node(
6868
end_index = _fixup_end(end, shape, dim)
6969
size = end_index - start_index
7070

71-
assert size > 0
72-
assert size <= shape[dim]
71+
if size <= 0:
72+
raise ValueError(
73+
f"The calculated slice size must be positive. Got {size=} "
74+
f"with {start_index=} and {end_index=}."
75+
)
76+
if size > shape[dim]:
77+
raise ValueError(
78+
f"The calculated slice size cannot be greater than the dimension size"
79+
f". Got {size=} and {shape[dim]=}."
80+
)
7381

7482
# Convert aten args to Tosa's start and size attributes and in TOSA dim order.
7583
attr = ts.TosaSerializerAttribute()
@@ -122,8 +130,16 @@ def define_node(
122130
end_index = _fixup_end(end, shape, dim)
123131
size = end_index - start_index
124132

125-
assert size > 0
126-
assert size <= shape[dim]
133+
if size <= 0:
134+
raise ValueError(
135+
f"The calculated slice size must be positive. Got {size=} "
136+
f"with {start_index=} and {end_index=}."
137+
)
138+
if size > shape[dim]:
139+
raise ValueError(
140+
f"The calculated slice size cannot be greater than the dimension size"
141+
f". Got {size=} and {shape[dim]=}."
142+
)
127143

128144
# Convert aten args to Tosa's start and size shape_t tensors and in TOSA dim order.
129145
starts = [

0 commit comments

Comments
 (0)