提交 5e358424 authored 作者: carriepl's avatar carriepl

Fix bug and refactor in python backend

上级 7772a869
...@@ -1370,7 +1370,7 @@ class Scan(PureOp): ...@@ -1370,7 +1370,7 @@ class Scan(PureOp):
# and store it in `outs` as usual # and store it in `outs` as usual
if not same_data: if not same_data:
outs[j][0][k + pos[j]] = \ outs[j][0][k + pos[j]] = \
input_storage[inp_idx].storage[0] input_storage[self.n_seqs + inp_idx].storage[0]
else: else:
# This output tap has not been preallocated, recover # This output tap has not been preallocated, recover
...@@ -1390,12 +1390,17 @@ class Scan(PureOp): ...@@ -1390,12 +1390,17 @@ class Scan(PureOp):
for j in xrange(begin, end): for j in xrange(begin, end):
# Check whether the initialization of the output storage map # Copy the output value to `outs`, if necessary
# for this output has been reused. if store_steps[j] == 1 or self.vector_outs[j]:
outs[j][0][pos[j]] = \
output_storage[offset_out + j].storage[0]
else:
# Check whether the initialization of the output storage
# map for this output has been reused.
old_var = old_output_storage[offset_out + j] old_var = old_output_storage[offset_out + j]
old_data = old_output_data[offset_out + j]
new_var = output_storage[offset_out + j].storage[0] new_var = output_storage[offset_out + j].storage[0]
if old_var is new_var: if old_var is new_var:
old_data = old_output_data[offset_out + j]
if old_data is None: if old_data is None:
output_reused = False output_reused = False
elif hasattr(new_var, 'gpudata'): elif hasattr(new_var, 'gpudata'):
...@@ -1405,9 +1410,7 @@ class Scan(PureOp): ...@@ -1405,9 +1410,7 @@ class Scan(PureOp):
else: else:
output_reused = False output_reused = False
# Copy the output value to `outs`, if necessary if not output_reused:
if (store_steps[j] == 1 or self.vector_outs[j] or
not output_reused):
outs[j][0][pos[j]] = \ outs[j][0][pos[j]] = \
output_storage[offset_out + j].storage[0] output_storage[offset_out + j].storage[0]
...@@ -1416,21 +1419,6 @@ class Scan(PureOp): ...@@ -1416,21 +1419,6 @@ class Scan(PureOp):
end += self.n_nit_sot end += self.n_nit_sot
for j in xrange(begin, end): for j in xrange(begin, end):
# Check whether the initialization of the output storage map
# for this output has been reused.
old_var = old_output_storage[offset_out + j]
old_data = old_output_data[offset_out + j]
new_var = output_storage[offset_out + j].storage[0]
if old_var is new_var:
if old_data is None:
output_reused = False
elif hasattr(new_var, 'gpudata'):
output_reused = (new_var.gpudata == old_data)
elif hasattr(new_var, 'data'):
output_reused = (new_var.data == old_data)
else:
output_reused = False
if i == 0: if i == 0:
jout = j + offset_out jout = j + offset_out
shape = (store_steps[j],) + \ shape = (store_steps[j],) + \
...@@ -1446,8 +1434,26 @@ class Scan(PureOp): ...@@ -1446,8 +1434,26 @@ class Scan(PureOp):
elif outs[j][0].shape[0] != store_steps[j]: elif outs[j][0].shape[0] != store_steps[j]:
outs[j][0] = outs[j][0][:store_steps[j]] outs[j][0] = outs[j][0][:store_steps[j]]
outs[j][0][pos[j]] = output_storage[jout].storage[0] outs[j][0][pos[j]] = output_storage[jout].storage[0]
elif (store_steps[j] == 1 or self.vector_outs[j] or elif store_steps[j] == 1 or self.vector_outs[j]:
not output_reused): outs[j][0][pos[j]] = \
output_storage[j + offset_out].storage[0]
else:
# Check whether the initialization of the output storage map
# for this output has been reused.
old_var = old_output_storage[offset_out + j]
old_data = old_output_data[offset_out + j]
new_var = output_storage[offset_out + j].storage[0]
if old_var is new_var:
if old_data is None:
output_reused = False
elif hasattr(new_var, 'gpudata'):
output_reused = (new_var.gpudata == old_data)
elif hasattr(new_var, 'data'):
output_reused = (new_var.data == old_data)
else:
output_reused = False
if not output_reused:
outs[j][0][pos[j]] = \ outs[j][0][pos[j]] = \
output_storage[j + offset_out].storage[0] output_storage[j + offset_out].storage[0]
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论