Skip to content

Commit

Permalink
Replaced all occurrences of np.bool to np.bool_ and np.complex to np.…
Browse files Browse the repository at this point in the history
…complex_
  • Loading branch information
u7122029 committed Jul 26, 2023
1 parent 0101108 commit 418f22d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion imgaug/augmentables/polys.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ def extract_from_image(self, image):
rr_face, cc_face = skimage.draw.polygon(
yy_mask, xx_mask, shape=(height_mask, width_mask))

mask = np.zeros((height_mask, width_mask), dtype=np.bool)
mask = np.zeros((height_mask, width_mask), dtype=np.bool_)
mask[rr_face, cc_face] = True

if image.ndim == 3:
Expand Down
2 changes: 1 addition & 1 deletion imgaug/augmenters/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -3384,7 +3384,7 @@ def _get_augmenter_active(self, nb_rows, random_state):
# pylint: disable=invalid-name
nn = self._get_n(nb_rows, random_state)
nn = [min(n, len(self)) for n in nn]
augmenter_active = np.zeros((nb_rows, len(self)), dtype=np.bool)
augmenter_active = np.zeros((nb_rows, len(self)), dtype=np.bool_)
for row_idx, n_true in enumerate(nn):
if n_true > 0:
augmenter_active[row_idx, 0:n_true] = 1
Expand Down
4 changes: 2 additions & 2 deletions imgaug/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -2588,7 +2588,7 @@ def _draw_samples(self, size, random_state):
# result = np.float_power(samples, exponents)
# TODO why was float32 type here replaced with complex number
# formulation?
result = np.power(samples.astype(np.complex), exponents).real
result = np.power(samples.astype(np.complex_), exponents).real
if result.dtype != samples_dtype:
result = result.astype(samples_dtype)

Expand Down Expand Up @@ -3558,7 +3558,7 @@ def _draw_samples_hw(self, height, width, random_state):
wn = wn.astype(np.float32)

# equivalent but slightly faster then:
# wn_freqs_mul = np.zeros(treal.shape, dtype=np.complex)
# wn_freqs_mul = np.zeros(treal.shape, dtype=np.complex_)
# wn_freqs_mul.real = wn[0]
# wn_freqs_mul.imag = wn[1]
# wn_inv = np.fft.ifft2(wn_freqs_mul).real
Expand Down
8 changes: 4 additions & 4 deletions test/augmentables/test_bbs.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,7 @@ def test_draw_label_on_image(self):
def _get_standard_draw_box_on_image_vars(cls):
image = np.zeros((10, 10, 3), dtype=np.uint8)
bb = ia.BoundingBox(y1=1, x1=1, y2=3, x2=3)
bb_mask = np.zeros(image.shape[0:2], dtype=np.bool)
bb_mask = np.zeros(image.shape[0:2], dtype=np.bool_)
bb_mask[1:3+1, 1] = True
bb_mask[1:3+1, 3] = True
bb_mask[1, 1:3+1] = True
Expand Down Expand Up @@ -823,7 +823,7 @@ def test_draw_box_on_image_no_copy(self):
def test_draw_box_on_image_bb_outside_of_image(self):
image = np.zeros((10, 10, 3), dtype=np.uint8)
bb = ia.BoundingBox(y1=-1, x1=-1, y2=2, x2=2)
bb_mask = np.zeros(image.shape[0:2], dtype=np.bool)
bb_mask = np.zeros(image.shape[0:2], dtype=np.bool_)
bb_mask[2, 0:3] = True
bb_mask[0:3, 2] = True

Expand All @@ -837,7 +837,7 @@ def test_draw_box_on_image_bb_outside_of_image(self):
def test_draw_box_on_image_bb_outside_of_image_and_very_small(self):
image, bb, bb_mask = self._get_standard_draw_box_on_image_vars()
bb = ia.BoundingBox(y1=-1, x1=-1, y2=1, x2=1)
bb_mask = np.zeros(image.shape[0:2], dtype=np.bool)
bb_mask = np.zeros(image.shape[0:2], dtype=np.bool_)
bb_mask[0:1+1, 1] = True
bb_mask[1, 0:1+1] = True

Expand All @@ -850,7 +850,7 @@ def test_draw_box_on_image_bb_outside_of_image_and_very_small(self):

def test_draw_box_on_image_size_2(self):
image, bb, _ = self._get_standard_draw_box_on_image_vars()
bb_mask = np.zeros(image.shape[0:2], dtype=np.bool)
bb_mask = np.zeros(image.shape[0:2], dtype=np.bool_)
bb_mask[0:5, 0:5] = True
bb_mask[2, 2] = False

