Max Mayzel wrote:
> Dag Sverre Seljebotn <da...@...> writes:
>
>
>> Max wrote:
>>
>>> Hi,
>>> I'm trying to run testlapack example from cython-notur09 on OS X 10.6.
>>> First, while compiling I faced with following error
>>> gcc -L/sw64/lib -bundle -L/sw64/lib/python2.6/config -lpython2.6
>>> build/temp.macosx-10.4-i386-2.6/lapack.o
>>> -L/Applications/development/sage//local/lib -llapack -lf77blas -lcblas
>>> -latlas -o lapack.so -g
>>> Undefined symbols:
>>> "_clapack_dgesv", referenced from:
>>> _dgesv in lapack.o
>>> _dsolve in lapack.o
>>> ld: symbol(s) not found
>>> So I changed clapack_dgesw in lapack.pxd to dgesw and successfully
>>> build it against SAGE (sage-4.2.1-OSX10.6-Intel-64bit-i386-Darwin.dmg)
>>> but when I run testlapack.test() python froze, using 100% of CPU,
>>> below is debuging info.
>>>
>>>
>>>>>> tl.test()
>>>>>>
>>> test start
>>> ^C
>>> Program received signal SIGINT, Interrupt.
>>> 0x00000001005280a4 in dgesv (__pyx_v_Order=CblasRowMajor, __pyx_v_N=3,
>>> __pyx_v_NRHS=1, __pyx_v_A=0x7fff5fbfdda0, __pyx_v_lda=3,
>>> __pyx_v_ipiv=0x7fff5fbfde10, __pyx_v_B=0x7fff5fbfddf0, __pyx_v_ldb=3)
>>> at lapack.c:775
>>> 775 static int dgesv(enum CBLAS_ORDER __pyx_v_Order, int __pyx_v_N,
>>> int __pyx_v_NRHS, double *__pyx_v_A, int __pyx_v_lda, int
>>> *__pyx_v_ipiv, double *__pyx_v_B, int __pyx_v_ldb) {
>>> (gdb) exit
>>>
>>> I was also tried to build it against Mac OS X accelerated framework
>>> and the result is the same, while on linux this example works fine.
>>> Any suggestions what's wrong?
>>>
>
> Dag, here are clapack.h on linux
> int clapack_dgesv(const enum CBLAS_ORDER Order, const int N, const int NRHS,
> double *A, const int lda, int *ipiv,
> double *B, const int ldb);
>
> and on Mac accelerated framework
>
> /* Subroutine */ int dgesv_(__CLPK_integer *n, __CLPK_integer *nrhs,
> __CLPK_doublereal *a, __CLPK_integer
> *lda, __CLPK_integer *ipiv, __CLPK_doublereal *b, __CLPK_integer *ldb,
> __CLPK_integer *info);
>
> Max
>
OK, that explains it -- they're different APIs. What clapack.h on Mac
apparently contains is a direct interface to the FORTRAN lapack. You
need to declare the function above to Cython (note that the signature is
very different, taking pointers to integers etc.), and write a wrapper
in Cython which
a) Passes e.g. "&n" rather than "n", &nrhs rather than nrhs and so on
(and make sure n and nrhs and so on all have the type __CLPK_integer).
b) The data (__CLPK_doublereal*s) should be passed like this:
def dgesv(..., a, b):
cdef np.ndarray[double, ndim=2, mode='fortan'] a_work =
np.asfortranarray(a)
cdef np.ndarray[double, ndim=2, mode='fortan'] b_work =
np.asfortranarray(b)
errcode = dgesv_(...., <__CLPK_doublereal*>a_work.data,
<...>b_work.data,. ..)
...
if b_work is not b:
b[...] = b_work # verbatim "..."! Copies back data if contiguous
copy had to be made
This overwrites b with the solution, which is perhaps not what you want,
but makes for a raw wrapper. Otherwise:
... b_work = b.copy('F')
return b_work # or some slice of it...don't remember LAPACK here
Dag Sverre
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev