Skip to content

Commit e86d0a1

Browse files
committed
pre-commit: apply on Python files
1 parent 2cd9fa6 commit e86d0a1

14 files changed

+327
-277
lines changed

benchmarks/bench-switch.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
import timeit
88

99
from IPython import get_ipython
10+
1011
ipython = get_ipython()
1112

1213
quat = eigenpy.Quaternion()
13-
a = [0., 0., 0.]
14+
a = [0.0, 0.0, 0.0]
1415

1516
cmd1 = "timeit np.array(a)"
1617
print("\n")
@@ -50,7 +51,7 @@
5051
ipython.magic(cmd5)
5152
print("\n")
5253

53-
a_matrix = np.matrix(a);
54+
a_matrix = np.matrix(a)
5455
cmd6 = "timeit np.asarray(a_matrix)"
5556
print(cmd6)
5657
ipython.magic(cmd6)

unittest/python/test_LDLT.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,22 @@
44
import numpy.linalg as la
55

66
dim = 100
7-
A = np.random.rand(dim,dim)
7+
A = np.random.rand(dim, dim)
88

9-
A = (A + A.T)*0.5 + np.diag(10. + np.random.rand(dim))
9+
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
1010

1111
ldlt = eigenpy.LDLT(A)
1212

1313
L = ldlt.matrixL()
1414
D = ldlt.vectorD()
1515
P = ldlt.transpositionsP()
1616

17-
assert eigenpy.is_approx(np.transpose(P).dot(L.dot(np.diag(D).dot(np.transpose(L).dot(P)))),A)
17+
assert eigenpy.is_approx(
18+
np.transpose(P).dot(L.dot(np.diag(D).dot(np.transpose(L).dot(P)))), A
19+
)
1820

19-
X = np.random.rand(dim,20)
21+
X = np.random.rand(dim, 20)
2022
B = A.dot(X)
2123
X_est = ldlt.solve(B)
22-
assert eigenpy.is_approx(X,X_est)
23-
assert eigenpy.is_approx(A.dot(X_est),B)
24+
assert eigenpy.is_approx(X, X_est)
25+
assert eigenpy.is_approx(A.dot(X_est), B)

unittest/python/test_LLT.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44
import numpy.linalg as la
55

66
dim = 100
7-
A = np.random.rand(dim,dim)
7+
A = np.random.rand(dim, dim)
88

9-
A = (A + A.T)*0.5 + np.diag(10. + np.random.rand(dim))
9+
A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
1010

1111
llt = eigenpy.LLT(A)
1212

1313
L = llt.matrixL()
14-
assert eigenpy.is_approx(L.dot(np.transpose(L)),A)
14+
assert eigenpy.is_approx(L.dot(np.transpose(L)), A)
1515

16-
X = np.random.rand(dim,20)
16+
X = np.random.rand(dim, 20)
1717
B = A.dot(X)
1818
X_est = llt.solve(B)
19-
assert eigenpy.is_approx(X,X_est)
20-
assert eigenpy.is_approx(A.dot(X_est),B)
19+
assert eigenpy.is_approx(X, X_est)
20+
assert eigenpy.is_approx(A.dot(X_est), B)

unittest/python/test_MINRES.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
minres = eigenpy.MINRES(A)
1010

11-
X = np.random.rand(dim,20)
11+
X = np.random.rand(dim, 20)
1212
B = A.dot(X)
1313
X_est = minres.solve(B)
14-
print("A.dot(X_est):",A.dot(X_est))
15-
print("B:",B)
16-
assert eigenpy.is_approx(A.dot(X_est),B,1e-6)
14+
print("A.dot(X_est):", A.dot(X_est))
15+
print("B:", B)
16+
assert eigenpy.is_approx(A.dot(X_est), B, 1e-6)

unittest/python/test_complex.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,22 @@
88
rows = 10
99
cols = 20
1010

11+
1112
def test(dtype):
12-
Z = np.zeros((rows,cols),dtype=dtype)
13-
Z.real = np.random.rand(rows,cols)
14-
Z.imag = np.random.rand(rows,cols)
15-
16-
Z_real = real(Z)
17-
assert (Z_real == Z.real).all()
18-
Z_imag = imag(Z)
19-
assert (Z_imag == Z.imag).all()
20-
21-
Y = np.ones((rows,cols))
22-
Y_complex = ascomplex(Y)
23-
assert (Y_complex.real == Y).all()
24-
assert (Y_complex.imag == np.zeros((rows,cols))).all()
13+
Z = np.zeros((rows, cols), dtype=dtype)
14+
Z.real = np.random.rand(rows, cols)
15+
Z.imag = np.random.rand(rows, cols)
16+
17+
Z_real = real(Z)
18+
assert (Z_real == Z.real).all()
19+
Z_imag = imag(Z)
20+
assert (Z_imag == Z.imag).all()
21+
22+
Y = np.ones((rows, cols))
23+
Y_complex = ascomplex(Y)
24+
assert (Y_complex.real == Y).all()
25+
assert (Y_complex.imag == np.zeros((rows, cols))).all()
26+
2527

