@@ -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