Was that really only 5 functions? (Hope the rest of it is not this slow...)


Began work on creating wrappers for ctypes that work approximately the same as the ones planned for the 3.0 release (though written in Python, rather than C). Basically each function that needs array processing gets a number of annotations with callable objects. Those callable objects will eventually be written in C (for the performance critical ones), as will a wrapper that runs the various callables to do the conversions.

So far there are 6 "hooks" for the callable objects:

  • Convert the Python arguments 1-by-1 to internal formats (Numpy arrays, mostly)
  • Create internal-format values for each C argument from the array of Python arguments (this is where arrays get broken into multiple arguments for C, for instance)
  • Convert internal-format C arguments into ctypes-friendly formts (the only case this is necessary so far is for Numpy arrays)
  • Check for error conditions
  • Store internal-format values (mostly for keeping, e.g. pointers live after setting)
  • Return appropriate value (e.g. choosing an output parameter, or returning an scalar rather than an array when only a single value is returned)

The APIs for the individual hooks aren't particularly elegant yet, but that will change as I get more of the complex parts of the API wrapped and figure out what isn't actually necessary. So far they seem a little... overdone :) , most of the callables I've defined so far are trivial little things. In the SWIG wrapper they are expanded to a single line of C code in most cases (it's just that figuring out how that happens through the dozens of layers of macros is a bit involved ;) ).

Comments

Comments are closed.

Pingbacks

Pingbacks are closed.