From e86d0a196e6410ad2c6b0843d396f040d7970cb0 Mon Sep 17 00:00:00 2001
From: Justin Carpentier <justin.carpentier@inria.fr>
Date: Fri, 8 Apr 2022 19:21:29 +0200
Subject: [PATCH] pre-commit: apply on Python files

---
 benchmarks/bench-switch.py                    |   5 +-
 unittest/python/test_LDLT.py                  |  14 +-
 unittest/python/test_LLT.py                   |  12 +-
 unittest/python/test_MINRES.py                |   8 +-
 unittest/python/test_complex.py               |  28 ++-
 unittest/python/test_eigen_ref.py             |  32 +--
 unittest/python/test_eigen_solver.py          |   7 +-
 unittest/python/test_geometry.py              |  80 +++---
 unittest/python/test_matrix.py                | 238 ++++++++++--------
 unittest/python/test_return_by_ref.py         |  71 +++---
 .../python/test_self_adjoint_eigen_solver.py  |   7 +-
 unittest/python/test_switch.py                |   4 +-
 unittest/python/test_user_type.py             |  96 +++----
 unittest/python/test_version.py               |   2 +-
 14 files changed, 327 insertions(+), 277 deletions(-)

diff --git a/benchmarks/bench-switch.py b/benchmarks/bench-switch.py
index 6f42cc5..289a95c 100644
--- a/benchmarks/bench-switch.py
+++ b/benchmarks/bench-switch.py
@@ -7,10 +7,11 @@ import time
 import timeit
 
 from IPython import get_ipython
+
 ipython = get_ipython()
 
 quat = eigenpy.Quaternion()
-a = [0., 0., 0.]
+a = [0.0, 0.0, 0.0]
 
 cmd1 = "timeit np.array(a)"
 print("\n")
@@ -50,7 +51,7 @@ print(cmd5)
 ipython.magic(cmd5)
 print("\n")
 
-a_matrix = np.matrix(a);
+a_matrix = np.matrix(a)
 cmd6 = "timeit np.asarray(a_matrix)"
 print(cmd6)
 ipython.magic(cmd6)
diff --git a/unittest/python/test_LDLT.py b/unittest/python/test_LDLT.py
index 9efcb2a..06cae89 100644
--- a/unittest/python/test_LDLT.py
+++ b/unittest/python/test_LDLT.py
@@ -4,9 +4,9 @@ import numpy as np
 import numpy.linalg as la
 
 dim = 100
-A = np.random.rand(dim,dim)
+A = np.random.rand(dim, dim)
 
-A = (A + A.T)*0.5 + np.diag(10. + np.random.rand(dim))
+A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
 
 ldlt = eigenpy.LDLT(A)
 
@@ -14,10 +14,12 @@ L = ldlt.matrixL()
 D = ldlt.vectorD()
 P = ldlt.transpositionsP()
 
-assert eigenpy.is_approx(np.transpose(P).dot(L.dot(np.diag(D).dot(np.transpose(L).dot(P)))),A)
+assert eigenpy.is_approx(
+    np.transpose(P).dot(L.dot(np.diag(D).dot(np.transpose(L).dot(P)))), A
+)
 
-X = np.random.rand(dim,20)
+X = np.random.rand(dim, 20)
 B = A.dot(X)
 X_est = ldlt.solve(B)
-assert eigenpy.is_approx(X,X_est)
-assert eigenpy.is_approx(A.dot(X_est),B)
+assert eigenpy.is_approx(X, X_est)
+assert eigenpy.is_approx(A.dot(X_est), B)
diff --git a/unittest/python/test_LLT.py b/unittest/python/test_LLT.py
index 430fc44..21cf275 100644
--- a/unittest/python/test_LLT.py
+++ b/unittest/python/test_LLT.py
@@ -4,17 +4,17 @@ import numpy as np
 import numpy.linalg as la
 
 dim = 100
-A = np.random.rand(dim,dim)
+A = np.random.rand(dim, dim)
 
-A = (A + A.T)*0.5 + np.diag(10. + np.random.rand(dim))
+A = (A + A.T) * 0.5 + np.diag(10.0 + np.random.rand(dim))
 
 llt = eigenpy.LLT(A)
 
 L = llt.matrixL()
-assert eigenpy.is_approx(L.dot(np.transpose(L)),A)
+assert eigenpy.is_approx(L.dot(np.transpose(L)), A)
 
-X = np.random.rand(dim,20)
+X = np.random.rand(dim, 20)
 B = A.dot(X)
 X_est = llt.solve(B)
