提交 57e6ab6d authored 作者: Mohammad Pezeshki's avatar Mohammad Pezeshki

test file deleted; total time computation became more efficient.

上级 a6328de4
import numpy
import theano
import theano.tensor as T
from theano.printing import debugprint
X = T.matrix('X')
W = T.matrix('W')
Y = T.dot(X, W)
Z = X - W
f = theano.function(inputs=[X, W], outputs=[Y, Z], profile=True)
for i in xrange(10):
f(numpy.random.uniform(size=(2, 2)),
numpy.random.uniform(size=(2, 2)))
#print f.profile.compute_total_times()
#print f.profile.apply_time
debugprint(f)
......@@ -294,20 +294,18 @@ class ProfileStats(object):
rval[node.op] += t
return rval
def get_node_total_time(self, node, total_times):
def fill_node_total_time(self, node, total_times):
if node not in total_times.keys():
total = self.apply_time[node]
for parent in node.get_parents():
if parent.owner in self.apply_time.keys():
total += self.get_node_total_time(parent.owner)
return total
else:
return total_times[node]
total_times[node] = total
def compute_total_times(self):
rval = {}
for node in self.apply_time.keys():
rval[node] = self.get_node_total_time(node, rval)
self.fill_node_total_time(node, rval)
return rval
def op_callcount(self):
......
......@@ -93,11 +93,10 @@ def debugprint(obj, depth=-1, print_type=False,
profile_list.append(None)
elif isinstance(obj, gof.Apply):
results_to_print.extend(obj.outputs)
for item in obj.outputs:
profile_list.append(None)
profile_list.extend([None for item in obj.outputs])
elif isinstance(obj, Function):
results_to_print.extend(obj.maker.fgraph.outputs)
profile_list.extend([None for item in obj.maker.fgraph.outputs])
profile_list.extend([obj.profile for item in obj.maker.fgraph.outputs])
order = obj.maker.fgraph.toposort()
elif isinstance(obj, gof.FunctionGraph):
results_to_print.extend(obj.outputs)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论