... | ... |
@@ -24,8 +24,8 @@ from numpy.linalg import matrix_rank, norm, slogdet, solve |
24 | 24 |
|
25 | 25 |
|
26 | 26 |
def fast_norm(v): |
27 |
- """ Manually take the vector norm for len 2, 3 vectors. Defaults to a square root of the dot product |
|
28 |
- for larger vectors. |
|
27 |
+ """Take the vector norm for len 2, 3 vectors. |
|
28 |
+ Defaults to a square root of the dot product for larger vectors. |
|
29 | 29 |
|
30 | 30 |
Note that for large vectors, it is possible for integer overflow to occur. |
31 | 31 |
For instance: |
... | ... |
@@ -34,7 +34,6 @@ def fast_norm(v): |
34 | 34 |
|
35 | 35 |
""" |
36 | 36 |
len_v = len(v) |
37 |
- # notice this method can be even more optimised |
|
38 | 37 |
if len_v == 2: |
39 | 38 |
return sqrt(v[0] * v[0] + v[1] * v[1]) |
40 | 39 |
if len_v == 3: |
... | ... |
@@ -104,7 +103,7 @@ def fast_2d_circumcircle(points): |
104 | 103 |
|
105 | 104 |
|
106 | 105 |
def fast_3d_circumcircle(points): |
107 |
- """Compute the center and radius of the circumscribed shpere of a simplex. |
|
106 |
+ """Compute the center and radius of the circumscribed sphere of a simplex. |
|
108 | 107 |
|
109 | 108 |
Parameters |
110 | 109 |
---------- |
... | ... |
@@ -68,7 +68,7 @@ def test_circumsphere(): |
68 | 68 |
from numpy.random import normal, uniform |
69 | 69 |
|
70 | 70 |
def generate_random_sphere_points(dim, radius=0): |
71 |
- """ Refer to https://math.stackexchange.com/a/1585996 """ |
|
71 |
+ """https://math.stackexchange.com/a/1585996""" |
|
72 | 72 |
|
73 | 73 |
vec = [None] * (dim + 1) |
74 | 74 |
center = uniform(-100, 100, dim) |
... | ... |
@@ -81,19 +81,15 @@ def test_circumsphere(): |
81 | 81 |
|
82 | 82 |
return radius, center, vec |
83 | 83 |
|
84 |
- center_diff_err = "Calculated center (%s) differs from true center (%s)\n" |
|
85 | 84 |
for dim in range(2, 10): |
86 | 85 |
radius, center, points = generate_random_sphere_points(dim) |
87 | 86 |
circ_center, circ_radius = circumsphere(points) |
88 | 87 |
err_msg = "" |
89 | 88 |
if not allclose(circ_center, center): |
90 |
- err_msg += center_diff_err % ( |
|
91 |
- ", ".join([str(x) for x in circ_center]), |
|
92 |
- ", ".join([str(x) for x in center]), |
|
93 |
- ) |
|
89 |
+ err_msg += f"Calculated center ({circ_center}) differs from true center ({center})\n" |
|
94 | 90 |
if not allclose(radius, circ_radius): |
95 |
- err_msg += "Calculated radius {} differs from true radius {}".format( |
|
96 |
- circ_radius, radius, |
|
91 |
+ err_msg += ( |
|
92 |
+ f"Calculated radius {circ_radius} differs from true radius {radius}\n" |
|
97 | 93 |
) |
98 | 94 |
if err_msg: |
99 | 95 |
raise AssertionError(err_msg) |