提交 55179c3c authored 作者: John Salvatier's avatar John Salvatier

remove format to support python2.5

上级 ec8710a3
...@@ -20,12 +20,12 @@ def compile_cutils(): ...@@ -20,12 +20,12 @@ def compile_cutils():
complex_types = ['npy_'+t for t in ['complex32', 'complex64', 'complex128', 'complex160', 'complex192', 'complex512'] ] complex_types = ['npy_'+t for t in ['complex32', 'complex64', 'complex128', 'complex160', 'complex192', 'complex512'] ]
inplace_map_template = """ inplace_map_template = """
#if defined({typen}) #if defined(%(typen))
static void {type}_inplace_add(PyArrayMapIterObject *mit, PyArrayIterObject *it) static void %(type)_inplace_add(PyArrayMapIterObject *mit, PyArrayIterObject *it)
{{ {{
int index = mit->size; int index = mit->size;
while (index--) {{ while (index--) {{
{op} %(op)
PyArray_MapIterNext(mit); PyArray_MapIterNext(mit);
PyArray_ITER_NEXT(it); PyArray_ITER_NEXT(it);
...@@ -34,31 +34,31 @@ def compile_cutils(): ...@@ -34,31 +34,31 @@ def compile_cutils():
#endif #endif
""" """
floatadd = "(({type}*)mit->dataptr)[0] = (({type}*)mit->dataptr)[0] + (({type}*)it->dataptr)[0];" floatadd = "((%(type)*)mit->dataptr)[0] = ((%(type)*)mit->dataptr)[0] + ((%(type)*)it->dataptr)[0];"
complexadd = """ complexadd = """
(({type}*)mit->dataptr)[0].real = (({type}*)mit->dataptr)[0].real + (({type}*)it->dataptr)[0].real; ((%(type)*)mit->dataptr)[0].real = ((%(type)*)mit->dataptr)[0].real + ((%(type)*)it->dataptr)[0].real;
(({type}*)mit->dataptr)[0].imag = (({type}*)mit->dataptr)[0].imag + (({type}*)it->dataptr)[0].imag; ((%(type)*)mit->dataptr)[0].imag = ((%(type)*)mit->dataptr)[0].imag + ((%(type)*)it->dataptr)[0].imag;
""" """
fns = ''.join([inplace_map_template.format(type = t, typen = t.upper(), op = floatadd.format(type = t)) for t in types] + fns = ''.join([inplace_map_template % {'type' : t, 'typen' : t.upper(), 'op' : floatadd % {'type' : t} } for t in types] +
[inplace_map_template.format(type = t, typen = t.upper(), op = complexadd.format(type = t)) for t in complex_types]) [inplace_map_template % {'type' : t, 'typen' : t.upper(), 'op' : complexadd % {'type' : t} } for t in complex_types])
fn_array = ("inplace_map_binop addition_funcs[] = {" + fn_array = ("inplace_map_binop addition_funcs[] = {" +
''.join([""" ''.join(["""
#if defined({typen}) #if defined(%(typen))
{type}_inplace_add, %(type)_inplace_add,
#endif #endif
""".format(type = t, typen = t.upper()) for t in types+complex_types]) + """ % {'type' : t, 'typen' : t.upper()} for t in types+complex_types]) +
"""NULL}; """NULL};
""") """)
type_number_array = ("int type_numbers[] = {" + type_number_array = ("int type_numbers[] = {" +
''.join([""" ''.join(["""
#if defined({typen}) #if defined(%(typen))
{typen}, %(typen),
#endif #endif
""".format(type = t, typen = t.upper()) for t in types+complex_types]) + """ % {'type' : t, 'typen' : t.upper()} for t in types+complex_types]) +
"-1000};") "-1000};")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论