コード例 #1
0
def generate_api(output_dir, force=False):
    basename = 'multiarray_api'

    h_file = os.path.join(output_dir, '__%s.h' % basename)
    c_file = os.path.join(output_dir, '__%s.c' % basename)
    d_file = os.path.join(output_dir, '%s.txt' % basename)
    targets = (h_file, c_file, d_file)
    sources = ['numpy_api_order.txt']

    if (not force and not genapi.should_rebuild(targets, sources + [__file__])):
        return targets
    else:
        do_generate_api(targets, sources)

    return targets
コード例 #2
0
def generate_api(output_dir, force=False):
    basename = 'multiarray_api'

    h_file = os.path.join(output_dir, '__%s.h' % basename)
    c_file = os.path.join(output_dir, '__%s.c' % basename)
    d_file = os.path.join(output_dir, '%s.txt' % basename)
    targets = (h_file, c_file, d_file)
    sources = ['numpy_api_order.txt']

    if (not force and not genapi.should_rebuild(targets, sources + [__file__])):
        return targets
    else:
        do_generate_api(targets, sources)

    return targets
コード例 #3
0
ファイル: generate_numpy_api.py プロジェクト: Squarecap/numpy
def generate_api(output_dir, force=False):
    basename = "multiarray_api"

    h_file = os.path.join(output_dir, "__%s.h" % basename)
    c_file = os.path.join(output_dir, "__%s.c" % basename)
    d_file = os.path.join(output_dir, "%s.txt" % basename)
    targets = (h_file, c_file, d_file)

    sources = numpy_api.multiarray_api

    if not force and not genapi.should_rebuild(targets, [numpy_api.__file__, __file__]):
        return targets
    else:
        do_generate_api(targets, sources)

    return targets
コード例 #4
0
def generate_api(output_dir, force=False):
    basename = "ufunc_api"

    h_file = os.path.join(output_dir, "__%s.h" % basename)
    c_file = os.path.join(output_dir, "__%s.c" % basename)
    d_file = os.path.join(output_dir, "%s.txt" % basename)
    targets = (h_file, c_file, d_file)

    sources = ["ufunc_api_order.txt"]

    if not force and not genapi.should_rebuild(targets, sources + [__file__]):
        return targets
    else:
        do_generate_api(targets, sources)

    return targets
コード例 #5
0
def generate_api(output_dir, force=False):
    basename = "multiarray_api"

    h_file = os.path.join(output_dir, "__%s.h" % basename)
    c_file = os.path.join(output_dir, "__%s.c" % basename)
    d_file = os.path.join(output_dir, "%s.txt" % basename)
    targets = (h_file, c_file, d_file)

    sources = numpy_api.multiarray_api

    if not force and not genapi.should_rebuild(targets,
                                               [numpy_api.__file__, __file__]):
        return targets
    else:
        do_generate_api(targets, sources)

    return targets
