[Matrix-SIG] Numeric Nits

Rick White rlw@stsci.edu
Wed, 23 Jun 1999 17:12:07 -0400 (EDT)


Tim Hochberg wrote:

% Would it be possible and/or desirable to just have this special type modify
% the ways it casts scalars and not other arrays. For example, to behave as:
% 
% >>> a = arange(5, 'f2')
% >>> 5 * a
% array([0,5,10,15,20], 'f2')
% >>> arange(5, 'd') * a
% array([0,1,4,9,16], 'd')
%
% Or is that even more confusing....

I think it would be simpler both to implement and to understand if
there was just a 'd2' datatype that is above 'd' and if the promotion
hierarchy is defined so that binary operations between 'f2' and 'd' get
promoted to 'f2', but binary operations between 'f2' and 'd2' get
promoted to 'd2'.

Python scalars would get turned into arrays of type 'd', and everything
would work just fine (he said optimistically.)

I figured if such a second hierarchy were defined, for my applications
I would *always* use the higher types 'f2', 'd2', 'i2' etc. for every
array I create.  Then the effect would be what you want, which is that
scalars would not cause promotion.

I can see some tricky issues though involving scalar floats (type 'd')
and non-promoting integers (type 'i2').  I think I want this behavior:

>>> a = arange(5,'i2')
>>> a
array([0,5,10,15,20], 'i2')
>>> a*3.14
array([0,5,10,15,20], 'f2')

I.e. a 'd' scalar gets converted to type 'f2' when it is used with any
type 2 Numeric array except for type 'd2'.  I can imagine it may be
hard to define this behavior so everyone agrees on it.