Exemplo n.º 1
0
 def test_op_removed(self):
     x = matrix("x")
     y = x * consider_constant(x)
     f = aesara.function([x], y)
     # need to refer to aesara.consider_constant_ here,
     # aesara.consider_constant is a wrapper function!
     assert consider_constant_ not in [node.op for node in f.maker.fgraph.toposort()]
Exemplo n.º 2
0
    def test_grad(self):
        a = np.asarray(self.rng.randn(5, 5), dtype=config.floatX)

        x = matrix("x")

        expressions_gradients = [
            (x * consider_constant(x), x),
            (x * consider_constant(exp(x)), exp(x)),
            (consider_constant(x), aet.constant(0.0)),
            (x**2 * consider_constant(x), 2 * x**2),
        ]

        for expr, expr_grad in expressions_gradients:
            g = grad(expr.sum(), x)
            # gradient according to aesara
            f = aesara.function([x], g, on_unused_input="ignore")
            # desired gradient
            f2 = aesara.function([x], expr_grad, on_unused_input="ignore")

            assert np.allclose(f(a), f2(a))