-assert eigenpy.is_approx(X,X_est)
-assert eigenpy.is_approx(A.dot(X_est),B)
+assert eigenpy.is_approx(X, X_est)
+assert eigenpy.is_approx(A.dot(X_est), B)
diff --git a/unittest/python/test_MINRES.py b/unittest/python/test_MINRES.py
index 307ab3c..02287ad 100644
--- a/unittest/python/test_MINRES.py
+++ b/unittest/python/test_MINRES.py
@@ -8,9 +8,9 @@ A = np.eye(dim)
 
 minres = eigenpy.MINRES(A)
 
-X = np.random.rand(dim,20)
+X = np.random.rand(dim, 20)
 B = A.dot(X)
 X_est = minres.solve(B)
-print("A.dot(X_est):",A.dot(X_est))
-print("B:",B)
-assert eigenpy.is_approx(A.dot(X_est),B,1e-6)
+print("A.dot(X_est):", A.dot(X_est))
+print("B:", B)
+assert eigenpy.is_approx(A.dot(X_est), B, 1e-6)
diff --git a/unittest/python/test_complex.py b/unittest/python/test_complex.py
index 40ef195..0f1eba2 100644
--- a/unittest/python/test_complex.py
+++ b/unittest/python/test_complex.py
@@ -8,20 +8,22 @@ switchToNumpyArray()
 rows = 10
 cols = 20
 
+
 def test(dtype):
-  Z = np.zeros((rows,cols),dtype=dtype)
-  Z.real = np.random.rand(rows,cols)
-  Z.imag = np.random.rand(rows,cols)
-
-  Z_real = real(Z)
-  assert (Z_real == Z.real).all()
-  Z_imag = imag(Z)
-  assert (Z_imag == Z.imag).all()
-
-  Y = np.ones((rows,cols))
-  Y_complex = ascomplex(Y)
-  assert (Y_complex.real == Y).all()
-  assert (Y_complex.imag == np.zeros((rows,cols))).all()
+    Z = np.zeros((rows, cols), dtype=dtype)
+    Z.real = np.random.rand(rows, cols)
+    Z.imag = np.random.rand(rows, cols)
+
+    Z_real = real(Z)
+    assert (Z_real == Z.real).all()
+    Z_imag = imag(Z)
+    assert (Z_imag == Z.imag).all()
+
+    Y = np.ones((rows, cols))
+    Y_complex = ascomplex(Y)
+    assert (Y_complex.real == Y).all()
+    assert (Y_complex.imag == np.zeros((rows, cols))).all()
+
 
 # Float
 test(np.csingle)
diff --git a/unittest/python/test_eigen_ref.py b/unittest/python/test_eigen_ref.py
index 5ce4aaa..48c1ab9 100644
--- a/unittest/python/test_eigen_ref.py
+++ b/unittest/python/test_eigen_ref.py
@@ -1,31 +1,33 @@
 import numpy as np
 from eigen_ref import *
 
+
 def test(mat):
 
-  printMatrix(mat)
-  fill(mat,1.)
-  printMatrix(mat)
-  assert np.array_equal(mat,np.full(mat.shape,1.))
+    printMatrix(mat)
+    fill(mat, 1.0)
+    printMatrix(mat)
+    assert np.array_equal(mat, np.full(mat.shape, 1.0))
+
+    A_ref = asRef(mat.shape[0], mat.shape[1])
+    A_ref.fill(1.0)
+    A_ref2 = asRef(mat.shape[0], mat.shape[1])
 
-  A_ref = asRef(mat.shape[0],mat.shape[1])
-  A_ref.fill(1.)
-  A_ref2 = asRef(mat.shape[0],mat.shape[1])
+    assert np.array_equal(A_ref, A_ref2)
 
-  assert np.array_equal(A_ref,A_ref2)
+    A_ref2.fill(0)
+    assert np.array_equal(A_ref, A_ref2)
 
-  A_ref2.fill(0)
-  assert np.array_equal(A_ref,A_ref2)
+    ref = asRef(mat)
+    assert np.all(ref == mat)
 
-  ref = asRef(mat)
-  assert np.all(ref == mat)
+    const_ref = asConstRef(mat)
+    assert np.all(const_ref == mat)
 
-  const_ref = asConstRef(mat)
-  assert np.all(const_ref == mat)
 
 rows = 10
 cols = 30
 
-mat = np.ones((rows,cols),order='F')
+mat = np.ones((rows, cols), order="F")
 
 test(mat)
diff --git a/unittest/python/test_eigen_solver.py b/unittest/python/test_eigen_solver.py
index 68efa1c..a88f2f7 100644
--- a/unittest/python/test_eigen_solver.py
+++ b/unittest/python/test_eigen_solver.py
@@ -1,16 +1,17 @@
 import eigenpy
+
 eigenpy.switchToNumpyArray()
 
 import numpy as np
 import numpy.linalg as la
 
 dim = 100
-A = np.random.rand(dim,dim)
+A = np.random.rand(dim, dim)
 
 es = eigenpy.EigenSolver(A)
 
 V = es.eigenvectors()
 D = es.eigenvalues()
 
