cuda_cffi/_cffi_autogen_common.py
def generate_cffi_python_wrappers(cffi_cdef,
                                  build_func_body,
                                  variable_defs_json='',
                                  func_defs_json='',
                                  python_wrapper_file=None):
    """ generate python wrappers for all functions within cffi_cdef.

    Parameters
    ----------
    cffi_cdef : str
        cffi definition string as generated by `generate_cffi_cdef`
    build_func_body : callable
        function to build a string corresponding to the body of the python
        wrapper function
    variable_defs_json : str, optional
        filename of .json file containing dictionary of variable descriptions
    func_defs_json : str, optional
        filename of .json file containing dictionary of function descriptions
    python_wrapper_file : str, optional
        file to output the generated python wrappers to

    Returns
    -------
    python_wrappers : str
        string containing all of the python wrappers

    """
    cffi_cdef_list = cffi_cdef.split('\n')

    # find lines containing a function definition
    func_def_lines = []
    for idx, line in enumerate(cffi_cdef_list):
        # this loop matches each line containing the start of a function definition
        # if ('CUSOLVERAPI' in line) or ('CUSPARSEAPI' in line):
        if (line.startswith('cusolver') or
                line.lstrip().startswith('cusparse')) and \
                ('(' in line):  # TODO: fix this!
            func_def_lines.append(idx)

    # reformat each definition into a single line for easier string processing
    n_funcs = len(func_def_lines)
    cdef_list = []
    for i in range(len(func_def_lines)):
        loc1 = func_def_lines[i]
        if i < n_funcs - 1:
            loc2 = func_def_lines[i + 1]
            cdef = ' '.join([_remove_comment(l) for l in cffi_cdef_list[loc1:loc2]])
        else:
            cdef = ' '.join([_remove_comment(l) for l in cffi_cdef_list[loc1:]])
        # strip any remaining comments after the semicolon
        cdef = cdef[:cdef.find(';') + 1]

        cdef_list.append(cdef)

    # read function and variable definition strings to use when building the
    # the Python doc strings
    if variable_defs_json:
        variable_descriptions = get_function_descriptions(variable_defs_json)
    if func_defs_json:
        func_descriptions = get_function_descriptions(func_defs_json)

    # build the wrappers
    python_wrappers = ''
    for cdef in cdef_list:

        python_wrappers += build_python_func(
            cdef,
            build_func_body,
            variable_descriptions=variable_descriptions,
            func_descriptions=func_descriptions)

    if python_wrapper_file is not None:
        with open(python_wrapper_file, 'w') as f:
            f.write(python_wrappers)
    return python_wrappers
 generate python wrappers for all functions within cffi_cdef.

    Parameters
    ----------
    cffi_cdef : str
        cffi definition string as generated by `generate_cffi_cdef`
    build_func_body : callable
        function to build a string corresponding to the body of the python
        wrapper function
    variable_defs_json : str, optional
        filename of .json file containing dictionary of variable descriptions
    func_defs_json : str, optional
        filename of .json file containing dictionary of function descriptions
    python_wrapper_file : str, optional
        file to output the generated python wrappers to

    Returns
    -------
    python_wrappers : str
        string containing all of the python wrappers

    
generate python wrappers for all functions within cffi_cdef.
Parameters



Returns

