The following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don’t like. You can also save this page to your account.
Example 1
def run(count_path, out_path, smooth=0, cds=True, normalize=False, neg=1): counts = create_representation("Explicit", count_path, normalize=False) old_mat = counts.m index = counts.wi smooth = old_mat.sum() * smooth # getting marginal probs row_probs = old_mat.sum(1) + smooth col_probs = old_mat.sum(0) + smooth if cds: col_probs = np.power(col_probs, 0.75) row_probs = row_probs / row_probs.sum() col_probs = col_probs / col_probs.sum() # building PPMI matrix ppmi_mat = make_ppmi_mat(old_mat, row_probs, col_probs, smooth, neg=neg, normalize=normalize) import pyximport pyximport.install(setup_args={"include_dirs": np.get_include()}) from representations import sparse_io sparse_io.export_mat_eff(ppmi_mat.row, ppmi_mat.col, ppmi_mat.data, out_path + ".bin") util.write_pickle(index, out_path + "-index.pkl")
Example 2
def configuration(parent_package="", top_path=None): config = Configuration("metrics", parent_package, top_path) cblas_libs, blas_info = get_blas_info() if os.name == 'posix': cblas_libs.append('m') config.add_extension("_kernel_fast", sources=["_kernel_fast.c"], include_dirs=[os.path.join('..', 'src', 'cblas'), numpy.get_include(), blas_info.pop('include_dirs', [])], libraries=cblas_libs, extra_compile_args=blas_info.pop('extra_compile_args', []), **blas_info) config.add_subpackage('tests') return config
Example 3
def configuration(parent_package="", top_path=None): import os from numpy.distutils.misc_util import Configuration import numpy libraries = [] if os.name == 'posix': libraries.append('m') config = Configuration("utils", parent_package, top_path) config.add_extension("_ranking_svm", sources=["_ranking_svm.c"], include_dirs=[numpy.get_include()], libraries=libraries, extra_compile_args=["-O3"]) config.set_options(ignore_setup_xxx_py=True, assume_default_configuration=True, delegate_options_to_subpackages=True, quiet=True) return config
Example 4
def extensions(): from numpy import get_include from Cython.Build import cythonize ext_core = Extension( "pydpc.core", sources=["ext/core.pyx", "ext/_core.c"], include_dirs=[get_include()], extra_compile_args=["-O3", "-std=c99"]) exts = [ext_core] return cythonize(exts)
Example 5
def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration('decomposition', parent_package, top_path) extensions = [ Extension('modl.decomposition.dict_fact_fast', sources=['modl/decomposition/dict_fact_fast.pyx'], include_dirs=[numpy.get_include()], ), Extension('modl.decomposition.recsys_fast', sources=['modl/decomposition/recsys_fast.pyx'], include_dirs=[numpy.get_include()], ), ] config.ext_modules += extensions config.add_subpackage('tests') return config
Example 6
def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration('input_data', parent_package, top_path) extensions = [ Extension('modl.input_data.image_fast', sources=['modl/input_data/image_fast.pyx'], include_dirs=[numpy.get_include()] ), ] config.add_subpackage('tests') config.add_subpackage('fmri') config.ext_modules += extensions return config
Example 7
def include_dirs_hook(): if sys.version_info[0] >= 3: import builtins if hasattr(builtins, '__NUMPY_SETUP__'): del builtins.__NUMPY_SETUP__ import imp import numpy imp.reload(numpy) else: import __builtin__ if hasattr(__builtin__, '__NUMPY_SETUP__'): del __builtin__.__NUMPY_SETUP__ import numpy reload(numpy) ext = Extension('test', []) ext.include_dirs.append(numpy.get_include()) if not has_include_file( ext.include_dirs, os.path.join("numpy", "arrayobject.h")): warnings.warn( "The C headers for numpy could not be found. " "You may need to install the development package") return [numpy.get_include()]
Example 8
def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration('polylearn', parent_package, top_path) config.add_extension('loss_fast', sources=['loss_fast.cpp'], include_dirs=[numpy.get_include()]) config.add_extension('cd_direct_fast', sources=['cd_direct_fast.cpp'], include_dirs=[numpy.get_include()]) config.add_extension('cd_linear_fast', sources=['cd_linear_fast.cpp'], include_dirs=[numpy.get_include()]) config.add_extension('cd_lifted_fast', sources=['cd_lifted_fast.cpp'], include_dirs=[numpy.get_include()]) config.add_subpackage('tests') return config
Example 9
def __init__(self, mjpro_path): self.mjpro_path = mjpro_path self.extension = Extension( 'mujoco_py.cymj', sources=[join(self.CYMJ_DIR_PATH, "cymj.pyx")], include_dirs=[ self.CYMJ_DIR_PATH, join(mjpro_path, 'include'), np.get_include(), ], libraries=['mujoco150'], library_dirs=[join(mjpro_path, 'bin')], extra_compile_args=[ '-fopenmp', # needed for OpenMP '-w', # suppress numpy compilation warnings ], extra_link_args=['-fopenmp'], language='c')
Example 10
def get_include(): """ Return the directory that contains the NumPy \\*.h header files. Extension modules that need to compile against NumPy should use this function to locate the appropriate include directory. Notes ----- When using ``distutils``, for example in ``setup.py``. :: import numpy as np ... Extension('extension_name', ... include_dirs=[np.get_include()]) ... """ import cykdtree return os.path.dirname(cykdtree.__file__)
Example 11
def setup_package(): metadata = dict(name=spfeas_name, maintainer=maintainer, maintainer_email=maintainer_email, description=description, license=license_file, version=__version__, long_description=long_description, author=author_file, packages=get_packages(), package_data=get_package_data(), ext_modules=cythonize(get_pyx_list()), include_dirs=[np.get_include()], cmdclass=dict(build_ext=build_ext), zip_safe=False, download_url=git_url, install_requires=required_packages, entry_points=get_console_dict()) setup(**metadata)
Example 12
def configuration(parent_package="", top_path=None): cblas_libs, blas_info = get_blas_info() libraries = [] if os.name == 'posix': cblas_libs.append('m') libraries.append('m') config = Configuration("arima", parent_package, top_path) config.add_extension("_arima", sources=["_arima.pyx"], include_dirs=[numpy.get_include(), blas_info.pop('include_dirs', [])], libraries=libraries, extra_compile_args=blas_info.pop( 'extra_compile_args', []), **blas_info) config.add_subpackage('tests') return config
Example 13
def run(self): # Check numpy is installed before trying to find the location # of numpy headers try: import numpy except ImportError: raise ImportError('numpy need to be installed before GAMtools can be ' 'compiled. Try installing with "pip install numpy" ' 'before installing GAMtools.') self.include_dirs.append(numpy.get_include()) build_ext.run(self) # Utility function to read the README file. # Used for the long_description. It's nice, because now 1) we have a top level # README file and 2) it's easier to type in the README file than to put a raw # string in below ...
Example 14
def configuration(parent_package="", top_path=None): config = Configuration("decomposition", parent_package, top_path) libraries = [] if os.name == 'posix': libraries.append('m') config.add_extension("_online_lda", sources=["_online_lda.c"], include_dirs=[numpy.get_include()], libraries=libraries) config.add_extension('cdnmf_fast', sources=['cdnmf_fast.c'], include_dirs=[numpy.get_include()], libraries=libraries) config.add_subpackage("tests") return config
Example 15
def configuration(parent_package="", top_path=None): config = Configuration("manifold", parent_package, top_path) libraries = [] if os.name == 'posix': libraries.append('m') config.add_extension("_utils", sources=["_utils.c"], include_dirs=[numpy.get_include()], libraries=libraries, extra_compile_args=["-O3"]) cblas_libs, blas_info = get_blas_info() eca = blas_info.pop('extra_compile_args', []) eca.append("-O4") config.add_extension("_barnes_hut_tsne", libraries=cblas_libs, sources=["_barnes_hut_tsne.c"], include_dirs=[join('..', 'src', 'cblas'), numpy.get_include(), blas_info.pop('include_dirs', [])], extra_compile_args=eca, **blas_info) return config
Example 16
def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration('sparsetools', parent_package, top_path) config.add_extension('_traversal', sources=['_traversal.c'], include_dirs=[numpy.get_include()], #libraries=libraries ) config.add_extension('_graph_tools', sources=['_graph_tools.c'], include_dirs=[numpy.get_include()], #libraries=libraries ) return config
Example 17
def __getitem__(self, key): if key != 'build_ext': return super(LazyBuildExtCommandClass, self).__getitem__(key) from Cython.Distutils import build_ext as cython_build_ext import numpy # Cython_build_ext isn't a new-style class in Py2. class build_ext(cython_build_ext, object): """ Custom build_ext command that lazily adds numpy's include_dir to extensions. """ def build_extensions(self): """ Lazily append numpy's include directory to Extension includes. This is done here rather than at module scope because setup.py may be run before numpy has been installed, in which case importing numpy and calling `numpy.get_include()` will fail. """ numpy_incl = numpy.get_include() for ext in self.extensions: ext.include_dirs.append(numpy_incl) super(build_ext, self).build_extensions() return build_ext
Example 18
def run(self): # Make sure the compiled Cython files in the distribution are up-to-date from Cython.Build import cythonize cythonize(['polo.pyx'], include_dirs=[numpy.get_include()]) _sdist.run(self)
Example 19
def run(word_gen, index, window_size, out_file): context = [] pair_counts = Counter() for word in word_gen: context.append(index[word]) if len(context) > window_size * 2 + 1: context.pop(0) pair_counts = _process_context(context, pair_counts, window_size) import pyximport pyximport.install(setup_args={"include_dirs": np.get_include()}) from representations import sparse_io sparse_io.export_mat_from_dict(pair_counts, out_file)
Example 20
def load_matrix(f): if not f.endswith('.bin'): f += ".bin" import pyximport pyximport.install(setup_args={"include_dirs": np.get_include()}) from representations import sparse_io return sparse_io.retrieve_mat_as_coo(f).tocsr()
Example 21
def test_include_dirs(self): # As a sanity check, just test that get_include # includes something reasonable. Somewhat # related to ticket #1405. include_dirs = [np.get_include()] for path in include_dirs: assert_(isinstance(path, (str, unicode))) assert_(path != '')
Example 22
def get_include(): """ Return the directory that contains the NumPy \\*.h header files. Extension modules that need to compile against NumPy should use this function to locate the appropriate include directory. Notes ----- When using ``distutils``, for example in ``setup.py``. :: import numpy as np ... Extension('extension_name', ... include_dirs=[np.get_include()]) ... """ import numpy if numpy.show_config is None: # running from numpy source directory d = os.path.join(os.path.dirname(numpy.__file__), 'core', 'include') else: # using installed numpy core headers import numpy.core as core d = os.path.join(os.path.dirname(core.__file__), 'include') return d
Example 23
def get_numpy_include_dirs(): # numpy_include_dirs are set by numpy/core/setup.py, otherwise [] include_dirs = Configuration.numpy_include_dirs[:] if not include_dirs: import numpy include_dirs = [ numpy.get_include() ] # else running numpy/core/setup.py return include_dirs
Example 24
def finalize_options(self): super().finalize_options() import numpy import pybind11 self.include_dirs.extend([ numpy.get_include(), pybind11.get_include(user=True), pybind11.get_include(), ])
Example 25
def run(self): """Overridden method. Runs the build. Library directories and include directories are checked here, first. """ # Add the numpy include directory. self.include_dirs.insert(0, get_include()) # Call the base class method. build_ext.run(self)
Example 26
def finalize_options(self): _build_ext.finalize_options(self) # Prevent numpy from thinking it is still in its setup process: __builtins__.__NUMPY_SETUP__ = False import numpy self.include_dirs.append(numpy.get_include())
Example 27
def __getitem__(self, key): if key != 'build_ext': return super(LazyBuildExtCommandClass, self).__getitem__(key) from Cython.Distutils import build_ext as cython_build_ext import numpy # Cython_build_ext isn't a new-style class in Py2. class build_ext(cython_build_ext, object): """ Custom build_ext command that lazily adds numpy's include_dir to extensions. """ def build_extensions(self): """ Lazily append numpy's include directory to Extension includes. This is done here rather than at module scope because setup.py may be run before numpy has been installed, in which case importing numpy and calling `numpy.get_include()` will fail. """ numpy_incl = numpy.get_include() for ext in self.extensions: ext.include_dirs.append(numpy_incl) super(build_ext, self).build_extensions() return build_ext
Example 28
def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration("wrapper", parent_package, top_path) try: import build_info except ImportError: build_info = None if build_info is None: config.set_options(ignore_setup_xxx_py=True, assume_default_configuration=True, delegate_options_to_subpackages=True, quiet=True) return config from Cython.Build import cythonize import numpy cythonize(cython_path("_wrapper.pyx"), language="c++") # CMake outputs multiple include dirs separated by ";" # but the setup scripts needs it as list => split it config.add_extension( '_wrapper', sources=["_wrapper.cpp"], # Generated by cythonize include_dirs=[".", numpy.get_include(), build_info.BOLERO_INCLUDE_DIRS.split(";"), build_info.BL_LOADER_INCLUDE_DIRS.split(";"), build_info.LIB_MANAGER_INCLUDE_DIRS.split(";")], libraries=["bl_loader", "lib_manager"], library_dirs=[build_info.BL_LOADER_LIBRARY_DIRS.split(";"), build_info.LIB_MANAGER_LIBRARY_DIRS.split(";")], define_macros=[("NDEBUG",)], extra_compile_args=["-O3", "-Wno-unused-function", "-Wno-unused-but-set-variable",]) return config
Example 29
def ext_modules(): import numpy walks_ext = Extension('jwalk.walks', ['jwalk/src/walks.pyx'], include_dirs=[numpy.get_include()]) return [walks_ext]
Example 30
def test_include_dirs(self): # As a sanity check, just test that get_include # includes something reasonable. Somewhat # related to ticket #1405. include_dirs = [np.get_include()] for path in include_dirs: assert_(isinstance(path, (str, unicode))) assert_(path != '')
Example 31
def get_include(): """ Return the directory that contains the NumPy \\*.h header files. Extension modules that need to compile against NumPy should use this function to locate the appropriate include directory. Notes ----- When using ``distutils``, for example in ``setup.py``. :: import numpy as np ... Extension('extension_name', ... include_dirs=[np.get_include()]) ... """ import numpy if numpy.show_config is None: # running from numpy source directory d = os.path.join(os.path.dirname(numpy.__file__), 'core', 'include') else: # using installed numpy core headers import numpy.core as core d = os.path.join(os.path.dirname(core.__file__), 'include') return d
Example 32
def get_numpy_include_dirs(): # numpy_include_dirs are set by numpy/core/setup.py, otherwise [] include_dirs = Configuration.numpy_include_dirs[:] if not include_dirs: import numpy include_dirs = [ numpy.get_include() ] # else running numpy/core/setup.py return include_dirs
Example 33
def compile_(self): """Translate cython code to C code and compile it.""" from Cython import Build argv = copy.deepcopy(sys.argv) sys.argv = [sys.argv[0], 'build_ext', '--build-lib='+self.buildpath] exc_modules = [ distutils.extension.Extension( 'hydpy.cythons.autogen.'+self.cyname, [self.cyfilepath], extra_compile_args=['-O2'])] distutils.core.setup(ext_modules=Build.cythonize(exc_modules), include_dirs=[numpy.get_include()]) sys.argv = argv
Example 34
def finalize_options(self): try: import cython import numpy except ImportError: raise ImportError( """Could not import cython or numpy. Building yt from source requires cython and numpy to be installed. Please install these packages using the appropriate package manager for your python environment.""") if LooseVersion(cython.__version__) < LooseVersion('0.24'): raise RuntimeError( """Building yt from source requires Cython 0.24 or newer but Cython %s is installed. Please update Cython using the appropriate package manager for your python environment.""" % cython.__version__) if LooseVersion(numpy.__version__) < LooseVersion('1.10.4'): raise RuntimeError( """Building yt from source requires NumPy 1.10.4 or newer but NumPy %s is installed. Please update NumPy using the appropriate package manager for your python environment.""" % numpy.__version__) from Cython.Build import cythonize self.distribution.ext_modules[:] = cythonize( self.distribution.ext_modules) _build_ext.finalize_options(self) # Prevent numpy from thinking it is still in its setup process # see http://stackoverflow.com/a/21621493/1382869 if isinstance(__builtins__, dict): # sometimes this is a dict so we need to check for that # https://docs.python.org/3/library/builtins.html __builtins__["__NUMPY_SETUP__"] = False else: __builtins__.__NUMPY_SETUP__ = False self.include_dirs.append(numpy.get_include())
Example 35
def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration('randomkit', parent_package, top_path) libs = [] if sys.platform == 'win32': libs.append('Advapi32') extensions = [Extension('modl.utils.randomkit.random_fast', sources=['modl/utils/randomkit/random_fast.pyx', 'modl/utils/randomkit/randomkit.c', 'modl/utils/randomkit/distributions.c', ], language="c++", include_dirs=[numpy.get_include(), 'modl/utils/randomkit'], ), Extension('modl.utils.randomkit.sampler', sources=['modl/utils/randomkit/sampler.pyx'], language="c++", include_dirs=[numpy.get_include()] )] config.ext_modules += extensions config.add_subpackage('tests') return config
Example 36
def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration('math', parent_package, top_path) extensions = [Extension('modl.utils.math.enet', sources=['modl/utils/math/enet.pyx'], include_dirs=[numpy.get_include()], ), ] config.ext_modules += extensions config.add_subpackage('tests') return config
Example 37
def __str__(self): import pybind11 return pybind11.get_include(self.user)
Example 38
def __str__(self): import numpy as np return np.get_include()
Example 39
def extension_modules(): import numpy as np libraries, library_dirs = BuildFortranThenExt.get_library_dirs() extensions = [] for name, dependencies in FORTRAN_MODULES.items(): if name in ('types', 'status'): # No speedup. continue mod_name = 'bezier._{}_speedup'.format(name) path = SPEEDUP_FILENAME.format(name) if BuildFortranThenExt.USE_SHARED_LIBRARY: # Here we don't depend on object files since the functionality # is contained in the shared library. extra_objects = [] else: # NOTE: These may be treated as relative paths and replaced # before the extension is actually built. extra_objects = [ OBJECT_FILENAME.format(dependency) for dependency in dependencies ] # NOTE: Copy ``libraries`` and ``library_dirs`` so they # aren't shared (and mutable) between extensions. extension = setuptools.Extension( mod_name, [path], extra_objects=extra_objects, include_dirs=[ np.get_include(), os.path.join('src', 'bezier', 'include'), ], libraries=copy.deepcopy(libraries), library_dirs=copy.deepcopy(library_dirs), ) extensions.append(extension) return extensions
Example 40
def __str__(self): import pybind11 return pybind11.get_include(self.user)
Example 41
def __str__(self): import numpy as np return np.get_include() # As of Python 3.6, CCompiler has a `has_flag` method. # cf http://bugs.python.org/issue26689
Example 42
def finalize_options(self): global libnumpythia #global external_fastjet _build_ext.finalize_options(self) # Prevent numpy from thinking it is still in its setup process try: del builtins.__NUMPY_SETUP__ except AttributeError: pass import numpy libnumpythia.include_dirs.append(numpy.get_include())
Example 43
def get_include(): return os.path.join(sys.prefix, 'include')
Example 44
def get_numpy_include_dirs(): # numpy_include_dirs are set by numpy/core/setup.py, otherwise [] include_dirs = Configuration.numpy_include_dirs[:] if not include_dirs: import numpy include_dirs = [ numpy.get_include() ] # else running numpy/core/setup.py return include_dirs
Example 45
def finalize_options(self): _build_ext.finalize_options(self) # Prevent numpy from thinking it is still in its setup process: __builtins__.__NUMPY_SETUP__ = False import numpy self.include_dirs.append(numpy.get_include()) # # This can be loosen probably, though it's fine I think # min_cython_ver = '0.24.0' # try: # import Cython # ver = Cython.__version__ # _CYTHON_INSTALLED = ver >= LooseVersion(min_cython_ver) # except ImportError: # _CYTHON_INSTALLED = False # try: # if not _CYTHON_INSTALLED: # raise ImportError('No supported version of Cython installed.') # from Cython.Distutils import build_ext # cython = True # except ImportError: # cython = False # if cython: # ext = '.pyx' # cmdclass = {'build_ext': build_ext} # else: # ext = '.cpp' # cmdclass = {} # if not os.path.exists(join("pyworld", "pyworld" + ext)): # raise RuntimeError("Cython is required to generate C++ wrapper")
Example 46
def test_include_dirs(self): # As a sanity check, just test that get_include # includes something reasonable. Somewhat # related to ticket #1405. include_dirs = [np.get_include()] for path in include_dirs: assert_(isinstance(path, (str, unicode))) assert_(path != '')
Example 47
def get_include(): """ Return the directory that contains the NumPy \\*.h header files. Extension modules that need to compile against NumPy should use this function to locate the appropriate include directory. Notes ----- When using ``distutils``, for example in ``setup.py``. :: import numpy as np ... Extension('extension_name', ... include_dirs=[np.get_include()]) ... """ import numpy if numpy.show_config is None: # running from numpy source directory d = os.path.join(os.path.dirname(numpy.__file__), 'core', 'include') else: # using installed numpy core headers import numpy.core as core d = os.path.join(os.path.dirname(core.__file__), 'include') return d
Example 48
def get_numpy_include_dirs(): # numpy_include_dirs are set by numpy/core/setup.py, otherwise [] include_dirs = Configuration.numpy_include_dirs[:] if not include_dirs: import numpy include_dirs = [ numpy.get_include() ] # else running numpy/core/setup.py return include_dirs
Example 49
def configuration(parent_package='', top_path=None): from numpy.distutils.misc_util import Configuration config = Configuration('sdtw', parent_package, top_path) config.add_extension('soft_dtw_fast', sources=['soft_dtw_fast.c'], include_dirs=[numpy.get_include()]) config.add_subpackage('tests') return config
Example 50
def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() # cos_module_np = Extension('cos_module_np', # sources=['PcgComp/kernels/cos_module_np.c'], # include_dirs=[numpy.get_include()])