!29113 modify tensor slice

Merge pull request !29113 from changzherui/mod_tensor_slice
This commit is contained in:
i-robot 2022-01-17 01:55:21 +00:00 committed by Gitee
commit 8903571af3
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 4 additions and 1 deletions

View File

@ -596,7 +596,10 @@ def get_slice_stride(index_slice, dim_size):
start_default = -1
stop_default = -(dim_size + 1)
start = start_default if index_slice.start is None else index_slice.start
stop = stop_default if index_slice.stop is None else index_slice.stop
if index_slice.stop is None:
stop = stop_default
else:
stop = min(stop_default, index_slice.stop) if step >= 0 else max(stop_default, index_slice.stop)
return start, stop, step