コード例 #6
0
def generate_api(output_dir, force=False):
    header_file = os.path.join(output_dir, "__multiarray_api.h")
    c_file = os.path.join(output_dir, "__multiarray_api.c")
    doc_file = os.path.join(output_dir, "multiarray_api.txt")

    targets = (header_file, c_file, doc_file)
    if not force and not genapi.should_rebuild(targets, [OBJECT_API_ORDER, MULTIARRAY_API_ORDER, __file__]):
        return targets

    objectapi_list = genapi.get_api_functions("OBJECT_API", OBJECT_API_ORDER)
    multiapi_list = genapi.get_api_functions("MULTIARRAY_API", MULTIARRAY_API_ORDER)
    # API fixes for __arrayobject_api.h

    fixed = 10
    numtypes = len(types) + fixed
    numobject = len(objectapi_list) + numtypes
    nummulti = len(multiapi_list)
    numtotal = numobject + nummulti

    module_list = []
    extension_list = []
    init_list = []

    # setup types
    for k, atype in enumerate(types):
        num = fixed + k
        astr = "        (void *) &Py%sArrType_Type," % types[k]
        init_list.append(astr)
        astr = "static PyTypeObject Py%sArrType_Type;" % types[k]
        module_list.append(astr)
        astr = "#define Py%sArrType_Type (*(PyTypeObject *)PyArray_API[%d])" % (types[k], num)
        extension_list.append(astr)

    # set up object API
    genapi.add_api_list(numtypes, "PyArray_API", objectapi_list, module_list, extension_list, init_list)

    # set up multiarray module API
    genapi.add_api_list(numobject, "PyArray_API", multiapi_list, module_list, extension_list, init_list)

    # Write to header
    fid = open(header_file, "w")
    s = h_template % ("\n".join(module_list), "\n".join(extension_list))
    fid.write(s)
    fid.close()

    # Write to c-code
    fid = open(c_file, "w")
    s = c_template % "\n".join(init_list)
    fid.write(s)
    fid.close()

    # write to documentation
    fid = open(doc_file, "w")
    fid.write(
        """
===========
Numpy C-API
===========

Object API
==========
"""
    )
    for func in objectapi_list:
        fid.write(func.to_ReST())
        fid.write("\n\n")
    fid.write(
        """

Multiarray API
==============
"""
    )
    for func in multiapi_list:
        fid.write(func.to_ReST())
        fid.write("\n\n")
    fid.close()

    return targets
コード例 #7
0
def generate_api(output_dir, force=False):
    header_file = os.path.join(output_dir, '__multiarray_api.h')
    c_file = os.path.join(output_dir,'__multiarray_api.c')
    doc_file = os.path.join(output_dir, 'multiarray_api.txt')

    targets = (header_file, c_file, doc_file)
    if (not force
            and not genapi.should_rebuild(targets,
                                          [OBJECT_API_ORDER,
                                           MULTIARRAY_API_ORDER,
                                           __file__])):
        return targets

    objectapi_list = genapi.get_api_functions('OBJECT_API',
                                              OBJECT_API_ORDER)
    multiapi_list = genapi.get_api_functions('MULTIARRAY_API',
                                             MULTIARRAY_API_ORDER)
    # API fixes for __arrayobject_api.h

    fixed = 10
    numtypes = len(types) + fixed
    numobject = len(objectapi_list) + numtypes
    nummulti = len(multiapi_list)
    numtotal = numobject + nummulti

    module_list = []
    extension_list = []
    init_list = []

    # setup types
    for k, atype in enumerate(types):
        num = fixed + k
        astr = "        (void *) &Py%sArrType_Type," % types[k]
        init_list.append(astr)
        astr = "static PyTypeObject Py%sArrType_Type;" % types[k]
        module_list.append(astr)
        astr = "#define Py%sArrType_Type (*(PyTypeObject *)PyArray_API[%d])" % \
               (types[k], num)
        extension_list.append(astr)

    # set up object API
    genapi.add_api_list(numtypes, 'PyArray_API', objectapi_list,
                        module_list, extension_list, init_list)

    # set up multiarray module API
    genapi.add_api_list(numobject, 'PyArray_API', multiapi_list,
                        module_list, extension_list, init_list)


    # Write to header
    fid = open(header_file, 'w')
    s = h_template % ('\n'.join(module_list), '\n'.join(extension_list))
    fid.write(s)
    fid.close()

    # Write to c-code
    fid = open(c_file, 'w')
    s = c_template % '\n'.join(init_list)
    fid.write(s)
    fid.close()

    # write to documentation
    fid = open(doc_file, 'w')
    fid.write('''
===========
Numpy C-API
===========

Object API
==========
''')
    for func in objectapi_list:
        fid.write(func.to_ReST())
        fid.write('\n\n')
    fid.write('''

Multiarray API
==============
''')
    for func in multiapi_list:
        fid.write(func.to_ReST())
        fid.write('\n\n')
    fid.close()

    return targets