Skip to content

Commit 1fe6b34

Browse files
committed
Update index url and check for macos
Add check to skip mkl_fft on darwin Minor update
1 parent 129f485 commit 1fe6b34

6 files changed

Lines changed: 40 additions & 86 deletions

File tree

pylops/signalprocessing/fft.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import pyfftw
2323

2424
if mkl_fft_message is None:
25-
import mkl_fft.interfaces.scipy_fft as mkl_backend
25+
import mkl_fft.interfaces.numpy_fft as mkl_backend
2626

2727
logger = logging.getLogger(__name__)
2828

@@ -414,21 +414,6 @@ def __init__(
414414
dtype: DTypeLike = "complex128",
415415
**kwargs_fft,
416416
) -> None:
417-
if np.dtype(dtype) == np.float16:
418-
warnings.warn(
419-
"mkl_fft backend is unavailable with float16 dtype. Will use float32."
420-
)
421-
dtype = np.float32
422-
elif np.dtype(dtype) == np.complex256:
423-
warnings.warn(
424-
"mkl_fft backend is unavailable with complex256 dtype. Will use complex128."
425-
)
426-
dtype = np.complex128
427-
elif np.dtype(dtype) == np.float128:
428-
warnings.warn(
429-
"mkl_fft backend is unavailable with float128 dtype. Will use float64."
430-
)
431-
dtype = np.float64
432417
super().__init__(
433418
dims=dims,
434419
axis=axis,
@@ -452,12 +437,6 @@ def __init__(
452437

453438
@reshaped
454439
def _matvec(self, x: NDArray) -> NDArray:
455-
if x.dtype == np.float16:
456-
x = x.astype(np.float32)
457-
elif x.dtype == np.float128:
458-
x = x.astype(np.float64)
459-
elif x.dtype == np.complex256:
460-
x = x.astype(np.complex128)
461440
if self.ifftshift_before:
462441
x = mkl_backend.ifftshift(x, axes=self.axis)
463442
if not self.clinear:
@@ -477,12 +456,6 @@ def _matvec(self, x: NDArray) -> NDArray:
477456

478457
@reshaped
479458
def _rmatvec(self, x: NDArray) -> NDArray:
480-
if x.dtype == np.float16:
481-
x = x.astype(np.float32)
482-
elif x.dtype == np.float128:
483-
x = x.astype(np.float64)
484-
elif x.dtype == np.complex256:
485-
x = x.astype(np.complex128)
486459
if self.fftshift_after:
487460
x = mkl_backend.ifftshift(x, axes=self.axis)
488461
if self.real:

pylops/signalprocessing/fft2d.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
mkl_fft_message = deps.mkl_fft_import("the mkl fft module")
1717

1818
if mkl_fft_message is None:
19-
import mkl_fft.interfaces.scipy_fft as mkl_backend
19+
import mkl_fft.interfaces.numpy_fft as mkl_backend
2020

2121

2222
class _FFT2D_numpy(_BaseFFTND):
@@ -257,21 +257,6 @@ def __init__(
257257
dtype: DTypeLike = "complex128",
258258
**kwargs_fft,
259259
) -> None:
260-
if np.dtype(dtype) == np.float16:
261-
warnings.warn(
262-
"mkl_fft backend is unavailable with float16 dtype. Will use float32."
263-
)
264-
dtype = np.float32
265-
elif np.dtype(dtype) == np.complex256:
266-
warnings.warn(
267-
"mkl_fft backend is unavailable with complex256 dtype. Will use complex128."
268-
)
269-
dtype = np.complex128
270-
elif np.dtype(dtype) == np.float128:
271-
warnings.warn(
272-
"mkl_fft backend is unavailable with float128 dtype. Will use float64."
273-
)
274-
dtype = np.float64
275260
super().__init__(
276261
dims=dims,
277262
axes=axes,
@@ -305,12 +290,6 @@ def __init__(
305290

306291
@reshaped
307292
def _matvec(self, x):
308-
if x.dtype == np.float16:
309-
x = x.astype(np.float32)
310-
elif x.dtype == np.float128:
311-
x = x.astype(np.float64)
312-
elif x.dtype == np.complex256:
313-
x = x.astype(np.complex128)
314293
if self.ifftshift_before.any():
315294
x = mkl_backend.ifftshift(x, axes=self.axes[self.ifftshift_before])
316295
if not self.clinear:
@@ -335,12 +314,6 @@ def _matvec(self, x):
335314

336315
@reshaped
337316
def _rmatvec(self, x):
338-
if x.dtype == np.float16:
339-
x = x.astype(np.float32)
340-
elif x.dtype == np.float128:
341-
x = x.astype(np.float64)
342-
elif x.dtype == np.complex256:
343-
x = x.astype(np.complex128)
344317
if self.fftshift_after.any():
345318
x = mkl_backend.ifftshift(x, axes=self.axes[self.fftshift_after])
346319
if self.real:

pylops/signalprocessing/fftnd.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
mkl_fft_message = deps.mkl_fft_import("the mkl fft module")
1717

1818
if mkl_fft_message is None:
19-
import mkl_fft.interfaces.scipy_fft as mkl_backend
19+
import mkl_fft.interfaces.numpy_fft as mkl_backend
2020

2121

2222
class _FFTND_numpy(_BaseFFTND):
@@ -238,21 +238,6 @@ def __init__(
238238
dtype: DTypeLike = "complex128",
239239
**kwargs_fft,
240240
) -> None:
241-
if np.dtype(dtype) == np.float16:
242-
warnings.warn(
243-
"mkl_fft backend is unavailable with float16 dtype. Will use float32."
244-
)
245-
dtype = np.float32
246-
elif np.dtype(dtype) == np.complex256:
247-
warnings.warn(
248-
"mkl_fft backend is unavailable with complex256 dtype. Will use complex128."
249-
)
250-
dtype = np.complex128
251-
elif np.dtype(dtype) == np.float128:
252-
warnings.warn(
253-
"mkl_fft backend is unavailable with float128 dtype. Will use float64."
254-
)
255-
dtype = np.float64
256241
super().__init__(
257242
dims=dims,
258243
axes=axes,
@@ -275,12 +260,6 @@ def __init__(
275260

276261
@reshaped
277262
def _matvec(self, x: NDArray) -> NDArray:
278-
if x.dtype == np.float16:
279-
x = x.astype(np.float32)
280-
elif x.dtype == np.float128:
281-
x = x.astype(np.float64)
282-
elif x.dtype == np.complex256:
283-
x = x.astype(np.complex128)
284263
if self.ifftshift_before.any():
285264
x = mkl_backend.ifftshift(x, axes=self.axes[self.ifftshift_before])
286265
if not self.clinear:
@@ -305,12 +284,6 @@ def _matvec(self, x: NDArray) -> NDArray:
305284

306285
@reshaped
307286
def _rmatvec(self, x: NDArray) -> NDArray:
308-
if x.dtype == np.float16:
309-
x = x.astype(np.float32)
310-
elif x.dtype == np.float128:
311-
x = x.astype(np.float64)
312-
elif x.dtype == np.complex256:
313-
x = x.astype(np.complex128)
314287
if self.fftshift_after.any():
315288
x = mkl_backend.ifftshift(x, axes=self.axes[self.fftshift_after])
316289
if self.real:

pytests/test_ffts.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import itertools
22
import os
3+
import sys
34

45
if int(os.environ.get("TEST_CUPY_PYLOPS", 0)):
56
import cupy as np
@@ -322,6 +323,8 @@ def test_unknown_engine(par):
322323

323324
@pytest.mark.parametrize("par", pars_fft_small_real)
324325
def test_FFT_small_real(par):
326+
if par["engine"] == "mkl_fft" and sys.platform == "darwin":
327+
pytest.skip("mkl_fft not supported on macOS")
325328
np.random.seed(5)
326329

327330
if backend == "numpy" or (backend == "cupy" and par["engine"] == "numpy"):
@@ -399,6 +402,8 @@ def test_FFT_small_real(par):
399402
)
400403
@pytest.mark.parametrize("par", pars_fft_random_real)
401404
def test_FFT_random_real(par):
405+
if par["engine"] == "mkl_fft" and sys.platform == "darwin":
406+
pytest.skip("mkl_fft not supported on macOS")
402407
np.random.seed(5)
403408

404409
shape = par["shape"]
@@ -455,6 +460,8 @@ def test_FFT_random_real(par):
455460

456461
@pytest.mark.parametrize("par", pars_fft_small_cpx)
457462
def test_FFT_small_complex(par):
463+
if par["engine"] == "mkl_fft" and sys.platform == "darwin":
464+
pytest.skip("mkl_fft not supported on macOS")
458465
np.random.seed(5)
459466
dtype, decimal = par["dtype_precision"]
460467
norm = par["norm"]
@@ -527,6 +534,8 @@ def test_FFT_small_complex(par):
527534

528535
@pytest.mark.parametrize("par", pars_fft_random_cpx)
529536
def test_FFT_random_complex(par):
537+
if par["engine"] == "mkl_fft" and sys.platform == "darwin":
538+
pytest.skip("mkl_fft not supported on macOS")
530539
np.random.seed(5)
531540
if backend == "numpy" or (backend == "cupy" and par["engine"] == "numpy"):
532541
shape = par["shape"]
@@ -614,6 +623,8 @@ def test_FFT_random_complex(par):
614623
)
615624
@pytest.mark.parametrize("par", pars_fft2d_random_real)
616625
def test_FFT2D_random_real(par):
626+
if par["engine"] == "mkl_fft" and sys.platform == "darwin":
627+
pytest.skip("mkl_fft not supported on macOS")
617628
np.random.seed(5)
618629
if backend == "numpy" or (backend == "cupy" and par["engine"] == "numpy"):
619630
shape = par["shape"]
@@ -675,6 +686,8 @@ def test_FFT2D_random_real(par):
675686

676687
@pytest.mark.parametrize("par", pars_fft2d_random_cpx)
677688
def test_FFT2D_random_complex(par):
689+
if par["engine"] == "mkl_fft" and sys.platform == "darwin":
690+
pytest.skip("mkl_fft not supported on macOS")
678691
np.random.seed(5)
679692
if backend == "numpy" or (backend == "cupy" and par["engine"] == "numpy"):
680693
shape = par["shape"]
@@ -756,6 +769,8 @@ def test_FFT2D_random_complex(par):
756769

757770
@pytest.mark.parametrize("par", pars_fftnd_random_real)
758771
def test_FFTND_random_real(par):
772+
if par["engine"] == "mkl_fft" and sys.platform == "darwin":
773+
pytest.skip("mkl_fft not supported on macOS")
759774
np.random.seed(5)
760775
if backend == "numpy" or (backend == "cupy" and par["engine"] == "numpy"):
761776
shape = par["shape"]
@@ -817,6 +832,8 @@ def test_FFTND_random_real(par):
817832

818833
@pytest.mark.parametrize("par", pars_fftnd_random_cpx)
819834
def test_FFTND_random_complex(par):
835+
if par["engine"] == "mkl_fft" and sys.platform == "darwin":
836+
pytest.skip("mkl_fft not supported on macOS")
820837
np.random.seed(5)
821838
shape = par["shape"]
822839
dtype, decimal = par["dtype_precision"]
@@ -893,6 +910,8 @@ def test_FFTND_random_complex(par):
893910

894911
@pytest.mark.parametrize("par", pars_fft2dnd_small_cpx)
895912
def test_FFT2D_small_complex(par):
913+
if par["engine"] == "mkl_fft" and sys.platform == "darwin":
914+
pytest.skip("mkl_fft not supported on macOS")
896915
np.random.seed(5)
897916
dtype, decimal = par["dtype_precision"]
898917
norm = par["norm"]
@@ -943,6 +962,8 @@ def test_FFT2D_small_complex(par):
943962

944963
@pytest.mark.parametrize("par", pars_fft2dnd_small_cpx)
945964
def test_FFTND_small_complex(par):
965+
if par["engine"] == "mkl_fft" and sys.platform == "darwin":
966+
pytest.skip("mkl_fft not supported on macOS")
946967
np.random.seed(5)
947968
dtype, decimal = par["dtype_precision"]
948969
norm = par["norm"]
@@ -1018,6 +1039,8 @@ def test_FFTND_small_complex(par):
10181039
],
10191040
)
10201041
def test_FFT_1dsignal(par):
1042+
if par["engine"] == "mkl_fft" and sys.platform == "darwin":
1043+
pytest.skip("mkl_fft not supported on macOS")
10211044
np.random.seed(5)
10221045
"""Dot-test and inversion for FFT operator for 1d signal"""
10231046
decimal = 3 if np.real(np.ones(1, par["dtype"])).dtype == np.float32 else 8
@@ -1135,6 +1158,8 @@ def test_FFT_2dsignal(par):
11351158
"""Dot-test and inversion for fft operator for 2d signal
11361159
(fft on single dimension)
11371160
"""
1161+
if par["engine"] == "mkl_fft" and sys.platform == "darwin":
1162+
pytest.skip("mkl_fft not supported on macOS")
11381163
np.random.seed(5)
11391164
decimal = 3 if np.real(np.ones(1, par["dtype"])).dtype == np.float32 else 8
11401165

@@ -1350,6 +1375,8 @@ def test_FFT_3dsignal(par):
13501375
"""Dot-test and inversion for fft operator for 3d signal
13511376
(fft on single dimension)
13521377
"""
1378+
if par["engine"] == "mkl_fft" and sys.platform == "darwin":
1379+
pytest.skip("mkl_fft not supported on macOS")
13531380
np.random.seed(5)
13541381
decimal = 3 if np.real(np.ones(1, par["dtype"])).dtype == np.float32 else 8
13551382

@@ -1576,6 +1603,8 @@ def test_FFT_3dsignal(par):
15761603
)
15771604
def test_FFT2D(par):
15781605
"""Dot-test and inversion for FFT2D operator for 2d signal"""
1606+
if par["engine"] == "mkl_fft" and sys.platform == "darwin":
1607+
pytest.skip("mkl_fft not supported on macOS")
15791608
np.random.seed(5)
15801609
decimal = 3 if np.real(np.ones(1, par["dtype"])).dtype == np.float32 else 8
15811610

@@ -1711,6 +1740,8 @@ def test_FFT2D(par):
17111740
)
17121741
def test_FFT3D(par):
17131742
"""Dot-test and inversion for FFTND operator for 3d signal"""
1743+
if par["engine"] == "mkl_fft" and sys.platform == "darwin":
1744+
pytest.skip("mkl_fft not supported on macOS")
17141745
np.random.seed(5)
17151746
decimal = 3 if np.real(np.ones(1, par["dtype"])).dtype == np.float32 else 8
17161747

requirements-dev.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
--index-url https://software.repos.intel.com/python/pypi
2+
--extra-index-url https://pypi.org/simple
3+
mkl_fft; sys_platform != "darwin"
14
numpy>=2.0.0
25
scipy>=1.13.0
36
jax
@@ -30,4 +33,3 @@ black
3033
flake8
3134
mypy
3235
pytensor>=2.28.0
33-
mkl-fft; sys_platform != "darwin"

requirements-doc.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
--index-url https://software.repos.intel.com/python/pypi
2+
--extra-index-url https://pypi.org/simple
3+
mkl_fft; sys_platform != "darwin"
14
numpy>=2.0.0
25
scipy>=1.13.0
36
jax
@@ -31,4 +34,3 @@ flake8
3134
mypy
3235
pytensor>=2.28.0
3336
pymc>=5.21.0
34-
mkl-fft; sys_platform != "darwin"

0 commit comments

Comments
 (0)