[Cython] Fused Types
markflorisson88 at gmail.com
Fri Apr 29 11:30:19 CEST 2011
On 29 April 2011 11:03, Pauli Virtanen <pav at iki.fi> wrote:
> Fri, 29 Apr 2011 10:23:55 +0200, mark florisson wrote:
>> Ok, branching on the type sounds fine to me. It brings one problem
>> though: because you cannot declare the variables of your variable type
>> (the type of say, mystruct.attrib), you will need to do multiple
>> declarations outside of your branches. So in my example:
>> cdef func(struct_t mystruct, int i):
>> cdef string_t string_var
>> cdef int int_var
>> if typeof(mystruct) is typeof(int):
>> int_var = mystruct.attrib + i
>> string_var = mystruct.attrib + i
>> But this is probably not a common case, so likely not an issue.
> Are you planning to special-case the "real_t complex" syntax? Shooting
> from the sidelines, one more generic solution might be, e.g.,
I'm sorry, I'm not sure what syntax you are referring to. Are you
talking about actual complex numbers?
> ctypedef cython.fused_type(A, B) struct_t
> ctypedef cython.fused_type(float, double, paired=struct_t) real_t
> ctypedef cython.fused_type(int_t, string_t, paired=struct_t) var_t
> and just restrict the specialization to cases that make sense.
The paired means you're declaring types of attributes?
> Pauli Virtanen
> cython-devel mailing list
> cython-devel at python.org
More information about the cython-devel