[Cython] bug in doc Tutorials/Working with NumPy

Stepan Kasal kasal at ucw.cz
Fri Nov 6 10:18:50 EST 2015


I was learning Cython from this tutorial when I noticed a glitch:

Near the end, after boundscheck False, some variables are changed to 
unsigned int.  But this has unexpected consequences: variables t_from and such
are not determined correctly, as one of the arguments is negative, but gets
cast to unsigned for comaprison.  (Yes, this is a weird feature of C.)

Actually, the use of unsigned does not seem to have any impact on performance,
so I suggest to scratch that part of tutorial.  Just explain that with boundscheck
off, negaitive indices no longer work.

(But there might perhaps be one small improvent in cython itself: with boundscheck
off, the index might be cast to unsigned before it is used:  this way we probably
crash on negative values, instead of silently accessing the negative offset of 
the array data.)

Thank you for nice piece of software,
	Stepan Kasal

More information about the cython-devel mailing list