Example #1
0
 def __init__(self):
     Extension.__init__(self, self.name, [], cython_c_in_temp=True)
     self.cython_compile_time_env = { "PY_MAJOR_VERSION" : sys.version_info[0] }
     self.make()
     self.check_cplusplus()
     self.add_optimize_flag()
     self.include_dirs.append(self.dbase)
     self.include_dirs = list(set(self.include_dirs))
     self.libraries = list(set(self.libraries))
     self.library_dirs = list(set(self.library_dirs))
     self.define_macros = list(set(self.define_macros))
     self.extra_link_args = list(set(self.extra_link_args))
Example #2
0
 def __init__(self):
     Extension.__init__(self, self.name, [], cython_c_in_temp=True)
     self.cython_compile_time_env = {
         "PY_MAJOR_VERSION": sys.version_info[0]
     }
     self.make()
     self.check_cplusplus()
     self.add_optimize_flag()
     self.include_dirs.append(self.dbase)
     self.include_dirs = list(set(self.include_dirs))
     self.libraries = list(set(self.libraries))
     self.library_dirs = list(set(self.library_dirs))
     self.define_macros = list(set(self.define_macros))
     self.extra_link_args = list(set(self.extra_link_args))
def get_ext_modules():
    if "build_ext" not in sys.argv and "bdist_wheel" not in sys.argv:
        # this isn't a binary build, so we dont need to cythonize the source
        return None

    # cython compiles all the .py files to .so objects that are included in the .whl
    # this should ONLY be run with bdist_wheel and NEVER sdist

    Options.docstrings = False
    Options.fast_fail = True
    Options.warning_errors = True
    Options.error_on_unknown_names = True
    Options.error_on_uninitialized = True
    compiler_directives = {
        "binding": True,  # default in cython 3
        "language_level": "3",
        "warn.unreachable": False,
    }

    # we need to create an Extension for each source .py file in the project
    # so that cython will compile it to .so
    packages = find_packages()
    source_py_files = []
    for pkg in packages:
        for source_py in glob.glob(pkg.replace(".", os.sep) + os.sep + "*.py"):
            module = source_py[:-3]  # strip .py
            module = module.replace(os.sep, ".")
            extension = Extension(module, [source_py])
            source_py_files.append(extension)

    return cythonize(source_py_files, compiler_directives=compiler_directives)
Example #4
0
def get_basic_extensions():
    if MODE == 'info':
        try:
            from Cython.Distutils import Extension
        except ImportError:
            from distutils.core import Extension
        try:
            import numpy
        except ImportError:
            include_dirs = []
        else:
            include_dirs = [numpy.get_include()]
    else:
        from Cython.Distutils import Extension
        import numpy
        include_dirs = [numpy.get_include()]

    ext_modules = [
        Extension(
            name="cyarray.carray",
            sources=["cyarray/carray.pyx"],
            include_dirs=include_dirs,
        ),
    ]
    return ext_modules
Example #5
0
def create_cython_ext_modules(cython_modules, profile_cython=False,
                              debug=False):
    """
    Create :class:`~distutils.extension.Extension` objects from
    *cython_modules*.

    *cython_modules* must be a dict, as returned by :func:`parse_setup_cfg`.

    If *profile_cython* is true, Cython modules are compiled to support Python
    proiflers.

    Debug symbols are included if *debug* is true.
    """
    if profile_cython:
        from Cython.Distutils import Extension
    else:
        from distutils.extension import Extension

    ret = []
    for name, mod_data in cython_modules.items():
        kwargs = {'name': name}
        kwargs.update(mod_data)
        if profile_cython:
            cython_directives = kwargs.setdefault('cython_directives', {})
            cython_directives['profile'] = True
        if debug:
            for args_name in ('extra_compile_args', 'extra_link_args'):
                args = kwargs.setdefault(args_name, [])
                if '-g' not in args:
                    args.append('-g')
        ext = Extension(**kwargs)
        ret.append(ext)
    return ret
Example #6
0
def cython_module(*args, **kwargs):
    from Cython.Distutils import Extension
    sources = []
    sources.extend(kwargs.pop('sources', []))
    include_dirs = []
    include_dirs.extend(kwargs.pop('include_dirs', []))
    ext_package = os.path.extsep.join(args)
    ext_pth = os.path.sep.join(args) + os.extsep + "pyx"
    sources.insert(0, ext_pth)
    language = kwargs.pop('language', 'c').lower()
    extra_compile_args = ['-Wno-unused-function',
                          '-Wno-unneeded-internal-declaration',
                          '-O3',
                          '-fstrict-aliasing',
                          '-funroll-loops',
                          '-mtune=native']
    if language in CPPLANGS:
        extra_compile_args.extend(['-std=%s' % CPPVERSION,
                                   '-stdlib=libc++',
                                   '-Wno-sign-compare',
                                   '-Wno-unused-private-field'])
    return Extension(ext_package, sources,
        language=language,
        include_dirs=include_dirs,
        extra_compile_args=extra_compile_args)
