def test_second_derivative_nes_is_zero_for_line():
    n = 13
    x = np.arange(n)
    x_with_gaps = x[np.array([1, 4, 5, 9, 11])]
    D = myl1tf.get_second_derivative_matrix_nes(x_with_gaps)
    slope = D * cvxopt.matrix(x_with_gaps)
    assert max(abs(slope)) < 1e-13
def test_second_derivative_nes_agrees_with_es():
    # should agree with regularly spaced version when regularly spaced
    n = 13
    D2 = myl1tf.get_second_derivative_matrix(n)
    D2_with_gaps = myl1tf.get_second_derivative_matrix_nes(range(n))
    diff = D2 - D2_with_gaps
    assert max(abs(diff)) < 1e-13
def test_second_derivative_nes_on_quadratic():
    # should agree with regularly spaced version when regularly spaced
    n = 12
    x = np.arange(n) * 1.0
    x = x[np.array([1, 2, 5, 9, 11])]
    y = 3.0 * x * x + 5.0 * x + 99.5
    expected = cvxopt.matrix([6.0 for xxx in [2.0, 5.0, 9.0]])
    F = myl1tf.get_second_derivative_matrix_nes(x)
    deriv2 = F * cvxopt.matrix(y)
    diff = deriv2 - expected
    assert max(abs(diff)) < 1e-13