def test_shapes_x_less(): rndm = np.random.RandomState(1234) x = np.sort(rndm.uniform(size=8)) y = np.random.uniform(size=9) y[-1] = y[0] with pytest.raises(ValueError): get_first_derivatives(x, y)
def test_matrix(): rndm = np.random.RandomState(1234) x = np.sort(rndm.uniform(size=8)) y = np.random.uniform(size=8) y[-1] = y[0] der = get_first_derivatives(x, y) assert_allclose(der.shape[0], x.shape[0], atol=1e-12)
assert len(x) == len(y) == 3 y[-1] = y[0] # shortcut x, y = map(np.asarray, (x, y)) h = x[1:] - x[:-1] m = (y[1:] - y[:-1]) / h s = (m / h).sum() / (1. / h).sum() print('OLD S : ', s) return ipt.CubicHermiteSpline(x, y, [s, s, s]) ''' n = 3 x = np.sort(np.random.random_sample(n) * 10) y = np.random.random_sample(n) * 30 y[-1] = y[0] t = get_first_derivatives(x, y) print("Our :", t[0]) try: spline = CyclicInterpCurve(x, y, t) except ZeroDivisionError as e: print(e) vhs = np.vectorize(spline) vhs1 = np.vectorize(per_spl(x, y)) #vhs2 = np.vectorize(per_spl_old(x, y)) #plt.figure(figsize=(10,10)) plt.scatter(x, y, marker='.', c='red') tmp = np.arange(x[0], x[n - 1], 0.01) plt.plot(tmp, vhs(tmp), label='our') plt.plot(tmp, vhs1(tmp), label='new') #plt.plot(tmp,vhs2(tmp), label='old') plt.legend(bbox_to_anchor=(0., 1.02, 1., .102),
def test_none_x(): x = None y = np.arange(8) with pytest.raises(ValueError): get_first_derivatives(x, y)
def test_x_asc(): x = np.array([1, 2, 3, 2.5, 1.5]) y = np.arange(5) with pytest.raises(ValueError): get_first_derivatives(x, y)
def test_non_periodic(): x = np.arange(8) y = np.arange(8) with pytest.raises(ValueError): get_first_derivatives(x, y)
def test_num_points(): x = np.arange(2) y = np.arange(2) with pytest.raises(ValueError): get_first_derivatives(x, y)
def test_non_sort(): rndm = np.random.RandomState(1234) x = np.sort(rndm.uniform(size=8)) y = np.random.uniform(size=8) with pytest.raises(ValueError): get_first_derivatives(x, y)
def test_none(): x = None y = None with pytest.raises(ValueError): get_first_derivatives(x, y)