Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(196)

Side by Side Diff: appengine/findit/libs/math/vectors.py

Issue 2548603003: Adding memoized functions (Closed)
Patch Set: forgot if I pushed the latest before CQ Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « appengine/findit/libs/math/test/functions_test.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import math 5 import math
6 import numpy as np 6 import numpy as np
7 7
8 8
9 def vsum(vs, shape=None): 9 def vsum(vs, shape=None):
10 """Accurate summation of a list of vectors. 10 """Accurate summation of a list of vectors.
(...skipping 13 matching lines...) Expand all
24 the vectors; (3) not all the vectors in the list have the same shape. 24 the vectors; (3) not all the vectors in the list have the same shape.
25 """ 25 """
26 if shape is None: 26 if shape is None:
27 if not vs: 27 if not vs:
28 return None 28 return None
29 29
30 shape = vs[0].shape 30 shape = vs[0].shape
31 31
32 # It'd be better to vectorize the implementation of Shewchuk's 32 # It'd be better to vectorize the implementation of Shewchuk's
33 # algorithm directly, so we can avoid needing to traverse ``vs`` 33 # algorithm directly, so we can avoid needing to traverse ``vs``
34 # repeatedly. However, this is deemed to have too high a maintinence 34 # repeatedly. However, this is deemed to have too high a maintenance
35 # cost for the performance benefit. 35 # cost for the performance benefit.
36 total = np.zeros(shape) 36 total = np.zeros(shape)
37 it = np.nditer(total, flags=['multi_index'], op_flags=['writeonly']) 37 it = np.nditer(total, flags=['multi_index'], op_flags=['writeonly'])
38 while not it.finished: 38 while not it.finished:
39 it[0] = math.fsum(v[it.multi_index] for v in vs) 39 it[0] = math.fsum(v[it.multi_index] for v in vs)
40 it.iternext() 40 it.iternext()
41 41
42 return total 42 return total
OLDNEW
« no previous file with comments | « appengine/findit/libs/math/test/functions_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698