Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_general_logarithm_translation(self):
# Check we can reverse translation
for i in range(50):
t = random_euc_mv()
biv = ninf * t /2
R = general_exp(biv).normal()
biv_2 = general_logarithm(R)
np.testing.assert_almost_equal(biv.value, biv_2.value)
def test_general_logarithm_conformal(self):
object_generators = [random_point_pair, random_line, random_circle, random_plane]
# object_generators = [random_sphere]
for obj_gen in object_generators:
print(obj_gen.__name__)
for i in range(10000):
X = obj_gen()
Y = obj_gen()
R = rotor_between_objects(X, Y)
biv = general_logarithm(R)
R_recon = general_exp(biv).normal()
np.testing.assert_almost_equal(R.value, R_recon.value, 4)
def test_general_logarithm_RS(self):
for i in range(5):
scale = 0.5 + np.random.rand()
S = generate_dilation_rotor(scale).normal()
R = generate_rotation_rotor(0.5, e1, e2).normal()
V = ( R *S).normal()
biv_test = general_logarithm(R) + general_logarithm(S)
biv = general_logarithm(V)
biv_alt = ga_log(R) + general_logarithm(S)
np.testing.assert_almost_equal(biv.value, biv_test.value, 5)
np.testing.assert_almost_equal(biv.value, biv_alt.value, 5)
def test_general_logarithm_TRS(self):
for i in range(5):
scale = 0.5 + np.random.rand()
S = generate_dilation_rotor(scale)
R = generate_rotation_rotor(0.5, e1, e2)
T = generate_translation_rotor(e3 + 7* e2 - e1)
V = (T * R * S).normal()
biv = general_logarithm(V)
V_rebuilt = general_exp(biv).normal()
biv2 = general_logarithm(V)
C1 = random_point_pair()
C2 = (V * C1 * ~V).normal()
C3 = (V_rebuilt * C1 * ~V_rebuilt).normal()
np.testing.assert_almost_equal(C2.value, C3.value)
def test_general_logarithm_RS(self):
for i in range(5):
scale = 0.5 + np.random.rand()
S = generate_dilation_rotor(scale).normal()
R = generate_rotation_rotor(0.5, e1, e2).normal()
V = ( R *S).normal()
biv_test = general_logarithm(R) + general_logarithm(S)
biv = general_logarithm(V)
biv_alt = ga_log(R) + general_logarithm(S)
np.testing.assert_almost_equal(biv.value, biv_test.value, 5)
np.testing.assert_almost_equal(biv.value, biv_alt.value, 5)
def test_general_logarithm_rotation(self):
# Check we can reverse rotations
for i in range(50):
R = random_rotation_rotor()
biv_2 = general_logarithm(R)
biv_3 = ga_log(R)
np.testing.assert_almost_equal(biv_2.value, biv_3.value, 3)
def test_general_logarithm_scaling(self):
# Check we can reverse scaling
for i in range(50):
scale = 0.5 + np.random.rand()
biv = -np.log(scale ) *e45 /2
R = general_exp(biv).normal()
biv_2 = general_logarithm(R)
np.testing.assert_almost_equal(biv.value, biv_2.value)
def test_general_logarithm_RS(self):
for i in range(5):
scale = 0.5 + np.random.rand()
S = generate_dilation_rotor(scale).normal()
R = generate_rotation_rotor(0.5, e1, e2).normal()
V = ( R *S).normal()
biv_test = general_logarithm(R) + general_logarithm(S)
biv = general_logarithm(V)
biv_alt = ga_log(R) + general_logarithm(S)
np.testing.assert_almost_equal(biv.value, biv_test.value, 5)
np.testing.assert_almost_equal(biv.value, biv_alt.value, 5)
def test_general_logarithm_TS(self):
for i in range(5):
scale = 0.5 +np.random.rand()
t = random_euc_mv()
S = generate_dilation_rotor(scale)
T = generate_translation_rotor(t)
V = ( T *S).normal()
biv = general_logarithm(V)
V_rebuilt = (general_exp(biv)).normal()
C1 = random_point_pair()
C2 = ( V *C1 *~V).normal()
C3 = (V_rebuilt *C1 *~V_rebuilt).normal()
np.testing.assert_almost_equal(C2.value, C3.value, 5)
def alt_rotor_cost(V):
"""
An alternate rotor cost for TRS rotors
"""
logV = general_logarithm(V)
scale_cost = np.abs(-2*logV[e45])
scalefac = np.e**(-2*logV[e45])
R = logV(e123)*e123
rotation_cost = abs((R*~R)[()])
translation_cost = scalefac*abs((logV - logV[e45]*e45 - logV(e123))|eo)
return rotation_cost + scale_cost + translation_cost