From 6d170bbb47b46467d66b9098f621e91131f019b3 Mon Sep 17 00:00:00 2001 From: zoooo0820 Date: Thu, 9 Nov 2023 04:00:30 +0000 Subject: [PATCH 1/3] fix single Py_Bool indexing and add unittest case --- .../base/dygraph/tensor_patch_methods.py | 4 +- python/paddle/base/variable_index.py | 6 +- test/indexing/test_getitem.py | 74 +++++++++++++++++++ test/indexing/test_setitem.py | 70 ++++++++++++++++++ 4 files changed, 150 insertions(+), 4 deletions(-) diff --git a/python/paddle/base/dygraph/tensor_patch_methods.py b/python/paddle/base/dygraph/tensor_patch_methods.py index 1f5b414ebb559e..6e61e38f1df023 100644 --- a/python/paddle/base/dygraph/tensor_patch_methods.py +++ b/python/paddle/base/dygraph/tensor_patch_methods.py @@ -747,7 +747,9 @@ def contain_tensor_or_list(item): item = (item,) for slice_item in item: - if isinstance(slice_item, (list, np.ndarray, Variable, range)): + if isinstance( + slice_item, (list, np.ndarray, Variable, range, bool) + ): return True return False diff --git a/python/paddle/base/variable_index.py b/python/paddle/base/variable_index.py index db43a53b5327fd..e36b9bca93cd0d 100644 --- a/python/paddle/base/variable_index.py +++ b/python/paddle/base/variable_index.py @@ -272,7 +272,7 @@ def replace_none(item): def is_integer_or_scalar_tensor(ele): from .framework import Variable - if isinstance(ele, int): + if type(ele) is int: return True elif isinstance(ele, Variable): # NOTE(zoooo0820): For compatibility, if FLAGS_set_to_1d is set to True, @@ -722,12 +722,12 @@ def parse_index(x, indices): elif isinstance(slice_item, bool): # single bool is advanced-indexing none_axes.append(dim) - estimated_dim += 1 advanced_index[estimated_dim] = ( estimated_dim, - paddle.to_tensor(slice_item), + paddle.to_tensor([slice_item]), ) has_advanced_index = True + estimated_dim += 1 elif isinstance(slice_item, slice): start = slice_item.start end = slice_item.stop diff --git a/test/indexing/test_getitem.py b/test/indexing/test_getitem.py index 6ce8519926a498..19f4ce557950fb 100644 --- a/test/indexing/test_getitem.py +++ b/test/indexing/test_getitem.py @@ -326,6 +326,45 @@ def test_indexing_is_multi_dim_list(self): np.testing.assert_allclose(y.numpy(), np_res) np.testing.assert_allclose(y.numpy(), y_index_tensor.numpy()) + def test_indexing_is_boolean_true(self): + # indexing is boolean, should improve rank of tensor and then treat it as advanced indexing. + np_data = ( + np.arange(3 * 4 * 5 * 6).reshape((6, 5, 4, 3)).astype(self.ndtype) + ) + + if self.dtype == 'bfloat16': + np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) + if self.dtype == 'complex64' or self.dtype == 'complex32': + np_data = np_data + 1j * np_data + + np_res = np_data[True] + + x = paddle.to_tensor(np_data, dtype=self.dtype) + y = x[True] + + if self.dtype == 'bfloat16': + y = paddle.cast(y, dtype='float32') + + np.testing.assert_allclose(y.numpy(), np_res) + + def test_indexing_is_boolean_false(self): + # indexing is boolean, should improve rank of tensor and then treat it as advanced indexing. + np_data = ( + np.arange(3 * 4 * 5 * 6).reshape((6, 5, 4, 3)).astype(self.ndtype) + ) + + if self.dtype == 'bfloat16': + np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) + if self.dtype == 'complex64' or self.dtype == 'complex32': + np_data = np_data + 1j * np_data + + np_res = np_data[1, False, 0] + + x = paddle.to_tensor(np_data, dtype=self.dtype) + y = x[1, False, 0] + + np.testing.assert_allclose(y.numpy(), np_res) + @unittest.skipIf( not core.is_compiled_with_cuda() @@ -1002,6 +1041,36 @@ def test_indexing_is_multi_dim_list(self): np.testing.assert_allclose(res[0], np_res) np.testing.assert_allclose(res[1], np_res) + def test_indexing_is_boolean_true(self): + # indexing is boolean, should improve rank of tensor and then treat it as advanced indexing. + np_data = np.arange(3 * 4 * 5 * 6).reshape((6, 5, 4, 3)) + np_res = np_data[True] + + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() + ): + x = paddle.to_tensor(np_data) + y = _getitem_static(x, True) + + res = self.exe.run(fetch_list=[y.name]) + + np.testing.assert_allclose(res[0], np_res) + + def test_indexing_is_boolean_false(self): + # indexing is boolean, should improve rank of tensor and then treat it as advanced indexing. + np_data = np.arange(3 * 4 * 5 * 6).reshape((6, 5, 4, 3)) + np_res = np_data[1, False, 0] + + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() + ): + x = paddle.to_tensor(np_data) + y = _getitem_static(x, (1, False, 0)) + + res = self.exe.run(fetch_list=[y.name]) + + np.testing.assert_allclose(res[0], np_res) + class TestGetitemBasicIndexOutputView(unittest.TestCase): def setUp(self): @@ -1077,3 +1146,8 @@ def test_bool_shape_error2(self): x = paddle.randn((4, 3, 2)) with self.assertRaises(IndexError): y = _getitem_static(x, (1, paddle.to_tensor([True, False]), [0, 1])) + + def test_bool_error(self): + x = paddle.randn((4, 3, 2)) + with self.assertRaises(ValueError): + y = _getitem_static(x, (True, [0, 1])) diff --git a/test/indexing/test_setitem.py b/test/indexing/test_setitem.py index 6620922603e7ac..741696f0dd8fb5 100644 --- a/test/indexing/test_setitem.py +++ b/test/indexing/test_setitem.py @@ -188,6 +188,46 @@ def test_indexing_is_multi_dim_list(self): x = paddle.cast(x, dtype='float32') np.testing.assert_allclose(x.numpy(), np_data) + def test_indexing_is_boolean_true(self): + # indexing is boolean, should improve rank of tensor and then treat it as advanced indexing. + np_data = ( + np.arange(3 * 4 * 5 * 6).reshape((6, 5, 4, 3)).astype(self.ndtype) + ) + + if self.dtype == 'bfloat16': + np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) + if self.dtype == 'complex64' or self.dtype == 'complex32': + np_data = np_data + 1j * np_data + + x = paddle.to_tensor(np_data, dtype=self.dtype) + np_data[2, True, :, 1] = 100 + x[2, True, :, 1] = 100 + + if self.dtype == 'bfloat16': + x = paddle.cast(x, dtype='float32') + + np.testing.assert_allclose(x.numpy(), np_data) + + def test_indexing_is_boolean_false(self): + # indexing is boolean, should improve rank of tensor and then treat it as advanced indexing. + np_data = ( + np.arange(3 * 4 * 5 * 6).reshape((6, 5, 4, 3)).astype(self.ndtype) + ) + + if self.dtype == 'bfloat16': + np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) + if self.dtype == 'complex64' or self.dtype == 'complex32': + np_data = np_data + 1j * np_data + + x = paddle.to_tensor(np_data, dtype=self.dtype) + np_data[False] = 100 + x[False] = 100 + + if self.dtype == 'bfloat16': + x = paddle.cast(x, dtype='float32') + + np.testing.assert_allclose(x.numpy(), np_data) + def test_inplace_with_stride(self): np_v = np.random.randn(3, 1).astype(self.ndtype) if self.dtype == 'bfloat16': @@ -503,3 +543,33 @@ def test_indexing_is_multi_dim_list(self): res = self.exe.run(fetch_list=[y.name]) np.testing.assert_allclose(res[0], np_data) + + def test_indexing_is_boolean_true(self): + # indexing is boolean, should improve rank of tensor and then treat it as advanced indexing. + np_data = np.arange(3 * 4 * 5 * 6).reshape((6, 5, 4, 3)) + np_data[2, True, :, 1] = 100 + + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() + ): + x = paddle.arange(3 * 4 * 5 * 6).reshape((6, 5, 4, 3)) + y = _setitem_static(x, (2, True, slice(None), 1), 100) + + res = self.exe.run(fetch_list=[y.name]) + + np.testing.assert_allclose(res[0], np_data) + + def test_indexing_is_boolean_false(self): + # indexing is boolean, should improve rank of tensor and then treat it as advanced indexing. + np_data = np.arange(3 * 4 * 5 * 6).reshape((6, 5, 4, 3)) + np_data[False] = 100 + + with paddle.static.program_guard( + paddle.static.Program(), paddle.static.Program() + ): + x = paddle.arange(3 * 4 * 5 * 6).reshape((6, 5, 4, 3)) + y = _setitem_static(x, False, 100) + + res = self.exe.run(fetch_list=[y.name]) + + np.testing.assert_allclose(res[0], np_data) From 5c1e797b025ab11f8ddf90221649b072814df433 Mon Sep 17 00:00:00 2001 From: zoooo0820 Date: Thu, 9 Nov 2023 07:22:03 +0000 Subject: [PATCH 2/3] fix ci error --- python/paddle/base/variable_index.py | 14 ++++++++------ test/indexing/test_getitem.py | 5 ----- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/python/paddle/base/variable_index.py b/python/paddle/base/variable_index.py index e36b9bca93cd0d..8320b87b1a81ff 100644 --- a/python/paddle/base/variable_index.py +++ b/python/paddle/base/variable_index.py @@ -694,7 +694,8 @@ def parse_index(x, indices): ) estimated_dim = 0 - for dim, slice_item in enumerate(indices): + dim = 0 + for i, slice_item in enumerate(indices): start, end, step = None, None, None if is_integer_or_scalar_tensor(slice_item): if ( @@ -719,6 +720,7 @@ def parse_index(x, indices): start = slice_item step = 1 end = slice_item + 1 if slice_item != -1 else MAX_INTEGER + dim += 1 elif isinstance(slice_item, bool): # single bool is advanced-indexing none_axes.append(dim) @@ -733,7 +735,7 @@ def parse_index(x, indices): end = slice_item.stop step = slice_item.step estimated_dim += 1 - + dim += 1 if start is None and end is None and step is None: continue @@ -761,7 +763,7 @@ def parse_index(x, indices): has_advanced_index = True estimated_dim += 1 - + dim += 1 elif isinstance(slice_item, paddle.base.Variable): # In this case, the Variable is not 0-dim Tensor and will be treated as advanced-indexing. if ( @@ -781,7 +783,7 @@ def parse_index(x, indices): advanced_index[estimated_dim] = (estimated_dim, slice_item) has_advanced_index = True estimated_dim += 1 - + dim += 1 elif isinstance(slice_item, paddle.pir.OpResult): # In this case, the Variable is not 0-dim Tensor and will be treated as advanced-indexing. if slice_item.dtype == paddle.pir.core.DataType.BOOL: @@ -798,7 +800,7 @@ def parse_index(x, indices): advanced_index[estimated_dim] = (estimated_dim, slice_item) has_advanced_index = True estimated_dim += 1 - + dim += 1 else: raise IndexError( "Valid index accept int / bool / slice / ellipsis / list / Tuple / Ndarray / Tensor, but received {}.".format( @@ -809,7 +811,7 @@ def parse_index(x, indices): starts.append(start) ends.append(end) steps.append(step) - axes.append(dim) + axes.append(dim - 1) use_strided_slice = ( True if ( diff --git a/test/indexing/test_getitem.py b/test/indexing/test_getitem.py index 19f4ce557950fb..d8f95c7458c321 100644 --- a/test/indexing/test_getitem.py +++ b/test/indexing/test_getitem.py @@ -1146,8 +1146,3 @@ def test_bool_shape_error2(self): x = paddle.randn((4, 3, 2)) with self.assertRaises(IndexError): y = _getitem_static(x, (1, paddle.to_tensor([True, False]), [0, 1])) - - def test_bool_error(self): - x = paddle.randn((4, 3, 2)) - with self.assertRaises(ValueError): - y = _getitem_static(x, (True, [0, 1])) From 6e8a422f8f9dd66f4e5928f89322db662d393b6b Mon Sep 17 00:00:00 2001 From: zoooo0820 Date: Thu, 9 Nov 2023 10:21:32 +0000 Subject: [PATCH 3/3] complex32 -> complex128 --- test/indexing/test_getitem.py | 34 +++++++++++++++++----------------- test/indexing/test_setitem.py | 24 ++++++++++++------------ 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/test/indexing/test_getitem.py b/test/indexing/test_getitem.py index d8f95c7458c321..f3a2374ecbe1d0 100644 --- a/test/indexing/test_getitem.py +++ b/test/indexing/test_getitem.py @@ -34,7 +34,7 @@ def test_combined_index_1(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_res = np_data[[0, 1], :, [1, 2]] @@ -52,7 +52,7 @@ def test_combined_index_2(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data x = paddle.to_tensor(np_data, dtype=self.dtype) @@ -70,7 +70,7 @@ def test_combined_index_3(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_res = np_data[[1, 0], :, [1, 4], 1:5:2, 4] @@ -89,7 +89,7 @@ def test_combined_index_4(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_res = np_data[:, [1, 0], 0:4:2, [2, 3], 4] @@ -107,7 +107,7 @@ def test_combined_index_5(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_res = np_data[::2, [1, 0], [2, 3], 0:4:2] @@ -125,7 +125,7 @@ def test_combined_index_6(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_res = np_data[::2, [1, 0], [2, 3], 0:4:2, [4, 6]] @@ -143,7 +143,7 @@ def test_combined_index_7(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_res = np_data[::2, [[1, 0]], [[2, 3]], 0:4:2, [[4, 6]]] @@ -161,7 +161,7 @@ def test_combined_index_8(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_res = np_data[ @@ -181,7 +181,7 @@ def test_combined_index_9(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_res = np_data[[[1, 0]], [1, 0], 0:4:2, [[3, 5], [4, 2]]] @@ -199,7 +199,7 @@ def test_combined_index_10(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_res = np_data[:, [True, False, True, False], 4] @@ -220,7 +220,7 @@ def test_combined_index_11(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_res = np_data[:, [False, False, False, False], 4] @@ -240,7 +240,7 @@ def test_index_has_range(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_res = np_data[:, range(3), 4] @@ -261,7 +261,7 @@ def test_indexing_with_bool_list1(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_res = np_data[[True, False, True], [False, False, False, True]] @@ -282,7 +282,7 @@ def test_indexing_with_bool_list2(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_res = np_data[ @@ -311,7 +311,7 @@ def test_indexing_is_multi_dim_list(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_res = np_data[np.array([[2, 3, 4], [1, 2, 5]])] @@ -334,7 +334,7 @@ def test_indexing_is_boolean_true(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_res = np_data[True] @@ -355,7 +355,7 @@ def test_indexing_is_boolean_false(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_res = np_data[1, False, 0] diff --git a/test/indexing/test_setitem.py b/test/indexing/test_setitem.py index 741696f0dd8fb5..c1d17a45341c00 100644 --- a/test/indexing/test_setitem.py +++ b/test/indexing/test_setitem.py @@ -32,7 +32,7 @@ def test_combined_index_1(self): np_data = np.zeros((3, 4, 5, 6), dtype='float32').astype(self.ndtype) if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data x = paddle.to_tensor(np_data, dtype=self.dtype) @@ -47,7 +47,7 @@ def test_combined_index_2(self): np_data = np.ones((3, 4, 5, 6), dtype='float32').astype(self.ndtype) if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data x = paddle.to_tensor(np_data, dtype=self.dtype) @@ -62,7 +62,7 @@ def test_combined_index_3(self): np_data = np.ones((3, 4, 5, 6), dtype='int32').astype(self.ndtype) if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data x = paddle.to_tensor(np_data, dtype=self.dtype) @@ -77,7 +77,7 @@ def test_index_has_range(self): np_data = np.ones((3, 4, 5, 6), dtype='int32').astype(self.ndtype) if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data x = paddle.to_tensor(np_data, dtype=self.dtype) @@ -93,7 +93,7 @@ def test_src_value_with_different_dtype_1(self): np_data = np.ones((3, 4, 5, 6), dtype='int32').astype(self.ndtype) if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_value = np.zeros((6,), dtype='float32') x = paddle.to_tensor(np_data, dtype=self.dtype) @@ -111,7 +111,7 @@ def test_src_value_with_different_dtype_2(self): np_data = np.ones((3, 4, 5, 6), dtype='float32').astype(self.ndtype) if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data np_value = np.zeros((6,), dtype='int64') @@ -132,7 +132,7 @@ def test_indexing_with_bool_list1(self): ) if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data x = paddle.to_tensor(np_data, dtype=self.dtype) @@ -151,7 +151,7 @@ def test_indexing_with_bool_list2(self): ) if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data x = paddle.to_tensor(np_data, dtype=self.dtype) @@ -178,7 +178,7 @@ def test_indexing_is_multi_dim_list(self): ) if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data x = paddle.to_tensor(np_data, dtype=self.dtype) np_data[np.array([[2, 3, 4], [1, 2, 5]])] = 100 @@ -196,7 +196,7 @@ def test_indexing_is_boolean_true(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data x = paddle.to_tensor(np_data, dtype=self.dtype) @@ -216,7 +216,7 @@ def test_indexing_is_boolean_false(self): if self.dtype == 'bfloat16': np_data = convert_uint16_to_float(convert_float_to_uint16(np_data)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_data = np_data + 1j * np_data x = paddle.to_tensor(np_data, dtype=self.dtype) @@ -232,7 +232,7 @@ def test_inplace_with_stride(self): np_v = np.random.randn(3, 1).astype(self.ndtype) if self.dtype == 'bfloat16': np_v = convert_uint16_to_float(convert_float_to_uint16(np_v)) - if self.dtype == 'complex64' or self.dtype == 'complex32': + if self.dtype == 'complex64' or self.dtype == 'complex128': np_v = np_v + 1j * np_v v = paddle.to_tensor(np_v, dtype=self.dtype) v.stop_gradient = False