當前位置: 首頁>>代碼示例>>Python>>正文


Python theano.Variable方法代碼示例

本文整理匯總了Python中theano.Variable方法的典型用法代碼示例。如果您正苦於以下問題:Python theano.Variable方法的具體用法?Python theano.Variable怎麽用?Python theano.Variable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在theano的用法示例。


在下文中一共展示了theano.Variable方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _is_sparse_variable

# 需要導入模塊: import theano [as 別名]
# 或者: from theano import Variable [as 別名]
def _is_sparse_variable(x):
    """

    Returns
    -------
    boolean
        True iff x is a L{SparseVariable} (and not a L{tensor.TensorType},
        for instance).

    """
    if not isinstance(x, gof.Variable):
        raise NotImplementedError("this function should only be called on "
                                  "*variables* (of type sparse.SparseType "
                                  "or tensor.TensorType, for instance), not ",
                                  x)
    return isinstance(x.type, SparseType) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:18,代碼來源:basic.py

示例2: make_node

# 需要導入模塊: import theano [as 別名]
# 或者: from theano import Variable [as 別名]
def make_node(self, img, kern):
        # Make sure both inputs are Variables with the same Type
        if not isinstance(img, theano.Variable):
            img = as_tensor_variable(img)
        if not isinstance(kern, theano.Variable):
            kern = as_tensor_variable(kern)
        ktype = img.type.clone(dtype=kern.dtype,
                               broadcastable=kern.broadcastable)
        kern = ktype.filter_variable(kern)

        if img.type.ndim != 4:
            raise TypeError('img must be 4D tensor')
        if kern.type.ndim != 4:
            raise TypeError('kern must be 4D tensor')

        broadcastable = [img.broadcastable[0],
                         kern.broadcastable[0],
                         False, False]
        output = img.type.clone(broadcastable=broadcastable)()
        return Apply(self, [img, kern], [output]) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:22,代碼來源:abstract_conv.py

示例3: get_flags

# 需要導入模塊: import theano [as 別名]
# 或者: from theano import Variable [as 別名]
def get_flags(*types):
        def get_dtype(t):
            if isinstance(t, string_types):
                return numpy.dtype(t)
            elif isinstance(t, Type):
                return t.dtype
            elif isinstance(t, Variable):
                return t.type.dtype
            else:
                raise TypeError("can't get a dtype from %s" % (type(t),))
        dtypes = [get_dtype(t) for t in types]
        flags = dict(cluda=True)
        if any(d == numpy.float64 for d in dtypes):
            flags['have_double'] = True
        if any(d.itemsize < 4 for d in dtypes):
            flags['have_small'] = True
        if any(d.kind == 'c' for d in dtypes):
            flags['have_complex'] = True
        if any(d == numpy.float16 for d in dtypes):
            flags['have_half'] = True
        return flags 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:23,代碼來源:basic_ops.py

示例4: _is_dense_variable

# 需要導入模塊: import theano [as 別名]
# 或者: from theano import Variable [as 別名]
def _is_dense_variable(x):
    """

    Returns
    -------
    boolean
        True if x is a L{tensor.TensorType} (and not a L{SparseVariable},
        for instance).

    """
    if not isinstance(x, gof.Variable):
        raise NotImplementedError("this function should only be called on "
                                  "*variables* (of type sparse.SparseType or "
                                  "tensor.TensorType, for instance), not ", x)
    return isinstance(x.type, tensor.TensorType) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:17,代碼來源:basic.py

示例5: as_sparse_variable

# 需要導入模塊: import theano [as 別名]
# 或者: from theano import Variable [as 別名]
def as_sparse_variable(x, name=None):
    """
    Wrapper around SparseVariable constructor to construct
    a Variable with a sparse matrix with the same dtype and
    format.

    Parameters
    ----------
    x
        A sparse matrix.

    Returns
    -------
    object
        SparseVariable version of `x`.

    """

    # TODO
    # Verify that sp is sufficiently sparse, and raise a
    # warning if it is not

    if isinstance(x, gof.Apply):
        if len(x.outputs) != 1:
            raise ValueError("It is ambiguous which output of a "
                             "multi-output Op has to be fetched.", x)
        else:
            x = x.outputs[0]
    if isinstance(x, gof.Variable):
        if not isinstance(x.type, SparseType):
            raise TypeError("Variable type field must be a SparseType.", x,
                            x.type)
        return x
    try:
        return constant(x, name=name)
    except TypeError:
        raise TypeError("Cannot convert %s to SparseType" % x, type(x)) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:39,代碼來源:basic.py

示例6: make_node

