当前位置: 首页>>代码示例>>Python>>正文


Python sparse.SparseType方法代码示例

本文整理汇总了Python中theano.sparse.SparseType方法的典型用法代码示例。如果您正苦于以下问题:Python sparse.SparseType方法的具体用法?Python sparse.SparseType怎么用?Python sparse.SparseType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在theano.sparse的用法示例。


在下文中一共展示了sparse.SparseType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: function

# 需要导入模块: from theano import sparse [as 别名]
# 或者: from theano.sparse import SparseType [as 别名]
def function(self, name=None):
        """
        Returns a compiled theano function to compute a representation

        Parameters
        ----------
        name : str
            WRITEME

        Returns
        -------
        WRITEME
        """
        inputs = SparseType('csr', dtype=theano.config.floatX)()
        return theano.function([inputs], self(inputs), name=name)



############################################################################# 
开发者ID:zchengquan,项目名称:TextDetector,代码行数:21,代码来源:pca.py

示例2: is_sparse

# 需要导入模块: from theano import sparse [as 别名]
# 或者: from theano.sparse import SparseType [as 别名]
def is_sparse(tensor):
    return th_sparse_module and isinstance(tensor.type, th_sparse_module.SparseType) 
开发者ID:lingluodlut,项目名称:Att-ChemdNER,代码行数:4,代码来源:theano_backend.py

示例3: test_sparse

# 需要导入模块: from theano import sparse [as 别名]
# 或者: from theano.sparse import SparseType [as 别名]
def test_sparse(self):
        if not scipy_imported:
            raise SkipTest('Optional package SciPy not installed')
        mySymbolicSparseList = TypedListType(
            sparse.SparseType('csr', theano.config.floatX))()
        mySymbolicSparse = sparse.csr_matrix()

        z = Index()(mySymbolicSparseList, mySymbolicSparse)

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

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

        self.assertTrue(f([x, y], y) == 1) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:17,代码来源:test_basic.py

示例4: function

# 需要导入模块: from theano import sparse [as 别名]
# 或者: from theano.sparse import SparseType [as 别名]
def function(self, name=None, repr_index=-1, sparse_input=False):
        """
        Compile a function computing representations on given layers.

        Parameters
        ----------
        name : string, optional
            name of the function
        repr_index : int, optional
            Index of the hidden representation to return.
            0 means the input, -1 the last output.
        sparse_input : bool, optional
            WRITEME

        Returns
        -------
        WRITEME
        """

        if sparse_input:
            inputs = SparseType('csr', dtype=theano.config.floatX)()
        else:
            inputs = tensor.matrix()

        return theano.function(
            [inputs],
            outputs=self(inputs)[repr_index],
            name=name) 
开发者ID:zchengquan,项目名称:TextDetector,代码行数:30,代码来源:blocks.py

示例5: test_sparse_input_aliasing_affecting_inplace_operations

# 需要导入模块: from theano import sparse [as 别名]
# 或者: from theano.sparse import SparseType [as 别名]
def test_sparse_input_aliasing_affecting_inplace_operations(self):
        ##
        # Note this test will never fail because I am not aware of any
        # inplace op on sparse variables
        try:
            import scipy.sparse as sp
        except ImportError:
            # The variable enable_sparse will be used to disable the test file.
            pass

        from theano.sparse import enable_sparse
        if not enable_sparse:
            raise SkipTest('Optional package sparse disabled')

        from theano import sparse

        # Note: to trigger this bug with theano rev 4586:2bc6fc7f218b,
        #        you need to make in inputs mutable (so that inplace
        #        operations are used) and to break the elemwise composition
        #        with some non-elemwise op (here dot)

        x = sparse.SparseType('csc', dtype='float64')()
        y = sparse.SparseType('csc', dtype='float64')()
        f = theano.function([theano.In(x, mutable=True),
                             theano.In(y, mutable=True)],
                            (x + y) + (x + y))
        # Test 1. If the same variable is given twice

        # Compute bogus values
        m = sp.csc_matrix(numpy.asarray(
            [[1, 0, 0, 0, 0],
             [0, 1, 0, 0, 0],
             [0, 0, 1, 0, 0],
             [0, 0, 0, 1, 0],
             [0, 0, 0, 0, 1]], dtype='float64'))
        bogus_vals = f(m, m)
        # Since we used inplace operation v and m may be corrupted
        # so we need to recreate them

        m = sp.csc_matrix(numpy.asarray(
            [[1, 0, 0, 0, 0],
             [0, 1, 0, 0, 0],
             [0, 0, 1, 0, 0],
             [0, 0, 0, 1, 0],
             [0, 0, 0, 0, 1]], dtype='float64'))
        m_copy = m.copy()
        vals = f(m, m_copy)

        assert numpy.allclose(vals.todense(), bogus_vals.todense()) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:51,代码来源:test_pfunc.py

示例6: test_sparse_input_aliasing_affecting_inplace_operations

# 需要导入模块: from theano import sparse [as 别名]
# 或者: from theano.sparse import SparseType [as 别名]
def test_sparse_input_aliasing_affecting_inplace_operations(self):
        ##
        # Note this test will never fail because I am not aware of any
        # inplace op on sparse variables
        try:
            import scipy.sparse as sp
        except ImportError:
            # The variable enable_sparse will be used to disable the test file.
            pass

        from theano.sparse import enable_sparse
        if enable_sparse == False:
            raise SkipTest('Optional package sparse disabled')

        from theano import sparse

        # Note: to trigger this bug with theano rev 4586:2bc6fc7f218b,
        #        you need to make in inputs mutable (so that inplace
        #        operations are used) and to break the elemwise composition
        #        with some non-elemwise op (here dot)

        x = sparse.SparseType('csc', dtype='float64')()
        y = sparse.SparseType('csc', dtype='float64')()
        f = theano.function([theano.In(x, mutable=True),
                             theano.In(y, mutable=True)],
                            (x + y) + (x + y))
        # Test 1. If the same variable is given twice

        # Compute bogus values
        m = sp.csc_matrix(numpy.asarray(
            [[1, 0, 0, 0, 0],
             [0, 1, 0, 0, 0],
             [0, 0, 1, 0, 0],
             [0, 0, 0, 1, 0],
             [0, 0, 0, 0, 1]], dtype='float64'))
        bogus_vals = f(m, m)
        # Since we used inplace operation v and m may be corrupted
        # so we need to recreate them

        m = sp.csc_matrix(numpy.asarray(
            [[1, 0, 0, 0, 0],
             [0, 1, 0, 0, 0],
             [0, 0, 1, 0, 0],
             [0, 0, 0, 1, 0],
             [0, 0, 0, 0, 1]], dtype='float64'))
        m_copy = m.copy()
        vals = f(m, m_copy)

        assert numpy.allclose(vals.todense(), bogus_vals.todense()) 
开发者ID:rizar,项目名称:attention-lvcsr,代码行数:51,代码来源:test_pfunc.py


注:本文中的theano.sparse.SparseType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。