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


Python Basic.__new__方法代码示例

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


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

示例1: __new__

# 需要导入模块: from sympy.core import Basic [as 别名]
# 或者: from sympy.core.Basic import __new__ [as 别名]
 def __new__(cls, func, center=[0,0,0], direction=[0,0,1], **kwargs):
     center = Mat(center)
     direction = Mat(direction)
     if norm(direction) == 0:
         raise ValueError
     direction = normalize(direction)
     return Basic.__new__(cls, func, center, direction)
开发者ID:worldmaker18349276,项目名称:magicpy,代码行数:9,代码来源:euclid.py

示例2: __new__

# 需要导入模块: from sympy.core import Basic [as 别名]
# 或者: from sympy.core.Basic import __new__ [as 别名]
 def __new__(cls, e, z, z0, dir="+"):
     e = sympify(e)
     z = sympify(z)
     z0 = sympify(z0)
     obj = Basic.__new__(cls)
     obj._args = (e, z, z0, dir)
     return obj
开发者ID:gnulinooks,项目名称:sympy,代码行数:9,代码来源:limits.py

示例3: __new__

# 需要导入模块: from sympy.core import Basic [as 别名]
# 或者: from sympy.core.Basic import __new__ [as 别名]
    def __new__(cls, *args, **options):
        # (Try to) sympify args first
        newargs = []
        for ec in args:
            pair = ExprCondPair(*ec)
            cond = pair.cond
            if cond == false:
                continue
            if not isinstance(cond, (bool, Relational, Boolean)):
                raise TypeError(
                    "Cond %s is of type %s, but must be a Relational,"
                    " Boolean, or a built-in bool." % (cond, type(cond)))
            newargs.append(pair)
            if cond == True:
                break

        if options.pop('evaluate', True):
            r = cls.eval(*newargs)
        else:
            r = None

        if r is None:
            return Basic.__new__(cls, *newargs, **options)
        else:
            return r
开发者ID:B-Rich,项目名称:sympy,代码行数:27,代码来源:piecewise.py

示例4: __new__

# 需要导入模块: from sympy.core import Basic [as 别名]
# 或者: from sympy.core.Basic import __new__ [as 别名]
    def __new__(cls, subset, superset):
        """
        Default constructor.

        It takes the subset and its superset as its parameters.

        Examples:
        >>> from sympy.combinatorics.subsets import Subset
        >>> a = Subset(['c','d'], ['a','b','c','d'])
        >>> a.subset
        ['c', 'd']
        >>> a.superset
        ['a', 'b', 'c', 'd']
        >>> a.size
        2
        """
        if len(subset) > len(superset):
            raise ValueError("Invalid arguments have been provided. The superset must be larger than the subset.")
        for elem in subset:
            if elem not in superset:
                raise ValueError("The superset provided is invalid as it does not contain the element %i" % elem)
        obj = Basic.__new__(cls)
        obj._subset = subset
        obj._superset = superset
        return obj
开发者ID:TeddyBoomer,项目名称:geophar,代码行数:27,代码来源:subsets.py

示例5: __new__

# 需要导入模块: from sympy.core import Basic [as 别名]
# 或者: from sympy.core.Basic import __new__ [as 别名]
    def __new__(cls, *args, **kw_args):
        """
        Constructor for the Permutation object.

        Examples
        ========

        >>> from sympy.combinatorics.permutations import Permutation
        >>> p = Permutation([0,1,2])
        >>> p
        Permutation([0, 1, 2])
        >>> q = Permutation([[0,1],[2]])
        >>> q
        Permutation([[0, 1], [2]])
        """
        if not args or not is_sequence(args[0]) or len(args) > 1 or \
           len(set(is_sequence(a) for a in args[0])) > 1:
            raise ValueError('Permutation argument must be a list of ints or a list of lists.')

        # 0, 1, ..., n-1 should all be present

        temp = [int(i) for i in flatten(args[0])]
        if set(range(len(temp))) != set(temp):
            raise ValueError("Integers 0 through %s must be present." % len(temp))

        cform = aform = None
        if args[0] and is_sequence(args[0][0]):
            cform = [list(a) for a in args[0]]
        else:
            aform = list(args[0])

        ret_obj = Basic.__new__(cls, (cform or aform), **kw_args)
        ret_obj._cyclic_form, ret_obj._array_form = cform, aform
        return ret_obj
