[Numpy-discussion] Another suggestion for making numpy's functions generic
Sun Oct 18 06:48:43 CDT 2009
On Sat, Oct 17, 2009 at 6:45 PM, Charles R Harris
> On Sat, Oct 17, 2009 at 6:49 AM, Darren Dale <firstname.lastname@example.org> wrote:
>> I think it will be not too difficult to document this overall scheme:
>> When calling numpy functions:
>> 1) __input_prepare__ provides an opportunity to operate on the inputs
>> to yield versions that are compatible with the operation (they should
>> obviously not be modified in place)
>> 2) the output array is established
>> 3) __array_prepare__ is used to determine the class of the output
>> array, as well as any metadata that needs to be established before the
>> operation proceeds
>> 4) the ufunc performs its operations
>> 5) __array_wrap__ provides an opportunity to update the output array
>> based on the results of the computation
>> Comments, criticisms? If PEP 3124^ were already a part of the standard
>> library, that could serve as the basis for generalizing numpy's
>> functions. But I think the PEP will not be approved in its current
>> form, and it is unclear when and if the author will revisit the
>> proposal. The scheme I'm imagining might be sufficient for our
> This sounds interesting to me, as it would push the use of array wrap down
> into a common function and make it easier to use.
Sorry, I don't understand what you mean.
> I wonder what the impact
> would be on the current subclasses of ndarray?
I don't think it will have any impact. The only change would be the
addition of __input_prepare__, which by default would simply return
the unmodified inputs.
> On a side note, I wonder if you could look into adding your reduce loop
> optimizations into the generic loops? It would be interesting to see if that
> speeded up some common operations. In any case, it can't hurt.
I think you are confusing me with someone else.
More information about the NumPy-Discussion