Skip to content

Commit 6333b6e

Browse files
committed
modAL.utils.combination make_linear_combination and make_product now uses genexps instead of list comprehension, 2x performance speedup
1 parent a9f7052 commit 6333b6e

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

modAL/utils/combination.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ def make_linear_combination(*functions, weights=None):
3838
'same as the number of given functions'
3939

4040
def linear_combination(*args, **kwargs):
41-
return np.sum([weights[i]*functions[i](*args, **kwargs)
42-
for i in range(len(weights))], axis=0)
41+
return np.sum((weights[i]*functions[i](*args, **kwargs)
42+
for i in range(len(weights))), axis=0)
4343

4444
return linear_combination
4545

@@ -73,8 +73,8 @@ def make_product(*functions, exponents=None):
7373
'same as the number of given functions'
7474

7575
def product_function(*args, **kwargs):
76-
return np.prod([functions[i](*args, **kwargs)**exponents[i]
77-
for i in range(len(exponents))], axis=0)
76+
return np.prod((functions[i](*args, **kwargs)**exponents[i]
77+
for i in range(len(exponents))), axis=0)
7878

7979
return product_function
8080

0 commit comments

Comments
 (0)