Example #1
0
    def test_extend_inplace(self):
        mySymbolicMatricesList1 = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()

        mySymbolicMatricesList2 = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()

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

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

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

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

        myType = TypedListType(TensorType(aesara.config.floatX, (False, False)))

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

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

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

        assert np.array_equal(myType.filter(testList), testList)
Example #4
0
    def test_not_a_list_on_filter(self):
        # Typed List Value should raises an error
        # if no iterable variable is given on input

        # list of matrices
        myType = TypedListType(TensorType(aesara.config.floatX, (False, False)))

        with pytest.raises(TypeError):
            myType.filter(4)
Example #5
0
    def test_comparison_different_depth(self):
        # Nested list with different depth aren't the same

        myNestedType = TypedListType(TensorType(aesara.config.floatX, (False, False)))

        myNestedType2 = TypedListType(myNestedType)

        myNestedType3 = TypedListType(myNestedType2)

        assert myNestedType2 != myNestedType3
Example #6
0
    def test_intern_filter(self):
        # Test checking if values contained are themselves
        # filtered. If they weren't this code would raise
        # an exception.

        myType = TypedListType(TensorType("float64", (False, False)))

        x = np.asarray([[4, 5], [4, 5]], dtype="float32")

        assert np.array_equal(myType.filter([x]), [x])
Example #7
0
    def test_interface(self):
        mySymbolicMatricesList = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()
        z = mySymbolicMatricesList.__len__()

        f = aesara.function([mySymbolicMatricesList], z)

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

        assert f([x, x]) == 2
Example #8
0
    def test_basic_nested_list(self):
        # Testing nested list with one level of depth

        myNestedType = TypedListType(TensorType(aesara.config.floatX, (False, False)))

        myType = TypedListType(myNestedType)

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

        assert np.array_equal(myType.filter([[x]]), [[x]])
Example #9
0
    def test_wrong_input_on_filter(self):
        # Typed list type should raises an
        # error if the argument given to filter
        # isn't of the same type as the one
        # specified on creation

        # list of matrices
        myType = TypedListType(TensorType(aesara.config.floatX, (False, False)))

        with pytest.raises(TypeError):
            myType.filter([4])
Example #10
0
    def test_nested_list_arg(self):
        # test for the 'depth' optional argument

        myNestedType = TypedListType(
            TensorType(aesara.config.floatX, (False, False)), 3
        )

        myType = TypedListType(TensorType(aesara.config.floatX, (False, False)))

        myManualNestedType = TypedListType(TypedListType(TypedListType(myType)))

        assert myNestedType == myManualNestedType
Example #11
0
    def test_interface(self):
        mySymbolicMatricesList = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()

        z = mySymbolicMatricesList.reverse()

        f = aesara.function([mySymbolicMatricesList], z)

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

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

        assert np.array_equal(f([x, y]), [y, x])
Example #12
0
    def test_type_equality(self):
        # Typed list types should only be equal
        # when they contains the same aesara
        # variables

        # list of matrices
        myType1 = TypedListType(TensorType(aesara.config.floatX, (False, False)))
        # list of matrices
        myType2 = TypedListType(TensorType(aesara.config.floatX, (False, False)))
        # list of scalars
        myType3 = TypedListType(TensorType(aesara.config.floatX, ()))

        assert myType2 == myType1
        assert myType3 != myType1
Example #13
0
    def test_interface(self):
        mySymbolicMatricesList = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()
        myMatrix = matrix()

        z = mySymbolicMatricesList.count(myMatrix)

        f = aesara.function([mySymbolicMatricesList, myMatrix], z)

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

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

        assert f([x, y], y) == 1
Example #14
0
    def test_interfaces(self):
        mySymbolicMatricesList = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()
        myMatrix = matrix()

        z = mySymbolicMatricesList.append(myMatrix)

        f = aesara.function([mySymbolicMatricesList, myMatrix], z)

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

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

        assert np.array_equal(f([x], y), [x, y])
Example #15
0
    def test_interface(self):
        mySymbolicMatricesList = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()
        myMatrix = matrix()
        myScalar = scalar(dtype="int64")

        z = mySymbolicMatricesList.insert(myScalar, myMatrix)

        f = aesara.function([mySymbolicMatricesList, myScalar, myMatrix], z)

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

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

        assert np.array_equal(f([x], np.asarray(1, dtype="int64"), y), [x, y])
Example #16
0
    def test_insert_inplace(self):
        mySymbolicMatricesList = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()
        mySymbolicIndex = scalar(dtype="int64")
        mySymbolicMatrix = matrix()

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

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

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

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

        assert np.array_equal(f([x], np.asarray(1, dtype="int64"), y), [x, y])
Example #17
0
    def test_interface(self):
        mySymbolicMatricesList1 = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()
        mySymbolicMatricesList2 = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()

        z = mySymbolicMatricesList1.extend(mySymbolicMatricesList2)

        f = aesara.function([mySymbolicMatricesList1, mySymbolicMatricesList2],
                            z)

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

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

        assert np.array_equal(f([x], [y]), [x, y])
