提交 ca08232f authored 作者: Frederic's avatar Frederic

Work around broken deep copy

上级 de61e6ca
...@@ -15,11 +15,12 @@ from copy import deepcopy ...@@ -15,11 +15,12 @@ from copy import deepcopy
from itertools import izip from itertools import izip
import logging import logging
from theano.gof import PureOp, Apply 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.compile import optdb from theano.compile import optdb
from theano.tensor import opt from theano.tensor import opt
...@@ -245,11 +246,14 @@ class IfElse(PureOp): ...@@ -245,11 +246,14 @@ class IfElse(PureOp):
else: else:
for out, outtype, t in izip(outputs, outtypes, ts): for out, outtype, t in izip(outputs, outtypes, ts):
compute_map[out][0] = 1 compute_map[out][0] = 1
val = storage_map[t][0]
if self.as_view: if self.as_view:
oval = storage_map[t][0] storage_map[out][0] = val
# Work around broken numpy deepcopy
elif type(a) in (numpy.ndarray, numpy.memmap):
storage_map[out][0] = val.copy()
else: else:
oval = deepcopy(storage_map[t][0]) storage_map[out][0] = deepcopy(val)
storage_map[out][0] = oval
return [] return []
else: else:
ls = [1 + idx + self.n_outs for idx in xrange(self.n_outs) ls = [1 + idx + self.n_outs for idx in xrange(self.n_outs)
...@@ -261,8 +265,12 @@ class IfElse(PureOp): ...@@ -261,8 +265,12 @@ class IfElse(PureOp):
compute_map[out][0] = 1 compute_map[out][0] = 1
# can't view both outputs unless destroyhandler # can't view both outputs unless destroyhandler
# improves # improves
oval = deepcopy(storage_map[f][0]) # Work around broken numpy deepcopy
storage_map[out][0] = oval val = storage_map[f][0]
if type(val) in (numpy.ndarray, numpy.memmap):
storage_map[out][0] = val.copy()
else:
storage_map[out][0] = deepcopy(val)
return [] return []
thunk.lazy = True thunk.lazy = True
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论