Skip to content

Commit

Permalink
copy=False in astype-s
Browse files Browse the repository at this point in the history
  • Loading branch information
vovaf709 committed Jul 26, 2023
1 parent 600646d commit cad739b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions imops/interp1d.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def __call__(self, x_new: np.ndarray) -> np.ndarray:
# TODO: Figure out how to properly handle multiple type signatures in Cython and remove `.astype`-s
out = self.src_interp1d(
self.y,
self.x.astype(np.float64),
x_new.astype(np.float64),
self.x.astype(np.float64, copy=False),
x_new.astype(np.float64, copy=False),
self.bounds_error,
0.0 if extrapolate else self.fill_value,
extrapolate,
Expand All @@ -177,7 +177,7 @@ def __call__(self, x_new: np.ndarray) -> np.ndarray:
if self.backend.name == 'Numba':
set_num_threads(old_num_threads)

out = out.astype(max(self.y.dtype, self.x.dtype, x_new.dtype, key=lambda x: x.type(0).itemsize))
out = out.astype(max(self.y.dtype, self.x.dtype, x_new.dtype, key=lambda x: x.type(0).itemsize), copy=False)

if self.n_dummy:
out = out[(0,) * self.n_dummy]
Expand Down
4 changes: 2 additions & 2 deletions imops/measure.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def label(
label_image, background=background, return_num=True, connectivity=connectivity
)
if dtype is not None:
labeled_image = labeled_image.astype(dtype)
labeled_image = labeled_image.astype(dtype, copy=False)
else:
if ndim == 1:
label_image = label_image[None]
Expand Down Expand Up @@ -198,7 +198,7 @@ def center_of_mass(
if labels.dtype != index.dtype:
raise ValueError(f'`labels` and `index` must have same dtype, got {labels.dtype} and {index.dtype}.')

if len(index) != len(unique(index.astype(int))):
if len(index) != len(unique(index.astype(int, copy=False))):
raise ValueError('`index` should consist of unique values.')

if num_threads > 1:
Expand Down
2 changes: 1 addition & 1 deletion imops/morphology.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def wrapped(
image = image[(None,) * n_dummy]
footprint = footprint[(None,) * n_dummy]

out = src_op(image.astype(bool), footprint.astype(bool), num_threads)
out = src_op(image.astype(bool, copy=False), footprint.astype(bool, copy=False), num_threads)

if n_dummy:
out = out[(0,) * n_dummy]
Expand Down
4 changes: 2 additions & 2 deletions imops/radon.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ def inverse_radon(
inside_circle = (squared[:, None] + squared[None, :]) <= radius**2

dtype = sinogram.dtype
filtered_sinogram = filtered_sinogram.astype(dtype)
theta, xs = np.deg2rad(theta, dtype=dtype), xs.astype(dtype)
filtered_sinogram = filtered_sinogram.astype(dtype, copy=False)
theta, xs = np.deg2rad(theta, dtype=dtype), xs.astype(dtype, copy=False)

num_threads = normalize_num_threads(num_threads, backend)

Expand Down

0 comments on commit cad739b

Please sign in to comment.