提交 3c755c69 authored 作者: Faruk Ahmed's avatar Faruk Ahmed 提交者: Frederic Bastien

ifelse - inherit from Op, rename make_thunk to make_py_thunk; scan - added make_py_thunk func

上级 7fa59095
...@@ -20,7 +20,7 @@ import numpy ...@@ -20,7 +20,7 @@ import numpy
import theano.tensor import theano.tensor
from theano.tensor import TensorType from theano.tensor import TensorType
from theano import gof from theano import gof
from theano.gof import PureOp, Apply from theano.gof import Op, Apply
from six import iteritems from six import iteritems
from six.moves import xrange from six.moves import xrange
...@@ -41,7 +41,7 @@ __contact__ = "Razvan Pascanu <r.pascanu@gmail>" ...@@ -41,7 +41,7 @@ __contact__ = "Razvan Pascanu <r.pascanu@gmail>"
_logger = logging.getLogger('theano.ifelse') _logger = logging.getLogger('theano.ifelse')
class IfElse(PureOp): class IfElse(Op):
""" """
Op that provides conditional graph evaluation if used with the CVM/VM Op that provides conditional graph evaluation if used with the CVM/VM
linkers. Note that there exist a helpful function `ifelse` that should linkers. Note that there exist a helpful function `ifelse` that should
...@@ -235,7 +235,7 @@ class IfElse(PureOp): ...@@ -235,7 +235,7 @@ class IfElse(PureOp):
if_true_op(*if_true, **dict(return_list=True)) + if_true_op(*if_true, **dict(return_list=True)) +
if_false_op(*if_false, **dict(return_list=True))) if_false_op(*if_false, **dict(return_list=True)))
def make_thunk(self, node, storage_map, compute_map, no_recycling): def make_py_thunk(self, node, storage_map, compute_map, no_recycling):
cond = node.inputs[0] cond = node.inputs[0]
ts = node.inputs[1:][:self.n_outs] ts = node.inputs[1:][:self.n_outs]
fs = node.inputs[1:][self.n_outs:] fs = node.inputs[1:][self.n_outs:]
......
...@@ -697,7 +697,8 @@ class Scan(PureOp): ...@@ -697,7 +697,8 @@ class Scan(PureOp):
self._hash_inner_graph, self._hash_inner_graph,
scan_utils.hash_listsDictsTuples(self.info))) scan_utils.hash_listsDictsTuples(self.info)))
def make_thunk(self, node, storage_map, compute_map, no_recycling): def make_thunk(self, node, storage_map, compute_map, no_recycling,
python_exec=False):
""" """
Parameters Parameters
...@@ -715,7 +716,8 @@ class Scan(PureOp): ...@@ -715,7 +716,8 @@ class Scan(PureOp):
no_recycling no_recycling
List of variables for which it is forbidden to reuse memory List of variables for which it is forbidden to reuse memory
allocated by a previous call. allocated by a previous call.
python_exec
If we want python execution.
Notes Notes
----- -----
If the thunk consults the storage_map on every call, it is safe If the thunk consults the storage_map on every call, it is safe
...@@ -864,6 +866,8 @@ class Scan(PureOp): ...@@ -864,6 +866,8 @@ class Scan(PureOp):
for out in self.fn.maker.fgraph.outputs] for out in self.fn.maker.fgraph.outputs]
try: try:
if python_exec is True:
raise theano.gof.cmodule.MissingGXX
cython_mintaps = numpy.asarray(self.mintaps, dtype='int32') cython_mintaps = numpy.asarray(self.mintaps, dtype='int32')
cython_tap_array_len = \ cython_tap_array_len = \
numpy.asarray([len(x) for x in self.tap_array], numpy.asarray([len(x) for x in self.tap_array],
...@@ -961,6 +965,13 @@ class Scan(PureOp): ...@@ -961,6 +965,13 @@ class Scan(PureOp):
rval.lazy = False rval.lazy = False
return rval return rval
def make_py_thunk(self, node, storage_map, compute_map, no_recycling):
return self.make_thunk(node=node,
storage_map=storage_map,
compute_map=compute_map,
no_recycling=no_recycling,
python_exec=True)
def inner_seqs(self, list_inputs): def inner_seqs(self, list_inputs):
# Given the list of inner inputs this function grabs those # Given the list of inner inputs this function grabs those
# corresponding to sequences # corresponding to sequences
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论