本文整理汇总了Python中sympy.utilities.lambdify.NUMPY_TRANSLATIONS类的典型用法代码示例。如果您正苦于以下问题:Python NUMPY_TRANSLATIONS类的具体用法?Python NUMPY_TRANSLATIONS怎么用?Python NUMPY_TRANSLATIONS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NUMPY_TRANSLATIONS类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_numpy_transl
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,代码行数:8,代码来源:test_lambdify.py
示例2: callback_factory
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,代码行数:46,代码来源:_sympy_Lambdify.py
示例3: test_lambdify_transl
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,代码行数:5,代码来源:test_numpy.py
示例4: test_lambdify_transl
def test_lambdify_transl():
from sympy.utilities.lambdify import NUMPY_TRANSLATIONS
for sym, mat in NUMPY_TRANSLATIONS.iteritems():
assert sym in sympy.functions.__dict__ or sym in ("Matrix", )
assert mat in numpy.__dict__
开发者ID:fperez,项目名称:sympy,代码行数:5,代码来源:test_numpy.py
示例5: vars
.. _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,代码行数:31,代码来源:nbvars.py
注:本文中的sympy.utilities.lambdify.NUMPY_TRANSLATIONS类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论