'Write a Cython file with python wrappers
This file contains all the definitions of the routines in c code and
refers to the header file.
Arguments
routines
List of Routine instances
f
File-like object to write the file to
prefix
The filename prefix, used to refer to the proper header file.
Only the basename of the prefix is used.'

def dump_pyx(self, routines, f, prefix):

    headers = []
    functions = []
    for routine in routines:
        prototype = self.generator.get_prototype(routine)
        headers.append(self.pyx_header.format(header_file=prefix, prototype=prototype))
        (py_rets, py_args, py_loc, py_inf) = self._partition_args(routine.arguments)
        name = routine.name
        arg_string = ',    '.join((self._prototype_arg(arg) for arg in py_args))
        local_decs = []
        for (arg, val) in py_inf.items():
            proto = self._prototype_arg(arg)
            (mat, ind) = val
            local_decs.append('                cdef    {0}    =    {1}.shape[{2}]'.format(proto, mat, ind))
        local_decs.extend(['                cdef    {0}'.format(self._declare_arg(a)) for a in py_loc])
        declarations = '\n'.join(local_decs)
        if declarations:
            declarations = (declarations + '\n')
        args_c = ',    '.join([self._call_arg(a) for a in routine.arguments])
        rets = ',    '.join([str(r.name) for r in py_rets])
        if routine.results:
            body = ('                return    %s(%s)' % (routine.name, args_c))
            if rets:
                body = ((body + ',    ') + rets)
        else:
            body = ('                %s(%s)\n' % (routine.name, args_c))
            body = ((body + '                return    ') + rets)
        functions.append(self.pyx_func.format(name=name, arg_string=arg_string, declarations=declarations, body=body))
    if self._need_numpy:
        f.write(self.pyx_imports)
    f.write('\n'.join(headers))
    f.write('\n'.join(functions))
