#9828: Upgrade to Cython 0.13
---------------------------+------------------------------------------------
   Reporter:  mpatel       |       Owner:  tbd         
       Type:  enhancement  |      Status:  needs_review
   Priority:  major        |   Milestone:              
  Component:  packages     |    Keywords:              
     Author:               |    Upstream:  N/A         
   Reviewer:               |      Merged:              
Work_issues:               |  
---------------------------+------------------------------------------------

Comment(by jason):

 I did sage -ba (4.6.alpha2, the above patches applied, and the new Cython
 spkg), and still got the following failures (Ubuntu 10.04 64-bit):

 {{{
 sage -t  -long local/lib/python2.6/site-
 packages/sagenb-0.8.2-py2.6.egg/sagenb/misc/sageinspect.py
 **********************************************************************
 File "/home/grout/sage-4.6.alpha2/local/lib/python2.6/site-
 packages/sagenb-0.8.2-py2.6.egg/sagenb/misc/sageinspect.py", line 1074:
     sage: sage_getsource(sage.rings.integer.Integer.__init__,
 is_binary=True)
 Expected:    Traceback (most recent call last):    ...    TypeError: arg
 is not a module, class, method, function, traceback, frame, or code
 objectGot:    '    def __init__(self, x=None, unsigned int base=0):\n
 """\n        EXAMPLES::\n        \n            sage: a =
 long(-901824309821093821093812093810928309183091832091)\n            sage:
 b = ZZ(a); b\n
 -901824309821093821093812093810928309183091832091\n            sage:
 ZZ(b)\n            -901824309821093821093812093810928309183091832091\n
 sage: ZZ(\'-901824309821093821093812093810928309183091832091\')\n
 -901824309821093821093812093810928309183091832091\n            sage:
 ZZ(int(-93820984323))\n            -93820984323\n            sage:
 ZZ(ZZ(-901824309821093821093812093810928309183091832091))\n
 -901824309821093821093812093810928309183091832091\n            sage:
 ZZ(QQ(-901824309821093821093812093810928309183091832091))\n
 -901824309821093821093812093810928309183091832091\n            sage:
 ZZ(RR(2.0)^80)\n            1208925819614629174706176\n            sage:
 ZZ(QQbar(sqrt(28-10*sqrt(3)) + sqrt(3)))\n            5\n            sage:
 ZZ(AA(32).nth_root(5))\n            2\n            sage:
 ZZ(pari(\'Mod(-3,7)\'))\n            4\n            sage: ZZ(\'sage\')\n
 Traceback (most recent call last):\n            ...\n
 TypeError: unable to convert x (=sage) to an integer\n            sage:
 Integer(\'zz\',36).str(36)\n            \'zz\'\n            sage:
 ZZ(\'0x3b\').str(16)\n            \'3b\'\n            sage: ZZ(
 ZZ(5).digits(3) , 3)\n            5\n            sage: import numpy\n
 sage: ZZ(numpy.int64(7^7))\n            823543\n            sage:
 ZZ(numpy.ubyte(-7))\n            249\n            sage: ZZ(True)\n
 1\n            sage: ZZ(False)\n            0\n            sage:
 ZZ(1==0)\n            0\n            sage: ZZ(\'+10\')\n            10\n
 \n        ::\n        \n            sage: k = GF(2)\n            sage: ZZ(
 (k(0),k(1)), 2)\n            2\n        \n        ::\n        \n
 sage: t = pari(0*ZZ[x].0 + 3)\n            sage: t.type()\n
 \'t_POL\'\n            sage: ZZ(t)\n            3\n\n            sage:
 ZZ(float(2.0))\n            2\n            sage: ZZ(float(1.0/0.0))\n
 Traceback (most recent call last):\n            ...\n
 OverflowError: cannot convert float infinity to integer\n            sage:
 ZZ(float(0.0/0.0))\n            Traceback (most recent call last):\n
 ...\n            ValueError: cannot convert float NaN to integer\n\n
 ::\n\n            sage: class MyInt(int):\n            ...       pass\n
 sage: class MyLong(long):\n            ...       pass\n            sage:
 class MyFloat(float):\n            ...       pass\n            sage:
 ZZ(MyInt(3))\n            3\n            sage: ZZ(MyLong(4))\n
 4\n            sage: ZZ(MyFloat(5))\n            5\n        """\n\n
 # TODO: All the code below should somehow be in an external\n        #
 cdef\'d function.  Then e.g., if a matrix or vector or\n        #
 polynomial is getting filled by mpz_t\'s, it can use the\n        # rules
 below to do the fill construction of mpz_t\'s, but\n        # without the
 overhead of creating any Python objects at all.\n        # The cdef\'s
 function should be of the form\n        #     mpz_init_set_sage(mpz_t y,
 object x)\n        # Then this function becomes the one liner:\n        #
 mpz_init_set_sage(self.value, x)\n\n        cdef Integer tmp\n        cdef
 char* xs\n        \n        cdef Element lift\n        \n        if x is
 None:\n            if mpz_sgn(self.value) != 0:\n
 mpz_set_si(self.value, 0)\n            \n        else:\n            #
 First do all the type-check versions; these are fast.\n\n            if
 PY_TYPE_CHECK(x, Integer):\n                set_from_Integer(self,
 <Integer>x)\n\n            elif PY_TYPE_CHECK(x, bool):\n
 mpz_set_si(self.value, PyInt_AS_LONG(x))\n\n            elif
 PyInt_Check(x):\n                mpz_set_si(self.value,
 PyInt_AS_LONG(x))\n\n            elif PyLong_Check(x):\n
 mpz_set_pylong(self.value, x)\n\n            elif PyFloat_Check(x):\n
 n = long(x)\n                if n == x:\n
 mpz_set_pylong(self.value, n)\n                else:\n
 raise TypeError, "Cannot convert non-integral float to integer"\n\n
 elif PY_TYPE_CHECK(x, pari_gen):\n                \n                if
 typ((<pari_gen>x).g) == t_INT:\n
 t_INT_to_ZZ(self.value, (<pari_gen>x).g)\n                    \n
 else:\n                    if typ((<pari_gen>x).g) == t_INTMOD:\n
 x = x.lift()\n                    # TODO: figure out how to convert to
 pari integer in base 16 ?\n                    \n                    #
 todo: having this "s" variable around here is causing\n
 # Cython to play games with refcount for the None object, which\n
 # seems really stupid.\n                \n                    try:\n
 s = hex(x)\n                        base = 16\n
 except:\n                        s = str(x)\n                        base
 = 10\n                        \n                    if
 mpz_set_str(self.value, s, base) != 0:\n                        raise
 TypeError, "Unable to coerce PARI %s to an Integer."%x\n\n            elif
 PyString_Check(x):\n                if base < 0 or base > 36:\n
 raise ValueError, "base (=%s) must be between 2 and 36"%base\n
 \n                xs = x\n                if xs[0] == c\'+\':\n
 xs += 1\n                if mpz_set_str(self.value, xs, base) != 0:\n
 raise TypeError, "unable to convert x (=%s) to an integer"%x\n
 \n            elif PyObject_HasAttrString(x, "_integer_"):\n
 # todo: Note that PyObject_GetAttrString returns NULL if\n
 # the attribute was not found. If we could test for this,\n
 # we could skip the double lookup. Unfortunately Cython doesn\'t\n
 # seem to let us do this; it flags an error if the function\n
 # returns NULL, because it can\'t construct an "object" object\n
 # out of the NULL pointer. This really sucks. Perhaps we could\n
 # make the function prototype have return type void*, but\n
 # then how do we make Cython handle the reference counting?\n
 set_from_Integer(self, (<object> PyObject_GetAttrString(x,
 "_integer_"))(the_integer_ring))\n\n            elif (PY_TYPE_CHECK(x,
  list) or PY_TYPE_CHECK(x, tuple)) and base > 1:\n                b =
 the_integer_ring(base)\n                tmp = the_integer_ring(0)\n
 for i in range(len(x)):\n                    tmp += t
 he_integer_ring(x[i])*b**i\n                mpz_set(self.value,
 tmp.value)\n\n            else:\n                import numpy\n
 if isinstance(x, numpy.integer):\n                    mpz_set_p
 ylong(self.value, x.__long__())\n                    return\n
 \n                elif PY_TYPE_CHECK(x, Element):\n
 try:\n                        lift = x.lift()\n
                  if lift._parent != (<Element>x)._parent:\n
 tmp = the_integer_ring(lift)\n
 mpz_swap(tmp.value, self.value)\n
 return\n                    except AttributeError:\n
 pass\n                        \n                raise TypeError, "unable
 to coerce %s to an integer" % type(x)\n'
 **********************************************************************
 File "/home/grout/sage-4.6.alpha2/local/lib/python2.6/site-
 packages/sagenb-0.8.2-py2.6.egg/sagenb/misc/sageinspect.py", line 1079:
     sage: sage_getdef(sage.rings.integer.Integer.__init__,
 obj_name='__init__')
 Expected:
     '__init__( [noargspec] )'
 Got:
     '__init__(x=None, base=0)'
 **********************************************************************
 1 items had failures:
    2 of  26 in __main__.example_23
 ***Test Failed*** 2 failures.
 }}}

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/9828#comment:29>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

-- 
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en.

Reply via email to