Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Numpy distutils howto

I spent almost an hour googling for the solution, but the documentation for numpy.distutils is very sparse.

I have a f2py-wrapped module. It consists basically of 3 files:

a.f90
a.pyf
lib.a <- this is a static library that contains most of the computational code

The module is well compiled with the following shell-script command.

f2py --build-dir temp -c a.pyf a.f90 lib.a --fcompiler=gnu95   
--fcompiler-flags="Zillions of compiler options"

As a result, I have the python module a.so (the name is specified in the .pyf file).

How do I do that with numpy.distutils (or some other python-oriented building tools)? A less important question is, can I also include the dependence from lib.a (and rebuild it when necessary?)

like image 834
Ivan Oseledets Avatar asked Aug 24 '12 20:08

Ivan Oseledets


1 Answers

So, it is not 1 hour of Googling, it took 2 days of Googling, but finally I found the way to do that. Hope, it will be helpful to someone.

  def configuration(parent_package='',top_path=None):
      from numpy.distutils.misc_util import Configuration, get_info
      config = Configuration('a', parent_package, top_path)
      lib = ['./libdir/lib.a']
      src = ['a.f90','a.pyf']
      inc_dir = ['libdir']              
      config.add_extension('mya',sources=src,depends=lib_tt,
                      include_dirs=inc_dir,extra_objects="lib.a")
      #The main trick was to use extra_objects keyword
      return config

  if __name__ == '__main__':
      from numpy.distutils.core import setup
      setup(**configuration(top_path='').todict())
like image 175
Ivan Oseledets Avatar answered Sep 20 '22 16:09

Ivan Oseledets