From b9f8ddb3b28947e65be62c542f6e57e2d36fb210 Mon Sep 17 00:00:00 2001 From: Paul McCarthy <pauldmccarthy@gmail.com> Date: Tue, 25 Jun 2024 21:07:38 +0100 Subject: [PATCH] MNT: np.array(a, copy=False) raises an error in numpy 2 if the array cannot be copied --- fsl/data/bitmap.py | 2 +- fsl/transform/affine.py | 4 ++-- fsl/utils/image/resample.py | 2 +- fsl/utils/memoize.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fsl/data/bitmap.py b/fsl/data/bitmap.py index f101a0dda..dd4d42a76 100644 --- a/fsl/data/bitmap.py +++ b/fsl/data/bitmap.py @@ -179,7 +179,7 @@ class Bitmap(object): for ci, ch in enumerate(dtype.names): data[ch] = self.data[..., ci] - data = np.array(data, order='F', copy=False) + data = np.asarray(data, order='F') return fslimage.Image(data, name=self.name, diff --git a/fsl/transform/affine.py b/fsl/transform/affine.py index fe8efd35e..0ffcad174 100644 --- a/fsl/transform/affine.py +++ b/fsl/transform/affine.py @@ -62,7 +62,7 @@ def veclength(vec): Multiple vectors may be passed in, with a shape of ``(n, 3)``. """ - vec = np.array(vec, copy=False).reshape(-1, 3) + vec = np.asarray(vec).reshape(-1, 3) return np.sqrt(np.einsum('ij,ij->i', vec, vec)) @@ -71,7 +71,7 @@ def normalise(vec): Multiple vectors may be passed in, with a shape of ``(n, 3)``. """ - vec = np.array(vec, copy=False).reshape(-1, 3) + vec = np.asarray(vec).reshape(-1, 3) n = (vec.T / veclength(vec)).T if n.size == 3: diff --git a/fsl/utils/image/resample.py b/fsl/utils/image/resample.py index 9f82be659..414043c1c 100644 --- a/fsl/utils/image/resample.py +++ b/fsl/utils/image/resample.py @@ -190,7 +190,7 @@ def resample(image, if origin not in ('centre', 'corner'): raise ValueError('Invalid value for origin: {}'.format(origin)) - data = np.array(image[sliceobj], dtype=dtype, copy=False) + data = np.asarray(image[sliceobj], dtype=dtype) if len(data.shape) != len(newShape): raise ValueError('Data dimensions do not match new shape: ' diff --git a/fsl/utils/memoize.py b/fsl/utils/memoize.py index b7ee159c2..151b1a8d3 100644 --- a/fsl/utils/memoize.py +++ b/fsl/utils/memoize.py @@ -242,8 +242,8 @@ def skipUnchanged(func): isarray = oldIsArray or newIsArray if isarray: - a = np.array(oldVal, copy=False) - b = np.array(value, copy=False) + a = np.asarray(oldVal) + b = np.asarray(value) nochange = (a.shape == b.shape) and np.allclose(a, b) else: -- GitLab