Skip to content

Commit 07a072c

Browse files
Initial commit of mkl_fft
mkl_fft is a Python interface to Intel (R) Math Kernel Library functions for performing discrete Fourier transforms, supporting working with NumPy's N-dimensional arrays.
0 parents  commit 07a072c

18 files changed

+5059
-0
lines changed

LICENSE.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Copyright (c) 2017, Intel Corporation
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are met:
5+
6+
* Redistributions of source code must retain the above copyright notice,
7+
this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above copyright
9+
notice, this list of conditions and the following disclaimer in the
10+
documentation and/or other materials provided with the distribution.
11+
* Neither the name of Intel Corporation nor the names of its contributors
12+
may be used to endorse or promote products derived from this software
13+
without specific prior written permission.
14+
15+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
19+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
22+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
23+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## ``mkl_fft`` -- a NumPy-based Python interface to Intel (R) MKL FFT functionality
2+
3+
`mkl_fft` started as a part of Intel (R) Distribution for Python* optimizations to NumPy, and is now being released
4+
as a stand-alone package. It can be installed into conda environment using
5+
6+
```
7+
conda install -c intel mkl_fft
8+
```
9+
10+
---
11+
12+
Since MKL FFT supports performing discrete Fourier transforms over non-contiguously laid out arrays, MKL can be directly
13+
used on any well-behaved floating point array with no internal overlaps for both in-place and not in-place transforms of
14+
arrays in single and double floating point precision.
15+
16+
This eliminates the need to copy input arrayy contiguously into an intermediate buffer.
17+
18+
`mkl_fft` directly supports N-dimensional Fourier transforms.
19+
20+
More details can be found in SciPy 2017 conference proceedings:
21+
https://github.com/scipy-conference/scipy_proceedings/tree/2017/papers/oleksandr_pavlyk
22+
23+
---
24+
25+
It implements the following functions:
26+
27+
### Complex transforms, similar to those in `scipy.fftpack`:
28+
29+
`fft(x, n=None, axis=-1, overwrite_x=False)`
30+
31+
`ifft(x, n=None, axis=-1, overwrite_x=False)`
32+
33+
`fft2(x, shape=None, axes=(-2,-1), overwrite_x=False)`
34+
35+
`ifft2(x, shape=None, axes=(-2,-1), overwrite_x=False)`
36+
37+
`fftn(x, n=None, axes=None, overwrite_x=False)`
38+
39+
`ifftn(x, n=None, axes=None, overwrite_x=False)`
40+
41+
### Real transforms
42+
43+
`rfft(x, n=None, axis=-1, overwrite_x=False)` - real 1D Fourier transform, like `scipy.fftpack.rfft`
44+
45+
`rfft_numpy(x, n=None, axis=-1)` - real 1D Fourier transform, like `numpy.fft.rfft`
46+
47+
`rfft2_numpy(x, s=None, axes=(-2,-1))` - real 2D Fourier transform, like `numpy.fft.rfft2`
48+
49+
`rfftn_numpy(x, s=None, axes=None)` - real 2D Fourier transform, like `numpy.fft.rfftn`
50+
51+
... and similar `irfft*` functions.
52+
53+
54+
The package also provides `mkl_fft._numpy_fft` and `mkl_fft._scipy_fft` interfaces which provide drop-in replacements for equivalent functions in NumPy and SciPy respectively.

conda-recipe/bld.bat

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@rem Remember to activate Intel Compiler, or remoe these two lines to ise Microsoft Visual Studio compiler
2+
3+
set CC=icl
4+
set LD=xilink
5+
6+
%PYTHON% setup.py build --force --compiler=intelemw install --old-and-unmanageable
7+
if errorlevel 1 exit 1

conda-recipe/build.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash -x
2+
3+
# make sure that compiler has been sourced, if necessary
4+
5+
if [ `uname` == Darwin ]; then
6+
export MACOSX_DEPLOYMENT_TARGET=10.10
7+
fi
8+
9+
CFLAGS="-I$PREFIX/include $CFLAGS" $PYTHON setup.py build --force --compiler=intelem install --old-and-unmanageable

