def test_long_arc(self): # interpolate two points from -pi/4 to pi/4 by the long arc x = np.array([-np.pi/4]) y = np.array([np.pi/4]) interp_values = math.circ_interp(x, y, 2, long_arc=True) self.assertTrue(np.allclose( math.circ_dist(interp_values, np.array([-1, -3, 3, 1]) * np.pi/4), np.zeros(4) )) # interlolate two points from pi/2 to -pi/2 by the short arc x = np.array([np.pi/2]) y = np.array([-np.pi/2]) interp_values = math.circ_interp(x, y, 2) self.assertTrue(np.allclose( math.circ_dist(interp_values, np.array([1/2.0, 1/6.0, -1/6.0, -1/2.0]) * np.pi), np.zeros(4) ))
def test_output(self): x = rd.random(self.n) y = rd.random(self.n) interp_values = math.circ_interp(x, y, self.k) self.assertEqual(np.shape(interp_values), (self.n, self.k + 2)) interp_diff = np.zeros((self.n, self.k + 1)) for i in xrange(self.k + 1): interp_diff[:, i] = math.circ_dist(interp_values[:, i], interp_values[:, i + 1]) for i in xrange(self.k + 1): self.assertTrue(np.allclose(interp_diff[:, 0], interp_diff[:, i]))
def test_reduce_angles(self): x = 12 * np.pi * rd.random(self.n) reduced_x = math.reduce_angles(x, lower=self.lower, upper=self.upper) # check if the actual angle values changed self.assertTrue(np.allclose( math.circ_dist(x, reduced_x), np.zeros(self.n) )) # check if the reduced angle values lie within the specified # bounds self.assertTrue(np.all(np.logical_and(self.lower < reduced_x, self.upper > reduced_x)))
def test_shifted_values(self): x = rd.random(self.n) shift = 2 * np.pi * rd.random(self.n) - np.pi dist = math.circ_dist(x, x + shift) self.assertLess(la.norm(shift - dist), self.eps)
def test_same_values(self): x = rd.random(self.n) dist = math.circ_dist(x, x) self.assertLess(la.norm(dist), self.eps)