[PYTHON MATRIX-SIG] casting and default types

Hinsen Konrad hinsenk@ere.umontreal.ca
Wed, 8 Nov 1995 09:32:01 -0500

   > My point of view is that as far as coercion is concerned, matrices
   > should behave just like scalars of the same type(s).

   But what you are unwilling to believe is that scalars do not always
   coerce automatically.

Not at all. I am just saying that if coercion is applied to a certain
combination of scalar types, then the same coercion should be applied
to arrays of the same type.

As to which coercions should occur automatically, I'd say that int ->
float -> complex should be automatic, but the reverse not, because it
leads to an essential loss of information (int ->float can
occasionally lead to a loss of precision, depending on how long the
representations of int and float are, but I can live with that).

   > Of course there is some chance of making a mistake and not noticing
   > it due to automatic coercion, but then you already have the same
   > risk with scalars. Besides, I just can't think of a reasonable
   > example...

   OK, how about this:

     1 / 2 * 2

   as opposed to:

     1 / 2.0 * 2

That's indeed a problem, but (in my point of view) not one caused by
coercion, but by the unfortunate fact that / denotes quite different
operations for integers and for floats.

   There was discussion in the Python list a while back about problems
   caused by a new feature that automatically coerced floating point
   values passed to functions expecting integer arguments.  Guido even
   expressed regret at being talked into adding the feature.  Check the
   list archive for details.

I didn't know about that feature, and I certainly don't like it (see

   As I said in my other note, I object less to coersion of element types
   that to coersion of ranks.

What exactly do you mean by "coercion of ranks"?

Konrad Hinsen                     | E-Mail: hinsenk@ere.umontreal.ca
Departement de chimie             | Tel.: +1-514-343-6111 ext. 3953
Universite de Montreal            | Fax:  +1-514-343-7586
C.P. 6128, succ. Centre-Ville     | Deutsch/Esperanto/English/Nederlands/
Montreal (QC) H3C 3J7             | Francais (phase experimentale)

MATRIX-SIG  - SIG on Matrix Math for Python

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