[Numpy-discussion] Add/multiply reduction confusion
Andrew Friedley
afriedle@indiana....
Sun Jul 5 13:47:18 CDT 2009
Stéfan van der Walt wrote:
> 2009/7/5 Andrew Friedley <afriedle@indiana.edu>:
>> I found the check that does the type 'upcasting' in
>> umath_ufunc_object.inc around line 3072 (NumPy 1.3.0). Turns out all I
>> need to do is make sure my add and multiply ufuncs are actually named
>> 'add' and 'multiply' and arrays will be upcasted appropriately.
> Would you please be so kind as to add your findings here:
>
> http://docs.scipy.org/numpy/docs/numpy-docs/reference/index.rst/#reference-index
>
> I haven't read through that document recently, so it may be in there already.
I created an account (afriedle) but looks like I don't have edit
permissions.
The user-side upcasting behavior for add/multiply is documented (though
a little hidden) in the long paragraph right before the 'Available
ufuncs' section.
http://docs.scipy.org/numpy/docs/numpy-docs/reference/ufuncs.rst/#ufuncs
I'm thinking something should be added on the C API side though, perhaps
on the 'name' parameter of PyUFunc_FromFuncAndData():
http://docs.scipy.org/numpy/docs/numpy-docs/reference/c-api.ufunc.rst/#c-api-ufunc
I would say something to the effect of (I borrowed from the user-side
blurb :) :
Specifying a name of 'add' or 'multiply' enables a special behavior for
integer-typed reductions when no dtype is given. If the input type is
an integer (or boolean) data type smaller than the size of the int_ data
type, it will be internally upcast to the int_ (or uint) data type.
Andrew
More information about the NumPy-Discussion
mailing list