[PYTHON MATRIX-SIG] type coercion one more time
Guido van Rossum
guido@CNRI.Reston.VA.US
Thu, 25 Jan 1996 11:27:05 -0500
> > No automatic coercion will take place between these precisions.
>
> This surprises me (especially since C does support float -> double
> coercions). Would you care to explain it?
>
> Naive users of the system are only expected to use arrays of longs,
> doubles, and complex doubles. I wanted to make sure that all of the
> automatic coercion rules would work for these most frequently used
> types so that they'll work just like the corresponding python scalars.
>
> On the other hand, I see the other types as being used for cases where
> the programmer really wants to use a particular precision, ie. 2-byte
> integers for dealing with 16-bit sound data. In a case like this it
> seems decidely unfriendly to automatically coerce to another
> precision.
>
> One can imagine dividing each sample in a sound by 2, and then trying
> to play it back and hearing garbage because it got automatically
> converted to an array of longs during the division.
I see your point, but I am uneasy with the solution. Shouldn't there
be a "divide in place" operation for this case that coerces constants
the other way? (I haven't followed all the details -- you may have it
already or you may have a good reason for not having it.)
I guess that you also don't check for overflow on such operations --
suppose I multiply each sample by 2 and it doesn't fit... This is
also different than Python's own numeric operations, but again I can
see the reason why (and I don't object in this case).
I guess I won't complain too loudly as long as you also have a way to
coerce an array of shorts into an array of longs.
(BTW, on 64-bit machines, there are three relevant int sizes. Do you
support this?)
> I do have one other possible set of rules that I would be happy with.
> These are basically the same as the last post, except:
>
> 4) Coercion to a higher precision is allowed within the main
> groupings.
>
> 5) The precision of a python scalar is allowed to change to match the
> other arguments (3.14 can be either a float or a double depending on
> which one is "desired").
Some examples, please? Where else is coercion applied? It does sound
like it could be a good compromise.
> I don't like this rule, but without it I think that it is too easy to
> get bitten by python scalars when writing "real" code.
Agreed.
> Does this make sense?
>
> Do people prefer this revised scheme?
I'm not sure. More input, please...
--Guido van Rossum <guido@CNRI.Reston.VA.US>
URL: <http://www.python.org/~guido/>
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================