[PYTHON MATRIX-SIG] casting and default types
Hinsen Konrad
hinsenk@ere.umontreal.ca
Tue, 7 Nov 1995 16:02:56 -0500
Actually, this is not true. There are some places where coersion
takes place automatically, but there are lot's of places where it
doesn't. In the case of numbers, witness the float() and int()
functions. Similarly, lists are not automatically converted to tuples
I can't imagine a need for float() and int() except in order to
"downgrade" a number. In all mathematical operations where floats
are required, I can just as well use ints. Lists and tuples are
another problem, of course.
My point of view is that as far as coercion is concerned, matrices
should behave just like scalars of the same type(s).
It's not just a matter of performance. It is also a matter of
correctness in some cases.
I don't understand. The choice is automatic coercion or none at all,
i.e. throwing an exception for mixed-type operations. I don't see
how one or the other can lead to a wrong result; it's either the
correct result or no result.
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...
Also, I'd expect users to be familiar with coercion. I haven't
made a survey, but I'd claim that most languages have coercion
between numerical types, similar to Python. That's certainly
true for the languages most used for numerical work.
I'd be much more in favor of having different kinds of matrices that
automagically coerce, if people really want this.
Which creates some question and probably a lot of confusion.
What happens if coercing and non-coercing matrices are combined?
What happens if a function written for one type of matrices
is used with the other? How can the matrices be distinguished
in output?
-------------------------------------------------------------------------------
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
=================