Greg Ewing wrote:
> Dag Sverre Seljebotn wrote:
>
>> This is hardly satisfying, and SOME kind of solution is needed here. If
>> only to prevent subtle bugs from mixing types from numpy.pxd with other
>> types in arithmetic!
>
> If you do this, you might like to consider a syntax
> I suggested earlier:
>
> ctypedef some int foo
> ctypedef some float bar
>
> etc.
Good idea!
Here's another worse-looking but more featureful alternative:
cdef extern from *:
ctypedef rank("mylib", 3) smallint
ctypedef rank("mylib", 4) largeint
This way one can create groups of ranked types. Arithmetic is allowed
within a group (adding smallint and largeint will result in largeint), but
not from one group to another (i.e. adding an "largeint" and a "long"
requires a cast or gives syntax error).
Internally, short, int, long etc. would be defined rank("c", x), and one
could then also support C99 int32_t, int64_t etc. as rank("c99", x).
Of course, there's no harm in making "some" an alias for a new rank-group
with only one element.
> Some thoughts on implementation:
>
> * Treat it as having a rank higher than any known
> rank for that kind. That way arithmetic etc. between
> known and unknown sizes will get promoted to an
> unknown size.
This would be a bad idea for some of the NumPy types which are unknown yet
very short. I'd prefer to require an explicit cast from one "side" to the
other.
> * Only allow it to be introduced via a typedef, so
> that generated code always has a named type for the
> C compiler to go on.
Definitely.
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev