[Matrix-SIG] Numeric Nits

Tim Hochberg tim.hochberg@ieee.org
Tue, 22 Jun 1999 16:54:19 -0600


Two thought regarding promotions of scalars to zeros sized arrays of
doubles:

First, perhaps the Numeric should be modified to so that zero-size arrays do
not get turned to scalars when they are manipulated. So, for example,
"-array(5)" would result in a zero sized array containing -5, not the scalar
negative five. I think this is feasible (at least in JNumeric where I'm
familiar with the internals), but I haven't investigated it in depth. It's
also possible it will break code. Something to think about anyway.

Second, two static functions could be added to Numeric to set the precision
of Scalar values. By default, floats would be converted to type 'd' when
they are converted to zero-d arrays, as they are now, but a call to:

>>> Numeric.setFloatPrecision('f')

would result in floats be converted to type 'f' instead. For example:

>>> arange(5, 'f') * 5
array([0, 5, 10, 15, 20], 'f')

Similarly,

>>> Numeric.setIntPrecision('s')

could be used to set the default conversion of Python integers to arrays.
I'm not sure if this should affect array creation as well. For example
should

>>> Numeric.setFloatPrecision('f')
>>> a= arrray([1.,2.,3.])

result in an array of type 'f' or an array of type 'd'?

The big advantage of this approach is it's gauranteed to not break any code.
It also has what I consider good (i.e., unsuprising) default behaviour,
while allowing more memory efficiency if necessary.

-tim