-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
Open
Description
Right now, reduce can be roughly described as:
it = iter_along_axis(arr) #pseudocode
result = func.identity or next(it)
for i in it:
result = func(result, i)
return resultOr diagramatically:
x2 x3 x3 xn
| | | |
V V V V
x1 -> (f) -> (f) -> (f) ... (f) --> result
What I'm proposing is a more powerful variant that allows extra state to be preserved between each function call:
it = iter_along_axis(arr) #pseudocode
result = func.identity or next(it)
state = None
for i in it:
result, state = func(result, i, reduce_state=state)
return result x2 x3 x3 xn
| | | |
V V V V
x1 -> ( ) -> ( ) -> ( ) ... ( ) --> result
(f) (f) (f) (f)
None -> ( ) -> ( ) -> ( ) ... ( )
This makes ufuncs capable of describing:
argminargmax
*gcd(ENH: Integer gcd function #8772)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels