提交 1d54925f authored 作者: Shawn Tan's avatar Shawn Tan

Added check in case flattened array is 1d.

上级 e1b2dc23
......@@ -679,29 +679,44 @@ class GpuAdvancedIncSubtensor(HideC, tensor.AdvancedIncSubtensor):
# build the indices and use it
index = idx_[p:] + [slice(None)] * (len(x_flat.shape) - len(idx_[p:]) - 1)
take_idx = sum(i * s for i, s in zip(nidx, strides))
k = get_iadd(node.inputs[0], node.inputs[1])
if x_flat.shape[-len(y_flat.shape):] == y_flat.shape or y_flat.shape == ():
# y_flat has to be broadcast over axes of x_flat[i]
for i in take_idx.flatten():
if len(idx_[p:]) > 0:
x_flat_sub = x_flat[i].__getitem__(index)
if index == []:
for j, i in enumerate(take_idx.flatten()):
if y_flat.shape == ():
val = y_flat
else:
x_flat_sub = x_flat[i]
val = y_flat[j]
tmp = pygpu.elemwise.elemwise2(
x_flat_sub, '+', y_flat, x_flat_sub,
x_flat[i], '+', val, x_flat[i],
broadcast=True,
convert_f16=True
)
x_flat[i].__setitem__(index, tmp)
x_flat.__setitem__(i, tmp)
else:
# y_flat's first axis corresponds to first exist of x_flat
for j, i in enumerate(take_idx.flatten()):
if len(idx_[p:]) > 0:
x_flat_sub = x_flat[i].__getitem__(index)
else:
x_flat_sub = x_flat[i]
k(x_flat_sub, y_flat[j % y_flat.shape[0]], broadcast=True)
k = get_iadd(node.inputs[0], node.inputs[1])
if x_flat.shape[-len(y_flat.shape):] == y_flat.shape or y_flat.shape == ():
# y_flat has to be broadcast over axes of x_flat[i]
for i in take_idx.flatten():
if len(idx_[p:]) > 0:
x_flat_sub = x_flat[i].__getitem__(index)
else:
x_flat_sub = x_flat[i]
tmp = pygpu.elemwise.elemwise2(
x_flat_sub, '+', y_flat, x_flat_sub,
broadcast=True,
convert_f16=True
)
x_flat[i].__setitem__(index, tmp)
else:
# y_flat's first axis corresponds to first exist of x_flat
for j, i in enumerate(take_idx.flatten()):
if len(idx_[p:]) > 0:
x_flat_sub = x_flat[i].__getitem__(index)
else:
x_flat_sub = x_flat[i]
k(x_flat_sub, y_flat[j % y_flat.shape[0]], broadcast=True)
x_ = x_flat.reshape(x_.shape).transpose(*rtransp)
out[0] = x_
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论