[Cython] Fused Types
Greg Ewing
greg.ewing at canterbury.ac.nz
Wed May 4 01:40:17 CEST 2011
Dag Sverre Seljebotn wrote:
> ctypedef fused_type(float, double) speed_t
> ctypedef fused_type(float, double) acceleration_t
>
> then you get 4 specializations.
>
> ctypedef speed_t acceleration_t
>
> I guess only 2 specializations.
>
> Treating the typedefs in this way is slightly fishy of course.
Indeed. This whole business seems rather too implicit to
me. I think I'd rather have explicit type parameters in
some form. Maybe
cdef func2[floating F](F x, F y):
# 2 specialisations
cdef func4[floating F, floating G](F x, G y):
# 4 specialisations
This also makes it clear how to refer to particular
specialisations: func2[float] or func4[float, double].
Pointers are handled in a natural way:
cdef funcfp[floating F](F x, F *y):
# 2 specialisations
It also extends naturally to fused types used in other
contexts:
cdef struct Vector[floating F]:
F x, y, z
--
Greg
More information about the cython-devel
mailing list