From e9353eadc20b23fc308db69d2d11c078c36cb515 Mon Sep 17 00:00:00 2001 From: mrava87 Date: Fri, 13 Sep 2024 15:30:41 +0300 Subject: [PATCH] fix: import same fix for other files --- pylops/basicoperators/firstderivative.py | 17 +++++++---------- pylops/basicoperators/laplacian.py | 13 ++----------- pylops/basicoperators/restriction.py | 17 +++++++---------- 3 files changed, 16 insertions(+), 31 deletions(-) diff --git a/pylops/basicoperators/firstderivative.py b/pylops/basicoperators/firstderivative.py index 9117eeff..c19a2650 100644 --- a/pylops/basicoperators/firstderivative.py +++ b/pylops/basicoperators/firstderivative.py @@ -6,18 +6,15 @@ from pylops import LinearOperator from pylops.utils._internal import _value_or_sized_to_tuple -from pylops.utils.backend import get_array_module, inplace_add, inplace_set +from pylops.utils.backend import ( + get_array_module, + get_normalize_axis_index, + inplace_add, + inplace_set, +) from pylops.utils.decorators import reshaped from pylops.utils.typing import DTypeLike, InputDimsLike, NDArray -# need to check numpy version since the namespace of normalize_axis_index -# changed from numpy>=2.0.0 -np_version = np.__version__.split(".") -if int(np_version[0]) > 1: - from numpy.lib.array_utils import normalize_axis_index -else: - from numpy.core.multiarray import normalize_axis_index - class FirstDerivative(LinearOperator): r"""First derivative. @@ -102,7 +99,7 @@ def __init__( dims = _value_or_sized_to_tuple(dims) super().__init__(dtype=np.dtype(dtype), dims=dims, dimsd=dims, name=name) - self.axis = normalize_axis_index(axis, len(self.dims)) + self.axis = get_normalize_axis_index()(axis, len(self.dims)) self.sampling = sampling self.kind = kind self.edge = edge diff --git a/pylops/basicoperators/laplacian.py b/pylops/basicoperators/laplacian.py index 99afd457..f8f836a5 100644 --- a/pylops/basicoperators/laplacian.py +++ b/pylops/basicoperators/laplacian.py @@ -3,20 +3,11 @@ from typing import Tuple -import numpy as np - from pylops import LinearOperator from pylops.basicoperators import SecondDerivative +from pylops.utils.backend import get_normalize_axis_index from pylops.utils.typing import DTypeLike, InputDimsLike, NDArray -# need to check numpy version since the namespace of normalize_axis_index -# changed from numpy>=2.0.0 -np_version = np.__version__.split(".") -if int(np_version[0]) > 1: - from numpy.lib.array_utils import normalize_axis_index -else: - from numpy.core.multiarray import normalize_axis_index - class Laplacian(LinearOperator): r"""Laplacian. @@ -76,7 +67,7 @@ def __init__( dtype: DTypeLike = "float64", name: str = "L", ): - axes = tuple(normalize_axis_index(ax, len(dims)) for ax in axes) + axes = tuple(get_normalize_axis_index()(ax, len(dims)) for ax in axes) if not (len(axes) == len(weights) == len(sampling)): raise ValueError("axes, weights, and sampling have different size") self.axes = axes diff --git a/pylops/basicoperators/restriction.py b/pylops/basicoperators/restriction.py index 1a745b30..2595c971 100644 --- a/pylops/basicoperators/restriction.py +++ b/pylops/basicoperators/restriction.py @@ -6,17 +6,14 @@ import numpy as np import numpy.ma as np_ma -# need to check numpy version since normalize_axis_index will be -# soon moved from numpy.core.multiarray to from numpy.lib.array_utils -np_version = np.__version__.split(".") -if int(np_version[0]) < 2: - from numpy.core.multiarray import normalize_axis_index -else: - from numpy.lib.array_utils import normalize_axis_index - from pylops import LinearOperator from pylops.utils._internal import _value_or_sized_to_tuple -from pylops.utils.backend import get_array_module, inplace_set, to_cupy_conditional +from pylops.utils.backend import ( + get_array_module, + get_normalize_axis_index, + inplace_set, + to_cupy_conditional, +) from pylops.utils.typing import DTypeLike, InputDimsLike, IntNDArray, NDArray logging.basicConfig(format="%(levelname)s: %(message)s", level=logging.WARNING) @@ -119,7 +116,7 @@ def __init__( ) -> None: ncp = get_array_module(iava) dims = _value_or_sized_to_tuple(dims) - axis = normalize_axis_index(axis, len(dims)) + axis = get_normalize_axis_index()(axis, len(dims)) dimsd = list(dims) # data dimensions dimsd[axis] = len(iava)