Skip to content

Commit

Permalink
Fix np.int and np.float usage in the tree. (apache#8389)
Browse files Browse the repository at this point in the history
* Fix np.int and np.float usage in the tree.

Newer versions of numpy give loads of warnings that suggest
that np.int and np.float will be deprecated. CI uses pytest
and these warning logs clog memory for testing and make it
slower.

* Fix formatting
  • Loading branch information
Ramana Radhakrishnan authored and ylc committed Jan 13, 2022
1 parent e24b0a3 commit 99071af
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
2 changes: 1 addition & 1 deletion python/tvm/autotvm/task/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _encode(x):
return ("TENSOR", get_const_tuple(x.shape), x.dtype)
if isinstance(x, (tuple, list, container.Array)):
return tuple([_encode(a) for a in x])
if isinstance(x, (str, int, float, np.int, np.float, expr.Var, expr.Any)):
if isinstance(x, (str, int, float, expr.Var, expr.Any)):
return x
if isinstance(x, (expr.StringImm, expr.IntImm, expr.FloatImm)):
return x.value
Expand Down
36 changes: 16 additions & 20 deletions python/tvm/topi/testing/depthwise_conv2d_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,15 @@ def depthwise_conv2d_python_nchw(input_np, filter_np, stride, padding):
]
elif padding == "SAME":
out_channel = in_channel * channel_multiplier
out_height = np.int(np.ceil(float(in_height) / float(stride_h)))
out_width = np.int(np.ceil(float(in_width) / float(stride_w)))
out_height = int(np.ceil(float(in_height) / float(stride_h)))
out_width = int(np.ceil(float(in_width) / float(stride_w)))
output_np = np.zeros((batch, out_channel, out_height, out_width))
pad_along_height = np.int(
np.max((out_height - 1) * stride_h + filter_height - in_height, 0)
)
pad_along_width = np.int(np.max((out_width - 1) * stride_w + filter_width - in_width, 0))
pad_top_tvm = np.int(np.ceil(float(pad_along_height) / 2))
pad_left_tvm = np.int(np.ceil(float(pad_along_width) / 2))
pad_top_scipy = np.int(np.ceil(float(filter_height - 1) / 2))
pad_left_scipy = np.int(np.ceil(float(filter_width - 1) / 2))
pad_along_height = int(np.max((out_height - 1) * stride_h + filter_height - in_height, 0))
pad_along_width = int(np.max((out_width - 1) * stride_w + filter_width - in_width, 0))
pad_top_tvm = int(np.ceil(float(pad_along_height) / 2))
pad_left_tvm = int(np.ceil(float(pad_along_width) / 2))
pad_top_scipy = int(np.ceil(float(filter_height - 1) / 2))
pad_left_scipy = int(np.ceil(float(filter_width - 1) / 2))
index_h = pad_top_scipy - pad_top_tvm
index_w = pad_left_scipy - pad_left_tvm
for i in range(batch):
Expand Down Expand Up @@ -138,17 +136,15 @@ def depthwise_conv2d_python_nhwc(input_np, filter_np, stride, padding):
]
if padding == "SAME":
out_channel = in_channel * channel_multiplier
out_height = np.int(np.ceil(float(in_height) / float(stride_h)))
out_width = np.int(np.ceil(float(in_width) / float(stride_w)))
out_height = int(np.ceil(float(in_height) / float(stride_h)))
out_width = int(np.ceil(float(in_width) / float(stride_w)))
output_np = np.zeros((batch, out_height, out_width, out_channel))
pad_along_height = np.int(
np.max((out_height - 1) * stride_h + filter_height - in_height, 0)
)
pad_along_width = np.int(np.max((out_width - 1) * stride_w + filter_width - in_width, 0))
pad_top_tvm = np.int(np.ceil(float(pad_along_height) / 2))
pad_left_tvm = np.int(np.ceil(float(pad_along_width) / 2))
pad_top_scipy = np.int(np.ceil(float(filter_height - 1) / 2))
pad_left_scipy = np.int(np.ceil(float(filter_width - 1) / 2))
pad_along_height = int(np.max((out_height - 1) * stride_h + filter_height - in_height, 0))
pad_along_width = int(np.max((out_width - 1) * stride_w + filter_width - in_width, 0))
pad_top_tvm = int(np.ceil(float(pad_along_height) / 2))
pad_left_tvm = int(np.ceil(float(pad_along_width) / 2))
pad_top_scipy = int(np.ceil(float(filter_height - 1) / 2))
pad_left_scipy = int(np.ceil(float(filter_width - 1) / 2))
index_h = pad_top_scipy - pad_top_tvm
index_w = pad_left_scipy - pad_left_tvm
for i in range(batch):
Expand Down

0 comments on commit 99071af

Please sign in to comment.