提交 f6ed1418 authored 作者: Olivier Delalleau's avatar Olivier Delalleau

Added tensor.zeros and tensor.ones similar to numpy syntax

上级 01006a4e
...@@ -1889,6 +1889,22 @@ def zeros_like(model): ...@@ -1889,6 +1889,22 @@ def zeros_like(model):
#return Zeros(model.type.ndim)(shape(model)) #return Zeros(model.type.ndim)(shape(model))
return fill(model, constant(0.0, dtype=model.type.dtype)) return fill(model, constant(0.0, dtype=model.type.dtype))
def zeros(shape, dtype=config.floatX):
"""
Create a Tensor filled with zeros, closer to Numpy's syntax than ``alloc``.
"""
return alloc(numpy.array(0, dtype=dtype), *shape)
def ones(shape, dtype=config.floatX):
"""
Create a Tensor filled with ones, closer to Numpy's syntax than ``alloc``.
"""
return alloc(numpy.array(1, dtype=dtype), *shape)
class Eye(gof.Op): class Eye(gof.Op):
def __init__(self, dtype=config.floatX): def __init__(self, dtype=config.floatX):
self.dtype = dtype self.dtype = dtype
...@@ -2054,6 +2070,7 @@ class Alloc(gof.Op): ...@@ -2054,6 +2070,7 @@ class Alloc(gof.Op):
alloc = Alloc() alloc = Alloc()
pprint.assign(alloc, printing.FunctionPrinter('alloc')) pprint.assign(alloc, printing.FunctionPrinter('alloc'))
@_redefine(elemwise.Elemwise(scal.identity)) @_redefine(elemwise.Elemwise(scal.identity))
def tensor_copy(a): def tensor_copy(a):
"""Create a duplicate of `a` (with duplicated storage)""" """Create a duplicate of `a` (with duplicated storage)"""
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论