提交 1059cf8f authored 作者: Olivier Breuleux's avatar Olivier Breuleux

+tensor.mean

上级 655e9e77
...@@ -78,6 +78,28 @@ class Env(utils.object2): ...@@ -78,6 +78,28 @@ class Env(utils.object2):
node.env = self node.env = self
node.deps = {} node.deps = {}
def disown(self):
"""
Cleans up all of this Env's nodes and results so they are not
associated with this Env anymore.
The Env should not be used anymore after disown is called.
This may not clean everything this Env's features set in the
nodes and results. If there are no features, this should set
them back to what they were originally.
"""
for node in self.nodes:
del node.env
del node.deps
for result in self.results:
del result.env
del result.clients
self.nodes = set()
self.results = set()
self.inputs = None
self.outputs = None
### clients ### ### clients ###
......
...@@ -626,6 +626,17 @@ identity = elemwise.Elemwise(scal.identity, inplace_pattern = {0: [0]}) ...@@ -626,6 +626,17 @@ identity = elemwise.Elemwise(scal.identity, inplace_pattern = {0: [0]})
def sum(input, axis = None): def sum(input, axis = None):
return elemwise.Sum(axis)(input) return elemwise.Sum(axis)(input)
def mean(input, axis = None):
s = sum(input, axis)
shp = shape(input)
if axis is None:
axis = range(input.type.ndim)
elif isinstance(axis, int):
axis = [axis]
for i in axis:
s = s / shp[i]
return s
########################## ##########################
# Arithmetics # Arithmetics
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论