提交 c81517aa authored 作者: notoraptor's avatar notoraptor

Fix typos in 'wrapper.py'.

Replace locals() by manual dicts to prevent any missing variables in formatted strings in `wrapper.py` and `test_wrapper.py`.
上级 0ad8d9fd
......@@ -72,18 +72,12 @@ class QuadraticOpFunc(Op):
""" % {'name': name, 'float_type': float_type}
def c_code(self, node, name, inputs, outputs, sub):
X = inputs[0]
Y = outputs[0]
coeff = sub['params']
fail = sub['fail']
float_type = node.inputs[0].type.dtype_specs()[1]
float_typenum = node.inputs[0].type.dtype_specs()[2]
return """
%(float_type)s a = (%(float_type)s) (*(npy_float64*) PyArray_GETPTR1(%(coeff)s->a, 0)); // 0-D TensorType.
%(float_type)s b = %(coeff)s->b; // Scalar.
%(float_type)s c = (%(float_type)s) PyFloat_AsDouble(%(coeff)s->c); // Generic.
Py_XDECREF(%(Y)s);
%(Y)s = (PyArrayObject*)PyArray_EMPTY(PyArray_NDIM(%(X)s), PyArray_DIMS(%(X)s), %(float_typenum)s, PyArray_IS_F_CONTIGUOUS(%(X)s));
%(Y)s = (PyArrayObject*)PyArray_EMPTY(PyArray_NDIM(%(X)s), PyArray_DIMS(%(X)s), PyArray_TYPE(%(X)s), PyArray_IS_F_CONTIGUOUS(%(X)s));
if (PyArray_CopyInto(%(Y)s, %(X)s) != 0) {
PyErr_SetString(PyExc_RuntimeError, "Unable to copy input into output.");
%(fail)s
......@@ -92,7 +86,8 @@ class QuadraticOpFunc(Op):
PyErr_SetString(PyExc_RuntimeError, "Unable to compute quadratic function.");
%(fail)s
}
""" % locals()
""" % dict(name=name, coeff=sub['params'], fail=sub['fail'],
X=inputs[0], Y=outputs[0], float_type=node.inputs[0].type.c_element_type())
# Same op as above, but implemented as a COp (with C code in an external file).
......
......@@ -305,10 +305,6 @@ class Wrapper(Type):
sub = {'fail': '{this->setErrorOccurred(); return;}'}
struct_name = self.name
struct_name_defined = struct_name.upper()
struct_declare = ''
struct_init = ''
struct_cleanup = ''
struct_extract = ''
c_declare_list = []
c_init_list = []
c_cleanup_list = []
......@@ -389,7 +385,9 @@ class Wrapper(Type):
}
};
#endif
""" % locals()
""" % dict(struct_name_defined=struct_name_defined, struct_name=struct_name, struct_declare=struct_declare,
struct_init=struct_init, struct_cleanup=struct_cleanup, struct_extract=struct_extract,
struct_extract_method=struct_extract_method)
def c_code_cache_version(self):
wrapper_c_code_version = (1, 6)
......@@ -400,29 +398,24 @@ class Wrapper(Type):
# so it's better to work directly with pointers.
def c_declare(self, name, sub, check_input=True):
struct_name = self.name
return """
%(struct_name)s* %(name)s;
""" % locals()
""" % dict(struct_name=self.name, name=name)
def c_init(self, name, sub):
# NB: It seems c_init() is not called for an op param.
# So the real initialization is done at top of c_extract.
return """
%(nams)s = NULL;
""" % locals()
%(name)s = NULL;
""" % dict(name=name)
def c_cleanup(self, name, sub):
return """
delete %(name)s;
%(name)s = NULL;
""" % locals()
""" % dict(name=name)
def c_extract(self, name, sub, check_input=True):
struct_name = self.name
fail = sub['fail']
length = self.length
fields_list = '"%s"' % '", "'.join(self.fields)
return """
/* Seems c_init() is not called for a op param. So I call `new` here. */
%(name)s = new %(struct_name)s;
......@@ -446,4 +439,5 @@ class Wrapper(Type):
%(fail)s
}
}
""" % locals()
""" % dict(name=name, struct_name=self.name, length=self.length, fail=sub['fail'],
fields_list='"%s"' % '", "'.join(self.fields))
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论