Skip to content

Commit

Permalink
fix: import same fix for other files
Browse files Browse the repository at this point in the history
  • Loading branch information
mrava87 committed Sep 13, 2024
1 parent ae354ee commit e9353ea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 31 deletions.
17 changes: 7 additions & 10 deletions pylops/basicoperators/firstderivative.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
13 changes: 2 additions & 11 deletions pylops/basicoperators/laplacian.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
17 changes: 7 additions & 10 deletions pylops/basicoperators/restriction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit e9353ea

Please sign in to comment.