python_wrappers : str
string containing all of the python wrappers
generate python wrappers for all functions within cffi_cdef . Parameters Returns python_wrappers : str string containing all of the python wrappers
def generate_cffi_python_wrappers(cffi_cdef,
                                  build_func_body,
                                  variable_defs_json='',
                                  func_defs_json='',
                                  python_wrapper_file=None):
    cffi_cdef_list = cffi_cdef.split('\n')
    func_def_lines = []
    for idx, line in enumerate(cffi_cdef_list):
        if (line.startswith('cusolver') or
                line.lstrip().startswith('cusparse')) and \
                ('(' in line):  
            func_def_lines.append(idx)
    n_funcs = len(func_def_lines)
    cdef_list = []
    for i in range(len(func_def_lines)):
        loc1 = func_def_lines[i]
        if i < n_funcs - 1:
            loc2 = func_def_lines[i + 1]
            cdef = ' '.join([_remove_comment(l) for l in cffi_cdef_list[loc1:loc2]])
        else:
            cdef = ' '.join([_remove_comment(l) for l in cffi_cdef_list[loc1:]])
        cdef = cdef[:cdef.find(';') + 1]
        cdef_list.append(cdef)
    if variable_defs_json:
        variable_descriptions = get_function_descriptions(variable_defs_json)
    if func_defs_json:
        func_descriptions = get_function_descriptions(func_defs_json)
    python_wrappers = ''
    for cdef in cdef_list:
        python_wrappers += build_python_func(
            cdef,
            build_func_body,
            variable_descriptions=variable_descriptions,
            func_descriptions=func_descriptions)
    if python_wrapper_file is not None:
        with open(python_wrapper_file, 'w') as f:
            f.write(python_wrappers)
    return python_wrappers
def generate_cffi_python_wrappers ( cffi_cdef , build_func_body , variable_defs_json = '' , func_defs_json = '' , python_wrapper_file = None ) : cffi_cdef_list = cffi_cdef . split ( '\n' ) func_def_lines = [ ] for idx , line in enumerate ( cffi_cdef_list ) : if ( line . startswith ( 'cusolver' ) or line . lstrip ( ) . startswith ( 'cusparse' ) ) and ( '(' in line ) : func_def_lines . append ( idx ) n_funcs = len ( func_def_lines ) cdef_list = [ ] for i in range ( len ( func_def_lines ) ) : loc1 = func_def_lines [ i ] if i < n_funcs - 1 : loc2 = func_def_lines [ i + 1 ] cdef = ' ' . join ( [ _remove_comment ( l ) for l in cffi_cdef_list [ loc1 : loc2 ] ] ) else : cdef = ' ' . join ( [ _remove_comment ( l ) for l in cffi_cdef_list [ loc1 : ] ] ) cdef = cdef [ : cdef . find ( ';' ) + 1 ] cdef_list . append ( cdef ) if variable_defs_json : variable_descriptions = get_function_descriptions ( variable_defs_json ) if func_defs_json : func_descriptions = get_function_descriptions ( func_defs_json ) python_wrappers = '' for cdef in cdef_list : python_wrappers += build_python_func ( cdef , build_func_body , variable_descriptions = variable_descriptions , func_descriptions = func_descriptions ) if python_wrapper_file is not None : with open ( python_wrapper_file , 'w' ) as f : f . write ( python_wrappers ) return python_wrappers
generate python wrappers for all functions within cffi_cdef.
generate python wrappers for all functions within cffi_cdef .
""" generate python wrappers for all functions within cffi_cdef.

    Parameters
    ----------
    cffi_cdef : str
        cffi definition string as generated by `generate_cffi_cdef`
    build_func_body : callable
        function to build a string corresponding to the body of the python
        wrapper function
    variable_defs_json : str, optional
        filename of .json file containing dictionary of variable descriptions
    func_defs_json : str, optional
        filename of .json file containing dictionary of function descriptions
    python_wrapper_file : str, optional
        file to output the generated python wrappers to

    Returns
    -------
    python_wrappers : str
        string containing all of the python wrappers

    """ # find lines containing a function definition # this loop matches each line containing the start of a function definition # if ('CUSOLVERAPI' in line) or ('CUSPARSEAPI' in line): # TODO: fix this! # reformat each definition into a single line for easier string processing # strip any remaining comments after the semicolon # read function and variable definition strings to use when building the # the Python doc strings # build the wrappers
cffi_cdef
build_func_body
variable_defs_json
func_defs_json
python_wrapper_file