提交 d365c904 authored 作者: nouiz's avatar nouiz

Merge pull request #1320 from lamblin/set_error_in_fail

Set Python exception when C code fails
......@@ -124,8 +124,19 @@ class CodeBlock:
def failure_code(sub):
"""WRITEME"""
return "{%(failure_var)s = %(id)s; goto __label_%(id)i;}" % sub
"""Code contained in sub['fail'], usually substituted for %(fail)s.
It sets information about current error, then goto the code
actually handling the failure, which is defined in struct_gen().
"""
return '''{
%(failure_var)s = %(id)s;
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_RuntimeError,
"Unexpected error in an Op's C code. "
"No Python exception was set.");
}
goto __label_%(id)i;}''' % sub
def code_gen(blocks):
......
......@@ -43,7 +43,7 @@ class NaiveAlgo(object):
def cache_version(self):
ver = self.scalar_op.c_code_cache_version()
if ver:
return (16, self.verbose, self.sync, ver)
return (17, self.verbose, self.sync, ver)
else:
return ver
......@@ -978,6 +978,15 @@ nd_collapse_[i]=0;
for (int i = 0; (i< %(nd)s) && (%(oname)s); ++i) {
if (dims[i] != CudaNdarray_HOST_DIMS(%(oname)s)[i])
{
PyErr_Format(PyExc_ValueError,
"GpuElemwise. Output dimension mis-match. Output"
" %(idx)d (indices start at 0), working inplace"
" on input %(input_idx)s, has shape[%%i] == %%i"
", but the output's size on that axis is %%i.",
i,
CudaNdarray_HOST_DIMS(%(oname)s)[i],
dims[i]
);
Py_DECREF(%(oname)s);
%(oname)s = NULL;
%(fail)s;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论