#10963: More functorial constructions
-------------------------------------+-------------------------------------
       Reporter:  nthiery            |        Owner:  stumpc5
           Type:  enhancement        |       Status:  needs_work
       Priority:  major              |    Milestone:
      Component:  categories         |   Resolution:
       Keywords:                     |    Merged in:
        Authors:  Nicolas M. ThiƩry  |    Reviewers:  Simon King
Report Upstream:  N/A                |  Work issues:  Reduce startup time
         Branch:                     |  by 5%. Avoid "recursion depth
   Dependencies:  #11224, #8327,     |  exceeded (ignored)".
  #10193, #12895, #14516, #14722,    |       Commit:
  #13589, #14471                     |     Stopgaps:
-------------------------------------+-------------------------------------

Comment (by SimonKing):

 For the record, I currently work with this patch
 {{{
 #!diff
 diff --git a/sage/structure/coerce_dict.pyx
 b/sage/structure/coerce_dict.pyx
 --- a/sage/structure/coerce_dict.pyx
 +++ b/sage/structure/coerce_dict.pyx
 @@ -187,14 +187,18 @@
          h,offset = r.key
          cdef list bucket = <object>PyList_GET_ITEM(buckets, (<size_t>h) %
 PyList_GET_SIZE(buckets))
          cdef Py_ssize_t i
 +        cdef object val
          for i from 0 <= i < PyList_GET_SIZE(bucket) by 3:
              if PyInt_AsSsize_t(PyList_GET_ITEM(bucket,i))==h:
                  if PyList_GET_ITEM(bucket,i+offset)==<void *>r:
 +                    val = <object>PyList_GET_ITEM(bucket,i+2)
 +                    print "deletion for",<size_t>h,"with
 value",<size_t><void*>val
                      del bucket[i:i+3]
                      D._size -= 1
                      break
                  else:
                      break
 +        print "last line for",<size_t>h,"with value",<size_t><void*>val

  cdef class TripleDictEraser:
      """
 }}}
 and the examples are
 {{{
 sage: from sage.structure.coerce_dict import MonoDict
 sage: M = MonoDict(11)
 sage: class A:
 ....:     def __del__(self):
 ....:         print "__del__",id(self)
 ....:
 sage: a = A()
 sage: prev = a
 sage: M = MonoDict(11)
 sage: for i in range(1000):
 ....:     newA = A()
 ....:     M[prev] = newA
 ....:     prev = newA
 ....:
 sage: del a
 deletion for 91294536 with value 89650384
 last line for 91294536 with value 89650384
 deletion for 89650384 with value 89650600
 last line for 89650384 with value 89650600
 deletion for 89650600 with value 89660160
 last line for 89650600 with value 89660160
 deletion for 89660160 with value 89660232
 last line for 89660160 with value 89660232
 deletion for 89660232 with value 89660016
 last line for 89660232 with value 89660016
 ...
 deletion for 91409944 with value 91410016
 last line for 91409944 with value 91410016
 Exception RuntimeError: 'maximum recursion depth exceeded while calling a
 Python object' in <sage.structure.coerce_dict.MonoDictEraser object at
 0x54169f0> ignored
 Exception RuntimeError: 'maximum recursion depth exceeded while calling a
 Python object' in <bound method A.__del__ of <__main__.A instance at
 0x572ce60>> ignored
 Exception RuntimeError: 'maximum recursion depth exceeded while calling a
 Python object' in <bound method A.__del__ of <__main__.A instance at
 0x572ce18>> ignored
 Exception RuntimeError: 'maximum recursion depth exceeded' in <bound
 method A.__del__ of <__main__.A instance at 0x572cdd0>> ignored
 __del__ 91409800
 __del__ 91409728
 __del__ 91409656
 __del__ 91409584
 __del__ 91409512
 ...
 __del__ 89660160
 __del__ 89650600
 __del__ 89650384
 __del__ 91294536
 }}}
 respectively
 {{{
 sage: from sage.structure.coerce_dict import MonoDict
 sage: M = MonoDict(11)
 sage: cython("""
 ....: cdef class A:
 ....:     cdef __weakref__
 ....:     def __dealloc__(self):
 ....:         print "__dealloc__",id(self)
 ....: """)
 ....:
 sage: a = A()
 sage: prev = a
 sage: for i in range(1000):
 ....:     newA = A()
 ....:     M[prev] = newA
 ....:     prev = newA
 ....:
 sage: len(M)
 1000
 sage: del a
 __dealloc__ 140403054971016
 deletion for 140403054971016 with value 140403054971064
 last line for 140403054971016 with value 140403054971064
 __dealloc__ 140403054971064
 deletion for 140403054971064 with value 140403054971184
 last line for 140403054971064 with value 140403054971184
 __dealloc__ 140403054971184
 deletion for 140403054971184 with value 140403054971160
 last line for 140403054971184 with value 140403054971160
 __dealloc__ 140403054971160
 deletion for 140403054971160 with value 140403054971208
 last line for 140403054971160 with value 140403054971208
 __dealloc__ 140403054971208
 deletion for 140403054971208 with value 140403054971088
 last line for 140403054971208 with value 140403054971088
 __dealloc__ 140403054971088
 deletion for 140403054971088 with value 140403054971112
 last line for 140403054971088 with value 140403054971112
 __dealloc__ 140403054971112
 deletion for 140403054971112 with value 140403054971232
 last line for 140403054971112 with value 140403054971232
 ...
 __dealloc__ 91285256
 deletion for 91285256 with value 91285280
 last line for 91285256 with value 91285280
 __dealloc__ 91285280
 deletion for 91285280 with value 91285304
 last line for 91285280 with value 91285304
 Exception RuntimeError: 'maximum recursion depth exceeded while calling a
 Python object' in
 <_home_simon__sage_temp_linux_sqwp_site_5429_tmp_oooXg4_spyx_0.A object at
 0x570e738> ignored
 Exception RuntimeError: 'maximum recursion depth exceeded while calling a
 Python object' in <sage.structure.coerce_dict.MonoDictEraser object at
 0x560f440> ignored
 }}}

 Conclusion: I thought I understood what was happening, but these two
 examples prove me wrong.
 }}}

--
Ticket URL: <http://trac.sagemath.org/ticket/10963#comment:102>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to