Skip to content

Commit

Permalink
Cleanup more uses of np.bool and np.int. (apache#8399)
Browse files Browse the repository at this point in the history
In a similar vein to previous pull requests
replacing deprecated use of np.bool and np.int from
numpy with bool and int.

https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
  • Loading branch information
Ramana Radhakrishnan authored and ylc committed Jan 13, 2022
1 parent 5d23037 commit 6b0817a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
16 changes: 8 additions & 8 deletions tests/python/frontend/onnx/test_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -2254,7 +2254,7 @@ def verify_where(condition, x, y, dtype, outdata, dynamic=False):

@tvm.testing.uses_gpu
def test_where():
condition = np.array([[1, 0], [1, 1]], dtype=np.bool)
condition = np.array([[1, 0], [1, 1]], dtype=bool)
x = np.array([[1, 2], [3, 4]], dtype=np.int64)
y = np.array([[9, 8], [7, 6]], dtype=np.int64)
outdata = np.where(condition, x, y)
Expand All @@ -2275,7 +2275,7 @@ def test_where():
outdata = np.where(condition, x, y)
verify_where(condition, x, y, TensorProto.FLOAT, outdata)

condition = np.array(1, dtype=np.bool)
condition = np.array(1, dtype=bool)
x = np.array([[1, 2], [3, 4]], dtype=np.float32)
y = np.array([[5, 6], [7, 8]], dtype=np.float32)
outdata = np.where(condition, x, y)
Expand Down Expand Up @@ -3965,7 +3965,7 @@ def verify_cond_loop():

trip_count = np.array(5).astype(np.int64)
res_y = np.array([13]).astype(np.float32)
cond = np.array(1).astype(np.bool)
cond = np.array(1).astype(bool)
loop_graph = onnx.helper.make_graph(
[loop_node],
"loop_outer",
Expand All @@ -3983,7 +3983,7 @@ def verify_cond_loop():

# Set a high trip count so that condition trips first.
trip_count = np.array(40).astype(np.int64)
cond = np.array(1).astype(np.bool)
cond = np.array(1).astype(bool)
input_vals = [trip_count, cond, y]
verify_with_ort_with_inputs(loop_model, input_vals, use_vm=True, freeze_params=True)

Expand Down Expand Up @@ -4021,7 +4021,7 @@ def verify_count_loop():

trip_count = np.array(5).astype(np.int64)
res_y = np.array([13]).astype(np.float32)
cond = np.array(1).astype(np.bool)
cond = np.array(1).astype(bool)
loop_graph = onnx.helper.make_graph(
[loop_node],
"loop_outer",
Expand All @@ -4038,7 +4038,7 @@ def verify_count_loop():
loop_model = onnx.helper.make_model(loop_graph)

trip_count = np.array(5).astype(np.int64)
cond = np.array(1).astype(np.bool)
cond = np.array(1).astype(bool)
input_vals = [trip_count, cond, y]
verify_with_ort_with_inputs(loop_model, input_vals, use_vm=True, freeze_params=True)

Expand Down Expand Up @@ -4075,7 +4075,7 @@ def verify_tensor_loop():
)

trip_count = np.array(5).astype(np.int64)
cond = np.array(1).astype(np.bool)
cond = np.array(1).astype(bool)
loop_graph = onnx.helper.make_graph(
[loop_node],
"loop_outer",
Expand All @@ -4092,7 +4092,7 @@ def verify_tensor_loop():
loop_model = onnx.helper.make_model(loop_graph)

trip_count = np.array(5).astype(np.int64)
cond = np.array(1).astype(np.bool)
cond = np.array(1).astype(bool)
input_vals = [trip_count, cond, y]
verify_with_ort_with_inputs(
loop_model, input_vals, use_vm=True, freeze_params=True, convert_to_static=True
Expand Down
6 changes: 3 additions & 3 deletions tests/python/relay/test_op_level4.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def verify(x_np, y_np, cond_np):

x_np = np.array(1.0, dtype)
y_np = np.array(-1.0, dtype)
cond_np = np.array([1, 0, 1], dtype=np.bool)
cond_np = np.array([1, 0, 1], dtype=bool)

verify(x_np, y_np, cond_np)

Expand All @@ -201,7 +201,7 @@ def verify(x_np, y_np, cond_np):

x_np = np.array([[1, 2], [3, 4]], dtype)
y_np = np.array([[5, 6], [7, 8]], dtype)
cond_np = np.array([[1], [0]], dtype=np.bool)
cond_np = np.array([[1], [0]], dtype=bool)

verify(x_np, y_np, cond_np)
verify(x_np, y_np, cond_np.T)
Expand All @@ -213,7 +213,7 @@ def verify(x_np, y_np, cond_np):
verify(x_np, y_np, cond_np)

x_np, y_np = np.ogrid[:3, :4]
cond_np = np.where(x_np < y_np, x_np, 10 + y_np).astype(np.bool)
cond_np = np.where(x_np < y_np, x_np, 10 + y_np).astype(bool)

verify(x_np.astype(dtype), y_np.astype(dtype), cond_np)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def verify_depthwise_conv2d_back_weight(
stride_w = stride_h
padding_w = padding_h

out_h = np.int((in_h + 2 * padding_h - filter_h) / stride_h + 1)
out_w = np.int((in_w + 2 * padding_w - filter_w) / stride_w + 1)
out_h = int((in_h + 2 * padding_h - filter_h) / stride_h + 1)
out_w = int((in_w + 2 * padding_w - filter_w) / stride_w + 1)
out_channel = in_channel * channel_multiplier

oshape = [batch, out_h, out_w, out_channel]
Expand Down
4 changes: 2 additions & 2 deletions tests/python/unittest/test_tir_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_const():
def test_scalar_dtype_inference():
for data in [
True,
np.bool(1),
bool(1),
np.uint8(1),
np.uint16(1),
np.uint32(1),
Expand All @@ -48,7 +48,7 @@ def test_scalar_dtype_inference():

for data in [
True,
np.bool(1),
bool(1),
np.uint8(1),
np.uint16(1),
np.uint32(1),
Expand Down

0 comments on commit 6b0817a

Please sign in to comment.