[Cython] Fused Types
Greg Ewing
greg.ewing at canterbury.ac.nz
Wed May 4 23:53:30 CEST 2011
Dag Sverre Seljebotn wrote:
> 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.
Seems to me that's more because generating lots of versions
of a function in C is hard work, and the designers of BLAS
didn't think it was worth providing more than two versions.
If they'd had a tool that would magically generate all the
combinations for them, they might have made a different choice.
What you seem to be trying to do here is enable compile-time
duck typing, so that you can write a function that "just works"
with a variety of argument types, without having to think
about the details.
With that mindset, seeing a function declared as
cdef func(floating x, floating y)
one would expect that x and y could be independently chosen
as any of the types classified as "floating", because that's
the way duck typing usually works. For example, if a Python
function is documented as taking two sequences, you expect
that to mean *any* two sequences, not two sequences of the
same type.
>
> 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.
What I'm suggesting doesn't have the full power of C++ templates
either, because the range of possible values for each type
parameter would still have to be specified in advance. However,
it makes the dependencies between the type parameters explicit,
rather than being hidden in some rather unintuitive implicit rules.
> 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?
I'm not sure that would help much. Reaching good decisions about
things like this requires time to think through all the issues.
--
Greg
More information about the cython-devel
mailing list