On 1/10/07, David M. Cooke <[EMAIL PROTECTED]> wrote:

On Jan 7, 2007, at 00:16 , Charles R Harris wrote:
>
> That brings up the main question I have about how to break up the C
> files. I note that most of the functions in multiarraymodule.c, for
> instance, are part of the C-API, and are tagged as belonging to
> either the MULTIARRAY_API or the OBJECT_API. Apparently the build
> system scans for these tags and extracts the files somewhere. So,
> what is this API, is it available somewhere or is the code just
> copied somewhere convenient. As to breaking up the files, the scan
> only covers the code in the two current files, included code from
> broken out parts is not seen. This strikes me as a bit of a kludge,
> but I am sure there is a reason for it. Anyway, I assume the build
> system can be fixed, so that brings up the question of how to break
> up the files. The maximal strategy is to make every API functions,
> with it's helper functions, a separate file. This adds a *lot* of
> files, but it is straight forward and modular. A less drastic
> approach is to start by breaking multiarraymodule into four files:
> the converters, the two apis, and the module functions. My own
> preference is for the bunch of files, but I suspect some will object.

The code for pulling out the ``MULTIARRAY_API`` and ``OBJECT_API``
(also ``UFUNC_API``) is in ``numpy/core/code_generators``. Taking
``MULTIARRAY_API`` as an example, the ``generate_array_api.py`` is
run by the ``numpy/core/setup.py`` file to generate the multiarray
(and object) API. The file ``numpy/core/code_generators/
array_api_order.txt`` is the order in which the API functions are
added to the  ``PyArray_API`` array; this is our guarantee that the
binary API doesn't change when functions are added. The files scanned
are listed ``in numpy/core/code_generators/genapi.py``, which is also
the module that does the heavy lifting in extracting the tagged
functions.


Looked to me like the order could change without causing problems. The
include file was also written by the code generator and for extension
modules was just a bunch of macros assigning the proper function pointer to
the correct name. That brings up another bit, however. At some point I would
like to break the include file into two parts, one for inclusion in the
other numpy modules and another for inclusion in extension modules, the big
#ifdef in the current file offends my sense of esthetics. It should also be
possible to attach the function pointers to real function prototype like
declarations, which would help extension modules check the code at compile
time.

The parameters and a leading comment for tagged functions are
extracted from the API source files; code is generated that sets
``PyArray_API`` up correctly (this is put into ``__multiarray.c`` in
the build ``src/`` directory), and a header file is created
(``__multiarray.h`` in the build ``include/`` directory) that
contains the ``#define's`` for calling the API functions as function
pointers into ``PyArray_API``. Also, a file ``multiarray_api.txt`` is
created that contains the leading comments for the tagged functions,
along with the function signatures, in reStructuredText format.

As to how to break up the files, I would prefer the four files
approach. I find that a bunch of files (one for each function) to be
difficult to work with, as I'm continually opening different files to
find functions. It's also to me taking modularity to the extreme,
where your first level of division into chunks (functions) are now
the same size as your second level (files).


Chuck
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to