Skip to content

Commit f63f669

Browse files
committed
Fix unittest
1 parent 269d483 commit f63f669

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

python/paddle/fluid/tests/unittests/dygraph_to_static/test_tensor_shape.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ def _set_expected_op_num(self):
347347
class TestTupleShape3(TestTensorShapeBasic):
348348
def init_test_func(self):
349349
self.input = numpy.ones((5, 7)).astype("int32")
350-
self.input_spec = [paddle.static.InputSec(shape=[5, 7], dtype="int32")]
350+
self.input_spec = [paddle.static.InputSpec(shape=[5, 7], dtype="int32")]
351351
self.dygraph_func = dyfunc_tuple_shape_3
352352

353353
def _set_expected_op_num(self):

python/paddle/fluid/variable_index.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,19 @@ def _getitem_impl_(var, item):
116116

117117
for dim, slice_item in enumerate(item):
118118
if is_integer_or_scalar_tensor(slice_item):
119-
if isinstance(slice_item, int) and var.shape[
120-
dim] is not None and var.shape[dim] != -1:
121-
if slice_item < 0 or slice_item >= var.shape[dim]:
122-
# For python, if users write a, b = var, the __getitem__
123-
# method will iterate through 0, 1, 2 ... until __getitem__
124-
# throws an IndexError, then stop. The var[0], var[1] will
125-
# be given to a, b respectively. If more values are given,
126-
# the unpack size would cause error.
127-
#
128-
# We raises IndexError here to support grammar like `a, b = var`
129-
raise IndexError(
130-
"slice_item %d at dim %d should be >= 0 and < var.shape[%d]: %d"
131-
% (slice_item, dim, dim, var.shape[dim]))
119+
if isinstance(slice_item,
120+
int) and var.shape[dim] is not None and var.shape[
121+
dim] >= 0 and slice_item >= var.shape[dim]:
122+
# For python, if users write a, b = var, the __getitem__
123+
# method will iterate through 0, 1, 2 ... until __getitem__
124+
# throws an IndexError, then stop. The var[0], var[1] will
125+
# be given to a, b respectively. If more values are given,
126+
# the unpack size would cause error.
127+
#
128+
# We raises IndexError here to support grammar like `a, b = var`
129+
raise IndexError(
130+
"slice_item %d at dim %d should be >= 0 and < var.shape[%d]: %d"
131+
% (slice_item, dim, dim, var.shape[dim]))
132132
decrease_axes.append(dim)
133133
start = slice_item
134134
step = 1

0 commit comments

Comments
 (0)