-assert eigenpy.is_approx(A.dot(V).real,V.dot(np.diag(D)).real)
-assert eigenpy.is_approx(A.dot(V).imag,V.dot(np.diag(D)).imag)
+assert eigenpy.is_approx(A.dot(V).real, V.dot(np.diag(D)).real)
+assert eigenpy.is_approx(A.dot(V).imag, V.dot(np.diag(D)).imag)
diff --git a/unittest/python/test_geometry.py b/unittest/python/test_geometry.py
index 2caa9fc..80ebf26 100644
--- a/unittest/python/test_geometry.py
+++ b/unittest/python/test_geometry.py
@@ -2,83 +2,87 @@ from __future__ import print_function
 
 from geometry import *
 import numpy as np
-from numpy import cos,sin
+from numpy import cos, sin
 
 verbose = True
 
-def isapprox(a,b,epsilon=1e-6):
-    if issubclass(a.__class__,np.ndarray) and issubclass(b.__class__,np.ndarray):
-        return np.allclose(a,b,epsilon)
+
+def isapprox(a, b, epsilon=1e-6):
+    if issubclass(a.__class__, np.ndarray) and issubclass(b.__class__, np.ndarray):
+        return np.allclose(a, b, epsilon)
     else:
-        return abs(a-b)<epsilon
+        return abs(a - b) < epsilon
+
 
 # --- Quaternion ---------------------------------------------------------------
 # Coefficient initialisation
 verbose and print("[Quaternion] Coefficient initialisation")
-q = Quaternion(1,2,3,4)
+q = Quaternion(1, 2, 3, 4)
 q.normalize()
-assert(isapprox(np.linalg.norm(q.coeffs()),q.norm()))
-assert(isapprox(np.linalg.norm(q.coeffs()),1))
+assert isapprox(np.linalg.norm(q.coeffs()), q.norm())
+assert isapprox(np.linalg.norm(q.coeffs()), 1)
 
 # Coefficient-vector initialisation
 verbose and print("[Quaternion] Coefficient-vector initialisation")
-v = np.array([0.5,-0.5,0.5,0.5])
+v = np.array([0.5, -0.5, 0.5, 0.5])
 qv = Quaternion(v)
-assert(isapprox(qv.coeffs(), v))
+assert isapprox(qv.coeffs(), v)
 
 # Angle axis initialisation
 verbose and print("[Quaternion] AngleAxis initialisation")
 r = AngleAxis(q)
 q2 = Quaternion(r)
-assert(q==q)
-assert(isapprox(q.coeffs(),q2.coeffs()))
-assert(q2.isApprox(q2))
-assert(q2.isApprox(q2,1e-2))
+assert q == q
+assert isapprox(q.coeffs(), q2.coeffs())
+assert q2.isApprox(q2)
+assert q2.isApprox(q2, 1e-2)
 
 Rq = q.matrix()
 Rr = r.matrix()
-assert(isapprox(Rq.dot(Rq.T),np.eye(3)))
-assert(isapprox(Rr,Rq))
+assert isapprox(Rq.dot(Rq.T), np.eye(3))
+assert isapprox(Rr, Rq)
 
 # Rotation matrix initialisation
 verbose and print("[Quaternion] Rotation Matrix initialisation")
 qR = Quaternion(Rr)
-assert(q.isApprox(qR))
-assert(isapprox(q.coeffs(),qR.coeffs()))
+assert q.isApprox(qR)
+assert isapprox(q.coeffs(), qR.coeffs())
 
-assert(isapprox(qR[3],1./np.sqrt(30)))
+assert isapprox(qR[3], 1.0 / np.sqrt(30))
 try:
-   qR[5]
-   print("Error, this message should not appear.")
+    qR[5]
+    print("Error, this message should not appear.")
 except RuntimeError as e:
-  if verbose: print("As expected, caught exception: ", e)
+    if verbose:
+        print("As expected, caught exception: ", e)
 
 # --- Angle Vector ------------------------------------------------
-r = AngleAxis(.1,np.array([1,0,0],np.double))
-if verbose: print("Rx(.1) = \n\n",r.matrix(),"\n")
-assert( isapprox(r.matrix()[2,2],cos(r.angle)))
-assert( isapprox(r.axis,np.array([1.,0,0])) )
-assert( isapprox(r.angle,0.1) )
-assert(r.isApprox(r))
-assert(r.isApprox(r,1e-2))
+r = AngleAxis(0.1, np.array([1, 0, 0], np.double))
+if verbose:
+    print("Rx(.1) = \n\n", r.matrix(), "\n")
+assert isapprox(r.matrix()[2, 2], cos(r.angle))
+assert isapprox(r.axis, np.array([1.0, 0, 0]))
+assert isapprox(r.angle, 0.1)
+assert r.isApprox(r)
+assert r.isApprox(r, 1e-2)
 
