Skip to content

Commit a5a053f

Browse files
committed
Getting rid of six and modifying setup
1 parent 4d96578 commit a5a053f

File tree

11 files changed

+103
-73
lines changed

11 files changed

+103
-73
lines changed

conf/meta.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
{% set data = load_setup_py_data() %}
2+
13
package:
24
name: mpi4py_fft
3-
version: "1.0.1"
5+
version: {{ data.get('version') }}
46

57
source:
68
git_url: ../
@@ -17,7 +19,6 @@ requirements:
1719
- mpi4py
1820
- numpy
1921
- nomkl
20-
- six
2122
- pip
2223
- fftw
2324
- setuptools
@@ -28,7 +29,6 @@ requirements:
2829
- numpy
2930
- fftw
3031
- pyfftw
31-
- six
3232
- nomkl
3333
- scipy >=1.0.0
3434
- h5py-parallel

docs/source/introduction.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Introduction
44
The Python package mpi4py-fft is a tool primarily for working with Fast
55
Fourier Transforms (FFTs) of (large) multidimensional arrays. There is really
66
no limit as to how large the arrays can be, just as long as there is sufficient
7-
computing powers available. Also, there are no limits as to how transforms can be
8-
configured. Just about any combination of transforms from the FFTW library is
9-
supported. Furthermore, mpi4py-fft can also be used simply to perform global
7+
computing powers available. Also, there are no limits as to how transforms can
8+
be configured. Just about any combination of transforms from the FFTW library
9+
is supported. Furthermore, mpi4py-fft can also be used simply to perform global
1010
redistributions (distribute and communicate) of large arrays with MPI, without
1111
any transforms at all.
1212

mpi4py_fft/__init__.py

+21
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
"""
2+
This is the **mpi4py-fft** package
3+
4+
What is **mpi4py-fft**?
5+
=======================
6+
7+
The Python package **mpi4py-fft** is a tool primarily for working with Fast
8+
Fourier Transforms (FFTs) of (large) multidimensional arrays. There is really
9+
no limit as to how large the arrays can be, just as long as there is sufficient
10+
computing powers available. Also, there are no limits as to how transforms can
11+
be configured. Just about any combination of transforms from the FFTW library
12+
is supported. Furthermore, mpi4py-fft can also be used simply to perform global
13+
redistributions (distribute and communicate) of large arrays with MPI, without
14+
any transforms at all.
15+
16+
For more information, see `documentation <https://mpi4py-fft.readthedocs.io>`_.
17+
18+
"""
19+
__version__ = '1.0.1'
20+
__author__ = 'Lisandro Dalcin and Mikael Mortensen'
21+
122
from .mpifft import PFFT, Function
223
from . import fftw
324
from .utilities import HDF5File, NCFile, generate_xdmf

mpi4py_fft/fftw/factory.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import six
1+
#pylint: disable=no-name-in-module
2+
23
import numpy as np
34
from mpi4py import MPI
45
from .utilities import FFTW_FORWARD, FFTW_MEASURE
@@ -40,9 +41,9 @@ def get_fftw_lib(dtype):
4041

4142
fftlib = {}
4243
for t in 'fdg':
43-
lib = get_fftw_lib(t)
44-
if lib is not None:
45-
fftlib[t.upper()] = lib
44+
fftw_lib = get_fftw_lib(t)
45+
if fftw_lib is not None:
46+
fftlib[t.upper()] = fftw_lib
4647

4748
comm = MPI.COMM_WORLD
4849

@@ -126,7 +127,7 @@ def export_wisdom(filename):
126127
"""
127128
rank = str(comm.Get_rank())
128129
e = []
129-
for key, lib in six.iteritems(fftlib):
130+
for key, lib in fftlib.items():
130131
e.append(lib.export_wisdom(bytearray(key+rank+'_'+filename, 'utf-8')))
131132
assert np.all(np.array(e) == 1), "Not able to export wisdom {}".format(filename)
132133

@@ -155,7 +156,7 @@ def import_wisdom(filename):
155156
"""
156157
rank = str(comm.Get_rank())
157158
e = []
158-
for key, lib in six.iteritems(fftlib):
159+
for key, lib in fftlib.items():
159160
e.append(lib.import_wisdom(bytearray(key+rank+'_'+filename, 'utf-8')))
160161
assert np.all(np.array(e) == 1), "Not able to import wisdom {}".format(filename)
161162