Example #7
0
    def def_ext_modules(self):
        # Overloading compilers.
        os.environ["CXX"] = "c++"
        os.environ["CC"] = "gcc"
        BITPIT_ENABLE_MPI = 0
        include_libs = "-I" + self.PABLO_include_path
        include_libs = include_libs + " -I" + self.IO_include_path

        if ((not (not self.mpi_include_path)) and (ENABLE_MPI4PY)):
            BITPIT_ENABLE_MPI = 1
            include_libs = include_libs + " -I" + self.mpi_include_path
            os.environ["CXX"] = "mpic++"
            os.environ["CC"] = "mpicc"

        _extra_compile_args = [
            "-std=c++11", "-O3", "-fPIC", include_libs,
            "-DBITPIT_ENABLE_MPI=" + str(BITPIT_ENABLE_MPI)
        ]
        _extra_link_args = ["-fPIC"
                            ]  # Needed? We have already the same flag for
        # the compiler args above.
        _cython_directives = {
            "boundscheck": False,
            "wraparound": False,
            # http://stackoverflow.com/questions/23351813/how-to-declare-an-ndarray-in-cython-with-a-general-floating-point-type
            "nonecheck": False
        }
        _language = "c++"
        _extra_objects = ["libbitpit_MPI.a" if (BITPIT_ENABLE_MPI) \
                                               else "libbitpit.a"]

        src_dir = os.path.dirname(self.IO_include_path.rstrip("/"))
        common_dir = src_dir + "/common/"
        operators_dir = src_dir + "/operators/"
        containers_dir = src_dir + "/containers/"
        _include_dirs = [
            ".", self.PABLO_include_path, self.IO_include_path, common_dir,
            operators_dir, containers_dir,
            numpy_get_include()
        ]

        # Cython compile time environment.
        _cc_time_env = {"BITPIT_ENABLE_MPI": BITPIT_ENABLE_MPI}

        ext_modules = [
            Extension(
                os.path.splitext(self.extensions_source)[0],
                [self.extensions_source],
                extra_compile_args=_extra_compile_args,
                extra_link_args=_extra_link_args,
                cython_directives=_cython_directives,
                language=_language,
                extra_objects=_extra_objects,
                include_dirs=_include_dirs,
                cython_compile_time_env=_cc_time_env,
            )
        ]
        #return cythonize(ext_modules)
        return ext_modules
Example #8
0
def get_openmp_flags():
    """Returns any OpenMP related flags if OpenMP is avaiable on the system.
    """
    omp_compile_flags, omp_link_flags = _get_openmp_flags()

    from textwrap import dedent
    try:
        from Cython.Distutils import Extension
        from pyximport import pyxbuild
    except ImportError:
        print("Unable to import Cython, disabling OpenMP for now.")
        return [], [], False

    from distutils.errors import CompileError, LinkError
    import shutil
    import tempfile
    test_code = dedent("""
    from cython.parallel import parallel, prange, threadid
    cimport openmp
    def n_threads():
        with nogil, parallel():
            openmp.omp_get_num_threads()
    """)
    tmp_dir = tempfile.mkdtemp()
    fname = os.path.join(tmp_dir, 'check_omp.pyx')
    with open(fname, 'w') as fp:
        fp.write(test_code)
    extension = Extension(
        name='check_omp',
        sources=[fname],
        include_dirs=base_includes,
        extra_compile_args=omp_compile_flags,
        extra_link_args=omp_link_flags,
    )
    has_omp = True
    try:
        pyxbuild.pyx_to_dll(fname, extension, pyxbuild_dir=tmp_dir)
        print("-" * 70)
        print("Using OpenMP.")
        print("-" * 70)
    except CompileError:
        print("*" * 70)
        print("Unable to compile OpenMP code. Not using OpenMP.")
        print("*" * 70)
        has_omp = False
    except LinkError:
        print("*" * 70)
        print("Unable to link OpenMP code. Not using OpenMP.")
        print("*" * 70)
        has_omp = False
    finally:
        shutil.rmtree(tmp_dir)

    if has_omp:
        return omp_compile_flags, omp_link_flags, True
    else:
        return [], [], False
Example #9
0
def make_cy_ext(filename, inc_dirs=inc_dirs, lib_dirs=lib_dirs, libs=libs, global_compile_args=global_compile_args, debug_build=debug_build):
	modname = filename.replace('.pyx', '').replace('/', '.')
	if not have_cython:
		filename = '%s.c' % filename[:-4]
	return Extension(name=modname, sources=[filename], 
					 include_dirs=inc_dirs, library_dirs=lib_dirs, libraries=libs,
					 extra_compile_args=global_compile_args + ['-fPIC'],
					 extra_link_args=global_compile_args + ['-fPIC'],
					 pyrex_gdb=debug_build,
					 cython_directives={'embedsignature': True})
Example #10
0
    def run(self):
        if self.cythonize:
            # Move py files to ext_modules except __init__.py
            if not self.distribution.ext_modules:
                self.distribution.ext_modules = []
            for (pkg, mod, pth) in build_py.find_all_modules(self):
                if self.is_to_cythonize(pkg, mod):
                    self.distribution.ext_modules.append(
                        Extension(".".join([pkg, mod]), [pth],
                                  cython_c_in_temp=True))

        return build_py.run(self)
