-
Notifications
You must be signed in to change notification settings - Fork 171
/
setup.py
165 lines (146 loc) · 5.27 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
from __future__ import absolute_import, print_function
import io
import os
import sys
from glob import glob
from os.path import basename
from os.path import dirname
from os.path import join
from os.path import splitext
from setuptools import find_packages
from setuptools import setup
from setuptools import Extension
from setuptools.command.install import install
# ================================ C++ extension
import numpy
PROJ_DIR = os.path.dirname(os.path.realpath(__file__))
# CPP_SRC_PATH = join(PROJ_DIR, 'cpp', 'src')
CPP_SRC_PATH = join('cpp', 'src')
# Obtain the numpy include directory. This logic works across numpy versions.
try:
numpy_include = numpy.get_include()
except AttributeError:
numpy_include = numpy.get_numpy_include()
# gather up all the source files
# srcFiles = [join(PROJ_DIR, 'python', 'bolt', 'native.i')]
srcFiles = [join('python', 'bolt', 'native.i')]
includeDirs = [numpy_include]
paths = [CPP_SRC_PATH]
for path in paths:
srcDir = path
for root, dirNames, fileNames in os.walk(srcDir):
for dirName in dirNames:
absPath = os.path.join(root, dirName)
if absPath.startswith("cpp/src/external"):
continue
print('adding dir to path: %s' % absPath)
globStr = "%s/*.cpp" % absPath
files = glob(globStr)
if 'eigen/src' not in absPath: # just include top level
includeDirs.append(absPath)
srcFiles += files
# set the compiler flags so it'll build on different platforms (feel free
# to file a pull request with a fix if it doesn't work on yours)
# note that -march=native implies -mavx and -mavx2; Bolt requires AVX2
extra_args = ['-std=c++14',
'-fno-rtti',
'-march=native',
'-ffast-math']
if sys.platform == 'darwin':
extra_args.append('-mmacosx-version-min=10.9')
os.environ['LDFLAGS'] = '-mmacosx-version-min=10.9 -stdlib=libc++ -framework Accelerate'
os.environ["CC"] = "g++" # force compiling c as c++
else: # based on Issue #4
if "CC" not in os.environ:
os.environ['CC'] = "clang"
if "CXX" not in os.environ:
os.environ['CXX'] = "clang++"
# extra_args += ['-stdlib=libc++']
# os.environ['CC'] = "clang"
# os.environ['CXX'] = "clang++"
# os.environ['LDFLAGS'] = '-lc++'
# else:
# os.environ["CC"] = "clang++" # force compiling c as c++
# inplace extension module
includeDirs += [join(PROJ_DIR, 'python', 'bolt')]
if 'EIGEN_INCLUDE_DIR' in os.environ:
includeDirs += [
os.environ['EIGEN_INCLUDE_DIR'],
os.environ['EIGEN_INCLUDE_DIR'] + '/Eigen'
]
else:
includeDirs += [
join(PROJ_DIR, 'cpp', 'src', 'external', 'eigen'),
join(PROJ_DIR, 'cpp', 'src', 'external', 'eigen', 'Eigen')
]
nativeExt = Extension("bolt._bolt", # must match cpp header name with leading _
srcFiles,
define_macros=[('NDEBUG', '1')],
include_dirs=includeDirs,
# swig_opts=['-c++', '-modern'],
swig_opts=['-c++'],
extra_compile_args=extra_args
# extra_link_args=['-stdlib=libc++'],
)
# ================================ Python modules
# glob_str = join('python', 'bolt') + '*.py'
# modules = [splitext(basename(path))[0] for path in glob(glob_str)]
# ================================ Call to setup()
# This ensures that the extension (which generates bolt.py) is built
# before py_modules are copied.
class CustomInstall(install):
def run(self):
self.run_command('build_ext')
self.do_egg_install()
setup(
cmdclass={'install': CustomInstall},
name='pybolt',
version='0.1.4',
license='MPL',
description='Fast approximate matrix and vector operations',
author='Davis Blalock',
author_email='[email protected]',
url='https://github.com/dblalock/bolt',
download_url='https://github.com/dblalock/bolt/archive/0.1.tar.gz',
packages=['bolt'],
package_dir={'bolt': 'python/bolt'},
py_modules=['python/bolt/bolt'],
include_package_data=True,
zip_safe=False,
classifiers=[
# complete classifier list:
# http://pypi.python.org/pypi?%3Aaction=list_classifiers
'Development Status :: 3 - Alpha',
'Intended Audience :: Developers',
'License :: OSI Approved :: Mozilla Public License 2.0 (MPL 2.0)',
'Operating System :: Unix',
'Operating System :: POSIX',
'Programming Language :: C',
'Programming Language :: C++',
'Programming Language :: Python',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: Implementation :: CPython',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
'Topic :: Utilities',
],
keywords=[
'Machine Learning', 'Compression', 'Big Data',
# eg: 'keyword1', 'keyword2', 'keyword3',
],
install_requires=[
'numpy',
'scikit-learn',
#'kmc2'
# 'sphinx_rtd_theme' # for docs
],
extras_require={
# eg:
# 'rst': ['docutils>=0.11'],
# ':python_version=="2.6"': ['argparse'],
},
ext_modules=[
nativeExt
],
)