def test_same_values(self): x = rd.random(self.n) for long_arc in (False, True): interp_values = math.circ_interp(x, x, self.k, long_arc) diff = interp_values - np.array([x] * (self.k + 2)).T self.assertTrue(np.allclose(diff, np.zeros((self.n, self.k + 2))))
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]))