[Numpy-discussion] ufunc.reduce and conversion

Travis Oliphant oliphant.travis at ieee.org
Wed Sep 20 05:59:42 CDT 2006


A. M. Archibald wrote:
> Hi,
>
> What are the rules for datatype conversion in ufuncs? Does ufunc(a,b)
> always yield the smallest type big enough to represent both a and b?
> What is the datatype of ufunc.reduce(a)?
>   
This is an unintended consequence of making add.reduce() reduce over at 
least a ("long").   I've fixed the code so that only add.reduce and 
multiply.reduce alter the default reducing data-type to be long.  All 
other cases use the data-type of the array as the default.

Regarding your other question on data-type conversion in ufuncs:

1)  If you specify an output array, then the result will be cast to the 
output array data-type.

2)  The actual computation takes place using a data-type that all 
(non-scalar) inputs can be cast to safely (with the exception that we 
assume that long long integers can be "safely" cast to "doubles" even 
though this is not technically true).

-Travis







More information about the Numpy-discussion mailing list