[Cython] bug in buffer syntax

2009-10-25 Thread Sturla Molden
If we have np.ndarray[double, ndim=2] array then (array[row,0]) and (array[0,column]) is a trick to get a pointer to a row or a column. Strangely, the expression is only allowed in cdef functions. In Python callable functions, it produces the error message Cannot take address of Python

Re: [Cython] bug in buffer syntax

2009-10-25 Thread Stefan Behnel
Sturla Molden, 25.10.2009 09:58: If we have np.ndarray[double, ndim=2] array then (array[row,0]) and (array[0,column]) is a trick to get a pointer to a row or a column. Strangely, the expression is only allowed in cdef functions. In Python callable functions, it produces the

[Cython] Relaxed run-time checks on buffer contiguity?

2009-10-25 Thread Sturla Molden
Buffers/ndarrays declared with mode=c or mode=fortran will only accept C or Fortran contiguous buffers. But the generated C code does not assume more than contiguity in the fastest varying dimension. With a = np.zeros((10,10)) b = a[::2, :] the code generated for np.ndarray[double,

Re: [Cython] bug in buffer syntax

2009-10-25 Thread Sturla Molden
Stefan Behnel skrev: Could you provide complete code examples for the two functions you use? Sure... I was fiddling with an experimental re-write (or clean-up) of SciPy's ckdtree. Here it is. Sturla # Rewrite by Sturla Molden, Oct 2009 # Changes are public domain. # Copyright

[Cython] C array support redux

2009-10-25 Thread Stefan Behnel
Hi all, the wiki has an enhancement page on better C array support. http://wiki.cython.org/enhancements/arraytypes Note that this is not about SIMD operations and whatnot, just about plain int[] x The page mentions things like dynamic memory allocation happening automatically behind

Re: [Cython] C array support redux

2009-10-25 Thread Lisandro Dalcin
On Sun, Oct 25, 2009 at 11:33 AM, Stefan Behnel stefan...@behnel.de wrote: Hi all, the wiki has an enhancement page on better C array support. http://wiki.cython.org/enhancements/arraytypes Note that this is not about SIMD operations and whatnot, just about plain        int[] x The page

Re: [Cython] C array support redux

2009-10-25 Thread Sturla Molden
Stefan Behnel skrev: The page mentions things like dynamic memory allocation happening automatically behind the scenes, so that cdef int a[runtime_size] would locally allocate memory, as would subsequent slicing, I guess. This by the way, can be deferred to the C or C++ compiler:

Re: [Cython] C array support redux

2009-10-25 Thread Stefan Behnel
Lisandro Dalcin, 25.10.2009 17:04: So you could support the lhs = rhs[slice] when lhs is a pyobject, but generate a Cython compile error if lhs is a C pointer/array type (perhaps making exceptions for the case of char[]/char*) until auto mem alloc is implemented. Yes, that occurred to me,

[Cython] optimizing list.pop

2009-10-25 Thread Sturla Molden
I just realized the Python does not provide a fast way of popping an item from a list, just append. I.e. there is a PyList_Append, but no PyList_Pop. And in Python's code for _listobject.c, the function listpop is declared static. When using a list as a stack (a common case for Python lists),

Re: [Cython] optimizing list.pop

2009-10-25 Thread Lisandro Dalcin
On Sun, Oct 25, 2009 at 2:39 PM, Sturla Molden stu...@molden.no wrote: I just realized the Python does not provide a fast way of popping an item from a list, just append. I.e. there is a PyList_Append, but no PyList_Pop. And in Python's code for _listobject.c, the function listpop is declared

Re: [Cython] Relaxed run-time checks on buffer contiguity?

2009-10-25 Thread Dag Sverre Seljebotn
Sturla Molden wrote: Buffers/ndarrays declared with mode=c or mode=fortran will only accept C or Fortran contiguous buffers. But the generated C code does not assume more than contiguity in the fastest varying dimension. With a = np.zeros((10,10)) b = a[::2, :] the code generated

Re: [Cython] C array support redux

2009-10-25 Thread Dag Sverre Seljebotn
Stefan Behnel wrote: Hi all, the wiki has an enhancement page on better C array support. http://wiki.cython.org/enhancements/arraytypes Note that this is not about SIMD operations and whatnot, just about plain int[] x The page mentions things like dynamic memory allocation

Re: [Cython] C array support redux

2009-10-25 Thread Dag Sverre Seljebotn
Stefan Behnel wrote: This would be a rather straight forward thing to support: cdef char* s = ... py_s = s[:30] It would translate directly to a call to PyString_FromStringAndSize(), which is a rather often requested feature IMO. All other base types would return a

Re: [Cython] C array support redux

2009-10-25 Thread Stefan Behnel
Dag Sverre Seljebotn, 25.10.2009 21:26: Stefan Behnel wrote: This would be a rather straight forward thing to support: cdef char* s = ... py_s = s[:30] It would translate directly to a call to PyString_FromStringAndSize(), which is a rather often requested feature IMO. All other