#NEWLINE# def reduction( x , chunk , aggregate , axis = None , keepdims = None , dtype = None , split_every = None , combine = None , name = None ) : #NEWLINE# #INDENT# ' General version of reductions\n\n    >>> reduction(my_array, np.sum, np.sum, axis=0, keepdims=False)  # doctest: +SKIP\n    ' #NEWLINE# if ( axis is None ) : #NEWLINE# #INDENT# axis = tuple ( range ( x . ndim ) ) #NEWLINE# #UNINDENT# if isinstance ( axis , int ) : #NEWLINE# #INDENT# axis = ( axis , ) #NEWLINE# #UNINDENT# axis = tuple ( ( ( i if ( i >= 0 ) else ( x . ndim + i ) ) for i in axis ) ) #NEWLINE# if ( dtype and ( 'dtype' in getargspec ( chunk ) . args ) ) : #NEWLINE# #INDENT# chunk = partial ( chunk , dtype = dtype ) #NEWLINE# #UNINDENT# if ( dtype and ( 'dtype' in getargspec ( aggregate ) . args ) ) : #NEWLINE# #INDENT# aggregate = partial ( aggregate , dtype = dtype ) #NEWLINE# #UNINDENT# inds = tuple ( range ( x . ndim ) ) #NEWLINE# tmp = atop ( partial ( chunk , axis = axis , keepdims = True ) , inds , x , inds ) #NEWLINE# tmp . _chunks = tuple ( ( ( ( ( 1 , ) * len ( c ) ) if ( i in axis ) else c ) for ( i , c ) in enumerate ( combine . chunks ) ) ) #NEWLINE# return _tree_reduce ( tmp , aggregate , axis , keepdims , dtype , split_every , combine , name = name )