[SciPy-dev] Extensions linking to libraries used by numpy/scipy

Tom Loredo loredo at astro.cornell.edu
Mon Mar 6 23:55:35 CST 2006

Robert, thanks for the interesting suggestions!

Robert Kern wrote:

> Also, I remember asking Pearu to expose the raw function pointer in the fortran
> object wrapper. The idea was to be able to allow f2py callback functions to be
> f2py'ed subroutines themselves, and have everything go really, really fast.
> In [6]: linalg.flapack.dgetrf._cpointer
> Out[6]: <PyCObject object at 0xd650>
> I believe this actually gives you the function pointer to DGETRF_. 

Alas, this is what I see on OS X (10.3.9):

In [9]: from scipy import linalg
In [10]: linalg.flapack.dgetrf._cpointer
AttributeError: 'module' object has no attribute 'flapack'

In [11]: linalg.lapack.dgetrf._cpointer
AttributeError: 'module' object has no attribute 'lapack'

In [12]: linalg.clapack.dgetrf._cpointer
AttributeError: 'module' object has no attribute 'clapack'                      

This is presumably related to whatever is behind the scipy.test()
warnings about missing blas/lapack on OS X that I and others have reported
here, presumably reflecting the use of Apple veclib stuff.  Any
ideas on a portable way to try this?

> Or you could
> just accept the fortran object itself, and access the function pointer from the
> PyFortranObject structure itself.
> Ah, now I've rambled myself to the right answer. Don't pay attention to anything
> but the last sentence of the previous paragraph. AFAICT, this is a new approach,
> so you can be our guinea pig.

I don't know how to pursue this.  I'll have to dig more into
the f2py docs to understand it.

And since I have the attention of the person behind random/mtrand 8-), 
I am also wrapping some RNGs in Fortran (e.g., multivariate t), and 
wondering if there is a way to have them call Numpy's "rand" (or 
standard_normal, etc.).  I thought perhaps I could try your trick, but:

In [13]: random.rand
Out[13]: <built-in method rand of mtrand.RandomState object at 0x3e110>
In [14]: random.rand._cpointer
AttributeError: 'builtin_function_or_method' object has no attribute '_cpointer'

I presume this is because mtrand is not built with f2py.  Right
now I'm just sending my Fortran RNGs arrays of input rands from
Python, rather than having them call a uniform or normal RNG
directly.  Fortunately what I'm working on now requires a
deterministic # of input randoms.  I'm not sure what I could
do in other cases without going through the overhead of a Python callback.
But this should work for now.


This mail sent through IMP: http://horde.org/imp/

More information about the Scipy-dev mailing list