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


Python scalar.as_scalar函数代码示例

本文整理汇总了Python中theano.scalar.as_scalar函数的典型用法代码示例。如果您正苦于以下问题:Python as_scalar函数的具体用法?Python as_scalar怎么用?Python as_scalar使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: ensure_float

def ensure_float(val, name):
    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:huamichaelchen,项目名称:Theano,代码行数:10,代码来源:nerv.py

示例2: wrapper

        def wrapper(*args):
            x = as_sparse_variable(args[0])
            
            xs = [scalar.as_scalar(arg) for arg in args[1:]]

            data, ind, ptr, shape = csm_properties(x)

            data = tensor_op(data, *xs)

            return CSM(x.format)(data, ind, ptr, shape)
开发者ID:jsalvatier,项目名称:Theano-1,代码行数:10,代码来源:sp2.py

示例3: make_node

    def make_node(self, kern, topgrad, desc, h, w):
        kern = as_cuda_ndarray_variable(kern)
        topgrad = as_cuda_ndarray_variable(topgrad)
        if kern.type.ndim != 4:
            raise TypeError('kern must be 4D tensor')
        if topgrad.type.ndim != 4:
            raise TypeError('topgrad must be 4D tensor')

        if not isinstance(desc.type, CDataType) \
                or desc.type.ctype != 'cudnnConvolutionDescriptor_t':
            raise TypeError('desc must be cudnnConvolutionDescriptor_t')

        h = as_scalar(h)
        w = as_scalar(w)

        broadcastable = [topgrad.type.broadcastable[0],
                         kern.type.broadcastable[1],
                         False, False]

        return Apply(self, [kern, topgrad, desc, h, w],
                     [CudaNdarrayType(broadcastable)()])
开发者ID:c0g,项目名称:Theano,代码行数:21,代码来源:dnn.py

示例4: ensure_dt

def ensure_dt(val, default, name, dtype):
    if val is None:
        val = 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 == dtype:
        val = val.astype(dtype)
    return val
开发者ID:hfinger,项目名称:Theano,代码行数:12,代码来源:dnn.py

示例5: make_node

 def make_node(self, pvals, unis, n=1):
     pvals = T.as_tensor_variable(pvals)
     unis = T.as_tensor_variable(unis)
     if pvals.ndim != 2:
         raise NotImplementedError('pvals ndim should be 2', pvals.ndim)
     if unis.ndim != 1:
         raise NotImplementedError('unis ndim should be 1', unis.ndim)
     if self.odtype == 'auto':
         odtype = pvals.dtype
     else:
         odtype = self.odtype
     out = T.tensor(dtype=odtype, broadcastable=pvals.type.broadcastable)
     return Apply(self, [pvals, unis, as_scalar(n)], [out])
开发者ID:DingKe,项目名称:attention-lvcsr,代码行数:13,代码来源:multinomial.py

示例6: make_node

    def make_node(self, pvals, unis, n):
        assert pvals.dtype == 'float32'
        assert unis.dtype == 'float32'
        ctx_name = infer_context_name(pvals, unis)

        pvals = as_gpuarray_variable(pvals, ctx_name)
        unis = as_gpuarray_variable(unis, ctx_name)

        if pvals.ndim != 2:
            raise NotImplementedError('pvals ndim should be 2', pvals.ndim)
        if unis.ndim != 1:
            raise NotImplementedError('unis ndim should be 1', unis.ndim)
        if self.odtype == 'auto':
            odtype = 'int64'
        else:
            odtype = self.odtype
        assert odtype == 'int64', odtype
        br = (pvals.broadcastable[1], pvals.broadcastable[0])
        out = GpuArrayType(broadcastable=br,
                           dtype=odtype,
                           context_name=ctx_name)()

        return Apply(self, [pvals, unis, as_scalar(n)], [out])
开发者ID:DEVESHTARASIA,项目名称:Theano,代码行数:23,代码来源:multinomial.py

示例7: make_node

 def make_node(self, input):
     input = scalar.as_scalar(input)
     output = input.type()
     return Apply(self, [input], [output])
开发者ID:Abioy,项目名称:Theano,代码行数:4,代码来源:test_op.py

示例8: make_node

    def make_node(self, val):
        from theano.scalar import as_scalar
        from theano import Apply

        val = as_scalar(val).astype('uint64')
        return Apply(self, [val], [self.rtype()])
开发者ID:JesseLivezey,项目名称:Theano,代码行数:6,代码来源:type.py

示例9: make_node

 def make_node(self, a, b):
     return Apply(self, [scalar.as_scalar(a), scalar.as_scalar(b)], [scalar.float64()])
开发者ID:HapeMask,项目名称:Theano,代码行数:2,代码来源:test_types.py

示例10: make_node

 def make_node(self, x, scal):
     x = as_tensor_variable(x)
     scal = as_scalar(scal)
     return Apply(self, [x, scal], [x.type()])
开发者ID:Chin-I,项目名称:ccw_tutorial_theano,代码行数:4,代码来源:scalmulop.py


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