Expand Down
22 changes: 11 additions & 11 deletions test/augmentables/test_kps.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ def test_draw_on_image(self):
kpi = ia.KeypointsOnImage(keypoints=kps, shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=np.bool_)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand All @@ -640,7 +640,7 @@ def test_draw_on_image_alpha_is_50_percent(self):
kpi = ia.KeypointsOnImage(keypoints=kps, shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=np.bool_)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand All @@ -659,7 +659,7 @@ def test_draw_on_image_size_3(self):
kpi = ia.KeypointsOnImage(keypoints=kps, shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=np.bool_)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand All @@ -678,7 +678,7 @@ def test_draw_on_image_blue_color(self):
kpi = ia.KeypointsOnImage(keypoints=kps, shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=np.bool_)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand All @@ -694,7 +694,7 @@ def test_draw_on_image_single_int_as_color(self):
kpi = ia.KeypointsOnImage(keypoints=kps, shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=np.bool_)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand All @@ -710,7 +710,7 @@ def test_draw_on_image_copy_is_false(self):
kpi = ia.KeypointsOnImage(keypoints=kps, shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=np.bool_)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand All @@ -733,7 +733,7 @@ def test_draw_on_image_keypoint_is_outside_of_image(self):
)
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=np.bool_)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand Down Expand Up @@ -766,7 +766,7 @@ def test_draw_on_image_one_kp_at_bottom_right_corner(self):
shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=np.bool_)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand All @@ -784,7 +784,7 @@ def test_draw_on_image_one_kp_at_bottom_right_corner_and_raise_true(self):
shape=(5, 5, 3))
image = np.zeros((5, 5, 3), dtype=np.uint8) + 10

kps_mask = np.zeros(image.shape[0:2], dtype=np.bool)
kps_mask = np.zeros(image.shape[0:2], dtype=np.bool_)
kps_mask[2, 1] = 1
kps_mask[4, 3] = 1

Expand Down Expand Up @@ -908,7 +908,7 @@ def test_to_keypoint_image_size_1(self):

image = kpi.to_keypoint_image(size=1)

kps_mask = np.zeros((5, 5, 2), dtype=np.bool)
kps_mask = np.zeros((5, 5, 2), dtype=np.bool_)
kps_mask[2, 1, 0] = 1
kps_mask[4, 3, 1] = 1
assert np.all(image[kps_mask] == 255)
Expand All @@ -920,7 +920,7 @@ def test_to_keypoint_image_size_3(self):

image = kpi.to_keypoint_image(size=3)

kps_mask = np.zeros((5, 5, 2), dtype=np.bool)
kps_mask = np.zeros((5, 5, 2), dtype=np.bool_)
kps_mask[2-1:2+1+1, 1-1:1+1+1, 0] = 1
kps_mask[4-1:4+1+1, 3-1:3+1+1, 1] = 1
assert np.all(image[kps_mask] >= 128)
Expand Down
2 changes: 1 addition & 1 deletion test/augmentables/test_segmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_bool_arr_3d(self):
def test_boolean_masks(self):
# Test for #189 (boolean mask inputs into SegmentationMapsOnImage not
# working)
for dt in [bool, np.bool]:
for dt in [bool, np.bool_]:
arr = np.array([
[0, 0, 0],
[0, 1, 0],
Expand Down
3 changes: 0 additions & 3 deletions test/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,9 +378,6 @@ def test_int_to_uint_with_clip(self):
# TODO is the copy_* function still used anywhere
class Test_copy_dtypes_for_restore(unittest.TestCase):
def test_images_as_list(self):
# TODO using dtype=np.bool is causing this to fail as it ends up
# being <type bool> instead of <type 'numpy.bool_'>.
# Any problems from that for the library?
images = [
np.zeros((1, 1, 3), dtype=np.uint8),
np.zeros((10, 16, 3), dtype=np.float32),
Expand Down
4 changes: 2 additions & 2 deletions test/test_imgaug.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class _Dummy(object):
np.zeros((1, 2), dtype=np.float16),
np.zeros((100,), dtype=np.float32),
np.zeros((1, 2), dtype=np.float64),
np.zeros((1, 2), dtype=np.bool)
np.zeros((1, 2), dtype=np.bool_)
]
for value in values_true:
assert ia.is_integer_array(value) is True
Expand All @@ -250,7 +250,7 @@ class _Dummy(object):
np.zeros((1, 2), dtype=np.uint16),
np.zeros((1, 2), dtype=np.int32),
np.zeros((1, 2), dtype=np.int64),
np.zeros((1, 2), dtype=np.bool)
np.zeros((1, 2), dtype=np.bool_)
]
for value in values_true:
assert ia.is_float_array(value) is True
Expand Down

0 comments on commit 418f22d

Please sign in to comment.