How do I define in Cython an external C ++ function that has input parameters as enumerations? MKL
So while trying to wrap this in Cython from MKL and dig into mkl_cblas.h
, I can see that these are enums:
typedef enum {CblasRowMajor=101, CblasColMajor=102} CBLAS_ORDER;
typedef enum {CblasNoTrans=111, CblasTrans=112, CblasConjTrans=113} CBLAS_TRANSPOSE;
And here is the function declaration:
void cblas_dgemm(const CBLAS_LAYOUT Layout, const CBLAS_TRANSPOSE TransA,
const CBLAS_TRANSPOSE TransB, const MKL_INT M, const MKL_INT N,
const MKL_INT K, const double alpha, const double *A,
const MKL_INT lda, const double *B, const MKL_INT ldb,
const double beta, double *C, const MKL_INT ldc);
Cython documentation is missing in this area as it seems like it suggests converting everything to int
, but then the MKL function complains that I didn't pass it the correct type ( enums
CBLAS_LAYOUT
and CBLAS_TRANSPOSE
not a type int
).
What is the correct way to identify them from Keaton? I.e:.
cimport cython
cdef extern from "mkl.h" nogil:
ctypedef enum CBLAS_LAYOUT:
CblasRowMajor
CblasColMajor
ctypedef enum CBLAS_TRANSPOSE:
CblasNoTrans
CblasTrans
CblasConjTrans
void dgemm "cblas_dgemm"(CBLAS_LAYOUT Layout,
CBLAS_TRANSPOSE TransA,
CBLAS_TRANSPOSE TransB,
int M,
int N,
int K,
double alpha,
double *A,
int lda,
double *B,
int ldb,
double beta,
double *C,
int ldc
)
The above compiles without error. But I got no results in C
(until I changed it to CblasColMajor
by calling dgemm
after I posted this). So I wonder if anyone can confirm if this is correct above.
I profiled above and SciPy
inline version Using the cython_blas Scipy interface from Cython not working on Mx1 1xN vectors and they are about the same (mine SciPy
is related to MKL) so I guess this is correct, but if there is a better / quicker way to do this please , post offers. However, I'll leave this posted for others as it doesn't look well documented in Cython.
source to share
No one has answered this question yet
See similar questions:
or similar: