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

Work around broken deep copy

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