提交 e574a994 authored 作者: Hengjean's avatar Hengjean

Added check_input flag

上级 17f1b0fa
...@@ -489,3 +489,10 @@ AddConfigVar('openmp_elemwise_minsize', ...@@ -489,3 +489,10 @@ AddConfigVar('openmp_elemwise_minsize',
IntParam(200000), IntParam(200000),
in_c_key=False, in_c_key=False,
) )
AddConfigVar('check_input',
"Specify if types should check their input in their C code. "
"It can be used to speed up compilation, reduce overhead"
"(particularly for scalars) and reduce the number of generated C"
"files.",
BoolParam(True))
...@@ -294,7 +294,7 @@ class CudaNdarrayType(Type): ...@@ -294,7 +294,7 @@ class CudaNdarrayType(Type):
%(name)s = (CudaNdarray*)py_%(name)s; %(name)s = (CudaNdarray*)py_%(name)s;
//std::cerr << "c_extract " << %(name)s << '\\n'; //std::cerr << "c_extract " << %(name)s << '\\n';
""" % locals() """ % locals()
if(check_input): if(check_input and theano.config.check_input):
print >> sio, """ print >> sio, """
if (%(name)s->nd != %(nd)s) if (%(name)s->nd != %(nd)s)
{ {
......
...@@ -273,7 +273,7 @@ class Scalar(Type): ...@@ -273,7 +273,7 @@ class Scalar(Type):
def c_extract(self, name, sub, check_input=True): def c_extract(self, name, sub, check_input=True):
specs = self.dtype_specs() specs = self.dtype_specs()
if(check_input): if(check_input and theano.config.check_input):
pre = """ pre = """
if (!PyObject_TypeCheck(py_%(name)s, &%(pyarr_type)s)) if (!PyObject_TypeCheck(py_%(name)s, &%(pyarr_type)s))
{ {
......
...@@ -438,7 +438,7 @@ class TensorType(Type): ...@@ -438,7 +438,7 @@ class TensorType(Type):
def c_extract(self, name, sub, check_input=True): def c_extract(self, name, sub, check_input=True):
"""Override `CLinkerType.c_extract` """ """Override `CLinkerType.c_extract` """
if(check_input): if(check_input and theano.config.check_input):
check = """ check = """
%(name)s = NULL; %(name)s = NULL;
if (py_%(name)s == Py_None) { if (py_%(name)s == Py_None) {
......
...@@ -246,7 +246,7 @@ class T_extending(unittest.TestCase): ...@@ -246,7 +246,7 @@ class T_extending(unittest.TestCase):
double.c_init = c_init double.c_init = c_init
def c_extract(name, sub, check_input=True): def c_extract(name, sub, check_input=True):
if(check_input): if(check_input and theano.config.check_input):
pre = """ pre = """
if (!PyFloat_Check(py_%(name)s)) { if (!PyFloat_Check(py_%(name)s)) {
PyErr_SetString(PyExc_TypeError, "expected a float"); PyErr_SetString(PyExc_TypeError, "expected a float");
...@@ -310,7 +310,7 @@ class T_extending(unittest.TestCase): ...@@ -310,7 +310,7 @@ class T_extending(unittest.TestCase):
""" % dict(name = name) """ % dict(name = name)
def c_extract(self, name, sub, check_input=True): def c_extract(self, name, sub, check_input=True):
if(check_input): if(check_input and theano.config.check_input):
pre = """ pre = """
if (!PyFloat_Check(py_%(name)s)) { if (!PyFloat_Check(py_%(name)s)) {
PyErr_SetString(PyExc_TypeError, "expected a float"); PyErr_SetString(PyExc_TypeError, "expected a float");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论