Skip to content

Commit 677855e

Browse files
committed
Update tools to use copy=False
1 parent 0beca2d commit 677855e

File tree

7 files changed

+48
-48
lines changed

7 files changed

+48
-48
lines changed

clifford/_multivector.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def vee(self, other) -> 'MultiVector':
122122
functions instead, as these work in degenerate metrics like PGA too,
123123
and are equivalent but faster in other metrics.
124124
"""
125-
return self.layout.MultiVector(value=self.layout.vee_func(self.value, other.value))
125+
return self.layout.MultiVector(value=self.layout.vee_func(self.value, other.value), copy=False)
126126

127127
def __and__(self, other) -> 'MultiVector':
128128
""" Alias for :meth:`~MultiVector.vee` """
@@ -255,10 +255,10 @@ def __rsub__(self, other) -> 'MultiVector':
255255
return self._newMV(newValue)
256256

257257
def right_complement(self) -> 'MultiVector':
258-
return self.layout.MultiVector(value=self.layout.right_complement_func(self.value))
258+
return self.layout.MultiVector(value=self.layout.right_complement_func(self.value), copy=False)
259259

260260
def left_complement(self) -> 'MultiVector':
261-
return self.layout.MultiVector(value=self.layout.left_complement_func(self.value))
261+
return self.layout.MultiVector(value=self.layout.left_complement_func(self.value), copy=False)
262262

263263
def __truediv__(self, other) -> 'MultiVector':
264264
"""Division, :math:`M N^{-1}`"""
@@ -769,7 +769,7 @@ def dual(self, I=None) -> 'MultiVector':
769769
I defaults to the pseudoscalar.
770770
"""
771771
if I is None:
772-
return self.layout.MultiVector(value=self.layout.dual_func(self.value))
772+
return self.layout.MultiVector(value=self.layout.dual_func(self.value), copy=False)
773773
else:
774774
Iinv = I.inv()
775775

clifford/tools/g3/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def np_to_euc_mv(np_in):
191191
output[1] = np_in[0]
192192
output[2] = np_in[1]
193193
output[3] = np_in[2]
194-
return layout.MultiVector(output)
194+
return layout.MultiVector(output, copy=False)
195195

196196

197197
def euc_mv_to_np(euc_point):

clifford/tools/g3c/__init__.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,7 @@ def get_line_intersection(L3, Ldd):
598598
Pd = 0.5*(Xdd+Xddd)
599599
P = -(Pd*ninf*Pd)(1)/(2*(Pd|einf)**2)[0]
600600
"""
601-
return layout.MultiVector(val_get_line_intersection(L3.value, Ldd.value))
601+
return layout.MultiVector(val_get_line_intersection(L3.value, Ldd.value), copy=False)
602602

603603

604604
@numba.njit
@@ -618,15 +618,15 @@ def midpoint_between_lines(L1, L2):
618618
Gets the point that is maximally close to both lines
619619
Hadfield and Lasenby AGACSE2018
620620
"""
621-
return layout.MultiVector(val_midpoint_between_lines(L1.value, L2.value))
621+
return layout.MultiVector(val_midpoint_between_lines(L1.value, L2.value), copy=False)
622622

623623

624624
def midpoint_of_line_cluster(line_cluster):
625625
"""
626626
Gets a center point of a line cluster
627627
Hadfield and Lasenby AGACSE2018
628628
"""
629-
return layout.MultiVector(val_midpoint_of_line_cluster(MVArray(line_cluster).value))
629+
return layout.MultiVector(val_midpoint_of_line_cluster(MVArray(line_cluster).value), copy=False)
630630

631631

632632
@numba.njit
@@ -809,7 +809,7 @@ def generate_dilation_rotor(scale):
809809
if abs(scale - 1.0) < 0.00001:
810810
u = np.zeros(32)
811811
u[0] = 1.0
812-
return layout.MultiVector(u)
812+
return layout.MultiVector(u, copy=False)
813813
gamma = math.log(scale)
814814
return math.cosh(gamma/2) + math.sinh(gamma/2)*(ninf^no)
815815

