[Cython] Fused Types
Robert Bradshaw
robertwb at math.washington.edu
Wed May 4 03:00:05 CEST 2011
On Tue, May 3, 2011 at 4:40 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> 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
That's an idea, it is nice and explicit without being too verbose. Any
thoughts on how one would define one's own "floating?"
I presume one then use a Vector[F] inside of func2[floating F]?
- Robert
More information about the cython-devel
mailing list