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_grade_obj(self):
algebras = [Cl(i) for i in [3, 4]] + [conformalize(Cl(3)[0])]
for alg in algebras:
layout = alg[0]
for i in range(len(layout.sig)+1):
mv = layout.randomMV()(i)
assert i == grade_obj(mv)
if random_sequence:
indices = random.sample(range(len(query_model)), len(query_model))
else:
indices = range(len(query_model))
for i in indices:
grade = grade_list[i]
new_obj = normalised(apply_rotor(query_model[i], R_total)(grade))
C1 = normalised(new_obj)
C2 = normalised(reference_model[i])
if abs(C1 + C2) < 0.0001:
C1 = -C1
if object_type == 'lines':
rroot = normalised(square_roots_of_rotor((rotor_between_objects(C1, C2)))[0])
else:
if motor:
if grade_obj(C1, 0.00001) == 4:
rroot = normalised(square_roots_of_rotor(rotor_between_objects(C1, C2))[0])
else:
rroot = normalised(square_roots_of_rotor(motor_between_objects(C1, C2))[0])
else:
rroot = normalised(square_roots_of_rotor(rotor_between_objects(C1, C2))[0])
r_set = normalised((rroot*r_set)(0, 2, 4))
R_total = normalised((rroot * R_total)(0, 2, 4))
if rotor_cost(r_set) < cost_tolerance:
exit_flag = 0
return R_total, exit_flag
exit_flag = 1
return R_total, exit_flag
def add_sphere(self, mv, color='rgb(0,0,0)'):
if grade_obj(mv) != 4:
raise ValueError('Input is not a sphere')
self.add(Sphere(mv, color))
def estimate_rotor_objects(reference_model, query_model, maxfev=20000,
print_res=False, object_type='generic', motor=False,
symmetric=False):
"""
Estimates the rotor that takes one set of objects to another
"""
grade_list = [grade_obj(q) for q in query_model]
x0 = np.finfo(float).eps * np.random.rand(6)
def minimisation_func(x):
R = rotorconversion(x)
query_model_remapped = [normalised((apply_rotor(l, R))(grade_list[i])) for i, l in enumerate(query_model)]
return object_set_cost_sum(reference_model, query_model_remapped,
object_type=object_type, motor=motor,
symmetric=symmetric)
res = minimize(minimisation_func, x0, method='SLSQP', options={'ftol': 10.0 ** (-16),
'maxiter': 1000,
'disp': False})
if print_res:
print(res)
res = minimize(minimisation_func, res.x, method='L-BFGS-B', options={'ftol': 10.0**(-16),
'maxiter': 1000,
def average_objects(obj_list, weights=[], check_grades=True):
"""
Hadfield and Lasenby, Direct Linear Interpolation of Geometric Objects, AGACSE2018
Directly averages conformal objects
Return a valid object from the addition result C
"""
if len(weights) == len(obj_list):
C = sum([o * w for o, w in zip(obj_list, weights)])
else:
C = sum(obj_list) / len(obj_list)
C3 = neg_twiddle_root(C)[0].normal()
if check_grades:
if cf.grade_obj(obj_list[0], 0.00001) != cf.grade_obj(C3, 0.00001):
raise ValueError('Created object is not same grade \n' + str(obj_list[0]) + '\n' + str(C3))
return C3
def add_circle(self, mv, color='rgb(0,0,0)'):
if grade_obj(mv) != 3:
raise ValueError('Input is not a circle')
self.add(Circle(mv, color))
def interp_objects_root(C1, C2, alpha):
"""
Hadfield and Lasenby, Direct Linear Interpolation of Geometric Objects, AGACSE2018
Directly linearly interpolates conformal objects
Return a valid object from the addition result C
"""
C = (1 - alpha) * C1 + alpha*C2
C3 = neg_twiddle_root(C)[0].normal()
if cf.grade_obj(C1, 0.00001) != cf.grade_obj(C3, 0.00001):
raise ValueError('Created object is not same grade')
return C3