本文整理汇总了Python中sympy.Basic.__new__方法的典型用法代码示例。如果您正苦于以下问题:Python Basic.__new__方法的具体用法?Python Basic.__new__怎么用?Python Basic.__new__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sympy.Basic
的用法示例。
在下文中一共展示了Basic.__new__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __new__
# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import __new__ [as 别名]
def __new__(cls, dimension):
dimension = sympify(dimension)
r = cls.eval(dimension)
if isinstance(r, Basic):
return r
obj = Basic.__new__(cls, dimension, **{'commutative': False})
return obj
示例2: __new__
# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import __new__ [as 别名]
def __new__(cls, iterable=None, shape=None, **kwargs):
from sympy.utilities.iterables import flatten
shape, flat_list = cls._handle_ndarray_creation_inputs(iterable, shape, **kwargs)
shape = Tuple(*map(_sympify, shape))
loop_size = functools.reduce(lambda x,y: x*y, shape) if shape else 0
# Sparse array:
if isinstance(flat_list, (dict, Dict)):
sparse_array = Dict(flat_list)
else:
sparse_array = {}
for i, el in enumerate(flatten(flat_list)):
if el != 0:
sparse_array[i] = _sympify(el)
sparse_array = Dict(sparse_array)
self = Basic.__new__(cls, sparse_array, shape, **kwargs)
self._shape = shape
self._rank = len(shape)
self._loop_size = loop_size
self._sparse_array = sparse_array
return self
示例3: __new__
# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import __new__ [as 别名]
def __new__(cls, dimension):
dimension = sympify(dimension)
r = cls.eval(dimension)
if isinstance(r, Basic):
return r
obj = Basic.__new__(cls, dimension)
return obj
示例4: __new__
# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import __new__ [as 别名]
def __new__(cls, sym, dist):
sym = sympify(sym)
if isinstance(dist, SingleContinuousDistribution):
return SingleContinuousPSpace(sym, dist)
if isinstance(dist, SingleDiscreteDistribution):
return SingleDiscretePSpace(sym, dist)
return Basic.__new__(cls, sym, dist)
示例5: __new__
# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import __new__ [as 别名]
def __new__(cls, arg):
arg = sympify(arg)
r = cls.canonize(arg)
if isinstance(r, Basic):
return r
obj = Basic.__new__(cls, arg)
return obj
示例6: __new__
# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import __new__ [as 别名]
def __new__ (cls, arg, **options):
# print "Inverse(", arg, ")"
# print INVERTIBLE
if isinstance(arg, Inverse):
return arg.args[0]
if arg.is_Number:
return 1 / arg
arg_rank = expr_rank(arg)
if arg_rank == 1:
raise NotInvertibleError
if is_one(arg):
return arg
if is_zero(arg):
raise NotInvertibleError
# FIXME: Funky case trying to catch lower triangular or diagonal
# muls like T(P_0)*A*P_0
if arg in INVERTIBLE:
pass
elif isinstance(arg, TensorExpr) and not arg.has_inverse:
raise NotInvertibleError
elif isinstance(arg, Mul):
if arg.args[0] == S(-1):
return - Inverse(reduce(operator.mul, arg.args[1:]))
if not expr_invertible(arg):
raise NotInvertibleError
options['commutative'] = arg.is_commutative
return Basic.__new__(cls, arg, **options)
示例7: _new
# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import __new__ [as 别名]
def _new(cls, *args, **kwargs):
if len(args)==1 and isinstance(args[0], ImmutableMatrix):
return args[0]
rows, cols, mat = MatrixBase._handle_creation_inputs(*args, **kwargs)
shape = Tuple(rows, cols)
mat = Tuple(*mat)
return Basic.__new__(cls, shape, mat)
示例8: __new__
# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import __new__ [as 别名]
def __new__(cls, mat):
if not mat.is_Matrix:
raise TypeError("Input to Determinant, %s, not a matrix" % str(mat))
if not mat.is_square:
raise ShapeError("Det of a non-square matrix")
return Basic.__new__(cls, mat)
示例9: _new
# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import __new__ [as 别名]
def _new(cls, *args, **kwargs):
if len(args) == 1 and isinstance(args[0], ImmutableMatrix):
return args[0]
rows, cols, flat_list = MatrixBase._handle_creation_inputs(*args, **kwargs)
rows = Integer(rows)
cols = Integer(cols)
mat = Tuple(*flat_list)
return Basic.__new__(cls, rows, cols, mat)
示例10: __new__
# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import __new__ [as 别名]
def __new__(cls, mat):
if not isinstance(mat, Matrix):
mat = Matrix(mat)
data = Tuple(*mat.mat)
shape = Tuple(*sympify(mat.shape))
obj = Basic.__new__(cls, data, shape)
obj.mat = mat
return obj
示例11: __new__
# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import __new__ [as 别名]
def __new__(cls, *args):
# args should be a tuple - a variable length argument list
obj = Basic.__new__(cls, *args)
obj._circuit = Mul(*args)
obj._rules = generate_gate_rules(args)
obj._eq_ids = generate_equivalent_ids(args)
return obj
示例12: __new__
# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import __new__ [as 别名]
def __new__(cls, M):
if not isinstance(M, Matrix):
M = Matrix(M)
data = Tuple(*M._mat)
shape = Tuple(*sympify(M.shape))
obj = Basic.__new__(cls, data, shape)
obj._mat = M
return obj
示例13: __new__
# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import __new__ [as 别名]
def __new__(cls, pspace, symbol=None):
if symbol is None:
# Allow single arg, representing pspace == PSpace()
pspace, symbol = PSpace(), pspace
if not isinstance(symbol, Symbol):
raise TypeError("symbol should be of type Symbol")
if not isinstance(pspace, PSpace):
raise TypeError("pspace variable should be of type PSpace")
return Basic.__new__(cls, pspace, symbol)
示例14: __new__
# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import __new__ [as 别名]
def __new__(cls, num, denom=None):
obj = Basic.__new__(cls)
if denom is None:
if isinstance(num, str):
obj.p, obj.q = parse_rational(num)
else:
obj.p = num
obj.q = denom
return obj
示例15: test_expr_fns
# 需要导入模块: from sympy import Basic [as 别名]
# 或者: from sympy.Basic import __new__ [as 别名]
def test_expr_fns():
from sympy.strategies.rl import rebuild
from sympy import Add
x, y = map(Symbol, 'xy')
expr = x + y**3
e = bottom_up(lambda x: x + 1, expr_fns)(expr)
b = bottom_up(lambda x: Basic.__new__(Add, x, 1), basic_fns)(expr)
assert rebuild(b) == e