'Test gradient for log_det'

def test_log_det(self):

    expr = log_det(self.A)
    self.A.value = (2 * np.eye(2))
    self.assertItemsAlmostEqual(expr.grad[self.A].todense(), ((1.0 / 2) * np.eye(2)))
    mat = np.matrix([[1, 2], [3, 5]])
    self.A.value = (mat.T * mat)
    val = np.linalg.inv(self.A.value).T
    self.assertItemsAlmostEqual(expr.grad[self.A].todense(), val)
    self.A.value = np.zeros((2, 2))
    self.assertAlmostEqual(expr.grad[self.A], None)
    self.A.value = (- np.matrix([[1, 2], [3, 4]]))
    self.assertAlmostEqual(expr.grad[self.A], None)
    K = Variable(8, 8)
    expr = log_det(K[[1, 2]][:, [1, 2]])
    K.value = np.eye(8)
    val = np.zeros((8, 8))
    val[([1, 2], [1, 2])] = 1
    self.assertItemsAlmostEqual(expr.grad[K].todense(), val)
