本文整理汇总了Python中sympy.core.Expr.__new__方法的典型用法代码示例。如果您正苦于以下问题:Python Expr.__new__方法的具体用法?Python Expr.__new__怎么用?Python Expr.__new__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.core.Expr
的用法示例。
在下文中一共展示了Expr.__new__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __new__
# 需要导入模块: from sympy.core import Expr [as 别名]
# 或者: from sympy.core.Expr import __new__ [as 别名]
def __new__(cls, label, shape=None, **kw_args):
from sympy import MatrixBase, NDimArray
if isinstance(label, string_types):
label = Symbol(label)
elif isinstance(label, Symbol):
pass
elif isinstance(label, (MatrixBase, NDimArray)):
return label
elif isinstance(label, Iterable):
return _sympify(label)
else:
label = _sympify(label)
if is_sequence(shape):
shape = Tuple(*shape)
elif shape is not None:
shape = Tuple(shape)
offset = kw_args.pop('offset', S.Zero)
strides = kw_args.pop('strides', None)
if shape is not None:
obj = Expr.__new__(cls, label, shape)
else:
obj = Expr.__new__(cls, label)
obj._shape = shape
obj._offset = offset
obj._strides = strides
obj._name = str(label)
return obj
示例2: __new__
# 需要导入模块: from sympy.core import Expr [as 别名]
# 或者: from sympy.core.Expr import __new__ [as 别名]
def __new__(cls, function, *symbols, **assumptions):
from sympy.integrals.integrals import _process_limits
# Any embedded piecewise functions need to be brought out to the
# top level so that integration can go into piecewise mode at the
# earliest possible moment.
function = piecewise_fold(sympify(function))
if function is S.NaN:
return S.NaN
if not symbols:
raise ValueError("Summation variables must be given")
limits, sign = _process_limits(*symbols)
# Only limits with lower and upper bounds are supported; the indefinite Sum
# is not supported
if any(len(l) != 3 or None in l for l in limits):
raise ValueError('Sum requires values for lower and upper bounds.')
obj = Expr.__new__(cls, **assumptions)
arglist = [sign*function]
arglist.extend(limits)
obj._args = tuple(arglist)
return obj
示例3: __new__
# 需要导入模块: from sympy.core import Expr [as 别名]
# 或者: from sympy.core.Expr import __new__ [as 别名]
def __new__(cls, label, range=None, **kw_args):
if isinstance(label, basestring):
label = Symbol(label, integer=True)
label, range = map(sympify, (label, range))
if not label.is_integer:
raise TypeError("Idx object requires an integer label")
elif is_sequence(range):
assert len(range) == 2, "Idx got range tuple with wrong length"
for bound in range:
if not (bound.is_integer or abs(bound) is S.Infinity):
raise TypeError("Idx object requires integer bounds")
args = label, Tuple(*range)
elif isinstance(range, Expr):
if not (range.is_integer or range is S.Infinity):
raise TypeError("Idx object requires an integer dimension")
args = label, Tuple(S.Zero, range-S.One)
elif range:
raise TypeError("range must be ordered iterable or integer sympy expression")
else:
args = label,
obj = Expr.__new__(cls, *args, **kw_args)
return obj
示例4: __new__
# 需要导入模块: from sympy.core import Expr [as 别名]
# 或者: from sympy.core.Expr import __new__ [as 别名]
def __new__(cls, label, range=None, **kw_args):
from sympy.utilities.misc import filldedent
if isinstance(label, basestring):
label = Symbol(label, integer=True)
label, range = map(sympify, (label, range))
if not label.is_integer:
raise TypeError("Idx object requires an integer label.")
elif is_sequence(range):
if len(range) != 2:
raise ValueError(filldedent("""
Idx range tuple must have length 2, but got %s""" % len(range)))
for bound in range:
if not (bound.is_integer or abs(bound) is S.Infinity):
raise TypeError("Idx object requires integer bounds.")
args = label, Tuple(*range)
elif isinstance(range, Expr):
if not (range.is_integer or range is S.Infinity):
raise TypeError("Idx object requires an integer dimension.")
args = label, Tuple(0, range - 1)
elif range:
raise TypeError(filldedent("""
The range must be an ordered iterable or
integer SymPy expression."""))
else:
args = label,
obj = Expr.__new__(cls, *args, **kw_args)
return obj
示例5: __new__
# 需要导入模块: from sympy.core import Expr [as 别名]
# 或者: from sympy.core.Expr import __new__ [as 别名]
def __new__(cls, e, z, z0, dir="+"):
e = sympify(e)
z = sympify(z)
z0 = sympify(z0)
obj = Expr.__new__(cls)
obj._args = (e, z, z0, dir)
return obj
示例6: __new__
# 需要导入模块: from sympy.core import Expr [as 别名]
# 或者: from sympy.core.Expr import __new__ [as 别名]
def __new__(cls, function, *symbols, **assumptions):
# Any embedded piecewise functions need to be brought out to the
# top level so that integration can go into piecewise mode at the
# earliest possible moment.
function = piecewise_fold(sympify(function))
if function is S.NaN:
return S.NaN
if symbols:
limits, sign = _process_limits(*symbols)
else:
# no symbols provided -- let's compute full anti-derivative
limits, sign = [Tuple(s) for s in function.free_symbols], 1
if len(limits) != 1:
raise ValueError("specify integration variables to integrate %s" % function)
while isinstance(function, Integral):
# denest the integrand
limits = list(function.limits) + limits
function = function.function
obj = Expr.__new__(cls, **assumptions)
arglist = [sign*function]
arglist.extend(limits)
obj._args = tuple(arglist)
obj.is_commutative = all(s.is_commutative for s in obj.free_symbols)
return obj
示例7: __new__
# 需要导入模块: from sympy.core import Expr [as 别名]
# 或者: from sympy.core.Expr import __new__ [as 别名]
def __new__(cls, name, abbrev, **assumptions):
obj = Expr.__new__(cls, **assumptions)
assert isinstance(name, str),`type(name)`
assert isinstance(abbrev, str),`type(abbrev)`
obj.name = name
obj.abbrev = abbrev
return obj
示例8: __new__
# 需要导入模块: from sympy.core import Expr [as 别名]
# 或者: from sympy.core.Expr import __new__ [as 别名]
def __new__(cls, term, *symbols, **assumptions):
term = sympify(term)
if term is S.NaN:
return S.NaN
if len(symbols) == 1:
symbol = symbols[0]
if isinstance(symbol, C.Equality):
k = symbol.lhs
a = symbol.rhs.start
n = symbol.rhs.end
elif is_sequence(symbol):
k, a, n = symbol
else:
raise ValueError("Invalid arguments")
k, a, n = map(sympify, (k, a, n))
else:
raise NotImplementedError
obj = Expr.__new__(cls, **assumptions)
obj._args = (term, Tuple(k, a, n))
return obj
示例9: __new__
# 需要导入模块: from sympy.core import Expr [as 别名]
# 或者: from sympy.core.Expr import __new__ [as 别名]
def __new__(cls, arg):
if hasattr(arg, 'adjoint'):
obj = arg.adjoint()
elif hasattr(arg, 'conjugate') and hasattr(arg, 'transpose'):
obj = arg.conjugate().transpose()
if obj is not None:
return obj
return Expr.__new__(cls, arg)
示例10: _new
# 需要导入模块: from sympy.core import Expr [as 别名]
# 或者: from sympy.core.Expr import __new__ [as 别名]
def _new(cls, poly, index):
"""Construct new ``RootOf`` object from raw data. """
obj = Expr.__new__(cls)
obj.poly = poly
obj.index = index
return obj
示例11: __new__
# 需要导入模块: from sympy.core import Expr [as 别名]
# 或者: from sympy.core.Expr import __new__ [as 别名]
def __new__(cls, label, shape=None, **kw_args):
if isinstance(label, string_types):
label = Symbol(label)
elif isinstance(label, Symbol):
pass
else:
raise TypeError("Base label should be a string or Symbol.")
if is_sequence(shape):
shape = Tuple(*shape)
else:
shape = sympify(shape)
if shape is not None:
obj = Expr.__new__(cls, label, shape, **kw_args)
else:
obj = Expr.__new__(cls, label, **kw_args)
obj._shape = shape
return obj
示例12: _new
# 需要导入模块: from sympy.core import Expr [as 别名]
# 或者: from sympy.core.Expr import __new__ [as 别名]
def _new(cls, poly, func, auto=True):
"""Construct new raw ``RootSum`` instance. """
obj = Expr.__new__(cls)
obj.poly = poly
obj.fun = func
obj.auto = auto
return obj
示例13: __new__
# 需要导入模块: from sympy.core import Expr [as 别名]
# 或者: from sympy.core.Expr import __new__ [as 别名]
def __new__(cls, name, n, m):
n, m = map(sympify, (n, m))
from sympy import MatrixBase
if isinstance(name, (MatrixBase,)):
if n.is_Integer and m.is_Integer:
return name[n, m]
name = sympify(name)
obj = Expr.__new__(cls, name, n, m)
return obj
示例14: __new__
# 需要导入模块: from sympy.core import Expr [as 别名]
# 或者: from sympy.core.Expr import __new__ [as 别名]
def __new__(cls, f, x=None):
if not isinstance(f, Poly):
f = Poly(f, x)
elif x is not None:
raise SymbolsError("Redundant symbols were given")
if f.is_multivariate:
raise ValueError('multivariate polynomial')
return Expr.__new__(cls, f)
示例15: __new__
# 需要导入模块: from sympy.core import Expr [as 别名]
# 或者: from sympy.core.Expr import __new__ [as 别名]
def __new__(cls, base, *args, **kw_args):
if not args: raise IndexException("Indexed needs at least one index")
if isinstance(base, (basestring, Symbol)):
base = IndexedBase(base)
elif not isinstance(base, IndexedBase):
raise TypeError("Indexed expects string, Symbol or IndexedBase as base")
# FIXME: 2.4 compatibility
args = map(_ensure_Idx, args)
# args = tuple([ a if isinstance(a, Idx) else Idx(a) for a in args ])
return Expr.__new__(cls, base, *args, **kw_args)