@@ -818,7 +818,7 @@ def generate_translation_rotor(euc_vector_a):
818818
"""
819819
Generates a rotor that translates objects along the euclidean vector euc_vector_a
820820
"""
821-
return layout.MultiVector(val_generate_translation_rotor(euc_vector_a.value))
821+
return layout.MultiVector(val_generate_translation_rotor(euc_vector_a.value), copy=False)
822822

823823

824824
@numba.njit
@@ -845,7 +845,7 @@ def meet(A, B):
845845
The meet algorithm as described in "A Covariant Approach to Geometry"
846846
I5*((I5*A) ^ (I5*B))
847847
"""
848-
return layout.MultiVector(meet_val(A.value, B.value))
848+
return layout.MultiVector(meet_val(A.value, B.value), copy=False)
849849

850850

851851
@numba.njit
@@ -878,7 +878,7 @@ def intersect_line_and_plane_to_point(line, plane):
878878
ans = val_intersect_line_and_plane_to_point(line.value, plane.value)
879879
if ans[0] == -1.:
880880
return None
881-
return layout.MultiVector(ans)
881+
return layout.MultiVector(ans, copy=False)
882882

883883

884884
@numba.njit
@@ -897,7 +897,7 @@ def normalise_n_minus_1(mv):
897897
"""
898898
Normalises a conformal point so that it has an inner product of -1 with einf
899899
"""
900-
return layout.MultiVector(val_normalise_n_minus_1(mv.value))
900+
return layout.MultiVector(val_normalise_n_minus_1(mv.value), copy=False)
901901

902902

903903
def quaternion_and_vector_to_rotor(quaternion, vector):
@@ -952,8 +952,8 @@ def point_pair_to_end_points(T):
952952
Extracts the end points of a point pair bivector
953953
"""
954954
output = val_point_pair_to_end_points(T.value)
955-
A = layout.MultiVector(output[0, :])
956-
B = layout.MultiVector(output[1, :])
955+
A = layout.MultiVector(output[0, :], copy=False)
956+
B = layout.MultiVector(output[1, :], copy=False)
957957
return A, B
958958

959959

@@ -1037,13 +1037,13 @@ def positive_root(sigma):
10371037
Square Root of Rotors - Evaluates the positive root
10381038
"""
10391039
res_val = positive_root_val(sigma.value)
1040-
return layout.MultiVector(res_val)
1040+
return layout.MultiVector(res_val, copy=False)
10411041

10421042

10431043
def negative_root(sigma):
10441044
""" Square Root of Rotors - Evaluates the negative root """
10451045
res_val = negative_root_val(sigma.value)
1046-
return layout.MultiVector(res_val)
1046+
return layout.MultiVector(res_val, copy=False)
10471047

10481048

10491049
@numba.njit
@@ -1090,7 +1090,7 @@ def val_annihilate_k(K_val, C_val):
10901090

10911091
def annihilate_k(K, C):
10921092
""" Removes K from C = KX via (K[0] - K[4])*C """
1093-
return layout.MultiVector(val_annihilate_k(K.value, C.value))
1093+
return layout.MultiVector(val_annihilate_k(K.value, C.value), copy=False)
10941094

10951095

10961096
@numba.njit
@@ -1275,7 +1275,7 @@ def motor_between_rounds(X1, X2):
12751275
Calculate the motor between any pair of rounds of the same grade
12761276
Line up the carriers, then line up the centers
12771277
"""
1278-
return layout.MultiVector(val_motor_between_rounds(X1.value, X2.value))
1278+
return layout.MultiVector(val_motor_between_rounds(X1.value, X2.value), copy=False)
12791279

12801280

12811281
@numba.njit
@@ -1333,7 +1333,7 @@ def motor_between_objects(X1, X2):
13331333
"""
13341334
Calculates a motor that takes X1 to X2
13351335
"""
1336-
return layout.MultiVector(val_motor_between_objects(X1.value, X2.value))
1336+
return layout.MultiVector(val_motor_between_objects(X1.value, X2.value), copy=False)
13371337

13381338

13391339
def calculate_S_over_mu(X1, X2):
@@ -1492,7 +1492,7 @@ def val_normalised(mv_val):
14921492

14931493
def normalised(mv):
14941494
""" fast version of the normal() function """
1495-
return layout.MultiVector(val_normalised(mv.value))
1495+
return layout.MultiVector(val_normalised(mv.value), copy=False)
14961496

