[PYTHON MATRIX-SIG] casting and default types

Jim Fulton, U.S. Geological Survey jfulton@usgs.gov
Tue, 07 Nov 1995 15:46:35 -0500

First of all, I want to apologize for not participating in this list
much lately.  I've been buried in a project here and haven't had time
to keep up.

On Tue, 7 Nov 1995 14:43:37 -0500 
Hinsen Konrad said:
>    The current instantiation (and lack of coercion) system is Jim Fulton's  
>    (more or less) and he could do a much better job of defending it than me.   
>    The principle issue is that automatic type coercions can hide bugs.  The  
> Whether or not coercion is a good idea is an old argument, but
> for Python it has long been decided: Python has coercion, and
> not having it for matrices would be simply inconsistent.

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
in many places where tuples are required.  And so on.
>    other issue is that automatic coercion can hide efficiency problems.  If I  
>    have a vector of ints that I'm frequently going to have to multiply by  
>    different vectors of floats, then it would be much more efficient for me to  
>    convert it to a vector of floats one time.  If I have automatic type  
> I'd suppose that people who need the highest possible performance
> are aware of this problem and are watching out for it. There
> is a profiler for Python that can help find such problems. I don't
> see this as a valid reason Python inconsistent and most users'
> life more difficult.

It's not just a matter of performance.  It is also a matter of
correctness in some cases.  
>    This is why I mentioned this issue as something that might be amenable to  
>    some sort of flag in the same way that IEEE exceptions could be (I was just  
> That's of course a possible solution, if someone thinks this
> is really important.

Global variables are evil.

I'd be much more in favor of having different kinds of matrices that
automagically coerce, if people really want this.

I have to bring myself up to date on the in's and outs of this coersion
issue.  I think my objection to Jim's original coersion proposal had to
do with ranks, more than the actual data types.  There are certainly
situations where coersion makes sense.  For example, in my Fortran
interface, FIDL, I automatically convert between argument and expected
numeric element types.


MATRIX-SIG  - SIG on Matrix Math for Python

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