diff --git a/paddle/fluid/operators/index_select_op.h b/paddle/fluid/operators/index_select_op.h index 96ec18d9a0d219bfd5fa10f45ca63e8c6fb7bce3..70714b7f3a0644e55c9bac27a88edb0b8a9921a4 100644 --- a/paddle/fluid/operators/index_select_op.h +++ b/paddle/fluid/operators/index_select_op.h @@ -52,6 +52,23 @@ void IndexSelectInner(const framework::ExecutionContext& context, TensorToVector(index, context.device_context(), &index_vec); std::vector out_vec(output->numel()); + for (int i = 0; i < index_size; i++) { + PADDLE_ENFORCE_GE( + index_vec[i], 0, + platform::errors::InvalidArgument( + "Variable value (index) of OP(index_select) " + "expected >= 0 and < %ld, but got %ld. Please check input " + "value.", + input_dim[dim], index_vec[i])); + PADDLE_ENFORCE_LT( + index_vec[i], input_dim[dim], + platform::errors::InvalidArgument( + "Variable value (index) of OP(index_select) " + "expected >= 0 and < %ld, but got %ld. Please check input " + "value.", + input_dim[dim], index_vec[i])); + } + VLOG(3) << "Index_Select_Debug; outer_nums: " << outer_nums << "; slice_size: " << slice_size << "; input_width: " << input_width << "; output_width: " << output_width diff --git a/python/paddle/fluid/tests/unittests/CMakeLists.txt b/python/paddle/fluid/tests/unittests/CMakeLists.txt index 6396467f0b957508f117be0d3b32843003b5ed0a..577205c1631d9e5a8757b27b2ee2892f794dd3a2 100644 --- a/python/paddle/fluid/tests/unittests/CMakeLists.txt +++ b/python/paddle/fluid/tests/unittests/CMakeLists.txt @@ -45,8 +45,6 @@ if(NOT WITH_GPU OR WIN32) LIST(REMOVE_ITEM TEST_OPS test_reducescatter_api) endif() -#TODO(malin): Fix this unitest failed on GCC8. -LIST(REMOVE_ITEM TEST_OPS test_roll_op) #TODO(sunxiaolong01): Fix this unitest failed on GCC8. LIST(REMOVE_ITEM TEST_OPS test_conv2d_transpose_op) if(WIN32) diff --git a/python/paddle/fluid/tests/unittests/test_roll_op.py b/python/paddle/fluid/tests/unittests/test_roll_op.py index d05fc45928fb7a924a734c2b88a532ba32bd5925..79162dbd9116d59eddbc0524d3c2d7378db522e0 100644 --- a/python/paddle/fluid/tests/unittests/test_roll_op.py +++ b/python/paddle/fluid/tests/unittests/test_roll_op.py @@ -50,7 +50,7 @@ class TestRollOp(OpTest): class TestRollOpCase2(TestRollOp): def init_dtype_type(self): self.dtype = np.float32 - self.x_shape = (100, 100, 5) + self.x_shape = (100, 10, 5) self.shifts = [8, -1] self.dims = [-1, -2] @@ -60,7 +60,7 @@ class TestRollAPI(unittest.TestCase): self.data_x = np.array( [[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]) - def test_index_select_api(self): + def test_roll_op_api(self): self.input_data() # case 1: