[Cython] Fused Types

mark florisson markflorisson88 at gmail.com
Wed May 4 10:47:27 CEST 2011


On 4 May 2011 10:24, Dag Sverre Seljebotn <d.s.seljebotn at astro.uio.no> wrote:
> On 05/04/2011 01:07 AM, Greg Ewing wrote:
>>
>> mark florisson wrote:
>>
>>> cdef func(floating x, floating y):
>>> ...
>>>
>>> you get a "float, float" version, and a "double, double" version, but
>>> not "float, double" or "double, float".
>>
>> It's hard to draw conclusions from this example because
>> it's degenerate. You don't really need multiple versions of a
>> function like that, because of float <-> double coercions.
>>
>> A more telling example might be
>>
>> cdef double dot_product(floating *u, floating *v, int length)
>>
>> By your current rules, this would give you one version that
>> takes two float vectors, and another that takes two double
>> vectors.
>>
>> But if you want to find the dot product of a float vector and
>> a double vector, you're out of luck.
>
> First, I'm open for your proposed syntax too...But in the interest of seeing
> how we got here:
>
> The argument to the above goes that you *should* be out of luck. For
> instance, talking about dot products, BLAS itself has float-float and
> double-double, but not float-double AFAIK.
>
> What you are saying that this does not have the full power of C++ templates.
> And the answer is that yes, this does not have the full power of C++
> templates.
>
> At the same time we discussed this, we also discussed better support for
> string-based templating languages (so that, e.g., compilation error messages
> could refer to the template file). The two are complementary.
>
> Going back to Greg's syntax: What I don't like is that it makes the simple
> unambiguous cases, where this would actually be used in real life, less
> readable.
>
> Would it be too complicated to have both? For instance;
>
>  i) You are allowed to use a *single* fused_type on a *function* without
> declaration.
>
> def f(floating x, floating *y): # ok
>
> Turns into
>
> def f[floating T](T x, T *y):
>
> This is NOT ok:
>
> def f(floating x, integral y):
> # ERROR: Please explicitly declare fused types inside []
>
>  ii) Using more than one fused type, or using it on a cdef class or struct,
> you need to use the [] declaration.
>

I don't think it would be too complicated, but as you mention it's
probably not a very likely case, and if the user does need it, a new
(equivalent) fused type can be created. The current way reads a lot
nicer than the indexed one in my opinion. So I'd be fine with
implementing it, but I find the current way more elegant.

> Finally: It is a bit uncomfortable that we seem to be hashing things out
> even as Mark is implementing this. Would it be feasible to have a Skype
> session sometimes this week where everybody interested in the outcome of
> this come together for an hour and actually decide on something?
>
> Mark: How much does this discussion of syntax impact your development? Are
> you able to treat them just as polish on top and work on the "engine"
> undisturbed by this?

Thanks for your consideration, I admit it it feels a bit uncomfortable
:) But at least this change shouldn't have such a big impact on the
code, it would mean some changes in a select few places, so it's
definitely polish. In any event, before we settle on this, I'd like to
do the cpdef support first and work on indexing from Python space, so
I think we have enough time to settle this argument on the ML.
Before that, I'm just going to finish up for a pull request for the
OpenMP branch, I'd like to see if I can get rid of some warnings.

> Dag Sverre
> _______________________________________________
> cython-devel mailing list
> cython-devel at python.org
> http://mail.python.org/mailman/listinfo/cython-devel
>


More information about the cython-devel mailing list