2628
# Float
2729
test(np.csingle)

unittest/python/test_eigen_ref.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
import numpy as np
22
from eigen_ref import *
33

4+
45
def test(mat):
56

6-
printMatrix(mat)
7-
fill(mat,1.)
8-
printMatrix(mat)
9-
assert np.array_equal(mat,np.full(mat.shape,1.))
7+
printMatrix(mat)
8+
fill(mat, 1.0)
9+
printMatrix(mat)
10+
assert np.array_equal(mat, np.full(mat.shape, 1.0))
11+
12+
A_ref = asRef(mat.shape[0], mat.shape[1])
13+
A_ref.fill(1.0)
14+
A_ref2 = asRef(mat.shape[0], mat.shape[1])
1015

11-
A_ref = asRef(mat.shape[0],mat.shape[1])
12-
A_ref.fill(1.)
13-
A_ref2 = asRef(mat.shape[0],mat.shape[1])
16+
assert np.array_equal(A_ref, A_ref2)
1417

15-
assert np.array_equal(A_ref,A_ref2)
18+
A_ref2.fill(0)
19+
assert np.array_equal(A_ref, A_ref2)
1620

17-
A_ref2.fill(0)
18-
assert np.array_equal(A_ref,A_ref2)
21+
ref = asRef(mat)
22+
assert np.all(ref == mat)
1923

20-
ref = asRef(mat)
21-
assert np.all(ref == mat)
24+
const_ref = asConstRef(mat)
25+
assert np.all(const_ref == mat)
2226

23-
const_ref = asConstRef(mat)
24-
assert np.all(const_ref == mat)
2527

2628
rows = 10
2729
cols = 30
2830

29-
mat = np.ones((rows,cols),order='F')
31+
mat = np.ones((rows, cols), order="F")
3032

3133
test(mat)
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
import eigenpy
2+
23
eigenpy.switchToNumpyArray()
34

45
import numpy as np
56
import numpy.linalg as la
67

78
dim = 100
8-
A = np.random.rand(dim,dim)
9+
A = np.random.rand(dim, dim)
910

1011
es = eigenpy.EigenSolver(A)
1112

1213
V = es.eigenvectors()
1314
D = es.eigenvalues()
1415

15-
assert eigenpy.is_approx(A.dot(V).real,V.dot(np.diag(D)).real)
16-
assert eigenpy.is_approx(A.dot(V).imag,V.dot(np.diag(D)).imag)
16+
assert eigenpy.is_approx(A.dot(V).real, V.dot(np.diag(D)).real)
17+
assert eigenpy.is_approx(A.dot(V).imag, V.dot(np.diag(D)).imag)

unittest/python/test_geometry.py

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -2,83 +2,87 @@
22

33
from geometry import *
44
import numpy as np
5-
from numpy import cos,sin
5+
from numpy import cos, sin
66

77
verbose = True
88

9-
def isapprox(a,b,epsilon=1e-6):
10-
if issubclass(a.__class__,np.ndarray) and issubclass(b.__class__,np.ndarray):
11-
return np.allclose(a,b,epsilon)
9+
10+
def isapprox(a, b, epsilon=1e-6):
11+
if issubclass(a.__class__, np.ndarray) and issubclass(b.__class__, np.ndarray):
12+
return np.allclose(a, b, epsilon)
1213
else:
13-
return abs(a-b)<epsilon
14+
return abs(a - b) < epsilon
15+
1416

1517
# --- Quaternion ---------------------------------------------------------------
1618
# Coefficient initialisation
1719
verbose and print("[Quaternion] Coefficient initialisation")
18-
q = Quaternion(1,2,3,4)
20+
q = Quaternion(1, 2, 3, 4)
1921
q.normalize()
20-
assert(isapprox(np.linalg.norm(q.coeffs()),q.norm()))
21-
assert(isapprox(np.linalg.norm(q.coeffs()),1))
22+
assert isapprox(np.linalg.norm(q.coeffs()), q.norm())
23+
assert isapprox(np.linalg.norm(q.coeffs()), 1)
2224

