Update with black formatted code.
philippeitis authored on 16/12/2019 08:33:45 • Joseph Weston committed on 05/05/2020 19:10:25...  ... 
@@ 4,7 +4,21 @@ from itertools import chain, combinations 
4  4 
from math import factorial 
5  5 
import scipy.spatial 
6  6 

7 
from numpy import square, zeros, subtract, array, ones, dot, asarray, concatenate, average, eye, mean, abs, sqrt 

7 
+from numpy import ( 

8 
+ square, 

9 
+ zeros, 

10 
+ subtract, 

11 
+ array, 

12 
+ ones, 

13 
+ dot, 

14 
+ asarray, 

15 
+ concatenate, 

16 
+ average, 

17 
+ eye, 

18 
+ mean, 

19 
+ abs, 

20 
+ sqrt, 

21 
+) 

8  22 
from numpy import sum as nsum 
9  23 
from numpy.linalg import det as ndet 
10  24 
from numpy.linalg import slogdet, solve, matrix_rank, norm 
...  ... 
@@ 12,13 +26,13 @@ from numpy.linalg import slogdet, solve, matrix_rank, norm 
12  26 

13  27 
def fast_norm(v): 
14  28 
""" Manually take the vector norm for len 2, 3 vectors. Defaults to a square root of the dot product 
15 
 for larger vectors. 

16 
 

17 
 Note that for large vectors, it is possible for integer overflow to occur. 

29 
+ for larger vectors. 

30 
+ 

31 
+ Note that for large vectors, it is possible for integer overflow to occur. 

18  32 
For instance: 
19  33 
vec = [49024, 59454, 12599, 63721, 18517, 27961] 
20  34 
dot(vec, vec) = 1602973744 
21 
 

35 
+ 

22  36 
""" 
23  37 
len_v = len(v) 
24  38 
# notice this method can be even more optimised 