提交 6a4445a1 authored 作者: Razvan Pascanu's avatar Razvan Pascanu

sync between cython implementation of scan and cython one.

上级 815b54cb
...@@ -56,7 +56,7 @@ import cython ...@@ -56,7 +56,7 @@ import cython
import numpy import numpy
cimport numpy cimport numpy
from theano import gof
import time import time
import copy import copy
from theano.sandbox import cuda from theano.sandbox import cuda
...@@ -331,7 +331,19 @@ def perform( ...@@ -331,7 +331,19 @@ def perform(
output_storage[<unsigned int>pdx].storage[0] = None output_storage[<unsigned int>pdx].storage[0] = None
# 5. compute outputs # 5. compute outputs
t0_fn = time.time() t0_fn = time.time()
fn()
try:
fn()
except Exception:
if hasattr(fn, 'position_of_error'):
# this is a new vm-provided function
# the C VM needs this because the exception manipulation
# done by raise_with_op is not implemented in C.
gof.vm.raise_with_op(fn.nodes[fn.position_of_error])
else:
# old-style linkers raise their own exceptions
raise
dt_fn = time.time() - t0_fn dt_fn = time.time() - t0_fn
t_fn += dt_fn t_fn += dt_fn
if self.as_while: if self.as_while:
...@@ -435,6 +447,16 @@ def perform( ...@@ -435,6 +447,16 @@ def perform(
elif store_steps[idx] > i - self.mintaps[idx]: elif store_steps[idx] > i - self.mintaps[idx]:
outs[idx][0][i-self.mintaps[idx]:] = 0 outs[idx][0][i-self.mintaps[idx]:] = 0
# This is a fix for a bug introduced by while. If you say
# you want to loop up to a condition, you expect the output
# to have that length ( and not the maximal length possible)
#
# Without this the behaviour of a scan op is not consistent
# if optimization gets applied compared to when optimization
# do not get applied
if i < n_steps:
outs[idx][0] = outs[idx][0][:-(n_steps - i)]
t_call = time.time() - t0_call t_call = time.time() - t0_call
if hasattr(fnct.maker, 'profile'): if hasattr(fnct.maker, 'profile'):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论