From 27a91b1a6ea18f88355f0153f737056d4e4a3fb2 Mon Sep 17 00:00:00 2001 From: zyfncg Date: Wed, 13 Apr 2022 22:03:30 +0800 Subject: [PATCH] Adjust the slice end in getitem (#41681) * adjust the slice end in getitem * fix bug * fix bug * fix bug * recover start change --- python/paddle/fluid/variable_index.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/python/paddle/fluid/variable_index.py b/python/paddle/fluid/variable_index.py index 257ddc96d9c..83a569aacc9 100644 --- a/python/paddle/fluid/variable_index.py +++ b/python/paddle/fluid/variable_index.py @@ -375,7 +375,13 @@ def _getitem_impl_(var, item): if start is None: start = 0 if step > 0 else MAX_INTEGER if end is None: - end = MAX_INTEGER if step > 0 else -1 + if var.shape[dim] != -1 and ( + paddle.fluid.framework._non_static_mode() or + var.desc.type() != core.VarDesc.VarType.LOD_TENSOR_ARRAY + ): + end = var.shape[dim] if step > 0 else -1 + else: + end = MAX_INTEGER if step > 0 else -1 elif isinstance(slice_item, list): all_bool = True -- GitLab