def test_multiply(self): m1 = Matrix33(np.arange(self._size)) m2 = Matrix33(np.arange(self._size)[::-1]) m = m1 * m2 self.assertTrue(np.array_equal(m, matrix33.multiply(m2, m1))) m1 = Matrix33(np.arange(self._size)) m2 = Matrix44(np.arange(16)) m = m1 * m2 self.assertTrue(np.array_equal(m, matrix33.multiply(matrix33.create_from_matrix44(m2), m1)))
def test_multiply(self): m1 = Matrix33(np.arange(self._size)) m2 = Matrix33(np.arange(self._size)[::-1]) m = m1 * m2 self.assertTrue(np.array_equal(m, matrix33.multiply(m1, m2))) m1 = Matrix33(np.arange(self._size)) m2 = Matrix44(np.arange(16)) m = m1 * m2 self.assertTrue(np.array_equal(m, matrix33.multiply(m1, matrix33.create_from_matrix44(m2))))
def test_operators_matrix33(self): m1 = Matrix33.identity() m2 = Matrix33.from_x_rotation(0.5) # add self.assertTrue(np.array_equal(m1 + m2, matrix33.create_identity() + matrix33.create_from_x_rotation(0.5))) # subtract self.assertTrue(np.array_equal(m1 - m2, matrix33.create_identity() - matrix33.create_from_x_rotation(0.5))) # multiply self.assertTrue(np.array_equal(m1 * m2, matrix33.multiply(matrix33.create_from_x_rotation(0.5), matrix33.create_identity()))) # divide self.assertRaises(ValueError, lambda: m1 / m2) # inverse self.assertTrue(np.array_equal(~m2, matrix33.inverse(matrix33.create_from_x_rotation(0.5)))) # == self.assertTrue(Matrix33() == Matrix33()) self.assertFalse(Matrix33() == Matrix33([1. for n in range(9)])) # != self.assertTrue(Matrix33() != Matrix33([1. for n in range(9)])) self.assertFalse(Matrix33() != Matrix33())
def test_operators_matrix44(self): m1 = Matrix33.identity() m2 = Matrix44.from_x_rotation(0.5) # add self.assertTrue( np.array_equal( m1 + m2, matrix33.create_identity() + matrix33.create_from_x_rotation(0.5))) # subtract self.assertTrue( np.array_equal( m1 - m2, matrix33.create_identity() - matrix33.create_from_x_rotation(0.5))) # multiply self.assertTrue( np.array_equal( m1 * m2, matrix33.multiply(matrix33.create_identity(), matrix33.create_from_x_rotation(0.5)))) # divide self.assertRaises(ValueError, lambda: m1 / m2)
def test_operators_quaternion(self): m = Matrix33.identity() q = Quaternion.from_x_rotation(0.7) # add self.assertRaises(ValueError, lambda: m + q) # subtract self.assertRaises(ValueError, lambda: m - q) # multiply self.assertTrue(np.array_equal(m * q, matrix33.multiply(matrix33.create_identity(), matrix33.create_from_quaternion(quaternion.create_from_x_rotation(0.7))))) # divide self.assertRaises(ValueError, lambda: m / q)
def test_operators_matrix44(self): m1 = Matrix33.identity() m2 = Matrix44.from_x_rotation(0.5) # add self.assertTrue(np.array_equal(m1 + m2, matrix33.create_identity() + matrix33.create_from_x_rotation(0.5))) # subtract self.assertTrue(np.array_equal(m1 - m2, matrix33.create_identity() - matrix33.create_from_x_rotation(0.5))) # multiply self.assertTrue(np.array_equal(m1 * m2, matrix33.multiply(matrix33.create_identity(), matrix33.create_from_x_rotation(0.5)))) # divide self.assertRaises(ValueError, lambda: m1 / m2)
def test_operators_quaternion(self): m = Matrix33.identity() q = Quaternion.from_x_rotation(0.7) # add self.assertRaises(ValueError, lambda: m + q) # subtract self.assertRaises(ValueError, lambda: m - q) # multiply self.assertTrue(np.array_equal(m * q, matrix33.multiply(matrix33.create_from_quaternion(quaternion.create_from_x_rotation(0.7)), matrix33.create_identity()))) # divide self.assertRaises(ValueError, lambda: m / q)
def test_multiply_rotation(self): m1 = matrix33.create_from_x_rotation(np.pi) m2 = matrix33.create_from_y_rotation(np.pi / 2.0) result = matrix33.multiply(m1, m2) self.assertTrue(np.allclose(result, np.dot(m1, m2)))
def test_multiply_identity(self): m1 = matrix33.create_identity() m2 = matrix33.create_identity() result = matrix33.multiply(m1, m2) self.assertTrue(np.allclose(result, np.dot(m1, m2)))
def test_multiply_rotation(self): m1 = matrix33.create_from_x_rotation(np.pi) m2 = matrix33.create_from_y_rotation(np.pi / 2.0) result = matrix33.multiply(m1, m2) self.assertTrue(np.allclose(result, np.dot(m1,m2)))
def test_multiply_identity(self): m1 = matrix33.create_identity() m2 = matrix33.create_identity() result = matrix33.multiply(m1, m2) self.assertTrue(np.allclose(result, np.dot(m1,m2)))