summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-06-27 22:08:07 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-06-27 22:08:07 +0000
commit36c72bfc2118e52160d3445e06b6e1cc17a2cba7 (patch)
tree5ab06939e7e4d7dc8fed3534f0d12a2fcc5e9e00 /numpy
parent47c92e4224ee36090289fcafa6820f749bc3d9b1 (diff)
downloadnumpy-36c72bfc2118e52160d3445e06b6e1cc17a2cba7.tar.gz
Add a function to retrieve a user-defined type number from the name of the associated type-object
Diffstat (limited to 'numpy')
-rw-r--r--numpy/core/code_generators/multiarray_api_order.txt1
-rw-r--r--numpy/core/src/arrayobject.c26
2 files changed, 24 insertions, 3 deletions
diff --git a/numpy/core/code_generators/multiarray_api_order.txt b/numpy/core/code_generators/multiarray_api_order.txt
index 67b09d190..10bd1219e 100644
--- a/numpy/core/code_generators/multiarray_api_order.txt
+++ b/numpy/core/code_generators/multiarray_api_order.txt
@@ -72,3 +72,4 @@ PyArray_RegisterCastFunc
PyArray_RegisterCanCast
PyArray_InitArrFuncs
PyArray_IntTupleFromIntp
+PyArray_TypeNumFromName
diff --git a/numpy/core/src/arrayobject.c b/numpy/core/src/arrayobject.c
index bd064b3f4..75021c902 100644
--- a/numpy/core/src/arrayobject.c
+++ b/numpy/core/src/arrayobject.c
@@ -1373,12 +1373,32 @@ _default_nonzero(void *ip, void *arr)
return FALSE;
}
+/*
+ Given a string return the type-number for
+ the data-type with that string as the type-object name.
+ Returns PyArray_NOTYPE without setting an error if no type can be
+ found. Only works for user-defined data-types.
+*/
+
+/*MULTIARRAY_API
+ */
+static int
+PyArray_TypeNumFromName(char *str)
+{
+ int i;
+ PyArray_Descr *descr;
+
+ for (i=0; i<PyArray_NUMUSERTYPES; i++) {
+ descr = userdescrs[i];
+ if (strcmp(descr->typeobj->tp_name, str) == 0)
+ return descr->type_num;
+ }
+
+ return PyArray_NOTYPE;
+}
/*
returns typenum to associate with this type >=PyArray_USERDEF.
- Also creates a copy of the VOID_DESCR table inserting it's typeobject in
- and it's typenum in the appropriate place.
-
needs the userdecrs table and PyArray_NUMUSER variables
defined in arratypes.inc
*/