Example #18
0
    def test_wrong_input(self):
        mySymbolicMatricesList = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()
        mySymbolicMatrix = matrix()

        with pytest.raises(TypeError):
            GetItem()(mySymbolicMatricesList, mySymbolicMatrix)
Example #19
0
    def test_wrong_input_on_creation(self):
        # Typed list type should raises an
        # error if the argument passed for
        # type is not a valid aesara type

        with pytest.raises(TypeError):
            TypedListType(None)
Example #20
0
    def test_non_tensor_type(self):
        mySymbolicNestedMatricesList = TypedListType(
            TensorType(aesara.config.floatX, (False, False)), 1)()
        mySymbolicMatricesList = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()

        z = Count()(mySymbolicNestedMatricesList, mySymbolicMatricesList)

        f = aesara.function(
            [mySymbolicNestedMatricesList, mySymbolicMatricesList], z)

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

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

        assert f([[x, y], [x, y, y]], [x, y]) == 1
Example #21
0
    def test_sanity_check(self):
        mySymbolicMatricesList = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()

        z = Length()(mySymbolicMatricesList)

        f = aesara.function([mySymbolicMatricesList], z)

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

        assert f([x, x, x, x]) == 4
Example #22
0
    def make_node(self, a):
        assert isinstance(a, (tuple, list))
        a2 = []
        for elem in a:
            if not isinstance(elem, Variable):
                elem = aet.as_tensor_variable(elem)
            a2.append(elem)
        if not all(a2[0].type == elem.type for elem in a2):
            raise TypeError("MakeList need all input variable to be of the same type.")
        tl = TypedListType(a2[0].type)()

        return Apply(self, a2, [tl])
Example #23
0
    def test_sanity_check(self):
        mySymbolicMatricesList = TypedListType(
            tt.TensorType(aesara.config.floatX, (False, False)))()

        z = Reverse()(mySymbolicMatricesList)

        f = aesara.function([mySymbolicMatricesList], z)

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

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

        assert np.array_equal(f([x, y]), [y, x])
Example #24
0
    def test_get_depth(self):
        # test case for get_depth utilitary function

        myType = TypedListType(TensorType(aesara.config.floatX, (False, False)))

        myManualNestedType = TypedListType(TypedListType(TypedListType(myType)))

        assert myManualNestedType.get_depth() == 3
Example #25
0
    def test_sanity_check_single(self):

        mySymbolicMatricesList = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()

        mySymbolicScalar = scalar(dtype="int64")

        z = GetItem()(mySymbolicMatricesList, mySymbolicScalar)

        f = aesara.function([mySymbolicMatricesList, mySymbolicScalar], z)

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

        assert np.array_equal(f([x], np.asarray(0, dtype="int64")), x)
Example #26
0
    def test_sparse(self):
        sp = pytest.importorskip("scipy")
        mySymbolicSparseList = TypedListType(
            sparse.SparseType("csr", aesara.config.floatX))()
        mySymbolicSparse = sparse.csr_matrix()

        z = Count()(mySymbolicSparseList, mySymbolicSparse)

        f = aesara.function([mySymbolicSparseList, mySymbolicSparse], z)

        x = sp.sparse.csr_matrix(random_lil((10, 40), aesara.config.floatX, 3))
        y = sp.sparse.csr_matrix(random_lil((10, 40), aesara.config.floatX, 3))

        assert f([x, y, y], y) == 2
Example #27
0
    def test_sanity_check(self):
        mySymbolicMatricesList = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()
        myMatrix = matrix()

        z = Remove()(mySymbolicMatricesList, myMatrix)

        f = aesara.function([mySymbolicMatricesList, myMatrix], z)

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

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

        assert np.array_equal(f([x, y], y), [x])
Example #28
0
    def test_sanity_check(self):
        mySymbolicMatricesList = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()
        myMatrix = matrix()

        z = Count()(mySymbolicMatricesList, myMatrix)

        f = aesara.function([mySymbolicMatricesList, myMatrix], z)

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

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

        assert f([y, y, x, y], y) == 3
Example #29
0
    def test_sanity_check_slice(self):

        mySymbolicMatricesList = TypedListType(
            TensorType(aesara.config.floatX, (False, False)))()

        mySymbolicSlice = SliceType()()

        z = GetItem()(mySymbolicMatricesList, mySymbolicSlice)

        assert not isinstance(z, TensorVariable)

        f = aesara.function([mySymbolicMatricesList, mySymbolicSlice], z)

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

        assert np.array_equal(f([x], slice(0, 1, 1)), [x])
Example #30
0
    def test_inplace(self):
        mySymbolicMatricesList = TypedListType(
            tt.TensorType(aesara.config.floatX, (False, False)))()
        myMatrix = tt.matrix()

        z = Remove(True)(mySymbolicMatricesList, myMatrix)

        f = aesara.function([mySymbolicMatricesList, myMatrix],
                            z,
                            accept_inplace=True)

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

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

        assert np.array_equal(f([x, y], y), [x])