提交 27060dbb authored 作者: carriepl's avatar carriepl

Merge pull request #2805 from SinaHonari/issue2085

Better error message when missing dimension in initial value in Scan
...@@ -288,14 +288,28 @@ class Scan(PureOp): ...@@ -288,14 +288,28 @@ class Scan(PureOp):
" does not match the number of inputs given to scan.") " does not match the number of inputs given to scan.")
new_inputs = [inputs[0]] new_inputs = [inputs[0]]
# assert dtype is consistent # assert dtype is consistent
err_msg1 = ('When compiling the inner function of scan the ' err_msg1 = ('When compiling the inner function of scan (the '
'following error has been encountered: The ' 'function called by scan in each of its iterations) '
'the following error has been encountered: The '
'%s %s (argument number %d) has dtype ' '%s %s (argument number %d) has dtype '
'%s and %d dimension(s). The corresponding slice %s ' '%s and %d dimension(s). The corresponding variable '
'however has dtype %s and %d dimension(s) (it should ' 'in the inner function of scan %s '
'have the same dtype and one fewer dimensions). This ' 'however has dtype %s and %d dimension(s). This '
'should never happen, please ' 'variable in the inner function of scan should '
'report to theano-dev mailing list' 'have the same dtype and one fewer dimension '
'compared to its corresponding variable in the initial '
'state (outputs_info in scan nomenclature). For example, '
'if the inner function of scan returns a vector '
'of size d and scan uses the values of '
'the previous time-step, then the initial state in scan '
'should be a matrix of shape (1, d). '
'The first dimension of this '
'matrix corresponds to the number of previous time-steps '
'that scan uses in each of its iterations. '
'In order to solve this issue if the two variable currently '
'have the same dimensionality, you can increase the '
'dimensionality of the varialbe in the initial state of scan '
'by using dimshuffle or shape_padleft. '
) )
err_msg2 = ('When compiling the inner function of scan the ' err_msg2 = ('When compiling the inner function of scan the '
'following error has been encountered: The ' 'following error has been encountered: The '
...@@ -304,13 +318,26 @@ class Scan(PureOp): ...@@ -304,13 +318,26 @@ class Scan(PureOp):
'has dtype %s, while the result of the inner function ' 'has dtype %s, while the result of the inner function '
'(`fn`) has dtype %s. This can happen if the inner ' '(`fn`) has dtype %s. This can happen if the inner '
'function of scan results in an upcast or downcast.') 'function of scan results in an upcast or downcast.')
err_msg3 = ('When compiling the inner function of scan the ' err_msg3 = ('When compiling the inner function of scan (the '
'following error has been encountered: The ' 'function called by scan in each of its iterations) '
'the following error has been encountered: The '
'initial state (`outputs_info` in scan nomenclature) ' 'initial state (`outputs_info` in scan nomenclature) '
'of variable %s (argument number %d) has %d dimension(s), ' 'of variable %s (argument number %d) has %d dimension(s), '
'while the result of the inner function (`fn`) has %d ' 'while the corresponding variable in the result of the inner '
'dimension(s) (should be one less than the initial ' 'function of scan (`fn`) has %d dimension(s) (it should '
'state).') 'be one less than the initial state). For example, '
'if the inner function of scan returns a vector '
'of size d and scan uses the values of '
'the previous time-step, then the initial state in scan '
'should be a matrix of shape (1, d). '
'The first dimension of this '
'matrix corresponds to the number of previous time-steps '
'that scan uses in each of its iterations. '
'In order to solve this issue if the two varialbe currently '
'have the same dimensionality, you can increase the '
'dimensionality of the variable in the initial state of scan '
'by using dimshuffle or shape_padleft. '
)
def format(var, as_var): def format(var, as_var):
""" This functions ensures that ``out`` has the same dtype as """ This functions ensures that ``out`` has the same dtype as
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论