-r.axis = np.array([0,1,0],np.double).T
-assert( isapprox(r.matrix()[0,0],cos(r.angle)))
+r.axis = np.array([0, 1, 0], np.double).T
+assert isapprox(r.matrix()[0, 0], cos(r.angle))
 
 ri = r.inverse()
-assert( isapprox(ri.angle,-.1) )
+assert isapprox(ri.angle, -0.1)
 
 R = r.matrix()
-r2 = AngleAxis(np.dot(R,R))
-assert( isapprox(r2.angle,r.angle*2) )
+r2 = AngleAxis(np.dot(R, R))
+assert isapprox(r2.angle, r.angle * 2)
 
 # --- USER FUNCTIONS -----------------------------------------------------------
 ro = testOutAngleAxis()
-assert(ro.__class__ == AngleAxis)
+assert ro.__class__ == AngleAxis
 res = testInAngleAxis(r)
-assert( res==r.angle )
+assert res == r.angle
 
 qo = testOutQuaternion()
-assert(qo.__class__ == Quaternion)
+assert qo.__class__ == Quaternion
 res = testInQuaternion(q)
-assert(q.norm() == res)
+assert q.norm() == res
diff --git a/unittest/python/test_matrix.py b/unittest/python/test_matrix.py
index 33b4c02..0edf188 100644
--- a/unittest/python/test_matrix.py
+++ b/unittest/python/test_matrix.py
@@ -5,144 +5,176 @@ import matrix as eigenpy
 
 verbose = True
 
-if verbose: print("===> From empty MatrixXd to Py")
+if verbose:
+    print("===> From empty MatrixXd to Py")
 M = eigenpy.emptyMatrix()
-assert M.shape == (0,0)
+assert M.shape == (0, 0)
 
-if verbose: print("===> From empty VectorXd to Py")
+if verbose:
+    print("===> From empty VectorXd to Py")
 v = eigenpy.emptyVector()
 assert v.shape == (0,)
 
-if verbose: print("===> From MatrixXd to Py")
-M = eigenpy.naturals(3,3,verbose)
-Mcheck = np.reshape(np.array(range(9),np.double),[3,3])
-assert np.array_equal(Mcheck,M)
-
-if verbose: print("===> From Matrix3d to Py")
-M33= eigenpy.naturals33(verbose)
-assert np.array_equal(Mcheck,M33)
-
-if verbose: print("===> From VectorXd to Py")
-v = eigenpy.naturalsX(3,verbose)
-vcheck = np.array(range(3),np.double).T
-assert np.array_equal(vcheck ,v)
-
-if verbose: print("===> From Py to Eigen::MatrixXd")
-if verbose: print("===> From Py to Eigen::MatrixXd")
-if verbose: print("===> From Py to Eigen::MatrixXd")
-Mref = np.reshape(np.array(range(64),np.double),[8,8])
+if verbose:
+    print("===> From MatrixXd to Py")
+M = eigenpy.naturals(3, 3, verbose)
+Mcheck = np.reshape(np.array(range(9), np.double), [3, 3])
+assert np.array_equal(Mcheck, M)
+
+if verbose:
+    print("===> From Matrix3d to Py")
+M33 = eigenpy.naturals33(verbose)
+assert np.array_equal(Mcheck, M33)
+
+if verbose:
+    print("===> From VectorXd to Py")
+v = eigenpy.naturalsX(3, verbose)
+vcheck = np.array(range(3), np.double).T
+assert np.array_equal(vcheck, v)
+
+if verbose:
+    print("===> From Py to Eigen::MatrixXd")
+if verbose:
+    print("===> From Py to Eigen::MatrixXd")
+if verbose:
+    print("===> From Py to Eigen::MatrixXd")
+Mref = np.reshape(np.array(range(64), np.double), [8, 8])
 
 # Test base function
 Mref_from_base = eigenpy.base(Mref)
-assert( np.array_equal(Mref,Mref_from_base) );
+assert np.array_equal(Mref, Mref_from_base)
 
 # Test plain function
 Mref_from_plain = eigenpy.plain(Mref)
-assert( np.array_equal(Mref,Mref_from_plain) );
+assert np.array_equal(Mref, Mref_from_plain)
 
-if verbose: print("===> Matrix 8x8")
+if verbose:
+    print("===> Matrix 8x8")
 M = Mref
-assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
-
-if verbose: print("===> Block 0:3x0:3")
-M = Mref[0:3,0:3]
-assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
-
-if verbose: print("===> Block 1:3x1:3")
-M = Mref[1:3,1:3]
-assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
-
-if verbose: print("===> Block 1:5:2x1:5:2")
-M = Mref[1:5:2,1:5:2]
-assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
-
-if verbose: print("===> Block 1:8:3x1:5")
-M = Mref[1:8:3,1:5]
-assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
-
-if verbose: print("===> Block transpose 1:8:3x1:6:2")
-M = Mref[1:8:3,0:6:2].T
-assert( np.array_equal(M,eigenpy.reflex(M,verbose)) );
-
-if verbose: print("===> Block Vector 1x0:6:2")
-M = Mref[1:2,0:6:2]
-assert( np.array_equal(M.squeeze(),eigenpy.reflex(M,verbose)) );
-
-if verbose: print("===> Block Vector 1x0:6:2 tanspose")
-M = Mref[1:2,0:6:2].T
-assert( np.array_equal(M.squeeze(),eigenpy.reflex(M,verbose)) );
-
-if verbose: print("===> Block Vector 0:6:2x1")
-M = Mref[0:6:2,1:2]
-assert( np.array_equal(M.squeeze(),eigenpy.reflex(M,verbose)) );
-
-if verbose: print("===> Block Vector 0:6:2x1 tanspose")
-M = Mref[0:6:2,1:2].T
-assert( np.array_equal(M.squeeze(),eigenpy.reflex(M,verbose)) );
-
-if verbose: print("===> From Py to Eigen::VectorXd")
-if verbose: print("===> From Py to Eigen::VectorXd")
-if verbose: print("===> From Py to Eigen::VectorXd")
-
-if verbose: print("===> Block Vector 0:6:2x1 1 dim")
-M = Mref[0:6:2,1].T
+assert np.array_equal(M, eigenpy.reflex(M, verbose))
+
+if verbose:
+    print("===> Block 0:3x0:3")
+M = Mref[0:3, 0:3]
+assert np.array_equal(M, eigenpy.reflex(M, verbose))
+
+if verbose:
+    print("===> Block 1:3x1:3")
+M = Mref[1:3, 1:3]
+assert np.array_equal(M, eigenpy.reflex(M, verbose))
+
+if verbose:
+    print("===> Block 1:5:2x1:5:2")
+M = Mref[1:5:2, 1:5:2]
+assert np.array_equal(M, eigenpy.reflex(M, verbose))
+
+if verbose:
+    print("===> Block 1:8:3x1:5")
+M = Mref[1:8:3, 1:5]
+assert np.array_equal(M, eigenpy.reflex(M, verbose))
+
+if verbose:
+    print("===> Block transpose 1:8:3x1:6:2")
+M = Mref[1:8:3, 0:6:2].T
+assert np.array_equal(M, eigenpy.reflex(M, verbose))
+
+if verbose:
+    print("===> Block Vector 1x0:6:2")
+M = Mref[1:2, 0:6:2]
+assert np.array_equal(M.squeeze(), eigenpy.reflex(M, verbose))
+
+if verbose:
+    print("===> Block Vector 1x0:6:2 tanspose")
+M = Mref[1:2, 0:6:2].T
+assert np.array_equal(M.squeeze(), eigenpy.reflex(M, verbose))
+
+if verbose:
+    print("===> Block Vector 0:6:2x1")
+M = Mref[0:6:2, 1:2]
+assert np.array_equal(M.squeeze(), eigenpy.reflex(M, verbose))
+
+if verbose:
+    print("===> Block Vector 0:6:2x1 tanspose")
+M = Mref[0:6:2, 1:2].T
+assert np.array_equal(M.squeeze(), eigenpy.reflex(M, verbose))
+
+if verbose:
+    print("===> From Py to Eigen::VectorXd")
+if verbose:
+    print("===> From Py to Eigen::VectorXd")
+if verbose:
+    print("===> From Py to Eigen::VectorXd")
+
+if verbose:
+    print("===> Block Vector 0:6:2x1 1 dim")
+M = Mref[0:6:2, 1].T
 # TODO
 # assert( np.array_equal(M.T,eigenpy.reflexV(M,verbose)) );
 
-if verbose: print("===> Block Vector 0:6:2x1")
-M = Mref[0:6:2,1:2]
-assert( np.array_equal(M.squeeze(),eigenpy.reflexV(M,verbose)) );
+if verbose:
+    print("===> Block Vector 0:6:2x1")
+M = Mref[0:6:2, 1:2]
+assert np.array_equal(M.squeeze(), eigenpy.reflexV(M, verbose))
 
-if verbose: print("===> Block Vector 0:6:2x1 transpose")
-M = Mref[0:6:2,1:2].T
+if verbose:
+    print("===> Block Vector 0:6:2x1 transpose")
+M = Mref[0:6:2, 1:2].T
 # TODO
 # assert( np.array_equal(M.T,eigenpy.reflexV(M,verbose)) );
 