开发者ID:piyushbansal,项目名称:sympy,代码行数:36,代码来源:permutations.py

示例6: __new__

# 需要导入模块: from sympy.core import Basic [as 别名]
# 或者: from sympy.core.Basic import __new__ [as 别名]
 def __new__(cls, arg, expr):
     if not isinstance(arg, Argument):
         raise TypeError("arg must be of type `Argument`")
     expr = _sympify(expr)
     if not isinstance(expr, (Expr, MatrixExpr)):
         raise TypeError("Unsupported expression type %s." % type(expr))
     return Basic.__new__(cls, arg, expr)
开发者ID:gitter-badger,项目名称:symcc,代码行数:9,代码来源:routines.py

示例7: __new__

# 需要导入模块: from sympy.core import Basic [as 别名]
# 或者: from sympy.core.Basic import __new__ [as 别名]
    def __new__(cls, name, objects=EmptySet(), commutative_diagrams=EmptySet()):
        if not name:
            raise ValueError("A Category cannot have an empty name.")

        new_category = Basic.__new__(cls, Symbol(name), Class(objects),
                                     FiniteSet(*commutative_diagrams))
        return new_category
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:9,代码来源:baseclasses.py

示例8: __new__

# 需要导入模块: from sympy.core import Basic [as 别名]
# 或者: from sympy.core.Basic import __new__ [as 别名]
    def __new__(cls, *args, **kw_args):
        """
        The constructor for the Prufer object.

        Examples
        ========
        >>> from sympy.combinatorics.prufer import Prufer

        A Prufer object can be constructed from a list of node connections
        and the number of nodes:

        >>> a = Prufer([[0, 1], [0, 2], [0, 3]], 4)
        >>> a.prufer_repr
        [0, 0]

        A Prufer object can be constructed from a Prufer sequence:

        >>> b = Prufer([1, 3])
        >>> b.tree_repr
        [[2, 1], [1, 3], [3, 0]]
        """
        ret_obj = Basic.__new__(cls, *args, **kw_args)
        if isinstance(args[0][0], list):
            ret_obj._tree_repr = args[0]
            ret_obj._nodes = args[1]
        else:
            ret_obj._prufer_repr = args[0]
            ret_obj._nodes = len(ret_obj._prufer_repr) + 2
        return ret_obj
开发者ID:fankalemura,项目名称:sympy,代码行数:31,代码来源:prufer.py

示例9: __new__

# 需要导入模块: from sympy.core import Basic [as 别名]
# 或者: from sympy.core.Basic import __new__ [as 别名]
    def __new__(cls, *args):
        from sympy.matrices.immutable import ImmutableDenseMatrix
        args = map(sympify, args)
        mat = ImmutableDenseMatrix(*args)

        obj = Basic.__new__(cls, mat)
        return obj
开发者ID:cklb,项目名称:sympy,代码行数:9,代码来源:blockmatrix.py

示例10: __new__

# 需要导入模块: from sympy.core import Basic [as 别名]
# 或者: from sympy.core.Basic import __new__ [as 别名]
 def __new__(cls, mat):
     mat = _sympify(mat)
     if not mat.is_Matrix:
         raise TypeError("mat should be a matrix")
     if not mat.is_square:
         raise ShapeError("Inverse of non-square matrix %s" % mat)
     return Basic.__new__(cls, mat)
开发者ID:Amo10,项目名称:Computer-Science-2014-2015,代码行数:9,代码来源:inverse.py

示例11: __new__

