[PYTHON MATRIX-SIG] type coercion one more time

James Hugunin jjh@Goldilocks.LCS.MIT.EDU
Thu, 25 Jan 96 08:13:02 EST


I've been working to design a stable version of automatic type
coercion that everybody (including myself) can be happy with.  The
following is what I have.  Much of this is in line with the C rules
for type coercion (at least according to my old K&R).  I will use the
standard C type names (double means a python float).

Only the following three automatic coercions are allowed:

1) Any integer type can be coerced to a float, a double, a complex float or
a complex double.

2) A float can only be coerced to a complex float.

3) A double can only be coerced to a complex double.

Explanation:

The following type hierarchy is assumed:

INTEGER < FLOAT < COMPLEX

Within each level there are a number of possible precisions.  No
automatic coercion will take place between these precisions.

This remains completely consistent with the existing python automatic
type coercion.

Examples:

a_t = array([x,y,z,...], 't') # Where t is a legal typecode

1 - signed byte
l - long
f - float
d - double
F - complex float
D - complex double

a_l * a_d = a_d
a_f * a_l = a_f
a_f * a_d = TypeError Exception raised
a_d * a_D = a_D
a_1 * a_l = TypeError Exception raised

Comments? - Jim




=================
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================