This function executes all the standard NumPy reduction function boilerplate code, just calling assign_identity and the appropriate inner loop function where necessary.
operand : The array to be reduced. out : NULL, or the array into which to place the result. wheremask : NOT YET SUPPORTED, but this parameter is placed here
System Message: ERROR/3 (<string>
, line 8) Unexpected indentation.
<blockquote> so that support can be added in the future without breaking API compatibility. Pass in NULL.</blockquote>
System Message: WARNING/2 (<string>
, line 10) Block quote ends without a blank line; unexpected unindent.
operand_dtype : The dtype the inner loop expects for the operand. result_dtype : The dtype the inner loop expects for the result. casting : The casting rule to apply to the operands. axis_flags : Flags indicating the reduction axes of 'operand'. reorderable : If True, the reduction being done is reorderable, which
System Message: ERROR/3 (<string>
, line 15) Unexpected indentation.
<blockquote> means specifying multiple axes of reduction at once is ok, and the reduction code may calculate the reduction in an arbitrary order. The calculation may be reordered because of cache behavior or multithreading requirements.</blockquote>
System Message: WARNING/2 (<string>
, line 19) Block quote ends without a blank line; unexpected unindent.
- keepdims : If true, leaves the reduction dimensions in the result
- with size one.
- subok : If true, the result uses the subclass of operand, otherwise
- it is always a base class ndarray.
- assign_identity : If NULL, PyArray_InitializeReduceResult is used, otherwise
- this function is called to initialize the result to the reduction's unit.
System Message: WARNING/2 (<string>
, line 26) Definition list ends without a blank line; unexpected unindent.
loop : The loop which does the reduction. data : Data which is passed to assign_identity and the inner loop. buffersize : Buffer size for the iterator. For the default, pass in 0. funcname : The name of the reduction function, for error messages.
TODO FIXME: if you squint, this is essentially an second independent implementation of generalized ufuncs with signature (i)->(), plus a few extra bells and whistles. (Indeed, as far as I can tell, it was originally split out to support a fancy version of count_nonzero... which is not actually a reduction function at all, it's just a (i)->() function!) So probably these two implementation should be merged into one. (In fact it would be quite nice to support axis= and keepdims etc. for arbitrary generalized ufuncs!)
Iterator parameters
Validate that the parameters for future expansion are NULL
This either conforms 'out' to the ndim of 'operand', or allocates a new array appropriate for this reduction.
Initialize the result to the reduction unit if possible, otherwise copy the initial values and get a view to the rest.
If this reduction is non-reorderable, make sure there are only 0 or 1 axes in axis_flags.
empty op_view signals no reduction; but 0-d arrays cannot be empty
Set up the iterator
Straightforward reduction
Strip out the extra 'one' dimensions in the result