I had a look at what it would take to improve the C-solution. However I find
that it is beyond my C-programming skils.
The gufunc defintion seems to be at odds with current working of the axis
keyword for mean, std and var. The latter support computation over multiple
axes, whereas the gufunc only seems to support calculation over a single axis.
As the behaviour of std, mean and var is largely inherited from ufuncs those
might offer a better starting point.
If the operator used in the ufunc could take a parameter from the outer_loop
accessing in this case the mean, then it would be possible to calculate the
required intermediate quantities. This should be a possibility as somewhere the
out array is also accessed in the correct manner and we should step through
both arrays in the same way.
Instead of:
'''Pseudocode
result = np.full(result_shape, op.identity) # op = ufunc
loop_outer_axes_result_array:
loop_over_inner_axes_input_array:
result[outer_axes] = op(result[outer_axes],
InArray[outer_axes + inner_axes])
'''
we would then get:
'''Pseudocode
result = np.full(result_shape, op.identity) # op = ufunc
loop_outer_axes_result_array:
loop_over_inner_axes_input_array:
result[outer_axes] = op(result[outer_axes],
InArray[outer_axes + inner_axes],
ParameterArray[outer_axes])
'''
Using for op:
'''Pseudocode
op(a,b,c) = a+b-c
'''
and for b the original data and for c the mean (M_1) you would obtain the Neely
correction for the mean.
Similarly using:
'''Pseudocode
op(a,b,c) = a+(b-c)^2
'''
you would obtain the sum of squared errors.
_______________________________________________
NumPy-Discussion mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/numpy-discussion.python.org/
Member address: [email protected]