Example #11
0
def get_parallel_extensions():
    if not HAVE_MPI:
        return []

    if MODE == 'info':
        from distutils.core import Extension
        include_dirs = []
        mpi_inc_dirs, mpi_compile_args, mpi_link_args = [], [], []
        zoltan_include_dirs, zoltan_library_dirs = [], []
    else:
        from Cython.Distutils import Extension
        import numpy
        include_dirs = [numpy.get_include()]
        mpi_inc_dirs, mpi_compile_args, mpi_link_args = get_mpi_flags()
        zoltan_include_dirs, zoltan_library_dirs = get_zoltan_args()

    # We should check again here as HAVE_MPI may be set to False when we try to
    # get the MPI flags and are not successful.
    if not HAVE_MPI:
        return []

    include_dirs += base_includes

    MPI4PY_V2 = False if mpi4py.__version__.startswith('1.') else True
    cython_compile_time_env = {'MPI4PY_V2': MPI4PY_V2}

    zoltan_lib = 'zoltan'
    if 'USE_TRILINOS' in CONFIG_OPTS:
        zoltan_lib = 'trilinos_zoltan'
    elif os.environ.get('USE_TRILINOS', None) is not None:
        zoltan_lib = 'trilinos_zoltan'

    parallel_modules = [
        Extension(
            name="pysph.parallel.parallel_manager",
            sources=["pysph/parallel/parallel_manager.pyx"],
            depends=get_deps(
                "pysph/base/point", "pysph/base/particle_array",
                "pysph/base/nnps_base"
            ),
            include_dirs=include_dirs + mpi_inc_dirs + zoltan_include_dirs,
            library_dirs=zoltan_library_dirs,
            libraries=[zoltan_lib, 'mpi'],
            extra_link_args=mpi_link_args,
            extra_compile_args=mpi_compile_args + extra_compile_args,
            cython_compile_time_env=cython_compile_time_env,
            language="c++",
            define_macros=MACROS,
        ),
    ]
    return parallel_modules
 def run(self):
     if self.cythonize:
         # Move py files to ext_modules except __init__.py
         if not self.distribution.ext_modules:
             self.distribution.ext_modules = []
         for (pkg, mod, pth) in build_py.find_all_modules(self):
             if self.is_to_cythonize(pkg, mod):
                 self.distribution.ext_modules.append(
                     Extension(
                         ".".join([pkg, mod]),
                         [pth],
                         cython_c_in_temp=True,
                         # Ensure cython compiles with a relevent language mode setting
                         cython_directives={
                             'language_level': sys.version[0]
                         }))
     return build_py.run(self)
Example #13
0
 def verletCython4(self, nStr, mStr, xyStr, vStr):
     global Tn, T
     init = sum([list(map(float, xyStr)),
                 list(map(float, vStr))], [])
     m = list(map(float, mStr))
     n = int(nStr)
     G = 6.674e-11
     t = np.linspace(0, T, Tn)
     dt = T / Tn
     x = np.zeros(n * len(t))
     y = np.zeros(n * len(t))
     for i in range(n):
         x[i] = init[i * 2]
         y[i] = init[i * 2 + 1]
     vx = np.zeros(n * len(t))
     vy = np.zeros(n * len(t))
     for i in range(n):
         vx[i] = init[i * 2 + 2 * n]
         vy[i] = init[i * 2 + 1 + 2 * n]
     m1 = np.array(m)
     axm = np.zeros(n * len(t))
     aym = np.zeros(n * len(t))
     import pyximport
     pyximport.install(setup_args={'include_dirs': np.get_include(),
                                   'ext_modules': [Extension("solver_cython4", ["solver_cython4.pyx"],
                                                             extra_compile_args=["-O3", "-fopenmp"],
                                                             extra_link_args=["-fopenmp"])]})
     import solver_cython4
     start_time = time.clock()
     result = solver_cython4.solver(n, G, dt, m1, t, x, y, vx, vy, axm, aym)
     time1 = time.clock() - start_time
     # # x
     # print(result[0])
     # # y
     # print(result[1])
     # # vx
     # print(result[2])
     # # vy
     # print(result[3])
     # # axm
     # print(result[4])
     # # aym
     # print(result[5])
     # self.countError(nStr, mStr, xyStr, vStr, result[0], result[1], n)
     return result[0], result[1], n, time1
Example #14
0
def extensions():
    __builtins__.__NUMPY_SETUP__ = False
    from Cython.Distutils import Extension
    import numpy as np
    extra_compile_args = ["-O3"]
    extra_link_args = []
    if sys.platform == "darwin":
        extra_compile_args.append("-mmacosx-version-min=10.9")
        extra_compile_args.append('-stdlib=libc++')
        extra_link_args.append('-stdlib=libc++')
    return [
        Extension('taylor_dtw.custom_dtw', ["taylor_dtw/custom_dtw.pyx"],
                  cython_directives={'language_level': sys.version_info[0]},
                  extra_compile_args=extra_compile_args,
                  extra_link_args=extra_link_args,
                  include_dirs=[np.get_include()],
                  language="c++")
    ]
Example #15
0
project_dir = os.path.dirname(os.path.abspath(__file__))
ctp_dir = os.path.join(project_dir, "rqctp")
lib_dir = os.path.join(project_dir, "ctp")

for name in os.listdir(ctp_dir):
    if name.endswith(".so") or name.endswith(".cpp"):
        os.remove(os.path.join(ctp_dir, name))

for name in os.listdir(lib_dir):
    if name.endswith(".so") or name.endswith(".h"):
        shutil.copy(os.path.join(lib_dir, name), os.path.join(ctp_dir, name))

setup(name="rqctp",
      version="0.0.1",
      ext_modules=cythonize(module_list=[
          Extension(
              name="rqctp.TraderApi",
              sources=["rqctp/TraderApi.pyx"],
              libraries=["thosttraderapi_se"],
              language="c++",
              library_dirs=["rqctp/"],
              extra_link_args=['-Wl,-rpath,$ORIGIN'],
          )
      ],
                            compiler_directives={
                                "language_level": 3,
                                "binding": True
                            }),
      requires=["Cython"])
