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


Python core.Expr类代码示例

本文整理汇总了Python中sympy.core.Expr的典型用法代码示例。如果您正苦于以下问题:Python Expr类的具体用法?Python Expr怎么用?Python Expr使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: __new__

    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
开发者ID:bjodah,项目名称:sympy,代码行数:31,代码来源:indexed.py

示例2: __new__

    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
开发者ID:MichaelMayorov,项目名称:sympy,代码行数:27,代码来源:summations.py

示例3: __new__

    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
开发者ID:101man,项目名称:sympy,代码行数:26,代码来源:indexed.py

示例4: __new__

    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
开发者ID:Acebulf,项目名称:sympy,代码行数:31,代码来源:indexed.py

示例5: __new__

 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
开发者ID:bibile,项目名称:sympy,代码行数:7,代码来源:limits.py

示例6: __new__

    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
开发者ID:manoj2378,项目名称:sympy,代码行数:31,代码来源:integrals.py

示例7: __new__

 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
开发者ID:Sumith1896,项目名称:sympy-polys,代码行数:7,代码来源:units.py

示例8: __new__

    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
开发者ID:101man,项目名称:sympy,代码行数:27,代码来源:products.py

示例9: __new__

 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)
开发者ID:Tkizzy,项目名称:PythonistaAppTemplate,代码行数:8,代码来源:dagger.py

示例10: _new

    def _new(cls, poly, index):
        """Construct new ``RootOf`` object from raw data. """
        obj = Expr.__new__(cls)

        obj.poly = poly
        obj.index = index

        return obj
开发者ID:AALEKH,项目名称:sympy,代码行数:8,代码来源:rootoftools.py

示例11: __new__

    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
开发者ID:A-turing-machine,项目名称:sympy,代码行数:18,代码来源:indexed.py

示例12: _new

    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
开发者ID:A-turing-machine,项目名称:sympy,代码行数:9,代码来源:rootoftools.py

示例13: __new__

 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
开发者ID:raoulb,项目名称:sympy,代码行数:9,代码来源:matexpr.py

示例14: __new__

    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)
开发者ID:Aang,项目名称:sympy,代码行数:10,代码来源:polyroots.py

示例15: __new__

 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)
开发者ID:bibile,项目名称:sympy,代码行数:10,代码来源:indexed.py


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