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


Python gof.Variable方法代码示例

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


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

示例1: _is_sparse_variable

# 需要导入模块: from theano import gof [as 别名]
# 或者: from theano.gof 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: wrap_in

# 需要导入模块: from theano import gof [as 别名]
# 或者: from theano.gof import Variable [as 别名]
def wrap_in(input):
        if isinstance(input, (SymbolicInput, SymbolicInputKit)):
            return input
        elif isinstance(input, gof.Variable):
            # r -> SymbolicInput(variable=r)
            return SymbolicInput(input)
        elif isinstance(input, (list, tuple)):
            # (r, u) -> SymbolicInput(variable=r, update=u)
            if len(input) == 2:
                return SymbolicInput(input[0], update=input[1])
            else:
                raise TypeError("Expected two elements in the list or tuple.",
                                input)
        else:
            raise TypeError("Unknown input type: %s (%s), expected Variable "
                            "instance", type(input), input) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:18,代码来源:function_module.py

示例3: uniform

# 需要导入模块: from theano import gof [as 别名]
# 或者: from theano.gof import Variable [as 别名]
def uniform(self, size, low=0.0, high=1.0, ndim=None,
            dtype=config.floatX):
        """
        Return symbolic tensor of uniform numbers.

        """
        if isinstance(size, tuple):
            msg = "size must be a tuple of int or a Theano variable"
            assert all([isinstance(i, int) or isinstance(i, Variable)
                for i in size]), msg
        else:
            msg = "size must be a tuple of int or a Theano variable"
            assert isinstance(size, Variable) and size.ndim == 1, msg
        generator = theano.shared(False)  # makes a generic
        s_size = theano.tensor.as_tensor_variable(size)
        u = CURAND_Uniform.new_auto_update(generator, ndim, dtype, s_size,
                self.next_seed())
        self.state_updates.append(u.update)
        rval = u * (high - low) + low
        if u.type.broadcastable != rval.type.broadcastable:
            raise NotImplementedError(
                'Increase the size to match the broadcasting pattern of '
                'low and `high` arguments'
            )
        return  rval 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:27,代码来源:rng_curand.py

示例4: make_node

# 需要导入模块: from theano import gof [as 别名]
# 或者: from theano.gof import Variable [as 别名]
def make_node(self, x, index):
        assert isinstance(x.type, TypedListType)
        if not isinstance(index, Variable):
            if isinstance(index, slice):
                index = Constant(SliceType(), index)
                return Apply(self, [x, index], [x.type()])
            else:
                index = T.constant(index, ndim=0, dtype='int64')
                return Apply(self, [x, index], [x.ttype()])
        if isinstance(index.type, SliceType):
            return Apply(self, [x, index], [x.type()])
        elif isinstance(index, T.TensorVariable) and index.ndim == 0:
            assert index.dtype == 'int64'
            return Apply(self, [x, index], [x.ttype()])
        else:
            raise TypeError('Expected scalar or slice as index.') 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:18,代码来源:basic.py

示例5: _is_dense_variable

# 需要导入模块: from theano import gof [as 别名]
# 或者: from theano.gof 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

示例6: as_sparse_variable

# 需要导入模块: from theano import gof [as 别名]
# 或者: from theano.gof 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

示例7: make_node

# 需要导入模块: from theano import gof [as 别名]
# 或者: from theano.gof 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

示例8: my_as_scalar

# 需要导入模块: from theano import gof [as 别名]
# 或者: from theano.gof import Variable [as 别名]
def my_as_scalar(a):
        # Since scal.as_scalar does not know about tensor types (it would
        # create a circular import) , this method converts either a
        # TensorVariable or a ScalarVariable to a scalar.
        if isinstance(a, gof.Variable) and isinstance(a.type, TensorType):
            return theano.tensor.scalar_from_tensor(a)
        else:
            return scal.as_scalar(a) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:10,代码来源:subtensor.py

示例9: as_index_variable