14971497

14981498
@numba.njit
@@ -1517,12 +1517,12 @@ def val_rotor_between_lines(L1_val, L2_val):
15171517

15181518
def rotor_between_lines(L1, L2):
15191519
""" return the rotor between two lines """
1520-
return layout.MultiVector(val_rotor_between_lines(L1.value, L2.value))
1520+
return layout.MultiVector(val_rotor_between_lines(L1.value, L2.value), copy=False)
15211521

15221522

15231523
def rotor_between_planes(P1, P2):
15241524
""" return the rotor between two planes """
1525-
return layout.MultiVector(val_rotor_rotor_between_planes(P1.value, P2.value))
1525+
return layout.MultiVector(val_rotor_rotor_between_planes(P1.value, P2.value), copy=False)
15261526

15271527

15281528
@numba.njit
@@ -1614,7 +1614,7 @@ def random_circle():
16141614
mv_a = val_random_euc_mv()
16151615
mv_b = val_random_euc_mv()
16161616
mv_c = val_random_euc_mv()
1617-
return layout.MultiVector(val_normalised(omt_func(omt_func(val_up(mv_a), val_up(mv_b)), val_up(mv_c))))
1617+
return layout.MultiVector(val_normalised(omt_func(omt_func(val_up(mv_a), val_up(mv_b)), val_up(mv_c))), copy=False)
16181618

16191619

16201620
def random_sphere_at_origin():
@@ -1664,7 +1664,7 @@ def val_apply_rotor(mv_val, rotor_val):
16641664

16651665
def apply_rotor(mv_in, rotor):
16661666
""" Applies rotor to multivector in a fast way """
1667-
return layout.MultiVector(val_apply_rotor(mv_in.value, rotor.value))
1667+
return layout.MultiVector(val_apply_rotor(mv_in.value, rotor.value), copy=False)
16681668

16691669

16701670
@numba.njit
@@ -1675,7 +1675,7 @@ def val_apply_rotor_inv(mv_val, rotor_val, rotor_val_inv):
16751675

16761676
def apply_rotor_inv(mv_in, rotor, rotor_inv):
16771677
""" Applies rotor to multivector in a fast way takes pre computed adjoint"""
1678-
return layout.MultiVector(val_apply_rotor_inv(mv_in.value, rotor.value, rotor_inv.value))
1678+
return layout.MultiVector(val_apply_rotor_inv(mv_in.value, rotor.value, rotor_inv.value), copy=False)
16791679

16801680

16811681
@numba.njit
@@ -1698,14 +1698,14 @@ def val_convert_2D_polar_line_to_conformal_line(rho, theta):
16981698
p1_val = val_convert_2D_point_to_conformal(x1, y1)
16991699
p2_val = val_convert_2D_point_to_conformal(x2, y2)
17001700
line_val = omt_func(omt_func(p1_val, p2_val), ninf_val)
1701-
line_val = line_val/abs(layout.MultiVector(line_val))
1701+
line_val = line_val/abs(layout.MultiVector(line_val), copy=False)
17021702
return line_val
17031703

17041704

17051705
def convert_2D_polar_line_to_conformal_line(rho, theta):
17061706
""" Converts a 2D polar line to a conformal line """
17071707
line_val = val_convert_2D_polar_line_to_conformal_line(rho, theta)
1708-
return layout.MultiVector(line_val)
1708+
return layout.MultiVector(line_val, copy=False)
17091709

17101710

17111711
@numba.njit
@@ -1718,7 +1718,7 @@ def val_up(mv_val):
17181718

17191719
def fast_up(mv):
17201720
""" Fast up mapping """
1721-
return layout.MultiVector(val_up(mv.value))
1721+
return layout.MultiVector(val_up(mv.value), copy=False)
17221722

17231723

17241724
@numba.njit
@@ -1743,14 +1743,14 @@ def val_down(mv_val):
17431743

17441744
def fast_down(mv):
17451745
""" A fast version of down() """
1746-
return layout.MultiVector(val_down(mv.value))
1746+
return layout.MultiVector(val_down(mv.value), copy=False)
17471747

17481748

