'Test domain for huber.'

def test_huber(self):

    expr = huber(self.a)
    self.a.value = 2
    self.assertAlmostEqual(expr.grad[self.a], 2)
    expr = huber(self.a, M=2)
    self.a.value = 3
    self.assertAlmostEqual(expr.grad[self.a], 4)
    self.a.value = (-1)
    self.assertAlmostEqual(expr.grad[self.a], (-2))
    expr = huber(self.x)
    self.x.value = [3, 4]
    val = (np.zeros((2, 2)) + np.diag([2, 2]))
    self.assertItemsAlmostEqual(expr.grad[self.x].todense(), val)
    expr = huber(self.x)
    self.x.value = [(-1e-09), 4]
    val = (np.zeros((2, 2)) + np.diag([0, 2]))
    self.assertItemsAlmostEqual(expr.grad[self.x].todense(), val)
    expr = huber(self.A, M=3)
    self.A.value = [[1, 2], [3, 4]]
    val = (np.zeros((4, 4)) + np.diag([2, 4, 6, 6]))
    self.assertItemsAlmostEqual(expr.grad[self.A].todense(), val)