# 需要导入模块: from theano import gof [as 别名]
# 或者: from theano.gof import Variable [as 别名]
def as_index_variable(idx):
    if idx is None:
        return NoneConst.clone()
    if isinstance(idx, slice):
        return make_slice(idx)
    if isinstance(idx, gof.Variable) and isinstance(idx.type, SliceType):
        return idx
    idx = theano.tensor.as_tensor_variable(idx)
    if idx.type.dtype[:3] not in ('int', 'uin'):
        raise TypeError('index must be integers')
    return idx 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:13,代码来源:subtensor.py

示例10: filter_variable

# 需要导入模块: from theano import gof [as 别名]
# 或者: from theano.gof import Variable [as 别名]
def filter_variable(self, other, allow_convert=True):
        """
        Convert a symbolic Variable into a TensorType, if compatible.

        For the moment, only a TensorType or CudaNdarrayType will be
        converted, provided they have the same number of dimensions,
        broadcastable pattern, and dtype.

        """
        if hasattr(other, '_as_TensorVariable'):
            other = other._as_TensorVariable()

        if not isinstance(other, Variable):
            # The value is not a Variable: we cast it into
            # a Constant of the appropriate Type.
            other = self.Constant(type=self, data=other)

        if other.type == self:
            return other

        if allow_convert:
            # Attempt safe broadcast conversion.
            other2 = self.convert_variable(other)
            if other2 is not None and other2.type == self:
                return other2

        raise TypeError(
            'Cannot convert Type %(othertype)s '
            '(of Variable %(other)s) into Type %(self)s. '
            'You can try to manually convert %(other)s into a %(self)s.' %
            dict(othertype=other.type,
                 other=other,
                 self=self)) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:35,代码来源:type.py

示例11: make_variable

# 需要导入模块: from theano import gof [as 别名]
# 或者: from theano.gof 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

示例12: all

# 需要导入模块: from theano import gof [as 别名]
# 或者: from theano.gof import Variable [as 别名]
def all(self, axis=None, keepdims=False):
        return theano.tensor.basic.all(self, axis=axis, keepdims=keepdims)

    # Otherwise TensorVariable[:-1] does not work as Python 2.5.1 calls
    # __len__ before calling __getitem__. It also does not catch the raised
    # Exception!
    # def __len__(self):
    #     # We can't implement __len__ as Python requests that this
    #     # function returns an integer >=0
    #     raise Exception("Theano Variables can't work with len(Theano "
    #                     "Variable) due to Python restriction. You can use "
    #                     "TheanoVariable.shape[0] instead.") 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:14,代码来源:var.py

示例13: validate

# 需要导入模块: from theano import gof [as 别名]
# 或者: from theano.gof import Variable [as 别名]
def validate(self, fgraph):
        if not hasattr(fgraph, 'destroyers'):
            return True
        for r in self.protected + list(fgraph.outputs):
            if fgraph.destroyers(r):
                raise gof.InconsistencyError("Trying to destroy a protected"
                                             "Variable.", r) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:9,代码来源:function_module.py

示例14: expand_in

# 需要导入模块: from theano import gof [as 别名]
# 或者: from theano.gof import Variable [as 别名]
def expand_in(sinput, rinputs):
        # For SymbolicInputKits, this extracts a list of SymbolicInput
        # instances and corresponding indices such that these
        # SymbolicInputs are representative of some of the Variable
        # instances in inputs.  For SymbolicInput, this returns None
        # as the list of indices and a list with just the
        # SymbolicInput.
        if isinstance(sinput, SymbolicInputKit):
            return sinput.complete(rinputs)
        elif isinstance(sinput, SymbolicInput):
            return [None, [sinput]] 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:13,代码来源:function_module.py

示例15: wrap_out

# 需要导入模块: from theano import gof [as 别名]
# 或者: from theano.gof import Variable [as 别名]
def wrap_out(output):
        if isinstance(output, SymbolicOutput):
            return output
        elif isinstance(output, gof.Variable):
            return SymbolicOutput(output)
        else:
            raise TypeError("Unknown output type: %s (%s)", type(output),
                            output) 
开发者ID:muhanzhang,项目名称:D-VAE,代码行数:10,代码来源:function_module.py


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