# 需要導入模塊: import theano [as 別名]
# 或者: from theano import Variable [as 別名]
def make_node(self, data, indices, indptr, shape):
        data = tensor.as_tensor_variable(data)

        if not isinstance(indices, gof.Variable):
            indices_ = numpy.asarray(indices)
            indices_32 = theano._asarray(indices, dtype='int32')
            assert (indices_ == indices_32).all()
            indices = indices_32
        if not isinstance(indptr, gof.Variable):
            indptr_ = numpy.asarray(indptr)
            indptr_32 = theano._asarray(indptr, dtype='int32')
            assert (indptr_ == indptr_32).all()
            indptr = indptr_32
        if not isinstance(shape, gof.Variable):
            shape_ = numpy.asarray(shape)
            shape_32 = theano._asarray(shape, dtype='int32')
            assert (shape_ == shape_32).all()
            shape = shape_32

        indices = tensor.as_tensor_variable(indices)
        indptr = tensor.as_tensor_variable(indptr)
        shape = tensor.as_tensor_variable(shape)

        if data.type.ndim != 1:
            raise TypeError('data argument must be a vector', data.type,
                            data.type.ndim)
        if indices.type.ndim != 1 or indices.type.dtype not in discrete_dtypes:
            raise TypeError('indices must be vector of integers', indices,
                            indices.type)
        if indptr.type.ndim != 1 or indptr.type.dtype not in discrete_dtypes:
            raise TypeError('indices must be vector of integers', indptr,
                            indptr.type)
        if shape.type.ndim != 1 or shape.type.dtype not in discrete_dtypes:
            raise TypeError('n_rows must be integer type', shape, shape.type)

        return gof.Apply(self,
                         [data, indices, indptr, shape],
                         [SparseType(dtype=data.type.dtype,
                                     format=self.format)()]) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:41,代碼來源:basic.py

示例7: make_node

# 需要導入模塊: import theano [as 別名]
# 或者: from theano import Variable [as 別名]
def make_node(self, x, maxout, gz):
        # make_node should only be called by the grad function of
        # Pool, so these asserts should not fail.
        assert isinstance(x, Variable) and x.ndim == 4
        assert isinstance(maxout, Variable) and maxout.ndim == 4
        assert isinstance(gz, Variable) and gz.ndim == 4
        x = tensor.as_tensor_variable(x)
        maxout = tensor.as_tensor_variable(maxout)
        gz = tensor.as_tensor_variable(gz)

        return Apply(self, [x, maxout, gz], [x.type()]) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:13,代碼來源:pool.py

示例8: make_node

# 需要導入模塊: import theano [as 別名]
# 或者: from theano import Variable [as 別名]
def make_node(self):
        return gof.Apply(self, [], [theano.Variable(Generic()),
                                    tensor(self.dtype,
                                           broadcastable=self.broadcastable)]) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:6,代碼來源:io.py

示例9: test0

# 需要導入模塊: import theano [as 別名]
# 或者: from theano import Variable [as 別名]
def test0(self):
        path = Variable(Generic())
        # Not specifying mmap_mode defaults to None, and the data is
        # copied into main memory
        x = tensor.load(path, 'int32', (False,))
        y = x * 2
        fn = function([path], y)
        assert (fn(self.filename) == (self.data * 2)).all() 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:10,代碼來源:test_io.py

示例10: test_invalid_modes

# 需要導入模塊: import theano [as 別名]
# 或者: from theano import Variable [as 別名]
def test_invalid_modes(self):
        # Modes 'r+', 'r', and 'w+' cannot work with Theano, becausei
        # the output array may be modified inplace, and that should not
        # modify the original file.
        path = Variable(Generic())
        for mmap_mode in ('r+', 'r', 'w+', 'toto'):
            self.assertRaises(ValueError,
                    tensor.load, path, 'int32', (False,), mmap_mode) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:10,代碼來源:test_io.py

示例11: test_memmap

# 需要導入模塊: import theano [as 別名]
# 或者: from theano import Variable [as 別名]
def test_memmap(self):
        path = Variable(Generic())
        x = tensor.load(path, 'int32', (False,), mmap_mode='c')
        fn = function([path], x)
        assert type(fn(self.filename)) == numpy.core.memmap 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:7,代碼來源:test_io.py

示例12: make_node

# 需要導入模塊: import theano [as 別名]
# 或者: from theano import Variable [as 別名]
def make_node(self, _x):
        if not isinstance(_x, theano.Variable):
            x = as_tensor_variable(_x)
        else:
            x = _x

        if x.type.ndim != 2:
            raise TypeError('ExtractDiag only works on matrices', _x)
        return Apply(self, [x], [x.type.__class__(broadcastable=(False,),
                                                  dtype=x.type.dtype)()]) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:12,代碼來源:nlinalg.py

示例13: make_node

# 需要導入模塊: import theano [as 別名]
# 或者: from theano import Variable [as 別名]
def make_node(self, x):
        # Must work for all type that have a shape attribute.
        # This will fail at execution time.
        if not isinstance(x, theano.Variable):
            x = theano.tensor.as_tensor_variable(x)
        return gof.Apply(self, [x], [theano.tensor.lvector()]) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:8,代碼來源:ops.py

示例14: ensure_float

# 需要導入模塊: import theano [as 別名]
# 或者: from theano import Variable [as 別名]
def ensure_float(val, default, name):
    if val is None:
        return default.clone()
    if not isinstance(val, Variable):
        val = constant(val)
    if hasattr(val, 'ndim') and val.ndim == 0:
        val = as_scalar(val)
    if not isinstance(val.type, theano.scalar.Scalar):
        raise TypeError("%s: expected a scalar value" % (name,))
    if not val.type.dtype == 'float32':
        raise TypeError("%s: type is not float32" % (name,))
    return val 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:14,代碼來源:dnn.py

示例15: make_variable

# 需要導入模塊: import theano [as 別名]
# 或者: from theano import Variable [as 別名]
def make_variable(self, name=None):
        """
        Return a `TensorVariable` of this type.

        Parameters
        ----------
        name : str
            A pretty name to identify this `Variable` when printing and
            debugging.

        """
        return self.Variable(self, name=name) 
開發者ID:muhanzhang,項目名稱:D-VAE,代碼行數:14,代碼來源:type.py


注:本文中的theano.Variable方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。