Converting bool to float

Scott Ransom sransom at nrao.edu
Wed Nov 1 22:55:27 CST 2006


On Wed, Nov 01, 2006 at 08:16:59PM -0700, Tim Hochberg wrote:
> Travis Oliphant wrote:
> > Robert Kern wrote:
> >> Travis Oliphant wrote:
> >>
> >>> It looks like 1.0-x is doing the right thing.
> >>>
> >>> The problem is 1.0*x for matrices is going to float64.  For arrays it 
> >>> returns float32 just like the 1.0-x
> >>>       
> >> Why is this the right thing? Python floats are float64.
> >>  
> > Yeah, why indeed.  Must be something with the scalar coercion code...
> 
> This is one of those things that pops up every few years. I suspect that 
> the best thing to do here is to treat 1.0, and all Python floats as 
> having a kind (float), but no precision. Or, equivalently treat them as 
> the smallest precision floating point value. The rationale behind this 
> is that otherwise float32 array will be promoted whenever they are 
> multiplied by Python floating point scalars. If Python floats are 
> treated as Float64 for purposes of determining output precision then 
> anyone using float32 arrays is going to have to wrap all of their 
> literals in float32 to prevent inadvertent upcasting to float64. This 
> was the origin of the (rather clunky) numarray spacesaver flag.

I'm one of those people who made serious use of that clunky
spacesaver flag for precisely this reason.  I deal with several GB
arrays of 32-bit floats (or 32-bit x2 complex numbers) on a
regular basis.  Having automatic upcasting from scalar operations
can be a royal pain.

Scott

-- 
Scott M. Ransom            Address:  NRAO
Phone:  (434) 296-0320               520 Edgemont Rd.
email:  sransom at nrao.edu             Charlottesville, VA 22903 USA
GPG Fingerprint: 06A9 9553 78BE 16DB 407B  FFCA 9BFA B6FF FFD3 2989

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the Numpy-discussion mailing list