From 11b38a68956d006b99a4cf78885de3070f60c41b Mon Sep 17 00:00:00 2001 From: Adam Paszke Date: Fri, 30 Sep 2016 16:37:07 -0400 Subject: Add more functions to autograd --- torch/_utils.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'torch/_utils.py') diff --git a/torch/_utils.py b/torch/_utils.py index 0ad2ee2924..9adba52e80 100644 --- a/torch/_utils.py +++ b/torch/_utils.py @@ -35,3 +35,20 @@ def _import_dotted_name(name): for component in components[1:]: obj = getattr(obj, component) return obj + + +# Taken from python 3.5 docs +def _accumulate(iterable): + 'Return running totals' + # _accumulate([1,2,3,4,5]) --> 1 3 6 10 15 + # _accumulate([1,2,3,4,5], operator.mul) --> 1 2 6 24 120 + it = iter(iterable) + try: + total = next(it) + except StopIteration: + return + yield total + for element in it: + total += element + yield total + -- cgit v1.2.3