예제 #1
0
 def test_matrix_exp(self):
     try:
         from scipy import linalg
         e = linalg.expm
         n = np.random.randint(1, 10)
         mat = np.random.rand(n, n)
         assert np.allclose(e(mat), matrix_exp(mat))
     except ImportError:
         raise unittest.SkipTest()
예제 #2
0
 def test_matrix_exp(self):
     try:
         from scipy import linalg
         e = linalg.expm
         n = 3
         mat = np.array([[5.59, -6.5, 0.73], [4.12, 6.4, -5.3],
                         [0.95, 3.54, -9.3]])
         assert np.allclose(e(mat), G.matrix_exp(mat))
     except ImportError:
         raise unittest.SkipTest('Scipy is not installed')
예제 #3
0
 def test_rotate(self):
     n = 15
     x = np.linspace(1.5, 10.0, n)
     y = np.linspace(5.0, 15.0, n)
     z = x * y / 10.0
     angle = 154.0
     theta = np.pi * angle / 180.0
     axis = np.array([1.0, np.sqrt(2.0), np.sqrt(3.0)])
     x_new, y_new, z_new = G.rotate(x, y, z, axis, angle)
     unit_vector = axis / np.linalg.norm(axis)
     mat = np.cross(np.eye(3), unit_vector * theta)
     rotation_matrix = G.matrix_exp(np.array(mat))
     test_points = []
     for xi, yi, zi in zip(x, y, z):
         point = np.array([xi, yi, zi])
         new = np.asarray(np.dot(rotation_matrix, point))
         test_points.append(new)
     test_points = np.asarray(test_points)
     x_test = test_points[:, 0]
     y_test = test_points[:, 1]
     z_test = test_points[:, 2]
     assert np.allclose(x_new, x_test)
     assert np.allclose(y_new, y_test)
     assert np.allclose(z_new, z_test)
예제 #4
0
 def test_rotate(self):
     n = np.random.randint(1, 25)
     x = np.random.random_sample(n)
     y = np.random.random_sample(n)
     z = np.random.random_sample(n)
     angle = np.random.uniform(0.0, 360.0)
     theta = np.pi * angle / 180.0
     axis = np.random.random_sample(3)
     x_new, y_new, z_new = rotate(x, y, z, axis, angle)
     unit_vector = axis / np.linalg.norm(axis)
     mat = np.cross(np.eye(3), unit_vector * theta)
     rotation_matrix = matrix_exp(np.matrix(mat))
     test_points = []
     for xi, yi, zi in zip(x, y, z):
         point = np.array([xi, yi, zi])
         new = np.asarray(np.dot(rotation_matrix, point))
         test_points.append(new[0])
     test_points = np.asarray(test_points)
     x_test = test_points[:, 0]
     y_test = test_points[:, 1]
     z_test = test_points[:, 2]
     assert np.allclose(x_new, x_test)
     assert np.allclose(y_new, y_test)
     assert np.allclose(z_new, z_test)