[Cython] Prototype for parametrized types
Dag Sverre Seljebotn
dagss at student.matnat.uio.no
Mon Mar 10 23:16:00 CET 2008
I can see that my syntax will conflict with optionally parametrized types. An approach (but I'll admit ot is getting a bit convoluted):
- numpy.ndarray(numpy.uint8, 2, arr) converts arr to the given type. Ie mix xompile-time and runtime params (but only the Cython developers need to care, an UnsupportedAtRuntimeError will be customary anyway...)
- if missing the value parameter, a constructor os returned instead, so
def foo(a : ndarray(uint8, 2))
has the same meaning as the (also legal)
def foo(a):
tmptype = ndarray(uint8, 2)
a = tmptype(a)
BTW, there's my suggestion for a Pythonic typedef as well.
- The auto-converted argument mechanism can always pass "value" by name for extra safety.
This really make it feel like a Python library and has no learning curve for experienced Python users? C library writers can keep the old syntax of course.
Dag Sverre
More information about the Cython-dev
mailing list