[Numpy-discussion] On my Cython/NumPy project

Dag Sverre Seljebotn dagss@student.matnat.uio...
Sat Jun 21 01:59:25 CDT 2008

Dag wrote:
> General feedback is welcome; in particular, I need more opinions about
> what syntax people would like. We seem unable to find something that we
> really like; this is the current best candidate (cdef is the way you
> declare types on variables in Cython):
> cdef int i = 4, j = 6
> cdef np.ndarray[np.float64, 2] arr = np.zeros((10, 10), dtype=np.float64)
> arr[i, j] = 1
> ...

Some more important points:
- There will likely be a compiler flag (and perhaps per-block or
per-variable pragmas) on whether bounds-checking is done or not)
- It doesn't look like negative indices will be supported in this mode, as
it adds another branch in potentially very tight loops. Opinions on this
are welcome though. In safe mode, bounds checking will catch it, while in
unsafe mode it will at best segfault and at worst corrupt data.

The negative indices thing is potentially confusing to new users. Pex uses
a different syntax (arr{i, j} for efficient array lookups) partly to make
this fact very explicit. Thoughts?

Dag Sverre

More information about the Numpy-discussion mailing list