17491749
def val_distance_point_to_line(point, line):
17501750
"""
17511751
Returns the euclidean distance between a point and a line
17521752
"""
1753-
return float(abs(layout.MultiVector(omt_func(point, line))))
1753+
return float(abs(layout.MultiVector(omt_func(point, line))), copy=False)
17541754

17551755

17561756
@numba.njit
@@ -1764,7 +1764,7 @@ def val_convert_2D_point_to_conformal(x, y):
17641764

17651765
def convert_2D_point_to_conformal(x, y):
17661766
""" Convert a 2D point to conformal """
1767-
return layout.MultiVector(val_convert_2D_point_to_conformal(x, y))
1767+
return layout.MultiVector(val_convert_2D_point_to_conformal(x, y), copy=False)
17681768

17691769

17701770
def distance_polar_line_to_euc_point_2d(rho, theta, x, y):
@@ -1789,7 +1789,7 @@ def fast_dual(a):
17891789
"""
17901790
Fast dual
17911791
"""
1792-
return layout.MultiVector(dual_func(a.value))
1792+
return layout.MultiVector(dual_func(a.value), copy=False)
17931793

17941794

17951795
class ConformalMVArray(cf.MVArray):
@@ -1854,7 +1854,7 @@ def from_value_array(value_array):
18541854

18551855

18561856
v_dual = np.vectorize(fast_dual, otypes=[ConformalMVArray])
1857-
v_new_mv = np.vectorize(lambda v: layout.MultiVector(v), otypes=[ConformalMVArray], signature='(n)->()')
1857+
v_new_mv = np.vectorize(lambda v: layout.MultiVector(v), otypes=[ConformalMVArray], signature='(n)->()', copy=False)
18581858
v_up = np.vectorize(fast_up, otypes=[ConformalMVArray])
18591859
v_down = np.vectorize(fast_down, otypes=[ConformalMVArray])
18601860
v_apply_rotor_inv = np.vectorize(apply_rotor_inv, otypes=[ConformalMVArray])

clifford/tools/g3c/cost_functions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def midpoint_and_error_of_line_cluster_eig(line_cluster):
6262

6363
point_val = np.zeros(32)
6464
point_val[1:6] = np.matmul(mat2solve, start)
65-
new_mv = layout.MultiVector(point_val)
65+
new_mv = layout.MultiVector(point_val, copy=False)
6666
new_mv = normalise_n_minus_1((new_mv * einf * new_mv)(1))
6767
return new_mv, val_point_to_line_cluster_distance(new_mv.value, line_cluster_array)
6868

@@ -84,7 +84,7 @@ def midpoint_and_error_of_line_cluster_svd(line_cluster):
8484

8585
point_val = np.zeros(32)
8686
point_val[np.array(layout.gradeList) == grade_val] = v[:, 1]
87-
new_mv = layout.MultiVector(point_val)
87+
new_mv = layout.MultiVector(point_val, copy=False)
8888
# new_mv = normalise_n_minus_1(new_mv * einf * new_mv)
8989
new_point = normalise_n_minus_1(new_mv) # up(down(new_mv) / 2)
9090
return new_point, val_point_to_line_cluster_distance(new_point.value, line_cluster_array)
@@ -98,7 +98,7 @@ def midpoint_and_error_of_line_cluster(line_cluster):
9898
"""
9999
line_cluster_array = np.array([l.value for l in line_cluster])
100100
cp_val = val_midpoint_of_line_cluster(line_cluster_array)
101-
return layout.MultiVector(cp_val), val_point_to_line_cluster_distance(cp_val, line_cluster_array)
101+
return layout.MultiVector(cp_val), val_point_to_line_cluster_distance(cp_val, line_cluster_array, copy=False)
102102

103103

104104
def midpoint_and_error_of_line_cluster_grad(line_cluster):
@@ -109,7 +109,7 @@ def midpoint_and_error_of_line_cluster_grad(line_cluster):
109109
"""
110110
line_cluster_array = np.array([l.value for l in line_cluster])
111111
cp_val = val_midpoint_of_line_cluster_grad(line_cluster_array)
112-
return layout.MultiVector(cp_val), val_point_to_line_cluster_distance(cp_val, line_cluster_array)
112+
return layout.MultiVector(cp_val), val_point_to_line_cluster_distance(cp_val, line_cluster_array, copy=False)
113113

114114

