コード例 #1
0
 def test_norm(self):
     """Test quaternion norm."""
     np.random.seed(0)
     shapes = [(4,), (5, 4), (5, 5, 4), (5, 5, 5, 4)]
     for shape in shapes:
         quats = np.random.random_sample(shape)
         norms = np.linalg.norm(quats, axis=-1)
         self.assertTrue(np.all(rowan.norm(quats) == norms))
コード例 #2
0
    def test_random_sample(self):
        """Generation with tuple"""
        s = (3, 4)
        np.random.seed(0)
        q = random.random_sample(s)
        self.assertTrue(q.shape == s + (4, ))
        self.assertTrue(np.allclose(norm(q), 1))

        q = random.random_sample()
        self.assertTrue(q.shape == (4, ))
コード例 #3
0
    def test_random(self):
        """Generation from various args"""
        s = (3, 4)
        np.random.seed(0)
        q = random.rand(s[0], s[1])
        self.assertTrue(q.shape == s + (4, ))
        self.assertTrue(np.allclose(norm(q), 1))

        q = random.rand()
        self.assertTrue(q.shape == (4, ))
コード例 #4
0
 def test_inverse(self):
     """Test quaternion inverse."""
     np.random.seed(0)
     shapes = [(4,), (5, 4), (5, 5, 4), (5, 5, 5, 4)]
     for shape in shapes:
         quats = np.random.random_sample(shape)
         quats_conj = quats.copy()
         quats_conj[..., 1:] *= -1
         quats_conj /= rowan.norm(quats)[..., np.newaxis] ** 2
         self.assertTrue(np.allclose(rowan.inverse(quats), quats_conj))