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

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

Issue 2625073003: [Predator] Add MetaWeight and MetaFeatureValue to group multiple weights and features together. (Closed)
Patch Set: Rebase. Created 3 years, 11 months 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/vectors_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 18 matching lines...) Expand all
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 maintenance 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 try:
40 it[0] = math.fsum(v[it.multi_index] for v in vs)
41 except TypeError:
42 it[0] = sum(v[it.multi_index] for v in vs)
43
40 it.iternext() 44 it.iternext()
41 45
42 return total 46 return total
OLDNEW
« no previous file with comments | « appengine/findit/libs/math/test/vectors_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698