115115
def line_plane_cost(line, plane):

clifford/tools/g3c/object_fitting.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def fit_circle(point_list):
4949
"""
5050
Performs Leo Dorsts circle fitting technique
5151
"""
52-
return layout.MultiVector(val_fit_circle(np.array([p.value for p in point_list])))
52+
return layout.MultiVector(val_fit_circle(np.array([p.value for p in point_list])), copy=False)
5353

5454

5555
@numba.njit
@@ -85,7 +85,7 @@ def fit_line(point_list):
8585
"""
8686
Does line fitting with combo J.Lasenbys method and L. Dorsts
8787
"""
88-
return layout.MultiVector(val_fit_line(np.array([p.value for p in point_list])))
88+
return layout.MultiVector(val_fit_line(np.array([p.value for p in point_list])), copy=False)
8989

9090

9191
@numba.njit
@@ -124,7 +124,7 @@ def fit_sphere(point_list):
124124
"""
125125
Performs Leo Dorsts sphere fitting technique
126126
"""
127-
return layout.MultiVector(val_fit_sphere(np.array([p.value for p in point_list])))
127+
return layout.MultiVector(val_fit_sphere(np.array([p.value for p in point_list])), copy=False)
128128

129129

130130
@numba.njit
@@ -158,4 +158,4 @@ def fit_plane(point_list):
158158
"""
159159
Does plane fitting with combo J.Lasenbys method and L. Dorsts
160160
"""
161-
return layout.MultiVector(val_fit_plane(np.array([p.value for p in point_list])))
161+
return layout.MultiVector(val_fit_plane(np.array([p.value for p in point_list])), copy=False)

clifford/tools/g3c/rotor_estimation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def extract_rotor_from_TRS_mat_est(mat_est):
8484
Given a matrix of the form [TRS_left@~TRS_right] returns TRS
8585
"""
8686
sph = (up(e1)^up(-e1)^up(e2)^up(e3)).normal()*I5
87-
sph2 = layout.MultiVector(mat_est@sph.value).normal()
87+
sph2 = layout.MultiVector(mat_est@sph.value, copy=False).normal()
8888
t = down((sph2*einf*sph2)(1))
8989
T = generate_translation_rotor(t)
9090
S = generate_dilation_rotor(get_radius_from_sphere(sph2*I5)/get_radius_from_sphere(sph*I5))
@@ -192,7 +192,7 @@ def de_keninck_twist(Y, X, guess=None):
192192
"""
193193
if guess is None:
194194
guess = (1.0 + 0*e1)
195-
return layout.MultiVector(val_de_keninck_twist(Y.value, X.value, guess.value))
195+
return layout.MultiVector(val_de_keninck_twist(Y.value, X.value, guess.value), copy=False)
196196

197197

198198
def average_estimator(reference_model, query_model):

clifford/tools/g3c/rotor_parameterisation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ def ga_exp(B):
195195
Fast implementation of the translation and rotation specific exp function
196196
"""
197197
if np.sum(np.abs(B.value)) < np.finfo(float).eps:
198-
return layout.MultiVector(unit_scalar_mv.value)
199-
return layout.MultiVector(val_exp(B.value))
198+
return layout.MultiVector(unit_scalar_mv.value, copy=False)
199+
return layout.MultiVector(val_exp(B.value), copy=False)
200200

201201

202202
def interpolate_TR_rotors(R_n_plus_1, R_n, interpolation_fraction):
@@ -295,7 +295,7 @@ def TR_biv_params_to_rotor(x):
295295
"""
296296
Converts between the parameters of a TR bivector and the rotor that it is generating
297297
"""
298-
return layout.MultiVector(val_TR_biv_params_to_rotor(x))
298+
return layout.MultiVector(val_TR_biv_params_to_rotor(x), copy=False)
299299

300300

301301
rotorconversion = TR_biv_params_to_rotor
@@ -318,4 +318,4 @@ def R_biv_params_to_rotor(x):
318318
"""
319319
Converts between the parameters of a R bivector and the rotor that it is generating
320320
"""
321-
return layout.MultiVector(val_R_biv_params_to_rotor(x))
321+
return layout.MultiVector(val_R_biv_params_to_rotor(x), copy=False)

0 commit comments

Comments
 (0)