On Friday, September 20, 2019 at 5:39:20 AM UTC-7, Simon King wrote: > > Hi! > > Although late... > > On 2019-09-01, mmarco <mma...@unizar.es <javascript:>> wrote: > > ... > > > > Do you think it is reasonable to do these deep changes in this short > time? > > If it is , then i definitely vote for it. > > > > If it is not, then I would propose to leave it as a longer term goal > > (hopefully not much longer), and once we have a fully python3 bases > sage, > > write the guidelines you gave down in the development guide so the new > code > > follows this approach. > > I think those things should definitely be in some written the guidelines! > > Since I am currently migrating my main Sage project from python-2 to > python-"2 and 3", I know that not all parts of the change of user code > are trivial. > I'd find it helpful to have some documents explaining the state of the > art in Sage (similar to some documents we have for our coercion > framework). > > I have a question on Cython, though: When functions/methods will more > often return an iterator instead of a list/tuple, what is the "cdef" > type of an iterator? I.e., how can one tell Cython that a particular > object is an iterator, so that Cython can produce faster code for it? > > I'm pretty sure cython can't. An iterator is a python object that adheres to a certain protocol (it provides "next" and "iter" is idempotent on it), not a particular type. There wouldn't be any optimizations that can be made with just that knowledge. You are of course free to make your own cdef class that adheres to the iterator protocol and in addition provides a c-level shortcut into its "next" functionality. That could save you some python function call overhead in cython code where you know that you'll have an iterator of that specific type.
In particular, the kind of "optimization" that iterators give over lists is a rather high-level one: by removing the requirement of O(N) memory usage, your code may be (asymptotically) more efficient because you don't need to claim so much memory. Whether for special cases (and small to moderate N) it's worth it, depends the particular application. On python level it seems to work rather well. I'm not so sure that this remains the case on cython level, where a whole slew of optimizations for list access are readily available. -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-devel/25a49443-860e-487e-b634-408430fd8d15%40googlegroups.com.