[Cython] Cython code producing different, incorrect results under Python 2.7 (not 3.x) under Cython 0.19

Nikita Nemkin nikita at nemkin.ru
Wed Apr 24 09:48:13 CEST 2013


On Wed, 24 Apr 2013 13:33:46 +0600, Nikita Nemkin <nikita at nemkin.ru> wrote:

Update: this is not a Cython bug.
_mcp.pyx declares #cython: wraparound=False, any negative index is expected
to fail.
It worked previously because Cython was using PySequence_GetSlice
which of course is not sensitive to Cython directives.

The only "fix" would be to produce a warning for constant negative indexes  
in
wraparound=False mode.


Best regards,
Nikita Nemkin


> On Wed, 24 Apr 2013 12:19:36 +0600, Stefan Behnel <stefan_ml at behnel.de>  
> wrote:
>
> The bug is here (at least one of them):
> https://github.com/scikit-image/scikit-image/blob/master/skimage/graph/_mcp.pyx#L179
> "shape[:-1]" returns incorrect result: input (8, 8), expected output  
> (8,),
> actual output ().
>
> I guess that means something is wrong with __Pyx_PyObject_GetSlice  
> utility,
> although I wasn't able to create a simple repro yet.
>
>
> Best regards,
> Nikita Nemkin
>
>
>> Hi,
>>
>> Josh Warner, 24.04.2013 08:06:
>>> Over in scikit-image we have traced an odd problem with a particular  
>>> Cython
>>> file to the 0.19 update of Cython. From at least Cython 0.15.1  
>>> (probably
>>> earlier) through 0.18, `_mcp.pyx` in `skimage.graph` compiled and  
>>> executed
>>> correctly, passing all package tests on both Python 2.7 and Python 3.
>>>
>>> After 0.19 was released and the Travis builds began using it, we began
>>> getting 100% repeatable errors from the previously clean master branch
>>> (example of an otherwise clean Python
>>> 2.7<https://travis-ci.org/scikit-image/scikit-image/jobs/6545505>Travis
>>> build; the
>>> Python 3 build  
>>> passed<https://travis-ci.org/scikit-image/scikit-image/builds/6545504>all
>>> tests). All of these errors/failures trace back to this Cython file.
>>> Oddly, the errors only happen on Python 2.7; our Python 3 Travis build
>>> passes.
>>>
>>> We are discussing this issue in scikit-image Github Issue
>>> #534<https://github.com/scikit-image/scikit-image/issues/534>;
>>> feel free to join the discussion there.
>>>
>>> The .pyx Cython file is located
>>> here<https://github.com/scikit-image/scikit-image/blob/master/skimage/graph/_mcp.pyx>and
>>> it has
>>> an associated .pxd file
>>> here<https://github.com/scikit-image/scikit-image/blob/master/skimage/graph/_mcp.pxd>.
>>> It should be noted the file compiles and executes without errors, but  
>>> its
>>> output is now incorrect in Python 2.x.
>>>
>>> In case the compiled results might be relevant, for your diffing  
>>> pleasure here
>>> is the compiled .c file from Cython
>>> 0.18<https://gist.github.com/JDWarner/af4f8ea85dce356ce95c>which
>>> passes all tests on both Python 2.7 and Python 3.x, while here
>>> is the compiled .c file from Cython
>>> 0.19<https://gist.github.com/JDWarner/56d15b7a7527b8d4314e>which
>>> produces different, incorrect results in Python 2.7.
>>>
>>> In the short term we are temporarily forcing Travis to use the 0.18  
>>> release
>>> of Cython, but that isn't a viable long term solution.
>>>
>>> It's possible the error is on our end, but seeing as it worked with  
>>> prior
>>> Cython releases we'd appreciate you taking a look.
>>
>> Thanks for bringing this up. You could make it a little easier for us by
>> pointing us at the code that produces the incorrect results you are
>> experiencing. The set of failing tests seems to be quite small, but  
>> before
>> we start digging through your code, I'm sure you can provide pointers to
>> the relevant code snippets for a couple of these tests (i.e. the test  
>> code
>> itself and the major code parts that produce the results) much more  
>> quickly.
>>
>> Stefan
>>
>> _______________________________________________
>> cython-devel mailing list
>> cython-devel at python.org
>> http://mail.python.org/mailman/listinfo/cython-devel


More information about the cython-devel mailing list