Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix numpy 1.20+ deprecation warnings #42929

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python/paddle/distributed/fleet/base/fleet_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1811,8 +1811,8 @@ def unscale_method(self, optimizer):
if (param._grad_ivar() is not None) and (
param._grad_ivar().dtype == core.VarDesc.VarType.FP32)
]
temp_found_inf_fp16 = to_variable(np.array([0]).astype(np.bool))
temp_found_inf_fp32 = to_variable(np.array([0]).astype(np.bool))
temp_found_inf_fp16 = to_variable(np.array([0]).astype(np.bool_))
temp_found_inf_fp32 = to_variable(np.array([0]).astype(np.bool_))
if len(param_grads_fp16):
_C_ops.check_finite_and_unscale(param_grads_fp16, self._scale,
param_grads_fp16,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ def unscale_method(self, optimizer):
else:
param_grads_fp32.append(param.grad)

temp_found_inf_fp16 = to_variable(np.array([0]).astype(np.bool))
temp_found_inf_fp32 = to_variable(np.array([0]).astype(np.bool))
temp_found_inf_fp16 = to_variable(np.array([0]).astype(np.bool_))
temp_found_inf_fp32 = to_variable(np.array([0]).astype(np.bool_))

device = "cpu" if optimizer.offload else "gpu"
dev_id = 0 if device == "cpu" else int(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ def unscale_method(self, optimizer):
else:
param_grads_fp32.append(param.grad)

temp_found_inf_fp16 = to_variable(np.array([0]).astype(np.bool))
temp_found_inf_fp32 = to_variable(np.array([0]).astype(np.bool))
temp_found_inf_fp16 = to_variable(np.array([0]).astype(np.bool_))
temp_found_inf_fp32 = to_variable(np.array([0]).astype(np.bool_))

device = "cpu" if optimizer.offload else "gpu"
dev_id = 0 if device == "cpu" else int(
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/data_feeder.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def convert_dtype(dtype):
return _PADDLE_DTYPE_2_NUMPY_DTYPE[dtype]
elif isinstance(dtype, type):
if dtype in [
np.bool, np.float16, np.uint16, np.float32, np.float64, np.int8,
bool, np.float16, np.uint16, np.float32, np.float64, np.int8,
np.int16, np.int32, np.int64, np.uint8, np.complex64,
np.complex128
]:
Expand Down
6 changes: 3 additions & 3 deletions python/paddle/fluid/dygraph/amp/loss_scaler.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ def __init__(self,
self._decr_count = 0
self._use_dynamic_loss_scaling = use_dynamic_loss_scaling

self._found_inf = to_variable(np.array([0]).astype(np.bool))
self._found_inf = to_variable(np.array([0]).astype(np.bool_))
self._temp_found_inf_fp16 = to_variable(
np.array([0]).astype(np.bool))
np.array([0]).astype(np.bool_))
self._temp_found_inf_fp32 = to_variable(
np.array([0]).astype(np.bool))
np.array([0]).astype(np.bool_))
self._scale = to_variable(
np.array([self._init_loss_scaling]).astype(np.float32))
self._cache_founf_inf = None
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def _as_lodtensor(data, place, dtype=None):
data = np.array([data]).astype(dtype)
elif isinstance(data, (list, tuple)):
data = np.array(data)
if data.dtype == np.object:
if data.dtype == np.object_:
raise TypeError(
"\n\tFaild to convert input data to a regular ndarray :\n\t* Usually "
"this means the input data contains nested lists with different lengths. "
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -1110,7 +1110,7 @@ def convert_np_dtype_to_dtype_(np_dtype):
return core.VarDesc.VarType.INT16
elif dtype == np.int64:
return core.VarDesc.VarType.INT64
elif dtype == np.bool:
elif dtype == np.bool_:
return core.VarDesc.VarType.BOOL
elif dtype == np.uint16:
# since there is still no support for bfloat16 in NumPy,
Expand Down
8 changes: 4 additions & 4 deletions python/paddle/fluid/layers/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -12860,8 +12860,8 @@ def logical_or(x, y, out=None, name=None):
import paddle
import numpy as np

x_data = np.array([True, False], dtype=np.bool).reshape(2, 1)
y_data = np.array([True, False, True, False], dtype=np.bool).reshape(2, 2)
x_data = np.array([True, False], dtype=np.bool_).reshape(2, 1)
y_data = np.array([True, False, True, False], dtype=np.bool_).reshape(2, 2)
x = paddle.to_tensor(x_data)
y = paddle.to_tensor(y_data)
res = paddle.logical_or(x, y)
Expand Down Expand Up @@ -12905,8 +12905,8 @@ def logical_xor(x, y, out=None, name=None):
import paddle
import numpy as np

x_data = np.array([True, False], dtype=np.bool).reshape([2, 1])
y_data = np.array([True, False, True, False], dtype=np.bool).reshape([2, 2])
x_data = np.array([True, False], dtype=np.bool_).reshape([2, 1])
y_data = np.array([True, False, True, False], dtype=np.bool_).reshape([2, 2])
x = paddle.to_tensor(x_data)
y = paddle.to_tensor(y_data)
res = paddle.logical_xor(x, y)
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def __next__(self):
@classmethod
def _check_input_array(cls, item):
arr = np.asarray(item)
if arr.dtype == np.object:
if arr.dtype == np.object_:
raise TypeError(
"\n\tFaild to convert input data to a regular ndarray :\n\t* Usually "
"this means the input data contains nested lists with different lengths. "
Expand Down
10 changes: 5 additions & 5 deletions python/paddle/fluid/tests/unittests/fft/test_fft.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ def rand_x(dims=1,
complex=False):
shape = [np.random.randint(min_dim_len, max_dim_len) for i in range(dims)]
if complex:
return np.random.randn(*shape).astype(
dtype) + 1.j * np.random.randn(*shape).astype(dtype)
return np.random.randn(
*shape).astype(dtype) + 1.j * np.random.randn(*shape).astype(dtype)
else:
return np.random.randn(*shape).astype(dtype)

Expand Down Expand Up @@ -473,7 +473,7 @@ def test_irfft2(self):
@parameterize((TEST_CASE_NAME, 'x', 'n', 'axis', 'norm', 'expect_exception'), [
('test_bool_input',
(np.random.randn(4, 4, 4) + 1j * np.random.randn(4, 4, 4)).astype(
np.bool8), None, -1, 'backward', NotImplementedError),
np.bool_), None, -1, 'backward', NotImplementedError),
('test_n_nagative', np.random.randn(4, 4, 4) +
1j * np.random.randn(4, 4, 4), -1, -1, 'backward', ValueError),
('test_n_zero', np.random.randn(4, 4) + 1j * np.random.randn(4, 4), 0, -1,
Expand Down Expand Up @@ -543,7 +543,7 @@ def test_irfft(self):
(TEST_CASE_NAME, 'x', 'n', 'axis', 'norm', 'expect_exception'),
[('test_bool_input',
(np.random.randn(4, 4, 4) + 1j * np.random.randn(4, 4, 4)).astype(
np.bool8), None, (-2, -1), 'backward', NotImplementedError),
np.bool_), None, (-2, -1), 'backward', NotImplementedError),
('test_n_nagative',
np.random.randn(4, 4, 4) + 1j * np.random.randn(4, 4, 4), (-1, -2),
(-2, -1), 'backward', ValueError),
Expand Down Expand Up @@ -625,7 +625,7 @@ def test_irfft2(self):
(TEST_CASE_NAME, 'x', 'n', 'axis', 'norm', 'expect_exception'),
[('test_bool_input',
(np.random.randn(4, 4, 4) + 1j * np.random.randn(4, 4, 4)).astype(
np.bool8), None, (-2, -1), 'backward', NotImplementedError),
np.bool_), None, (-2, -1), 'backward', NotImplementedError),
('test_n_nagative',
np.random.randn(4, 4, 4) + 1j * np.random.randn(4, 4, 4), (-1, -2),
(-2, -1), 'backward', ValueError),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def test_static_irfft2(self):
4), None, -1, 'backward', TypeError),
('test_bool_input',
(np.random.randn(4, 4, 4) + 1j * np.random.randn(4, 4, 4)).astype(
np.bool8), None, -1, 'backward', TypeError),
np.bool_), None, -1, 'backward', TypeError),
('test_n_nagative', np.random.randn(4, 4, 4) +
1j * np.random.randn(4, 4, 4), -1, -1, 'backward', ValueError),
('test_n_zero', np.random.randn(4, 4) + 1j * np.random.randn(4, 4), 0, -1,
Expand Down Expand Up @@ -406,7 +406,7 @@ def test_static_hfft(self):
4), None, -1, 'backward', TypeError),
('test_bool_input',
(np.random.randn(4, 4, 4) + 1j * np.random.randn(4, 4, 4)).astype(
np.bool8), None, -1, 'backward', TypeError),
np.bool_), None, -1, 'backward', TypeError),
('test_n_nagative', np.random.randn(4, 4, 4) +
1j * np.random.randn(4, 4, 4), -1, -1, 'backward', ValueError),
('test_n_zero', np.random.randn(4, 4) + 1j * np.random.randn(4, 4), 0, -1,
Expand Down Expand Up @@ -444,7 +444,7 @@ def test_static_irfft(self):
4, 4, 4), None, None, 'backward', TypeError),
('test_bool_input',
(np.random.randn(4, 4, 4) + 1j * np.random.randn(4, 4, 4)).astype(
np.bool8), None, (-2, -1), 'backward', TypeError),
np.bool_), None, (-2, -1), 'backward', TypeError),
('test_n_nagative',
np.random.randn(4, 4, 4) + 1j * np.random.randn(4, 4, 4), (-1, -2),
(-2, -1), 'backward', ValueError),
Expand Down Expand Up @@ -485,7 +485,7 @@ def test_static_hfft2(self):
4, 4, 4), None, None, 'backward', TypeError),
('test_bool_input',
(np.random.randn(4, 4, 4) + 1j * np.random.randn(4, 4, 4)).astype(
np.bool8), None, (-2, -1), 'backward', TypeError),
np.bool_), None, (-2, -1), 'backward', TypeError),
('test_n_nagative',
np.random.randn(4, 4, 4) + 1j * np.random.randn(4, 4, 4), (-1, -2),
(-2, -1), 'backward', ValueError),
Expand Down Expand Up @@ -526,7 +526,7 @@ def test_static_irfft2(self):
4, 4, 4), None, None, 'backward', TypeError),
('test_bool_input',
(np.random.randn(4, 4, 4) + 1j * np.random.randn(4, 4, 4)).astype(
np.bool8), None, (-2, -1), 'backward', TypeError),
np.bool_), None, (-2, -1), 'backward', TypeError),
('test_n_nagative',
np.random.randn(4, 4, 4) + 1j * np.random.randn(4, 4, 4), (-1, -2),
(-2, -1), 'backward', ValueError),
Expand Down Expand Up @@ -568,7 +568,7 @@ def test_static_hfftn(self):
4, 4, 4), None, None, 'backward', TypeError),
# ('test_bool_input',
# (np.random.randn(4, 4, 4) + 1j * np.random.randn(4, 4, 4)
# ).astype(np.bool8), None, (-2, -1), 'backward', ValueError),
# ).astype(np.bool_), None, (-2, -1), 'backward', ValueError),
('test_n_nagative',
np.random.randn(4, 4, 4) + 1j * np.random.randn(4, 4, 4), (-1, -2),
(-2, -1), 'backward', ValueError),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def set_data_feed(self):
self.feed_fp32 = {'in_0': data.astype(np.float32)}
self.feed_fp16 = {'in_0': data.astype(np.float16)}
data = np.random.choice([True, False], size=(2, 3, 1))
self.assign_bool = data.astype(np.bool)
self.assign_bool = data.astype(np.bool_)