# 需要导入模块: from sympy.core import Basic [as 别名]
# 或者: from sympy.core.Basic import __new__ [as 别名]
    def __new__(cls, *args, **kwargs):
        check = kwargs.get('check', True)

        obj = Basic.__new__(cls, *args)
        if check:
            validate(*args)
        return obj
开发者ID:Maihj,项目名称:sympy,代码行数:9,代码来源:matadd.py

示例12: __new__

# 需要导入模块: from sympy.core import Basic [as 别名]
# 或者: from sympy.core.Basic import __new__ [as 别名]
    def __new__(cls, partition, integer=None):
        """
        Generates a new IntegerPartition object from a list or dictionary.

        The partition can be given as a list of positive integers or a
        dictionary of (integer, multiplicity) items. If the partition is
        preceeded by an integer an error will be raised if the partition
        does not sum to that given integer.

        Examples
        ========

        >>> from sympy.combinatorics.partitions import IntegerPartition
        >>> a = IntegerPartition([5, 4, 3, 1, 1])
        >>> a
        IntegerPartition(14, (5, 4, 3, 1, 1))
        >>> print a
        [5, 4, 3, 1, 1]
        >>> IntegerPartition({1:3, 2:1})
        IntegerPartition(5, (2, 1, 1, 1))

        If the value that the partion should sum to is given first, a check
        will be made to see n error will be raised if there is a discrepancy:
        >>> IntegerPartition(10, [5, 4, 3, 1])
        Traceback (most recent call last):
        ...
        ValueError: The partition is not valid

        """
        from sympy.ntheory.residue_ntheory import int_tested

        if integer is not None:
            integer, partition = partition, integer
        if isinstance(partition, (dict, Dict)):
            _ = []
            for k, v in sorted(partition.items(), reverse=True):
                if not v:
                    continue
                k, v = int_tested(k, v)
                _.extend([k]*v)
            partition = tuple(_)
        else:
            partition = tuple(sorted(int_tested(partition), reverse=True))
        sum_ok = False
        if integer is None:
            integer = sum(partition)
            sum_ok = True
        else:
            integer = int_tested(integer)

        if not sum_ok and sum(partition) != integer:
            raise ValueError("Partition did not add to %s" % integer)
        if any(i < 1 for i in partition):
            raise ValueError("The summands must all be positive.")

        obj = Basic.__new__(cls, integer, partition)
        obj.partition = list(partition)
        obj.integer = integer
        return obj
开发者ID:StefenYin,项目名称:sympy,代码行数:61,代码来源:partitions.py

示例13: __new__

# 需要导入模块: from sympy.core import Basic [as 别名]
# 或者: from sympy.core.Basic import __new__ [as 别名]
    def __new__(cls, *args, **kwargs):
        args = list(map(sympify, args))
        check = kwargs.get('check', True)

        obj = Basic.__new__(cls, *args)
        if check:
            validate(*args)
        return obj
开发者ID:KonstantinTogoi,项目名称:sympy,代码行数:10,代码来源:matadd.py

示例14: _new

# 需要导入模块: from sympy.core import Basic [as 别名]
# 或者: from sympy.core.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 = cls._handle_creation_inputs(*args, **kwargs)
     rows = Integer(rows)
     cols = Integer(cols)
     mat = Tuple(*flat_list)
     return Basic.__new__(cls, rows, cols, mat)
开发者ID:JiraiyaGerotora,项目名称:sympy,代码行数:10,代码来源:immutable.py

示例15: __new__

# 需要导入模块: from sympy.core import Basic [as 别名]
# 或者: from sympy.core.Basic import __new__ [as 别名]
 def __new__(cls, mat, exp=S(-1)):
     # exp is there to make it consistent with
     # inverse.func(*inverse.args) == inverse
     mat = _sympify(mat)
     if not mat.is_Matrix:
         raise TypeError("mat should be a matrix")
     if not mat.is_square:
         raise ShapeError("Inverse of non-square matrix %s" % mat)
     return Basic.__new__(cls, mat, exp)
开发者ID:asmeurer,项目名称:sympy,代码行数:11,代码来源:inverse.py


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