当前位置: 首页>>代码示例>>Python>>正文


Python NUMPY_TRANSLATIONS.items方法代码示例

本文整理汇总了Python中sympy.utilities.lambdify.NUMPY_TRANSLATIONS.items方法的典型用法代码示例。如果您正苦于以下问题:Python NUMPY_TRANSLATIONS.items方法的具体用法?Python NUMPY_TRANSLATIONS.items怎么用?Python NUMPY_TRANSLATIONS.items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sympy.utilities.lambdify.NUMPY_TRANSLATIONS的用法示例。


在下文中一共展示了NUMPY_TRANSLATIONS.items方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_numpy_transl

# 需要导入模块: from sympy.utilities.lambdify import NUMPY_TRANSLATIONS [as 别名]
# 或者: from sympy.utilities.lambdify.NUMPY_TRANSLATIONS import items [as 别名]
def test_numpy_transl():
    if not numpy:
        skip("numpy not installed.")

    from sympy.utilities.lambdify import NUMPY_TRANSLATIONS
    for sym, nump in NUMPY_TRANSLATIONS.items():
        assert sym in sympy.__dict__
        assert nump in numpy.__dict__
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:10,代码来源:test_lambdify.py

示例2: callback_factory

# 需要导入模块: from sympy.utilities.lambdify import NUMPY_TRANSLATIONS [as 别名]
# 或者: from sympy.utilities.lambdify.NUMPY_TRANSLATIONS import items [as 别名]
def callback_factory(args, expr, module, use_numba=False):
    if module == 'numpy':
        from sympy.utilities.lambdify import NUMPY_TRANSLATIONS as TRANSLATIONS
        from sympy.printing.lambdarepr import NumPyPrinter as Printer

        def lambdarepr(_x):
            return Printer().doprint(_x)
    else:
        from sympy.printing.lambdarepr import lambdarepr
        if module == 'mpmath':
            from sympy.utilities.lambdify import MPMATH_TRANSLATIONS as TRANSLATIONS
        elif module == 'sympy':
            TRANSLATIONS = {}
        else:
            raise NotImplementedError("Lambdify does not yet support %s" % module)

    mod = __import__(module)
    from sympy import IndexedBase, Symbol
    x = IndexedBase('x')
    indices = [Symbol('..., %d' % i) for i in range(len(args))]
    dummy_subs = dict(zip(args, [x[i] for i in indices]))
    dummified = expr.xreplace(dummy_subs)
    estr = lambdarepr(dummified)

    namespace = mod.__dict__.copy()

    # e.g. NumPyPrinter incomplete: https://github.com/sympy/sympy/issues/11023
    # we need to read translations from lambdify
    for k, v in TRANSLATIONS.items():
        namespace[k] = namespace[v]

    if module != 'mpmath':
        namespace['Abs'] = abs

    func = eval('lambda x: %s' % estr, namespace)
    if use_numba:
        from numba import njit
        func = njit(func)
    if module == 'numpy':
        def wrapper(x):
            return func(mod.asarray(x, dtype=mod.float64))
    else:
        wrapper = func
    wrapper.__doc__ = estr

    return wrapper
开发者ID:bjodah,项目名称:sym,代码行数:48,代码来源:_sympy_Lambdify.py

示例3: test_lambdify_transl

# 需要导入模块: from sympy.utilities.lambdify import NUMPY_TRANSLATIONS [as 别名]
# 或者: from sympy.utilities.lambdify.NUMPY_TRANSLATIONS import items [as 别名]
def test_lambdify_transl():
    from sympy.utilities.lambdify import NUMPY_TRANSLATIONS
    for sym, mat in NUMPY_TRANSLATIONS.items():
        assert sym in sympy.__dict__
        assert mat in numpy.__dict__
开发者ID:DVNSarma,项目名称:sympy,代码行数:7,代码来源:test_numpy.py

示例4: vars

# 需要导入模块: from sympy.utilities.lambdify import NUMPY_TRANSLATIONS [as 别名]
# 或者: from sympy.utilities.lambdify.NUMPY_TRANSLATIONS import items [as 别名]
.. _symengine: https://github.com/symengine/symengine
.. _numba: http://numba.pydata.org/
"""
import six
#import ast
import numpy as np
import sympy as sy
import numba as nb
from warnings import warn
from platform import system
from sympy.utilities.lambdify import NUMPY_TRANSLATIONS, NUMPY_DEFAULT


npvars = vars(np)
npvars.update(NUMPY_DEFAULT)
npvars.update({k: getattr(np, v) for k, v in NUMPY_TRANSLATIONS.items()})
if "linux" in system().lower():
    jitkwargs = dict(nopython=True, nogil=True, parallel=True)
    veckwargs = dict(nopython=True, target="parallel")
else:
    jitkwargs = dict(nopython=True, nogil=True, parallel=False, cache=True)
    veckwargs = dict(nopython=True, target="cpu")


def numbafy(fn, args, compiler="jit", **nbkws):
    """
    Compile a string, sympy expression or symengine expression using numba.

    Not all functions are supported by Python's numerical package (numpy). For
    difficult cases, valid Python code (as string) may be more suitable than
    symbolic expressions coming from sympy, symengine, etc. When compiling
开发者ID:tjduigna,项目名称:exa,代码行数:33,代码来源:nbvars.py


注:本文中的sympy.utilities.lambdify.NUMPY_TRANSLATIONS.items方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。