Hi all,

I'm trying to simply call a C-LAPACK function (in this case, matrix multiplication) from Cython. I don't want to dynamically link to an existing C-LAPACK installation, so I've packaged the necessary headers/*.c files for that function with my code. I compile it using setup.py and then try to call it from a Cython (*.pyx) file.

I made a self-contained example here:

https://github.com/yarden/learn_cython

The README.txt explains how to compile and "run.py" is the test script. The key code from that example is below. I basically include the *.c / *.h files in the src/ and include/ directories and then define the external function as:

cdef extern from "f2c.h":

ctypedef int integer

ctypedef double doublereal

# Import lapack functions.

cdef extern from "clapack.h":

cdef extern from "f2c.h":

pass

integer c_dgemm "dgemm_"(char *transa, char *transb, integer *m, integer *

n, integer *k, doublereal *alpha, doublereal *a, integer *lda,

doublereal *b, integer *ldb, doublereal *beta, doublereal *c__,

integer *ldc)

I then call the function as follows:

cdef int main():

# Form of matrix

cdef char transa_val = 'N'

cdef char *transa = &transa_val

cdef char transb_val = 'N'

cdef char *transb = &transb_val

# Number of rows of matrix A

cdef int m = 3

cdef int n = 3

cdef int k = 3

cdef double alpha = 1.0

cdef np.ndarray[double, ndim=2, mode="c"] a = \

np.array([[1, 2, 3],

[4, 5, 6],

[7, 8, 9]], dtype=float)

cdef np.ndarray[double, ndim=2, mode="c"] b = \

np.array([[1, 0, 0],

[0, 0, 0],

[1, 1, 1]], dtype=float)

# result is a double pointer

cdef np.ndarray[double, ndim=2, mode="c"] c = \

np.empty([3, 3], dtype=float)

cdef int lda = m

cdef int ldb = n

cdef double beta = 1.0

cdef int ldc = 1

print "Multipling: "

print a

print " times "

print b

c_dgemm(transa, transb, &m, &n, &k, &alpha, &a[0,0], &lda, &b[0,0], &ldb, &beta, &c[0,0], &ldc)

return 0

main()

Then I compile and run this as follows:

$ python setup.py sdist

$ python setup.py build_ext

$ python run.py

This always yields the error:

ImportError: undefined symbol: dgemm_

Even though though the function body and header is included. What did I do wrong here?

Thanks very much in advance for your help.

--

---

You received this message because you are subscribed to the Google Groups "cython-users" group.

To unsubscribe from this group and stop receiving emails from it, send an email to cython-users+unsubscribe <at> googlegroups.com.

For more options, visit

https://groups.google.com/groups/opt_out.