示例#1
0
    def test_inplace(self):
        mySymbolicMatricesList = TypedListType(
            T.TensorType(theano.config.floatX, (False, False)))()
        myMatrix = T.matrix()

        z = Append(True)(mySymbolicMatricesList, myMatrix)

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

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

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

        self.assertTrue(numpy.array_equal(f([x], y), [x, y]))
示例#2
0
    def test_sanity_check(self):
        mySymbolicMatricesList = TypedListType(T.TensorType(
            theano.config.floatX, (False, False)))()
        myMatrix = T.matrix()
        myScalar = T.scalar(dtype='int64')

        z = Insert()(mySymbolicMatricesList, myScalar, myMatrix)

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

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

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

        self.assertTrue(numpy.array_equal(f([x], numpy.asarray(1,
                        dtype='int64'), y), [x, y]))
示例#3
0
    def test_sanity_check_single(self):

        mySymbolicMatricesList = TypedListType(
            T.TensorType(theano.config.floatX, (False, False)))()

        mySymbolicScalar = T.scalar(dtype='int64')

        z = GetItem()(mySymbolicMatricesList, mySymbolicScalar)

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

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

        self.assertTrue(
            numpy.array_equal(f([x], numpy.asarray(0, dtype='int64')), x))
示例#4
0
    def test_sanity_check_slice(self):

        mySymbolicMatricesList = TypedListType(
            T.TensorType(theano.config.floatX, (False, False)))()

        mySymbolicSlice = SliceType()()

        z = GetItem()(mySymbolicMatricesList, mySymbolicSlice)

        self.assertFalse(isinstance(z, T.TensorVariable))

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

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

        self.assertTrue(numpy.array_equal(f([x], slice(0, 1, 1)), [x]))
示例#5
0
    def test_comparison_uneven_nested(self):
        # test for comparison between uneven nested list

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

        myManualNestedType1 = TypedListType(TypedListType(TypedListType(myType)))

        myManualNestedType2 = TypedListType(TypedListType(myType))

        assert myManualNestedType1 != myManualNestedType2
        assert myManualNestedType2 != myManualNestedType1
示例#6
0
    def test_constant_input(self):
        mySymbolicMatricesList = TypedListType(
            T.TensorType(theano.config.floatX, (False, False)))()

        z = GetItem()(mySymbolicMatricesList, 0)

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

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

        self.assertTrue(numpy.array_equal(f([x]), x))

        z = GetItem()(mySymbolicMatricesList, slice(0, 1, 1))

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

        self.assertTrue(numpy.array_equal(f([x]), [x]))
示例#7
0
    def test_append_inplace(self):
        mySymbolicMatricesList = TypedListType(T.TensorType(
                                               theano.config.floatX, (False, False)))()
        mySymbolicMatrix = T.matrix()
        z = Append()(mySymbolicMatricesList, mySymbolicMatrix)
        m = theano.compile.mode.get_default_mode().including("typed_list_inplace_opt")
        f = theano.function([In(mySymbolicMatricesList, borrow=True,
                                mutable=True),
                            In(mySymbolicMatrix, borrow=True,
                               mutable=True)], z, accept_inplace=True, mode=m)
        self.assertTrue(f.maker.fgraph.toposort()[0].op.inplace)

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

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

        self.assertTrue(numpy.array_equal(f([x], y), [x, y]))
示例#8
0
    def test_inplace(self):
        mySymbolicMatricesList = TypedListType(
            T.TensorType(theano.config.floatX, (False, False)))()
        myMatrix = T.matrix()
        myScalar = T.scalar(dtype="int64")

        z = Insert(True)(mySymbolicMatricesList, myScalar, myMatrix)

        f = theano.function([mySymbolicMatricesList, myScalar, 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], np.asarray(1, dtype="int64"), y), [x, y])
示例#9
0
    def test_interface(self):
        mySymbolicMatricesList = TypedListType(
            T.TensorType(theano.config.floatX, (False, False)))()
        mySymbolicScalar = T.scalar()

        z = mySymbolicMatricesList[mySymbolicScalar]

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

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

        self.assertTrue(numpy.array_equal(f([x], numpy.asarray(0)), x))

        z = mySymbolicMatricesList[0:1:1]

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

        self.assertTrue(numpy.array_equal(f([x]), [x]))
示例#10
0
    def test_interface(self):
        mySymbolicMatricesList = TypedListType(
            T.TensorType(theano.config.floatX, (False, False)))()
        mySymbolicScalar = T.scalar(dtype="int64")

        z = mySymbolicMatricesList[mySymbolicScalar]

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

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

        assert np.array_equal(f([x], np.asarray(0, dtype="int64")), x)

        z = mySymbolicMatricesList[0]

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

        assert np.array_equal(f([x]), x)
示例#11
0
    def test_reverse_inplace(self):
        mySymbolicMatricesList = TypedListType(
            tt.TensorType(theano.config.floatX, (False, False)))()

        z = Reverse()(mySymbolicMatricesList)
        m = theano.compile.mode.get_default_mode().including(
            "typed_list_inplace_opt")
        f = theano.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])
示例#12
0
    def test_comparison_uneven_nested(self):
        """
        test for comparison between uneven nested list
        """

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

        myManualNestedType1 = TypedListType(TypedListType(
                                            TypedListType(myType)))

        myManualNestedType2 = TypedListType(TypedListType(myType))

        self.assertFalse(myManualNestedType1 == myManualNestedType2)
        self.assertFalse(myManualNestedType2 == myManualNestedType1)
示例#13
0
    def test_variable_is_Typed_List_variable(self):
        mySymbolicVariable = TypedListType(
            T.TensorType(theano.config.floatX, (False, False))
        )()

        assert isinstance(mySymbolicVariable, theano.typed_list.TypedListVariable)