@IPUOpTest.static_graph
def build_model(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def init_data(self):

B_data = np.random.uniform(-127, 127, (5, 20)).astype(np.float32)

quant_B = np.round(B_data * self.scale_y[0]).astype(np.int)
quant_B = np.round(B_data * self.scale_y[0]).astype(np.int_)
output = np.dot(A_data, quant_B)

scale_output_shift = (self.scale_out) / \
Expand Down Expand Up @@ -136,7 +136,7 @@ def init_data(self):
A_data_reshape = A_data.reshape(3 * 4, 4 * 3)
B_data_reshape = B_data.reshape(2 * 6, 1 * 2 * 3)

quant_B = np.round(B_data_reshape * self.scale_y[0]).astype(np.int)
quant_B = np.round(B_data_reshape * self.scale_y[0]).astype(np.int_)
output = np.dot(A_data_reshape, quant_B)

scale_output_shift = (self.scale_out) / \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def setUp(self):
self.shape = self.get_x_shape()
self.axis = self.get_axis()

x = np.random.uniform(0.1, 1, self.shape).astype(np.float)
x = np.random.uniform(0.1, 1, self.shape).astype(np.float64)
zlsh80826 marked this conversation as resolved.
Show resolved Hide resolved
out = convert_float_to_uint16(
np.apply_along_axis(stable_softmax, self.axis, x))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def set_attrs(self):
}
if self.use_variance:
self.attrs['variance'] = self.prior_box_var.astype(
np.float).flatten()
np.float64).flatten()
zlsh80826 marked this conversation as resolved.
Show resolved Hide resolved
if self.axis != 0:
self.attrs['axis'] = self.axis

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def init_test_params(self):
self.batch_size = 10