mpi4py_fft/fftw/xfftn.py

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import six
1+
#pylint: disable=no-name-in-module,unused-import
22
import numpy as np
33
from .factory import get_planned_FFT
44
from .utilities import FFTW_FORWARD, FFTW_BACKWARD, FFTW_REDFT00, FFTW_REDFT01, \
@@ -8,7 +8,7 @@
88
FFTW_ESTIMATE, FFTW_WISDOM_ONLY, C2C_FORWARD, C2C_BACKWARD, R2C, C2R, \
99
FFTW_R2HC, FFTW_HC2R, FFTW_DHT, get_alignment, aligned, aligned_like
1010

11-
flag_dict = {key: val for key, val in six.iteritems(locals())
11+
flag_dict = {key: val for key, val in locals().items()
1212
if key.startswith('FFTW_')}
1313

1414
dct_type = {
@@ -835,4 +835,3 @@ def get_normalization(kind, shape, axes):
835835
hfftn: ihfftn,
836836
ihfftn: hfftn
837837
}
838-

mpi4py_fft/utilities/file_base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import six
21
import numpy as np
32

43
class FileBase(object):
@@ -34,7 +33,7 @@ def write(self, step, fields, **kw):
3433
arrays to be stored, whereas 2-tuples are arrays with associated
3534
*global* slices.
3635
"""
37-
for group, list_of_fields in six.iteritems(fields):
36+
for group, list_of_fields in fields.items():
3837
assert isinstance(list_of_fields, (tuple, list))
3938
assert isinstance(group, str)
4039

mpi4py_fft/utilities/generate_xdmf.py

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
11
# pylint: disable=line-too-long
22
import copy
33
import re
4-
import six
54
from numpy import dtype, array, invert, take
6-
try:
7-
import h5py
8-
except ImportError: #pragma: no cover
9-
import warnings
10-
warnings.warn('h5py not installed')
11-
125

136
__all__ = ('generate_xdmf',)
147

@@ -120,6 +113,7 @@ def generate_xdmf(h5filename, periodic=True, order='paraview'):
120113
opposite order in the XDMF-file for 2D slices. Make choice of
121114
order here.
122115
"""
116+
import h5py
123117
f = h5py.File(h5filename)
124118
keys = []
125119
f.visit(keys.append)
@@ -148,7 +142,7 @@ def generate_xdmf(h5filename, periodic=True, order='paraview'):
148142
periodic = list(array(invert(periodic), int))
149143

150144
coor = ['x0', 'x1', 'x2', 'x3', 'x4']
151-
for ndim, dsets in six.iteritems(datasets):
145+
for ndim, dsets in datasets.items():
152146
timesteps = list(dsets.keys())
153147
per = copy.copy(periodic)
154148
if not timesteps:
@@ -272,7 +266,7 @@ def generate_xdmf(h5filename, periodic=True, order='paraview'):
272266
grid[slices] += get_grid(geometry[slices], topology[slices],
273267
attrs[slices].rstrip())
274268
attrs[slices] = ''
275-
for slices, ff in six.iteritems(xff):
269+
for slices, ff in xff.items():
276270
if 'slice' in slices:
277271
fname = h5filename[:-3]+"_"+slices+".xdmf"
278272
else:

requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
numpy
22
cython
33
mpi4py
4-
six

setup.py

+57-39
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env python
22

3-
import os, sys
3+
import os
4+
import sys
5+
import re
46
import shutil
57
from distutils import ccompiler
6-
import six
78
from setuptools import setup
89
from setuptools.extension import Extension
910
from numpy import get_include
@@ -19,49 +20,66 @@
1920
include_dirs.append(os.path.join(os.environ[f], 'include'))
2021

2122
prec_map = {'float': 'f', 'double': '', 'long double': 'l'}
22-
compiler = ccompiler.new_compiler()
2323

24-
libs = {}
25-
for d in ('float', 'double', 'long double'):
26-
lib = 'fftw3'+prec_map[d]
27-
if compiler.find_library_file(library_dirs, lib):
28-
libs[d] = [lib]
29-
tlib = '_'.join((lib, 'threads'))
30-
if compiler.find_library_file(library_dirs, tlib):
31-
libs[d].append(tlib)
32-
if sys.platform in ('unix', 'darwin'):
33-
libs[d].append('m')
24+
def get_fftw_libs():
25+
"""Return FFTW libraries"""
26+
compiler = ccompiler.new_compiler()
27+
libs = {}
28+
for d in ('float', 'double', 'long double'):
29+
lib = 'fftw3'+prec_map[d]
30+
if compiler.find_library_file(library_dirs, lib):
31+
libs[d] = [lib]
32+
tlib = '_'.join((lib, 'threads'))
33+
if compiler.find_library_file(library_dirs, tlib):
34+
libs[d].append(tlib)
35+
if sys.platform in ('unix', 'darwin'):
36+
libs[d].append('m')
37+
return libs
3438

35-
# Generate files with float and long double if needed
36-
for d in ('float', 'long double'):
37-
p = 'fftw'+prec_map[d]+'_'
38-
for fl in ('fftw_planxfftn.h', 'fftw_planxfftn.c', 'fftw_xfftn.pyx', 'fftw_xfftn.pxd'):
39-
fp = fl.replace('fftw_', p)
40-
shutil.copy(os.path.join(fftwdir, fl), os.path.join(fftwdir, fp))
41-
sedcmd = "sed -i ''" if sys.platform == 'darwin' else "sed -i''"
42-
os.system(sedcmd + " 's/fftw_/{0}/g' {1}".format(p, os.path.join(fftwdir, fp)))
43-
os.system(sedcmd + " 's/double/{0}/g' {1}".format(d, os.path.join(fftwdir, fp)))
39+
def generate_extensions(fftwlibs):
40+
"""Generate files with float and long double"""
41+
for d in fftwlibs:
42+
if d == 'double':
43+
continue
44+
p = 'fftw'+prec_map[d]+'_'
45+
for fl in ('fftw_planxfftn.h', 'fftw_planxfftn.c', 'fftw_xfftn.pyx', 'fftw_xfftn.pxd'):
46+
fp = fl.replace('fftw_', p)
47+
shutil.copy(os.path.join(fftwdir, fl), os.path.join(fftwdir, fp))
48+
sedcmd = "sed -i ''" if sys.platform == 'darwin' else "sed -i''"
49+
os.system(sedcmd + " 's/fftw_/{0}/g' {1}".format(p, os.path.join(fftwdir, fp)))
50+
os.system(sedcmd + " 's/double/{0}/g' {1}".format(d, os.path.join(fftwdir, fp)))
4451

45-
ext = [Extension("mpi4py_fft.fftw.utilities",
46-
sources=[os.path.join(fftwdir, "utilities.pyx")],
47-
include_dirs=[get_include(),
48-
os.path.join(sys.prefix, 'include')])]
52+
def get_extensions(fftwlibs):
53+
"""Return list of extension modules"""
54+
ext = [Extension("mpi4py_fft.fftw.utilities",
55+
sources=[os.path.join(fftwdir, "utilities.pyx")],
56+
include_dirs=include_dirs)]
4957

50-
for d, v in six.iteritems(libs):
51-
p = 'fftw'+prec_map[d]+'_'
52-
ext.append(Extension("mpi4py_fft.fftw.{}xfftn".format(p),
53-
sources=[os.path.join(fftwdir, "{}xfftn.pyx".format(p)),
54-
os.path.join(fftwdir, "{}planxfftn.c".format(p))],
55-
#define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')],
56-
libraries=v,
57-
include_dirs=include_dirs,
58-
library_dirs=library_dirs))
58+
for d, libs in fftwlibs.items():
59+
p = 'fftw'+prec_map[d]+'_'
60+
ext.append(Extension("mpi4py_fft.fftw.{}xfftn".format(p),
61+
sources=[os.path.join(fftwdir, "{}xfftn.pyx".format(p)),
62+
os.path.join(fftwdir, "{}planxfftn.c".format(p))],
63+
#define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')],
64+
libraries=libs,
65+
include_dirs=include_dirs,
66+
library_dirs=library_dirs))
67+
return ext
5968

69+
def version():
70+
srcdir = os.path.join(cwd, 'mpi4py_fft')
71+
with open(os.path.join(srcdir, '__init__.py')) as f:
72+
m = re.search(r"__version__\s*=\s*'(.*)'", f.read())
73+
return m.groups()[0]
74+
75+
fftw_libs = get_fftw_libs()
76+
assert len(fftw_libs) > 0, "No FFTW libraries found!"
77+
generate_extensions(fftw_libs)
6078
with open("README.rst", "r") as fh:
6179
long_description = fh.read()
6280

6381
setup(name="mpi4py-fft",
64-
version="1.0.1",
82+
version=version(),
6583
description="mpi4py-fft -- FFT with MPI",
6684
long_description=long_description,
6785
author="Lisandro Dalcin and Mikael Mortensen",
@@ -82,7 +100,7 @@
82100
'Topic :: Scientific/Engineering :: Mathematics',
83101
'Topic :: Software Development :: Libraries :: Python Modules',
84102
],
85-
ext_modules=ext,
86-
install_requires=["mpi4py", "numpy", "six"],
87-
setup_requires=["setuptools>=18.0", "cython>=0.25", "six"]
103+
ext_modules=get_extensions(fftw_libs),
104+
install_requires=["mpi4py", "numpy"],
105+
setup_requires=["setuptools>=18.0", "cython>=0.25"]
88106
)

