def build_extension(self, ext): from numpy import get_include as _np_inc np_inc = _np_inc() pybind_inc = 'lib/pybind11/include' ext.include_dirs.append(np_inc) ext.include_dirs.append(pybind_inc) ext.extra_compile_args += ['-fopenmp' if sys.platform != 'darwin' else '-fopenmp=libiomp5'] if sys.platform.startswith('linux'): ext.extra_link_args += ['-lgomp'] elif sys.platform == 'darwin': ext.extra_link_args += ['-liomp5'] super(Build, self).build_extension(ext)
def build_extensions(self): extra_compile_args = [] extra_link_args = [] define_macros = [] from numpy import get_include as _np_inc np_inc = _np_inc() pybind_inc = Path(pybind11.get_include()) common_inc = Path('deeptime') / 'src' / 'include' if self.compiler.compiler_type == 'msvc': cxx_flags = [ '/EHsc', '/std:c++latest', '/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version() ] extra_link_args.append('/machine:X64') else: cxx_flags = ['-std=c++17'] extra_compile_args += ['-pthread'] extra_link_args = ['-lpthread'] has_openmp = supports_omp(self.compiler) if has_openmp: extra_compile_args += [ '-fopenmp' if sys.platform != 'darwin' else '-fopenmp=libiomp5' ] if sys.platform.startswith('linux'): extra_link_args += ['-lgomp'] elif sys.platform == 'darwin': extra_link_args += ['-liomp5'] else: raise ValueError("Should not happen.") define_macros += [('USE_OPENMP', None)] for ext in self.extensions: ext.include_dirs.append(np_inc) ext.include_dirs.append(pybind_inc.resolve()) ext.include_dirs.append(common_inc.resolve()) if ext.language == 'c++': ext.extra_compile_args += cxx_flags ext.extra_compile_args += extra_compile_args ext.extra_link_args += extra_link_args ext.define_macros += define_macros super(Build, self).build_extensions()
def build_extension(self, ext): from numpy import get_include as _np_inc np_inc = _np_inc() pybind_inc = 'lib/pybind11/include' ext.include_dirs.append(np_inc) ext.include_dirs.append(pybind_inc) if supports_omp(self.compiler): ext.extra_compile_args += [ '-fopenmp' if sys.platform != 'darwin' else '-fopenmp=libiomp5' ] if sys.platform.startswith('linux'): ext.extra_link_args += ['-lgomp'] elif sys.platform == 'darwin': ext.extra_link_args += ['-liomp5'] else: raise ValueError("Hmm.") ext.define_macros += [('USE_OPENMP', None)] super(Build, self).build_extension(ext)
def build_extensions(self): extra_compile_args = [] extra_link_args = [] define_macros = [] from numpy import get_include as _np_inc np_inc = _np_inc() pybind_inc = 'lib/pybind11/include' # TODO: this is platform dependent, e.g. win should be treated differently. if self.compiler.compiler_type == 'msvc': cxx_flags = [ '/EHsc', '/std:c++latest', '/DVERSION_INFO=\\"%s\\"' % self.distribution.get_version() ] extra_link_args.append('/machine:X64') else: cxx_flags = ['-std=c++14'] has_openmp = supports_omp(self.compiler) if has_openmp: extra_compile_args += [ '-fopenmp' if sys.platform != 'darwin' else '-fopenmp=libiomp5' ] if sys.platform.startswith('linux'): extra_link_args += ['-lgomp'] elif sys.platform == 'darwin': extra_link_args += ['-liomp5'] else: raise ValueError("Hmm.") define_macros += [('USE_OPENMP', None)] for ext in self.extensions: ext.include_dirs.append(np_inc) ext.include_dirs.append(pybind_inc) if ext.language == 'c++': ext.extra_compile_args += cxx_flags ext.extra_compile_args += extra_compile_args ext.extra_link_args += extra_link_args ext.define_macros += define_macros super(Build, self).build_extensions()
def build_extensions(self): extra_compile_args = [] extra_link_args = [] define_macros = [] from numpy import get_include as _np_inc np_inc = _np_inc() pybind_inc = Path(pybind11.get_include()) common_inc = Path('deeptime') / 'src' / 'include' if self.compiler.compiler_type == 'msvc': cxx_flags = [ '/EHsc', '/std:c++17', '/bigobj', f'/DVERSION_INFO=\\"{self.distribution.get_version()}\\"' ] extra_link_args.append('/machine:X64') else: cxx_flags = [ '-std=c++17', "-fvisibility=hidden", "-g0", "-Wno-register" ] extra_compile_args += ['-pthread'] extra_link_args = ['-lpthread'] self.setup_openmp(define_macros, extra_compile_args, extra_link_args) for ext in self.extensions: ext.include_dirs.append(common_inc.resolve()) ext.include_dirs.append(np_inc) ext.include_dirs.append(pybind_inc.resolve()) if ext.language == 'c++': ext.extra_compile_args += cxx_flags ext.extra_compile_args += extra_compile_args ext.extra_link_args += extra_link_args ext.define_macros += define_macros super(Build, self).build_extensions()
def extensions(): """How do we handle cython: 1. when on git, require cython during setup time (do not distribute generated .c files via git) a) cython present -> fine b) no cython present -> install it on the fly. Extensions have to have .pyx suffix This is solved via a lazy evaluation of the extension list. This is needed, because build_ext is being called before cython will be available. https://bitbucket.org/pypa/setuptools/issue/288/cannot-specify-cython-under-setup_requires 2. src dist install (have pre-converted c files and pyx files) a) cython present -> fine b) no cython -> use .c files """ USE_CYTHON = False try: from Cython.Build import cythonize USE_CYTHON = True except ImportError: warnings.warn('Cython not found. Using pre cythonized files.') # setup OpenMP support from setup_util import detect_openmp openmp_enabled, needs_gomp = detect_openmp() import mdtraj from numpy import get_include as _np_inc np_inc = _np_inc() exts = [] if sys.platform.startswith('win'): lib_prefix = 'lib' else: lib_prefix = '' regspatial_module = \ Extension('pyemma.coordinates.clustering.regspatial', sources=[ 'pyemma/coordinates/clustering/src/regspatial.c', 'pyemma/coordinates/clustering/src/clustering.c'], include_dirs=[ mdtraj.capi()['include_dir'], np_inc, 'pyemma/coordinates/clustering/include', ], libraries=[lib_prefix+'theobald'], library_dirs=[mdtraj.capi()['lib_dir']], extra_compile_args=['-std=c99', '-g', '-O3', '-pg']) kmeans_module = \ Extension('pyemma.coordinates.clustering.kmeans_clustering', sources=[ 'pyemma/coordinates/clustering/src/kmeans.c', 'pyemma/coordinates/clustering/src/clustering.c'], include_dirs=[ mdtraj.capi()['include_dir'], np_inc, 'pyemma/coordinates/clustering/include'], libraries=[lib_prefix+'theobald'], library_dirs=[mdtraj.capi()['lib_dir']], extra_compile_args=['-std=c99']) covar_module = \ Extension('pyemma.coordinates.estimators.covar.covar_c.covartools', sources=['pyemma/coordinates/estimators/covar/covar_c/covartools.pyx', 'pyemma/coordinates/estimators/covar/covar_c/_covartools.c'], include_dirs=['pyemma/coordinates/estimators/covar/covar_c/', np_inc, ], extra_compile_args=['-std=c99', '-O3']) exts += [ regspatial_module, kmeans_module, covar_module, ] if not USE_CYTHON: # replace pyx files by their pre generated c code. for e in exts: new_src = [] for s in e.sources: new_src.append(s.replace('.pyx', '.c')) e.sources = new_src else: exts = cythonize(exts) if openmp_enabled: warnings.warn('enabled openmp') omp_compiler_args = ['-fopenmp'] omp_libraries = ['-lgomp'] if needs_gomp else [] omp_defines = [('USE_OPENMP', None)] for e in exts: e.extra_compile_args += omp_compiler_args e.extra_link_args += omp_libraries e.define_macros += omp_defines return exts
def extensions(): """How do we handle cython: 1. when on git, require cython during setup time (do not distribute generated .c files via git) a) cython present -> fine b) no cython present -> install it on the fly. Extensions have to have .pyx suffix This is solved via a lazy evaluation of the extension list. This is needed, because build_ext is being called before cython will be available. https://bitbucket.org/pypa/setuptools/issue/288/cannot-specify-cython-under-setup_requires 2. src dist install (have pre-converted c files and pyx files) a) cython present -> fine b) no cython -> use .c files """ USE_CYTHON = False try: from Cython.Build import cythonize USE_CYTHON = True except ImportError: warnings.warn('Cython not found. Using pre cythonized files.') # setup OpenMP support from setup_util import detect_openmp openmp_enabled, needs_gomp = detect_openmp() from numpy import get_include as _np_inc np_inc = _np_inc() exts = [] mle_trev_given_pi_dense_module = \ Extension('msmtools.estimation.dense.mle_trev_given_pi', sources=['msmtools/estimation/dense/mle_trev_given_pi.pyx', 'msmtools/estimation/dense/_mle_trev_given_pi.c'], depends=['msmtools/util/sigint_handler.h'], include_dirs=['msmtools/estimation/dense', np_inc]) mle_trev_given_pi_sparse_module = \ Extension('msmtools.estimation.sparse.mle_trev_given_pi', sources=['msmtools/estimation/sparse/mle_trev_given_pi.pyx', 'msmtools/estimation/sparse/_mle_trev_given_pi.c'], depends=['msmtools/util/sigint_handler.h'], include_dirs=['msmtools/estimation/dense', np_inc]) mle_trev_dense_module = \ Extension('msmtools.estimation.dense.mle_trev', sources=['msmtools/estimation/dense/mle_trev.pyx', 'msmtools/estimation/dense/_mle_trev.c'], depends=['msmtools/util/sigint_handler.h'], include_dirs=[np_inc]) mle_trev_sparse_module = \ Extension('msmtools.estimation.sparse.mle_trev', sources=['msmtools/estimation/sparse/mle_trev.pyx', 'msmtools/estimation/sparse/_mle_trev.c'], depends=['msmtools/util/sigint_handler.h'], include_dirs=[np_inc, ]) sampler_rev = \ Extension('msmtools.estimation.dense.sampler_rev', sources=['msmtools/estimation/dense/sampler_rev.pyx', 'msmtools/estimation/dense/sample_rev.c', 'msmtools/estimation/dense/_rnglib.c', 'msmtools/estimation/dense/_ranlib.c'], include_dirs=[np_inc, ]) sampler_revpi = \ Extension('msmtools.estimation.dense.sampler_revpi', sources=['msmtools/estimation/dense/sampler_revpi.pyx', 'msmtools/estimation/dense/sample_revpi.c', 'msmtools/estimation/dense/_rnglib.c', 'msmtools/estimation/dense/_ranlib.c'], include_dirs=[np_inc, ]) kahandot_module = \ Extension('msmtools.util.kahandot', sources = ['msmtools/util/kahandot_src/kahandot.pyx', 'msmtools/util/kahandot_src/_kahandot.c'], depends = ['msmtools/util/kahandot_src/_kahandot.h'], include_dirs=[np_inc, ]) exts += [ mle_trev_given_pi_dense_module, mle_trev_given_pi_sparse_module, mle_trev_dense_module, mle_trev_sparse_module, sampler_rev, sampler_revpi, kahandot_module ] if USE_CYTHON: # if we have cython available now, cythonize module exts = cythonize(exts) else: # replace pyx files by their pre generated c code. for e in exts: new_src = [] for s in e.sources: new_src.append(s.replace('.pyx', '.c')) e.sources = new_src if openmp_enabled: warnings.warn('enabled openmp') omp_compiler_args = ['-fopenmp'] omp_libraries = ['-lgomp'] if needs_gomp else [] omp_defines = [('USE_OPENMP', None)] for e in exts: e.extra_compile_args += omp_compiler_args e.extra_link_args += omp_libraries e.define_macros += omp_defines return exts
def extensions(): """How do we handle cython: 1. when on git, require cython during setup time (do not distribute generated .c files via git) a) cython present -> fine b) no cython present -> install it on the fly. Extensions have to have .pyx suffix This is solved via a lazy evaluation of the extension list. This is needed, because build_ext is being called before cython will be available. https://bitbucket.org/pypa/setuptools/issue/288/cannot-specify-cython-under-setup_requires 2. src dist install (have pre-converted c files and pyx files) a) cython present -> fine b) no cython -> use .c files """ USE_CYTHON = False try: from Cython.Build import cythonize USE_CYTHON = True except ImportError: warnings.warn('Cython not found. Using pre cythonized files.') import mdtraj from numpy import get_include as _np_inc np_inc = _np_inc() pybind_inc = os.path.join(os.path.dirname(__file__), 'pybind11', 'include') assert os.path.exists(pybind_inc) exts = [] lib_prefix = 'lib' if sys.platform.startswith('win') else '' common_cflags = [ '-O3', ] clustering_module = \ Extension('pyemma.coordinates.clustering._ext', sources=['pyemma/coordinates/clustering/src/clustering_module.cpp'], include_dirs=[ mdtraj.capi()['include_dir'], np_inc, pybind_inc, 'pyemma/coordinates/clustering/include', ], language='c++', libraries=[lib_prefix+'theobald'], library_dirs=[mdtraj.capi()['lib_dir']], extra_compile_args=common_cflags) covar_module = \ Extension('pyemma._ext.variational.estimators.covar_c._covartools', sources=['pyemma/_ext/variational/estimators/covar_c/covartools.cpp'], include_dirs=['pyemma/_ext/variational/estimators/covar_c/', np_inc, pybind_inc, ], language='c++', extra_compile_args=common_cflags) eig_qr_module = \ Extension('pyemma._ext.variational.solvers.eig_qr.eig_qr', sources=['pyemma/_ext/variational/solvers/eig_qr/eig_qr.pyx'], include_dirs=['pyemma/_ext/variational/solvers/eig_qr/', np_inc], extra_compile_args=['-std=c99'] + common_cflags) orderedset = \ Extension('pyemma._ext.orderedset._orderedset', sources=['pyemma/_ext/orderedset/_orderedset.pyx'], include_dirs=[np_inc], extra_compile_args=['-std=c99'] + common_cflags) exts += [clustering_module, covar_module, eig_qr_module, orderedset] if not USE_CYTHON: # replace pyx files by their pre generated c code. for e in exts: new_src = [] for s in e.sources: new_src.append(s.replace('.pyx', '.c')) e.sources = new_src else: exts = cythonize(exts) return exts
def extensions(): """How do we handle cython: 1. when on git, require cython during setup time (do not distribute generated .c files via git) a) cython present -> fine b) no cython present -> install it on the fly. Extensions have to have .pyx suffix This is solved via a lazy evaluation of the extension list. This is needed, because build_ext is being called before cython will be available. https://bitbucket.org/pypa/setuptools/issue/288/cannot-specify-cython-under-setup_requires 2. src dist install (have pre-converted c files and pyx files) a) cython present -> fine b) no cython -> use .c files """ USE_CYTHON = False try: from Cython.Build import cythonize USE_CYTHON = True except ImportError: warnings.warn('Cython not found. Using pre cythonized files.') import mdtraj # Note, that we add numpy include to every extension after declaration. from numpy import get_include as _np_inc np_inc = _np_inc() pybind_inc = get_pybind_include() lib_prefix = 'lib' if sys.platform.startswith('win') else '' common_cflags = ['-O3', ] clustering_module = \ Extension('pyemma.coordinates.clustering._ext', sources=['pyemma/coordinates/clustering/src/clustering_module.cpp'], include_dirs=[ mdtraj.capi()['include_dir'], pybind_inc, 'pyemma/coordinates/clustering/include', ], language='c++', libraries=[lib_prefix+'theobald'], library_dirs=[mdtraj.capi()['lib_dir']], extra_compile_args=common_cflags) covar_module = \ Extension('pyemma._ext.variational.estimators.covar_c._covartools', sources=['pyemma/_ext/variational/estimators/covar_c/covartools.cpp'], include_dirs=['pyemma/_ext/variational/estimators/covar_c/', pybind_inc, ], language='c++', extra_compile_args=common_cflags) eig_qr_module = \ Extension('pyemma._ext.variational.solvers.eig_qr.eig_qr', sources=['pyemma/_ext/variational/solvers/eig_qr/eig_qr.pyx'], include_dirs=['pyemma/_ext/variational/solvers/eig_qr/', np_inc], extra_compile_args=['-std=c99'] + common_cflags) orderedset = \ Extension('pyemma._ext.orderedset._orderedset', sources=['pyemma/_ext/orderedset/_orderedset.pyx'], extra_compile_args=['-std=c99'] + common_cflags) extra_compile_args = ["-O3", "-std=c99"] ext_bar = Extension( "pyemma.thermo.extensions.bar", sources=["pyemma/thermo/extensions/bar/bar.pyx", "pyemma/thermo/extensions/bar/_bar.c", "pyemma/thermo/extensions/util/_util.c"], extra_compile_args=extra_compile_args) ext_wham = Extension( "pyemma.thermo.extensions.wham", sources=["pyemma/thermo/extensions/wham/wham.pyx", "pyemma/thermo/extensions/wham/_wham.c", "pyemma/thermo/extensions/util/_util.c"], extra_compile_args=extra_compile_args) ext_mbar = Extension( "pyemma.thermo.extensions.mbar", sources=["pyemma/thermo/extensions/mbar/mbar.pyx", "pyemma/thermo/extensions/mbar/_mbar.c", "pyemma/thermo/extensions/util/_util.c"], extra_compile_args=extra_compile_args) ext_tram = Extension( "pyemma.thermo.extensions.tram", sources=["pyemma/thermo/extensions/tram/tram.pyx", "pyemma/thermo/extensions/tram/_tram.c", "pyemma/thermo/extensions/util/_util.c"], extra_compile_args=extra_compile_args) ext_dtram = Extension( "pyemma.thermo.extensions.dtram", sources=["pyemma/thermo/extensions/dtram/dtram.pyx", "pyemma/thermo/extensions/dtram/_dtram.c", "pyemma/thermo/extensions/util/_util.c"], extra_compile_args=extra_compile_args) ext_trammbar = Extension( "pyemma.thermo.extensions.trammbar", sources=["pyemma/thermo/extensions/trammbar/trammbar.pyx", "pyemma/thermo/extensions/tram/_tram.c", "pyemma/thermo/extensions/util/_util.c"], extra_compile_args=extra_compile_args + ["-DTRAMMBAR"]) ext_mbar_direct = Extension( "pyemma.thermo.extensions.mbar_direct", sources=["pyemma/thermo/extensions/mbar_direct/mbar_direct.pyx", "pyemma/thermo/extensions/mbar_direct/_mbar_direct.c", "pyemma/thermo/extensions/util/_util.c"], extra_compile_args=extra_compile_args) ext_tram_direct = Extension( "pyemma.thermo.extensions.tram_direct", sources=["pyemma/thermo/extensions/tram_direct/tram_direct.pyx", "pyemma/thermo/extensions/tram_direct/_tram_direct.c", "pyemma/thermo/extensions/util/_util.c"], extra_compile_args=extra_compile_args) ext_trammbar_direct = Extension( "pyemma.thermo.extensions.trammbar_direct", sources=["pyemma/thermo/extensions/trammbar_direct/trammbar_direct.pyx", "pyemma/thermo/extensions/tram_direct/_tram_direct.c", "pyemma/thermo/extensions/util/_util.c"], extra_compile_args=extra_compile_args + ["-DTRAMMBAR"]) ext_util = Extension( "pyemma.thermo.extensions.util", sources=["pyemma/thermo/extensions/util/util.pyx", "pyemma/thermo/extensions/util/_util.c"], extra_compile_args=extra_compile_args) exts_thermo = [ ext_bar, ext_wham, ext_mbar, ext_tram, ext_dtram, ext_trammbar, ext_mbar_direct, ext_tram_direct, ext_trammbar_direct, ext_util] exts = [clustering_module, covar_module, eig_qr_module, orderedset ] exts += exts_thermo for e in exts: e.include_dirs.append(np_inc) if not USE_CYTHON: # replace pyx files by their pre generated c code. for e in exts: new_src = [] for s in e.sources: new_src.append(s.replace('.pyx', '.c')) e.sources = new_src else: exts = cythonize(exts, language_level=sys.version_info[0]) return exts