コード例 #1
0
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
コード例 #2
0
ファイル: setup.py プロジェクト: kziolkowska/PyEMMA
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()

    exts = []

    mle_trev_given_pi_dense_module = \
        Extension('pyemma.msm.estimation.dense.mle_trev_given_pi',
                  sources=['pyemma/msm/estimation/dense/mle_trev_given_pi.pyx',
                           'pyemma/msm/estimation/dense/_mle_trev_given_pi.c'],
                  include_dirs=['pyemma/msm/estimation/dense'])

    mle_trev_given_pi_sparse_module = \
        Extension('pyemma.msm.estimation.sparse.mle_trev_given_pi',
                  sources=['pyemma/msm/estimation/sparse/mle_trev_given_pi.pyx',
                           'pyemma/msm/estimation/sparse/_mle_trev_given_pi.c'],
                  include_dirs=['pyemma/msm/estimation/dense'])

    mle_trev_sparse_module = \
        Extension('pyemma.msm.estimation.sparse.mle_trev',
                  sources=['pyemma/msm/estimation/sparse/mle_trev.pyx',
                           'pyemma/msm/estimation/sparse/_mle_trev.c'])

    exts += [mle_trev_given_pi_dense_module,
             mle_trev_given_pi_sparse_module,
             mle_trev_sparse_module]

#     kahan_sum = Extension('pyemma.coordinates.coordinate_transformation.exts.stable_sum',
#                           sources=['pyemma/coordinates/coordinate_transformation/exts/stable_sum.pyx'],
#                           extra_compile_args = ['-g'])
#     
#     update_mean = Extension('pyemma.coordinates.coordinate_transformation.exts.fmath_wrapper',
#                           sources=['pyemma/coordinates/coordinate_transformation/exts/fmath_wrapper.pyx'],)
# 
#     #exts += [kahan_sum]
#     exts += [update_mean]
    if USE_CYTHON: # if we have cython available now, cythonize module
        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
コード例 #3
0
ファイル: setup.py プロジェクト: ismaelresp/PyEMMA
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

    exts = []

    mle_trev_given_pi_dense_module = \
        Extension('pyemma.msm.estimation.dense.mle_trev_given_pi',
                  sources=['pyemma/msm/estimation/dense/mle_trev_given_pi.pyx',
                           'pyemma/msm/estimation/dense/_mle_trev_given_pi.c'],
                  include_dirs=['pyemma/msm/estimation/dense'])

    mle_trev_given_pi_sparse_module = \
        Extension('pyemma.msm.estimation.sparse.mle_trev_given_pi',
                  sources=['pyemma/msm/estimation/sparse/mle_trev_given_pi.pyx',
                           'pyemma/msm/estimation/sparse/_mle_trev_given_pi.c'],
                  include_dirs=['pyemma/msm/estimation/dense'])

    mle_trev_sparse_module = \
        Extension('pyemma.msm.estimation.sparse.mle_trev',
                  sources=['pyemma/msm/estimation/sparse/mle_trev.pyx',
                           'pyemma/msm/estimation/sparse/_mle_trev.c'])
    if sys.platform.startswith('win'):
        lib_prefix = 'lib'
    else:
        lib_prefix = ''
    regspatial_module = \
        Extension('pyemma.coordinates.clustering.regspatial',
                  sources = ['pyemma/coordinates/clustering/regspatial.c'],
                  include_dirs = [mdtraj.capi()['include_dir']],
                  libraries = [lib_prefix+'theobald'],
                  library_dirs = [mdtraj.capi()['lib_dir']])

    exts += [mle_trev_given_pi_dense_module,
             mle_trev_given_pi_sparse_module,
             mle_trev_sparse_module,
             regspatial_module]

    if USE_CYTHON: # if we have cython available now, cythonize module
        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