On Aug 17, 2008, at 12:23 AM, Dag Sverre Seljebotn wrote: > I'm not sure what you mean -- a negative bound is only checked for > once per dimension. I.e. Positive ints are only checked for > negativity once per dim. > > (Remember that one must also check for the negative bound, i.e. -n, > but this is only done for negative numbers).
I am talking about the case where bounds checking is turned off, and "once per dimension" is relatively expensive. Even when it predicts correctly it still does the test. I've got some code using 2D buffers in the inner loop. Here's the timings: CPU time: 1.50 s, Wall time: 1.52 s -- standard buffers CPU time: 1.00 s, Wall time: 1.01 s -- boundscheck=False CPU time: 0.77 s, Wall time: 0.78 s -- unsigned indices (Note, I'm not even going to time the non-buffer version, but its certainly on the order of minutes--buffers are awsome!). > There is potential for optimizing the exceptional case when bounds > are off (but the code would be a little less clean and exceptional > cases are just that). > > Could you perhaps post some C code modified as you suggest? Essentially it's the C code one gets if one manually casts the indices to unsigned ints. It's just that that makes the code significantly uglier. > Finally, if what you propose is a change in semantics, then this > already met resistance on the numpy list. Perhaps a buffer-unsigned- > indices-only compiler directive. I was thinking of the case that bounds checking is turned off, in which case we already have a change in semantics, right? I could see this being a distinct compiler directive though, that's probably the way to go. > (However I think that it is possible to write your code using > unsigneds so that you use unsigned everywhere instead of signed, > and then this comes automatically...) > > I don't care too much about constants, they're not likely to be > used in performance critical code I think. Constants will be optimized away. But if I write "i+1" where i is an unsigned int, the result is still signed. > > Dag Sverre Seljebotn > > -----Original Message----- > From: Robert Bradshaw <[EMAIL PROTECTED]> > Date: Sunday, Aug 17, 2008 6:55 am > Subject: [Cython] Boundchecking question > To: Cython-dev <[email protected]>Reply-To: cython- > [EMAIL PROTECTED] > > I've been playing with the (very cool!) buffer stuff Dag did getting >> ready for the SciPy conference. I've seen a 20% increase in speed not >> adjusting for negative indices, but making sure the indices are >> unsigned is a pain (especially if there is arithmetic involved). One >> proposal that has been brought up is to make positive integer >> constants unsigned, which could lead to complications elsewhere and >> would still require care. Another proposal that I'd like to throw out >> there is to have negative index realigning part of bounds checking, >> i.e. negative indices are not checked for if bounds checking is off. >> >> Thoughts? >> >> - Robert >> >> _______________________________________________ >> Cython-dev mailing list >> [email protected] >> http://codespeak.net/mailman/listinfo/cython-dev >> > > _______________________________________________ > Cython-dev mailing list > [email protected] > http://codespeak.net/mailman/listinfo/cython-dev _______________________________________________ Cython-dev mailing list [email protected] http://codespeak.net/mailman/listinfo/cython-dev
