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.


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?

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

Reply via email to