self.variances = [0.1, 0.1, 0.2, 0.2]
self.variances = np.array(self.variances, dtype=np.float).flatten()
self.variances = np.array(self.variances, dtype=np.float64).flatten()
zlsh80826 marked this conversation as resolved.
Show resolved Hide resolved

self.clip = True
self.num_priors = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_check_output(self):
class TestFillZerosLikeOpBool(TestFillZerosLikeOp):

def init_dtype(self):
self.dtype = np.bool
self.dtype = np.bool_


class TestFillZerosLikeOpFp16(TestFillZerosLikeOp):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def init_test_params(self):
self.set_min_max_aspect_ratios_order()
self.real_aspect_ratios = [1, 2.0, 1.0 / 2.0, 3.0, 1.0 / 3.0]
self.aspect_ratios = np.array(self.aspect_ratios,
dtype=np.float).flatten()
dtype=np.float64).flatten()
self.variances = [0.1, 0.1, 0.2, 0.2]
self.variances = np.array(self.variances, dtype=np.float).flatten()
self.variances = np.array(self.variances, dtype=np.float64).flatten()
zlsh80826 marked this conversation as resolved.
Show resolved Hide resolved

self.clip = True
self.num_priors = len(self.real_aspect_ratios) * len(self.min_sizes)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def setUp(self):
}
self.outputs = {
'Out':
self.inputs['X'].max(axis=tuple(self.attrs['dim'])).astype(np.bool)
self.inputs['X'].max(axis=tuple(self.attrs['dim'])).astype(np.bool_)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def setUp(self):
}
self.outputs = {
'Out':
self.inputs['X'].min(axis=tuple(self.attrs['dim'])).astype(np.bool)
self.inputs['X'].min(axis=tuple(self.attrs['dim'])).astype(np.bool_)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,8 @@ def setUp(self):
self.attrs = {'dim': [0], 'out_dtype': int(core.VarDesc.VarType.BOOL)}
self.outputs = {
'Out':
self.inputs['X'].prod(axis=tuple(self.attrs['dim'])).astype(np.bool)
self.inputs['X'].prod(axis=tuple(self.attrs['dim'])).astype(
np.bool_)
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class TestSizeOp4(TestSizeOp):

def config(self):
self.shape = [2**10]
self.dtype = np.bool
self.dtype = np.bool_


class TestSizeOp5(TestSizeOp):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def test_check_output(self):
self.check_output_with_place(self.place)

def init_dtype(self):
self.dtype = np.bool
self.dtype = np.bool_

def initTestCase(self):
self.real_op_type = np.random.choice(['triu', 'tril'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def setUp(self):

self.init()
fluid.core.globals()['FLAGS_min_loss_scaling'] = 1639
found_inf = np.array([True], dtype=np.bool)
found_inf = np.array([True], dtype=np.bool_)
x = np.random.random((1024, 1024)).astype(self.dtype)
i = np.random.randint(0, 1024, 1)
j = np.random.randint(0, 1024, 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def setUp(self):
self.place = paddle.NPUPlace(0)

self.init()
found_inf = np.array([False], dtype=np.bool)
found_inf = np.array([False], dtype=np.bool_)
x = np.random.random((1024, 1024)).astype(self.dtype)

self.inputs = {
Expand Down Expand Up @@ -82,7 +82,7 @@ def setUp(self):
self.place = paddle.NPUPlace(0)

self.init()
found_inf = np.array([True], dtype=np.bool)
found_inf = np.array([True], dtype=np.bool_)
x = np.random.random((1024, 1024)).astype(self.dtype)
i = np.random.randint(0, 1024, 1)
j = np.random.randint(0, 1024, 1)
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/op_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ def infer_dtype(numpy_dict, dtype_set):
np.dtype(np.int16),
np.dtype(np.int8),
np.dtype(np.uint8),
np.dtype(np.bool)
np.dtype(np.bool_)
]
# check the dtype in dtype_list in order, select the first dtype that in dtype_set
for dtype in dtype_list:
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_assign_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def test_assign_LoDTensorArray(self):

def test_assign_NumpyArray(self):
with fluid.dygraph.guard():
array = np.random.random(size=(100, 10)).astype(np.bool)
array = np.random.random(size=(100, 10)).astype(np.bool_)
result1 = paddle.zeros(shape=[3, 3], dtype='float32')
paddle.assign(array, result1)
self.assertTrue(np.allclose(result1.numpy(), array))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def bipartite_match(distance, match_indices, match_dist):

match_sorted = sorted(match_pair, key=lambda tup: tup[2], reverse=True)

row_indices = -1 * np.ones((row, ), dtype=np.int)
row_indices = -1 * np.ones((row, ), dtype=np.int_)

idx = 0
for i, j, dist in match_sorted:
Expand Down Expand Up @@ -69,7 +69,7 @@ def batch_bipartite_match(distance, lod, match_type=None, dist_threshold=None):
"""
n = len(lod)
m = distance.shape[1]
match_indices = -1 * np.ones((n, m), dtype=np.int)
match_indices = -1 * np.ones((n, m), dtype=np.int_)
match_dist = np.zeros((n, m), dtype=np.float32)
cur_offset = 0
for i in range(n):
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/fluid/tests/unittests/test_box_coder_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def setUp(self):
self.attrs = {
'code_type': 'decode_center_size',
'box_normalized': False,
'variance': prior_box_var.astype(np.float).flatten(),
'variance': prior_box_var.astype(np.float64).flatten(),
zlsh80826 marked this conversation as resolved.
Show resolved Hide resolved
'axis': axis
}
self.outputs = {'OutputBox': output_box}
Expand Down
Loading