Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 monai/data/synthetic.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def create_test_image_2d(
raise ValueError(f"the minimal size {min_size} of the image should be larger than `2 * rad_max` 2x{rad_max}.")

image = np.zeros((height, width))
rs: np.random.RandomState = np.random.random.__self__ if random_state is None else random_state # type: ignore
rs: np.random.RandomState = np.random.RandomState() if random_state is None else random_state

for _ in range(num_objs):
x = rs.randint(rad_max, height - rad_max)
Expand Down Expand Up @@ -139,7 +139,7 @@ def create_test_image_3d(
raise ValueError(f"the minimal size {min_size} of the image should be larger than `2 * rad_max` 2x{rad_max}.")

image = np.zeros((height, width, depth))
rs: np.random.RandomState = np.random.random.__self__ if random_state is None else random_state # type: ignore
rs: np.random.RandomState = np.random.RandomState() if random_state is None else random_state

for _ in range(num_objs):
x = rs.randint(rad_max, height - rad_max)
Expand Down
2 changes: 1 addition & 1 deletion monai/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def get_random_patch(
"""

# choose the minimal corner of the patch
rand_int = np.random.randint if rand_state is None else rand_state.randint
rand_int = np.random.RandomState().randint if rand_state is None else rand_state.randint
min_corner = tuple(rand_int(0, ms - ps + 1) if ms > ps else 0 for ms, ps in zip(dims, patch_size))

# create the slices for each dimension which define the patch in the source array
Expand Down
4 changes: 2 additions & 2 deletions monai/transforms/signal/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ def __call__(self, signal: NdarrayOrTensor) -> NdarrayOrTensor:
data = convert_to_tensor(self.freqs * time_partial)
sine_partial = self.magnitude * torch.sin(data)

loc = np.random.choice(range(length))
loc = self.R.choice(range(length))
signal = paste(signal, sine_partial, (loc,))

return signal
Expand Down Expand Up @@ -354,7 +354,7 @@ def __call__(self, signal: NdarrayOrTensor) -> NdarrayOrTensor:
time_partial = np.arange(0, round(self.fracs * length), 1)
squaredpulse_partial = self.magnitude * squarepulse(self.freqs * time_partial)

loc = np.random.choice(range(length))
loc = self.R.choice(range(length))
signal = paste(signal, squaredpulse_partial, (loc,))

return signal
Expand Down
6 changes: 3 additions & 3 deletions monai/transforms/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ def generate_pos_neg_label_crop_centers(

"""
if rand_state is None:
rand_state = np.random.random.__self__ # type: ignore
rand_state = np.random.RandomState()

centers = []
fg_indices = np.asarray(fg_indices) if isinstance(fg_indices, Sequence) else fg_indices
Expand Down Expand Up @@ -721,7 +721,7 @@ def generate_label_classes_crop_centers(

"""
if rand_state is None:
rand_state = np.random.random.__self__ # type: ignore
rand_state = np.random.RandomState()

if num_samples < 1:
raise ValueError(f"num_samples must be an int number and greater than 0, got {num_samples}.")
Expand Down Expand Up @@ -1585,7 +1585,7 @@ def get_extreme_points(
"""
check_non_lazy_pending_ops(img, name="get_extreme_points")
if rand_state is None:
rand_state = np.random.random.__self__ # type: ignore
rand_state = np.random.RandomState()
indices = where(img != background)
if np.size(indices[0]) == 0:
raise ValueError("get_extreme_points: no foreground object in mask!")
Expand Down
2 changes: 1 addition & 1 deletion monai/utils/ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,6 @@ def random_idx(rows: int, cols: int, depths: int | None = None) -> np.ndarray:
idx.append((r, c))

idx_np = np.array(idx)
np.random.shuffle(idx_np)
np.random.RandomState().shuffle(idx_np)

return idx_np
Loading