• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python compatibility.cmp函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: __cmp__

    def __cmp__(self, other):
        """Comparison of two GeometryEntities."""
        n1 = self.__class__.__name__
        n2 = other.__class__.__name__
        c = cmp(n1, n2)
        if not c:
            return 0

        i1 = -1
        for cls in self.__class__.__mro__:
            try:
                i1 = ordering_of_classes.index(cls.__name__)
                break
            except ValueError:
                i1 = -1
        if i1 == -1:
            return c

        i2 = -1
        for cls in other.__class__.__mro__:
            try:
                i2 = ordering_of_classes.index(cls.__name__)
                break
            except ValueError:
                i2 = -1
        if i2 == -1:
            return c

        return cmp(i1, i2)
开发者ID:ENuge,项目名称:sympy,代码行数:29,代码来源:entity.py


示例2: __cmp__

    def __cmp__(cls, other):
        # If the other object is not a Basic subclass, then we are not equal to
        # it.
        if not isinstance(other, BasicType):
            return -1
        n1 = cls.__name__
        n2 = other.__name__
        c = cmp(n1,n2)
        if not c: return 0

        UNKNOWN = len(ordering_of_classes)+1
        try:
            i1 = ordering_of_classes.index(n1)
        except ValueError:
            #print 'Add',n1,'to basic.ordering_of_classes list'
            #return c
            i1 = UNKNOWN
        try:
            i2 = ordering_of_classes.index(n2)
        except ValueError:
            #print 'Add',n2,'to basic.ordering_of_classes list'
            #return c
            i2 = UNKNOWN
        if i1 == UNKNOWN and i2 == UNKNOWN:
            return c
        return cmp(i1,i2)
开发者ID:Grahack,项目名称:geophar,代码行数:26,代码来源:core.py


示例3: compare_pretty

    def compare_pretty(a, b):
        """
        Is a > b in the sense of ordering in printing?

        THIS FUNCTION IS DEPRECATED.  Use ``default_sort_key`` instead.

        ::

          yes ..... return 1
          no ...... return -1
          equal ... return 0

        Strategy:

        It uses Basic.compare as a fallback, but improves it in many cases,
        like ``x**3``, ``x**4``, ``O(x**3)`` etc. In those simple cases, it just parses the
        expression and returns the "sane" ordering such as::

          1 < x < x**2 < x**3 < O(x**4) etc.

        Examples
        ========

        >>> from sympy.abc import x
        >>> from sympy import Basic, Number
        >>> Basic._compare_pretty(x, x**2)
        -1
        >>> Basic._compare_pretty(x**2, x**2)
        0
        >>> Basic._compare_pretty(x**3, x**2)
        1
        >>> Basic._compare_pretty(Number(1, 2), Number(1, 3))
        1
        >>> Basic._compare_pretty(Number(0), Number(-1))
        1

        """
        try:
            a = _sympify(a)
        except SympifyError:
            pass

        try:
            b = _sympify(b)
        except SympifyError:
            pass

        # both objects are non-SymPy
        if (not isinstance(a, Basic)) and (not isinstance(b, Basic)):
            return cmp(a, b)

        if not isinstance(a, Basic):
            return -1   # other < sympy

        if not isinstance(b, Basic):
            return +1   # sympy > other

        # now both objects are from SymPy, so we can proceed to usual comparison
        return cmp(a.sort_key(), b.sort_key())
开发者ID:bladewang,项目名称:sympy,代码行数:59,代码来源:basic.py


示例4: compare

    def compare(self, other):
        """
        Return -1, 0, 1 if the object is smaller, equal, or greater than other.

        Not in the mathematical sense. If the object is of a different type
        from the "other" then their classes are ordered according to
        the sorted_classes list.

        Examples
        ========

        >>> from sympy.abc import x, y
        >>> x.compare(y)
        -1
        >>> x.compare(x)
        0
        >>> y.compare(x)
        1

        """
        # all redefinitions of __cmp__ method should start with the
        # following three lines:
        if self is other:
            return 0
        c = cmp(self.__class__, other.__class__)
        if c:
            return c
        #
        st = self._hashable_content()
        ot = other._hashable_content()
        c = cmp(len(st), len(ot))
        if c:
            return c
        for l, r in zip(st, ot):
            if isinstance(l, Basic):
                c = l.compare(r)
            elif isinstance(l, frozenset):
                c = 0
            else:
                c = cmp(l, r)
            if c:
                return c
        return 0
开发者ID:bladewang,项目名称:sympy,代码行数:43,代码来源:basic.py


示例5: test_logic_cmp

def test_logic_cmp():
    l1 = And('a', Not('b'))
    l2 = And('a', Not('b'))

    assert hash(l1) == hash(l2)
    assert (l1==l2) == T
    assert (l1!=l2) == F
    assert cmp(l1, l2) == 0

    assert And('a','b','c') == And('b','a','c')
    assert And('a','b','c') == And('c','b','a')
    assert And('a','b','c') == And('c','a','b')
开发者ID:StefenYin,项目名称:sympy,代码行数:12,代码来源:test_logic.py


示例6: sdp_add_term

