summaryrefslogtreecommitdiff
path: root/scipy/base/src/arrayobject.c
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2005-09-29 09:23:46 +0000
committerTravis Oliphant <oliphant@enthought.com>2005-09-29 09:23:46 +0000
commitca2d4dc36cd735c76f895d86e8424099603a9fed (patch)
tree142d564f27b86920c8ce4954d09605c23a57f6f3 /scipy/base/src/arrayobject.c
parent5daeb8eccba19179efd9469a0d916a18ab38dea0 (diff)
downloadnumpy-ca2d4dc36cd735c76f895d86e8424099603a9fed.tar.gz
Added a can_cast Python function.
Diffstat (limited to 'scipy/base/src/arrayobject.c')
-rw-r--r--scipy/base/src/arrayobject.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/scipy/base/src/arrayobject.c b/scipy/base/src/arrayobject.c
index 17a9914a8..f174977c5 100644
--- a/scipy/base/src/arrayobject.c
+++ b/scipy/base/src/arrayobject.c
@@ -5506,6 +5506,32 @@ PyArray_CanCastSafely(int fromtype, int totype)
}
}
+static Bool
+PyArray_CanCastTo(PyArray_Typecode *from, PyArray_Typecode *to)
+{
+ int fromtype=from->type_num;
+ int totype=to->type_num;
+ Bool ret;
+
+ ret = (Bool) PyArray_CanCastSafely(fromtype, totype);
+ if (ret) { /* Check String and Unicode more closely */
+ if (fromtype == PyArray_STRING) {
+ if (totype == PyArray_STRING) {
+ ret = (from->itemsize <= to->itemsize);
+ }
+ else if (totype == PyArray_UNICODE) {
+ ret = (from->itemsize * sizeof(Py_UNICODE)\
+ <= to->itemsize);
+ }
+ }
+ else if (fromtype == PyArray_UNICODE) {
+ if (totype == PyArray_UNICODE) {
+ ret = (from->itemsize <= to->itemsize);
+ }
+ }
+ }
+ return ret;
+}