提交 529259a6 authored 作者: Frederic's avatar Frederic

Do a copy when NumPy didn't allocate new memory.

An opt will remove this case if the repeat pattern is a constant 1.
上级 69ce2cd1
......@@ -4011,9 +4011,18 @@ class Tile(Op):
def perform(self, node, inp, out_):
x, reps = inp
out, = out_
out[0] = numpy.tile(x, reps)
if len(out[0].shape) != self.ndim:
raise ValueError('Tile.perform produced incorrect shape')
res = numpy.tile(x, reps)
if res.ndim != self.ndim:
raise ValueError(
'Tile.perform produced incorrect number of dimensions')
if (numpy.asarray(reps) == 1).all():
# In that case, some NumPy version return a view! As this
# op isn't declared as inplace, we need to check that and
# copy the data.
if numpy.may_share_memory(res, x):
res = res.copy()
out[0] = res
def infer_shape(self, node, in_shapes):
# Note: in contrast with numpy, it is assumed that x.shape and reps
......
......@@ -2894,6 +2894,7 @@ class T_Tile(unittest.TestCase):
topo = f.maker.fgraph.toposort()
assert len(topo) == 1
assert isinstance(topo[0].op, compile.DeepCopyOp)
f(data)
# If the repeat parameter is longer then v.ndim, we must
# replace it with a DimShuffle to add the extra parameter.
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论