def sdp_add_term(f, term, u, O, K):
    """Add a single term using bisection method. """
    M, c = term

    if not c:
        return f
    if not f:
        return [(M, c)]

    monoms = sdp_monoms(f)

    if cmp(O(M), O(monoms[ 0])) > 0:
        return [(M, c)] + f
    if cmp(O(M), O(monoms[-1])) < 0:
        return f + [(M, c)]

    lo, hi = 0, len(monoms)-1

    while lo <= hi:
        i = (lo + hi) // 2
        j = cmp(O(M), O(monoms[i]))

        if not j:
            coeff = f[i][1] + c

            if not coeff:
                return f[:i] + f[i+1:]
            else:
                return f[:i] + [(M, coeff)] + f[i+1:]
        else:
            if j > 0:
                hi = i - 1
            else:
                lo = i + 1
    else:
        return f[:i] + [(M, c)] + f[i+1:]
开发者ID:TeddyBoomer,项目名称:wxgeometrie,代码行数:36,代码来源:groebnertools.py


示例7: _compare_pretty

    def _compare_pretty(a, b):
        from sympy.series.order import Order
        if isinstance(a, Order) and not isinstance(b, Order):
            return 1
        if not isinstance(a, Order) and isinstance(b, Order):
            return -1

        if a.is_Rational and b.is_Rational:
            return cmp(a.p*b.q, b.p*a.q)
        else:
            from sympy.core.symbol import Wild
            p1, p2, p3 = Wild("p1"), Wild("p2"), Wild("p3")
            r_a = a.match(p1 * p2**p3)
            if r_a and p3 in r_a:
                a3 = r_a[p3]
                r_b = b.match(p1 * p2**p3)
                if r_b and p3 in r_b:
                    b3 = r_b[p3]
                    c = Basic.compare(a3, b3)
                    if c != 0:
                        return c

        return Basic.compare(a,b)
开发者ID:Jerryy,项目名称:sympy,代码行数:23,代码来源:basic.py


示例8: _what_known_about

    def _what_known_about(self, k):
        """tries hard to give an answer to: what is known about fact `k`

           NOTE: You should not use this directly -- see make__get_assumption
                 instead

           This function is called when a request is made to see what a fact
           value is.

           If we are here, it means that the asked-for fact is not known, and
           we should try to find a way to find its value.

           For this we use several techniques:

           1. _eval_is_<fact>
           ------------------

           first fact-evaluation function is tried,  for example
           _eval_is_integer


           2. relations
           ------------

           if the first step did not succeeded (no such function, or its return
           is None) then we try related facts. For example

                       means
             rational   -->   integer

           another example is joined rule:

             integer & !odd  --> even

           so in the latter case if we are looking at what 'even' value is,
           'integer' and 'odd' facts will be asked.


           3. evalf() for comparable
           -------------------------

           as a last resort for comparable objects we get their numerical value
           -- this helps to determine facts like 'positive' and 'negative'



           In all cases when we settle on some fact value, it is given to
           _learn_new_facts to deduce all its implications, and also the result
           is cached in ._assumptions for later quick access.
        """
        if k not in _assume_defined:
            raise AttributeError('undefined assumption %r' % (k))

        seen = self._a_inprogress
        if k in seen:
            raise CycleDetected
        seen.append(k)

        try:
            # First try the assumption evaluation function if it exists
            if hasattr(self, '_eval_is_' + k):
                try:
                    a = getattr(self, '_eval_is_' + k)()
                except CycleDetected:
                    pass
                else:
                    if a is not None:
                        self._learn_new_facts( ((k, a),) )
                        return a

            # Try assumption's prerequisites
            for pk in _assume_rules.prereq[k]:
                if hasattr(self, '_eval_is_' + pk):
                    # cycle
                    if pk in seen:
                        continue
                    a = getattr(self, 'is_' + pk)
                    if a is not None:
                        self._learn_new_facts( ((pk,a),) )
                        # it is possible that we either know or don't know k at
                        # this point
                        try:
                            return self._assumptions[k]
                        except KeyError:
                            pass
        finally:
            seen.pop()

        # For positive/negative try to ask evalf
        if k in _real_ordering and self.is_comparable:
            e = self.evalf(1)

            if e.is_Number:
                a = _real_cmp0_table[k][cmp(e, 0)]

                if a is not None:
                    self._learn_new_facts( ((k,a),) )
                    return a

        # No result -- unknown
#.........这里部分代码省略.........
开发者ID:igaurangagrawal,项目名称:sympy,代码行数:101,代码来源:assumptions.py


示例9: __cmp__

    def __cmp__(a, b):
        if type(a) is not type(b):
            return cmp( str(type(a)), str(type(b)) )

        else:
            return cmp(a.args, b.args)
开发者ID:Abhityagi16,项目名称:sympy,代码行数:6,代码来源:logic.py


示例10: _compare_pretty

 def _compare_pretty(a, b):
     return cmp(str(a), str(b))
开发者ID:abhishekkumawat23,项目名称:sympy,代码行数:2,代码来源:operations.py


示例11: monomial_grevlex_cmp

def monomial_grevlex_cmp(a, b):
    return cmp(sum(a), sum(b)) or cmp(tuple(reversed(b)), tuple(reversed(a)))
开发者ID:TeddyBoomer,项目名称:wxgeometrie,代码行数:2,代码来源:monomialtools.py


示例12: monomial_grlex_cmp

def monomial_grlex_cmp(a, b):
    return cmp(sum(a), sum(b)) or cmp(a, b)
开发者ID:TeddyBoomer,项目名称:wxgeometrie,代码行数:2,代码来源:monomialtools.py


示例13: monomial_lex_cmp

def monomial_lex_cmp(a, b):
    return cmp(a, b)
开发者ID:TeddyBoomer,项目名称:wxgeometrie,代码行数:2,代码来源:monomialtools.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python compatibility.cmp_to_key函数代码示例发布时间:2022-05-27
下一篇:
Python compatibility.callable函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap