[PYTHON MATRIX-SIG] type coercion one more time
Perry A. Stoll
stoll@atr-sw.atr.co.jp
Fri, 26 Jan 1996 01:33:59 +0900
>>>>> "JH" == James Hugunin <jjh@Goldilocks.LCS.MIT.EDU> writes:
JH> From: Guido van Rossum <guido@CNRI.Reston.VA.US>
>> No automatic coercion will take place between these precisions.
JH> This surprises me (especially since C does support float ->
JH> double coercions). Would you care to explain it?
JH> Naive users of the system are only expected to use arrays of
JH> longs, doubles, and complex doubles. I wanted to make sure
JH> that all of the automatic coercion rules would work for these
JH> most frequently used types so that they'll work just like the
JH> corresponding python scalars.
JH> On the other hand, I see the other types as being used for
JH> cases where the programmer really wants to use a particular
JH> precision, ie. 2-byte integers for dealing with 16-bit sound
JH> data. In a case like this it seems decidely unfriendly to
JH> automatically coerce to another precision.
JH> One can imagine dividing each sample in a sound by 2, and then
JH> trying to play it back and hearing garbage because it got
JH> automatically converted to an array of longs during the
JH> division.
JH> I do have one other possible set of rules that I would be
JH> happy with. These are basically the same as the last post,
JH> except:
JH> 4) Coercion to a higher precision is allowed within the main
JH> groupings.
JH> 5) The precision of a python scalar is allowed to change to
JH> match the other arguments (3.14 can be either a float or a
JH> double depending on which one is "desired").
JH> Do people prefer this revised scheme?
So you try to coerce a scalar to the type of the matrix, using
the same idea as in 4)? Is the following right?
Array_SomeIntType * AnyIntType = Array_SomeIntType
Array_SomeIntType * SomeFloatType =? Array_SomeFloatType
Array_SomeFloatType * AnyIntType =? Array_SomeFloatType
Array_SomeFloatType * OtherFloatType = Array_SomeFloatType
That seems pretty reasonable. Do the '=?' cases sound ok? It should
preserve coercions with the normal Python types. Users of specialized
C type multiarrays must exercise a bit of caution that they don't
cause overflow, but that isn't unreasonable.
-Perry
=================
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================