[Numpy-discussion] Possible bug

Todd Miller jmiller at stsci.edu
Tue Sep 2 12:06:12 CDT 2003


These problems are (partially) addressed in numarray-0.7 with the
addition of a check_overflow parameter to numarray.fromlist().  The
checked fromlist is now used in the implementation of ufuncs (e.g.
multiply), preventing the silent truncation of scalar values to the type
of the array.  

Problem c:  solved -- 1001 scalar was silently truncated to Int8 before
multiplication.

Problem e:  solved -- 3000 was silently truncated to Int8 during
fromlist.  Use fromlist() rather than array() and add
check_overflow=1 parameter.

Problem f: rejected  -- working as designed, won't change.  Floating
point numbers passed into array() are silently truncated if the type is
not a floating point type.  Operating on an integer array and a floating
point scalar returns a floating point array by design;  likewise,
operating on an integer array with an integer scalar returns an integer
array.  This is all expected behavior.

Problem g: unaddressed -- working as designed, open to discussion.  The
silent truncation of g to Int16 is documented in the description of
astype().  It's possible to add a check_overflow flag to astype()

Thanks for the feedback,
Todd

On Mon, 2003-08-18 at 09:20, Colin J. Williams wrote:
> # ta.py to check Int8, Int16
> import numarray as _n
> import numarray.numerictypes as _nt
> b= _n.arange(4, type= _nt.Int8)
> print 'b, b._type:', b, b._type
> c= b*1001                                        # Grief here - type not 
> updated
> print 'c, c._type:', c, c._type    
> e= _n.array([1, -2, 3000, 4.6], type= _nt.Int8)  # undocumented feature 
> fraction discarded
>                                                  # and lowest eight bits 
> retained as a signed
>                                                  # integer.
> print 'e, e._type:', e, e._type
> f= _n.array([1, 2, 3, 4.6], type= _nt.Int8) * 9.6
> print 'f, f._type:', f, f._type
> g= (f.copy()*2000).astype(_nt.Int16)             # undocumented - see e 
> above
> print 'g, g._type:', g, g._type
> 
> 
> --------------------------------------------------------------------
> PythonWin 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] 
> on win32.
> Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - 
> see 'Help/About PythonWin' for further copyright information.
>  >>> b, b._type: [0 1 2 3] Int8
> c, c._type: [  0 -23 -46 -69] Int8
> e, e._type: [  1  -2 -72   4] Int8
> f, f._type: [  9.6  19.2  28.8  38.4] Float64
> g, g._type: [ 19200 -27136  -7937  11264] Int16
> 
> Colin W.
> 
> 
> 
> -------------------------------------------------------
> This SF.Net email sponsored by: Free pre-built ASP.NET sites including
> Data Reports, E-commerce, Portals, and Forums are available now.
> Download today and enter to win an XBOX or Visual Studio .NET.
> http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
-- 
Todd Miller 			jmiller at stsci.edu
STSCI / ESS / SSB





More information about the Numpy-discussion mailing list