-if verbose: print("===> From Py to Eigen::Matrix3d")
-if verbose: print("===> From Py to Eigen::Matrix3d")
-if verbose: print("===> From Py to Eigen::Matrix3d")
-
-if verbose: print("===> Block Vector 0:3x0:6:2 ")
-M = Mref[0:3,0:6:2]
-assert( np.array_equal(M,eigenpy.reflex33(M,verbose)) );
-
-if verbose: print("===> Block Vector 0:3x0:6:2 T")
-M = Mref[0:3,0:6].T
+if verbose:
+    print("===> From Py to Eigen::Matrix3d")
+if verbose:
+    print("===> From Py to Eigen::Matrix3d")
+if verbose:
+    print("===> From Py to Eigen::Matrix3d")
+
+if verbose:
+    print("===> Block Vector 0:3x0:6:2 ")
+M = Mref[0:3, 0:6:2]
+assert np.array_equal(M, eigenpy.reflex33(M, verbose))
+
+if verbose:
+    print("===> Block Vector 0:3x0:6:2 T")
+M = Mref[0:3, 0:6].T
 # TODO
 # try:
-    # assert( np.array_equal(M,eigenpy.reflex33(M,verbose)) );
+# assert( np.array_equal(M,eigenpy.reflex33(M,verbose)) );
 # except eigenpy.Exception as e:
-    # if verbose: print("As expected, got the following /ROW/ error:", e.message)
+# if verbose: print("As expected, got the following /ROW/ error:", e.message)
 
-if verbose: print("===> From Py to Eigen::Vector3d")
-if verbose: print("===> From Py to Eigen::Vector3d")
-if verbose: print("===> From Py to Eigen::Vector3d")
+if verbose:
+    print("===> From Py to Eigen::Vector3d")
+if verbose:
+    print("===> From Py to Eigen::Vector3d")
+if verbose:
+    print("===> From Py to Eigen::Vector3d")
 
 # TODO
 # M = Mref[0:3,1:2]
 # assert( np.array_equal(M,eigenpy.reflex3(M,verbose)) );
 
-value = 2.
+value = 2.0
 mat1x1 = eigenpy.matrix1x1(value)
-assert(mat1x1.size == 1)
-assert(mat1x1[0,0] == value)
+assert mat1x1.size == 1
+assert mat1x1[0, 0] == value
 
 vec1x1 = eigenpy.vector1x1(value)
-assert(vec1x1.size == 1)
-assert(vec1x1[0] == value)
+assert vec1x1.size == 1
+assert vec1x1[0] == value
 
 # test registration of matrix6
-mat6 = eigenpy.matrix6(0.)
-assert(mat6.size == 36)
+mat6 = eigenpy.matrix6(0.0)
+assert mat6.size == 36
 
 # test RowMajor
 
-mat = np.arange(0,10).reshape(2,5)
-assert((eigenpy.asRowMajorFromColMajorMatrix(mat) == mat).all())
-assert((eigenpy.asRowMajorFromRowMajorMatrix(mat) == mat).all())
+mat = np.arange(0, 10).reshape(2, 5)
+assert (eigenpy.asRowMajorFromColMajorMatrix(mat) == mat).all()
+assert (eigenpy.asRowMajorFromRowMajorMatrix(mat) == mat).all()
 
-vec = np.arange(0,10)
-assert((eigenpy.asRowMajorFromColMajorMatrix(vec) == vec).all())
-assert((eigenpy.asRowMajorFromColMajorVector(vec) == vec).all())
-assert((eigenpy.asRowMajorFromRowMajorMatrix(vec) == vec).all())
-assert((eigenpy.asRowMajorFromRowMajorVector(vec) == vec).all())
+vec = np.arange(0, 10)
+assert (eigenpy.asRowMajorFromColMajorMatrix(vec) == vec).all()
+assert (eigenpy.asRowMajorFromColMajorVector(vec) == vec).all()
+assert (eigenpy.asRowMajorFromRowMajorMatrix(vec) == vec).all()
+assert (eigenpy.asRowMajorFromRowMajorVector(vec) == vec).all()
diff --git a/unittest/python/test_return_by_ref.py b/unittest/python/test_return_by_ref.py
index 59f6d13..c93bebc 100644
--- a/unittest/python/test_return_by_ref.py
+++ b/unittest/python/test_return_by_ref.py
@@ -2,54 +2,57 @@ import return_by_ref
 from return_by_ref import Matrix, RowMatrix, Vector
 import numpy as np
 
+
 def test_shared(mat):
 
-  m_ref = mat.ref()
-  m_ref.fill(0)
-  m_copy = mat.copy()
-  assert np.array_equal(m_ref,m_copy)
+    m_ref = mat.ref()
+    m_ref.fill(0)
+    m_copy = mat.copy()
+    assert np.array_equal(m_ref, m_copy)
+
+    m_const_ref = mat.const_ref()
+    assert np.array_equal(m_const_ref, m_copy)
+    assert np.array_equal(m_const_ref, m_ref)
 
