[Matrix-SIG] Proposal for further single-precision clean-up.

Travis Oliphant Oliphant.Travis@mayo.edu
Sat, 15 Jan 2000 23:56:57 -0600 (CST)

Recently I submitted patches that in my view alleviate some of the
difficulties encountered when working with single precision arrays.  I am
now submitting a proposal for immediate changes that could be made to
Numerical Python to further improve single precision work.   For the
future I am in support of modifying Python so that scalars are the same as
rank-0 arrays, but any move in that direction is certainly several months
or even years away.  

Instead of waiting for something to happen, we should establish a
consistent usage that allows single-precision work in Numerical Python to
proceed.  The problem has always been that Python does not define
single-precision scalars. I suggest, that as far as NumPy is concerned, we
define single-precision scalars to be the corresponding rank-0 array. 

This is the direction I was going with the recent patches to NumPy. I'm
now proposing that we finish the job so that for any operation on a 
single-precision array that returns a scalar for which no Python scalar of
equivalent precision exists, NumPy returns a rank-0 array.  

Some have expressed concerns that rank-0 arrays won't behave correctly as
scalars and will therefore be useless as return values.  Because of
Python's abstract object interface, rank-0 arrays can be defined to act
like Python scalars in nearly every way (the only exception I can think of
right now is list indexing -- and that could be fixed in Python).

Some have also objected that rank-0 arrays are not scalars so that
equating them will cause confusion.  I can respect those concerns but feel
that in the current state of Numerical Python the association between
rank-0 arrays and scalars is valid and useful.
At its core, my proposal requires changes to the getitem function of
single-precision types in arraytypes.c and then a careful checking to make
sure that everytime that function is used, the following code accepts the
philosophy that the returned objects are either rank-0 arrays or Python
scalars of the corresponding precision.

In my mind, this fix is not ideal, but I think it will help
single-precision users and establish a practical consistency for the time

I can fix the code and patch the source tree after receiving approval from
Paul who will listen to the responses on this list.  So, if you can think
of example code that such a change would break,  or if you agree with
these changes please post to the list.