Esempio n. 1
0
    def test_fail(self):
        # Test that conv2d fails for dimensions other than 2 or 3.

        with pytest.raises(Exception):
            conv.conv2d(tt.dtensor4(), tt.dtensor3())
        with pytest.raises(Exception):
            conv.conv2d(tt.dtensor3(), tt.dvector())
Esempio n. 2
0
    def test_wrong_input(self):
        # Make sure errors are raised when image and kernel are not 4D tensors

        with pytest.raises(Exception):
            self.validate((3, 2, 8, 8), (4, 2, 5, 5),
                          "valid",
                          input=tt.dmatrix())
        with pytest.raises(Exception):
            self.validate((3, 2, 8, 8), (4, 2, 5, 5),
                          "valid",
                          filters=tt.dvector())
        with pytest.raises(Exception):
            self.validate((3, 2, 8, 8), (4, 2, 5, 5),
                          "valid",
                          input=tt.dtensor3())
Esempio n. 3
0
    def test_simple_3d(self):
        # Increments or sets part of a tensor by a scalar using full slice and
        # a partial slice depending on a scalar.

        a = tt.dtensor3()
        increment = tt.dscalar()
        sl1 = slice(None)
        sl2_end = tt.lscalar()
        sl2 = slice(sl2_end)
        sl3 = 2

        val_a = np.ones((5, 3, 4))
        val_inc = 2.3
        val_sl2_end = 2

        for method in [tt.set_subtensor, tt.inc_subtensor]:
            print("MethodSet", method)

            resut = method(a[sl1, sl3, sl2], increment)

            f = aesara.function([a, increment, sl2_end], resut)

            expected_result = np.copy(val_a)
            result = f(val_a, val_inc, val_sl2_end)

            if method is tt.set_subtensor:
                expected_result[:, sl3, :val_sl2_end] = val_inc
            else:
                expected_result[:, sl3, :val_sl2_end] += val_inc

            utt.assert_allclose(result, expected_result)

            # Test when we broadcast the result
            resut = method(a[sl1, sl2], increment)

            f = aesara.function([a, increment, sl2_end], resut)

            expected_result = np.copy(val_a)
            result = f(val_a, val_inc, val_sl2_end)

            if method is tt.set_subtensor:
                expected_result[:, :val_sl2_end] = val_inc
            else:
                expected_result[:, :val_sl2_end] += val_inc

            utt.assert_allclose(result, expected_result)
 def test_infer_shape(self):
     z = tt.dtensor3()
     x = tt.dmatrix()
     y = tt.dscalar()
     self._compile_and_check(
         [x, y],
         [self.op(x, y)],
         [np.random.rand(8, 5), np.random.rand()],
         self.op_class,
     )
     self._compile_and_check(
         [z, y],
         [self.op(z, y)],
         # must be square when nd>2
         [np.random.rand(8, 8, 8),
          np.random.rand()],
         self.op_class,
         warn=False,
     )
Esempio n. 5
0
    def test_multinomial_tensor3_b(self):
        # Test the examples given in the multinomial documentation regarding
        # tensor3 objects
        rng_R = random_state_type()
        n = 9
        pvals = tensor.dtensor3()
        post_r, out = multinomial(rng_R, n=n, pvals=pvals, size=(10, 1, -1))
        assert out.ndim == 4
        assert out.broadcastable == (False, True, False, False)

        f = compile.function([rng_R, pvals], [post_r, out],
                             accept_inplace=True)

        rng = np.random.RandomState(utt.fetch_seed())

        pvals_val = np.asarray([[[0.1, 0.9], [0.2, 0.8], [0.3, 0.7]]])
        assert pvals_val.shape == (1, 3, 2)

        out_rng, draw = f(rng, pvals_val)
        assert draw.shape == (10, 1, 3, 2)
        assert np.allclose(draw.sum(axis=3), 9)