'Test 1D convolution.'

def test_1D_conv(self):

    n = 3
    x = Variable(n)
    f = [1, 2, 3]
    g = [0, 1, 0.5]
    f_conv_g = [0.0, 1.0, 2.5, 4.0, 1.5]
    expr = conv(f, g)
    assert expr.is_constant()
    self.assertEqual(expr.size, (5, 1))
    self.assertItemsAlmostEqual(expr.value, f_conv_g)
    expr = conv(f, x)
    assert expr.is_affine()
    self.assertEqual(expr.size, (5, 1))
    t = Variable()
    prob = Problem(Minimize(norm(expr, 1)), [(x == g)])
    result = prob.solve()
    self.assertAlmostEqual(result, sum(f_conv_g))
    self.assertItemsAlmostEqual(expr.value, f_conv_g)
