'Test domain for power.'

def test_power(self):

    expr = sqrt(self.a)
    self.a.value = 2
    self.assertAlmostEqual(expr.grad[self.a], (0.5 / np.sqrt(2)))
    self.a.value = 3
    self.assertAlmostEqual(expr.grad[self.a], (0.5 / np.sqrt(3)))
    self.a.value = (-1)
    self.assertAlmostEqual(expr.grad[self.a], None)
    expr = (self.x ** 3)
    self.x.value = [3, 4]
    self.assertItemsAlmostEqual(expr.grad[self.x].todense(), np.matrix('27    0;    0    48'))
    expr = (self.x ** 3)
    self.x.value = [(-1e-09), 4]
    self.assertItemsAlmostEqual(expr.grad[self.x].todense(), np.matrix('0    0;    0    48'))
    expr = (self.A ** 2)
    self.A.value = [[1, (-2)], [3, 4]]
    val = (np.zeros((4, 4)) + np.diag([2, (-4), 6, 8]))
    self.assertItemsAlmostEqual(expr.grad[self.A].todense(), val)
    expr = (self.a ** 0)
    self.assertAlmostEqual(expr.grad[self.a], 0)
    expr = (self.x ** 0)
    self.assertItemsAlmostEqual(expr.grad[self.x].todense(), np.zeros((2, 2)))
