Skip to content

Commit ea16c74

Browse files
committed
Modify factory.py for possibly not all precisions
1 parent 597ebe7 commit ea16c74

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

mpi4py_fft/fftw/factory.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
import six
22
import numpy as np
3-
from . import fftwf_xfftn, fftw_xfftn, fftwl_xfftn
3+
from . import fftw_xfftn
4+
try:
5+
from . import fftwf_xfftn
6+
except ImportError:
7+
fftwf_xfftn = None
8+
try:
9+
from . import fftwl_xfftn
10+
except ImportError:
11+
fftwl_xfftn = None
412
from .utilities import FFTW_FORWARD, FFTW_MEASURE
513

6-
fftlib = {
7-
'F': fftwf_xfftn,
8-
'D': fftw_xfftn,
9-
'G': fftwl_xfftn}
14+
fftlib = {}
15+
for k, v in zip(('F', 'D', 'G'), (fftwf_xfftn, fftw_xfftn, fftwl_xfftn))
16+
if v is not None:
17+
fftlib[k] = v
1018

1119
def get_planned_FFT(input_array, output_array, axes=(-1,), kind=FFTW_FORWARD,
1220
threads=1, flags=(FFTW_MEASURE,), normalize=1):
@@ -60,6 +68,7 @@ def get_planned_FFT(input_array, output_array, axes=(-1,), kind=FFTW_FORWARD,
6068
6169
"""
6270
dtype = input_array.dtype.char
71+
assert dtype.upper() in fftlib
6372
_fft = fftlib[dtype.upper()]
6473
return _fft.FFT(input_array, output_array, axes, kind, threads, flags,
6574
normalize)
@@ -74,8 +83,8 @@ def export_wisdom(filename):
7483
7584
Note
7685
----
77-
Wisdom is stored for all three precisions, float, double and long double,
78-
using, respectively, prefix ``F_``, ``D_`` and ``G_``. Wisdom is
86+
Wisdom is stored for all precisions available: float, double and long
87+
double, using, respectively, prefix ``F_``, ``D_`` and ``G_``. Wisdom is
7988
imported using :func:`.import_wisdom`.
8089
8190
See also
@@ -98,8 +107,8 @@ def import_wisdom(filename):
98107
99108
Note
100109
----
101-
Wisdom is imported for all three precisions, float, double and long double,
102-
using, respectively, prefix ``F_``, ``D_`` and ``G_``. Wisdom is
110+
Wisdom is imported for all available precisions: float, double and long
111+
double, using, respectively, prefix ``F_``, ``D_`` and ``G_``. Wisdom is
103112
exported using :func:`.export_wisdom`.
104113
105114
See also
@@ -130,4 +139,3 @@ def set_timelimit(limit):
130139
def cleanup():
131140
for lib in fftlib.values():
132141
lib.cleanup()
133-

0 commit comments

Comments
 (0)