[PYTHON MATRIX-SIG] C API questions

Konrad Hinsen hinsen@ibs.ibs.fr
Wed, 6 Nov 96 17:40:15 +0100


> Unfortunately, if the user has taken a slice of the array (or indexed into
> it if it's more than 1d) they can have an array with a pointer to the data
> in your original array and there's no way for you to know this (except of
> course for the original array's reference count).

It doesn't help me much to know it, I have to be able to prevent it...

> This does appear to be a bit of a problem.  I never imagined people would
> want to call a NumPy function from generic, non-python-aware C.  Could you
> explain a little bit more the reasoning behind this design?  At first

The application is force field evaluation for molecular systems. There
are a set of "force fields", which are essentially subroutines that
take a list of points as input and return a single value. So far no
problem, but optionally they also add something to selected elements
of one or two arrays passed to them (energy gradients and force
constant matrices).

There will eventually be many of these subroutines, who may even call
one another. And they might be written in Python, C, or Fortran.
So what I need is a unified interface (or rather two, one in Python
and one in C) that makes it possible to call any of these subroutines
without knowing more than its address.

The easiest solution would be to pass around array objects; the C
functions could easily extract the data from them. But I also want the
C interface to be usable from Fortran, and there's the problem.
The only data structure known to Fortran is an array, so I *have*
to pass C-style arrays in my generic interface. And that causes
all the trouble for a force field implemented in Python.

Konrad.
-- 
-------------------------------------------------------------------------------
Konrad Hinsen                          | E-Mail: hinsen@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire   | Tel.: +33-76.88.99.28
Institut de Biologie Structurale       | Fax:  +33-76.88.54.94
41, av. des Martyrs                    | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France         | Nederlands/Francais
-------------------------------------------------------------------------------

=================
MATRIX-SIG  - SIG on Matrix Math for Python

send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
=================