Skip to content

Commit d9d6d1d

Browse files
Milestone: small subset of ufuncs added and working
1 parent 3a06ca6 commit d9d6d1d

File tree

6 files changed

+449
-88
lines changed

6 files changed

+449
-88
lines changed

mkl_umath/generate_umath.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
import ufunc_docstrings as docstrings
99
sys.path.pop(0)
1010

11-
Zero = "PyInt_FromLong(0)"
12-
One = "PyInt_FromLong(1)"
11+
Zero = "PyLong_FromLong(0)"
12+
One = "PyLong_FromLong(1)"
1313
True_ = "(Py_INCREF(Py_True), Py_True)"
1414
False_ = "(Py_INCREF(Py_False), Py_False)"
1515
None_ = object()
@@ -1178,11 +1178,9 @@ def make_code(funcdict, filename):
11781178
11791179
Please make changes to the code generator program (%s)
11801180
**/
1181-
#include "ufunc_object.h"
1182-
#include "ufunc_type_resolution.h"
1183-
#include "loops.h"
1184-
#include "matmul.h"
1185-
#include "clip.h"
1181+
#include "Python.h"
1182+
#include "numpy/ufuncobject.h"
1183+
#include "loops_intel.h"
11861184
%s
11871185
11881186
static int

mkl_umath/setup.py

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,28 @@
2525
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2626

2727
import sys
28+
from os import (getcwd, environ, makedirs)
2829
from os.path import join, exists, abspath, dirname
29-
from os import getcwd
30-
from os import environ
30+
import importlib.machinery # requires Python >= 3.4
31+
from distutils.dep_util import newer
32+
33+
def load_module(name, fn):
34+
"""
35+
Credit: numpy.compat.npy_load_module
36+
"""
37+
return importlib.machinery.SourceFileLoader(name, fn).load_module()
38+
39+
40+
def separator_join(sep, strs):
41+
"""
42+
Joins non-empty arguments strings with dot.
43+
44+
Credit: numpy.distutils.misc_util.dot_join
45+
"""
46+
assert isinstance(strs, (list, tuple))
47+
assert isinstance(sep, str)
48+
return sep.join([si for si in strs if si])
49+
3150

3251
def configuration(parent_package='',top_path=None):
3352
from numpy.distutils.misc_util import Configuration
@@ -52,7 +71,26 @@ def configuration(parent_package='',top_path=None):
5271
wdir = join(pdir, 'src')
5372
mkl_info = get_info('mkl')
5473

55-
sources = []
74+
generate_umath_py = join(pdir, 'generate_umath.py')
75+
n = separator_join('_', (config.name, 'generate_umath'))
76+
generate_umath = load_module(n, generate_umath_py)
77+
del n
78+
79+
def generate_umath_c(ext, build_dir):
80+
target_dir = join(build_dir, 'src')
81+
target = join(target_dir, '__umath_generated.c')
82+
if not exists(target_dir):
83+
print("Folder {} was expected to exist, but creating".format(target_dir))
84+
makedirs(target_dir)
85+
script = generate_umath_py
86+
if newer(script, target):
87+
with open(target, 'w') as f:
88+
f.write(generate_umath.make_code(generate_umath.defdict,
89+
generate_umath.__file__))
90+
config.add_include_dirs(target_dir)
91+
return []
92+
93+
sources = [generate_umath_c]
5694
# try:
5795
# from Cython.Build import cythonize
5896
# sources = [join(pdir, '_pydfti.pyx')]
@@ -67,18 +105,20 @@ def configuration(parent_package='',top_path=None):
67105
config.add_extension(
68106
name = '_ufuncs',
69107
sources = [
108+
join(wdir, 'loops_intel.h.src'),
109+
join(wdir, 'loops_intel.c.src'),
70110
join(wdir, 'ufuncsmodule.c'),
71-
join(wdir, 'loops_intel.c.src')
72111
] + sources,
73112
depends = [
74-
# join(wdir, 'mklfft.h'),
113+
join(wdir, 'blocking_utils.h'),
114+
join(wdir, 'fast_loop_macros.h'),
75115
],
76116
include_dirs = [wdir] + mkl_include_dirs,
77117
libraries = mkl_libraries,
78118
library_dirs = mkl_library_dirs,
79119
extra_compile_args = [
80-
'-DNDEBUG',
81-
# '-ggdb', '-O0', '-Wall', '-Wextra', '-DDEBUG',
120+
# '-DNDEBUG',
121+
'-ggdb', '-O0', '-Wall', '-Wextra', '-DDEBUG',
82122
]
83123
)
84124

0 commit comments

Comments
 (0)