Example #16
0
from setuptools import setup

have_cython = False
try:
    from Cython.Distutils import build_ext, Extension
    have_cython = True

except ImportError:
    from setuptools.command.build_ext import build_ext
    from setuptools.extension import Extension

if have_cython:
    packer = Extension(
        "erlpack._packer",
        cython_cplus=True,
        extra_compile_args=['-O3'],
        sources=["py/erlpack/_packer.pyx"]
    )
    unpacker = Extension(
        "erlpack._unpacker",
        cython_cplus=True,
        extra_compile_args=['-O3'],
        sources=["py/erlpack/_unpacker.pyx"]
    )
else:
    packer = Extension('erlpack._packer', sources=[
                       'py/erlpack/_packer.cpp'], extra_compile_args=['-O3'])
    unpacker = Extension('erlpack._unpacker', sources=[
                         'py/erlpack/_unpacker.cpp'], extra_compile_args=['-O3'])

ext_modules = [packer, unpacker]
Example #17
0
    platforms=['Any'],
    classifiers=classifiers,
    url='http://github.com/fish2000/halogen',
    packages=find_packages(),
    package_dir={
        'haldol': 'haldol',
        'halogen': 'halogen'
    },
    package_data=dict(),
    test_suite='nose.collector',
    ext_modules=cythonize(
        [  # type: ignore
            Extension(
                'halogen.api',  # type: ignore
                api_extension_sources + haldol_sources,
                language="c++",
                include_dirs=[d for d in include_dirs if os.path.isdir(d)],
                define_macros=macros.to_list(),
                extra_link_args=['-lHalide'],
                extra_compile_args=[
                    '-Wno-unused-function',
                    '-Wno-unneeded-internal-declaration', '-O3',
                    '-fstrict-aliasing', '-funroll-loops', '-mtune=native',
                    '-std=c++17', '-stdlib=libc++'
                ])
        ],
        nthreads=cpu_count(),
        compiler_directives=dict(language_level=2,
                                 infer_types=True,
                                 embedsignature=True)))
Example #18
0
    def def_ext_modules(self):
        # Define \"Extension\" being cythonized.
        # Overloading compilers.
        os.environ["CXX"] = "c++"
        os.environ["CC"] = "gcc"
        BITPIT_ENABLE_MPI = 0
        include_paths = [
            self.bitpit_path + "/include/bitpit/",
            self.madeleine_path + "../../src/"
        ]

        mpi_lib = ""
        if ((not (not self.mpi_include_path)) and (ENABLE_MPI4PY)):
            BITPIT_ENABLE_MPI = 1
            include_paths.append(self.mpi_include_path)
            os.environ["CXX"] = "mpic++"
            os.environ["CC"] = "mpicc"
            mpi_lib = "/usr/local/openmpi-1.10.5_intel/lib/libmpi.so"
            mpi_lib = "/usr/lib64/openmpi-1.10/lib/libmpi.so"

        _extra_compile_args = [
            "-std=c++11",
            "-g",
            "-O0",
            "-fPIC",
            #include_paths,
            "-DBITPIT_ENABLE_MPI=" + str(BITPIT_ENABLE_MPI)
        ]
        _extra_link_args = ["-fPIC"
                            ]  # Needed? We have already the same flag for
        # the compiler args above.
        _cython_directives = {
            "boundscheck": False,
            "wraparound": False,
            # http://stackoverflow.com/questions/23351813/how-to-declare-an-ndarray-in-cython-with-a-general-floating-point-type
            "nonecheck": False
        }
        _language = "c++"
        bitpit_lib = self.bitpit_path + "/lib/"
        if (BITPIT_ENABLE_MPI):
            bitpit_lib = bitpit_lib + "libbitpit_MPI_D.so"
        else:
            bitpit_lib = bitpit_lib + "libbitpit_D.so"
        madeleine_lib = self.madeleine_path + "libmadeleine.so"
        _extra_objects = [mpi_lib, bitpit_lib, madeleine_lib, "-lxml2"]

        ##FINO QUI!
        #print(os.path.dirname(self.bitpit_include_path))
        #piercedVector_subdir = os.path.dirname(self.bitpit_include_path) + "/containers/"
        _include_dirs = [".", numpy_get_include()]
        _include_dirs.extend(include_paths)

        # Cython compile time environment.
        _cc_time_env = {"BITPIT_ENABLE_MPI": BITPIT_ENABLE_MPI}

        ext_modules = [
            Extension(
                os.path.splitext(self.extensions_source)[0],
                [self.extensions_source],
                extra_compile_args=_extra_compile_args,
                extra_link_args=_extra_link_args,
                cython_directives=_cython_directives,
                language=_language,
                extra_objects=_extra_objects,
                include_dirs=_include_dirs,
                cython_compile_time_env=_cc_time_env,
            )
        ]
        return cythonize(ext_modules, gdb_debug=True)
Example #19
0
        import pytest
        errno = pytest.main(self.test_args)
        sys.exit(errno)


with open('README.rst') as f:
    long_description = f.read()

