提交 5930ecd4 authored 作者: Frederic Bastien's avatar Frederic Bastien

Postpone some code from Composite.__init__ to later in case we don't need them.…

Postpone some code from Composite.__init__ to later in case we don't need them. Could speed up fusion optimization.
上级 3acf57cb
......@@ -3487,6 +3487,9 @@ class Composite(ScalarOp):
Return the C code for this Composite Op.
"""
# It was already called
if hasattr(self, '_c_code'):
return
subd = dict(chain(
((e, "%%(i%i)s" % i) for i, e in enumerate(self.fgraph.inputs)),
((e, "%%(o%i)s" % i) for i, e in enumerate(self.fgraph.outputs))))
......@@ -3650,7 +3653,8 @@ class Composite(ScalarOp):
# Postpone the creation in case it isn't needed.
# self.init_name() # self.name
self.name = None
self.init_c_code() # self._c_code and self.nodenames
def prepare_node(self, node, storage_map, compute_map):
self.init_py_impls() # self._impls
def output_types(self, input_types):
......@@ -3695,6 +3699,9 @@ class Composite(ScalarOp):
raise NotImplementedError("grad is not implemented for Composite")
def c_code(self, node, nodename, inames, onames, sub):
if not hasattr(self, '_c_code'):
self.init_c_code()
d = dict(chain(izip(("i%i" % i for i in xrange(len(inames))), inames),
izip(("o%i" % i for i in xrange(len(onames))),
onames)), **sub)
......@@ -3752,9 +3759,13 @@ class Composite(ScalarOp):
return False
# see __hash__ for comment on why there is no mention of fgraph
# or module cache key here.
if not hasattr(self, '_c_code'):
self.init_c_code() # self._c_code and self.nodenames
return (self._c_code == other._c_code)
def __hash__(self):
if not hasattr(self, '_c_code'):
self.init_c_code() # self._c_code and self.nodenames
rval = hash((type(self),
self.nin,
self.nout,
......@@ -3771,7 +3782,7 @@ class Composite(ScalarOp):
def __getstate__(self):
rval = dict(self.__dict__)
del rval['_impls']
rval.pop('_impls', None)
del rval['fgraph']
return rval
......
......@@ -849,6 +849,13 @@ second dimension
char = numpy.sctype2char(out_dtype)
sig = char * node.nin + '->' + char * node.nout
node.tag.sig = sig
node.tag.fake_node = Apply(self.scalar_op,
[get_scalar_type(dtype=input.type.dtype).make_variable()
for input in node.inputs],
[get_scalar_type(dtype=output.type.dtype).make_variable()
for output in node.outputs])
self.scalar_op.prepare_node(node.tag.fake_node, [], [])
def perform(self, node, inputs, output_storage):
if len(node.inputs) >= 32:
......@@ -1109,11 +1116,7 @@ second dimension
# We generate the C code of the inner loop using the scalar op
task_code = self.scalar_op.c_code(
Apply(self.scalar_op,
[get_scalar_type(dtype=input.type.dtype).make_variable()
for input in node.inputs],
[get_scalar_type(dtype=output.type.dtype).make_variable()
for output in node.outputs]),
node.tag.fake_node,
nodename + '_scalar_',
["%s_i" % s for s in _inames],
["%s_i" % s for s in onames],
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论