|
1 | 1 | ## Tensor times same vector in all but one (TTSV1) and all but two (TTSV2) |
| 2 | +import math |
2 | 3 | from collections import defaultdict |
3 | 4 | from itertools import combinations |
4 | | -from math import factorial |
5 | 5 |
|
6 | 6 | import numpy as np |
7 | | -from numpy import prod |
8 | | -from scipy.signal import convolve |
9 | | -from scipy.sparse import coo_array |
10 | | -from scipy.special import binom as binomial |
11 | 7 |
|
12 | 8 | __all__ = [ |
13 | 9 | "pairwise_incidence", |
@@ -78,9 +74,10 @@ def banerjee_coeff(size, max_size): |
78 | 74 | Sinan Aksoy, Ilya Amburg, Stephen Young, |
79 | 75 | https://doi.org/10.1137/23M1584472 |
80 | 76 | """ |
| 77 | + from scipy.special import binom |
| 78 | + |
81 | 79 | return sum( |
82 | | - ((-1) ** j) * binomial(size, j) * (size - j) ** max_size |
83 | | - for j in range(size + 1) |
| 80 | + ((-1) ** j) * binom(size, j) * (size - j) ** max_size for j in range(size + 1) |
84 | 81 | ) |
85 | 82 |
|
86 | 83 |
|
@@ -119,15 +116,15 @@ def ttsv1(node_dict, edge_dict, r, a): |
119 | 116 | """ |
120 | 117 | n = len(node_dict) |
121 | 118 | s = np.zeros(n) |
122 | | - r_minus_1_factorial = factorial(r - 1) |
| 119 | + r_minus_1_factorial = math.factorial(r - 1) |
123 | 120 | for node, edges in node_dict.items(): |
124 | 121 | c = 0 |
125 | 122 | for e in edges: |
126 | 123 | l = len(edge_dict[e]) |
127 | 124 | alpha = banerjee_coeff(l, r) |
128 | 125 | edge_without_node = [v for v in edge_dict[e] if v != node] |
129 | 126 | if l == r: |
130 | | - gen_fun_coef = prod(a[edge_without_node]) |
| 127 | + gen_fun_coef = np.prod(a[edge_without_node]) |
131 | 128 | elif 2 ** (l - 1) < r * (l - 1): |
132 | 129 | gen_fun_coef = _get_gen_coef_subset_expansion( |
133 | 130 | a[edge_without_node], a[node], r - 1 |
@@ -175,6 +172,9 @@ def ttsv2(pair_dict, edge_dict, r, a, n): |
175 | 172 | Sinan Aksoy, Ilya Amburg, Stephen Young, |
176 | 173 | https://doi.org/10.1137/23M1584472 |
177 | 174 | """ |
| 175 | + from scipy.signal import convolve |
| 176 | + from scipy.sparse import coo_array |
| 177 | + |
178 | 178 | s = {} |
179 | 179 | r_minus_2_factorial = factorial(r - 2) |
180 | 180 | for (v1, v2), edges in pair_dict.items(): |
@@ -317,6 +317,8 @@ def _get_gen_coef_fft_fast_array(edge_without_node, a, node, l, r): |
317 | 317 | Sinan Aksoy, Ilya Amburg, Stephen Young, |
318 | 318 | https://doi.org/10.1137/23M1584472 |
319 | 319 | """ |
| 320 | + from scipy.signal import convolve |
| 321 | + |
320 | 322 | coefs = [1] |
321 | 323 | for i in range(1, r): |
322 | 324 | coefs.append(coefs[-1] * a[node] / i) |
|
0 commit comments