Re: [Cython] About IndexNode and unicode[index]

2013-02-28 Thread Stefan Behnel
Zaur Shibzukhov, 01.03.2013 08:37: > unicode_slice.h > - > > #include "unicodeobject.h" > > static inline PyObject* unicode_slice( > PyObject* text, Py_ssize_t start, Py_ssize_t stop); > > /// PyUnicode_Substring /// > > /* CURRENT */ > >

Re: [Cython] About IndexNode and unicode[index]

2013-02-28 Thread Zaur Shibzukhov
2013/3/1 ZS : > 2013/3/1 Stefan Behnel : >> ZS, 28.02.2013 21:07: >>> 2013/2/28 Stefan Behnel: > This allows to write unicode text parsing code almost at C speed > mostly in python (+ .pxd defintions). I suggest simply adding a constant flag argument to the existing function

Re: [Cython] Be more forgiving about memoryview strides

2013-02-28 Thread Robert Bradshaw
On Thu, Feb 28, 2013 at 11:12 AM, Nathaniel Smith wrote: > On Thu, Feb 28, 2013 at 5:50 PM, Robert Bradshaw wrote: >> On Thu, Feb 28, 2013 at 7:13 AM, Sebastian Berg >> wrote: >>> Hey, >>> >>> Maybe someone here already saw it (I don't have a track account, or I >>> would just create a ticket),

Re: [Cython] About IndexNode and unicode[index]

2013-02-28 Thread Zaur Shibzukhov
>>> >>> I think you could even pass in two flags, one for wraparound and one for >>> boundscheck, and then just evaluate them appropriately in the existing "if" >>> tests above. That should allow both features to be supported independently >>> in a fast way. >>> >> Intresting, could C compilers in

Re: [Cython] About IndexNode and unicode[index]

2013-02-28 Thread Stefan Behnel
ZS, 01.03.2013 07:43: > 2013/3/1 Stefan Behnel: >> ZS, 28.02.2013 21:07: >>> 2013/2/28 Stefan Behnel: > This allows to write unicode text parsing code almost at C speed > mostly in python (+ .pxd defintions). I suggest simply adding a constant flag argument to the existing functio

Re: [Cython] About IndexNode and unicode[index]

2013-02-28 Thread ZS
2013/3/1 Stefan Behnel : > ZS, 28.02.2013 21:07: >> 2013/2/28 Stefan Behnel: This allows to write unicode text parsing code almost at C speed mostly in python (+ .pxd defintions). >>> >>> I suggest simply adding a constant flag argument to the existing function >>> that states if checking

Re: [Cython] About IndexNode and unicode[index]

2013-02-28 Thread ZS
2013/3/1 Stefan Behnel : > ZS, 28.02.2013 21:07: >> 2013/2/28 Stefan Behnel: This allows to write unicode text parsing code almost at C speed mostly in python (+ .pxd defintions). >>> >>> I suggest simply adding a constant flag argument to the existing function >>> that states if checking

Re: [Cython] About IndexNode and unicode[index]

2013-02-28 Thread Stefan Behnel
ZS, 28.02.2013 21:07: > 2013/2/28 Stefan Behnel: >>> This allows to write unicode text parsing code almost at C speed >>> mostly in python (+ .pxd defintions). >> >> I suggest simply adding a constant flag argument to the existing function >> that states if checking should be done or not. Inlining

Re: [Cython] About IndexNode and unicode[index]

2013-02-28 Thread ZS
2013/2/28 Stefan Behnel : >> This allows to write unicode text parsing code almost at C speed >> mostly in python (+ .pxd defintions). > > I suggest simply adding a constant flag argument to the existing function > that states if checking should be done or not. Inlining will let the C > compiler dr

Re: [Cython] About IndexNode and unicode[index]

2013-02-28 Thread Stefan Behnel
ZS, 28.02.2013 19:31: > 2013/2/28 ZS: >> Looking into IndexNode class in ExprNode.py I have seen a possibility >> for addition of more fast code path for unicode[index] as it done in >> method `generate_setitem_code` in case of lists. >> >> This is files for evaluation of performance difference: >

Re: [Cython] Be more forgiving about memoryview strides

2013-02-28 Thread Nathaniel Smith
On Thu, Feb 28, 2013 at 5:50 PM, Robert Bradshaw wrote: > On Thu, Feb 28, 2013 at 7:13 AM, Sebastian Berg > wrote: >> Hey, >> >> Maybe someone here already saw it (I don't have a track account, or I >> would just create a ticket), but it would be nice if Cython was more >> forgiving about contigu

Re: [Cython] Class methods returning C++ class references are not dealt with correctly?

2013-02-28 Thread Bradley M. Froehle
Hey Yury: Yes, you are right. I was thinking this was a function and not a method. As an even ickier workaround: #define TokenStack_top_p(token_stack) &token_stack->top() cdef extern from "": Token* TokenStack_top_p(TokenStack*) except + cdef Token* tok = TokenStack_top_p(sel

Re: [Cython] About IndexNode and unicode[index]

2013-02-28 Thread ZS
2013/2/28 ZS : > Looking into IndexNode class in ExprNode.py I have seen a possibility > for addition of more fast code path for unicode[index] as it done in > method `generate_setitem_code` in case of lists. > > This is files for evaluation of performance difference: > > unicode_index.h > >

Re: [Cython] Class methods returning C++ class references are not dealt with correctly?

2013-02-28 Thread Yury V. Zaytsev
Hi Brad, On Thu, 2013-02-28 at 08:01 -0800, Bradley M. Froehle wrote: > > cdef extern from "test.h": > int* foo2ptr "&foo" () > > cdef int *x = foo2ptr() Thank you for this interesting suggestion, but I must be missing something, because when I do the following: cdef extern from "token

Re: [Cython] Be more forgiving about memoryview strides

2013-02-28 Thread Robert Bradshaw
On Thu, Feb 28, 2013 at 7:13 AM, Sebastian Berg wrote: > Hey, > > Maybe someone here already saw it (I don't have a track account, or I > would just create a ticket), but it would be nice if Cython was more > forgiving about contiguous requirements on strides. In the future this > would make it ea

Re: [Cython] Class methods returning C++ class references are not dealt with correctly?

2013-02-28 Thread Bradley M. Froehle
On Thu, Feb 28, 2013 at 4:58 AM, Yury V. Zaytsev wrote: > Hi, > > I'm sorry if my question would appear to be trivial, but what am I > supposed to do, if I want to wrap class methods, that return a reference > to another class? As a workaround you could use: cdef extern from "test.h": int*

[Cython] Be more forgiving about memoryview strides

2013-02-28 Thread Sebastian Berg
Hey, Maybe someone here already saw it (I don't have a track account, or I would just create a ticket), but it would be nice if Cython was more forgiving about contiguous requirements on strides. In the future this would make it easier for numpy to go forward with changing the contiguous flags to

Re: [Cython] MemoryViews require writeable arrays?

2013-02-28 Thread Sturla Molden
On 28.02.2013 15:55, Dave Hirschfeld wrote: So the issue is that at present memoryviews can't be readonly? https://github.com/cython/cython/blob/master/Cython/Compiler/MemoryView.py#L33 Typed memoryviews are thus acquired with the PyBUF_WRITEABLE flag. If the the assigned buffer is readonly,

Re: [Cython] Class methods returning C++ class references are not dealt with correctly?

2013-02-28 Thread Sturla Molden
On 28.02.2013 15:46, Yury V. Zaytsev wrote: My method call is actually wrapped in a try { ... } catch clause, because I declared it as being able to throw exceptions, so the reference can't be defined in this block, or it will not be accessible to the outside world. If Cython generates illegal

Re: [Cython] MemoryViews require writeable arrays?

2013-02-28 Thread Dave Hirschfeld
Sturla Molden writes: > > On 27.02.2013 20:05, Dave Hirschfeld wrote: > > > Is this a required restriction? Is there any workaround? > > http://www.python.org/dev/peps/pep-3118/ > > What you should consider is the "readonly" field in "struct bufferinfo" > or the access flag "PyBUF_WRITEABLE"

Re: [Cython] Class methods returning C++ class references are not dealt with correctly?

2013-02-28 Thread Yury V. Zaytsev
On Thu, 2013-02-28 at 15:34 +0100, Sturla Molden wrote: > > This is clearly a bug in Cython. One cannot let a C++ reference > dangle. Hi Sturla, Thanks for the confirmation! I had a closer look at it, and I think I know why this happens. My method call is actually wrapped in a try { ... } catch

Re: [Cython] Class methods returning C++ class references are not dealt with correctly?

2013-02-28 Thread Sturla Molden
On 28.02.2013 13:58, Yury V. Zaytsev wrote: Hi, I'm sorry if my question would appear to be trivial, but what am I supposed to do, if I want to wrap class methods, that return a reference to another class? From reading the list, I've gathered that apparently the best strategy of dealing with r

Re: [Cython] MemoryViews require writeable arrays?

2013-02-28 Thread Sturla Molden
On 27.02.2013 20:05, Dave Hirschfeld wrote: Is this a required restriction? Is there any workaround? http://www.python.org/dev/peps/pep-3118/ What you should consider is the "readonly" field in "struct bufferinfo" or the access flag "PyBUF_WRITEABLE". In short: A PEP3118 buffer can be r

[Cython] Class methods returning C++ class references are not dealt with correctly?

2013-02-28 Thread Yury V. Zaytsev
Hi, I'm sorry if my question would appear to be trivial, but what am I supposed to do, if I want to wrap class methods, that return a reference to another class? >From reading the list, I've gathered that apparently the best strategy of dealing with references is just to not to use them (convert

[Cython] MemoryView Casting slow compared to ndarray buffer syntax

2013-02-28 Thread Dave Hirschfeld
%%cython cimport cython import numpy as np cimport numpy as np ctypedef np.float64_t float64_t @cython.boundscheck(False) @cython.wraparound(False) @cython.cdivision(True) def echo_numpy(np.ndarray[float64_t, ndim=1] x): return x @cython.boundscheck(False) @cython.wraparound(False) @cython.

Re: [Cython] Non-deterministic behavoiur?

2013-02-28 Thread Dave Hirschfeld
Dave Hirschfeld writes: > > Dave Hirschfeld writes: > > > > > Using the following test code: > > > > > So, it seems either typing the array as a memview or printing res > > will screw up the calculation. > > > > The cython code is given below. Any ideas if this is a cython bug or somethin

[Cython] About IndexNode and unicode[index]

2013-02-28 Thread ZS
Looking into IndexNode class in ExprNode.py I have seen a possibility for addition of more fast code path for unicode[index] as it done in method `generate_setitem_code` in case of lists. This is files for evaluation of performance difference: unicode_index.h /* This is striped version of

Re: [Cython] Non-deterministic behavoiur?

2013-02-28 Thread Dave Hirschfeld
Dave Hirschfeld writes: > > Using the following test code: > > So, it seems either typing the array as a memview or printing res > will screw up the calculation. > > The cython code is given below. Any ideas if this is a cython bug or > something > I'm doing wrong? > > Thanks, > Dave > T