-  m_const_ref = mat.const_ref()
-  assert np.array_equal(m_const_ref,m_copy)
-  assert np.array_equal(m_const_ref,m_ref)
+    m_ref.fill(1)
+    assert not np.array_equal(m_ref, m_copy)
+    assert np.array_equal(m_const_ref, m_ref)
 
-  m_ref.fill(1)
-  assert not np.array_equal(m_ref,m_copy)
-  assert np.array_equal(m_const_ref,m_ref)
+    try:
+        m_const_ref.fill(2)
+        assert False
+    except:
+        assert True
 
-  try:
-    m_const_ref.fill(2)
-    assert False
-  except:
-    assert True
 
 def test_not_shared(mat):
 
-  m_ref = mat.ref()
-  m_ref.fill(100.)
-  m_copy = mat.copy()
-  assert not np.array_equal(m_ref,m_copy)
+    m_ref = mat.ref()
+    m_ref.fill(100.0)
+    m_copy = mat.copy()
+    assert not np.array_equal(m_ref, m_copy)
+
+    m_const_ref = mat.const_ref()
+    assert np.array_equal(m_const_ref, m_copy)
+    assert not np.array_equal(m_const_ref, m_ref)
 
-  m_const_ref = mat.const_ref()
-  assert np.array_equal(m_const_ref,m_copy)
-  assert not np.array_equal(m_const_ref,m_ref)
+    m_ref.fill(10.0)
+    assert not np.array_equal(m_ref, m_copy)
+    assert not np.array_equal(m_const_ref, m_ref)
 
-  m_ref.fill(10.)
-  assert not np.array_equal(m_ref,m_copy)
-  assert not np.array_equal(m_const_ref,m_ref)
+    try:
+        m_const_ref.fill(2)
+        assert True
+    except:
+        assert False
 
-  try:
-    m_const_ref.fill(2)
-    assert True
-  except:
-    assert False
 
 rows = 10
 cols = 30
 
-mat = Matrix(rows,cols)
-row_mat = RowMatrix(rows,cols)
-vec = Vector(rows,1)
+mat = Matrix(rows, cols)
+row_mat = RowMatrix(rows, cols)
+vec = Vector(rows, 1)
 
 test_shared(mat)
 test_shared(row_mat)
@@ -59,5 +62,3 @@ return_by_ref.sharedMemory(False)
 test_not_shared(mat)
 test_not_shared(row_mat)
 test_not_shared(vec)
-
-
diff --git a/unittest/python/test_self_adjoint_eigen_solver.py b/unittest/python/test_self_adjoint_eigen_solver.py
index a919ebf..ae98605 100644
--- a/unittest/python/test_self_adjoint_eigen_solver.py
+++ b/unittest/python/test_self_adjoint_eigen_solver.py
@@ -1,16 +1,17 @@
 import eigenpy
+
 eigenpy.switchToNumpyArray()
 
 import numpy as np
 import numpy.linalg as la
 
 dim = 100
-A = np.random.rand(dim,dim)
-A = (A + A.T)*0.5
+A = np.random.rand(dim, dim)
+A = (A + A.T) * 0.5
 
 es = eigenpy.SelfAdjointEigenSolver(A)
 
 V = es.eigenvectors()
 D = es.eigenvalues()
 
-assert eigenpy.is_approx(A.dot(V),V.dot(np.diag(D)),1e-6)
+assert eigenpy.is_approx(A.dot(V), V.dot(np.diag(D)), 1e-6)
diff --git a/unittest/python/test_switch.py b/unittest/python/test_switch.py
index b76040a..a5d8a97 100644
--- a/unittest/python/test_switch.py
+++ b/unittest/python/test_switch.py
@@ -9,7 +9,7 @@ quat = eigenpy.Quaternion()
 coeffs_vector = quat.coeffs()
 print(type(coeffs_vector))
 
-assert isinstance(coeffs_vector,np.matrixlib.defmatrix.matrix)
+assert isinstance(coeffs_vector, np.matrixlib.defmatrix.matrix)
 assert eigenpy.getNumpyType() == np.matrix
 
 # Switch to numpy.array
@@ -17,5 +17,5 @@ eigenpy.switchToNumpyArray()
 coeffs_array = quat.coeffs()
 print(type(coeffs_array))
 
-assert isinstance(coeffs_vector,np.ndarray)
+assert isinstance(coeffs_vector, np.ndarray)
 assert eigenpy.getNumpyType() == np.ndarray
diff --git a/unittest/python/test_user_type.py b/unittest/python/test_user_type.py
index 956108d..76e5dfe 100644
--- a/unittest/python/test_user_type.py
+++ b/unittest/python/test_user_type.py
@@ -1,61 +1,65 @@
 import user_type
 import numpy as np
-#from packaging import version
+
+# from packaging import version
 
 rows = 10
 cols = 20
 