conda-recipe/meta.yaml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{% set version = "1.0.0" %}
2+
{% set buildnumber = 14 %}
3+
4+
### If you change the iccver here, you must also set the path correctly in build.sh / bld.bat!!!
5+
{% set iccver = "16.0.3" %} [unix or py3k]
6+
{% set iccver = "13.1.5" %} [win and py27]
7+
8+
package:
9+
name: mkl_fft
10+
version: {{ version }}
11+
12+
source:
13+
git_url: http://github.com/IntelPython/mkl_fft
14+
git_tag: v{{version}}
15+
16+
build:
17+
number: {{buildnumber}}
18+
features:
19+
- intel
20+
always_include_files:
21+
- {{ SP_DIR.replace('\\', '/') if win else SP_DIR }}/mkl_fft/__init__.py
22+
- {{ SP_DIR.replace('\\', '/') if win else SP_DIR }}/mkl_fft/_float16_utils.py
23+
- {{ SP_DIR.replace('\\', '/') if win else SP_DIR }}/mkl_fft/_pydfti.*
24+
- {{ SP_DIR.replace('\\', '/') if win else SP_DIR }}/mkl_fft/_numpy_fft.py
25+
- {{ SP_DIR.replace('\\', '/') if win else SP_DIR }}/mkl_fft/_scipy_fft.py
26+
- {{ SP_DIR.replace('\\', '/') if win else SP_DIR }}/mkl_fft/setup.py
27+
- {{ SP_DIR.replace('\\', '/') if win else SP_DIR }}/mkl_fft/tests/test_fft1d.py
28+
- {{ SP_DIR.replace('\\', '/') if win else SP_DIR }}/mkl_fft/__pycache__/*
29+
- {{ SP_DIR.replace('\\', '/') if win else SP_DIR }}/mkl_fft/tests/__pycache__/*
30+
31+
requirements:
32+
build:
33+
- python
34+
- setuptools
35+
- intelpython
36+
- mkl-devel [not nomkl]
37+
- icc_rt
38+
- cython
39+
- numpy x.x
40+
run:
41+
- python
42+
- mkl [not nomkl]
43+
- icc_rt >={{iccver}}
44+
- intelpython
45+
- numpy x.x
46+
47+
test:
48+
commands:
49+
- nosetests -v mkl_fft
50+
requires:
51+
- nose
52+
imports:
53+
- mkl_fft
54+
- mkl_fft._numpy_fft
55+
- mkl_fft._scipy_fft
56+
57+
about:
58+
home: http://github.com/IntelPython/mkl_fft
59+
license: BSD
60+
license_file: LICENSE.txt
61+
summary: NumPy-based implementation of Fast Fourier Transform using Intel (R) Math Kernel Library

conda-recipe/run_test.py

Whitespace-only changes.

mkl_fft/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2017, Intel Corporation
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# * Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
# * Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
# * Neither the name of Intel Corporation nor the names of its contributors
13+
# may be used to endorse or promote products derived from this software
14+
# without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
from ._pydfti import (fft, ifft, fft2, ifft2, fftn, ifftn, rfft, irfft,
28+
rfft_numpy, irfft_numpy, rfftn_numpy, irfftn_numpy)
29+
30+
__all__ = ['fft', 'ifft', 'fft2', 'ifft2', 'fftn', 'ifftn', 'rfft', 'irfft',
31+
'rfft_numpy', 'irfft_numpy', 'rfftn_numpy', 'irfftn_numpy']

mkl_fft/_float16_utils.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env python
2+
# Copyright (c) 2017, Intel Corporation
3+
#
4+
# Redistribution and use in source and binary forms, with or without
5+
# modification, are permitted provided that the following conditions are met:
6+
#
7+
# * Redistributions of source code must retain the above copyright notice,
8+
# this list of conditions and the following disclaimer.
9+
# * Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
# * Neither the name of Intel Corporation nor the names of its contributors
13+
# may be used to endorse or promote products derived from this software
14+
# without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
20+
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
from numpy import half, float32, asarray, ndarray, longdouble, float64
28+
29+
__all__ = ['__upcast_float16_array']
30+
31+
def __upcast_float16_array(x):
32+
if hasattr(x, "dtype"):
33+
xdt = x.dtype
34+
if xdt == half:
35+
# no half-precision routines, so convert to single precision
36+
return asarray(x, dtype=float32)
37+
if xdt == longdouble and not xdt == float64 :
38+
raise ValueError("type %s is not supported" % xdt)
39+
if not isinstance(x, ndarray):
40+
__x = asarray(x)
41+
xdt = __x.dtype
42+
if xdt == half:
43+
# no half-precision routines, so convert to single precision
44+
return asarray(__x, dtype=float32)
45+
if xdt == longdouble and not xdt == float64:
46+
raise ValueError("type %s is not supported" % xdt)
47+
return __x
48+
return x

0 commit comments

Comments
 (0)