[Matrix-SIG] Numeric Nits

Scott M. Ransom ransom@cfa.harvard.edu
Wed, 23 Jun 1999 18:47:48 +0000


Christos Siopis wrote:
> 
> On Wed, 23 Jun 1999, Scott M. Ransom wrote:
> 
> > The more I think about it, maybe Konrad et al. are correct with the
> > solution of declaring certain 'f' arrays higher in the cast hierarchy
> > than doubles.  These arrays would never be up-cast to type double.  This
> > would allow the use of the same simple syntax (i.e. arange(3.0, typecode
> = 'f') * 2.0  gives array([ 0.,  2.,  4.],'f') _not_ array([ 0.,  2., 
> 4.]).
> 
> However, just to play devil's advocate, suppose a new user *does* know
> that Python natively only supports doubles and that upcasting is the
> normal behavior --then s/he might be confused that the result is a float.
> Alternatively, what if one *does* want the result of arange(3.0, typecode
> = 'f') * 2.0 to be a double? (ok here one could simply use 'd' instead of
> 'f' but that could be an issue in more complex expressions, where one
> might be forced to convert the whole expression back to double).
> 
> Furthermore, if types such as bytes, shorts, etc. are also introduced,
> figuring out the resulting type might get messy, e.g. would

I guess I didn't state this very clearly, but I was thinking of a _new_
type code for single-precision floats that would never be up-cast.  Call
the type 'fnc' for float no-cast or something.  Then a standard 'f' type
array performs as usual, but an 'fnc' array would not be up-cast.  So my
example above should read:
(i.e. arange(3.0, typecode = 'fnc') * 2.0  gives array([ 0.,  2., 
4.],'fnc') _not_ array([ 0., 2., 4.]).

I believe that the greatest need for this type is on the floating point
side of things.  Since Python uses Int32 as the standard length integer
(or am I wrong about this on 64bit machines...), casts from 'int' to
'long' are not a problem.  If people are concerned with short and byte
arrays on the other hand, it should be possible to create no-cast
versions of these types (although now we are talking about a whole lotta
complication).

Scott

-- 
Scott M. Ransom                   
Phone:  (781) 320-9867             Address:  75 Sanderson Ave.
email:  ransom@cfa.harvard.edu               Dedham, MA  02026
PGP Fingerprint: D2 0E D0 10 CD 95 06 DA  EF 78 FE 2B CB 3A D3 53