Numercal python's savespace

Travis Oliphant olipt at mayo.edu
Wed Aug 23 09:59:08 EDT 2000


> I use Numerical python for computations with large arrays in single
> precision, and struggle a little with avoiding the silent upcasting. 
> 
> The documentation more or less recommend using lambda functions like
> 
> real= lambda x: Numeric.array(x,'f')
> 
> a=b+ real(4.234)
> 
> 
> I find this rather tedious, and prefer defining a and b as 
> 
> Numeric.array( (...), savespace=1)
> 
> which seem to supress silent upcasting. But is this enough to ensure
> no upcasting is done?  If so, is it possible to make this the default
> behaviour?  What is the recommended way to work in single precision?


Well you've entered a lengthy debate that still hasn't quite resolved
itself --- but we're getting there.  For those of us who really like the
single precision features of Numeric Python, this silent upcasting can be
a real problem.  The savespace feature is a recent addition, whose purpose
was to alleviate some of the difficulty.  

If you use the savespace feature, then upcasting will never be performed
(but downcasting will) unless you perform an operation on two "savespace"
arrays in which case the usual coercion rules will apply.  In particular,
if A is a "savespace" array, then

2*A  will also be a "savespace" array of the same precision as "A."

This is not in the standard documentation as it is a recent addition, but
it should work just like that.

Good luck,

Travis Oliphant





More information about the Python-list mailing list