2325
# Coefficient-vector initialisation
2426
verbose and print("[Quaternion] Coefficient-vector initialisation")
25-
v = np.array([0.5,-0.5,0.5,0.5])
27+
v = np.array([0.5, -0.5, 0.5, 0.5])
2628
qv = Quaternion(v)
27-
assert(isapprox(qv.coeffs(), v))
29+
assert isapprox(qv.coeffs(), v)
2830

2931
# Angle axis initialisation
3032
verbose and print("[Quaternion] AngleAxis initialisation")
3133
r = AngleAxis(q)
3234
q2 = Quaternion(r)
33-
assert(q==q)
34-
assert(isapprox(q.coeffs(),q2.coeffs()))
35-
assert(q2.isApprox(q2))
36-
assert(q2.isApprox(q2,1e-2))
35+
assert q == q
36+
assert isapprox(q.coeffs(), q2.coeffs())
37+
assert q2.isApprox(q2)
38+
assert q2.isApprox(q2, 1e-2)
3739

3840
Rq = q.matrix()
3941
Rr = r.matrix()
40-
assert(isapprox(Rq.dot(Rq.T),np.eye(3)))
41-
assert(isapprox(Rr,Rq))
42+
assert isapprox(Rq.dot(Rq.T), np.eye(3))
43+
assert isapprox(Rr, Rq)
4244

4345
# Rotation matrix initialisation
4446
verbose and print("[Quaternion] Rotation Matrix initialisation")
4547
qR = Quaternion(Rr)
46-
assert(q.isApprox(qR))
47-
assert(isapprox(q.coeffs(),qR.coeffs()))
48+
assert q.isApprox(qR)
49+
assert isapprox(q.coeffs(), qR.coeffs())
4850

49-
assert(isapprox(qR[3],1./np.sqrt(30)))
51+
assert isapprox(qR[3], 1.0 / np.sqrt(30))
5052
try:
51-
qR[5]
52-
print("Error, this message should not appear.")
53+
qR[5]
54+
print("Error, this message should not appear.")
5355
except RuntimeError as e:
54-
if verbose: print("As expected, caught exception: ", e)
56+
if verbose:
57+
print("As expected, caught exception: ", e)
5558

5659
# --- Angle Vector ------------------------------------------------
57-
r = AngleAxis(.1,np.array([1,0,0],np.double))
58-
if verbose: print("Rx(.1) = \n\n",r.matrix(),"\n")
59-
assert( isapprox(r.matrix()[2,2],cos(r.angle)))
60-
assert( isapprox(r.axis,np.array([1.,0,0])) )
61-
assert( isapprox(r.angle,0.1) )
62-
assert(r.isApprox(r))
63-
assert(r.isApprox(r,1e-2))
60+
r = AngleAxis(0.1, np.array([1, 0, 0], np.double))
61+
if verbose:
62+
print("Rx(.1) = \n\n", r.matrix(), "\n")
63+
assert isapprox(r.matrix()[2, 2], cos(r.angle))
64+
assert isapprox(r.axis, np.array([1.0, 0, 0]))
65+
assert isapprox(r.angle, 0.1)
66+
assert r.isApprox(r)
67+
assert r.isApprox(r, 1e-2)
6468

65-
r.axis = np.array([0,1,0],np.double).T
66-
assert( isapprox(r.matrix()[0,0],cos(r.angle)))
69+
r.axis = np.array([0, 1, 0], np.double).T
70+
assert isapprox(r.matrix()[0, 0], cos(r.angle))
6771

6872
ri = r.inverse()
69-
assert( isapprox(ri.angle,-.1) )
73+
assert isapprox(ri.angle, -0.1)
7074

7175
R = r.matrix()
72-
r2 = AngleAxis(np.dot(R,R))
73-
assert( isapprox(r2.angle,r.angle*2) )
76+
r2 = AngleAxis(np.dot(R, R))
77+
assert isapprox(r2.angle, r.angle * 2)
7478

7579
# --- USER FUNCTIONS -----------------------------------------------------------
7680
ro = testOutAngleAxis()
77-
assert(ro.__class__ == AngleAxis)
81+
assert ro.__class__ == AngleAxis
7882
res = testInAngleAxis(r)
79-
assert( res==r.angle )
83+
assert res == r.angle
8084

8185
qo = testOutQuaternion()
82-
assert(qo.__class__ == Quaternion)
86+
assert qo.__class__ == Quaternion
8387
res = testInQuaternion(q)
84-
assert(q.norm() == res)
88+
assert q.norm() == res

0 commit comments

Comments
 (0)