setup(
    name="dmft-learn",
    description="Educative code on DMFT",
    long_description=long_description,
    version=dmft.__version__,
    packages=find_packages(),
    author="Óscar Nájera",
    author_email='*****@*****.**',
    license="GNU General Public License v3 (GPLv3)",
    install_requires=['numpy', 'scipy', 'matplotlib', 'slaveparticles'],
    setup_requires=['Sphinx', 'cython'],
    tests_require=['pytest', 'pytest-cov'],
    cmdclass={
        'test': PyTest,
        'build_ext': build_ext
    },
    ext_modules=[
        Extension('hffast', ['dmft/hirschfye_cy.pyx'],
                  include_dirs=[np.get_include()],
                  libraries=['blas', 'gsl']),
    ],
)
Example #20
0
from distutils.core import setup
from Cython.Build import cythonize

#from distutils.extension import Extension
#from Cython.Distutils import build_ext
from Cython.Distutils import build_ext, Extension
import numpy as np

ext_modules = [
    Extension(
        name="bedsim.cython2.cconstraints",
        sources=[
            "bedsim/cython2/cconstraints.pyx", "bedsim/cython2/constraints.c"
        ],
        # extra_objects=["fc.o"],  # if you compile fc.cpp separately
        include_dirs=[np.get_include()
                      ],  # .../site-packages/numpy/core/include
        language="c",
        extra_compile_args="-O3 -Wall".split(),
        # libraries=
        # extra_compile_args = "...".split(),
        # extra_link_args = "...".split()
    ),
    Extension(
        name="bedsim.cython2.ccsht",
        sources=["bedsim/cython2/ccsht.pyx", "bedsim/cython2/csht.c"],
        include_dirs=[np.get_include()
                      ],  # .../site-packages/numpy/core/include
        language="c",
        extra_compile_args="-O3 -Wall".split(),
    ),
    Extension(
Example #21
0
File: setup.py Project: jlazar17/dm
from distutils.core import setup
from Cython.Distutils import Extension
from Cython.Distutils import build_ext
import cython_gsl

setup(include_dirs=[cython_gsl.get_include()],
      cmdclass={'build_ext': build_ext},
      ext_modules=[
          Extension("gslneuosc", ["src/gslneuosc.pyx"],
                    libraries=cython_gsl.get_libraries(),
                    library_dirs=[cython_gsl.get_library_dir()],
                    include_dirs=[cython_gsl.get_cython_include_dir()])
      ])
Example #22
0
setup(
    name="dmft-learn",
    description="Educative code on DMFT",
    long_description=long_description,
    version=dmft.__version__,
    packages=find_packages(),
    author="Óscar Nájera",
    author_email='*****@*****.**',
    license="GNU General Public License v3 (GPLv3)",
    install_requires=[
        'numpy', 'scipy', 'matplotlib', 'slaveparticles', 'joblib', 'pandas',
        'numba', 'h5py', 'mpi4py'
    ],
    setup_requires=['sphinx', 'cython', 'pytest-runner'],
    tests_require=['pytest-cov', 'pytest'],  # Somehow this order is relevant
    cmdclass={'build_ext': build_ext},
    ext_modules=[
        Extension('dmft.hffast', ['dmft/hirschfye_cy.pyx', 'dmft/hfc.cpp'],
                  include_dirs=[np.get_include()],
                  language="c++",
                  extra_compile_args=["-std=c++11"],
                  libraries=['gsl', 'openblas']),
    ],
    classifiers=[
        "Intended Audience :: Developers",
        "Intended Audience :: Science/Research",
        "Programming Language :: Python",
        "Topic :: Scientific/Engineering",
        "Topic :: Software Development",
    ])
Example #23
0
                  "(compile/link inplace)"

    # Override to keep only the stats extension.
    def finalize_options(self):
        # Force inplace building for ease of importation
        self.inplace = True

        build_ext.finalize_options(self)


ext_modules = []
ext_modules.append(
    Extension(
        'challenge_scoring.tractanalysis.robust_streamlines_metrics',
        ['challenge_scoring/tractanalysis/robust_streamlines_metrics.pyx'],
        include_dirs=[
            numpy.get_include(),
            os.path.join(os.path.dirname(os.path.realpath(__file__)),
                         'challenge_scoring/c_src')
        ]))

dependencies = ['dipy', 'nibabel']

setup(
    name='tractometer',
    version='1.0.1',
    description='Scoring system used for the ISMRM 2015 Tractography Challenge',
    url='https://github.com/scilus/ismrm_2015_tractography_challenge_scoring',
    ext_modules=cythonize(ext_modules),
    author='The challenge team',
    author_email='*****@*****.**',
    packages=[
Example #24
0
])

config['include_dirs'] = [
    os.path.join(pylon_dir, 'Development', 'include'),
    os.path.join(pylon_cython_dir, "cython\\pxd\\cythoninterface"),
    os.path.join(pylon_cython_dir, "cython\\pxd\\cinterface\\baslerpylon."),
    os.path.join(pylon_cython_dir, "cython\c++"), python_dir, "cython\pxd",
    "cython\c++"
]
config['language'] = 'c++'
config['include_dirs'].append(numpy.get_include())

ext_modules = [
    Extension('pylonsample.sample_camera_event_handler',
              sources=[
                  "cython/pyx/pylonsample/sample_camera_event_handler.pyx",
                  "cython/c++/CSampleCameraEventHandler.cpp"
              ],
              **config),
    Extension(
        'pylonsample.sample_chunk_ts_image_event_handler',
        sources=[
            "cython/pyx/pylonsample/sample_chunk_ts_image_event_handler.pyx",
            "cython/c++/CSampleChunkTSImageEventHandler.cpp"
        ],
        **config),
    Extension('pylonsample.sample_image_event_handler',
              sources=[
                  "cython/pyx/pylonsample/sample_image_event_handler.pyx",
                  "cython/c++/CSampleImageEventHandler.cpp"
              ],
              **config),
Example #25
0
def get_basic_extensions():
    if MODE == 'info':
        try:
            from Cython.Distutils import Extension
        except ImportError:
            from distutils.core import Extension
        try:
            import numpy
        except ImportError:
            include_dirs = []
        else:
            include_dirs = [numpy.get_include()]
    else:
        from Cython.Distutils import Extension
        import numpy
        include_dirs = [numpy.get_include()]

    openmp_compile_args, openmp_link_args, openmp_env = get_openmp_flags()

    ext_modules = [
        Extension(
            name="pyzoltan.core.carray",
            sources=["pyzoltan/core/carray.pyx"],
            include_dirs=include_dirs,
            extra_compile_args=extra_compile_args,
            language="c++"
        ),

        Extension(
            name="pysph.base.particle_array",
            sources=["pysph/base/particle_array.pyx"],
            depends=get_deps("pyzoltan/core/carray"),
            include_dirs=include_dirs,
            extra_compile_args=extra_compile_args,
            language="c++"
        ),

        Extension(
            name="pysph.base.point",
            sources=["pysph/base/point.pyx"],
            extra_compile_args=extra_compile_args,
            include_dirs=include_dirs,
            language="c++"
        ),

        Extension(
            name="pysph.base.nnps_base",
            sources=["pysph/base/nnps_base.pyx"],
            depends=get_deps(
                "pyzoltan/core/carray", "pysph/base/point",
                "pysph/base/particle_array",
            ),
            include_dirs=include_dirs,
            extra_compile_args=extra_compile_args + openmp_compile_args,
            extra_link_args=openmp_link_args,
            cython_compile_time_env={'OPENMP': openmp_env},
            language="c++"
        ),


        Extension(
            name="pysph.base.linked_list_nnps",
            sources=["pysph/base/linked_list_nnps.pyx"],
            depends=get_deps(
                "pysph/base/nnps_base"
            ),
            include_dirs=include_dirs,
            extra_compile_args=extra_compile_args + openmp_compile_args,
            extra_link_args=openmp_link_args,
            cython_compile_time_env={'OPENMP': openmp_env},
            language="c++"
        ),

        Extension(
            name="pysph.base.box_sort_nnps",
            sources=["pysph/base/box_sort_nnps.pyx"],
            depends=get_deps(
                "pysph/base/nnps_base", "pysph/base/linked_list_nnps"
            ),
            include_dirs=include_dirs,
            extra_compile_args=extra_compile_args + openmp_compile_args,
            extra_link_args=openmp_link_args,
            cython_compile_time_env={'OPENMP': openmp_env},
            language="c++"
        ),

        Extension(
            name="pysph.base.spatial_hash_nnps",
            sources=["pysph/base/spatial_hash_nnps.pyx"],
            depends=get_deps(
                "pysph/base/nnps_base"
            ),
            include_dirs=include_dirs,
            extra_compile_args=extra_compile_args + openmp_compile_args,
            extra_link_args=openmp_link_args,
            cython_compile_time_env={'OPENMP': openmp_env},
            language="c++"
        ),

        Extension(
            name="pysph.base.cell_indexing_nnps",
            sources=["pysph/base/cell_indexing_nnps.pyx"],
            depends=get_deps(
                "pysph/base/nnps_base"
            ),
            include_dirs=include_dirs,
            extra_compile_args=extra_compile_args + openmp_compile_args,
            extra_link_args=openmp_link_args,
            cython_compile_time_env={'OPENMP': openmp_env},
            language="c++"
        ),


        Extension(
            name="pysph.base.z_order_nnps",
            sources=["pysph/base/z_order_nnps.pyx"],
            depends=get_deps(
                "pysph/base/nnps_base"
            ),
            include_dirs=include_dirs,
            extra_compile_args=extra_compile_args + openmp_compile_args,
            extra_link_args=openmp_link_args,
            cython_compile_time_env={'OPENMP': openmp_env},
            language="c++"
        ),

        Extension(
            name="pysph.base.stratified_hash_nnps",
            sources=["pysph/base/stratified_hash_nnps.pyx"],
            depends=get_deps(
                "pysph/base/nnps_base"
            ),
            include_dirs=include_dirs,
            extra_compile_args=extra_compile_args + openmp_compile_args,
            extra_link_args=openmp_link_args,
            cython_compile_time_env={'OPENMP': openmp_env},
            language="c++"
        ),

        Extension(
            name="pysph.base.stratified_sfc_nnps",
            sources=["pysph/base/stratified_sfc_nnps.pyx"],
            depends=get_deps(
                "pysph/base/nnps_base", "pysph/base/z_order_nnps"
            ),
            include_dirs=include_dirs,
            extra_compile_args=extra_compile_args + openmp_compile_args,
            extra_link_args=openmp_link_args,
            cython_compile_time_env={'OPENMP': openmp_env},
            language="c++"
        ),

        Extension(
            name="pysph.base.octree",
            sources=["pysph/base/octree.pyx"],
            depends=get_deps(
                "pysph/base/nnps_base"
            ),
            include_dirs=include_dirs,
            extra_compile_args=extra_compile_args + openmp_compile_args,
            extra_link_args=openmp_link_args,
            cython_compile_time_env={'OPENMP': openmp_env},
            language="c++"
        ),

        Extension(
            name="pysph.base.octree_nnps",
            sources=["pysph/base/octree_nnps.pyx"],
            depends=get_deps(
                "pysph/base/nnps_base", "pysph/base/octree"
            ),
            include_dirs=include_dirs,
            extra_compile_args=extra_compile_args + openmp_compile_args,
            extra_link_args=openmp_link_args,
            cython_compile_time_env={'OPENMP': openmp_env},
            language="c++"
        ),

        # kernels used for tests
        Extension(
            name="pysph.base.c_kernels",
            sources=["pysph/base/c_kernels.pyx"],
            include_dirs=include_dirs,
            extra_compile_args=extra_compile_args,
            language="c++"
        ),

        # Eigen decomposition code
        Extension(
            name="pysph.base.linalg3",
            sources=["pysph/base/linalg3.pyx"],
            include_dirs=include_dirs,
            extra_compile_args=extra_compile_args,
            language="c++"
        ),
    ]

    if HAVE_OPENCL:
        ext_modules.extend((
            Extension(
                name="pysph.base.gpu_nnps_base",
                sources=["pysph/base/gpu_nnps_base.pyx"],
                depends=get_deps(
                    "pyzoltan/core/carray", "pysph/base/point",
                    "pysph/base/particle_array", "pysph/base/nnps_base"
                ),
                include_dirs=include_dirs,
                extra_compile_args=extra_compile_args + openmp_compile_args,
                extra_link_args=openmp_link_args,
                cython_compile_time_env={'OPENMP': openmp_env},
                language="c++"
            ),

            Extension(
                name="pysph.base.z_order_gpu_nnps",
                sources=["pysph/base/z_order_gpu_nnps.pyx"],
                depends=get_deps(
                    "pysph/base/nnps_base"
                ),
                include_dirs=include_dirs,
                extra_compile_args=extra_compile_args + openmp_compile_args,
                extra_link_args=openmp_link_args,
                cython_compile_time_env={'OPENMP': openmp_env},
                language="c++"
            ),

            Extension(
                name="pysph.base.stratified_sfc_gpu_nnps",
                sources=["pysph/base/stratified_sfc_gpu_nnps.pyx"],
                depends=get_deps(
                    "pysph/base/nnps_base"
                ),
                include_dirs=include_dirs,
                extra_compile_args=extra_compile_args + openmp_compile_args,
                extra_link_args=openmp_link_args,
                cython_compile_time_env={'OPENMP': openmp_env},
                language="c++"
            ))
        )

    return ext_modules
Example #26
0
def get_openmp_flags():
    """Returns any OpenMP related flags if OpenMP is avaiable on the system.
    """
    if sys.platform == 'win32':
        omp_compile_flags, omp_link_flags = ['/openmp'], []
    else:
        omp_compile_flags, omp_link_flags = ['-fopenmp'], ['-fopenmp']

    env_var = os.environ.get('USE_OPENMP', '')
    if env_var.lower() in ("0", 'false', 'n'):
        print("-"*70)
        print("OpenMP disabled by environment variable (USE_OPENMP).")
        return [], [], False

    from textwrap import dedent
    try:
        from Cython.Distutils import Extension
        from pyximport import pyxbuild
    except ImportError:
        print("Unable to import Cython, disabling OpenMP for now.")
        return [], [], False

    from distutils.errors import CompileError, LinkError
    import shutil
    import tempfile
    test_code = dedent("""
    from cython.parallel import parallel, prange, threadid
    cimport openmp
    def n_threads():
        with nogil, parallel():
            openmp.omp_get_num_threads()
    """)
    tmp_dir = tempfile.mkdtemp()
    fname = path.join(tmp_dir, 'check_omp.pyx')
    with open(fname, 'w') as fp:
        fp.write(test_code)
    extension = Extension(
        name='check_omp', sources=[fname],
        extra_compile_args=omp_compile_flags,
        extra_link_args=omp_link_flags,
    )
    has_omp = True
    try:
        pyxbuild.pyx_to_dll(fname, extension, pyxbuild_dir=tmp_dir)
        print("-"*70)
        print("Using OpenMP.")
        print("-"*70)
    except CompileError:
        print("*"*70)
        print("Unable to compile OpenMP code. Not using OpenMP.")
        print("*"*70)
        has_omp = False
    except LinkError:
        print("*"*70)
        print("Unable to link OpenMP code. Not using OpenMP.")
        print("*"*70)
        has_omp = False
    finally:
        shutil.rmtree(tmp_dir)

    if has_omp:
        return omp_compile_flags, omp_link_flags, True
    else:
        return [], [], False
Example #27
0
def get_omp_flags():
    """Returns openmp flags if OpenMP is available.

    Implementation based on https://bitbucket.org/pysph/pysph

    """
    omp_compile_flags, omp_link_flags = ['-fopenmp'], ['-fopenmp']

    env_var = os.environ.get('USE_OPENMP', '')
    if env_var.lower() in ['0', 'false', 'n']:
        print("-" * 70)
        print("OpenMP disabled. Enable using 'USE_OPENMP'")
        print("-" * 70)
        return [], [], False

    from textwrap import dedent
    try:
        from Cython.Distutils import Extension
        from pyximport import pyxbuild
    except ImportError:
        print("Unable to import Cython, disabling OpenMP for now.")
        return [], [], False
    from distutils.errors import CompileError, LinkError
    import shutil
    import tempfile
    test_code = dedent("""
    from cython.parallel import parallel, prange, threadid
    cimport openmp
    def n_threads():
        with nogil, parallel():
            openmp.omp_get_num_threads()
    """)
    tmp_dir = tempfile.mkdtemp()
    fname = path.join(tmp_dir, 'check_omp.pyx')
    with open(fname, 'w') as fp:
        fp.write(test_code)
    extension = Extension(
        name='check_omp',
        sources=[fname],
        extra_compile_args=omp_compile_flags,
        extra_link_args=omp_link_flags,
    )
    has_omp = True
    try:
        mod = pyxbuild.pyx_to_dll(fname, extension, pyxbuild_dir=tmp_dir)
        print("-" * 70)
        print("Using OpenMP.")
        print("-" * 70)
    except CompileError:
        print("*" * 70)
        print("Unable to compile OpenMP code. Not using OpenMP.")
        print("*" * 70)
        has_omp = False
    except LinkError:
        print("*" * 70)
        print("Unable to link OpenMP code. Not using OpenMP.")
        print("*" * 70)
        has_omp = False
    finally:
        shutil.rmtree(tmp_dir)

    if has_omp:
        return omp_compile_flags, omp_link_flags, True
    else:
        return [], [], False
Example #28
0
#from setuptools import setup, Extension
from distutils.core import setup
from numpy import get_include
from Cython.Distutils import Extension
from Cython.Distutils import build_ext

logicle_extension = Extension(
    'fcm.core._logicle',
    sources=[
        'fcm/core/logicle_ext/%s' % i
        for i in ['Logicle.cpp', 'my_logicle.cpp', 'my_logicle_wrapper.cpp']
    ],
    include_dirs=[get_include()])

munkres_extension = Extension(
    "fcm.alignment.munkres",
    ["fcm/alignment/munkres.pyx", "fcm/alignment/munkres_ext/Munkres.cpp"],
    include_dirs=[get_include(), 'fcm/alignment/munkres_ext/'],
    language='c++')
setup(
    name='fcm',
    version='0.9.5',
    url='http://code.google.com/p/py-fcm/',
    packages=[
        'fcm', 'fcm.core', 'fcm.graphics', 'fcm.gui', 'fcm.io',
        'fcm.statistics', 'fcm.alignment'
    ],
    package_data={'': ['data/*']},
    description='Python Flow Cytometry (FCM) Tools',
    author='Jacob Frelinger',
    author_email='*****@*****.**',
Example #29
0
from distutils.core import setup
from Cython.Build import cythonize
from Cython.Distutils import Extension
import os

os.environ['LDFLAGS'] = "-framework AVFoundation -framework CoreWLAN -framework AppKit"
os.environ['CFLAGS'] = "-mmacosx-version-min=10.7 -std=c++11 --stdlib=libc++"

setup(ext_modules=cythonize(Extension(
    'IAgoraRtcEngine',
    ['IAgoraRtcEngine_pyx.pyx'],
    libraries=['AgoraRtcEngineKit'],
    library_dirs=['./lib'],
    include_dirs=['./include']
)))
Example #30
0
# handle nersc-specific compiling options. This will have to be run with
# a UCS2 version of Python (the default in Ubuntu is UCS4, so a custom
# Python may have to be used.
if "--NERSC" in argv:
    argv.remove("--NERSC")
    extra_link_args = ["-Wl,--wrap=memcpy", "-Wl,-Bsymbolic-functions"]
    sources.append("memcpy.c")  # this prevents a GLIBC2.14 function

if platform == "darwin":
    # paths for homebrew gmp and gmpxx
    include_dirs.append("/usr/local/include")
    library_dirs.append("/usr/local/lib")
elif platform == "win32":
    extra_compile_args = ["-DSOPLEX_WITH_GMP", "/MT", "/EHsc"]

ext_modules = cythonize([Extension(
    "soplex", sources,
    include_dirs=include_dirs,
    libraries=["soplex", "gmp"],
    library_dirs=library_dirs,
    extra_compile_args=extra_compile_args,
    extra_link_args=extra_link_args,
    language="c++")])

setup(
    name="soplex",
    cmdclass={"build_ext": build_ext},
    ext_modules=ext_modules,
    version="0.0.5"
)
Example #31
0
if sys.platform == 'win32':
    build_options = fake_detect_pylon_windows()
elif sys.platform == 'darwin':
    build_options = fake_detect_pylon_osx()
else:
    build_options = detect_pylon()

# Set build language
build_options['language'] = 'c++'

# Add numpy build options
build_options['include_dirs'].append(numpy.get_include())

pypylon_extensions = [
    Extension('pypylon.cython.version', [
        'cython/version.pyx',
    ], **build_options),
    Extension('pypylon.cython.factory', [
        'cython/factory.pyx',
    ], **build_options),
]

setup(
    name='pypylon',
    license="custom",
    description="Cython module to provide access to Pylon's SDK.",
    version='0.0.1',
    author="Matthias Blaicher",
    author_email="*****@*****.**",
    cmdclass={'build_ext': build_ext},
    ext_modules=pypylon_extensions,