Example #1
0
    def test_insert_inplace(self):
        mySymbolicMatricesList = TypedListType(
            tt.TensorType(theano.config.floatX, (False, False)))()
        mySymbolicIndex = tt.scalar(dtype="int64")
        mySymbolicMatrix = tt.matrix()

        z = Insert()(mySymbolicMatricesList, mySymbolicIndex, mySymbolicMatrix)
        m = theano.compile.mode.get_default_mode().including(
            "typed_list_inplace_opt")

        f = theano.function(
            [
                In(mySymbolicMatricesList, borrow=True, mutable=True),
                mySymbolicIndex,
                mySymbolicMatrix,
            ],
            z,
            accept_inplace=True,
            mode=m,
        )
        assert f.maker.fgraph.toposort()[0].op.inplace

        x = rand_ranged(-1000, 1000, [100, 101])

        y = rand_ranged(-1000, 1000, [100, 101])

        assert np.array_equal(f([x], np.asarray(1, dtype="int64"), y), [x, y])
Example #2
0
    def test_extend_inplace(self):
        mySymbolicMatricesList1 = TypedListType(
            tt.TensorType(theano.config.floatX, (False, False)))()

        mySymbolicMatricesList2 = TypedListType(
            tt.TensorType(theano.config.floatX, (False, False)))()

        z = Extend()(mySymbolicMatricesList1, mySymbolicMatricesList2)
        m = theano.compile.mode.get_default_mode().including(
            "typed_list_inplace_opt")
        f = theano.function(
            [
                In(mySymbolicMatricesList1, borrow=True, mutable=True),
                mySymbolicMatricesList2,
            ],
            z,
            mode=m,
        )
        assert f.maker.fgraph.toposort()[0].op.inplace

        x = rand_ranged(-1000, 1000, [100, 101])

        y = rand_ranged(-1000, 1000, [100, 101])

        assert np.array_equal(f([x], [y]), [x, y])
Example #3
0
    def test_filter_sanity_check(self):
        # Simple test on typed list type filter

        myType = TypedListType(
            tt.TensorType(theano.config.floatX, (False, False)))

        x = rand_ranged(-1000, 1000, [100, 100])

        assert np.array_equal(myType.filter([x]), [x])
Example #4
0
    def test_load_alot(self):
        myType = TypedListType(
            tt.TensorType(theano.config.floatX, (False, False)))

        x = rand_ranged(-1000, 1000, [10, 10])
        testList = []
        for i in range(10000):
            testList.append(x)

        assert np.array_equal(myType.filter(testList), testList)
Example #5
0
    def test_basic_nested_list(self):
        # Testing nested list with one level of depth

        myNestedType = TypedListType(
            tt.TensorType(theano.config.floatX, (False, False)))

        myType = TypedListType(myNestedType)

        x = rand_ranged(-1000, 1000, [100, 100])

        assert np.array_equal(myType.filter([[x]]), [[x]])
Example #6
0
    def test_reverse_inplace(self):
        mySymbolicMatricesList = TypedListType(
            tt.TensorType(aesara.config.floatX, (False, False)))()

        z = Reverse()(mySymbolicMatricesList)
        m = aesara.compile.mode.get_default_mode().including(
            "typed_list_inplace_opt")
        f = aesara.function(
            [In(mySymbolicMatricesList, borrow=True, mutable=True)],
            z,
            accept_inplace=True,
            mode=m,
        )
        assert f.maker.fgraph.toposort()[0].op.inplace

        x = rand_ranged(-1000, 1000, [100, 101])

        y = rand_ranged(-1000, 1000, [100, 101])

        assert np.array_equal(f([x, y]), [y, x])
Example #7
0
)
TestErfcxInplaceBroadcast = makeBroadcastTester(
    op=inplace.erfcx_inplace,
    expected=expected_erfcx,
    good=_good_broadcast_unary_normal_float_no_complex_small_neg_range,
    eps=2e-10,
    mode=mode_no_scipy,
    inplace=True,
    skip=skip_scipy,
)

TestErfinvBroadcast = makeBroadcastTester(
    op=aet.erfinv,
    expected=expected_erfinv,
    good={
        "normal": [rand_ranged(-0.9, 0.9, (2, 3))],
        "empty": [np.asarray([], dtype=config.floatX)],
    },
    grad=_grad_broadcast_unary_abs1_no_complex,
    eps=2e-10,
    mode=mode_no_scipy,
    skip=skip_scipy,
)

TestErfcinvBroadcast = makeBroadcastTester(
    op=aet.erfcinv,
    expected=expected_erfcinv,
    good={
        "normal": [rand_ranged(0.001, 1.9, (2, 3))],
        "empty": [np.asarray([], dtype=config.floatX)],
    },
Example #8
0
)
TestErfcxInplaceBroadcast = makeBroadcastTester(
    op=inplace.erfcx_inplace,
    expected=expected_erfcx,
    good=_good_broadcast_unary_normal_float_no_complex_small_neg_range,
    eps=2e-10,
    mode=mode_no_scipy,
    inplace=True,
    skip=skip_scipy,
)

TestErfinvBroadcast = makeBroadcastTester(
    op=aet.erfinv,
    expected=expected_erfinv,
    good={
        "normal": [rand_ranged(-0.9, 0.9, (2, 3))],
        "empty": [np.asarray([], dtype=config.floatX)],
    },
    grad=_grad_broadcast_unary_abs1_no_complex,
    eps=2e-10,
    mode=mode_no_scipy,
    skip=skip_scipy,
)

TestErfcinvBroadcast = makeBroadcastTester(
    op=aet.erfcinv,
    expected=expected_erfcinv,
    good={
        "normal": [rand_ranged(0.001, 1.9, (2, 3))],
        "empty": [np.asarray([], dtype=config.floatX)],
    },