[Numpy-discussion] Poll: Semantics for % in Cython

Stéfan van der Walt stefan@sun.ac...
Thu Mar 12 16:41:54 CDT 2009

Hi Dag

2009/3/12 Dag Sverre Seljebotn <dagss@student.matnat.uio.no>:
> (First off, is it OK to continue polling the NumPy list now and then on
> Cython language decisions? Or should I expect that any interested Cython
> users follow the Cython list?)

Given that many of the subscribers make use of the NumPy support in
Cython, I don't think they would mind; I, for one, don't.

> In Python, if I write "-1 % 5", I get 4. However, in C if I write "-1 %
> 5" I get -1. The question is, what should I get in Cython if I write (a
> % b) where a and b are cdef ints? Should I
> [ ] Get 4, because it should behave just like in Python, avoiding
> surprises when adding types to existing algorithms (this will require
> extra logic and be a bit slower)

I'd much prefer this option.  When students struggle to get their code
faster, my advice to them is: "run it to Cython, and if you are still
not happy, start tweaking this and that".  It would be much harder to
take that route if you had to take a number of exceptional behaviours
into account.

> (Orthogonal to this, we can introduce compiler directives to change the
> meaning of the operator from the default in a code blocks, and/or make
> special functions for the semantics that are not chosen as default.)

In my experience, keeping the rules simple has a big benefit (the
"programmer's brain cache" can only hold a small number of items -- a
very good analogy made by Fernando Perez), so I would prefer not to
have this option.


More information about the Numpy-discussion mailing list