diff options
author | Arink Verma <arinkverma@gmail.com> | 2013-08-03 18:09:55 +0530 |
---|---|---|
committer | Arink Verma <arinkverma@gmail.com> | 2013-08-30 02:14:29 +0530 |
commit | 79342d5993168a5e43d57924bb3fa75a4fa3ec01 (patch) | |
tree | 90a828383c1097b3ef3c0aad7aba22c30a651d79 /numpy/core/src/scalarmathmodule.c.src | |
parent | 70de8aa2b3a3b300c6a858cbdbb9226ce46591e1 (diff) | |
download | numpy-79342d5993168a5e43d57924bb3fa75a4fa3ec01.tar.gz |
Extracting longlong value without converting it to NyType
Diffstat (limited to 'numpy/core/src/scalarmathmodule.c.src')
-rw-r--r-- | numpy/core/src/scalarmathmodule.c.src | 70 |
1 files changed, 66 insertions, 4 deletions
diff --git a/numpy/core/src/scalarmathmodule.c.src b/numpy/core/src/scalarmathmodule.c.src index 5233d33c8..c379b4698 100644 --- a/numpy/core/src/scalarmathmodule.c.src +++ b/numpy/core/src/scalarmathmodule.c.src @@ -661,13 +661,13 @@ static void */ /**begin repeat - * #name = longlong, ulonglong, half, float, longdouble, + * #name = half, float, longdouble, * cfloat, cdouble, clongdouble# - * #type = npy_longlong, npy_ulonglong, npy_half, npy_float, npy_longdouble, + * #type = npy_half, npy_float, npy_longdouble, * npy_cfloat, npy_cdouble, npy_clongdouble# - * #Name = LongLong, ULongLong, Half, Float, LongDouble, + * #Name = Half, Float, LongDouble, * CFloat, CDouble, CLongDouble# - * #TYPE = NPY_LONGLONG, NPY_ULONGLONG, NPY_HALF, NPY_FLOAT, NPY_LONGDOUBLE, + * #TYPE = NPY_HALF, NPY_FLOAT, NPY_LONGDOUBLE, * NPY_CFLOAT, NPY_CDOUBLE, NPY_CLONGDOUBLE# */ @@ -711,6 +711,7 @@ _@name@_convert_to_ctype(PyObject *a, @type@ *arg1) /**end repeat**/ + /* Same as above but added exact checks against known python types for speed */ /**begin repeat @@ -887,6 +888,67 @@ _@name@_convert_to_ctype(PyObject *a, @type@ *arg1) /**end repeat**/ + +/**begin repeat + * #name = longlong, ulonglong# + * #type = npy_longlong, npy_ulonglong# + * #Name = LongLong, ULongLong# + * #TYPE = NPY_LONGLONG, NPY_ULONGLONG# + */#PYEXTRACTCTYPE = PyLong_AsLongLong, PyLong_AsUnsignedLongLong# + +static int +_@name@_convert_to_ctype(PyObject *a, @type@ *arg1) +{ + PyObject *temp; + +#if PY_VERSION_HEX >= 0x03000000 + if(PyLong_CheckExact(a)){ + *arg1 = @PYEXTRACTCTYPE@(a); + return 0; + } +#else + if (PyInt_CheckExact(a)){ + *arg1 = PyInt_AS_LONG(a); + return 0; + } +#endif + + if (PyArray_IsScalar(a, @Name@)) { + *arg1 = PyArrayScalar_VAL(a, @Name@); + return 0; + } + else if (PyArray_IsScalar(a, Generic)) { + PyArray_Descr *descr1; + + if (!PyArray_IsScalar(a, Number)) { + return -1; + } + descr1 = PyArray_DescrFromTypeObject((PyObject *)Py_TYPE(a)); + if (PyArray_CanCastSafely(descr1->type_num, @TYPE@)) { + PyArray_CastScalarDirect(a, descr1, arg1, @TYPE@); + Py_DECREF(descr1); + return 0; + } + else { + Py_DECREF(descr1); + return -1; + } + } + else if (PyArray_GetPriority(a, NPY_PRIORITY) > NPY_PRIORITY) { + return -2; + } + else if ((temp = PyArray_ScalarFromObject(a)) != NULL) { + int retval = _@name@_convert_to_ctype(temp, arg1); + + Py_DECREF(temp); + return retval; + } + return -2; +} + +/**end repeat**/ + + /**begin repeat * #name = byte, ubyte, short, ushort, int, uint, * long, ulong, longlong, ulonglong, |