Skip to content

Commit

Permalink
fix: improve typing, remove wrong optional
Browse files Browse the repository at this point in the history
  • Loading branch information
cako committed Oct 3, 2024
1 parent df7d002 commit f93dfe1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 33 deletions.
28 changes: 12 additions & 16 deletions pylops/signalprocessing/fourierradon2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
jit_message = deps.numba_import("the radon2d module")

if jit_message is None:

from ._fourierradon2d_cuda import _aradon_inner_2d_cuda, _radon_inner_2d_cuda
from ._fourierradon2d_numba import _aradon_inner_2d, _radon_inner_2d

Expand Down Expand Up @@ -44,16 +43,16 @@ class FourierRadon2D(LinearOperator):
Number of samples in Fourier transform
flims : :obj:`tuple`, optional
Indices of lower and upper limits of Fourier axis to be used in
the application of the Radon matrix (if ``None``, use entire axis)
kind : :obj:`str`, optional
the application of the Radon matrix (when ``None``, use entire axis)
kind : :obj:`str`
Curve to be used for stacking/spreading (``linear``, ``parabolic``)
engine : :obj:`str`, optional
engine : :obj:`str`
Engine used for computation (``numpy`` or ``numba`` or ``cuda``)
num_threads_per_blocks : :obj:`tuple`, optional
num_threads_per_blocks : :obj:`tuple`
Number of threads in each block (only when ``engine=cuda``)
dtype : :obj:`str`, optional
dtype : :obj:`str`
Type of elements in input array.
name : :obj:`str`, optional
name : :obj:`str`
Name of operator (to be used by :func:`pylops.utils.describe.describe`)
Attributes
Expand Down Expand Up @@ -115,11 +114,11 @@ def __init__(
pxaxis: NDArray,
nfft: int,
flims: Optional[Tuple[int, int]] = None,
kind: Optional[str] = "linear",
engine: Optional[str] = "numpy",
kind: str = "linear",
engine: str = "numpy",
num_threads_per_blocks: Tuple[int, int] = (32, 32),
dtype: Optional[DTypeLike] = "float64",
name: Optional[str] = "C",
dtype: DTypeLike = "float64",
name: str = "R",
) -> None:
# engine
if engine not in ["numpy", "numba", "cuda"]:
Expand All @@ -140,12 +139,9 @@ def __init__(
self.dt = taxis[1] - taxis[0]
self.dh = haxis[1] - haxis[0]
self.f = np.fft.rfftfreq(self.nfft, d=self.dt)
self.nfft2 = self.f.size
self.nfft2 = len(self.f)
self.cdtype = get_complex_dtype(dtype)

self.flims = flims
if flims is None:
self.flims = (0, self.nfft2)
self.flims = (0, self.nfft2) if flims is None else flims

if kind == "parabolic":
self.haxis = self.haxis**2
Expand Down
30 changes: 13 additions & 17 deletions pylops/signalprocessing/fourierradon3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
jit_message = deps.numba_import("the radon2d module")

if jit_message is None:

from ._fourierradon3d_cuda import _aradon_inner_3d_cuda, _radon_inner_3d_cuda
from ._fourierradon3d_numba import _aradon_inner_3d, _radon_inner_3d

Expand Down Expand Up @@ -48,18 +47,18 @@ class FourierRadon3D(LinearOperator):
Number of samples in Fourier transform
flims : :obj:`tuple`, optional
Indices of lower and upper limits of Fourier axis to be used in
the application of the Radon matrix (if ``None``, use entire axis)
kind : :obj:`tuple`, optional
the application of the Radon matrix (when ``None``, use entire axis)
kind : :obj:`tuple`
Curves to be used for stacking/spreading along the y- and x- axes
(``("linear", "linear")``, ``("linear", "parabolic")``,
``("parabolic", "linear")``, or ``("parabolic", "parabolic")``)
engine : :obj:`str`, optional
engine : :obj:`str`
Engine used for computation (``numpy`` or ``numba`` or ``cuda``)
num_threads_per_blocks : :obj:`tuple`, optional
num_threads_per_blocks : :obj:`tuple`
Number of threads in each block (only when ``engine=cuda``)
dtype : :obj:`str`, optional
dtype : :obj:`str`
Type of elements in input array.
name : :obj:`str`, optional
name : :obj:`str`
Name of operator (to be used by :func:`pylops.utils.describe.describe`)
Attributes
Expand Down Expand Up @@ -125,11 +124,11 @@ def __init__(
pxaxis: NDArray,
nfft: int,
flims: Optional[Tuple[int, int]] = None,
kind: Optional[tuple] = ("linear", "linear"),
engine: Optional[str] = "numpy",
kind: Tuple[str, str] = ("linear", "linear"),
engine: str = "numpy",
num_threads_per_blocks: Tuple[int, int] = (32, 32),
dtype: Optional[DTypeLike] = "float64",
name: Optional[str] = "C",
dtype: DTypeLike = "float64",
name: str = "R",
) -> None:
# engine
if engine not in ["numpy", "numba", "cuda"]:
Expand All @@ -138,7 +137,7 @@ def __init__(
engine = "numpy"

# kind
if not isinstance(kind, (tuple, list)) and len(kind) != 2:
if len(kind) != 2:
raise ValueError("kind must be a tuple of two elements")

# dimensions and super
Expand All @@ -155,12 +154,9 @@ def __init__(
self.dhy = hyaxis[1] - hyaxis[0]
self.dhx = hxaxis[1] - hxaxis[0]
self.f = np.fft.rfftfreq(self.nfft, d=self.dt)
self.nfft2 = self.f.size
self.nfft2 = len(self.f)
self.cdtype = get_complex_dtype(dtype)

self.flims = flims
if flims is None:
self.flims = (0, self.nfft2)
self.flims = (0, self.nfft2) if flims is None else flims

if kind[0] == "parabolic":
self.hyaxis = self.hyaxis**2
Expand Down

0 comments on commit f93dfe1

Please sign in to comment.