From ca2d4dc36cd735c76f895d86e8424099603a9fed Mon Sep 17 00:00:00 2001 From: Travis Oliphant Date: Thu, 29 Sep 2005 09:23:46 +0000 Subject: Added a can_cast Python function. --- scipy/base/src/arrayobject.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'scipy/base/src/arrayobject.c') 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; +} -- cgit v1.2.1