summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wiebe <mwwiebe@gmail.com>2011-01-25 18:21:43 -0800
committerMark Wiebe <mwwiebe@gmail.com>2011-01-25 18:30:27 -0800
commitcf8d15203cd24bc7a836c98117a8e4edc9debd8b (patch)
tree2b4601f015d10acc02973d2b86fff3e78a0c8cc3
parent585a636f95c3bf884e53a6724738a26d4a5b00e4 (diff)
downloadnumpy-cf8d15203cd24bc7a836c98117a8e4edc9debd8b.tar.gz
ENH: core: Make PyArray_ArrFuncs have the same structure as in 1.5 and earlier
-rw-r--r--numpy/core/include/numpy/ndarraytypes.h24
-rw-r--r--numpy/core/src/multiarray/arraytypes.c.src147
-rw-r--r--numpy/core/src/multiarray/convert_datatype.c4
-rw-r--r--numpy/core/src/multiarray/usertypes.c6
4 files changed, 103 insertions, 78 deletions
diff --git a/numpy/core/include/numpy/ndarraytypes.h b/numpy/core/include/numpy/ndarraytypes.h
index a9ead0184..08612668e 100644
--- a/numpy/core/include/numpy/ndarraytypes.h
+++ b/numpy/core/include/numpy/ndarraytypes.h
@@ -420,6 +420,14 @@ typedef struct {
} PyArray_Dims;
typedef struct {
+ /*
+ * Functions to cast to most other standard types
+ * Can have some NULL entries. The types
+ * DATETIME, TIMEDELTA, and HALF go into the castdict
+ * even though they are built-in.
+ */
+ PyArray_VectorUnaryFunc *cast[NPY_NTYPES_ABI_COMPATIBLE];
+
/* The next four functions *cannot* be NULL */
/*
@@ -513,22 +521,6 @@ typedef struct {
PyArray_FastClipFunc *fastclip;
PyArray_FastPutmaskFunc *fastputmask;
PyArray_FastTakeFunc *fasttake;
-
- /*
- * A little room to grow --- should use generic function
- * interface for most additions
- */
- void *pad1;
- void *pad2;
- void *pad3;
- void *pad4;
-
- /*
- * Functions to cast to all other standard types
- * Can have some NULL entries
- */
- PyArray_VectorUnaryFunc *cast[NPY_NTYPES];
-
} PyArray_ArrFuncs;
/* The item must be reference counted when it is inserted or extracted. */
diff --git a/numpy/core/src/multiarray/arraytypes.c.src b/numpy/core/src/multiarray/arraytypes.c.src
index 9c8c7200c..11760241e 100644
--- a/numpy/core/src/multiarray/arraytypes.c.src
+++ b/numpy/core/src/multiarray/arraytypes.c.src
@@ -3601,6 +3601,29 @@ static int
* #endian = |, |, =#
*/
static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {
+ {
+ (PyArray_VectorUnaryFunc*)@from@_to_BOOL,
+ (PyArray_VectorUnaryFunc*)@from@_to_BYTE,
+ (PyArray_VectorUnaryFunc*)@from@_to_UBYTE,
+ (PyArray_VectorUnaryFunc*)@from@_to_SHORT,
+ (PyArray_VectorUnaryFunc*)@from@_to_USHORT,
+ (PyArray_VectorUnaryFunc*)@from@_to_INT,
+ (PyArray_VectorUnaryFunc*)@from@_to_UINT,
+ (PyArray_VectorUnaryFunc*)@from@_to_LONG,
+ (PyArray_VectorUnaryFunc*)@from@_to_ULONG,
+ (PyArray_VectorUnaryFunc*)@from@_to_LONGLONG,
+ (PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG,
+ (PyArray_VectorUnaryFunc*)@from@_to_FLOAT,
+ (PyArray_VectorUnaryFunc*)@from@_to_DOUBLE,
+ (PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from@_to_CFLOAT,
+ (PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from@_to_OBJECT,
+ (PyArray_VectorUnaryFunc*)@from@_to_STRING,
+ (PyArray_VectorUnaryFunc*)@from@_to_UNICODE,
+ (PyArray_VectorUnaryFunc*)@from@_to_VOID
+ },
(PyArray_GetItemFunc*)@from@_getitem,
(PyArray_SetItemFunc*)@from@_setitem,
(PyArray_CopySwapNFunc*)@from@_copyswapn,
@@ -3625,34 +3648,7 @@ static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {
NULL,
(PyArray_FastClipFunc *)NULL,
(PyArray_FastPutmaskFunc *)NULL,
- (PyArray_FastTakeFunc *)NULL,
- NULL, NULL, NULL, NULL,
- {
- (PyArray_VectorUnaryFunc*)@from@_to_BOOL,
- (PyArray_VectorUnaryFunc*)@from@_to_BYTE,
- (PyArray_VectorUnaryFunc*)@from@_to_UBYTE,
- (PyArray_VectorUnaryFunc*)@from@_to_SHORT,
- (PyArray_VectorUnaryFunc*)@from@_to_USHORT,
- (PyArray_VectorUnaryFunc*)@from@_to_INT,
- (PyArray_VectorUnaryFunc*)@from@_to_UINT,
- (PyArray_VectorUnaryFunc*)@from@_to_LONG,
- (PyArray_VectorUnaryFunc*)@from@_to_ULONG,
- (PyArray_VectorUnaryFunc*)@from@_to_LONGLONG,
- (PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG,
- (PyArray_VectorUnaryFunc*)@from@_to_FLOAT,
- (PyArray_VectorUnaryFunc*)@from@_to_DOUBLE,
- (PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE,
- (PyArray_VectorUnaryFunc*)@from@_to_CFLOAT,
- (PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE,
- (PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE,
- (PyArray_VectorUnaryFunc*)@from@_to_OBJECT,
- (PyArray_VectorUnaryFunc*)@from@_to_STRING,
- (PyArray_VectorUnaryFunc*)@from@_to_UNICODE,
- (PyArray_VectorUnaryFunc*)@from@_to_VOID,
- (PyArray_VectorUnaryFunc*)@from@_to_DATETIME,
- (PyArray_VectorUnaryFunc*)@from@_to_TIMEDELTA,
- (PyArray_VectorUnaryFunc*)@from@_to_HALF
- }
+ (PyArray_FastTakeFunc *)NULL
};
/*
@@ -3697,6 +3693,29 @@ static PyArray_Descr @from@_Descr = {
* #isobject= 0*18,NPY_OBJECT_DTYPE_FLAGS,0*2#
*/
static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {
+ {
+ (PyArray_VectorUnaryFunc*)@from@_to_BOOL,
+ (PyArray_VectorUnaryFunc*)@from@_to_BYTE,
+ (PyArray_VectorUnaryFunc*)@from@_to_UBYTE,
+ (PyArray_VectorUnaryFunc*)@from@_to_SHORT,
+ (PyArray_VectorUnaryFunc*)@from@_to_USHORT,
+ (PyArray_VectorUnaryFunc*)@from@_to_INT,
+ (PyArray_VectorUnaryFunc*)@from@_to_UINT,
+ (PyArray_VectorUnaryFunc*)@from@_to_LONG,
+ (PyArray_VectorUnaryFunc*)@from@_to_ULONG,
+ (PyArray_VectorUnaryFunc*)@from@_to_LONGLONG,
+ (PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG,
+ (PyArray_VectorUnaryFunc*)@from@_to_FLOAT,
+ (PyArray_VectorUnaryFunc*)@from@_to_DOUBLE,
+ (PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from@_to_CFLOAT,
+ (PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE,
+ (PyArray_VectorUnaryFunc*)@from@_to_OBJECT,
+ (PyArray_VectorUnaryFunc*)@from@_to_STRING,
+ (PyArray_VectorUnaryFunc*)@from@_to_UNICODE,
+ (PyArray_VectorUnaryFunc*)@from@_to_VOID
+ },
(PyArray_GetItemFunc*)@from@_getitem,
(PyArray_SetItemFunc*)@from@_setitem,
(PyArray_CopySwapNFunc*)@from@_copyswapn,
@@ -3721,34 +3740,7 @@ static PyArray_ArrFuncs _Py@NAME@_ArrFuncs = {
NULL,
(PyArray_FastClipFunc*)@from@_fastclip,
(PyArray_FastPutmaskFunc*)@from@_fastputmask,
- (PyArray_FastTakeFunc*)@from@_fasttake,
- NULL, NULL, NULL, NULL,
- {
- (PyArray_VectorUnaryFunc*)@from@_to_BOOL,
- (PyArray_VectorUnaryFunc*)@from@_to_BYTE,
- (PyArray_VectorUnaryFunc*)@from@_to_UBYTE,
- (PyArray_VectorUnaryFunc*)@from@_to_SHORT,
- (PyArray_VectorUnaryFunc*)@from@_to_USHORT,
- (PyArray_VectorUnaryFunc*)@from@_to_INT,
- (PyArray_VectorUnaryFunc*)@from@_to_UINT,
- (PyArray_VectorUnaryFunc*)@from@_to_LONG,
- (PyArray_VectorUnaryFunc*)@from@_to_ULONG,
- (PyArray_VectorUnaryFunc*)@from@_to_LONGLONG,
- (PyArray_VectorUnaryFunc*)@from@_to_ULONGLONG,
- (PyArray_VectorUnaryFunc*)@from@_to_FLOAT,
- (PyArray_VectorUnaryFunc*)@from@_to_DOUBLE,
- (PyArray_VectorUnaryFunc*)@from@_to_LONGDOUBLE,
- (PyArray_VectorUnaryFunc*)@from@_to_CFLOAT,
- (PyArray_VectorUnaryFunc*)@from@_to_CDOUBLE,
- (PyArray_VectorUnaryFunc*)@from@_to_CLONGDOUBLE,
- (PyArray_VectorUnaryFunc*)@from@_to_OBJECT,
- (PyArray_VectorUnaryFunc*)@from@_to_STRING,
- (PyArray_VectorUnaryFunc*)@from@_to_UNICODE,
- (PyArray_VectorUnaryFunc*)@from@_to_VOID,
- (PyArray_VectorUnaryFunc*)@from@_to_DATETIME,
- (PyArray_VectorUnaryFunc*)@from@_to_TIMEDELTA,
- (PyArray_VectorUnaryFunc*)@from@_to_HALF
- }
+ (PyArray_FastTakeFunc*)@from@_fasttake
};
/*
@@ -3902,8 +3894,49 @@ set_typeinfo(PyObject *dict)
PyObject *infodict, *s;
int i;
+ PyArray_Descr *dtype;
+ PyObject *cobj, *key;
+
+ /* Add cast functions for the new types */
+/**begin repeat
+ *
+ * #name1 = BOOL, BYTE, UBYTE, SHORT, USHORT, INT, UINT,
+ * LONG, ULONG, LONGLONG, ULONGLONG, HALF, FLOAT, DOUBLE, LONGDOUBLE,
+ * CFLOAT, CDOUBLE, CLONGDOUBLE, OBJECT, STRING, UNICODE, VOID,
+ * DATETIME,TIMEDELTA#
+ */
+/**begin repeat1
+ *
+ * #name2 = HALF, DATETIME, TIMEDELTA#
+ */
+ dtype = _builtin_descrs[NPY_@name1@];
+ if (dtype->f->castdict == NULL) {
+ dtype->f->castdict = PyDict_New();
+ if (dtype->f->castdict == NULL) {
+ return -1;
+ }
+ }
+ key = PyInt_FromLong(NPY_@name2@);
+ if (key == NULL) {
+ return -1;
+ }
+ cobj = NpyCapsule_FromVoidPtr((void *)@name1@_to_@name2@, NULL);
+ if (cobj == NULL) {
+ Py_DECREF(key);
+ return -1;
+ }
+ if (PyDict_SetItem(dtype->f->castdict, key, cobj) < 0) {
+ Py_DECREF(key);
+ Py_DECREF(cobj);
+ return -1;
+ }
+ Py_DECREF(key);
+ Py_DECREF(cobj);
+/**end repeat1**/
+/**end repeat**/
+
for (i = 0; i < _MAX_LETTER; i++) {
- _letter_to_num[i] = PyArray_NTYPES;
+ _letter_to_num[i] = NPY_NTYPES;
}
/**begin repeat
diff --git a/numpy/core/src/multiarray/convert_datatype.c b/numpy/core/src/multiarray/convert_datatype.c
index d4e5003fd..45a20b5de 100644
--- a/numpy/core/src/multiarray/convert_datatype.c
+++ b/numpy/core/src/multiarray/convert_datatype.c
@@ -83,10 +83,10 @@ PyArray_GetCastFunc(PyArray_Descr *descr, int type_num)
{
PyArray_VectorUnaryFunc *castfunc = NULL;
- if (type_num < PyArray_NTYPES) {
+ if (type_num < NPY_NTYPES_ABI_COMPATIBLE) {
castfunc = descr->f->cast[type_num];
}
- if (castfunc == NULL) {
+ else {
PyObject *obj = descr->f->castdict;
if (obj && PyDict_Check(obj)) {
PyObject *key;
diff --git a/numpy/core/src/multiarray/usertypes.c b/numpy/core/src/multiarray/usertypes.c
index 594722695..618ffb776 100644
--- a/numpy/core/src/multiarray/usertypes.c
+++ b/numpy/core/src/multiarray/usertypes.c
@@ -94,7 +94,7 @@ PyArray_InitArrFuncs(PyArray_ArrFuncs *f)
{
int i;
- for(i = 0; i < PyArray_NTYPES; i++) {
+ for(i = 0; i < NPY_NTYPES_ABI_COMPATIBLE; i++) {
f->cast[i] = NULL;
}
f->getitem = NULL;
@@ -188,11 +188,11 @@ PyArray_RegisterCastFunc(PyArray_Descr *descr, int totype,
PyObject *cobj, *key;
int ret;
- if (totype < PyArray_NTYPES) {
+ if (totype < NPY_NTYPES_ABI_COMPATIBLE) {
descr->f->cast[totype] = castfunc;
return 0;
}
- if (!PyTypeNum_ISUSERDEF(totype)) {
+ if (totype >= NPY_NTYPES && !PyTypeNum_ISUSERDEF(totype)) {
PyErr_SetString(PyExc_TypeError, "invalid type number.");
return -1;
}