[Numpy-discussion] On my Cython/NumPy project
Sat Jun 21 18:51:02 CDT 2008
On Sat, Jun 21, 2008 at 18:45, Anne Archibald <firstname.lastname@example.org> wrote:
> 2008/6/21 Robert Kern <email@example.com>:
>> On Sat, Jun 21, 2008 at 17:08, Anne Archibald <firstname.lastname@example.org> wrote:
>>> My suggestion is this: allow negative indices, accepting the cost in
>>> tight loops. (If bounds checking is enabled, the cost will be
>>> negligible anyway.) Provide a #pragma allowing the user to assert that
>>> a certain piece of code uses no negative indices.
>> Instead of a #pragma, you could rely on the type of the index. If it
>> is unsigned, you can do the fast path; if it is signed, you need to
>> check for and handle potential negatives.
> Cute! And then it's easy to make "for i in range(n)" produce unsigned
> results with no effort on the part of the user.
Not entirely. You still need to declare "cdef unsigned int i". Cython
does not translate the for loop into fast C unless if the variable has
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the Numpy-discussion