Skip to content

Commit

Permalink
[TF] Fix a bug in _stridedSlice() (apache#6829)
Browse files Browse the repository at this point in the history
When stride < 0, the slicing range for whole demension should be
  [-1, -(dim+1))
  • Loading branch information
lixiaoquan authored and trevor-m committed Dec 4, 2020
1 parent 91ff038 commit 671bc28
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
8 changes: 6 additions & 2 deletions python/tvm/relay/frontend/tensorflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -1616,11 +1616,15 @@ def _transform_mask(stride_dim, ellipsis_mask):
if final_index == len(m_begin):
break
if mask & begin_mask:
m_begin[final_index] = data_shape[final_index] if stride[index] < 0 else 0
m_begin[final_index] = -1 if stride[index] < 0 else 0
elif begin[index]:
m_begin[final_index] = begin[index]
if mask & end_mask:
m_end[final_index] = 0 if stride[index] < 0 else data_shape[final_index]
m_end[final_index] = (
-(data_shape[final_index] + 1)
if stride[index] < 0
else data_shape[final_index]
)
elif end[index]:
m_end[final_index] = end[index]
m_stride[final_index] = stride[index]
Expand Down
10 changes: 10 additions & 0 deletions tests/python/frontend/tensorflow/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -1895,6 +1895,16 @@ def test_forward_stridedslice():
begin_mask=5,
end_mask=8,
)
_test_stridedslice(
(1, 13, 13, 3, 2),
[0, 0],
[1, 1],
[1, -1],
"float32",
ellipsis_mask=1,
begin_mask=2,
end_mask=2,
)


#######################################################################
Expand Down

0 comments on commit 671bc28

Please sign in to comment.