I already did that and I get this: cdef list codeSet = []
__pyx_1 = PyList_New(0); if (unlikely(!__pyx_1)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 210; __pyx_clineno = __LINE__; goto __pyx_L1_error;} __pyx_v_codeSet = __pyx_1; __pyx_1 = 0; and if I don't do it that way I get: addVector = [] __pyx_2 = PyList_New(0); if (unlikely(!__pyx_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 215; __pyx_clineno = __LINE__; goto __pyx_L1_error;} Py_DECREF(__pyx_v_addVector); __pyx_v_addVector = ((PyObject *)__pyx_2); __pyx_2 = 0; On Sep 26, 2:55 am, Robert Bradshaw <[EMAIL PROTECTED]> wrote: > On Sep 26, 2008, at 12:09 AM, Simon King wrote: > > > > > > > On Sep 25, 6:45 pm, cesarnda <[EMAIL PROTECTED]> wrote: > > ... > >> result = [] > > ... > >> result.append(n) > > > ... > >> if I compile in the notebook I get a html file showing me the > >> following lines in yellow: > > >> def primes(int kmax): > >> result = [] > >> result.append(n) > >> return result > > >> how can I modify this example to avoid the yellow lines? > > > As other people pointed out, there is not much hope for the "def" and > > the "return" line. > > > But wouldn't it be possible to do > > cdef list result = [] > > Yep, you could do this. The resulting C code calls PyList_New(0) > which is the fastest way to make a list. > > > And isn't there a quick, dirty and potentially unsafe way of appending > > to a list? > > Since it knows result is a list (due to the cdef above), it uses > PyList_Append, the fastest way to append to a list. > > > Or at least for assigning a value to some list entry? I > > think I have seen it somewhere, but I don't remember the name. > > Yep. Currently it calls __Pyx_SetItemInt which does an inline runtime > boundscheck and check for a list, and if it's OK uses a macro to > reset the specified entry right there. We could (should) optimize > this in the case it already knows it's a list, but with good branch > prediction it's probably within 5% of as fast as it could be period. > > - Robert --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-support URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---