+
 def test(dtype):
-  mat = np.array(np.ones((rows,cols)).astype(np.intc),dtype=dtype)
-  mat = np.random.rand(rows,cols).astype(dtype)
-  mat_copy = mat.copy()
-  assert (mat == mat_copy).all()
-  assert not (mat != mat_copy).all()
-
-#  if version.parse(np.__version__) >= version.parse("1.21.0"): # check if it fixes for new versio of NumPy
-#    mat.fill(mat.dtype.type(20.))
-#    mat_copy = mat.copy()
-#    assert((mat == mat_copy).all())
-#    assert(not (mat != mat_copy).all())
-
-  mat_op = mat + mat
-  mat_op = mat.copy(order='F') + mat.copy(order='C')
-
-  mat_op = mat - mat
-  mat_op = mat * mat
-  mat_op = mat.dot(mat.T)
-  mat_op = mat / mat
-
-  mat_op = -mat
-
-  assert (mat >= mat).all()
-  assert (mat <= mat).all()
-  assert not (mat > mat).all()
-  assert not (mat < mat).all()
-
-  mat2 = mat.dot(mat.T)
-  mat2_ref = mat.astype(np.double).dot(mat.T.astype(np.double))
-  assert np.isclose(mat2.astype(np.double),mat2_ref).all()
-  if np.__version__ >= '1.17.0':
-    mat2 = np.matmul(mat,mat.T)
-    assert np.isclose(mat2.astype(np.double),mat2_ref).all()
-
-def test_cast(from_dtype,to_dtype):
-  np.can_cast(from_dtype,to_dtype)
-
-  from_mat = np.zeros((rows,cols),dtype=from_dtype)
-  to_mat = from_mat.astype(dtype=to_dtype)
+    mat = np.array(np.ones((rows, cols)).astype(np.intc), dtype=dtype)
+    mat = np.random.rand(rows, cols).astype(dtype)
+    mat_copy = mat.copy()
+    assert (mat == mat_copy).all()
+    assert not (mat != mat_copy).all()
+
+    #  if version.parse(np.__version__) >= version.parse("1.21.0"): # check if it fixes for new versio of NumPy
+    #    mat.fill(mat.dtype.type(20.))
+    #    mat_copy = mat.copy()
+    #    assert((mat == mat_copy).all())
+    #    assert(not (mat != mat_copy).all())
+
+    mat_op = mat + mat
+    mat_op = mat.copy(order="F") + mat.copy(order="C")
+
+    mat_op = mat - mat
+    mat_op = mat * mat
+    mat_op = mat.dot(mat.T)
+    mat_op = mat / mat
+
+    mat_op = -mat
+
+    assert (mat >= mat).all()
+    assert (mat <= mat).all()
+    assert not (mat > mat).all()
+    assert not (mat < mat).all()
+
+    mat2 = mat.dot(mat.T)
+    mat2_ref = mat.astype(np.double).dot(mat.T.astype(np.double))
+    assert np.isclose(mat2.astype(np.double), mat2_ref).all()
+    if np.__version__ >= "1.17.0":
+        mat2 = np.matmul(mat, mat.T)
+        assert np.isclose(mat2.astype(np.double), mat2_ref).all()
+
+
+def test_cast(from_dtype, to_dtype):
+    np.can_cast(from_dtype, to_dtype)
+
+    from_mat = np.zeros((rows, cols), dtype=from_dtype)
+    to_mat = from_mat.astype(dtype=to_dtype)
+
 
 test(user_type.CustomDouble)
 
-test_cast(user_type.CustomDouble,np.double)
-test_cast(np.double,user_type.CustomDouble)
+test_cast(user_type.CustomDouble, np.double)
+test_cast(np.double, user_type.CustomDouble)
 
-test_cast(user_type.CustomDouble,np.int64)
-test_cast(np.int64,user_type.CustomDouble)
+test_cast(user_type.CustomDouble, np.int64)
+test_cast(np.int64, user_type.CustomDouble)
 
-test_cast(user_type.CustomDouble,np.int32)
-test_cast(np.int32,user_type.CustomDouble)
+test_cast(user_type.CustomDouble, np.int32)
+test_cast(np.int32, user_type.CustomDouble)
 
 test(user_type.CustomFloat)
 
diff --git a/unittest/python/test_version.py b/unittest/python/test_version.py
index 36d3c64..ddd7832 100644
--- a/unittest/python/test_version.py
+++ b/unittest/python/test_version.py
@@ -2,6 +2,6 @@ from __future__ import print_function
 
 import eigenpy
 
-assert eigenpy.checkVersionAtLeast(0,0,0)
+assert eigenpy.checkVersionAtLeast(0, 0, 0)
 assert eigenpy.__version__ != ""
 assert eigenpy.__raw_version__ != ""
-- 
GitLab