On Wed, 11 Dec 2002, Andrea Riciputi wrote:
> Hi there,
> I'm playing with Numeric and even if I've not so much experience with
> it I'm trying to write a C extention to Python that can use Numeric
> arrays. The basic idea consists in handling C (dynamically allocated)
> array as Numeric array (if Numeric is installed) or as simple Python
> lists if not.
>
> How can I detect at compile time if Numeric is installed or not?? I've
> thought something like:
>
> #ifdef NUMERIC_IS_HERE
> #include "Numeric/arrayobject.h"
> #endif
>
> But I've not found any hints in Numeric manual. Can anyone suggest a
> solution to me?
If you are using distutils for building extension modules then you can
test if Numeric is available in setup.py file and define, say, HAVE_NUMPY
macro, if Numeric is available. For example,
#-------
have_numpy = 0
try:
import Numeric
have_numpy = 1
except ImportError:
pass
define_macros = []
if have_numpy:
define_macros.append(('HAVE_NUMPY', None))
if __name__ == "__main__":
from distutils.core import setup
setup(name = ...,
ext_modules = [...],
define_macros = define_macros
)
#---------
and in extension source files use
#ifdef HAVE_NUMPY
...
#endif
HTH,
Pearu
|