'Test domain for entr.'

def test_entr(self):

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