Skip to content
This repository was archived by the owner on Oct 31, 2023. It is now read-only.

Commit de5eb11

Browse files
icemelonbwasti
authored andcommitted
[Relay][Frontend][Bugfix] Fix bug in converting slice_axis when axis is negative (apache#2739)
* bug fix * trigger ci
1 parent ff782b5 commit de5eb11

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

python/tvm/relay/frontend/mxnet.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ def _mx_slice_axis(inputs, attrs):
200200
axis = attrs.get_int("axis")
201201
ax_beg = attrs.get_int("begin")
202202
ax_end = attrs.get_str("end")
203+
if axis < 0:
204+
axis += len(shape)
205+
assert axis >= 0 and axis < len(shape)
203206
if ax_end == "None":
204207
ax_end = int(shape[axis])
205208
else:

tests/python/frontend/mxnet/test_forward.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ def verify(shape, axis, begin, end):
352352
verify((3, 4), 0, 1, None)
353353
verify((3, 4), 1, 0, 2)
354354
verify((3, 4), 1, -3, -1)
355+
verify((3, 4), -1, -3, -1)
355356

356357

357358
if __name__ == '__main__':
@@ -380,4 +381,4 @@ def verify(shape, axis, begin, end):
380381
test_forward_broadcast_ops()
381382
test_forward_elemwise_ops()
382383
test_forward_scalar_ops()
383-
test_forward_slice_axis()
384+
test_forward_slice_axis()

0 commit comments

Comments
 (0)