diff options
author | Pauli Virtanen <pav@iki.fi> | 2019-12-07 14:40:48 +0200 |
---|---|---|
committer | Pauli Virtanen <pav@iki.fi> | 2019-12-14 14:14:37 +0200 |
commit | 669cd13c692cfe8476e24dad3d42bbbd94547727 (patch) | |
tree | c16e68e20ff92c8389c446c4e96eb6d39e8a164e | |
parent | a92039db1edf9d85059ddadc10134f434ae82ce7 (diff) | |
download | numpy-669cd13c692cfe8476e24dad3d42bbbd94547727.tar.gz |
ENH: update BLAS symbol suffix/prefix handling in cblasfuncs & linalg
Revise the BLAS name mangling to support the general scheme.
-rw-r--r-- | numpy/core/src/common/cblasfuncs.c | 10 | ||||
-rw-r--r-- | numpy/core/src/common/npy_cblas.h | 30 | ||||
-rw-r--r-- | numpy/core/src/common/npy_cblas64_.h | 31 | ||||
-rw-r--r-- | numpy/core/src/common/python_xerbla.c | 19 | ||||
-rw-r--r-- | numpy/linalg/lapack_lite/python_xerbla.c | 13 | ||||
-rw-r--r-- | numpy/linalg/lapack_litemodule.c | 27 | ||||
-rw-r--r-- | numpy/linalg/umath_linalg.c.src | 20 | ||||
-rw-r--r-- | numpy/testing/_private/utils.py | 2 |
8 files changed, 45 insertions, 107 deletions
diff --git a/numpy/core/src/common/cblasfuncs.c b/numpy/core/src/common/cblasfuncs.c index 14d13a6c7..e78587de0 100644 --- a/numpy/core/src/common/cblasfuncs.c +++ b/numpy/core/src/common/cblasfuncs.c @@ -10,20 +10,10 @@ #include <assert.h> #include <numpy/arrayobject.h> #include "npy_cblas.h" -#include "npy_cblas64_.h" #include "arraytypes.h" #include "common.h" -/* - * If 64-bit CBLAS with symbol suffix '64_' is available, use it. - */ -#ifdef HAVE_CBLAS64_ -#define CBLAS_FUNC(name) name ## 64_ -#else -#define CBLAS_FUNC(name) name -#endif - static const double oneD[2] = {1.0, 0.0}, zeroD[2] = {0.0, 0.0}; static const float oneF[2] = {1.0, 0.0}, zeroF[2] = {0.0, 0.0}; diff --git a/numpy/core/src/common/npy_cblas.h b/numpy/core/src/common/npy_cblas.h index 12db55bde..97308238a 100644 --- a/numpy/core/src/common/npy_cblas.h +++ b/numpy/core/src/common/npy_cblas.h @@ -25,8 +25,34 @@ enum CBLAS_SIDE {CblasLeft=141, CblasRight=142}; #define CBLAS_INDEX size_t /* this may vary between platforms */ -#define BLASINT int -#define BLASNAME(name) name +#ifdef NO_APPEND_FORTRAN +#define BLAS_FORTRAN_SUFFIX +#else +#define BLAS_FORTRAN_SUFFIX _ +#endif + +#ifndef BLAS_SYMBOL_PREFIX +#define BLAS_SYMBOL_PREFIX +#endif + +#ifndef BLAS_SYMBOL_SUFFIX +#define BLAS_SYMBOL_SUFFIX +#endif + +#define BLAS_FUNC_CONCAT(name,prefix,suffix,suffix2) prefix ## name ## suffix ## suffix2 +#define BLAS_FUNC_EXPAND(name,prefix,suffix,suffix2) BLAS_FUNC_CONCAT(name,prefix,suffix,suffix2) + +#define CBLAS_FUNC(name) BLAS_FUNC_EXPAND(name,BLAS_SYMBOL_PREFIX,,BLAS_SYMBOL_SUFFIX) +#define BLAS_FUNC(name) BLAS_FUNC_EXPAND(name,BLAS_SYMBOL_PREFIX,BLAS_FORTRAN_SUFFIX,BLAS_SYMBOL_SUFFIX) + +#ifdef HAVE_BLAS_ILP64 +#define CBLAS_INT npy_int64 +#else +#define CBLAS_INT int +#endif + +#define BLASNAME(name) CBLAS_FUNC(name) +#define BLASINT CBLAS_INT #include "npy_cblas_base.h" diff --git a/numpy/core/src/common/npy_cblas64_.h b/numpy/core/src/common/npy_cblas64_.h deleted file mode 100644 index bbc4b3559..000000000 --- a/numpy/core/src/common/npy_cblas64_.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * This header provides numpy a consistent interface to CBLAS code. It is needed - * because not all providers of cblas provide cblas.h. For instance, MKL provides - * mkl_cblas.h and also typedefs the CBLAS_XXX enums. - */ -#ifndef _NPY_CBLAS64__H_ -#define _NPY_CBLAS64__H_ - -#include <stddef.h> - -#include "npy_cblas.h" - -/* Allow the use in C++ code. */ -#ifdef __cplusplus -extern "C" -{ -#endif - -#define BLASINT npy_int64 -#define BLASNAME(name) name##64_ - -#include "npy_cblas_base.h" - -#undef BLASINT -#undef BLASNAME - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/numpy/core/src/common/python_xerbla.c b/numpy/core/src/common/python_xerbla.c index d88562b7a..fe2f718b2 100644 --- a/numpy/core/src/common/python_xerbla.c +++ b/numpy/core/src/common/python_xerbla.c @@ -1,11 +1,6 @@ #include "Python.h" #include "numpy/npy_common.h" - -/* - * From f2c.h, this should be safe unless fortran is set to use 64 - * bit integers. We don't seem to have any good way to detect that. - */ -typedef int integer; +#include "npy_cblas.h" /* From the original manpage: @@ -24,7 +19,7 @@ typedef int integer; info: Number of the invalid parameter. */ -int xerbla_(char *srname, integer *info) +CBLAS_INT BLAS_FUNC(xerbla)(char *srname, CBLAS_INT *info) { static const char format[] = "On entry to %.*s" \ " parameter number %d had an illegal value"; @@ -42,7 +37,7 @@ int xerbla_(char *srname, integer *info) #ifdef WITH_THREAD save = PyGILState_Ensure(); #endif - PyOS_snprintf(buf, sizeof(buf), format, len, srname, *info); + PyOS_snprintf(buf, sizeof(buf), format, len, srname, (int)*info); PyErr_SetString(PyExc_ValueError, buf); #ifdef WITH_THREAD PyGILState_Release(save); @@ -50,11 +45,3 @@ int xerbla_(char *srname, integer *info) return 0; } - - -/* Same for LAPACK64_ */ -npy_int64 xerbla_64_(char *srname, npy_int64 *info) -{ - integer info_int = (integer)*info; - return xerbla_(srname, &info_int); -} diff --git a/numpy/linalg/lapack_lite/python_xerbla.c b/numpy/linalg/lapack_lite/python_xerbla.c index c239a3620..4dbb92e1f 100644 --- a/numpy/linalg/lapack_lite/python_xerbla.c +++ b/numpy/linalg/lapack_lite/python_xerbla.c @@ -1,5 +1,6 @@ #include "Python.h" #include "numpy/npy_common.h" +#include "npy_cblas.h" #undef c_abs #include "f2c.h" @@ -21,7 +22,7 @@ info: Number of the invalid parameter. */ -int xerbla_(char *srname, integer *info) +CBLAS_INT BLAS_FUNC(xerbla)(char *srname, CBLAS_INT *info) { static const char format[] = "On entry to %.*s" \ " parameter number %d had an illegal value"; @@ -39,7 +40,7 @@ int xerbla_(char *srname, integer *info) #ifdef WITH_THREAD save = PyGILState_Ensure(); #endif - PyOS_snprintf(buf, sizeof(buf), format, len, srname, *info); + PyOS_snprintf(buf, sizeof(buf), format, len, srname, (int)*info); PyErr_SetString(PyExc_ValueError, buf); #ifdef WITH_THREAD PyGILState_Release(save); @@ -47,11 +48,3 @@ int xerbla_(char *srname, integer *info) return 0; } - - -/* Same for LAPACK64_ */ -npy_int64 xerbla_64_(char *srname, npy_int64 *info) -{ - integer info_int = (integer)*info; - return xerbla_(srname, &info_int); -} diff --git a/numpy/linalg/lapack_litemodule.c b/numpy/linalg/lapack_litemodule.c index c80179fdf..4c80317f5 100644 --- a/numpy/linalg/lapack_litemodule.c +++ b/numpy/linalg/lapack_litemodule.c @@ -6,31 +6,14 @@ More modifications by Jeff Whitaker #include "Python.h" #include "numpy/arrayobject.h" +#include "npy_cblas.h" -#ifndef NPY_UMATH_USE_BLAS64_ - -/* - * Standard BLAS - */ -#ifdef NO_APPEND_FORTRAN -# define FNAME(x) x -#else -# define FNAME(x) x##_ -#endif +#define FNAME(name) BLAS_FUNC(name) -#define FINT_PYFMT "i" -typedef int fortran_int; +typedef CBLAS_INT fortran_int; -#else - -/* - * BLAS64_ - */ - -#define FNAME(x) x##_64_ - -typedef npy_int64 fortran_int; +#ifdef HAVE_BLAS_ILP64 #if NPY_BITSOF_SHORT == 64 #define FINT_PYFMT "h" @@ -46,6 +29,8 @@ typedef npy_int64 fortran_int; compiler and platform, or set NPY_USE_BLAS64_=0 #endif +#else +#define FINT_PYFMT "i" #endif typedef struct { float r, i; } f2c_complex; diff --git a/numpy/linalg/umath_linalg.c.src b/numpy/linalg/umath_linalg.c.src index b111f75d5..e864c541b 100644 --- a/numpy/linalg/umath_linalg.c.src +++ b/numpy/linalg/umath_linalg.c.src @@ -15,6 +15,8 @@ #include "npy_config.h" +#include "npy_cblas.h" + #include <stddef.h> #include <stdio.h> #include <assert.h> @@ -62,23 +64,9 @@ dbg_stack_trace() ***************************************************************************** */ -#ifndef NPY_UMATH_USE_BLAS64_ - -#ifdef NO_APPEND_FORTRAN -# define FNAME(x) x -#else -# define FNAME(x) x##_ -#endif - -typedef int fortran_int; +#define FNAME(x) BLAS_FUNC(x) -#else - -#define FNAME(x) x##_64_ - -typedef npy_int64 fortran_int; - -#endif +typedef CBLAS_INT fortran_int; typedef struct { float r, i; } f2c_complex; typedef struct { double r, i; } f2c_doublecomplex; diff --git a/numpy/testing/_private/utils.py b/numpy/testing/_private/utils.py index 8599222d3..23267a9e1 100644 --- a/numpy/testing/_private/utils.py +++ b/numpy/testing/_private/utils.py @@ -54,7 +54,7 @@ verbose = 0 IS_PYPY = platform.python_implementation() == 'PyPy' HAS_REFCOUNT = getattr(sys, 'getrefcount', None) is not None -HAS_LAPACK64 = hasattr(numpy.__config__, 'lapack64__opt_info') +HAS_LAPACK64 = hasattr(numpy.__config__, 'lapack_ilp64_opt_info') def import_nose(): |