diff options
Diffstat (limited to 'numpy/core')
| -rw-r--r-- | numpy/core/code_generators/generate_array_api.py | 5 | ||||
| -rw-r--r-- | numpy/core/code_generators/generate_ufunc_api.py | 4 | ||||
| -rw-r--r-- | numpy/core/include/numarray/arraybase.h | 7 | ||||
| -rw-r--r-- | numpy/core/include/numarray/cfunc.h | 78 | ||||
| -rw-r--r-- | numpy/core/include/numarray/libnumarray.h | 33 | ||||
| -rw-r--r-- | numpy/core/include/numarray/nummacro.h | 2 | ||||
| -rw-r--r-- | numpy/core/src/_sortmodule.c.src | 2 | ||||
| -rw-r--r-- | numpy/core/src/scalarmathmodule.c.src | 4 | ||||
| -rw-r--r-- | numpy/core/src/umathmodule.c.src | 2 |
9 files changed, 93 insertions, 44 deletions
diff --git a/numpy/core/code_generators/generate_array_api.py b/numpy/core/code_generators/generate_array_api.py index 3177a88bb..9fba31a90 100644 --- a/numpy/core/code_generators/generate_array_api.py +++ b/numpy/core/code_generators/generate_array_api.py @@ -62,7 +62,7 @@ static void **PyArray_API=NULL; #if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT) static int -import_array(void) +_import_array(void) { PyObject *numpy = PyImport_ImportModule("numpy.core.multiarray"); PyObject *c_api = NULL; @@ -84,6 +84,9 @@ import_array(void) } return 0; } + +#define import_array() { if (_import_array() < 0) {PyErr_Print(); Py_FatalError("numpy.core.multiarray failed to import... exiting.\n"); } } + #endif #endif diff --git a/numpy/core/code_generators/generate_ufunc_api.py b/numpy/core/code_generators/generate_ufunc_api.py index 1b9919cfa..a52ce0856 100644 --- a/numpy/core/code_generators/generate_ufunc_api.py +++ b/numpy/core/code_generators/generate_ufunc_api.py @@ -29,7 +29,7 @@ static void **PyUFunc_API=NULL; %s static int -import_umath(void) +_import_umath(void) { PyObject *numpy = PyImport_ImportModule("numpy.core.umath"); PyObject *c_api = NULL; @@ -46,6 +46,8 @@ import_umath(void) return 0; } +#define import_umath() { if (_import_umath() < 0) {PyErr_Print(); Py_FatalError("numpy.core.umath failed to import... exiting.\n"); }} + #define import_ufunc import_umath #endif diff --git a/numpy/core/include/numarray/arraybase.h b/numpy/core/include/numarray/arraybase.h index 5f61bbb64..cf4043491 100644 --- a/numpy/core/include/numarray/arraybase.h +++ b/numpy/core/include/numarray/arraybase.h @@ -8,7 +8,7 @@ typedef enum { - tAny, + tAny=-1, tBool=PyArray_BOOL, tInt8=PyArray_INT8, tUInt8=PyArray_UINT8, @@ -23,16 +23,16 @@ typedef enum tComplex32=PyArray_COMPLEX64, tComplex64=PyArray_COMPLEX128, tObject=PyArray_OBJECT, /* placeholder... does nothing */ + tMaxType=PyArray_NTYPES, tDefault = tFloat64, #if BITSOF_LONG == 64 tLong = tInt64, #else tLong = tInt32, #endif - tMaxType } NumarrayType; -#define nNumarrayType 16 +#define nNumarrayType PyArray_NTYPES #define HAS_UINT64 1 @@ -43,7 +43,6 @@ typedef enum } NumarrayByteOrder; - #define Complex64 Complex64_ typedef struct { Float32 r, i; } Complex32; typedef struct { Float64 r, i; } Complex64; diff --git a/numpy/core/include/numarray/cfunc.h b/numpy/core/include/numarray/cfunc.h new file mode 100644 index 000000000..b581be08f --- /dev/null +++ b/numpy/core/include/numarray/cfunc.h @@ -0,0 +1,78 @@ +#if !defined(__cfunc__) +#define __cfunc__ 1 + +typedef PyObject *(*CFUNCasPyValue)(void *); +typedef int (*UFUNC)(long, long, long, void **, long*); +/* typedef void (*CFUNC_2ARG)(long, void *, void *); */ +/* typedef void (*CFUNC_3ARG)(long, void *, void *, void *); */ +typedef int (*CFUNCfromPyValue)(PyObject *, void *); +typedef int (*CFUNC_STRIDE_CONV_FUNC)(long, long, maybelong *, + void *, long, maybelong*, void *, long, maybelong *); + +typedef int (*CFUNC_STRIDED_FUNC)(PyObject *, long, PyArrayObject **, + char **data); + +#define MAXARRAYS 16 + +typedef enum { + CFUNC_UFUNC, + CFUNC_STRIDING, + CFUNC_NSTRIDING, + CFUNC_AS_PY_VALUE, + CFUNC_FROM_PY_VALUE +} eCfuncType; + +typedef struct { + char *name; + void *fptr; /* Pointer to "un-wrapped" c function */ + eCfuncType type; /* UFUNC, STRIDING, AsPyValue, FromPyValue */ + Bool chkself; /* CFUNC does own alignment/bounds checking */ + Bool align; /* CFUNC requires aligned buffer pointers */ + Int8 wantIn, wantOut; /* required input/output arg counts. */ + Int8 sizes[MAXARRAYS]; /* array of align/itemsizes. */ + Int8 iters[MAXARRAYS]; /* array of element counts. 0 --> niter. */ +} CfuncDescriptor; + +typedef struct { + PyObject_HEAD + CfuncDescriptor descr; +} CfuncObject; + +#define SELF_CHECKED_CFUNC_DESCR(name, type) \ + static CfuncDescriptor name##_descr = { #name, (void *) name, type, 1 } + +#define CHECK_ALIGN 1 + +#define CFUNC_DESCR(name, type, align, iargs, oargs, s1, s2, s3, i1, i2, i3) \ + static CfuncDescriptor name##_descr = \ + { #name, (void *)name, type, 0, align, iargs, oargs, {s1, s2, s3}, {i1, i2, i3} } + +#define UFUNC_DESCR1(name, s1) \ + CFUNC_DESCR(name, CFUNC_UFUNC, CHECK_ALIGN, 0, 1, s1, 0, 0, 0, 0, 0) + +#define UFUNC_DESCR2(name, s1, s2) \ + CFUNC_DESCR(name, CFUNC_UFUNC, CHECK_ALIGN, 1, 1, s1, s2, 0, 0, 0, 0) + +#define UFUNC_DESCR3(name, s1, s2, s3) \ + CFUNC_DESCR(name, CFUNC_UFUNC, CHECK_ALIGN, 2, 1, s1, s2, s3, 0, 0, 0) + +#define UFUNC_DESCR3sv(name, s1, s2, s3) \ + CFUNC_DESCR(name, CFUNC_UFUNC, CHECK_ALIGN, 2, 1, s1, s2, s3, 1, 0, 0) + +#define UFUNC_DESCR3vs(name, s1, s2, s3) \ + CFUNC_DESCR(name, CFUNC_UFUNC, CHECK_ALIGN, 2, 1, s1, s2, s3, 0, 1, 0) + +#define STRIDING_DESCR2(name, align, s1, s2) \ + CFUNC_DESCR(name, CFUNC_STRIDING, align, 1, 1, s1, s2, 0, 0, 0, 0) + +#define NSTRIDING_DESCR1(name) \ + CFUNC_DESCR(name, CFUNC_NSTRIDING, 0, 0, 1, 0, 0, 0, 0, 0, 0) + +#define NSTRIDING_DESCR2(name) \ + CFUNC_DESCR(name, CFUNC_NSTRIDING, 0, 1, 1, 0, 0, 0, 0, 0, 0) + +#define NSTRIDING_DESCR3(name) \ + CFUNC_DESCR(name, CFUNC_NSTRIDING, 0, 2, 1, 0, 0, 0, 0, 0, 0) + +#endif + diff --git a/numpy/core/include/numarray/libnumarray.h b/numpy/core/include/numarray/libnumarray.h index 5d8f6948b..301fa2e94 100644 --- a/numpy/core/include/numarray/libnumarray.h +++ b/numpy/core/include/numarray/libnumarray.h @@ -9,43 +9,12 @@ #include "arraybase.h" #include "nummacro.h" #include "numcomplex.h" +#include "ieeespecial.h" #ifdef __cplusplus extern "C" { #endif -#define _NAtype_toDescr(type) (((type)==tAny) ? NULL : \ - PyArray_DescrFromType(type)) - -#define NA_InputArray(obj, type, flags) \ - (PyArrayObject *)\ - PyArray_FromAny(obj, _NAtype_toDescr(type), 0, 0, flags, NULL) - -#define NA_OutputArray(obj, type, flags) \ - (PyArrayObject *) \ - ((PyArray_Check(obj) && PyArray_CHKFLAGS(obj, flags)) ? \ - PyArray_Empty(PyArray_NDIM(obj), \ - PyArray_DIMS(obj), \ - ((type == tAny) && \ - (Py_INCREF(PyArray_DESCR(obj)) || 1)) ? \ - PyArray_DESCR(obj) : \ - PyArray_DescrFromType(type), 0) : \ - PyArray_FromAny(obj, _NAtype_toDescr(type), 0, 0, flags, NULL)) - -#define NA_IoArray(obj, type, flags) \ - (PyArrayObject *) \ - PyArray_FromAny(obj, _NAtype_toDescr(type), 0, 0, flags | \ - UPDATEIFCOPY, NULL) - -#define NA_vNewArray(buffer, type, ndim, shape) \ - (PyArrayObject *) \ - PyArray_NewFromDescr(&PyArray_Type, \ - PyArray_DescrFromType(type), \ - ndim, shape, NULL, buffer, CARRAY_FLAGS, \ - NULL) - -PyArrayObject *NA_NewArray(void *buffer, NumarrayType type, int ndim, ...); - /* Header file for libnumarray */ #if !defined(_libnumarray_MODULE) diff --git a/numpy/core/include/numarray/nummacro.h b/numpy/core/include/numarray/nummacro.h index e44dfd9df..6b185e81e 100644 --- a/numpy/core/include/numarray/nummacro.h +++ b/numpy/core/include/numarray/nummacro.h @@ -326,8 +326,6 @@ typedef enum #define BOOLEAN_BITWISE_NOT(x) ((x) ^ 1) -#define NA_elements PyArray_SIZE - #define NA_NBYTES(a) (a->descr->elsize * NA_elements(a)) #if defined(NA_SMP) diff --git a/numpy/core/src/_sortmodule.c.src b/numpy/core/src/_sortmodule.c.src index e152fe29f..a87a6858f 100644 --- a/numpy/core/src/_sortmodule.c.src +++ b/numpy/core/src/_sortmodule.c.src @@ -464,6 +464,6 @@ init_sort(void) { m = Py_InitModule("_sort", methods); - if (import_array() < 0) return; + import_array(); add_sortfuncs(); } diff --git a/numpy/core/src/scalarmathmodule.c.src b/numpy/core/src/scalarmathmodule.c.src index aef6ad8d4..1ef548169 100644 --- a/numpy/core/src/scalarmathmodule.c.src +++ b/numpy/core/src/scalarmathmodule.c.src @@ -1095,8 +1095,8 @@ PyMODINIT_FUNC initscalarmath(void) { m = Py_InitModule("scalarmath", methods); - if (import_array() < 0) return; - if (import_umath() < 0) return; + import_array(); return; + import_umath(); return; if (get_functions() < 0) return; diff --git a/numpy/core/src/umathmodule.c.src b/numpy/core/src/umathmodule.c.src index 8975e68b6..8d1cd1b87 100644 --- a/numpy/core/src/umathmodule.c.src +++ b/numpy/core/src/umathmodule.c.src @@ -2045,7 +2045,7 @@ PyMODINIT_FUNC initumath(void) { m = Py_InitModule("umath", methods); /* Import the array */ - if (import_array() < 0) { + if (_import_array() < 0) { if (!PyErr_Occurred()) { PyErr_SetString(PyExc_ImportError, "umath failed: Could not import array core."); |
