Re: [Cython] Add support for list/tuple slicing

2013-03-07 Thread Zaur Shibzukhov
2013/3/7 Zaur Shibzukhov : > Current Cython generate for slicing of list/tuple general > PySequence_GetSlice/SetSlice call. > We could replace that to native call for Py{List|Tuple}_GetSlice and > PyList_SetSlice for lists/tuples. There is updated change that use utility code __Pyx_Py{List|Tuple}_

Re: [Cython] Cython syntax to pre-allocate lists for performance

2013-03-07 Thread Robert Bradshaw
On Thu, Mar 7, 2013 at 3:19 PM, Greg Ewing wrote: > Nikita Nemkin wrote: >> >> Sorry, accidental early send. Previous mail continued... >> >> [None] * N makes an extra pass over the list to assign None to each item >> (and also incref None n times). > > > Maybe this could be optimised by adding N

Re: [Cython] Cython syntax to pre-allocate lists for performance

2013-03-07 Thread Greg Ewing
Nikita Nemkin wrote: Sorry, accidental early send. Previous mail continued... [None] * N makes an extra pass over the list to assign None to each item (and also incref None n times). Maybe this could be optimised by adding N to the reference count instead of incrementing it N times? -- Greg _

Re: [Cython] Cython syntax to pre-allocate lists for performance

2013-03-07 Thread Robert Bradshaw
On Thu, Mar 7, 2013 at 10:26 AM, Yury V. Zaytsev wrote: > Hi Stefan, > > On Thu, 2013-03-07 at 12:21 +0100, Stefan Behnel wrote: > >> Note that Python has an algorithm for shrinking a list on appending, so >> this might not be sufficient for your use case. What do you need it for? > > W00t! I didn

Re: [Cython] Cython syntax to pre-allocate lists for performance

2013-03-07 Thread Yury V. Zaytsev
Hi Stefan, On Thu, 2013-03-07 at 12:21 +0100, Stefan Behnel wrote: > Note that Python has an algorithm for shrinking a list on appending, so > this might not be sufficient for your use case. What do you need it for? W00t! I didn't know about that. I'm wrapping a C++ code that should transmit la

Re: [Cython] Cython syntax to pre-allocate lists for performance

2013-03-07 Thread Robert Bradshaw
On Thu, Mar 7, 2013 at 6:48 AM, Stefan Behnel wrote: > Zaur Shibzukhov, 07.03.2013 15:39: >> 2013/3/7 Zaur Shibzukhov >> >>> I guess the problem is to construct new (even empty) list with >>> pre-allocated memory exactly for N elements. >>> >>> N*[NULL] - changes semantics because there can't be l

[Cython] Add support for list/tuple slicing

2013-03-07 Thread Zaur Shibzukhov
Hello! Current Cython generate for slicing of list/tuple general PySequence_GetSlice/SetSlice call. We could replace that to native call for Py{List|Tuple}_GetSlice and PyList_SetSlice for lists/tuples. Here are the changes: https://github.com/intellimath/cython/commit/27525a5dc9f6eba31b330a6ec04

Re: [Cython] Cython syntax to pre-allocate lists for performance

2013-03-07 Thread Stefan Behnel
Zaur Shibzukhov, 07.03.2013 15:39: > 2013/3/7 Zaur Shibzukhov > >> I guess the problem is to construct new (even empty) list with >> pre-allocated memory exactly for N elements. >> >> N*[NULL] - changes semantics because there can't be list with N elements >> and filled by NULL. >> N*[None] - more

Re: [Cython] Cython syntax to pre-allocate lists for performance

2013-03-07 Thread Zaur Shibzukhov
2013/3/7 Zaur Shibzukhov > I guess the problem is to construct new (even empty) list with > pre-allocated memory exactly for N elements. > > N*[NULL] - changes semantics because there can't be list with N elements > and filled by NULL. > N*[None] - more expansive for further assignments because o

Re: [Cython] Cython syntax to pre-allocate lists for performance

2013-03-07 Thread Zaur Shibzukhov
2013/3/7 Stefan Behnel > Yury V. Zaytsev, 07.03.2013 12:16: > > Is there any syntax that I can use to do something like this in Cython: > > > > py_object_ = PyList_New(123); ? > > Note that Python has an algorithm for shrinking a list on appending, so > this might not be sufficient for your u

Re: [Cython] Cython syntax to pre-allocate lists for performance

2013-03-07 Thread Nikita Nemkin
Sorry, accidental early send. Previous mail continued... [None] * N makes an extra pass over the list to assign None to each item (and also incref None n times). This is useless extra work. The larget the list, the worse it gets. Best regards, Nikita Nemkin _

Re: [Cython] Cython syntax to pre-allocate lists for performance

2013-03-07 Thread Nikita Nemkin
On Thu, 07 Mar 2013 17:16:10 +0600, Yury V. Zaytsev wrote: Hi, Is there any syntax that I can use to do something like this in Cython: py_object_ = PyList_New(123); ? If not, do you think that this can be added in one way or another? Unfortunately, I can't think of a non-disruptive wa

Re: [Cython] Cython syntax to pre-allocate lists for performance

2013-03-07 Thread Stefan Behnel
Yury V. Zaytsev, 07.03.2013 12:16: > Is there any syntax that I can use to do something like this in Cython: > > py_object_ = PyList_New(123); ? Note that Python has an algorithm for shrinking a list on appending, so this might not be sufficient for your use case. > If not, do you think tha

[Cython] Cython syntax to pre-allocate lists for performance

2013-03-07 Thread Yury V. Zaytsev
Hi, Is there any syntax that I can use to do something like this in Cython: py_object_ = PyList_New(123); ? If not, do you think that this can be added in one way or another? Unfortunately, I can't think of a non-disruptive way of doing it. For instance, if this [None] * N is given a