tests/test_fftw.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from __future__ import print_function
22
from time import time
3-
import six
43
import numpy as np
54
from scipy.fftpack import dctn as scipy_dctn
65
from scipy.fftpack import dstn as scipy_dstn
@@ -24,7 +23,7 @@
2423
'dct1': fftw.FFTW_REDFT00,
2524
'dst1': fftw.FFTW_RODFT00}
2625

27-
rkinds = {val: key for key, val in six.iteritems(kinds)}
26+
rkinds = {val: key for key, val in kinds.items()}
2827

2928
def allclose(a, b):
3029
atol = abstol[a.dtype.char.lower()]
@@ -123,11 +122,11 @@ def test_fftw():
123122
kds = np.random.randint(3, 11, size=naxes) # get naxes random transforms
124123
tsf = [rkinds[k] for k in kds]
125124
T = fftw.get_planned_FFT(input_array, input_array.copy(), axes=axes,
126-
kind=kds, threads=threads, flags=fflags)
125+
kind=kds, threads=threads, flags=fflags)
127126
C = T(A)
128127
TI = fftw.get_planned_FFT(input_array.copy(), input_array.copy(), axes=axes,
129-
kind=list([fftw.inverse[kd] for kd in kds]),
130-
threads=threads, flags=iflags)
128+
kind=list([fftw.inverse[kd] for kd in kds]),
129+
threads=threads, flags=iflags)
131130

132131
C2 = TI(C)
133132
M = fftw.get_normalization(kds, input_array.shape, axes)

tests/test_libfft.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def allclose(a, b):
1919
def test_libfft():
2020
from itertools import product
2121

22-
dims = (1, 2, 3)
22+
dims = (1, 2, 3)
2323
sizes = (7, 8, 9)
2424
types = ''
2525
for t in 'fdg':
@@ -56,7 +56,7 @@ def test_libfft():
5656
A = fft.backward(B, A)
5757
t0 += time()
5858
assert allclose(A, X)
59-
print(use_pyfftw, t0)
59+
print('use_pyfftw: ', use_pyfftw, t0)
6060
# Padding is different because the physical space is padded and as such
6161
# difficult to initialize. We solve this problem by making one extra
6262
# transform

0 commit comments

Comments
 (0)