summaryrefslogtreecommitdiff
path: root/scipy/base/src/arrayobject.c
diff options
context:
space:
mode:
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;
+}