diff --git "a/partition_94.json" "b/partition_94.json" new file mode 100644--- /dev/null +++ "b/partition_94.json" @@ -0,0 +1,26810 @@ +[ + { + "hash": "c10618c8b35ee51475627289169caea1fc39c3af", + "msg": "Fix nonzero and go back to using Generic scalar handler on failure in main scalar routine.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-04-27T19:57:19+00:00", + "author_timezone": 0, + "committer_date": "2006-04-27T19:57:19+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "3caa584104049198562906e3e72f25dd298748b7" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 16, + "insertions": 62, + "lines": 78, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -159,6 +159,14 @@ static void\n }\n /**end repeat**/\n \n+/**begin repeat\n+ #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n+ #oper=and*10, xor*10, or*10#\n+ #op=&*10, ^*10, |*10#\n+ **/\n+#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n+/**end repeat**/\n+\n /**begin repeat\n #name=float, double, longdouble#\n **/\n@@ -280,8 +288,13 @@ _@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1,\n #power=0*60,1*10,0*106,1*6,0*12#\n **/\n \n+#if @power@\n+static PyObject *\n+@name@_power(PyObject *a, PyObject *b, PyObject *c)\n+#else\n static PyObject *\n @name@_@oper@(PyObject *a, PyObject *b)\n+#endif\n {\n PyObject *ret;\n @name@ arg1, arg2, out;\n@@ -291,16 +304,16 @@ static PyObject *\n \t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n-\tbreak;\n+ break;\n case -1: /* can't cast both safely use different add function */\n-\tPy_INCREF(Py_NotImplemented);\n-\treturn Py_NotImplemented;\n- case -2: /* use ufunc */\n+ Py_INCREF(Py_NotImplemented);\n+ return Py_NotImplemented;\n+ case -2: /* use default handling */\n \tif (PyErr_Occurred()) return NULL;\n #if @power@\n-\treturn PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n+ return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n #else\n-\treturn PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n+ return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n #endif\n }\n \n@@ -329,8 +342,8 @@ static PyObject *\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n }\n+/**end repeat**/\n \n-/**end repeat**/\t\n \n /**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n@@ -339,29 +352,29 @@ static PyObject *\n #define @name@_@oper@ NULL\n /**end repeat**/\n \n+\n /**begin repeat\n- #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n- #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*5#\n- #oper=negative*16, positive*16, absolute*16, nonzero*16, invert*16#\n+ #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n+ #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n+ #oper=negative*16, positive*16, absolute*16, invert*16#\n **/\n-\n static PyObject *\n @name@_@oper@(PyObject *a)\n {\n- PyObject *ret;\n @name@ arg1, out;\n+ PyObject *ret;\n \t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n-\tbreak;\n+ break;\n case -1: /* can't cast both safely use different add function */\n \tPy_INCREF(Py_NotImplemented);\n \treturn Py_NotImplemented;\n- case -2: /* use ufunc */\n+ case -2: /* use default handling */\n \tif (PyErr_Occurred()) return NULL;\n-\treturn PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n+ return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n-\t\n+\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n \n@@ -369,8 +382,37 @@ static PyObject *\n \n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n+\n return ret;\n+}\n+/**end repeat**/\n+\n+\n+/**begin repeat\n+ #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n+ #simp=1*13,0*3#\n+**/\n+static int\n+@name@_nonzero(PyObject *a)\n+{\n+ int ret;\n+ @name@ arg1;\n+\t\n+ if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n+\tif (PyErr_Occurred()) return -1;\n+ return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n+ }\n+ \n+ /* here we do the actual calculation with arg1 and arg2 */\n+ /* make it a function call. */\n \n+#if @simp@\n+ ret = (arg1 != 0);\n+#else \n+ ret = ((arg1.real != 0) || (arg1.imag != 0));\n+#endif\n+ \n+ return ret;\n }\n /**end repeat**/\n \n@@ -552,6 +594,8 @@ alter_pyscalars(PyObject *dummy, PyObject *args)\n \t return NULL;\n \t}\n }\n+ Py_INCREF(Py_None);\n+ return Py_None;\n }\n \n char doc_restorepyscalars[] = \"\";\n@@ -584,6 +628,8 @@ restore_pyscalars(PyObject *dummy, PyObject *args)\n \t return NULL;\n \t}\n }\n+ Py_INCREF(Py_None);\n+ return Py_None;\n }\n \n static struct PyMethodDef methods[] = {\n", + "added_lines": 62, + "deleted_lines": 16, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide @name@_cfloat_divide\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\nvoid\n@name@_ctype_invert(@name@ a, @name@ *out)\n{\n *out = ~a;\n}\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide @name@_cfloat_divide\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\nvoid\n@name@_ctype_invert(@name@ a, @name@ *out)\n{\n *out = ~a;\n}\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n\treturn PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n\treturn PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n\n/**end repeat**/\t\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*5#\n #oper=negative*16, positive*16, absolute*16, nonzero*16, invert*16#\n**/\n\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n PyObject *ret;\n @name@ arg1, out;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\t\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "/**begin repeat", + " #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#", + " #oper=and*10, xor*10, or*10#", + " #op=&*10, ^*10, |*10#", + " **/", + "#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)", + "/**end repeat**/", + "", + "#if @power@", + "static PyObject *", + "@name@_power(PyObject *a, PyObject *b, PyObject *c)", + "#else", + "#endif", + " break;", + " Py_INCREF(Py_NotImplemented);", + " return Py_NotImplemented;", + " case -2: /* use default handling */", + " return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);", + " return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);", + "/**end repeat**/", + "", + " #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#", + " #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#", + " #oper=negative*16, positive*16, absolute*16, invert*16#", + " PyObject *ret;", + " break;", + " case -2: /* use default handling */", + " return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);", + "", + "", + "}", + "/**end repeat**/", + "", + "", + "/**begin repeat", + " #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#", + " #simp=1*13,0*3#", + "**/", + "static int", + "@name@_nonzero(PyObject *a)", + "{", + " int ret;", + " @name@ arg1;", + "", + " if (_@name@_convert_to_ctype(a, &arg1) < 0) {", + "\tif (PyErr_Occurred()) return -1;", + " return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);", + " }", + "", + " /* here we do the actual calculation with arg1 and arg2 */", + " /* make it a function call. */", + "#if @simp@", + " ret = (arg1 != 0);", + "#else", + " ret = ((arg1.real != 0) || (arg1.imag != 0));", + "#endif", + "", + " return ret;", + " Py_INCREF(Py_None);", + " return Py_None;", + " Py_INCREF(Py_None);", + " return Py_None;" + ], + "deleted": [ + "\tbreak;", + "\tPy_INCREF(Py_NotImplemented);", + "\treturn Py_NotImplemented;", + " case -2: /* use ufunc */", + "\treturn PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);", + "\treturn PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);", + "/**end repeat**/", + " #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#", + " #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*5#", + " #oper=negative*16, positive*16, absolute*16, nonzero*16, invert*16#", + "", + " PyObject *ret;", + "\tbreak;", + " case -2: /* use ufunc */", + "\treturn PyGenericArrType_Type.tp_as_number->nb_@oper@(a);", + "" + ] + } + } + ] + }, + { + "hash": "66e926b38691ace409835b8492a53f74121cb983", + "msg": "implemented @name@_ctype_nonzero in scalarmath", + "author": { + "name": "sasha", + "email": "sasha@localhost" + }, + "committer": { + "name": "sasha", + "email": "sasha@localhost" + }, + "author_date": "2006-04-27T20:08:06+00:00", + "author_timezone": 0, + "committer_date": "2006-04-27T20:08:06+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "c10618c8b35ee51475627289169caea1fc39c3af" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 0, + "insertions": 9, + "lines": 9, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -203,6 +203,15 @@ static void\n #define @name@_ctype_floor_divide @name@_cfloat_divide\n /**end repeat**/\n \n+/**begin repeat\n+ #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n+**/\n+void /* XXX: Non-zero should probably have Bool *out, not @name@ */\n+@name@_ctype_nonzero(@name@ a, @name@ *out)\n+{\n+ *out = (a != 0);\n+}\n+/**end repeat**/\n \n /**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n", + "added_lines": 9, + "deleted_lines": 0, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide @name@_cfloat_divide\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nvoid /* XXX: Non-zero should probably have Bool *out, not @name@ */\n@name@_ctype_nonzero(@name@ a, @name@ *out)\n{\n *out = (a != 0);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\nvoid\n@name@_ctype_invert(@name@ a, @name@ *out)\n{\n *out = ~a;\n}\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide @name@_cfloat_divide\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\nvoid\n@name@_ctype_invert(@name@ a, @name@ *out)\n{\n *out = ~a;\n}\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "/**begin repeat", + " #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#", + "**/", + "void /* XXX: Non-zero should probably have Bool *out, not @name@ */", + "@name@_ctype_nonzero(@name@ a, @name@ *out)", + "{", + " *out = (a != 0);", + "}", + "/**end repeat**/" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "f37d7f1909f7a6e18c541c853c2b126ef2854de7", + "msg": "Fixed up nonzero --- it doesn't need a ctype implementation anymore...", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-04-27T20:12:46+00:00", + "author_timezone": 0, + "committer_date": "2006-04-27T20:12:46+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "66e926b38691ace409835b8492a53f74121cb983" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 15, + "insertions": 1, + "lines": 16, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -203,24 +203,10 @@ static void\n #define @name@_ctype_floor_divide @name@_cfloat_divide\n /**end repeat**/\n \n-/**begin repeat\n- #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n-**/\n-void /* XXX: Non-zero should probably have Bool *out, not @name@ */\n-@name@_ctype_nonzero(@name@ a, @name@ *out)\n-{\n- *out = (a != 0);\n-}\n-/**end repeat**/\n-\n /**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n **/\n-void\n-@name@_ctype_invert(@name@ a, @name@ *out)\n-{\n- *out = ~a;\n-}\n+#define @name@_ctype_invert(a, out) *(out) = ~a;\n /**end repeat**/\n \n /*** END OF BASIC CODE **/\n", + "added_lines": 1, + "deleted_lines": 15, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide @name@_cfloat_divide\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide @name@_cfloat_divide\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nvoid /* XXX: Non-zero should probably have Bool *out, not @name@ */\n@name@_ctype_nonzero(@name@ a, @name@ *out)\n{\n *out = (a != 0);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\nvoid\n@name@_ctype_invert(@name@ a, @name@ *out)\n{\n *out = ~a;\n}\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "#define @name@_ctype_invert(a, out) *(out) = ~a;" + ], + "deleted": [ + "/**begin repeat", + " #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#", + "**/", + "void /* XXX: Non-zero should probably have Bool *out, not @name@ */", + "@name@_ctype_nonzero(@name@ a, @name@ *out)", + "{", + " *out = (a != 0);", + "}", + "/**end repeat**/", + "", + "void", + "@name@_ctype_invert(@name@ a, @name@ *out)", + "{", + " *out = ~a;", + "}" + ] + } + } + ] + }, + { + "hash": "77dfa4121ddec3518bc58553598f9b0f6750aa9c", + "msg": "implemented @name@_ctype_absolute in scalarmath", + "author": { + "name": "sasha", + "email": "sasha@localhost" + }, + "committer": { + "name": "sasha", + "email": "sasha@localhost" + }, + "author_date": "2006-04-27T20:33:09+00:00", + "author_timezone": 0, + "committer_date": "2006-04-27T20:33:09+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "f37d7f1909f7a6e18c541c853c2b126ef2854de7" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 0, + "insertions": 24, + "lines": 24, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -203,6 +203,30 @@ static void\n #define @name@_ctype_floor_divide @name@_cfloat_divide\n /**end repeat**/\n \n+#define NOP\n+/**begin repeat\n+ #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n+ #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n+**/\n+static void\n+@name@_ctype_absolute(@name@ a, @name@ *out)\n+{\n+ *out = @fun@(a);\n+}\n+/**end repeat**/\n+\n+/**begin repeat\n+ #name= cfloat, cdouble, clongdouble#\n+ #sqrt= sqrtf, sqrt, sqrtl#\n+**/\n+static void\n+@name@_ctype_absolute(@name@ a, @name@ *out)\n+{\n+ out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n+ out->imag = 0;\n+}\n+/**end repeat**/\n+\n /**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n **/\n", + "added_lines": 24, + "deleted_lines": 0, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide @name@_cfloat_divide\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide @name@_cfloat_divide\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "#define NOP", + "/**begin repeat", + " #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#", + " #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl#", + "**/", + "static void", + "@name@_ctype_absolute(@name@ a, @name@ *out)", + "{", + " *out = @fun@(a);", + "}", + "/**end repeat**/", + "", + "/**begin repeat", + " #name= cfloat, cdouble, clongdouble#", + " #sqrt= sqrtf, sqrt, sqrtl#", + "**/", + "static void", + "@name@_ctype_absolute(@name@ a, @name@ *out)", + "{", + " out->real = @sqrt@(a.real*a.real + a.imag*a.imag);", + " out->imag = 0;", + "}", + "/**end repeat**/", + "" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "a129ce4f8b4d8ff6910a476b5fa8e6c7e99b04ea", + "msg": "implemented @name@_ctype_(positive,negative) in scalarmath", + "author": { + "name": "sasha", + "email": "sasha@localhost" + }, + "committer": { + "name": "sasha", + "email": "sasha@localhost" + }, + "author_date": "2006-04-27T20:52:07+00:00", + "author_timezone": 0, + "committer_date": "2006-04-27T20:52:07+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "77dfa4121ddec3518bc58553598f9b0f6750aa9c" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 0, + "insertions": 31, + "lines": 31, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -203,6 +203,37 @@ static void\n #define @name@_ctype_floor_divide @name@_cfloat_divide\n /**end repeat**/\n \n+/**begin repeat\n+ #name=byte, short, int, long, longlong, float, double, longdouble#\n+**/\n+static void\n+@name@_ctype_negative(@name@ a, @name@ *out)\n+{\n+ *out = -a;\n+}\n+/**end repeat**/\n+\n+/**begin repeat\n+ #name= cfloat, cdouble, clongdouble#\n+**/\n+static void\n+@name@_ctype_negative(@name@ a, @name@ *out)\n+{\n+ out->real = -a.real;\n+ out->imag = -a.imag;\n+}\n+/**end repeat**/\n+\n+/**begin repeat\n+ #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n+**/\n+static void\n+@name@_ctype_positive(@name@ a, @name@ *out)\n+{\n+ *out = a;\n+}\n+/**end repeat**/\n+\n #define NOP\n /**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n", + "added_lines": 31, + "deleted_lines": 0, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide @name@_cfloat_divide\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide @name@_cfloat_divide\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "/**begin repeat", + " #name=byte, short, int, long, longlong, float, double, longdouble#", + "**/", + "static void", + "@name@_ctype_negative(@name@ a, @name@ *out)", + "{", + " *out = -a;", + "}", + "/**end repeat**/", + "", + "/**begin repeat", + " #name= cfloat, cdouble, clongdouble#", + "**/", + "static void", + "@name@_ctype_negative(@name@ a, @name@ *out)", + "{", + " out->real = -a.real;", + " out->imag = -a.imag;", + "}", + "/**end repeat**/", + "", + "/**begin repeat", + " #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#", + "**/", + "static void", + "@name@_ctype_positive(@name@ a, @name@ *out)", + "{", + " *out = a;", + "}", + "/**end repeat**/", + "" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "46abd33794766b162d6b60f15ef042630746e96a", + "msg": "implemented (float, double, longdouble)_ctype_power in scalarmath", + "author": { + "name": "sasha", + "email": "sasha@localhost" + }, + "committer": { + "name": "sasha", + "email": "sasha@localhost" + }, + "author_date": "2006-04-27T21:15:42+00:00", + "author_timezone": 0, + "committer_date": "2006-04-27T21:15:42+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "a129ce4f8b4d8ff6910a476b5fa8e6c7e99b04ea" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 0, + "insertions": 10, + "lines": 10, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -203,6 +203,16 @@ static void\n #define @name@_ctype_floor_divide @name@_cfloat_divide\n /**end repeat**/\n \n+/**begin repeat\n+ #name= float, double, longdouble#\n+ #fun= powf, pow, powl#\n+**/\n+static void\n+@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n+ *out = @fun@(a, b);\n+}\n+/**end repeat**/\n+\n /**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n **/\n", + "added_lines": 10, + "deleted_lines": 0, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide @name@_cfloat_divide\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide @name@_cfloat_divide\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "/**begin repeat", + " #name= float, double, longdouble#", + " #fun= powf, pow, powl#", + "**/", + "static void", + "@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {", + " *out = @fun@(a, b);", + "}", + "/**end repeat**/", + "" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "b31750988b97901c96bc5ff906ee281534753727", + "msg": "Add multiply and floor_divide", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-04-27T21:17:34+00:00", + "author_timezone": 0, + "committer_date": "2006-04-27T21:17:34+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "46abd33794766b162d6b60f15ef042630746e96a" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 2, + "insertions": 68, + "lines": 70, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -159,6 +159,46 @@ static void\n }\n /**end repeat**/\n \n+/**begin repeat\n+ #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n+ #big=(int,uint)*2,(longlong,ulonglong)*2#\n+ #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n+ #BIG=(INT,UINT)*2,(LONGLONG,ULONGLONG)*2#\n+ #neg=(1,0)*4#\n+ **/\n+#if SIZEOF_@BIG@ > SIZEOF_@NAME@\n+static void\n+@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n+ @big@ temp;\n+ temp = ((@big@) a) * ((@big@) b);\n+ *out = (@name@) temp;\n+#if @neg@\n+ if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n+#else\n+ if (temp > MAX_@NAME@) \n+#endif\n+ generate_overflow_error();\n+ return;\n+}\n+#endif\n+/**end repeat**/\n+\n+/**begin repeat\n+ #name=int,uint,long,ulong,longlong,ulonglong#\n+ #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n+ #char=(s,u)*3\n+ **/\n+#if SIZEOF_LONGLONG == SIZEOF_@NAME@\n+static void\n+@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n+ *out = a * b;\n+ if (@char@longlong_overflow(a, b))\n+ generate_overflow_error();\n+ return;\n+}\n+#endif\n+/**end repeat**/\n+\n /**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n@@ -167,20 +207,41 @@ static void\n #define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n /**end repeat**/\n \n+\n+\n+#ifndef HAVE_LONGDOUBLE_FUNCS\n+#ifdef floorl\n+#undef floorl\n+#endif\n+longdouble floorl(longdouble x) {\n+\treturn (longdouble) floor((double)x);\n+}\n+#endif\n+#ifndef HAVE_FLOOR_FUNCS\n+#ifdef floorf\n+#undef floorf\n+#endif\n+float floorf(float x) {\n+\treturn (float) floor((double)x);\n+}\n+#endif\n+\n /**begin repeat\n #name=float, double, longdouble#\n+ #c=f,,l#\n **/\n #define @name@_ctype_add(a, b, outp) *(outp) = a + b\n #define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n #define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n #define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n #define @name@_ctype_true_divide @name@_ctype_divide\n-#define @name@_ctype_floor_divide @name@_ctype_divide\n+#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n /**end repeat**/\n \n /**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n+ #c=f,,l#\n **/\n #define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n@@ -200,7 +261,12 @@ static void\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n #define @name@_ctype_true_divide @name@_cfloat_divide\n-#define @name@_ctype_floor_divide @name@_cfloat_divide\n+#define @name@_ctype_floor_divide(a, b, outp) do { \\\n+ @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n+ (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n+ ((a).real*(b).real + (b).imag*(b).imag); \\\n+ (outp)->imag = 0; \\\n+ }while(0)\n /**end repeat**/\n \n /**begin repeat\n", + "added_lines": 68, + "deleted_lines": 2, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #BIG=(INT,UINT)*2,(LONGLONG,ULONGLONG)*2#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@BIG@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n #char=(s,u)*3\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n\n\n#ifndef HAVE_LONGDOUBLE_FUNCS\n#ifdef floorl\n#undef floorl\n#endif\nlongdouble floorl(longdouble x) {\n\treturn (longdouble) floor((double)x);\n}\n#endif\n#ifndef HAVE_FLOOR_FUNCS\n#ifdef floorf\n#undef floorf\n#endif\nfloat floorf(float x) {\n\treturn (float) floor((double)x);\n}\n#endif\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide @name@_cfloat_divide\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "/**begin repeat", + " #name=byte,ubyte,short,ushort,int,uint,long,ulong#", + " #big=(int,uint)*2,(longlong,ulonglong)*2#", + " #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#", + " #BIG=(INT,UINT)*2,(LONGLONG,ULONGLONG)*2#", + " #neg=(1,0)*4#", + " **/", + "#if SIZEOF_@BIG@ > SIZEOF_@NAME@", + "static void", + "@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {", + " @big@ temp;", + " temp = ((@big@) a) * ((@big@) b);", + " *out = (@name@) temp;", + "#if @neg@", + " if (temp > MAX_@NAME@ || temp < MIN_@NAME@)", + "#else", + " if (temp > MAX_@NAME@)", + "#endif", + " generate_overflow_error();", + " return;", + "}", + "#endif", + "/**end repeat**/", + "", + "/**begin repeat", + " #name=int,uint,long,ulong,longlong,ulonglong#", + " #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#", + " #char=(s,u)*3", + " **/", + "#if SIZEOF_LONGLONG == SIZEOF_@NAME@", + "static void", + "@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {", + " *out = a * b;", + " if (@char@longlong_overflow(a, b))", + " generate_overflow_error();", + " return;", + "}", + "#endif", + "/**end repeat**/", + "", + "", + "", + "#ifndef HAVE_LONGDOUBLE_FUNCS", + "#ifdef floorl", + "#undef floorl", + "#endif", + "longdouble floorl(longdouble x) {", + "\treturn (longdouble) floor((double)x);", + "}", + "#endif", + "#ifndef HAVE_FLOOR_FUNCS", + "#ifdef floorf", + "#undef floorf", + "#endif", + "float floorf(float x) {", + "\treturn (float) floor((double)x);", + "}", + "#endif", + "", + " #c=f,,l#", + "#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))", + " #c=f,,l#", + "#define @name@_ctype_floor_divide(a, b, outp) do { \\", + " @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\", + " (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\", + " ((a).real*(b).real + (b).imag*(b).imag); \\", + " (outp)->imag = 0; \\", + " }while(0)" + ], + "deleted": [ + "#define @name@_ctype_floor_divide @name@_ctype_divide", + "#define @name@_ctype_floor_divide @name@_cfloat_divide" + ] + } + } + ] + }, + { + "hash": "81588c84e2b2193cb1d9b54758d2ffb9161cf951", + "msg": "Perhaps floor functions should be present", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-04-27T21:18:34+00:00", + "author_timezone": 0, + "committer_date": "2006-04-27T21:18:34+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "b31750988b97901c96bc5ff906ee281534753727" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 20, + "insertions": 1, + "lines": 21, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -109,7 +109,7 @@ static int slonglong_overflow(longlong a0, longlong b0)\n BINARY:\n \n add, subtract, multiply, divide, remainder, divmod, power, \n-floor_divide, true_divide\n+floor, divide, true_divide\n \n lshift, rshift, and, or, xor (integers only)\n \n@@ -207,25 +207,6 @@ static void\n #define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n /**end repeat**/\n \n-\n-\n-#ifndef HAVE_LONGDOUBLE_FUNCS\n-#ifdef floorl\n-#undef floorl\n-#endif\n-longdouble floorl(longdouble x) {\n-\treturn (longdouble) floor((double)x);\n-}\n-#endif\n-#ifndef HAVE_FLOOR_FUNCS\n-#ifdef floorf\n-#undef floorf\n-#endif\n-float floorf(float x) {\n-\treturn (float) floor((double)x);\n-}\n-#endif\n-\n /**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n", + "added_lines": 1, + "deleted_lines": 20, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor, divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #BIG=(INT,UINT)*2,(LONGLONG,ULONGLONG)*2#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@BIG@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n #char=(s,u)*3\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #BIG=(INT,UINT)*2,(LONGLONG,ULONGLONG)*2#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@BIG@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n #char=(s,u)*3\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n\n\n#ifndef HAVE_LONGDOUBLE_FUNCS\n#ifdef floorl\n#undef floorl\n#endif\nlongdouble floorl(longdouble x) {\n\treturn (longdouble) floor((double)x);\n}\n#endif\n#ifndef HAVE_FLOOR_FUNCS\n#ifdef floorf\n#undef floorf\n#endif\nfloat floorf(float x) {\n\treturn (float) floor((double)x);\n}\n#endif\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "floor, divide, true_divide" + ], + "deleted": [ + "floor_divide, true_divide", + "", + "", + "#ifndef HAVE_LONGDOUBLE_FUNCS", + "#ifdef floorl", + "#undef floorl", + "#endif", + "longdouble floorl(longdouble x) {", + "\treturn (longdouble) floor((double)x);", + "}", + "#endif", + "#ifndef HAVE_FLOOR_FUNCS", + "#ifdef floorf", + "#undef floorf", + "#endif", + "float floorf(float x) {", + "\treturn (float) floor((double)x);", + "}", + "#endif", + "" + ] + } + } + ] + }, + { + "hash": "a974a0667c20ffe6670db29843c2a75edf2d4d05", + "msg": "Fix typo", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-04-27T21:19:25+00:00", + "author_timezone": 0, + "committer_date": "2006-04-27T21:19:25+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "81588c84e2b2193cb1d9b54758d2ffb9161cf951" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 1, + "insertions": 1, + "lines": 2, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -186,7 +186,7 @@ static void\n /**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n- #char=(s,u)*3\n+ #char=(s,u)*3#\n **/\n #if SIZEOF_LONGLONG == SIZEOF_@NAME@\n static void\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor, divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #BIG=(INT,UINT)*2,(LONGLONG,ULONGLONG)*2#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@BIG@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n #char=(s,u)*3#\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor, divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #BIG=(INT,UINT)*2,(LONGLONG,ULONGLONG)*2#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@BIG@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n #char=(s,u)*3\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + " #char=(s,u)*3#" + ], + "deleted": [ + " #char=(s,u)*3" + ] + } + } + ] + }, + { + "hash": "18d4b43bec7390282ee944b673fbdc5b7779f4eb", + "msg": "Fix typo", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-04-27T21:20:51+00:00", + "author_timezone": 0, + "committer_date": "2006-04-27T21:20:51+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "a974a0667c20ffe6670db29843c2a75edf2d4d05" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 1, + "insertions": 1, + "lines": 2, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -241,7 +241,7 @@ static void\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n-#define @name@_ctype_true_divide @name@_cfloat_divide\n+#define @name@_ctype_true_divide @name@_ctype_divide\n #define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor, divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #BIG=(INT,UINT)*2,(LONGLONG,ULONGLONG)*2#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@BIG@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n #char=(s,u)*3#\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor, divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #BIG=(INT,UINT)*2,(LONGLONG,ULONGLONG)*2#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@BIG@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n #char=(s,u)*3#\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_cfloat_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "#define @name@_ctype_true_divide @name@_ctype_divide" + ], + "deleted": [ + "#define @name@_ctype_true_divide @name@_cfloat_divide" + ] + } + } + ] + }, + { + "hash": "1dc253cf87be58ed0d57c98d91ee8038750db94a", + "msg": "implemented (float,double,longdouble)_ctype_remainder", + "author": { + "name": "sasha", + "email": "sasha@localhost" + }, + "committer": { + "name": "sasha", + "email": "sasha@localhost" + }, + "author_date": "2006-04-28T02:07:40+00:00", + "author_timezone": 0, + "committer_date": "2006-04-28T02:07:40+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "18d4b43bec7390282ee944b673fbdc5b7779f4eb" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 0, + "insertions": 10, + "lines": 10, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -250,6 +250,16 @@ static void\n }while(0)\n /**end repeat**/\n \n+/**begin repeat\n+ #name=float,double,longdouble#\n+ #c=f,,l#\n+**/\n+static void \n+@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n+ *out = a - floor@c@(a/b)*b;\n+} \n+/**end repeat**/ \n+\n /**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n", + "added_lines": 10, + "deleted_lines": 0, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor, divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #BIG=(INT,UINT)*2,(LONGLONG,ULONGLONG)*2#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@BIG@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n #char=(s,u)*3#\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n #c=f,,l#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - floor@c@(a/b)*b;\n} \n/**end repeat**/ \n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor, divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #BIG=(INT,UINT)*2,(LONGLONG,ULONGLONG)*2#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@BIG@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n #char=(s,u)*3#\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "/**begin repeat", + " #name=float,double,longdouble#", + " #c=f,,l#", + "**/", + "static void", + "@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {", + " *out = a - floor@c@(a/b)*b;", + "}", + "/**end repeat**/", + "" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "1640c112ed63ee5251109a62e131e2ca0ac21f5a", + "msg": "implemented @name@_ctype_(l,r)shift", + "author": { + "name": "sasha", + "email": "sasha@localhost" + }, + "committer": { + "name": "sasha", + "email": "sasha@localhost" + }, + "author_date": "2006-04-28T03:01:16+00:00", + "author_timezone": 0, + "committer_date": "2006-04-28T03:01:16+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "1dc253cf87be58ed0d57c98d91ee8038750db94a" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 3, + "insertions": 3, + "lines": 6, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -200,9 +200,9 @@ static void\n /**end repeat**/\n \n /**begin repeat\n- #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n- #oper=and*10, xor*10, or*10#\n- #op=&*10, ^*10, |*10#\n+ #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n+ #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n+ #op=&*10, ^*10, |*10, <<*10, >>*10#\n **/\n #define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n /**end repeat**/\n", + "added_lines": 3, + "deleted_lines": 3, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor, divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #BIG=(INT,UINT)*2,(LONGLONG,ULONGLONG)*2#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@BIG@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n #char=(s,u)*3#\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n #c=f,,l#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - floor@c@(a/b)*b;\n} \n/**end repeat**/ \n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor, divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #BIG=(INT,UINT)*2,(LONGLONG,ULONGLONG)*2#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@BIG@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n #char=(s,u)*3#\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#\n #oper=and*10, xor*10, or*10#\n #op=&*10, ^*10, |*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n #c=f,,l#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - floor@c@(a/b)*b;\n} \n/**end repeat**/ \n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + " #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#", + " #oper=and*10, xor*10, or*10, lshift*10, rshift*10#", + " #op=&*10, ^*10, |*10, <<*10, >>*10#" + ], + "deleted": [ + " #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*3#", + " #oper=and*10, xor*10, or*10#", + " #op=&*10, ^*10, |*10#" + ] + } + } + ] + }, + { + "hash": "6172e536a2cbf76fd7ff8b947db11c4542998fdd", + "msg": "Add ctype_true_divide, ctype_divide, and ctype_floor_divide for integers.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-04-28T03:48:17+00:00", + "author_timezone": 0, + "committer_date": "2006-04-28T03:48:17+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "1640c112ed63ee5251109a62e131e2ca0ac21f5a" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 5, + "insertions": 31, + "lines": 36, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -163,10 +163,10 @@ static void\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n- #BIG=(INT,UINT)*2,(LONGLONG,ULONGLONG)*2#\n+ #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n **/\n-#if SIZEOF_@BIG@ > SIZEOF_@NAME@\n+#if SIZEOF_@SIZE@ > SIZEOF_@NAME@\n static void\n @name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n@@ -185,10 +185,10 @@ static void\n \n /**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n- #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n+ #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n **/\n-#if SIZEOF_LONGLONG == SIZEOF_@NAME@\n+#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\n static void\n @name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n@@ -199,6 +199,31 @@ static void\n #endif\n /**end repeat**/\n \n+/**begin repeat\n+ #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n+ **/\n+static void\n+@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n+\tif (b == 0) {\n+\t\tgenerate_divbyzero_error();\n+\t\t*out = 0;\n+\t}\n+\telse {\n+\t\t*out = a / b;\n+\t}\n+}\n+#define @name@_ctype_floor_divide @name@_ctype_divide\n+/**end repeat**/\n+\n+\n+/**begin repeat\n+ #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n+ #otyp=float*4, double*6#\n+ **/\n+#define @name@_ctype_true_divide(a, b, out)\t\\\n+\t*(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n+/**end repeat**/\n+\n /**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n@@ -400,9 +425,10 @@ _@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1,\n /**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n- #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n+ #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, lshift*10, rshift*10, true_divide*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n+ #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n **/\n \n #if @power@\n", + "added_lines": 31, + "deleted_lines": 5, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor, divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@SIZE@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n **/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n\tif (b == 0) {\n\t\tgenerate_divbyzero_error();\n\t\t*out = 0;\n\t}\n\telse {\n\t\t*out = a / b;\n\t}\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n **/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n\t*(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n #c=f,,l#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - floor@c@(a/b)*b;\n} \n/**end repeat**/ \n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, lshift*10, rshift*10, true_divide*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor, divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #BIG=(INT,UINT)*2,(LONGLONG,ULONGLONG)*2#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@BIG@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n #char=(s,u)*3#\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n #c=f,,l#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - floor@c@(a/b)*b;\n} \n/**end repeat**/ \n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + " #SIZE=INT*4,LONGLONG*4#", + "#if SIZEOF_@SIZE@ > SIZEOF_@NAME@", + " #SIZE=INT*2,LONG*2,LONGLONG*2#", + "#if SIZEOF_LONGLONG == SIZEOF_@SIZE@", + "/**begin repeat", + " #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#", + " **/", + "static void", + "@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {", + "\tif (b == 0) {", + "\t\tgenerate_divbyzero_error();", + "\t\t*out = 0;", + "\t}", + "\telse {", + "\t\t*out = a / b;", + "\t}", + "}", + "#define @name@_ctype_floor_divide @name@_ctype_divide", + "/**end repeat**/", + "", + "", + "/**begin repeat", + " #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#", + " #otyp=float*4, double*6#", + " **/", + "#define @name@_ctype_true_divide(a, b, out)\t\\", + "\t*(out) = ((@otyp@) (a)) / ((@otyp@) (b));", + "/**end repeat**/", + "", + " #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, lshift*10, rshift*10, true_divide*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#", + " #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#" + ], + "deleted": [ + " #BIG=(INT,UINT)*2,(LONGLONG,ULONGLONG)*2#", + "#if SIZEOF_@BIG@ > SIZEOF_@NAME@", + " #NAME=INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#", + "#if SIZEOF_LONGLONG == SIZEOF_@NAME@", + " #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, true_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#" + ] + } + } + ] + }, + { + "hash": "ed4b92a17d3972d5537396344a4880ea0cfc1da2", + "msg": "Fix true_divide for integers.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-04-28T03:50:37+00:00", + "author_timezone": 0, + "committer_date": "2006-04-28T03:50:37+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "6172e536a2cbf76fd7ff8b947db11c4542998fdd" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 4, + "insertions": 6, + "lines": 10, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -425,10 +425,11 @@ _@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1,\n /**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n- #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, lshift*10, rshift*10, true_divide*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n+ #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n+ #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n **/\n \n #if @power@\n@@ -440,7 +441,8 @@ static PyObject *\n #endif\n {\n PyObject *ret;\n- @name@ arg1, arg2, out;\n+ @name@ arg1, arg2;\n+ @otyp@ out;\n #if @fperr@\n int retstatus;\n #endif \n@@ -481,8 +483,8 @@ static PyObject *\n \t return NULL;\n }\n #endif\n- ret = PyArrayScalar_New(@Name@);\n- PyArrayScalar_VAL(ret, @Name@) = out;\n+ ret = PyArrayScalar_New(@OName@);\n+ PyArrayScalar_VAL(ret, @OName@) = out;\n return ret;\n }\n /**end repeat**/\n", + "added_lines": 6, + "deleted_lines": 4, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor, divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@SIZE@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n **/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n\tif (b == 0) {\n\t\tgenerate_divbyzero_error();\n\t\t*out = 0;\n\t}\n\telse {\n\t\t*out = a / b;\n\t}\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n **/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n\t*(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n #c=f,,l#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - floor@c@(a/b)*b;\n} \n/**end repeat**/ \n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@OName@);\n PyArrayScalar_VAL(ret, @OName@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor, divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@SIZE@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n **/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n\tif (b == 0) {\n\t\tgenerate_divbyzero_error();\n\t\t*out = 0;\n\t}\n\telse {\n\t\t*out = a / b;\n\t}\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n **/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n\t*(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n #c=f,,l#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - floor@c@(a/b)*b;\n} \n/**end repeat**/ \n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, lshift*10, rshift*10, true_divide*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + " #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#", + " #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#", + " @name@ arg1, arg2;", + " @otyp@ out;", + " ret = PyArrayScalar_New(@OName@);", + " PyArrayScalar_VAL(ret, @OName@) = out;" + ], + "deleted": [ + " #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, lshift*10, rshift*10, true_divide*10, and*10, or*10, xor*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#", + " @name@ arg1, arg2, out;", + " ret = PyArrayScalar_New(@Name@);", + " PyArrayScalar_VAL(ret, @Name@) = out;" + ] + } + } + ] + }, + { + "hash": "638ed060ef7a79e3892ef4d2db4444cf2794d193", + "msg": "Implement divmod", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-04-28T04:15:10+00:00", + "author_timezone": 0, + "committer_date": "2006-04-28T04:15:10+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "ed4b92a17d3972d5537396344a4880ea0cfc1da2" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 1, + "insertions": 41, + "lines": 42, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -201,6 +201,7 @@ static void\n \n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n+ #neg=(1,0)*2#\n **/\n static void\n @name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n@@ -208,6 +209,12 @@ static void\n \t\tgenerate_divbyzero_error();\n \t\t*out = 0;\n \t}\n+#if @neg@\n+\telse if (b == -1 && a < 0 && a == -a) {\n+\t\tgenerate_overflow_error();\n+\t\t*out = a / b;\n+\t}\n+#endif\n \telse {\n \t\t*out = a / b;\n \t}\n@@ -215,7 +222,6 @@ static void\n #define @name@_ctype_floor_divide @name@_ctype_divide\n /**end repeat**/\n \n-\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n@@ -285,6 +291,15 @@ static void\n } \n /**end repeat**/ \n \n+/**begin repeat\n+ #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n+ **/\n+#define @name@_ctype_divmod(a, b, out, out2) {\t\\\n+\t@name@_ctype_floor_divide(a, b, out);\t\\\n+\t@name@_ctype_remainder(a, b, out2);\t\\\n+\t}\n+/**end repeat**/\n+\n /**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n@@ -428,6 +443,7 @@ _@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1,\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n+ #twoout=0*50,1*10,0*110,1*6,0*18#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n **/\n@@ -443,6 +459,11 @@ static PyObject *\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n+#if @twoout@\n+ @otyp@ out2;\n+ PyObject *obj;\n+#endif\n+\n #if @fperr@\n int retstatus;\n #endif \n@@ -468,7 +489,11 @@ static PyObject *\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n+#if @twoout@\n+ @name@_ctype_@oper@(arg1, arg2, &out, &out2);\n+#else\n @name@_ctype_@oper@(arg1, arg2, &out);\n+#endif\n \n #if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n@@ -483,8 +508,23 @@ static PyObject *\n \t return NULL;\n }\n #endif\n+\n+#if @tupout@\n+ ret = PyTuple_New(2);\n+ if (ret==NULL) return NULL;\n+ obj = PyArrayScalar_New(@OName@);\n+ if (obj == NULL) {Py_DECREF(ret); return;}\n+ PyArrayScalar_VAL(ret, @OName@) = out;\n+ PyTuple_SET_ITEM(ret, 0, obj);\n+ obj = PyArrayScalar_New(@OName@);\n+ if (obj == NULL) {Py_DECREF(ret); return;}\n+ PyArrayScalar_VAL(ret, @OName@) = out2;\n+ PyTuple_SET_ITEM(ret, 1, obj);\n+#else\n ret = PyArrayScalar_New(@OName@);\n+ if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @OName@) = out;\n+#endif\n return ret;\n }\n /**end repeat**/\n", + "added_lines": 41, + "deleted_lines": 1, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor, divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@SIZE@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #neg=(1,0)*2#\n **/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n\tif (b == 0) {\n\t\tgenerate_divbyzero_error();\n\t\t*out = 0;\n\t}\n#if @neg@\n\telse if (b == -1 && a < 0 && a == -a) {\n\t\tgenerate_overflow_error();\n\t\t*out = a / b;\n\t}\n#endif\n\telse {\n\t\t*out = a / b;\n\t}\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n **/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n\t*(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n #c=f,,l#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - floor@c@(a/b)*b;\n} \n/**end repeat**/ \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n **/\n#define @name@_ctype_divmod(a, b, out, out2) {\t\\\n\t@name@_ctype_floor_divide(a, b, out);\t\\\n\t@name@_ctype_remainder(a, b, out2);\t\\\n\t}\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n #twoout=0*50,1*10,0*110,1*6,0*18#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @twoout@\n @otyp@ out2;\n PyObject *obj;\n#endif\n\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @twoout@\n @name@_ctype_@oper@(arg1, arg2, &out, &out2);\n#else\n @name@_ctype_@oper@(arg1, arg2, &out);\n#endif\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n\n#if @tupout@\n ret = PyTuple_New(2);\n if (ret==NULL) return NULL;\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return;}\n PyArrayScalar_VAL(ret, @OName@) = out;\n PyTuple_SET_ITEM(ret, 0, obj);\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return;}\n PyArrayScalar_VAL(ret, @OName@) = out2;\n PyTuple_SET_ITEM(ret, 1, obj);\n#else\n ret = PyArrayScalar_New(@OName@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @OName@) = out;\n#endif\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor, divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@SIZE@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n **/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n\tif (b == 0) {\n\t\tgenerate_divbyzero_error();\n\t\t*out = 0;\n\t}\n\telse {\n\t\t*out = a / b;\n\t}\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n **/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n\t*(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n #c=f,,l#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - floor@c@(a/b)*b;\n} \n/**end repeat**/ \n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n @name@_ctype_@oper@(arg1, arg2, &out);\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n ret = PyArrayScalar_New(@OName@);\n PyArrayScalar_VAL(ret, @OName@) = out;\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + " #neg=(1,0)*2#", + "#if @neg@", + "\telse if (b == -1 && a < 0 && a == -a) {", + "\t\tgenerate_overflow_error();", + "\t\t*out = a / b;", + "\t}", + "#endif", + "/**begin repeat", + " #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#", + " **/", + "#define @name@_ctype_divmod(a, b, out, out2) {\t\\", + "\t@name@_ctype_floor_divide(a, b, out);\t\\", + "\t@name@_ctype_remainder(a, b, out2);\t\\", + "\t}", + "/**end repeat**/", + "", + " #twoout=0*50,1*10,0*110,1*6,0*18#", + "#if @twoout@", + " @otyp@ out2;", + " PyObject *obj;", + "#endif", + "", + "#if @twoout@", + " @name@_ctype_@oper@(arg1, arg2, &out, &out2);", + "#else", + "#endif", + "", + "#if @tupout@", + " ret = PyTuple_New(2);", + " if (ret==NULL) return NULL;", + " obj = PyArrayScalar_New(@OName@);", + " if (obj == NULL) {Py_DECREF(ret); return;}", + " PyArrayScalar_VAL(ret, @OName@) = out;", + " PyTuple_SET_ITEM(ret, 0, obj);", + " obj = PyArrayScalar_New(@OName@);", + " if (obj == NULL) {Py_DECREF(ret); return;}", + " PyArrayScalar_VAL(ret, @OName@) = out2;", + " PyTuple_SET_ITEM(ret, 1, obj);", + "#else", + " if (ret==NULL) return NULL;", + "#endif" + ], + "deleted": [ + "" + ] + } + } + ] + }, + { + "hash": "37b177864b0d4a5fa5add75a64b020db6cf533a4", + "msg": "Finish up scalarmath. Needs testing...", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-04-28T06:49:01+00:00", + "author_timezone": 0, + "committer_date": "2006-04-28T06:49:01+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "638ed060ef7a79e3892ef4d2db4444cf2794d193" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 83, + "insertions": 279, + "lines": 362, + "files": 3, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "THANKS.txt", + "new_path": "THANKS.txt", + "filename": "THANKS.txt", + "extension": "txt", + "change_type": "MODIFY", + "diff": "@@ -14,7 +14,7 @@ Travis Vaught and Joe Cooper for administration of numpy.org web site and SVN\n Eric Firing for bugfixes.\n Arnd Baecker for 64-bit testing\n David Cooke for many code improvements including the auto-generated C-API, and optimizations.\n-Alexander Belopolsky (Sasha) for Masked array bug-fixes and tests and rank-0 array improvements and other code additions\n+Alexander Belopolsky (Sasha) for Masked array bug-fixes and tests, rank-0 array improvements, scalar math help and other code additions\n Francesc Altet for unicode and nested record tests and help with nested records\n Tim Hochberg for getting the build working on MSVC, optimization improvements, and code review\n Charles Harris for the sorting code originally written for Numarray.\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "Travis Oliphant for the majority of code adaptation\nJim Hugunin, Paul Dubois, Konrad Hinsen, David Ascher, and many others for \n Numeric on which the code is based.\nPerry Greenfield, J Todd Miller, Rick White, Paul Barrett for Numarray\n which gave much inspiration and showed the way forward.\nPaul Dubois for Masked Arrays\nPearu Peterson for f2py and distutils and help with code organization\nRobert Kern for mtrand, bug fixes, help with distutils, and code organization\nEric Jones for sundry subroutines\nFernando Perez for code snippets, ideas, bufixes, and testing.\nJohn Hunter for code snippets (from matplotlib)\nChris Hanley for help with records.py, testing, and bug fixes.\nTravis Vaught and Joe Cooper for administration of numpy.org web site and SVN \nEric Firing for bugfixes.\nArnd Baecker for 64-bit testing\nDavid Cooke for many code improvements including the auto-generated C-API, and optimizations.\nAlexander Belopolsky (Sasha) for Masked array bug-fixes and tests, rank-0 array improvements, scalar math help and other code additions\nFrancesc Altet for unicode and nested record tests and help with nested records\nTim Hochberg for getting the build working on MSVC, optimization improvements, and code review\nCharles Harris for the sorting code originally written for Numarray.\n", + "source_code_before": "Travis Oliphant for the majority of code adaptation\nJim Hugunin, Paul Dubois, Konrad Hinsen, David Ascher, and many others for \n Numeric on which the code is based.\nPerry Greenfield, J Todd Miller, Rick White, Paul Barrett for Numarray\n which gave much inspiration and showed the way forward.\nPaul Dubois for Masked Arrays\nPearu Peterson for f2py and distutils and help with code organization\nRobert Kern for mtrand, bug fixes, help with distutils, and code organization\nEric Jones for sundry subroutines\nFernando Perez for code snippets, ideas, bufixes, and testing.\nJohn Hunter for code snippets (from matplotlib)\nChris Hanley for help with records.py, testing, and bug fixes.\nTravis Vaught and Joe Cooper for administration of numpy.org web site and SVN \nEric Firing for bugfixes.\nArnd Baecker for 64-bit testing\nDavid Cooke for many code improvements including the auto-generated C-API, and optimizations.\nAlexander Belopolsky (Sasha) for Masked array bug-fixes and tests and rank-0 array improvements and other code additions\nFrancesc Altet for unicode and nested record tests and help with nested records\nTim Hochberg for getting the build working on MSVC, optimization improvements, and code review\nCharles Harris for the sorting code originally written for Numarray.\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "Alexander Belopolsky (Sasha) for Masked array bug-fixes and tests, rank-0 array improvements, scalar math help and other code additions" + ], + "deleted": [ + "Alexander Belopolsky (Sasha) for Masked array bug-fixes and tests and rank-0 array improvements and other code additions" + ] + } + }, + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -109,7 +109,7 @@ static int slonglong_overflow(longlong a0, longlong b0)\n BINARY:\n \n add, subtract, multiply, divide, remainder, divmod, power, \n-floor, divide, true_divide\n+floor_divide, true_divide\n \n lshift, rshift, and, or, xor (integers only)\n \n@@ -165,20 +165,20 @@ static void\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n- **/\n+**/\n #if SIZEOF_@SIZE@ > SIZEOF_@NAME@\n static void\n @name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n- @big@ temp;\n- temp = ((@big@) a) * ((@big@) b);\n- *out = (@name@) temp;\n+ @big@ temp;\n+ temp = ((@big@) a) * ((@big@) b);\n+ *out = (@name@) temp;\n #if @neg@\n- if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n+ if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n #else\n if (temp > MAX_@NAME@) \n #endif\n- generate_overflow_error();\n- return;\n+\t generate_overflow_error();\n+ return;\n }\n #endif\n /**end repeat**/\n@@ -187,67 +187,100 @@ static void\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n- **/\n+**/\n #if SIZEOF_LONGLONG == SIZEOF_@SIZE@\n static void\n @name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n- *out = a * b;\n- if (@char@longlong_overflow(a, b))\n- generate_overflow_error();\n- return;\n+ *out = a * b;\n+ if (@char@longlong_overflow(a, b))\n+\tgenerate_overflow_error();\n+ return;\n }\n #endif\n /**end repeat**/\n \n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n- #neg=(1,0)*2#\n- **/\n+ #neg=(1,0)*5#\n+**/\n static void\n @name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n-\tif (b == 0) {\n-\t\tgenerate_divbyzero_error();\n-\t\t*out = 0;\n-\t}\n+ if (b == 0) {\n+\tgenerate_divbyzero_error();\n+\t*out = 0;\n+ }\n #if @neg@\n-\telse if (b == -1 && a < 0 && a == -a) {\n-\t\tgenerate_overflow_error();\n-\t\t*out = a / b;\n-\t}\n+ else if (b == -1 && a < 0 && a == -a) {\n+\tgenerate_overflow_error();\n+\t*out = a / b;\n+ }\n #endif\n-\telse {\n-\t\t*out = a / b;\n-\t}\n+ else {\n+\t*out = a / b;\n+ }\n }\n #define @name@_ctype_floor_divide @name@_ctype_divide\n+static void\n+@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {\n+ if (a == 0 || b == 0) {\n+\tif (b == 0) generate_divbyzero_error();\n+\t*out = 0;\n+ }\n+#if @neg@\n+ else if ((a > 0) == (b > 0)) {\n+\t*out = a % b;\n+ }\n+ else { /* handled like Python does */\n+\t*out = a % b;\n+\tif (*out) *out += b;\n+ }\n+#else\n+ *out = a % b;\n+#endif\n+}\n /**end repeat**/\n \n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n- **/\n+**/\n #define @name@_ctype_true_divide(a, b, out)\t\\\n-\t*(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n+ *(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n+/**end repeat**/\n+\n+/* b will always be positive in this call */\n+/**begin repeat\n+ #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n+**/\n+static void\n+@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n+ \n+}\n /**end repeat**/\n \n+\n+\n+/* QUESTION: Should we check for overflow / underflow in (l,r)shift? */\n+\n /**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n- **/\n+**/\n #define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n /**end repeat**/\n \n /**begin repeat\n #name=float, double, longdouble#\n- #c=f,,l#\n **/\n+static @name@ (*_basic_@name@_floor)(@name@);\n #define @name@_ctype_add(a, b, outp) *(outp) = a + b\n #define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n #define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n #define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n #define @name@_ctype_true_divide @name@_ctype_divide\n-#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n+#define @name@_ctype_floor_divide(a, b, outp) \\\n+ *(outp) = _basic_@name@_floor((a) / (b))\n /**end repeat**/\n \n /**begin repeat\n@@ -255,13 +288,13 @@ static void\n #rtype=float, double, longdouble#\n #c=f,,l#\n **/\n-#define @name@_ctype_add(a, b, outp) do{\t\t\\\n- (outp)->real = (a).real + (b).real;\t\t\t\\\n- (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n+#define @name@_ctype_add(a, b, outp) do{\t\\\n+ (outp)->real = (a).real + (b).real;\t\t\\\n+ (outp)->imag = (a).imag + (b).imag;\t\t\\\n }while(0)\n-#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n- (outp)->real = (a).real - (b).real;\t\t\t\\\n- (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n+#define @name@_ctype_subtract(a, b, outp) do{\t\\\n+ (outp)->real = (a).real - (b).real;\t\t\\\n+ (outp)->imag = (a).imag - (b).imag;\t\t\\\n }while(0)\n #define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n@@ -273,53 +306,58 @@ static void\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n #define @name@_ctype_true_divide @name@_ctype_divide\n-#define @name@_ctype_floor_divide(a, b, outp) do { \\\n- @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n- (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n- ((a).real*(b).real + (b).imag*(b).imag); \\\n- (outp)->imag = 0; \\\n- }while(0)\n+#define @name@_ctype_floor_divide(a, b, outp) do {\t\t\\\n+ (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) /\t\\\n+ ((a).real*(b).real + (b).imag*(b).imag);\t\t\t\\\n+ (outp)->imag = 0;\t\t\t\t\t\t\\\n+ }while(0)\n /**end repeat**/\n \n /**begin repeat\n #name=float,double,longdouble#\n- #c=f,,l#\n **/\n static void \n @name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n- *out = a - floor@c@(a/b)*b;\n+ *out = a - _basic_@name@_floor(a/b)*b;\n } \n /**end repeat**/ \n \n+\n+\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n- **/\n+**/\n #define @name@_ctype_divmod(a, b, out, out2) {\t\\\n-\t@name@_ctype_floor_divide(a, b, out);\t\\\n-\t@name@_ctype_remainder(a, b, out2);\t\\\n-\t}\n+ @name@_ctype_floor_divide(a, b, out);\t\\\n+ @name@_ctype_remainder(a, b, out2);\t\t\\\n+ }\n /**end repeat**/\n \n /**begin repeat\n #name= float, double, longdouble#\n- #fun= powf, pow, powl#\n **/\n+static @name@ (*_basic_@name@_pow)(@name@ a, @name@ b);\n static void\n @name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n- *out = @fun@(a, b);\n+ *out = _basic_@name@_pow(a, b);\n }\n /**end repeat**/\n \n /**begin repeat\n- #name=byte, short, int, long, longlong, float, double, longdouble#\n+ #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n+ #uns=(1,0)*5,0*3#\n **/\n static void\n @name@_ctype_negative(@name@ a, @name@ *out)\n {\n+#if @uns@\n+ generate_overflow_error();\n+#endif\n *out = -a;\n }\n /**end repeat**/\n \n+\n /**begin repeat\n #name= cfloat, cdouble, clongdouble#\n **/\n@@ -341,6 +379,30 @@ static void\n }\n /**end repeat**/\n \n+/* Get the nc_powf, nc_pow, and nc_powl functions from \n+ the data area of the power ufunc in umathmodule. \n+*/\n+\n+\n+/**begin repeat\n+ #name=cfloat, cdouble, clongdouble#\n+**/\n+static void\n+@name@_ctype_positive(@name@ a, @name@ *out)\n+{\n+ out->real = a.real;\n+ out->imag = a.imag;\n+}\n+static void (*_basic_@name@_pow)(@name@ *, @name@ *, @name@ *);\n+static void\n+@name@_ctype_power(@name@ a, @name@ b, @name@ *out)\n+{\n+ _basic_@name@_pow(&a, &b, out);\n+}\n+/**end repeat**/\n+\n+\n+\n #define NOP\n /**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n@@ -438,23 +500,17 @@ _@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1,\n /**end repeat**/\n \n /**begin repeat\n- #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n- #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n- #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n- #fperr=1*110,0*30,1*54#\n- #power=0*60,1*10,0*106,1*6,0*12#\n- #twoout=0*50,1*10,0*110,1*6,0*18#\n- #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n- #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n+ #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n+ #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n+ #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, floor_divide*6, true_divide*6, divmod*3, remainder*3#\n+ #fperr=1*70,0*50,1*52#\n+ #twoout=0*50,1*10,0*106,1*3,0*3#\n+ #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*12, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n+ #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*12, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n **/\n \n-#if @power@\n-static PyObject *\n-@name@_power(PyObject *a, PyObject *b, PyObject *c)\n-#else\n static PyObject *\n @name@_@oper@(PyObject *a, PyObject *b)\n-#endif\n {\n PyObject *ret;\n @name@ arg1, arg2;\n@@ -476,11 +532,7 @@ static PyObject *\n return Py_NotImplemented;\n case -2: /* use default handling */\n \tif (PyErr_Occurred()) return NULL;\n-#if @power@\n- return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n-#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n-#endif\n }\n \n #if @fperr@\n@@ -509,15 +561,15 @@ static PyObject *\n }\n #endif\n \n-#if @tupout@\n+#if @twoout@\n ret = PyTuple_New(2);\n if (ret==NULL) return NULL;\n obj = PyArrayScalar_New(@OName@);\n- if (obj == NULL) {Py_DECREF(ret); return;}\n+ if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out;\n PyTuple_SET_ITEM(ret, 0, obj);\n obj = PyArrayScalar_New(@OName@);\n- if (obj == NULL) {Py_DECREF(ret); return;}\n+ if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out2;\n PyTuple_SET_ITEM(ret, 1, obj);\n #else\n@@ -529,6 +581,98 @@ static PyObject *\n }\n /**end repeat**/\n \n+/**begin repeat\n+ #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float, double, longdouble, cfloat, cdouble, clongdouble#\n+ #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n+ #otyp=float*4, double*6, float, double, longdouble, cfloat, cdouble, clongdouble#\n+ #OName=Float*4, Double*6, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n+ #isint=(1,0)*5,0*6#\n+ #cmplx=0*13,1*3#\n+**/\n+\n+static PyObject *\n+@name@_power(PyObject *a, PyObject *b, PyObject *c)\n+{\n+ PyObject *ret;\n+ @name@ arg1, arg2, out;\n+ @otyp@ out1;\n+ int retstatus;\n+\t\n+ switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n+ case 0:\n+ break;\n+ case -1: /* can't cast both safely use different add function */\n+ Py_INCREF(Py_NotImplemented);\n+ return Py_NotImplemented;\n+ case -2: /* use default handling */\n+\tif (PyErr_Occurred()) return NULL;\n+ return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n+ }\n+\n+ PyUFunc_clearfperr();\n+\n+ /* here we do the actual calculation with arg1 and arg2 */\n+ /* as a function call. */\n+#if @cmplx@\n+ if (arg2.real == 0 && arg1.real == 0) {\n+\tout1.real = out.real = 1.0;\n+\tout1.imag = out.imag = 0.0;\n+ }\n+#else\n+ if (arg2 == 0) {\n+\tout1 = out = 1;\n+ } \n+#endif\n+#if @isint@\n+ else if (arg2 < 0) {\n+\t@name@_ctype_power(arg1, -arg2, &out);\n+\tout1 = 1.0 / out;\n+ }\n+#endif\n+ else {\n+\t@name@_ctype_power(arg1, arg2, &out);\n+ }\n+\n+ /* Check status flag. If it is set, then look up what to do */\n+ retstatus = PyUFunc_getfperr();\n+ if (retstatus) {\n+\tint bufsize, errmask;\n+\tPyObject *errobj;\n+\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n+\t\t\t\t&errobj) < 0) \n+\t return NULL;\n+\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n+\t return NULL;\n+ }\n+\n+#if @isint@\n+ if (arg2 < 0) {\n+\tret = PyArrayScalar_New(@OName@);\n+\tif (ret==NULL) return NULL;\n+\tPyArrayScalar_VAL(ret, @OName@) = out1;\n+ }\n+ else {\n+\tret = PyArrayScalar_New(@Name@);\n+\tif (ret==NULL) return NULL;\n+\tPyArrayScalar_VAL(ret, @Name@) = out;\n+ }\n+#else\n+ ret = PyArrayScalar_New(@Name@);\n+ if (ret==NULL) return NULL;\n+ PyArrayScalar_VAL(ret, @Name@) = out;\n+#endif\n+ \n+ return ret;\n+}\n+/**end repeat**/\n+\n+\n+/**begin repeat\n+#name=(cfloat,cdouble,clongdouble)*2#\n+#oper=divmod*3,remainder*3#\n+**/\n+#define @name@_@oper@ NULL\n+/**end repeat**/\n \n /**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n@@ -539,9 +683,9 @@ static PyObject *\n \n \n /**begin repeat\n- #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n- #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n- #oper=negative*16, positive*16, absolute*16, invert*16#\n+ #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3, byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n+ #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*3, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n+ #oper=negative*16, positive*16, absolute*16, invert*10#\n **/\n static PyObject *\n @name@_@oper@(PyObject *a)\n@@ -572,6 +716,11 @@ static PyObject *\n }\n /**end repeat**/\n \n+/**begin repeat\n+#name=float,double,longdouble,cfloat,cdouble,clongdouble#\n+**/\n+#define @name@_invert NULL\n+/**end repeat**/\n \n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n@@ -745,6 +894,57 @@ add_scalarmath(void)\n /**end repeat**/\n }\n \n+static int\n+get_functions(void)\n+{\n+ PyObject *mm, *obj;\n+ void **funcdata;\n+ char *signatures;\n+ int i, j;\n+\t\n+ /* Get the nc_pow functions */\n+ /* Get the pow functions */\n+ mm = PyImport_ImportModule(\"numpy.core.umath\");\n+ if (mm == NULL) return -1;\n+ \n+ obj = PyObject_GetAttrString(mm, \"power\");\n+ if (obj == NULL) goto fail;\n+ funcdata = ((PyUFuncObject *)obj)->data;\n+ signatures = ((PyUFuncObject *)obj)->types;\n+ \n+ i = 0;\n+ j = 0;\n+ while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n+ _basic_float_pow = funcdata[j];\n+ _basic_double_pow = funcdata[j+1];\n+ _basic_longdouble_pow = funcdata[j+2];\n+ _basic_cfloat_pow = funcdata[j+3];\n+ _basic_cdouble_pow = funcdata[j+4];\n+ _basic_clongdouble_pow = funcdata[j+5];\n+\n+ Py_DECREF(obj);\n+\n+ /* Get the floor functions */\n+\n+ obj = PyObject_GetAttrString(mm, \"floor\");\n+ if (obj == NULL) goto fail;\n+ funcdata = ((PyUFuncObject *)obj)->data;\n+ signatures = ((PyUFuncObject *)obj)->types;\n+ \n+ i = 0;\n+ j = 0;\n+ while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n+ _basic_float_floor = funcdata[j];\n+ _basic_double_floor = funcdata[j+1];\n+ _basic_longdouble_floor = funcdata[j+2];\n+\n+ Py_DECREF(obj);\n+ \n+ fail:\n+ Py_DECREF(mm);\n+ return -1;\n+}\n+\n static void *saved_tables[9];\n \n char doc_alterpyscalars[] = \"\";\n@@ -833,6 +1033,8 @@ PyMODINIT_FUNC initscalarmath(void) {\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n \n+ if (get_functions() < 0) return;\n+\n add_scalarmath();\n \n saved_tables[0] = PyInt_Type.tp_as_number;\n", + "added_lines": 277, + "deleted_lines": 75, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n**/\n#if SIZEOF_@SIZE@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n\t generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n**/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n\tgenerate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #neg=(1,0)*5#\n**/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n if (b == 0) {\n\tgenerate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if (b == -1 && a < 0 && a == -a) {\n\tgenerate_overflow_error();\n\t*out = a / b;\n }\n#endif\n else {\n\t*out = a / b;\n }\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\nstatic void\n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {\n if (a == 0 || b == 0) {\n\tif (b == 0) generate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if ((a > 0) == (b > 0)) {\n\t*out = a % b;\n }\n else { /* handled like Python does */\n\t*out = a % b;\n\tif (*out) *out += b;\n }\n#else\n *out = a % b;\n#endif\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n**/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n *(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/* b will always be positive in this call */\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n \n}\n/**end repeat**/\n\n\n\n/* QUESTION: Should we check for overflow / underflow in (l,r)shift? */\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n**/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_floor)(@name@);\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) \\\n *(outp) = _basic_@name@_floor((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\\\n (outp)->real = (a).real + (b).real;\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\\\n (outp)->real = (a).real - (b).real;\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do {\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) /\t\\\n ((a).real*(b).real + (b).imag*(b).imag);\t\t\t\\\n (outp)->imag = 0;\t\t\t\t\t\t\\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - _basic_@name@_floor(a/b)*b;\n} \n/**end repeat**/ \n\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_ctype_divmod(a, b, out, out2) {\t\\\n @name@_ctype_floor_divide(a, b, out);\t\\\n @name@_ctype_remainder(a, b, out2);\t\t\\\n }\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_pow)(@name@ a, @name@ b);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = _basic_@name@_pow(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #uns=(1,0)*5,0*3#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n#if @uns@\n generate_overflow_error();\n#endif\n *out = -a;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n/* Get the nc_powf, nc_pow, and nc_powl functions from \n the data area of the power ufunc in umathmodule. \n*/\n\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n out->real = a.real;\n out->imag = a.imag;\n}\nstatic void (*_basic_@name@_pow)(@name@ *, @name@ *, @name@ *);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out)\n{\n _basic_@name@_pow(&a, &b, out);\n}\n/**end repeat**/\n\n\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, floor_divide*6, true_divide*6, divmod*3, remainder*3#\n #fperr=1*70,0*50,1*52#\n #twoout=0*50,1*10,0*106,1*3,0*3#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*12, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*12, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n**/\n\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @twoout@\n @otyp@ out2;\n PyObject *obj;\n#endif\n\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @twoout@\n @name@_ctype_@oper@(arg1, arg2, &out, &out2);\n#else\n @name@_ctype_@oper@(arg1, arg2, &out);\n#endif\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n\n#if @twoout@\n ret = PyTuple_New(2);\n if (ret==NULL) return NULL;\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out;\n PyTuple_SET_ITEM(ret, 0, obj);\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out2;\n PyTuple_SET_ITEM(ret, 1, obj);\n#else\n ret = PyArrayScalar_New(@OName@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @OName@) = out;\n#endif\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float, double, longdouble, cfloat, cdouble, clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #otyp=float*4, double*6, float, double, longdouble, cfloat, cdouble, clongdouble#\n #OName=Float*4, Double*6, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #isint=(1,0)*5,0*6#\n #cmplx=0*13,1*3#\n**/\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n @otyp@ out1;\n int retstatus;\n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n }\n\n PyUFunc_clearfperr();\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @cmplx@\n if (arg2.real == 0 && arg1.real == 0) {\n\tout1.real = out.real = 1.0;\n\tout1.imag = out.imag = 0.0;\n }\n#else\n if (arg2 == 0) {\n\tout1 = out = 1;\n } \n#endif\n#if @isint@\n else if (arg2 < 0) {\n\t@name@_ctype_power(arg1, -arg2, &out);\n\tout1 = 1.0 / out;\n }\n#endif\n else {\n\t@name@_ctype_power(arg1, arg2, &out);\n }\n\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n\n#if @isint@\n if (arg2 < 0) {\n\tret = PyArrayScalar_New(@OName@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @OName@) = out1;\n }\n else {\n\tret = PyArrayScalar_New(@Name@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @Name@) = out;\n }\n#else\n ret = PyArrayScalar_New(@Name@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @Name@) = out;\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n#name=(cfloat,cdouble,clongdouble)*2#\n#oper=divmod*3,remainder*3#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3, byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*3, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n #oper=negative*16, positive*16, absolute*16, invert*10#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n#name=float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_invert NULL\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic int\nget_functions(void)\n{\n PyObject *mm, *obj;\n void **funcdata;\n char *signatures;\n int i, j;\n\t\n /* Get the nc_pow functions */\n /* Get the pow functions */\n mm = PyImport_ImportModule(\"numpy.core.umath\");\n if (mm == NULL) return -1;\n \n obj = PyObject_GetAttrString(mm, \"power\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_pow = funcdata[j];\n _basic_double_pow = funcdata[j+1];\n _basic_longdouble_pow = funcdata[j+2];\n _basic_cfloat_pow = funcdata[j+3];\n _basic_cdouble_pow = funcdata[j+4];\n _basic_clongdouble_pow = funcdata[j+5];\n\n Py_DECREF(obj);\n\n /* Get the floor functions */\n\n obj = PyObject_GetAttrString(mm, \"floor\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_floor = funcdata[j];\n _basic_double_floor = funcdata[j+1];\n _basic_longdouble_floor = funcdata[j+2];\n\n Py_DECREF(obj);\n \n fail:\n Py_DECREF(mm);\n return -1;\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n if (get_functions() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor, divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n **/\n#if SIZEOF_@SIZE@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n **/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #neg=(1,0)*2#\n **/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n\tif (b == 0) {\n\t\tgenerate_divbyzero_error();\n\t\t*out = 0;\n\t}\n#if @neg@\n\telse if (b == -1 && a < 0 && a == -a) {\n\t\tgenerate_overflow_error();\n\t\t*out = a / b;\n\t}\n#endif\n\telse {\n\t\t*out = a / b;\n\t}\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n **/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n\t*(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n **/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\t\\\n (outp)->real = (a).real + (b).real;\t\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\t\\\n (outp)->real = (a).real - (b).real;\t\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do { \\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\\n ((a).real*(b).real + (b).imag*(b).imag); \\\n (outp)->imag = 0; \\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n #c=f,,l#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - floor@c@(a/b)*b;\n} \n/**end repeat**/ \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n **/\n#define @name@_ctype_divmod(a, b, out, out2) {\t\\\n\t@name@_ctype_floor_divide(a, b, out);\t\\\n\t@name@_ctype_remainder(a, b, out2);\t\\\n\t}\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n #fun= powf, pow, powl#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = @fun@(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n *out = -a;\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#\n #fperr=1*110,0*30,1*54#\n #power=0*60,1*10,0*106,1*6,0*12#\n #twoout=0*50,1*10,0*110,1*6,0*18#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#\n**/\n\n#if @power@\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n#else\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n#endif\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @twoout@\n @otyp@ out2;\n PyObject *obj;\n#endif\n\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n#if @power@\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n#else\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n#endif\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @twoout@\n @name@_ctype_@oper@(arg1, arg2, &out, &out2);\n#else\n @name@_ctype_@oper@(arg1, arg2, &out);\n#endif\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n\n#if @tupout@\n ret = PyTuple_New(2);\n if (ret==NULL) return NULL;\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return;}\n PyArrayScalar_VAL(ret, @OName@) = out;\n PyTuple_SET_ITEM(ret, 0, obj);\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return;}\n PyArrayScalar_VAL(ret, @OName@) = out2;\n PyTuple_SET_ITEM(ret, 1, obj);\n#else\n ret = PyArrayScalar_New(@OName@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @OName@) = out;\n#endif\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#\n #oper=negative*16, positive*16, absolute*16, invert*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "floor_divide, true_divide", + "**/", + " @big@ temp;", + " temp = ((@big@) a) * ((@big@) b);", + " *out = (@name@) temp;", + " if (temp > MAX_@NAME@ || temp < MIN_@NAME@)", + "\t generate_overflow_error();", + " return;", + "**/", + " *out = a * b;", + " if (@char@longlong_overflow(a, b))", + "\tgenerate_overflow_error();", + " return;", + " #neg=(1,0)*5#", + "**/", + " if (b == 0) {", + "\tgenerate_divbyzero_error();", + "\t*out = 0;", + " }", + " else if (b == -1 && a < 0 && a == -a) {", + "\tgenerate_overflow_error();", + "\t*out = a / b;", + " }", + " else {", + "\t*out = a / b;", + " }", + "static void", + "@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {", + " if (a == 0 || b == 0) {", + "\tif (b == 0) generate_divbyzero_error();", + "\t*out = 0;", + " }", + "#if @neg@", + " else if ((a > 0) == (b > 0)) {", + "\t*out = a % b;", + " }", + " else { /* handled like Python does */", + "\t*out = a % b;", + "\tif (*out) *out += b;", + " }", + "#else", + " *out = a % b;", + "#endif", + "}", + "**/", + " *(out) = ((@otyp@) (a)) / ((@otyp@) (b));", + "/**end repeat**/", + "", + "/* b will always be positive in this call */", + "/**begin repeat", + " #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#", + "**/", + "static void", + "@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {", + "", + "}", + "", + "", + "/* QUESTION: Should we check for overflow / underflow in (l,r)shift? */", + "", + "**/", + "static @name@ (*_basic_@name@_floor)(@name@);", + "#define @name@_ctype_floor_divide(a, b, outp) \\", + " *(outp) = _basic_@name@_floor((a) / (b))", + "#define @name@_ctype_add(a, b, outp) do{\t\\", + " (outp)->real = (a).real + (b).real;\t\t\\", + " (outp)->imag = (a).imag + (b).imag;\t\t\\", + "#define @name@_ctype_subtract(a, b, outp) do{\t\\", + " (outp)->real = (a).real - (b).real;\t\t\\", + " (outp)->imag = (a).imag - (b).imag;\t\t\\", + "#define @name@_ctype_floor_divide(a, b, outp) do {\t\t\\", + " (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) /\t\\", + " ((a).real*(b).real + (b).imag*(b).imag);\t\t\t\\", + " (outp)->imag = 0;\t\t\t\t\t\t\\", + " }while(0)", + " *out = a - _basic_@name@_floor(a/b)*b;", + "", + "", + "**/", + " @name@_ctype_floor_divide(a, b, out);\t\\", + " @name@_ctype_remainder(a, b, out2);\t\t\\", + " }", + "static @name@ (*_basic_@name@_pow)(@name@ a, @name@ b);", + " *out = _basic_@name@_pow(a, b);", + " #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#", + " #uns=(1,0)*5,0*3#", + "#if @uns@", + " generate_overflow_error();", + "#endif", + "", + "/* Get the nc_powf, nc_pow, and nc_powl functions from", + " the data area of the power ufunc in umathmodule.", + "*/", + "", + "", + "/**begin repeat", + " #name=cfloat, cdouble, clongdouble#", + "**/", + "static void", + "@name@_ctype_positive(@name@ a, @name@ *out)", + "{", + " out->real = a.real;", + " out->imag = a.imag;", + "}", + "static void (*_basic_@name@_pow)(@name@ *, @name@ *, @name@ *);", + "static void", + "@name@_ctype_power(@name@ a, @name@ b, @name@ *out)", + "{", + " _basic_@name@_pow(&a, &b, out);", + "}", + "/**end repeat**/", + "", + "", + "", + " #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#", + " #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#", + " #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, floor_divide*6, true_divide*6, divmod*3, remainder*3#", + " #fperr=1*70,0*50,1*52#", + " #twoout=0*50,1*10,0*106,1*3,0*3#", + " #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*12, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#", + " #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*12, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#", + "#if @twoout@", + " if (obj == NULL) {Py_DECREF(ret); return NULL;}", + " if (obj == NULL) {Py_DECREF(ret); return NULL;}", + "/**begin repeat", + " #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float, double, longdouble, cfloat, cdouble, clongdouble#", + " #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#", + " #otyp=float*4, double*6, float, double, longdouble, cfloat, cdouble, clongdouble#", + " #OName=Float*4, Double*6, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#", + " #isint=(1,0)*5,0*6#", + " #cmplx=0*13,1*3#", + "**/", + "", + "static PyObject *", + "@name@_power(PyObject *a, PyObject *b, PyObject *c)", + "{", + " PyObject *ret;", + " @name@ arg1, arg2, out;", + " @otyp@ out1;", + " int retstatus;", + "", + " switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {", + " case 0:", + " break;", + " case -1: /* can't cast both safely use different add function */", + " Py_INCREF(Py_NotImplemented);", + " return Py_NotImplemented;", + " case -2: /* use default handling */", + "\tif (PyErr_Occurred()) return NULL;", + " return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);", + " }", + "", + " PyUFunc_clearfperr();", + "", + " /* here we do the actual calculation with arg1 and arg2 */", + " /* as a function call. */", + "#if @cmplx@", + " if (arg2.real == 0 && arg1.real == 0) {", + "\tout1.real = out.real = 1.0;", + "\tout1.imag = out.imag = 0.0;", + " }", + "#else", + " if (arg2 == 0) {", + "\tout1 = out = 1;", + " }", + "#endif", + "#if @isint@", + " else if (arg2 < 0) {", + "\t@name@_ctype_power(arg1, -arg2, &out);", + "\tout1 = 1.0 / out;", + " }", + "#endif", + " else {", + "\t@name@_ctype_power(arg1, arg2, &out);", + " }", + "", + " /* Check status flag. If it is set, then look up what to do */", + " retstatus = PyUFunc_getfperr();", + " if (retstatus) {", + "\tint bufsize, errmask;", + "\tPyObject *errobj;", + "\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask,", + "\t\t\t\t&errobj) < 0)", + "\t return NULL;", + "\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))", + "\t return NULL;", + " }", + "", + "#if @isint@", + " if (arg2 < 0) {", + "\tret = PyArrayScalar_New(@OName@);", + "\tif (ret==NULL) return NULL;", + "\tPyArrayScalar_VAL(ret, @OName@) = out1;", + " }", + " else {", + "\tret = PyArrayScalar_New(@Name@);", + "\tif (ret==NULL) return NULL;", + "\tPyArrayScalar_VAL(ret, @Name@) = out;", + " }", + "#else", + " ret = PyArrayScalar_New(@Name@);", + " if (ret==NULL) return NULL;", + " PyArrayScalar_VAL(ret, @Name@) = out;", + "#endif", + "", + " return ret;", + "}", + "/**end repeat**/", + "", + "", + "/**begin repeat", + "#name=(cfloat,cdouble,clongdouble)*2#", + "#oper=divmod*3,remainder*3#", + "**/", + "#define @name@_@oper@ NULL", + "/**end repeat**/", + " #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3, byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#", + " #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*3, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#", + " #oper=negative*16, positive*16, absolute*16, invert*10#", + "/**begin repeat", + "#name=float,double,longdouble,cfloat,cdouble,clongdouble#", + "**/", + "#define @name@_invert NULL", + "/**end repeat**/", + "static int", + "get_functions(void)", + "{", + " PyObject *mm, *obj;", + " void **funcdata;", + " char *signatures;", + " int i, j;", + "", + " /* Get the nc_pow functions */", + " /* Get the pow functions */", + " mm = PyImport_ImportModule(\"numpy.core.umath\");", + " if (mm == NULL) return -1;", + "", + " obj = PyObject_GetAttrString(mm, \"power\");", + " if (obj == NULL) goto fail;", + " funcdata = ((PyUFuncObject *)obj)->data;", + " signatures = ((PyUFuncObject *)obj)->types;", + "", + " i = 0;", + " j = 0;", + " while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}", + " _basic_float_pow = funcdata[j];", + " _basic_double_pow = funcdata[j+1];", + " _basic_longdouble_pow = funcdata[j+2];", + " _basic_cfloat_pow = funcdata[j+3];", + " _basic_cdouble_pow = funcdata[j+4];", + " _basic_clongdouble_pow = funcdata[j+5];", + "", + " Py_DECREF(obj);", + "", + " /* Get the floor functions */", + "", + " obj = PyObject_GetAttrString(mm, \"floor\");", + " if (obj == NULL) goto fail;", + " funcdata = ((PyUFuncObject *)obj)->data;", + " signatures = ((PyUFuncObject *)obj)->types;", + "", + " i = 0;", + " j = 0;", + " while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}", + " _basic_float_floor = funcdata[j];", + " _basic_double_floor = funcdata[j+1];", + " _basic_longdouble_floor = funcdata[j+2];", + "", + " Py_DECREF(obj);", + "", + " fail:", + " Py_DECREF(mm);", + " return -1;", + "}", + "", + " if (get_functions() < 0) return;", + "" + ], + "deleted": [ + "floor, divide, true_divide", + " **/", + " @big@ temp;", + " temp = ((@big@) a) * ((@big@) b);", + " *out = (@name@) temp;", + " if (temp > MAX_@NAME@ || temp < MIN_@NAME@)", + " generate_overflow_error();", + " return;", + " **/", + " *out = a * b;", + " if (@char@longlong_overflow(a, b))", + " generate_overflow_error();", + " return;", + " #neg=(1,0)*2#", + " **/", + "\tif (b == 0) {", + "\t\tgenerate_divbyzero_error();", + "\t\t*out = 0;", + "\t}", + "\telse if (b == -1 && a < 0 && a == -a) {", + "\t\tgenerate_overflow_error();", + "\t\t*out = a / b;", + "\t}", + "\telse {", + "\t\t*out = a / b;", + "\t}", + " **/", + "\t*(out) = ((@otyp@) (a)) / ((@otyp@) (b));", + " **/", + " #c=f,,l#", + "#define @name@_ctype_floor_divide(a, b, outp) *(outp) = floor@c@((a) / (b))", + "#define @name@_ctype_add(a, b, outp) do{\t\t\\", + " (outp)->real = (a).real + (b).real;\t\t\t\\", + " (outp)->imag = (a).imag + (b).imag;\t\t\t\\", + "#define @name@_ctype_subtract(a, b, outp) do{\t\t\\", + " (outp)->real = (a).real - (b).real;\t\t\t\\", + " (outp)->imag = (a).imag - (b).imag;\t\t\t\\", + "#define @name@_ctype_floor_divide(a, b, outp) do { \\", + " @rtype@ d = (a).real*(b).real + (b).imag*(b).imag; \\", + " (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) / \\", + " ((a).real*(b).real + (b).imag*(b).imag); \\", + " (outp)->imag = 0; \\", + " }while(0)", + " #c=f,,l#", + " *out = a - floor@c@(a/b)*b;", + " **/", + "\t@name@_ctype_floor_divide(a, b, out);\t\\", + "\t@name@_ctype_remainder(a, b, out2);\t\\", + "\t}", + " #fun= powf, pow, powl#", + " *out = @fun@(a, b);", + " #name=byte, short, int, long, longlong, float, double, longdouble#", + " #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*14, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#", + " #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*14, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#", + " #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, power*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, remainder*6, divmod*6, power*6, floor_divide*6, true_divide*6#", + " #fperr=1*110,0*30,1*54#", + " #power=0*60,1*10,0*106,1*6,0*12#", + " #twoout=0*50,1*10,0*110,1*6,0*18#", + " #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*9#", + " #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*9#", + "#if @power@", + "static PyObject *", + "@name@_power(PyObject *a, PyObject *b, PyObject *c)", + "#else", + "#endif", + "#if @power@", + " return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);", + "#else", + "#endif", + "#if @tupout@", + " if (obj == NULL) {Py_DECREF(ret); return;}", + " if (obj == NULL) {Py_DECREF(ret); return;}", + " #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*4#", + " #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*4#", + " #oper=negative*16, positive*16, absolute*16, invert*16#" + ] + } + }, + { + "old_path": "numpy/core/src/umathmodule.c.src", + "new_path": "numpy/core/src/umathmodule.c.src", + "filename": "umathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -1211,8 +1211,6 @@ Py_get_one(PyObject *o)\n }\n \n \n-static int numeric_zero = 0;\n-\n /**begin repeat\n #TYP=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n #typ=char, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n@@ -1225,14 +1223,11 @@ static void\n \tregister intp os=steps[2], n=dimensions[0];\n \tchar *i1=args[0], *i2=args[1], *op=args[2];\n \t@btyp@ x, y, v;\n- @typ@ z;\n \n \tfor(i=0; i\n\n/* A whole slew of basic math functions are provided originally\n by Konrad Hinsen. */\n\n#if !defined(__STDC__) && !defined(_MSC_VER)\nextern double fmod (double, double);\nextern double frexp (double, int *);\nextern double ldexp (double, int);\nextern double modf (double, double *);\n#endif\n#ifndef M_PI\n#define M_PI 3.14159265358979323846264338328\n#endif\n\n\n#ifndef HAVE_INVERSE_HYPERBOLIC\nstatic double acosh(double x)\n{\n\treturn 2*log(sqrt((x+1.0)/2)+sqrt((x-1.0)/2));\n}\n\ndouble log1p(double);\nstatic double asinh(double xx)\n{\n\tdouble x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e8) {\n\t\td = x;\n\t} else {\n\t\td = sqrt(x*x + 1);\n\t}\n\treturn sign*log1p(x*(1.0 + x/(d+1)));\n}\n\nstatic double atanh(double x)\n{\n\treturn 0.5*log1p(2.0*x/(1.0-x));\n}\n#endif\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC_FLOAT)\n#ifdef HAVE_FLOAT_FUNCS\n#ifdef log1pf\n#undef log1pf\n#endif\n#ifdef logf\n#undef logf\n#endif\n#ifdef sqrtf\n#undef sqrtf\n#endif\nfloat log1pf(float);\nfloat logf(float);\nfloat sqrtf(float);\n#ifdef acoshf\n#undef acoshf\n#endif\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\n#ifdef asinhf\n#undef asinhf\n#endif\nstatic float asinhf(float xx)\n{\n\tfloat x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e5) {\n\t\td = x;\n\t} else {\n\t\td = sqrtf(x*x + 1);\n\t}\n\treturn sign*log1pf(x*(1.0 + x/(d+1)));\n}\n\n#ifdef atanhf\n#undef atanhf\n#endif\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\n#ifdef acoshf\n#undef acoshf\n#endif\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\n#ifdef asinhf\n#undef asinhf\n#endif\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\n#ifdef atanhf\n#undef atanhf\n#endif\nstatic float atanhf(float x)\n{\n return (float)atanh((double)(x));\n}\n#endif\n#endif\n\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE)\n#ifdef HAVE_LONGDOUBLE_FUNCS\n#ifdef logl\n#undef logl\n#endif\n#ifdef sqrtl\n#undef sqrtl\n#endif\n#ifdef log1pl\n#undef log1pl\n#endif\nlongdouble logl(longdouble);\nlongdouble sqrtl(longdouble);\nlongdouble log1pl(longdouble);\n#ifdef acoshl\n#undef acoshl\n#endif\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\n#ifdef asinhl\n#undef asinhl\n#endif\nstatic longdouble asinhl(longdouble xx)\n{\n\tlongdouble x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e17) {\n\t\td = x;\n\t} else {\n\t\td = sqrtl(x*x + 1);\n\t}\n\treturn sign*log1pl(x*(1.0 + x/(d+1)));\n}\n\n#ifdef atanhl\n#undef atanhl\n#endif\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n\n#else\n\n#ifdef acoshl\n#undef acoshl\n#endif\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\n#ifdef asinhl\n#undef asinhl\n#endif\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\n#ifdef atanhl\n#undef atanhl\n#endif\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\n}\n\n#endif\n#endif\n\n\n#ifdef HAVE_HYPOT\n#if !defined(NeXT) && !defined(_MSC_VER)\nextern double hypot(double, double);\n#endif\n#else\nstatic double hypot(double x, double y)\n{\n\tdouble yx;\n\n\tx = fabs(x);\n\ty = fabs(y);\n\tif (x < y) {\n\t\tdouble temp = x;\n\t\tx = y;\n\t\ty = temp;\n\t}\n\tif (x == 0.)\n\t\treturn 0.;\n\telse {\n\t\tyx = y/x;\n\t\treturn x*sqrt(1.+yx*yx);\n\t}\n}\n#endif\n\n\n#ifndef HAVE_RINT\nstatic double \nrint (double x)\n{\n\tdouble y, r;\n\t\n\ty = floor(x);\n\tr = x - y;\n\t\n\tif (r > 0.5) goto rndup;\n\n\t/* Round to nearest even */\n\tif (r==0.5) {\n\t\tr = y - 2.0*floor(0.5*y);\n\t\tif (r==1.0) {\n\t\trndup:\t \n\t\t\ty+=1.0;\n\t\t}\n\t}\n\treturn y;\n}\n#endif\n\n\n\n/* Define isnan, isinf, isfinite, signbit if needed */\n/* Use fpclassify if possible */\n/* isnan, isinf --\n these will use macros and then fpclassify if available before\n defaulting to a dumb convert-to-double version...\n\n isfinite -- define a macro if not already available\n signbit -- if macro available use it, otherwise define a function\n and a dumb convert-to-double version for other types.\n*/\n\n#if defined(fpclassify)\n\n#if !defined(isnan)\n#define isnan(x) (fpclassify(x) == FP_NAN)\n#endif\n#if !defined(isinf)\n#define isinf(x) (fpclassify(x) == FP_INFINITE)\n#endif\n\n#else /* check to see if already have a function like this */\n\n#if !defined(HAVE_ISNAN)\n\n#if !defined(isnan)\n#include \"_isnan.c\"\n#endif\n#endif /* HAVE_ISNAN */\n\n#if !defined(HAVE_ISINF)\n#if !defined(isinf)\n#define isinf(x) (!isnan((x)) && isnan((x)-(x)))\n#endif\n#endif /* HAVE_ISINF */\n\n#endif /* defined(fpclassify) */\n\n\n/* Define signbit if needed */\n#if !defined(signbit)\n#include \"_signbit.c\"\n#endif\n\n/* Now defined the extended type macros */\n\n#if !defined(isnan)\n\n#if !defined(HAVE_LONGDOUBLE_FUNCS) || !defined(HAVE_ISNAN)\n#define isnanl(x) isnan((double)(x))\n#endif\n\n#if !defined(HAVE_FLOAT_FUNCS) || !defined(HAVE_ISNAN)\n#define isnanf(x) isnan((double)(x))\n#endif\n\n#else /* !defined(isnan) */\n\n#define isnanl(x) isnan((x))\n#define isnanf(x) isnan((x))\n\n#endif /* !defined(isnan) */\n\n\n#if !defined(isinf)\n\n#if !defined(HAVE_LONGDOUBLE_FUNCS) || !defined(HAVE_ISINF)\n#define isinfl(x) (!isnanl((x)) && isnanl((x)-(x)))\n#endif\n\n#if !defined(HAVE_FLOAT_FUNCS) || !defined(HAVE_ISINF)\n#define isinff(x) (!isnanf((x)) && isnanf((x)-(x)))\n#endif\n\n#else /* !defined(isinf) */\n\n#define isinfl(x) isinf((x))\n#define isinff(x) isinf((x))\n\n#endif /* !defined(isinf) */\n\n\n#if !defined(signbit)\n#define signbitl(x) ((longdouble) signbit((double)(x)))\n#define signbitf(x) ((float) signbit((double) (x)))\n#else\n#define signbitl(x) signbit((x))\n#define signbitf(x) signbit((x))\n#endif\n\n#if !defined(isfinite)\n#define isfinite(x) (!(isinf((x)) || isnan((x))))\n#endif\n#define isfinitef(x) (!(isinff((x)) || isnanf((x))))\n#define isfinitel(x) (!(isinfl((x)) || isnanl((x))))\n\n\n/* First, the C functions that do the real work */\n\n/* if C99 extensions not available then define dummy functions that use the\n double versions for\n\n sin, cos, tan\n sinh, cosh, tanh,\n fabs, floor, ceil, fmod, sqrt, log10, log, exp, fabs\n asin, acos, atan,\n asinh, acosh, atanh\n\n hypot, atan2, pow\n*/\n\n/**begin repeat\n\n#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan,rint)*2#\n#typ=longdouble*17, float*17#\n#c=l*17,f*17#\n#TYPE=LONGDOUBLE*17, FLOAT*17#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef @kind@@c@\n#undef @kind@@c@\n#endif\n@typ@ @kind@@c@(@typ@ x) {\n\treturn (@typ@) @kind@((double)x);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n\n#kind=(atan2,hypot,pow,fmod)*2#\n#typ=longdouble*4, float*4#\n#c=l*4,f*4#\n#TYPE=LONGDOUBLE*4,FLOAT*4#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef @kind@@c@\n#undef @kind@@c@\n#endif\n@typ@ @kind@@c@(@typ@ x, @typ@ y) {\n\treturn (@typ@) @kind@((double)x, (double) y);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n#kind=modf*2#\n#typ=longdouble, float#\n#c=l,f#\n#TYPE=LONGDOUBLE, FLOAT#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef modf@c@\n#undef modf@c@\n#endif\n@typ@ modf@c@(@typ@ x, @typ@ *iptr) {\n double nx, niptr, y;\n nx = (double) x;\n y = modf(nx, &niptr);\n *iptr = (@typ@) niptr;\n return (@typ@) y;\n}\n#endif\n/**end repeat**/\n\n\n\n#ifndef HAVE_LOG1P\ndouble log1p(double x)\n{\n\tdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn log(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_LONGDOUBLE_FUNCS)\n#ifdef log1pl\n#undef log1pl\n#endif\nlongdouble log1pl(longdouble x)\n{\n\tlongdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logl(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_FLOAT_FUNCS)\n#ifdef log1pf\n#undef log1pf\n#endif\nfloat log1pf(float x)\n{\n\tfloat u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logf(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#ifndef HAVE_EXPM1\nstatic double expm1(double x)\n{\n\tdouble u = exp(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/log(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_LONGDOUBLE_FUNCS)\n#ifdef expml1\n#undef expml1\n#endif\nstatic longdouble expm1l(longdouble x)\n{\n\tlongdouble u = expl(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logl(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_FLOAT_FUNCS)\n#ifdef expm1f\n#undef expm1f\n#endif\nstatic float expm1f(float x)\n{\n\tfloat u = expf(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logf(u);\n\t}\n}\n#endif\n\n\n\n\n/* Don't pass structures between functions (only pointers) because how\n structures are passed is compiler dependent and could cause\n segfaults if ufuncobject.c is compiled with a different compiler\n than an extension that makes use of the UFUNC API\n*/\n\n/**begin repeat\n\n#typ=float, double, longdouble#\n#c=f,,l#\n*/\n\n/* constants */\nstatic c@typ@ nc_1@c@ = {1., 0.};\nstatic c@typ@ nc_half@c@ = {0.5, 0.};\nstatic c@typ@ nc_i@c@ = {0., 1.};\nstatic c@typ@ nc_i2@c@ = {0., 0.5};\n/*\nstatic c@typ@ nc_mi@c@ = {0., -1.};\nstatic c@typ@ nc_pi2@c@ = {M_PI/2., 0.};\n*/\n\nstatic void\nnc_sum@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real + b->real;\n\tr->imag = a->imag + b->imag;\n\treturn;\n}\n\nstatic void\nnc_diff@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real - b->real;\n\tr->imag = a->imag - b->imag;\n\treturn;\n}\n\nstatic void\nnc_neg@c@(c@typ@ *a, c@typ@ *r)\n{\n\tr->real = -a->real;\n\tr->imag = -a->imag;\n\treturn;\n}\n\nstatic void\nnc_prod@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tregister @typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\tr->real = ar*br - ai*bi;\n\tr->imag = ar*bi + ai*br;\n\treturn;\n}\n\nstatic void\nnc_quot@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\n\tregister @typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\tregister @typ@ d = br*br + bi*bi;\n\tr->real = (ar*br + ai*bi)/d;\n\tr->imag = (ai*br - ar*bi)/d;\n\treturn;\n}\n\nstatic void\nnc_floor_quot@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tregister @typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\tregister @typ@ d = br*br + bi*bi;\n\tr->real = floor@c@((ar*br + ai*bi)/d);\n\tr->imag = 0;\n\treturn;\n}\n\nstatic void\nnc_sqrt@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ s,d;\n\tif (x->real == 0. && x->imag == 0.)\n\t\t*r = *x;\n\telse {\n\t\ts = sqrt@c@(0.5*(fabs@c@(x->real) + hypot@c@(x->real,x->imag)));\n\t\td = 0.5*x->imag/s;\n\t\tif (x->real > 0.) {\n\t\t\tr->real = s;\n\t\t\tr->imag = d;\n\t\t}\n\t\telse if (x->imag >= 0.) {\n\t\t\tr->real = d;\n\t\t\tr->imag = s;\n\t\t}\n\t\telse {\n\t\t\tr->real = -d;\n\t\t\tr->imag = -s;\n\t\t}\n\t}\n\treturn;\n}\n\nstatic void\nnc_log@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ l = hypot@c@(x->real,x->imag);\n\tr->imag = atan2@c@(x->imag, x->real);\n\tr->real = log@c@(l);\n\treturn;\n}\n\nstatic void\nnc_log1p@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ l = hypot@c@(x->real + 1.0,x->imag);\n\tr->imag = atan2@c@(x->imag, x->real + 1.0);\n\tr->real = log@c@(l);\n\treturn;\n}\n\nstatic void\nnc_exp@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ a = exp@c@(x->real);\n\tr->real = a*cos@c@(x->imag);\n\tr->imag = a*sin@c@(x->imag);\n\treturn;\n}\n\nstatic void\nnc_expm1@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ a = exp@c@(x->real);\n\tr->real = a*cos@c@(x->imag) - 1.0;\n\tr->imag = a*sin@c@(x->imag);\n\treturn;\n}\n\nstatic void\nnc_pow@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n intp n;\n @typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\n\tif (br == 0. && bi == 0.) {\n\t\tr->real = 1.;\n\t\tr->imag = 0.;\n return;\n\t}\n\tif (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n return;\n\t}\n if (bi == 0 && (n=(intp)br) == br) {\n if (n > -100 && n < 100) {\n c@typ@ p, aa;\n intp mask = 1;\n if (n < 0) n = -n;\n aa = nc_1@c@;\n p.real = ar; p.imag = ai;\n while (1) {\n if (n & mask)\n nc_prod@c@(&aa,&p,&aa);\n mask <<= 1;\n if (n < mask || mask <= 0) break;\n nc_prod@c@(&p,&p,&p);\n }\n r->real = aa.real; r->imag = aa.imag;\n if (br < 0) nc_quot@c@(&nc_1@c@, r, r);\n return;\n }\n }\n /* complexobect.c uses an inline version of this formula\n investigate whether this had better performance or accuracy */\n nc_log@c@(a, r);\n nc_prod@c@(r, b, r);\n nc_exp@c@(r, r);\n return;\n}\n\n\nstatic void\nnc_prodi@c@(c@typ@ *x, c@typ@ *r)\n{\n\tr->real = -x->imag;\n\tr->imag = x->real;\n\treturn;\n}\n\n\nstatic void\nnc_acos@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x,x,r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_sum@c@(x, r, r);\n\tnc_log@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/* return nc_neg(nc_prodi(nc_log(nc_sum(x,nc_prod(nc_i,\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x))))))));\n\t*/\n}\n\nstatic void\nnc_acosh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x, x, r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_sum@c@(x, r, r);\n\tnc_log@c@(r, r);\n\treturn;\n\t/*\n\t return nc_log(nc_sum(x,nc_prod(nc_i,\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x))))));\n\t*/\n}\n\nstatic void\nnc_asin@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_prod@c@(x, x, r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(x, pa);\n\tnc_sum@c@(pa, r, r);\n\tnc_log@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/*\n\t return nc_neg(nc_prodi(nc_log(nc_sum(nc_prod(nc_i,x),\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x)))))));\n\t*/\n}\n\n\nstatic void\nnc_asinh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x, x, r);\n\tnc_sum@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_diff@c@(r, x, r);\n\tnc_log@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/*\n\t return nc_neg(nc_log(nc_diff(nc_sqrt(nc_sum(nc_1,nc_prod(x,x))),x)));\n\t*/\n}\n\nstatic void\nnc_atan@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_diff@c@(&nc_i@c@, x, pa);\n\tnc_sum@c@(&nc_i@c@, x, r);\n\tnc_quot@c@(r, pa, r);\n\tnc_log@c@(r,r);\n\tnc_prod@c@(&nc_i2@c@, r, r);\n\treturn;\n\t/*\n\t return nc_prod(nc_i2,nc_log(nc_quot(nc_sum(nc_i,x),nc_diff(nc_i,x))));\n\t*/\n}\n\nstatic void\nnc_atanh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_diff@c@(&nc_1@c@, x, r);\n\tnc_sum@c@(&nc_1@c@, x, pa);\n\tnc_quot@c@(pa, r, r);\n\tnc_log@c@(r, r);\n\tnc_prod@c@(&nc_half@c@, r, r);\n\treturn;\n\t/*\n\t return nc_prod(nc_half,nc_log(nc_quot(nc_sum(nc_1,x),nc_diff(nc_1,x))));\n\t*/\n}\n\nstatic void\nnc_cos@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos@c@(xr)*cosh@c@(xi);\n\tr->imag = -sin@c@(xr)*sinh@c@(xi);\n\treturn;\n}\n\nstatic void\nnc_cosh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos(xi)*cosh(xr);\n\tr->imag = sin(xi)*sinh(xr);\n\treturn;\n}\n\n\n#define M_LOG10_E 0.434294481903251827651128918916605082294397\n\nstatic void\nnc_log10@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_log@c@(x, r);\n\tr->real *= M_LOG10_E;\n\tr->imag *= M_LOG10_E;\n\treturn;\n}\n\nstatic void\nnc_sin@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = sin@c@(xr)*cosh@c@(xi);\n\tr->imag = cos@c@(xr)*sinh@c@(xi);\n\treturn;\n}\n\nstatic void\nnc_sinh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos@c@(xi)*sinh@c@(xr);\n\tr->imag = sin@c@(xi)*cosh@c@(xr);\n\treturn;\n}\n\nstatic void\nnc_tan@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ sr,cr,shi,chi;\n\t@typ@ rs,is,rc,ic;\n\t@typ@ d;\n\t@typ@ xr=x->real, xi=x->imag;\n\tsr = sin@c@(xr);\n\tcr = cos@c@(xr);\n\tshi = sinh(xi);\n\tchi = cosh(xi);\n\trs = sr*chi;\n\tis = cr*shi;\n\trc = cr*chi;\n\tic = -sr*shi;\n\td = rc*rc + ic*ic;\n\tr->real = (rs*rc+is*ic)/d;\n\tr->imag = (is*rc-rs*ic)/d;\n\treturn;\n}\n\nstatic void\nnc_tanh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ si,ci,shr,chr;\n\t@typ@ rs,is,rc,ic;\n\t@typ@ d;\n\t@typ@ xr=x->real, xi=x->imag;\n\tsi = sin@c@(xi);\n\tci = cos@c@(xi);\n\tshr = sinh@c@(xr);\n\tchr = cosh@c@(xr);\n\trs = ci*shr;\n\tis = si*chr;\n\trc = ci*chr;\n\tic = si*shr;\n\td = rc*rc + ic*ic;\n\tr->real = (rs*rc+is*ic)/d;\n\tr->imag = (is*rc-rs*ic)/d;\n\treturn;\n}\n\n/**end repeat**/\n\n\n/**begin repeat\n\n#TYPE=(BOOL, BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#\n#OP=||, +*13, ^, -*13#\n#kind=add*14, subtract*14#\n#typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; ireal;\n xi = x->imag;\n y->real = xr*xr - xi*xi;\n y->imag = 2*xr*xi;\n }\n}\n/**end repeat**/\n\nstatic PyObject *\nPy_square(PyObject *o)\n{\n return PyNumber_Multiply(o, o);\n}\n\n\n/**begin repeat\n#TYP=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#typ=char, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n*/\nstatic void\n@TYP@_reciprocal(char **args, intp *dimensions, intp *steps, void *data)\n{\n intp i, is1 = steps[0], os = steps[1], n = dimensions[0];\n char *i1 = args[0], *op = args[1];\n\n for (i = 0; i < n; i++, i1 += is1, op += os) {\n @typ@ x = *((@typ@ *)i1);\n *((@typ@ *)op) = 1.0 / x;\n }\n}\n/**end repeat**/\n\n/**begin repeat\n#TYP=CFLOAT,CDOUBLE,CLONGDOUBLE#\n#typ=float, double, longdouble#\n*/\nstatic void\n@TYP@_reciprocal(char **args, intp *dimensions, intp *steps, void *data)\n{\n intp i, is1 = steps[0], os = steps[1], n = dimensions[0];\n char *i1 = args[0], *op = args[1];\n c@typ@ *x, *y;\n @typ@ xr, xi, r, denom;\n\n for (i = 0; i < n; i++, i1 += is1, op += os) {\n x = (c@typ@ *)i1;\n y = (c@typ@ *)op;\n xr = x->real;\n xi = x->imag;\n if (fabs(xi) <= fabs(xr)) {\n r = xi / xr;\n denom = xr + xi * r;\n y->real = 1 / denom;\n y->imag = -r / denom;\n } else {\n r = xr / xi;\n denom = xr * r + xi;\n y->real = r / denom;\n y->imag = -1 / denom;\n }\n }\n}\n/**end repeat**/\n\n\n\nstatic PyObject *\nPy_reciprocal(PyObject *o)\n{\n PyObject *one, *result;\n one = PyInt_FromLong(1);\n if (!one) return NULL;\n result = PyNumber_Divide(one, o);\n Py_DECREF(one);\n return result;\n}\n\n/* ones_like is defined here because it's used for x**0 */\n\n/**begin repeat\n#TYP=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#typ=char, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n*/\nstatic void\n@TYP@_ones_like(char **args, intp *dimensions, intp *steps, void *data)\n{\n intp i, os = steps[1], n = dimensions[0];\n char *op = args[1];\n\n for (i = 0; i < n; i++, op += os) {\n *((@typ@ *)op) = 1;\n }\n}\n/**end repeat**/\n\n/**begin repeat\n#TYP=CFLOAT,CDOUBLE,CLONGDOUBLE#\n#typ=float, double, longdouble#\n*/\nstatic void\n@TYP@_ones_like(char **args, intp *dimensions, intp *steps, void *data)\n{\n intp i, is1 = steps[0], os = steps[1], n = dimensions[0];\n char *i1 = args[0], *op = args[1];\n c@typ@ *x, *y;\n @typ@ xr, xi, xmag2;\n \n for (i = 0; i < n; i++, i1 += is1, op += os) {\n x = (c@typ@ *)i1;\n y = (c@typ@ *)op;\n xr = x->real;\n xi = x->imag;\n xmag2 = xr*xr + xi*xi;\n y->real = 1.0;\n y->imag = 0.0;\n }\n}\n/**end repeat**/\n\nstatic PyObject *\nPy_get_one(PyObject *o)\n{\n return PyInt_FromLong(1);\n}\n\n\n/**begin repeat\n#TYP=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n#typ=char, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n#btyp=float*4, double*6#\n*/\nstatic void\n@TYP@_power(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i, is1=steps[0],is2=steps[1];\n\tregister intp os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\t@btyp@ x, y, v;\n\n\tfor(i=0; i, >=, <, <=, ==, !=, &&, ||, &, |, ^#\n**/\nstatic void\nBOOL_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tBool in1, in2;\n\tfor(i=0; i*13, >=*13, <*13, <=*13#\n#typ=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*4#\n#kind= greater*13, greater_equal*13, less*13, less_equal*13#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, >=*3, <*3, <=*3#\n#typ=(cfloat, cdouble, clongdouble)*4#\n#kind= greater*3, greater_equal*3, less*3, less_equal*3#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; ireal == ((@typ@ *)i2)->real)\n\t\t\t*((Bool *)op)=((@typ@ *)i1)->imag @OP@ \\\n\t\t\t\t((@typ@ *)i2)->imag;\n\t\telse\n\t\t\t*((Bool *)op)=((@typ@ *)i1)->real @OP@ \\\n\t\t\t\t((@typ@ *)i2)->real;\n\t}\n}\n/**end repeat**/\n\n\n/**begin repeat\n#TYPE=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*4#\n#typ=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*4#\n#OP= ==*13, !=*13, &&*13, ||*13#\n#kind=equal*13, not_equal*13, logical_and*13, logical_or*13#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i 0 ? 1 : ((x) < 0 ? -1 : 0))\n#define _SIGN2(x) ((x) == 0 ? 0 : 1)\n#define _SIGNC(x) (((x).real > 0) ? 1 : ((x).real < 0 ? -1 : ((x).imag > 0 ? 1 : ((x).imag < 0) ? -1 : 0)))\n/**begin repeat\n#TYPE=BYTE,SHORT,INT,LONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE,UBYTE,USHORT,UINT,ULONG,ULONGLONG#\n#typ=byte,short,int,long,longlong,float,double,longdouble,ubyte,ushort,uint,ulong,ulonglong#\n#func=_SIGN1*8,_SIGN2*5#\n */\nstatic void\n@TYPE@_sign(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],os=steps[1], n=dimensions[0];\n\tchar *i1=args[0], *op=args[1];\n @typ@ t1;\n\tfor(i=0; ireal ||\t\\\n\t\t\t\t ((@typ@ *)i1)->imag);\n\t}\n}\n/**end repeat**/\n\n\n\n\n/**begin repeat\n#TYPE=BYTE,SHORT,INT,LONG,LONGLONG#\n#typ=byte, short, int, long, longlong#\n#c=f*2,,,l*1#\n*/\nstatic void\n@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tregister @typ@ ix,iy, tmp;\n\tfor(i=0; i 0) == (iy > 0)) {\n\t\t\t*((@typ@ *)op) = ix % iy;\n\t\t}\n\t\telse { /* handle mixed case the way Python does */\n\t\t\ttmp = ix % iy;\n\t\t\tif (tmp) tmp += iy;\n\t\t\t*((@typ@ *)op)= tmp;\n\t\t}\n\t}\n}\n/**end repeat**/\n\n/**begin repeat\n#TYPE=UBYTE,USHORT,UINT,ULONG,ULONGLONG#\n#typ=ubyte, ushort, uint, ulong, ulonglong#\n*/\nstatic void\n@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tregister @typ@ ix,iy;\n\tfor(i=0; i>*10#\n#kind=bitwise_and*10, bitwise_or*10, bitwise_xor*10, left_shift*10, right_shift*10#\n\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tregister char *i1=args[0], *i2=args[1], *op=args[2];\n\tif (is1 == 0) {\n\t\tregister @typ@ t1 = *((@typ@ *)i1);\n\t\tfor (i=0; ireal || ((@typ@ *)i1)->imag;\n\t\tp2 = ((@typ@ *)i2)->real || ((@typ@ *)i2)->imag;\n\t\t*((Bool *)op)= (p1 || p2) && !(p1 && p2);\n\t}\n}\n/**end repeat**/\n\n\n\n/**begin repeat\n\n#TYPE=(BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#\n#OP= >*14, <*14#\n#typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#\n#kind= maximum*14, minimum*14#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, <*3#\n#typ=(cfloat, cdouble, clongdouble)*2#\n#kind= maximum*3, minimum*3#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n @typ@ *i1c, *i2c;\n\tfor(i=0; ireal @OP@ i2c->real) || \\\n ((i1c->real==i2c->real) && (i1c->imag @OP@ i2c->imag)))\n memmove(op, i1, sizeof(@typ@));\n else\n memmove(op, i2, sizeof(@typ@));\n\t}\n}\n/**end repeat**/\n\n\n\n/*** isinf, isinf, isfinite, signbit ***/\n/**begin repeat\n#kind=isnan*3, isinf*3, isfinite*3, signbit*3#\n#TYPE=(FLOAT, DOUBLE, LONGDOUBLE)*4#\n#typ=(float, double, longdouble)*4#\n#c=(f,,l)*4#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n register intp i;\n intp is=steps[0], os=steps[1], n=dimensions[0];\n char *ip=args[0], *op=args[1];\n for(i=0; i\n\n/* A whole slew of basic math functions are provided originally\n by Konrad Hinsen. */\n\n#if !defined(__STDC__) && !defined(_MSC_VER)\nextern double fmod (double, double);\nextern double frexp (double, int *);\nextern double ldexp (double, int);\nextern double modf (double, double *);\n#endif\n#ifndef M_PI\n#define M_PI 3.14159265358979323846264338328\n#endif\n\n\n#ifndef HAVE_INVERSE_HYPERBOLIC\nstatic double acosh(double x)\n{\n\treturn 2*log(sqrt((x+1.0)/2)+sqrt((x-1.0)/2));\n}\n\ndouble log1p(double);\nstatic double asinh(double xx)\n{\n\tdouble x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e8) {\n\t\td = x;\n\t} else {\n\t\td = sqrt(x*x + 1);\n\t}\n\treturn sign*log1p(x*(1.0 + x/(d+1)));\n}\n\nstatic double atanh(double x)\n{\n\treturn 0.5*log1p(2.0*x/(1.0-x));\n}\n#endif\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC_FLOAT)\n#ifdef HAVE_FLOAT_FUNCS\n#ifdef log1pf\n#undef log1pf\n#endif\n#ifdef logf\n#undef logf\n#endif\n#ifdef sqrtf\n#undef sqrtf\n#endif\nfloat log1pf(float);\nfloat logf(float);\nfloat sqrtf(float);\n#ifdef acoshf\n#undef acoshf\n#endif\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\n#ifdef asinhf\n#undef asinhf\n#endif\nstatic float asinhf(float xx)\n{\n\tfloat x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e5) {\n\t\td = x;\n\t} else {\n\t\td = sqrtf(x*x + 1);\n\t}\n\treturn sign*log1pf(x*(1.0 + x/(d+1)));\n}\n\n#ifdef atanhf\n#undef atanhf\n#endif\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\n#ifdef acoshf\n#undef acoshf\n#endif\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\n#ifdef asinhf\n#undef asinhf\n#endif\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\n#ifdef atanhf\n#undef atanhf\n#endif\nstatic float atanhf(float x)\n{\n return (float)atanh((double)(x));\n}\n#endif\n#endif\n\n\n#if !defined(HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE)\n#ifdef HAVE_LONGDOUBLE_FUNCS\n#ifdef logl\n#undef logl\n#endif\n#ifdef sqrtl\n#undef sqrtl\n#endif\n#ifdef log1pl\n#undef log1pl\n#endif\nlongdouble logl(longdouble);\nlongdouble sqrtl(longdouble);\nlongdouble log1pl(longdouble);\n#ifdef acoshl\n#undef acoshl\n#endif\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\n#ifdef asinhl\n#undef asinhl\n#endif\nstatic longdouble asinhl(longdouble xx)\n{\n\tlongdouble x, d;\n\tint sign;\n\tif (xx < 0.0) {\n\t\tsign = -1;\n\t\tx = -xx;\n\t}\n\telse {\n\t\tsign = 1;\n\t\tx = xx;\n\t}\n\tif (x > 1e17) {\n\t\td = x;\n\t} else {\n\t\td = sqrtl(x*x + 1);\n\t}\n\treturn sign*log1pl(x*(1.0 + x/(d+1)));\n}\n\n#ifdef atanhl\n#undef atanhl\n#endif\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n\n#else\n\n#ifdef acoshl\n#undef acoshl\n#endif\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\n#ifdef asinhl\n#undef asinhl\n#endif\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\n#ifdef atanhl\n#undef atanhl\n#endif\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\n}\n\n#endif\n#endif\n\n\n#ifdef HAVE_HYPOT\n#if !defined(NeXT) && !defined(_MSC_VER)\nextern double hypot(double, double);\n#endif\n#else\nstatic double hypot(double x, double y)\n{\n\tdouble yx;\n\n\tx = fabs(x);\n\ty = fabs(y);\n\tif (x < y) {\n\t\tdouble temp = x;\n\t\tx = y;\n\t\ty = temp;\n\t}\n\tif (x == 0.)\n\t\treturn 0.;\n\telse {\n\t\tyx = y/x;\n\t\treturn x*sqrt(1.+yx*yx);\n\t}\n}\n#endif\n\n\n#ifndef HAVE_RINT\nstatic double \nrint (double x)\n{\n\tdouble y, r;\n\t\n\ty = floor(x);\n\tr = x - y;\n\t\n\tif (r > 0.5) goto rndup;\n\n\t/* Round to nearest even */\n\tif (r==0.5) {\n\t\tr = y - 2.0*floor(0.5*y);\n\t\tif (r==1.0) {\n\t\trndup:\t \n\t\t\ty+=1.0;\n\t\t}\n\t}\n\treturn y;\n}\n#endif\n\n\n\n/* Define isnan, isinf, isfinite, signbit if needed */\n/* Use fpclassify if possible */\n/* isnan, isinf --\n these will use macros and then fpclassify if available before\n defaulting to a dumb convert-to-double version...\n\n isfinite -- define a macro if not already available\n signbit -- if macro available use it, otherwise define a function\n and a dumb convert-to-double version for other types.\n*/\n\n#if defined(fpclassify)\n\n#if !defined(isnan)\n#define isnan(x) (fpclassify(x) == FP_NAN)\n#endif\n#if !defined(isinf)\n#define isinf(x) (fpclassify(x) == FP_INFINITE)\n#endif\n\n#else /* check to see if already have a function like this */\n\n#if !defined(HAVE_ISNAN)\n\n#if !defined(isnan)\n#include \"_isnan.c\"\n#endif\n#endif /* HAVE_ISNAN */\n\n#if !defined(HAVE_ISINF)\n#if !defined(isinf)\n#define isinf(x) (!isnan((x)) && isnan((x)-(x)))\n#endif\n#endif /* HAVE_ISINF */\n\n#endif /* defined(fpclassify) */\n\n\n/* Define signbit if needed */\n#if !defined(signbit)\n#include \"_signbit.c\"\n#endif\n\n/* Now defined the extended type macros */\n\n#if !defined(isnan)\n\n#if !defined(HAVE_LONGDOUBLE_FUNCS) || !defined(HAVE_ISNAN)\n#define isnanl(x) isnan((double)(x))\n#endif\n\n#if !defined(HAVE_FLOAT_FUNCS) || !defined(HAVE_ISNAN)\n#define isnanf(x) isnan((double)(x))\n#endif\n\n#else /* !defined(isnan) */\n\n#define isnanl(x) isnan((x))\n#define isnanf(x) isnan((x))\n\n#endif /* !defined(isnan) */\n\n\n#if !defined(isinf)\n\n#if !defined(HAVE_LONGDOUBLE_FUNCS) || !defined(HAVE_ISINF)\n#define isinfl(x) (!isnanl((x)) && isnanl((x)-(x)))\n#endif\n\n#if !defined(HAVE_FLOAT_FUNCS) || !defined(HAVE_ISINF)\n#define isinff(x) (!isnanf((x)) && isnanf((x)-(x)))\n#endif\n\n#else /* !defined(isinf) */\n\n#define isinfl(x) isinf((x))\n#define isinff(x) isinf((x))\n\n#endif /* !defined(isinf) */\n\n\n#if !defined(signbit)\n#define signbitl(x) ((longdouble) signbit((double)(x)))\n#define signbitf(x) ((float) signbit((double) (x)))\n#else\n#define signbitl(x) signbit((x))\n#define signbitf(x) signbit((x))\n#endif\n\n#if !defined(isfinite)\n#define isfinite(x) (!(isinf((x)) || isnan((x))))\n#endif\n#define isfinitef(x) (!(isinff((x)) || isnanf((x))))\n#define isfinitel(x) (!(isinfl((x)) || isnanl((x))))\n\n\n/* First, the C functions that do the real work */\n\n/* if C99 extensions not available then define dummy functions that use the\n double versions for\n\n sin, cos, tan\n sinh, cosh, tanh,\n fabs, floor, ceil, fmod, sqrt, log10, log, exp, fabs\n asin, acos, atan,\n asinh, acosh, atanh\n\n hypot, atan2, pow\n*/\n\n/**begin repeat\n\n#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan,rint)*2#\n#typ=longdouble*17, float*17#\n#c=l*17,f*17#\n#TYPE=LONGDOUBLE*17, FLOAT*17#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef @kind@@c@\n#undef @kind@@c@\n#endif\n@typ@ @kind@@c@(@typ@ x) {\n\treturn (@typ@) @kind@((double)x);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n\n#kind=(atan2,hypot,pow,fmod)*2#\n#typ=longdouble*4, float*4#\n#c=l*4,f*4#\n#TYPE=LONGDOUBLE*4,FLOAT*4#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef @kind@@c@\n#undef @kind@@c@\n#endif\n@typ@ @kind@@c@(@typ@ x, @typ@ y) {\n\treturn (@typ@) @kind@((double)x, (double) y);\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n#kind=modf*2#\n#typ=longdouble, float#\n#c=l,f#\n#TYPE=LONGDOUBLE, FLOAT#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\n#ifdef modf@c@\n#undef modf@c@\n#endif\n@typ@ modf@c@(@typ@ x, @typ@ *iptr) {\n double nx, niptr, y;\n nx = (double) x;\n y = modf(nx, &niptr);\n *iptr = (@typ@) niptr;\n return (@typ@) y;\n}\n#endif\n/**end repeat**/\n\n\n\n#ifndef HAVE_LOG1P\ndouble log1p(double x)\n{\n\tdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn log(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_LONGDOUBLE_FUNCS)\n#ifdef log1pl\n#undef log1pl\n#endif\nlongdouble log1pl(longdouble x)\n{\n\tlongdouble u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logl(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#if !defined(HAVE_LOG1P) || !defined(HAVE_FLOAT_FUNCS)\n#ifdef log1pf\n#undef log1pf\n#endif\nfloat log1pf(float x)\n{\n\tfloat u = 1. + x;\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else {\n\t\treturn logf(u) * x / (u-1.);\n\t}\n}\n#endif\n\n#ifndef HAVE_EXPM1\nstatic double expm1(double x)\n{\n\tdouble u = exp(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/log(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_LONGDOUBLE_FUNCS)\n#ifdef expml1\n#undef expml1\n#endif\nstatic longdouble expm1l(longdouble x)\n{\n\tlongdouble u = expl(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logl(u);\n\t}\n}\n#endif\n\n#if !defined(HAVE_EXPM1) || !defined(HAVE_FLOAT_FUNCS)\n#ifdef expm1f\n#undef expm1f\n#endif\nstatic float expm1f(float x)\n{\n\tfloat u = expf(x);\n\tif (u == 1.0) {\n\t\treturn x;\n\t} else if (u-1.0 == -1.0) {\n\t\treturn -1;\n\t} else {\n\t\treturn (u-1.0) * x/logf(u);\n\t}\n}\n#endif\n\n\n\n\n/* Don't pass structures between functions (only pointers) because how\n structures are passed is compiler dependent and could cause\n segfaults if ufuncobject.c is compiled with a different compiler\n than an extension that makes use of the UFUNC API\n*/\n\n/**begin repeat\n\n#typ=float, double, longdouble#\n#c=f,,l#\n*/\n\n/* constants */\nstatic c@typ@ nc_1@c@ = {1., 0.};\nstatic c@typ@ nc_half@c@ = {0.5, 0.};\nstatic c@typ@ nc_i@c@ = {0., 1.};\nstatic c@typ@ nc_i2@c@ = {0., 0.5};\n/*\nstatic c@typ@ nc_mi@c@ = {0., -1.};\nstatic c@typ@ nc_pi2@c@ = {M_PI/2., 0.};\n*/\n\nstatic void\nnc_sum@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real + b->real;\n\tr->imag = a->imag + b->imag;\n\treturn;\n}\n\nstatic void\nnc_diff@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tr->real = a->real - b->real;\n\tr->imag = a->imag - b->imag;\n\treturn;\n}\n\nstatic void\nnc_neg@c@(c@typ@ *a, c@typ@ *r)\n{\n\tr->real = -a->real;\n\tr->imag = -a->imag;\n\treturn;\n}\n\nstatic void\nnc_prod@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tregister @typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\tr->real = ar*br - ai*bi;\n\tr->imag = ar*bi + ai*br;\n\treturn;\n}\n\nstatic void\nnc_quot@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\n\tregister @typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\tregister @typ@ d = br*br + bi*bi;\n\tr->real = (ar*br + ai*bi)/d;\n\tr->imag = (ai*br - ar*bi)/d;\n\treturn;\n}\n\nstatic void\nnc_floor_quot@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\tregister @typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\tregister @typ@ d = br*br + bi*bi;\n\tr->real = floor@c@((ar*br + ai*bi)/d);\n\tr->imag = 0;\n\treturn;\n}\n\nstatic void\nnc_sqrt@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ s,d;\n\tif (x->real == 0. && x->imag == 0.)\n\t\t*r = *x;\n\telse {\n\t\ts = sqrt@c@(0.5*(fabs@c@(x->real) + hypot@c@(x->real,x->imag)));\n\t\td = 0.5*x->imag/s;\n\t\tif (x->real > 0.) {\n\t\t\tr->real = s;\n\t\t\tr->imag = d;\n\t\t}\n\t\telse if (x->imag >= 0.) {\n\t\t\tr->real = d;\n\t\t\tr->imag = s;\n\t\t}\n\t\telse {\n\t\t\tr->real = -d;\n\t\t\tr->imag = -s;\n\t\t}\n\t}\n\treturn;\n}\n\nstatic void\nnc_log@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ l = hypot@c@(x->real,x->imag);\n\tr->imag = atan2@c@(x->imag, x->real);\n\tr->real = log@c@(l);\n\treturn;\n}\n\nstatic void\nnc_log1p@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ l = hypot@c@(x->real + 1.0,x->imag);\n\tr->imag = atan2@c@(x->imag, x->real + 1.0);\n\tr->real = log@c@(l);\n\treturn;\n}\n\nstatic void\nnc_exp@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ a = exp@c@(x->real);\n\tr->real = a*cos@c@(x->imag);\n\tr->imag = a*sin@c@(x->imag);\n\treturn;\n}\n\nstatic void\nnc_expm1@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ a = exp@c@(x->real);\n\tr->real = a*cos@c@(x->imag) - 1.0;\n\tr->imag = a*sin@c@(x->imag);\n\treturn;\n}\n\nstatic void\nnc_pow@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n intp n;\n @typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\n\tif (br == 0. && bi == 0.) {\n\t\tr->real = 1.;\n\t\tr->imag = 0.;\n return;\n\t}\n\tif (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n return;\n\t}\n if (bi == 0 && (n=(intp)br) == br) {\n if (n > -100 && n < 100) {\n c@typ@ p, aa;\n intp mask = 1;\n if (n < 0) n = -n;\n aa = nc_1@c@;\n p.real = ar; p.imag = ai;\n while (1) {\n if (n & mask)\n nc_prod@c@(&aa,&p,&aa);\n mask <<= 1;\n if (n < mask || mask <= 0) break;\n nc_prod@c@(&p,&p,&p);\n }\n r->real = aa.real; r->imag = aa.imag;\n if (br < 0) nc_quot@c@(&nc_1@c@, r, r);\n return;\n }\n }\n /* complexobect.c uses an inline version of this formula\n investigate whether this had better performance or accuracy */\n nc_log@c@(a, r);\n nc_prod@c@(r, b, r);\n nc_exp@c@(r, r);\n return;\n}\n\n\nstatic void\nnc_prodi@c@(c@typ@ *x, c@typ@ *r)\n{\n\tr->real = -x->imag;\n\tr->imag = x->real;\n\treturn;\n}\n\n\nstatic void\nnc_acos@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x,x,r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_sum@c@(x, r, r);\n\tnc_log@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/* return nc_neg(nc_prodi(nc_log(nc_sum(x,nc_prod(nc_i,\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x))))))));\n\t*/\n}\n\nstatic void\nnc_acosh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x, x, r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_sum@c@(x, r, r);\n\tnc_log@c@(r, r);\n\treturn;\n\t/*\n\t return nc_log(nc_sum(x,nc_prod(nc_i,\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x))))));\n\t*/\n}\n\nstatic void\nnc_asin@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_prod@c@(x, x, r);\n\tnc_diff@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_prodi@c@(x, pa);\n\tnc_sum@c@(pa, r, r);\n\tnc_log@c@(r, r);\n\tnc_prodi@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/*\n\t return nc_neg(nc_prodi(nc_log(nc_sum(nc_prod(nc_i,x),\n\t nc_sqrt(nc_diff(nc_1,nc_prod(x,x)))))));\n\t*/\n}\n\n\nstatic void\nnc_asinh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_prod@c@(x, x, r);\n\tnc_sum@c@(&nc_1@c@, r, r);\n\tnc_sqrt@c@(r, r);\n\tnc_diff@c@(r, x, r);\n\tnc_log@c@(r, r);\n\tnc_neg@c@(r, r);\n\treturn;\n\t/*\n\t return nc_neg(nc_log(nc_diff(nc_sqrt(nc_sum(nc_1,nc_prod(x,x))),x)));\n\t*/\n}\n\nstatic void\nnc_atan@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_diff@c@(&nc_i@c@, x, pa);\n\tnc_sum@c@(&nc_i@c@, x, r);\n\tnc_quot@c@(r, pa, r);\n\tnc_log@c@(r,r);\n\tnc_prod@c@(&nc_i2@c@, r, r);\n\treturn;\n\t/*\n\t return nc_prod(nc_i2,nc_log(nc_quot(nc_sum(nc_i,x),nc_diff(nc_i,x))));\n\t*/\n}\n\nstatic void\nnc_atanh@c@(c@typ@ *x, c@typ@ *r)\n{\n\tc@typ@ a, *pa=&a;\n\tnc_diff@c@(&nc_1@c@, x, r);\n\tnc_sum@c@(&nc_1@c@, x, pa);\n\tnc_quot@c@(pa, r, r);\n\tnc_log@c@(r, r);\n\tnc_prod@c@(&nc_half@c@, r, r);\n\treturn;\n\t/*\n\t return nc_prod(nc_half,nc_log(nc_quot(nc_sum(nc_1,x),nc_diff(nc_1,x))));\n\t*/\n}\n\nstatic void\nnc_cos@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos@c@(xr)*cosh@c@(xi);\n\tr->imag = -sin@c@(xr)*sinh@c@(xi);\n\treturn;\n}\n\nstatic void\nnc_cosh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos(xi)*cosh(xr);\n\tr->imag = sin(xi)*sinh(xr);\n\treturn;\n}\n\n\n#define M_LOG10_E 0.434294481903251827651128918916605082294397\n\nstatic void\nnc_log10@c@(c@typ@ *x, c@typ@ *r)\n{\n\tnc_log@c@(x, r);\n\tr->real *= M_LOG10_E;\n\tr->imag *= M_LOG10_E;\n\treturn;\n}\n\nstatic void\nnc_sin@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = sin@c@(xr)*cosh@c@(xi);\n\tr->imag = cos@c@(xr)*sinh@c@(xi);\n\treturn;\n}\n\nstatic void\nnc_sinh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ xr=x->real, xi=x->imag;\n\tr->real = cos@c@(xi)*sinh@c@(xr);\n\tr->imag = sin@c@(xi)*cosh@c@(xr);\n\treturn;\n}\n\nstatic void\nnc_tan@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ sr,cr,shi,chi;\n\t@typ@ rs,is,rc,ic;\n\t@typ@ d;\n\t@typ@ xr=x->real, xi=x->imag;\n\tsr = sin@c@(xr);\n\tcr = cos@c@(xr);\n\tshi = sinh(xi);\n\tchi = cosh(xi);\n\trs = sr*chi;\n\tis = cr*shi;\n\trc = cr*chi;\n\tic = -sr*shi;\n\td = rc*rc + ic*ic;\n\tr->real = (rs*rc+is*ic)/d;\n\tr->imag = (is*rc-rs*ic)/d;\n\treturn;\n}\n\nstatic void\nnc_tanh@c@(c@typ@ *x, c@typ@ *r)\n{\n\t@typ@ si,ci,shr,chr;\n\t@typ@ rs,is,rc,ic;\n\t@typ@ d;\n\t@typ@ xr=x->real, xi=x->imag;\n\tsi = sin@c@(xi);\n\tci = cos@c@(xi);\n\tshr = sinh@c@(xr);\n\tchr = cosh@c@(xr);\n\trs = ci*shr;\n\tis = si*chr;\n\trc = ci*chr;\n\tic = si*shr;\n\td = rc*rc + ic*ic;\n\tr->real = (rs*rc+is*ic)/d;\n\tr->imag = (is*rc-rs*ic)/d;\n\treturn;\n}\n\n/**end repeat**/\n\n\n/**begin repeat\n\n#TYPE=(BOOL, BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#\n#OP=||, +*13, ^, -*13#\n#kind=add*14, subtract*14#\n#typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; ireal;\n xi = x->imag;\n y->real = xr*xr - xi*xi;\n y->imag = 2*xr*xi;\n }\n}\n/**end repeat**/\n\nstatic PyObject *\nPy_square(PyObject *o)\n{\n return PyNumber_Multiply(o, o);\n}\n\n\n/**begin repeat\n#TYP=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#typ=char, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n*/\nstatic void\n@TYP@_reciprocal(char **args, intp *dimensions, intp *steps, void *data)\n{\n intp i, is1 = steps[0], os = steps[1], n = dimensions[0];\n char *i1 = args[0], *op = args[1];\n\n for (i = 0; i < n; i++, i1 += is1, op += os) {\n @typ@ x = *((@typ@ *)i1);\n *((@typ@ *)op) = 1.0 / x;\n }\n}\n/**end repeat**/\n\n/**begin repeat\n#TYP=CFLOAT,CDOUBLE,CLONGDOUBLE#\n#typ=float, double, longdouble#\n*/\nstatic void\n@TYP@_reciprocal(char **args, intp *dimensions, intp *steps, void *data)\n{\n intp i, is1 = steps[0], os = steps[1], n = dimensions[0];\n char *i1 = args[0], *op = args[1];\n c@typ@ *x, *y;\n @typ@ xr, xi, r, denom;\n\n for (i = 0; i < n; i++, i1 += is1, op += os) {\n x = (c@typ@ *)i1;\n y = (c@typ@ *)op;\n xr = x->real;\n xi = x->imag;\n if (fabs(xi) <= fabs(xr)) {\n r = xi / xr;\n denom = xr + xi * r;\n y->real = 1 / denom;\n y->imag = -r / denom;\n } else {\n r = xr / xi;\n denom = xr * r + xi;\n y->real = r / denom;\n y->imag = -1 / denom;\n }\n }\n}\n/**end repeat**/\n\n\n\nstatic PyObject *\nPy_reciprocal(PyObject *o)\n{\n PyObject *one, *result;\n one = PyInt_FromLong(1);\n if (!one) return NULL;\n result = PyNumber_Divide(one, o);\n Py_DECREF(one);\n return result;\n}\n\n/* ones_like is defined here because it's used for x**0 */\n\n/**begin repeat\n#TYP=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE#\n#typ=char, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n*/\nstatic void\n@TYP@_ones_like(char **args, intp *dimensions, intp *steps, void *data)\n{\n intp i, os = steps[1], n = dimensions[0];\n char *op = args[1];\n\n for (i = 0; i < n; i++, op += os) {\n *((@typ@ *)op) = 1;\n }\n}\n/**end repeat**/\n\n/**begin repeat\n#TYP=CFLOAT,CDOUBLE,CLONGDOUBLE#\n#typ=float, double, longdouble#\n*/\nstatic void\n@TYP@_ones_like(char **args, intp *dimensions, intp *steps, void *data)\n{\n intp i, is1 = steps[0], os = steps[1], n = dimensions[0];\n char *i1 = args[0], *op = args[1];\n c@typ@ *x, *y;\n @typ@ xr, xi, xmag2;\n \n for (i = 0; i < n; i++, i1 += is1, op += os) {\n x = (c@typ@ *)i1;\n y = (c@typ@ *)op;\n xr = x->real;\n xi = x->imag;\n xmag2 = xr*xr + xi*xi;\n y->real = 1.0;\n y->imag = 0.0;\n }\n}\n/**end repeat**/\n\nstatic PyObject *\nPy_get_one(PyObject *o)\n{\n return PyInt_FromLong(1);\n}\n\n\nstatic int numeric_zero = 0;\n\n/**begin repeat\n#TYP=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG#\n#typ=char, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n#btyp=float*4, double*6#\n*/\nstatic void\n@TYP@_power(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i, is1=steps[0],is2=steps[1];\n\tregister intp os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\t@btyp@ x, y, v;\n @typ@ z;\n\n\tfor(i=0; i, >=, <, <=, ==, !=, &&, ||, &, |, ^#\n**/\nstatic void\nBOOL_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tBool in1, in2;\n\tfor(i=0; i*13, >=*13, <*13, <=*13#\n#typ=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*4#\n#kind= greater*13, greater_equal*13, less*13, less_equal*13#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, >=*3, <*3, <=*3#\n#typ=(cfloat, cdouble, clongdouble)*4#\n#kind= greater*3, greater_equal*3, less*3, less_equal*3#\n*/\n\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; ireal == ((@typ@ *)i2)->real)\n\t\t\t*((Bool *)op)=((@typ@ *)i1)->imag @OP@ \\\n\t\t\t\t((@typ@ *)i2)->imag;\n\t\telse\n\t\t\t*((Bool *)op)=((@typ@ *)i1)->real @OP@ \\\n\t\t\t\t((@typ@ *)i2)->real;\n\t}\n}\n/**end repeat**/\n\n\n/**begin repeat\n#TYPE=(BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*4#\n#typ=(byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*4#\n#OP= ==*13, !=*13, &&*13, ||*13#\n#kind=equal*13, not_equal*13, logical_and*13, logical_or*13#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i 0 ? 1 : ((x) < 0 ? -1 : 0))\n#define _SIGN2(x) ((x) == 0 ? 0 : 1)\n#define _SIGNC(x) (((x).real > 0) ? 1 : ((x).real < 0 ? -1 : ((x).imag > 0 ? 1 : ((x).imag < 0) ? -1 : 0)))\n/**begin repeat\n#TYPE=BYTE,SHORT,INT,LONG,LONGLONG,FLOAT,DOUBLE,LONGDOUBLE,UBYTE,USHORT,UINT,ULONG,ULONGLONG#\n#typ=byte,short,int,long,longlong,float,double,longdouble,ubyte,ushort,uint,ulong,ulonglong#\n#func=_SIGN1*8,_SIGN2*5#\n */\nstatic void\n@TYPE@_sign(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],os=steps[1], n=dimensions[0];\n\tchar *i1=args[0], *op=args[1];\n @typ@ t1;\n\tfor(i=0; ireal ||\t\\\n\t\t\t\t ((@typ@ *)i1)->imag);\n\t}\n}\n/**end repeat**/\n\n\n\n\n/**begin repeat\n#TYPE=BYTE,SHORT,INT,LONG,LONGLONG#\n#typ=byte, short, int, long, longlong#\n#ftyp=float*2,double*2,longdouble*1#\n#c=f*2,,,l*1#\n*/\nstatic void\n@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tregister @typ@ ix,iy, tmp;\n\tfor(i=0; i 0) == (iy > 0)) {\n\t\t\t*((@typ@ *)op) = ix % iy;\n\t\t}\n\t\telse { /* handle mixed case the way Python does */\n\t\t\ttmp = ix % iy;\n\t\t\tif (tmp) tmp += iy;\n\t\t\t*((@typ@ *)op)= tmp;\n\t\t}\n\t}\n}\n/**end repeat**/\n\n/**begin repeat\n#TYPE=UBYTE,USHORT,UINT,ULONG,ULONGLONG#\n#typ=ubyte, ushort, uint, ulong, ulonglong#\n*/\nstatic void\n@TYPE@_remainder(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tregister @typ@ ix,iy;\n\tfor(i=0; i>*10#\n#kind=bitwise_and*10, bitwise_or*10, bitwise_xor*10, left_shift*10, right_shift*10#\n\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tregister char *i1=args[0], *i2=args[1], *op=args[2];\n\tif (is1 == 0) {\n\t\tregister @typ@ t1 = *((@typ@ *)i1);\n\t\tfor (i=0; ireal || ((@typ@ *)i1)->imag;\n\t\tp2 = ((@typ@ *)i2)->real || ((@typ@ *)i2)->imag;\n\t\t*((Bool *)op)= (p1 || p2) && !(p1 && p2);\n\t}\n}\n/**end repeat**/\n\n\n\n/**begin repeat\n\n#TYPE=(BOOL,BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG,LONGLONG,ULONGLONG,FLOAT,DOUBLE,LONGDOUBLE)*2#\n#OP= >*14, <*14#\n#typ=(Bool, byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble)*2#\n#kind= maximum*14, minimum*14#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\tfor(i=0; i*3, <*3#\n#typ=(cfloat, cdouble, clongdouble)*2#\n#kind= maximum*3, minimum*3#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i;\n\tintp is1=steps[0],is2=steps[1],os=steps[2], n=dimensions[0];\n\tchar *i1=args[0], *i2=args[1], *op=args[2];\n @typ@ *i1c, *i2c;\n\tfor(i=0; ireal @OP@ i2c->real) || \\\n ((i1c->real==i2c->real) && (i1c->imag @OP@ i2c->imag)))\n memmove(op, i1, sizeof(@typ@));\n else\n memmove(op, i2, sizeof(@typ@));\n\t}\n}\n/**end repeat**/\n\n\n\n/*** isinf, isinf, isfinite, signbit ***/\n/**begin repeat\n#kind=isnan*3, isinf*3, isfinite*3, signbit*3#\n#TYPE=(FLOAT, DOUBLE, LONGDOUBLE)*4#\n#typ=(float, double, longdouble)*4#\n#c=(f,,l)*4#\n*/\nstatic void\n@TYPE@_@kind@(char **args, intp *dimensions, intp *steps, void *func)\n{\n register intp i;\n intp is=steps[0], os=steps[1], n=dimensions[0];\n char *ip=args[0], *op=args[1];\n for(i=0; i> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n**/\n#if SIZEOF_@SIZE@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n\t generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n**/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n\tgenerate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #neg=(1,0)*5#\n**/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n if (b == 0) {\n\tgenerate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if (b == -1 && a < 0 && a == -a) {\n\tgenerate_overflow_error();\n\t*out = a / b;\n }\n#endif\n else {\n\t*out = a / b;\n }\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\nstatic void\n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {\n if (a == 0 || b == 0) {\n\tif (b == 0) generate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if ((a > 0) == (b > 0)) {\n\t*out = a % b;\n }\n else { /* handled like Python does */\n\t*out = a % b;\n\tif (*out) *out += b;\n }\n#else\n *out = a % b;\n#endif\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n**/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n *(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/* b will always be positive in this call */\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n \n}\n/**end repeat**/\n\n\n\n/* QUESTION: Should we check for overflow / underflow in (l,r)shift? */\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n**/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_floor)(@name@);\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) \\\n *(outp) = _basic_@name@_floor((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\\\n (outp)->real = (a).real + (b).real;\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\\\n (outp)->real = (a).real - (b).real;\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do {\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) /\t\\\n ((a).real*(b).real + (b).imag*(b).imag);\t\t\t\\\n (outp)->imag = 0;\t\t\t\t\t\t\\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - _basic_@name@_floor(a/b)*b;\n} \n/**end repeat**/ \n\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_ctype_divmod(a, b, out, out2) {\t\\\n @name@_ctype_floor_divide(a, b, out);\t\\\n @name@_ctype_remainder(a, b, out2);\t\t\\\n }\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_pow)(@name@ a, @name@ b);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = _basic_@name@_pow(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #uns=(1,0)*5,0*3#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n#if @uns@\n generate_overflow_error();\n#endif\n *out = -a;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n/* Get the nc_powf, nc_pow, and nc_powl functions from \n the data area of the power ufunc in umathmodule. \n*/\n\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n out->real = a.real;\n out->imag = a.imag;\n}\nstatic void (*_basic_@name@_pow)(@name@ *, @name@ *, @name@ *);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out)\n{\n _basic_@name@_pow(&a, &b, out);\n}\n/**end repeat**/\n\n\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, floor_divide*6, true_divide*6, divmod*3, remainder*3#\n #fperr=1*70,0*50,1*52#\n #twoout=0*50,1*10,0*106,1*3,0*3#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*12, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*12, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n**/\n\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @twoout@\n @otyp@ out2;\n PyObject *obj;\n#endif\n\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @twoout@\n @name@_ctype_@oper@(arg1, arg2, &out, &out2);\n#else\n @name@_ctype_@oper@(arg1, arg2, &out);\n#endif\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n\n#if @twoout@\n ret = PyTuple_New(2);\n if (ret==NULL) return NULL;\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out;\n PyTuple_SET_ITEM(ret, 0, obj);\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out2;\n PyTuple_SET_ITEM(ret, 1, obj);\n#else\n ret = PyArrayScalar_New(@OName@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @OName@) = out;\n#endif\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float, double, longdouble, cfloat, cdouble, clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #otyp=float*4, double*6, float, double, longdouble, cfloat, cdouble, clongdouble#\n #OName=Float*4, Double*6, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #isint=(1,0)*5,0*6#\n #cmplx=0*13,1*3#\n**/\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n @otyp@ out1;\n int retstatus;\n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n }\n\n PyUFunc_clearfperr();\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @cmplx@\n if (arg2.real == 0 && arg1.real == 0) {\n\tout1.real = out.real = 1.0;\n\tout1.imag = out.imag = 0.0;\n }\n#else\n if (arg2 == 0) {\n\tout1 = out = 1;\n } \n#endif\n#if @isint@\n else if (arg2 < 0) {\n\t@name@_ctype_power(arg1, -arg2, &out);\n\tout1 = 1.0 / out;\n }\n#endif\n else {\n\t@name@_ctype_power(arg1, arg2, &out);\n }\n\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n\n#if @isint@\n if (arg2 < 0) {\n\tret = PyArrayScalar_New(@OName@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @OName@) = out1;\n }\n else {\n\tret = PyArrayScalar_New(@Name@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @Name@) = out;\n }\n#else\n ret = PyArrayScalar_New(@Name@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @Name@) = out;\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n#name=(cfloat,cdouble,clongdouble)*2#\n#oper=divmod*3,remainder*3#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3, byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*3, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n #oper=negative*16, positive*16, absolute*16, invert*10#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n#name=float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_invert NULL\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic int\nget_functions(void)\n{\n PyObject *mm, *obj;\n void **funcdata;\n char *signatures;\n int i, j;\n int ret = -1;\n\t\n /* Get the nc_pow functions */\n /* Get the pow functions */\n mm = PyImport_ImportModule(\"numpy.core.umath\");\n if (mm == NULL) return -1;\n \n obj = PyObject_GetAttrString(mm, \"power\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_pow = funcdata[j];\n _basic_double_pow = funcdata[j+1];\n _basic_longdouble_pow = funcdata[j+2];\n _basic_cfloat_pow = funcdata[j+3];\n _basic_cdouble_pow = funcdata[j+4];\n _basic_clongdouble_pow = funcdata[j+5];\n\n Py_DECREF(obj);\n\n /* Get the floor functions */\n\n obj = PyObject_GetAttrString(mm, \"floor\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_floor = funcdata[j];\n _basic_double_floor = funcdata[j+1];\n _basic_longdouble_floor = funcdata[j+2];\n\n Py_DECREF(obj);\n ret = 0;\n fail:\n Py_DECREF(mm);\n return ret;\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n if (get_functions() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n\n NOT FINISHED\n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n**/\n#if SIZEOF_@SIZE@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n\t generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n**/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n\tgenerate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #neg=(1,0)*5#\n**/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n if (b == 0) {\n\tgenerate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if (b == -1 && a < 0 && a == -a) {\n\tgenerate_overflow_error();\n\t*out = a / b;\n }\n#endif\n else {\n\t*out = a / b;\n }\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\nstatic void\n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {\n if (a == 0 || b == 0) {\n\tif (b == 0) generate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if ((a > 0) == (b > 0)) {\n\t*out = a % b;\n }\n else { /* handled like Python does */\n\t*out = a % b;\n\tif (*out) *out += b;\n }\n#else\n *out = a % b;\n#endif\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n**/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n *(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/* b will always be positive in this call */\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n \n}\n/**end repeat**/\n\n\n\n/* QUESTION: Should we check for overflow / underflow in (l,r)shift? */\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n**/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_floor)(@name@);\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) \\\n *(outp) = _basic_@name@_floor((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\\\n (outp)->real = (a).real + (b).real;\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\\\n (outp)->real = (a).real - (b).real;\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do {\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) /\t\\\n ((a).real*(b).real + (b).imag*(b).imag);\t\t\t\\\n (outp)->imag = 0;\t\t\t\t\t\t\\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - _basic_@name@_floor(a/b)*b;\n} \n/**end repeat**/ \n\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_ctype_divmod(a, b, out, out2) {\t\\\n @name@_ctype_floor_divide(a, b, out);\t\\\n @name@_ctype_remainder(a, b, out2);\t\t\\\n }\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_pow)(@name@ a, @name@ b);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = _basic_@name@_pow(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #uns=(1,0)*5,0*3#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n#if @uns@\n generate_overflow_error();\n#endif\n *out = -a;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n/* Get the nc_powf, nc_pow, and nc_powl functions from \n the data area of the power ufunc in umathmodule. \n*/\n\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n out->real = a.real;\n out->imag = a.imag;\n}\nstatic void (*_basic_@name@_pow)(@name@ *, @name@ *, @name@ *);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out)\n{\n _basic_@name@_pow(&a, &b, out);\n}\n/**end repeat**/\n\n\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, floor_divide*6, true_divide*6, divmod*3, remainder*3#\n #fperr=1*70,0*50,1*52#\n #twoout=0*50,1*10,0*106,1*3,0*3#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*12, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*12, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n**/\n\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @twoout@\n @otyp@ out2;\n PyObject *obj;\n#endif\n\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @twoout@\n @name@_ctype_@oper@(arg1, arg2, &out, &out2);\n#else\n @name@_ctype_@oper@(arg1, arg2, &out);\n#endif\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n\n#if @twoout@\n ret = PyTuple_New(2);\n if (ret==NULL) return NULL;\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out;\n PyTuple_SET_ITEM(ret, 0, obj);\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out2;\n PyTuple_SET_ITEM(ret, 1, obj);\n#else\n ret = PyArrayScalar_New(@OName@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @OName@) = out;\n#endif\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float, double, longdouble, cfloat, cdouble, clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #otyp=float*4, double*6, float, double, longdouble, cfloat, cdouble, clongdouble#\n #OName=Float*4, Double*6, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #isint=(1,0)*5,0*6#\n #cmplx=0*13,1*3#\n**/\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n @otyp@ out1;\n int retstatus;\n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n }\n\n PyUFunc_clearfperr();\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @cmplx@\n if (arg2.real == 0 && arg1.real == 0) {\n\tout1.real = out.real = 1.0;\n\tout1.imag = out.imag = 0.0;\n }\n#else\n if (arg2 == 0) {\n\tout1 = out = 1;\n } \n#endif\n#if @isint@\n else if (arg2 < 0) {\n\t@name@_ctype_power(arg1, -arg2, &out);\n\tout1 = 1.0 / out;\n }\n#endif\n else {\n\t@name@_ctype_power(arg1, arg2, &out);\n }\n\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n\n#if @isint@\n if (arg2 < 0) {\n\tret = PyArrayScalar_New(@OName@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @OName@) = out1;\n }\n else {\n\tret = PyArrayScalar_New(@Name@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @Name@) = out;\n }\n#else\n ret = PyArrayScalar_New(@Name@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @Name@) = out;\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n#name=(cfloat,cdouble,clongdouble)*2#\n#oper=divmod*3,remainder*3#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3, byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*3, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n #oper=negative*16, positive*16, absolute*16, invert*10#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n#name=float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_invert NULL\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic int\nget_functions(void)\n{\n PyObject *mm, *obj;\n void **funcdata;\n char *signatures;\n int i, j;\n\t\n /* Get the nc_pow functions */\n /* Get the pow functions */\n mm = PyImport_ImportModule(\"numpy.core.umath\");\n if (mm == NULL) return -1;\n \n obj = PyObject_GetAttrString(mm, \"power\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_pow = funcdata[j];\n _basic_double_pow = funcdata[j+1];\n _basic_longdouble_pow = funcdata[j+2];\n _basic_cfloat_pow = funcdata[j+3];\n _basic_cdouble_pow = funcdata[j+4];\n _basic_clongdouble_pow = funcdata[j+5];\n\n Py_DECREF(obj);\n\n /* Get the floor functions */\n\n obj = PyObject_GetAttrString(mm, \"floor\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_floor = funcdata[j];\n _basic_double_floor = funcdata[j+1];\n _basic_longdouble_floor = funcdata[j+2];\n\n Py_DECREF(obj);\n \n fail:\n Py_DECREF(mm);\n return -1;\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n if (get_functions() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + " int ret = -1;", + " ret = 0;", + " return ret;" + ], + "deleted": [ + "", + " NOT FINISHED", + "", + " return -1;" + ] + } + } + ] + }, + { + "hash": "da478e7332dc8dd0fc9a3fdbc1101a7eed831990", + "msg": "Fix-up size check for 64-bit", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-04-28T17:28:33+00:00", + "author_timezone": 0, + "committer_date": "2006-04-28T17:28:33+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "42f652d713fe507b5648dfe57987e3744acfe685" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 3, + "insertions": 3, + "lines": 6, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -8,9 +8,8 @@\n \n #include \"Python.h\"\n #include \"numpy/arrayobject.h\"\n-#include \"numpy/arrayscalars.h\"\n #include \"numpy/ufuncobject.h\"\n-\n+#include \"numpy/arrayscalars.h\"\n \n \n /** numarray adapted routines.... **/\n@@ -161,10 +160,11 @@ static void\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n+ #SIZENAME=BYTE*2,SHORT*2,INT*2,LONG*2#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n **/\n-#if SIZEOF_@SIZE@ > SIZEOF_@NAME@\n+#if SIZEOF_@SIZE@ > SIZEOF_@SIZENAME@\n static void\n @name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n", + "added_lines": 3, + "deleted_lines": 3, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/ufuncobject.h\"\n#include \"numpy/arrayscalars.h\"\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZENAME=BYTE*2,SHORT*2,INT*2,LONG*2#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n**/\n#if SIZEOF_@SIZE@ > SIZEOF_@SIZENAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n\t generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n**/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n\tgenerate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #neg=(1,0)*5#\n**/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n if (b == 0) {\n\tgenerate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if (b == -1 && a < 0 && a == -a) {\n\tgenerate_overflow_error();\n\t*out = a / b;\n }\n#endif\n else {\n\t*out = a / b;\n }\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\nstatic void\n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {\n if (a == 0 || b == 0) {\n\tif (b == 0) generate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if ((a > 0) == (b > 0)) {\n\t*out = a % b;\n }\n else { /* handled like Python does */\n\t*out = a % b;\n\tif (*out) *out += b;\n }\n#else\n *out = a % b;\n#endif\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n**/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n *(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/* b will always be positive in this call */\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n \n}\n/**end repeat**/\n\n\n\n/* QUESTION: Should we check for overflow / underflow in (l,r)shift? */\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n**/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_floor)(@name@);\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) \\\n *(outp) = _basic_@name@_floor((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\\\n (outp)->real = (a).real + (b).real;\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\\\n (outp)->real = (a).real - (b).real;\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do {\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) /\t\\\n ((a).real*(b).real + (b).imag*(b).imag);\t\t\t\\\n (outp)->imag = 0;\t\t\t\t\t\t\\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - _basic_@name@_floor(a/b)*b;\n} \n/**end repeat**/ \n\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_ctype_divmod(a, b, out, out2) {\t\\\n @name@_ctype_floor_divide(a, b, out);\t\\\n @name@_ctype_remainder(a, b, out2);\t\t\\\n }\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_pow)(@name@ a, @name@ b);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = _basic_@name@_pow(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #uns=(1,0)*5,0*3#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n#if @uns@\n generate_overflow_error();\n#endif\n *out = -a;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n/* Get the nc_powf, nc_pow, and nc_powl functions from \n the data area of the power ufunc in umathmodule. \n*/\n\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n out->real = a.real;\n out->imag = a.imag;\n}\nstatic void (*_basic_@name@_pow)(@name@ *, @name@ *, @name@ *);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out)\n{\n _basic_@name@_pow(&a, &b, out);\n}\n/**end repeat**/\n\n\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, floor_divide*6, true_divide*6, divmod*3, remainder*3#\n #fperr=1*70,0*50,1*52#\n #twoout=0*50,1*10,0*106,1*3,0*3#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*12, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*12, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n**/\n\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @twoout@\n @otyp@ out2;\n PyObject *obj;\n#endif\n\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @twoout@\n @name@_ctype_@oper@(arg1, arg2, &out, &out2);\n#else\n @name@_ctype_@oper@(arg1, arg2, &out);\n#endif\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n\n#if @twoout@\n ret = PyTuple_New(2);\n if (ret==NULL) return NULL;\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out;\n PyTuple_SET_ITEM(ret, 0, obj);\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out2;\n PyTuple_SET_ITEM(ret, 1, obj);\n#else\n ret = PyArrayScalar_New(@OName@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @OName@) = out;\n#endif\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float, double, longdouble, cfloat, cdouble, clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #otyp=float*4, double*6, float, double, longdouble, cfloat, cdouble, clongdouble#\n #OName=Float*4, Double*6, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #isint=(1,0)*5,0*6#\n #cmplx=0*13,1*3#\n**/\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n @otyp@ out1;\n int retstatus;\n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n }\n\n PyUFunc_clearfperr();\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @cmplx@\n if (arg2.real == 0 && arg1.real == 0) {\n\tout1.real = out.real = 1.0;\n\tout1.imag = out.imag = 0.0;\n }\n#else\n if (arg2 == 0) {\n\tout1 = out = 1;\n } \n#endif\n#if @isint@\n else if (arg2 < 0) {\n\t@name@_ctype_power(arg1, -arg2, &out);\n\tout1 = 1.0 / out;\n }\n#endif\n else {\n\t@name@_ctype_power(arg1, arg2, &out);\n }\n\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n\n#if @isint@\n if (arg2 < 0) {\n\tret = PyArrayScalar_New(@OName@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @OName@) = out1;\n }\n else {\n\tret = PyArrayScalar_New(@Name@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @Name@) = out;\n }\n#else\n ret = PyArrayScalar_New(@Name@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @Name@) = out;\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n#name=(cfloat,cdouble,clongdouble)*2#\n#oper=divmod*3,remainder*3#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3, byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*3, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n #oper=negative*16, positive*16, absolute*16, invert*10#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n#name=float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_invert NULL\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic int\nget_functions(void)\n{\n PyObject *mm, *obj;\n void **funcdata;\n char *signatures;\n int i, j;\n int ret = -1;\n\t\n /* Get the nc_pow functions */\n /* Get the pow functions */\n mm = PyImport_ImportModule(\"numpy.core.umath\");\n if (mm == NULL) return -1;\n \n obj = PyObject_GetAttrString(mm, \"power\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_pow = funcdata[j];\n _basic_double_pow = funcdata[j+1];\n _basic_longdouble_pow = funcdata[j+2];\n _basic_cfloat_pow = funcdata[j+3];\n _basic_cdouble_pow = funcdata[j+4];\n _basic_clongdouble_pow = funcdata[j+5];\n\n Py_DECREF(obj);\n\n /* Get the floor functions */\n\n obj = PyObject_GetAttrString(mm, \"floor\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_floor = funcdata[j];\n _basic_double_floor = funcdata[j+1];\n _basic_longdouble_floor = funcdata[j+2];\n\n Py_DECREF(obj);\n ret = 0;\n fail:\n Py_DECREF(mm);\n return ret;\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n if (get_functions() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/arrayscalars.h\"\n#include \"numpy/ufuncobject.h\"\n\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n**/\n#if SIZEOF_@SIZE@ > SIZEOF_@NAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n\t generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n**/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n\tgenerate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #neg=(1,0)*5#\n**/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n if (b == 0) {\n\tgenerate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if (b == -1 && a < 0 && a == -a) {\n\tgenerate_overflow_error();\n\t*out = a / b;\n }\n#endif\n else {\n\t*out = a / b;\n }\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\nstatic void\n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {\n if (a == 0 || b == 0) {\n\tif (b == 0) generate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if ((a > 0) == (b > 0)) {\n\t*out = a % b;\n }\n else { /* handled like Python does */\n\t*out = a % b;\n\tif (*out) *out += b;\n }\n#else\n *out = a % b;\n#endif\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n**/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n *(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/* b will always be positive in this call */\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n \n}\n/**end repeat**/\n\n\n\n/* QUESTION: Should we check for overflow / underflow in (l,r)shift? */\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n**/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_floor)(@name@);\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) \\\n *(outp) = _basic_@name@_floor((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\\\n (outp)->real = (a).real + (b).real;\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\\\n (outp)->real = (a).real - (b).real;\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do {\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) /\t\\\n ((a).real*(b).real + (b).imag*(b).imag);\t\t\t\\\n (outp)->imag = 0;\t\t\t\t\t\t\\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - _basic_@name@_floor(a/b)*b;\n} \n/**end repeat**/ \n\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_ctype_divmod(a, b, out, out2) {\t\\\n @name@_ctype_floor_divide(a, b, out);\t\\\n @name@_ctype_remainder(a, b, out2);\t\t\\\n }\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_pow)(@name@ a, @name@ b);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = _basic_@name@_pow(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #uns=(1,0)*5,0*3#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n#if @uns@\n generate_overflow_error();\n#endif\n *out = -a;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n/* Get the nc_powf, nc_pow, and nc_powl functions from \n the data area of the power ufunc in umathmodule. \n*/\n\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n out->real = a.real;\n out->imag = a.imag;\n}\nstatic void (*_basic_@name@_pow)(@name@ *, @name@ *, @name@ *);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out)\n{\n _basic_@name@_pow(&a, &b, out);\n}\n/**end repeat**/\n\n\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, floor_divide*6, true_divide*6, divmod*3, remainder*3#\n #fperr=1*70,0*50,1*52#\n #twoout=0*50,1*10,0*106,1*3,0*3#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*12, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*12, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n**/\n\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @twoout@\n @otyp@ out2;\n PyObject *obj;\n#endif\n\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @twoout@\n @name@_ctype_@oper@(arg1, arg2, &out, &out2);\n#else\n @name@_ctype_@oper@(arg1, arg2, &out);\n#endif\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n\n#if @twoout@\n ret = PyTuple_New(2);\n if (ret==NULL) return NULL;\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out;\n PyTuple_SET_ITEM(ret, 0, obj);\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out2;\n PyTuple_SET_ITEM(ret, 1, obj);\n#else\n ret = PyArrayScalar_New(@OName@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @OName@) = out;\n#endif\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float, double, longdouble, cfloat, cdouble, clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #otyp=float*4, double*6, float, double, longdouble, cfloat, cdouble, clongdouble#\n #OName=Float*4, Double*6, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #isint=(1,0)*5,0*6#\n #cmplx=0*13,1*3#\n**/\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n @otyp@ out1;\n int retstatus;\n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n }\n\n PyUFunc_clearfperr();\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @cmplx@\n if (arg2.real == 0 && arg1.real == 0) {\n\tout1.real = out.real = 1.0;\n\tout1.imag = out.imag = 0.0;\n }\n#else\n if (arg2 == 0) {\n\tout1 = out = 1;\n } \n#endif\n#if @isint@\n else if (arg2 < 0) {\n\t@name@_ctype_power(arg1, -arg2, &out);\n\tout1 = 1.0 / out;\n }\n#endif\n else {\n\t@name@_ctype_power(arg1, arg2, &out);\n }\n\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n\n#if @isint@\n if (arg2 < 0) {\n\tret = PyArrayScalar_New(@OName@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @OName@) = out1;\n }\n else {\n\tret = PyArrayScalar_New(@Name@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @Name@) = out;\n }\n#else\n ret = PyArrayScalar_New(@Name@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @Name@) = out;\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n#name=(cfloat,cdouble,clongdouble)*2#\n#oper=divmod*3,remainder*3#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3, byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*3, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n #oper=negative*16, positive*16, absolute*16, invert*10#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n#name=float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_invert NULL\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic int\nget_functions(void)\n{\n PyObject *mm, *obj;\n void **funcdata;\n char *signatures;\n int i, j;\n int ret = -1;\n\t\n /* Get the nc_pow functions */\n /* Get the pow functions */\n mm = PyImport_ImportModule(\"numpy.core.umath\");\n if (mm == NULL) return -1;\n \n obj = PyObject_GetAttrString(mm, \"power\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_pow = funcdata[j];\n _basic_double_pow = funcdata[j+1];\n _basic_longdouble_pow = funcdata[j+2];\n _basic_cfloat_pow = funcdata[j+3];\n _basic_cdouble_pow = funcdata[j+4];\n _basic_clongdouble_pow = funcdata[j+5];\n\n Py_DECREF(obj);\n\n /* Get the floor functions */\n\n obj = PyObject_GetAttrString(mm, \"floor\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_floor = funcdata[j];\n _basic_double_floor = funcdata[j+1];\n _basic_longdouble_floor = funcdata[j+2];\n\n Py_DECREF(obj);\n ret = 0;\n fail:\n Py_DECREF(mm);\n return ret;\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n if (get_functions() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "#include \"numpy/arrayscalars.h\"", + " #SIZENAME=BYTE*2,SHORT*2,INT*2,LONG*2#", + "#if SIZEOF_@SIZE@ > SIZEOF_@SIZENAME@" + ], + "deleted": [ + "#include \"numpy/arrayscalars.h\"", + "", + "#if SIZEOF_@SIZE@ > SIZEOF_@NAME@" + ] + } + } + ] + }, + { + "hash": "40cc08de6d5fa4f7cc518c7caa97e196259e03a4", + "msg": "Fix type of _PyArrayScalar_BoolValues", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-04-28T18:04:33+00:00", + "author_timezone": 0, + "committer_date": "2006-04-28T18:04:33+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "da478e7332dc8dd0fc9a3fdbc1101a7eed831990" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 7, + "insertions": 11, + "lines": 18, + "files": 3, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/code_generators/generate_array_api.py", + "new_path": "numpy/core/code_generators/generate_array_api.py", + "filename": "generate_array_api.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -56,7 +56,7 @@\n #define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[6])\n #define PyArray_NUMUSERTYPES (*(int *)PyArray_API[7])\n #define PyBoolArrType_Type (*(PyTypeObject *)PyArray_API[8])\n-#define _PyArrayScalar_BoolValues (*(PyObject **)PyArray_API[9])\n+#define _PyArrayScalar_BoolValues ((PyBoolScalarObject *)PyArray_API[9])\n \n %s\n \n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "import os\nimport genapi\n\ntypes = ['Generic','Number','Integer','SignedInteger','UnsignedInteger',\n 'Inexact',\n 'Floating', 'ComplexFloating', 'Flexible', 'Character',\n 'Byte','Short','Int', 'Long', 'LongLong', 'UByte', 'UShort',\n 'UInt', 'ULong', 'ULongLong', 'Float', 'Double', 'LongDouble',\n 'CFloat', 'CDouble', 'CLongDouble', 'Object', 'String', 'Unicode',\n 'Void']\n\nh_template = r\"\"\"\n#ifdef _MULTIARRAYMODULE\n\ntypedef struct {\n\tPyObject_HEAD\n\tBool obval;\n} PyBoolScalarObject;\n\nstatic unsigned int PyArray_GetNDArrayCVersion (void);\nstatic PyTypeObject PyBigArray_Type;\nstatic PyTypeObject PyArray_Type;\nstatic PyTypeObject PyArrayDescr_Type;\nstatic PyTypeObject PyArrayFlags_Type;\nstatic PyTypeObject PyArrayIter_Type;\nstatic PyTypeObject PyArrayMapIter_Type;\nstatic PyTypeObject PyArrayMultiIter_Type;\nstatic int PyArray_NUMUSERTYPES=0;\nstatic PyTypeObject PyBoolArrType_Type;\nstatic PyBoolScalarObject _PyArrayScalar_BoolValues[2];\n\n%s\n\n#else\n\n#if defined(PY_ARRAY_UNIQUE_SYMBOL)\n#define PyArray_API PY_ARRAY_UNIQUE_SYMBOL\n#endif\n\n#if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)\nextern void **PyArray_API;\n#else\n#if defined(PY_ARRAY_UNIQUE_SYMBOL)\nvoid **PyArray_API;\n#else\nstatic void **PyArray_API=NULL;\n#endif\n#endif\n\n#define PyArray_GetNDArrayCVersion (*(unsigned int (*)(void)) PyArray_API[0])\n#define PyBigArray_Type (*(PyTypeObject *)PyArray_API[1])\n#define PyArray_Type (*(PyTypeObject *)PyArray_API[2])\n#define PyArrayDescr_Type (*(PyTypeObject *)PyArray_API[3])\n#define PyArrayFlags_Type (*(PyTypeObject *)PyArray_API[4])\n#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[5])\n#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[6])\n#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[7])\n#define PyBoolArrType_Type (*(PyTypeObject *)PyArray_API[8])\n#define _PyArrayScalar_BoolValues ((PyBoolScalarObject *)PyArray_API[9])\n\n%s\n\n#if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)\nstatic int\nimport_array(void)\n{\n PyObject *numpy = PyImport_ImportModule(\"numpy.core.multiarray\");\n PyObject *c_api = NULL;\n if (numpy == NULL) return -1;\n c_api = PyObject_GetAttrString(numpy, \"_ARRAY_API\");\n if (c_api == NULL) {Py_DECREF(numpy); return -1;}\n if (PyCObject_Check(c_api)) {\n PyArray_API = (void **)PyCObject_AsVoidPtr(c_api);\n }\n Py_DECREF(c_api);\n Py_DECREF(numpy);\n if (PyArray_API == NULL) return -1;\n /* Perform runtime check of C API version */\n if (NDARRAY_VERSION != PyArray_GetNDArrayCVersion()) {\n PyErr_Format(PyExc_RuntimeError, \"module compiled against \"\\\n \"version %%x of C-API but this version of numpy is %%x\", \\\n (int) NDARRAY_VERSION, (int) PyArray_GetNDArrayCVersion());\n return -1;\n }\n return 0;\n}\n#endif\n\n#endif\n\"\"\"\n\n\nc_template = r\"\"\"\n/* These pointers will be stored in the C-object for use in other\n extension modules\n*/\n\nvoid *PyArray_API[] = {\n (void *) PyArray_GetNDArrayCVersion,\n (void *) &PyBigArray_Type,\n (void *) &PyArray_Type,\n (void *) &PyArrayDescr_Type,\n (void *) &PyArrayFlags_Type,\n (void *) &PyArrayIter_Type,\n (void *) &PyArrayMultiIter_Type,\n (int *) &PyArray_NUMUSERTYPES,\n (void *) &PyBoolArrType_Type,\n (void *) &_PyArrayScalar_BoolValues,\n%s\n};\n\"\"\"\n\ndef generate_api(output_dir):\n objectapi_list = genapi.get_api_functions('OBJECT_API',\n 'array_api_order.txt')\n multiapi_list = genapi.get_api_functions('MULTIARRAY_API',\n 'multiarray_api_order.txt')\n # API fixes for __arrayobject_api.h\n\n fixed = 10\n numtypes = len(types) + fixed\n numobject = len(objectapi_list) + numtypes\n nummulti = len(multiapi_list)\n numtotal = numobject + nummulti\n\n module_list = []\n extension_list = []\n init_list = []\n\n # setup types\n for k, atype in enumerate(types):\n num = fixed + k\n astr = \" (void *) &Py%sArrType_Type,\" % types[k]\n init_list.append(astr)\n astr = \"static PyTypeObject Py%sArrType_Type;\" % types[k]\n module_list.append(astr)\n astr = \"#define Py%sArrType_Type (*(PyTypeObject *)PyArray_API[%d])\" % \\\n (types[k], num)\n extension_list.append(astr)\n\n #setup object API\n genapi.add_api_list(numtypes, 'PyArray_API', objectapi_list,\n module_list, extension_list, init_list)\n\n # setup multiarray module API\n genapi.add_api_list(numobject, 'PyArray_API', multiapi_list,\n module_list, extension_list, init_list)\n\n\n # Write to header\n fid = open(os.path.join(output_dir, '__multiarray_api.h'),'w')\n s = h_template % ('\\n'.join(module_list), '\\n'.join(extension_list))\n fid.write(s)\n fid.close()\n\n # Write to c-code\n fid = open(os.path.join(output_dir,'__multiarray_api.c'),'w')\n s = c_template % '\\n'.join(init_list)\n fid.write(s)\n fid.close()\n", + "source_code_before": "import os\nimport genapi\n\ntypes = ['Generic','Number','Integer','SignedInteger','UnsignedInteger',\n 'Inexact',\n 'Floating', 'ComplexFloating', 'Flexible', 'Character',\n 'Byte','Short','Int', 'Long', 'LongLong', 'UByte', 'UShort',\n 'UInt', 'ULong', 'ULongLong', 'Float', 'Double', 'LongDouble',\n 'CFloat', 'CDouble', 'CLongDouble', 'Object', 'String', 'Unicode',\n 'Void']\n\nh_template = r\"\"\"\n#ifdef _MULTIARRAYMODULE\n\ntypedef struct {\n\tPyObject_HEAD\n\tBool obval;\n} PyBoolScalarObject;\n\nstatic unsigned int PyArray_GetNDArrayCVersion (void);\nstatic PyTypeObject PyBigArray_Type;\nstatic PyTypeObject PyArray_Type;\nstatic PyTypeObject PyArrayDescr_Type;\nstatic PyTypeObject PyArrayFlags_Type;\nstatic PyTypeObject PyArrayIter_Type;\nstatic PyTypeObject PyArrayMapIter_Type;\nstatic PyTypeObject PyArrayMultiIter_Type;\nstatic int PyArray_NUMUSERTYPES=0;\nstatic PyTypeObject PyBoolArrType_Type;\nstatic PyBoolScalarObject _PyArrayScalar_BoolValues[2];\n\n%s\n\n#else\n\n#if defined(PY_ARRAY_UNIQUE_SYMBOL)\n#define PyArray_API PY_ARRAY_UNIQUE_SYMBOL\n#endif\n\n#if defined(NO_IMPORT) || defined(NO_IMPORT_ARRAY)\nextern void **PyArray_API;\n#else\n#if defined(PY_ARRAY_UNIQUE_SYMBOL)\nvoid **PyArray_API;\n#else\nstatic void **PyArray_API=NULL;\n#endif\n#endif\n\n#define PyArray_GetNDArrayCVersion (*(unsigned int (*)(void)) PyArray_API[0])\n#define PyBigArray_Type (*(PyTypeObject *)PyArray_API[1])\n#define PyArray_Type (*(PyTypeObject *)PyArray_API[2])\n#define PyArrayDescr_Type (*(PyTypeObject *)PyArray_API[3])\n#define PyArrayFlags_Type (*(PyTypeObject *)PyArray_API[4])\n#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[5])\n#define PyArrayMultiIter_Type (*(PyTypeObject *)PyArray_API[6])\n#define PyArray_NUMUSERTYPES (*(int *)PyArray_API[7])\n#define PyBoolArrType_Type (*(PyTypeObject *)PyArray_API[8])\n#define _PyArrayScalar_BoolValues (*(PyObject **)PyArray_API[9])\n\n%s\n\n#if !defined(NO_IMPORT_ARRAY) && !defined(NO_IMPORT)\nstatic int\nimport_array(void)\n{\n PyObject *numpy = PyImport_ImportModule(\"numpy.core.multiarray\");\n PyObject *c_api = NULL;\n if (numpy == NULL) return -1;\n c_api = PyObject_GetAttrString(numpy, \"_ARRAY_API\");\n if (c_api == NULL) {Py_DECREF(numpy); return -1;}\n if (PyCObject_Check(c_api)) {\n PyArray_API = (void **)PyCObject_AsVoidPtr(c_api);\n }\n Py_DECREF(c_api);\n Py_DECREF(numpy);\n if (PyArray_API == NULL) return -1;\n /* Perform runtime check of C API version */\n if (NDARRAY_VERSION != PyArray_GetNDArrayCVersion()) {\n PyErr_Format(PyExc_RuntimeError, \"module compiled against \"\\\n \"version %%x of C-API but this version of numpy is %%x\", \\\n (int) NDARRAY_VERSION, (int) PyArray_GetNDArrayCVersion());\n return -1;\n }\n return 0;\n}\n#endif\n\n#endif\n\"\"\"\n\n\nc_template = r\"\"\"\n/* These pointers will be stored in the C-object for use in other\n extension modules\n*/\n\nvoid *PyArray_API[] = {\n (void *) PyArray_GetNDArrayCVersion,\n (void *) &PyBigArray_Type,\n (void *) &PyArray_Type,\n (void *) &PyArrayDescr_Type,\n (void *) &PyArrayFlags_Type,\n (void *) &PyArrayIter_Type,\n (void *) &PyArrayMultiIter_Type,\n (int *) &PyArray_NUMUSERTYPES,\n (void *) &PyBoolArrType_Type,\n (void *) &_PyArrayScalar_BoolValues,\n%s\n};\n\"\"\"\n\ndef generate_api(output_dir):\n objectapi_list = genapi.get_api_functions('OBJECT_API',\n 'array_api_order.txt')\n multiapi_list = genapi.get_api_functions('MULTIARRAY_API',\n 'multiarray_api_order.txt')\n # API fixes for __arrayobject_api.h\n\n fixed = 10\n numtypes = len(types) + fixed\n numobject = len(objectapi_list) + numtypes\n nummulti = len(multiapi_list)\n numtotal = numobject + nummulti\n\n module_list = []\n extension_list = []\n init_list = []\n\n # setup types\n for k, atype in enumerate(types):\n num = fixed + k\n astr = \" (void *) &Py%sArrType_Type,\" % types[k]\n init_list.append(astr)\n astr = \"static PyTypeObject Py%sArrType_Type;\" % types[k]\n module_list.append(astr)\n astr = \"#define Py%sArrType_Type (*(PyTypeObject *)PyArray_API[%d])\" % \\\n (types[k], num)\n extension_list.append(astr)\n\n #setup object API\n genapi.add_api_list(numtypes, 'PyArray_API', objectapi_list,\n module_list, extension_list, init_list)\n\n # setup multiarray module API\n genapi.add_api_list(numobject, 'PyArray_API', multiapi_list,\n module_list, extension_list, init_list)\n\n\n # Write to header\n fid = open(os.path.join(output_dir, '__multiarray_api.h'),'w')\n s = h_template % ('\\n'.join(module_list), '\\n'.join(extension_list))\n fid.write(s)\n fid.close()\n\n # Write to c-code\n fid = open(os.path.join(output_dir,'__multiarray_api.c'),'w')\n s = c_template % '\\n'.join(init_list)\n fid.write(s)\n fid.close()\n", + "methods": [ + { + "name": "generate_api", + "long_name": "generate_api( output_dir )", + "filename": "generate_array_api.py", + "nloc": 34, + "complexity": 2, + "token_count": 246, + "parameters": [ + "output_dir" + ], + "start_line": 113, + "end_line": 160, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "generate_api", + "long_name": "generate_api( output_dir )", + "filename": "generate_array_api.py", + "nloc": 34, + "complexity": 2, + "token_count": 246, + "parameters": [ + "output_dir" + ], + "start_line": 113, + "end_line": 160, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 141, + "complexity": 2, + "token_count": 322, + "diff_parsed": { + "added": [ + "#define _PyArrayScalar_BoolValues ((PyBoolScalarObject *)PyArray_API[9])" + ], + "deleted": [ + "#define _PyArrayScalar_BoolValues (*(PyObject **)PyArray_API[9])" + ] + } + }, + { + "old_path": "numpy/core/include/numpy/arrayscalars.h", + "new_path": "numpy/core/include/numpy/arrayscalars.h", + "filename": "arrayscalars.h", + "extension": "h", + "change_type": "MODIFY", + "diff": "@@ -125,11 +125,13 @@ typedef struct {\n } PyVoidScalarObject;\n \n \n-#define PyArrayScalar_False ((PyObject *)&_PyArrayScalar_BoolValues[0])\n-#define PyArrayScalar_True ((PyObject *)&_PyArrayScalar_BoolValues[1])\n+#define PyArrayScalar_False ((PyObject *)(&(_PyArrayScalar_BoolValues[0])))\n+#define PyArrayScalar_True ((PyObject *)(&(_PyArrayScalar_BoolValues[1])))\n+#define PyArrayScalar_FromLong(i) \\\n+\t((PyObject *)(&(_PyArrayScalar_BoolValues[((i)!=0)])))\n #define PyArrayScalar_RETURN_BOOL_FROM_LONG(i)\t\t\t\\\n-\treturn Py_INCREF(&_PyArrayScalar_BoolValues[((i)!=0)]),\t\\\n-\t\t(PyObject *)&_PyArrayScalar_BoolValues[((i)!=0)]\n+\treturn Py_INCREF(PyArrayScalar_FromLong(i)), \\\n+\t\tPyArrayScalar_FromLong(i)\n #define PyArrayScalar_RETURN_FALSE\t\t\\\n \treturn Py_INCREF(PyArrayScalar_False),\t\\\n \t\tPyArrayScalar_False\n", + "added_lines": 6, + "deleted_lines": 4, + "source_code": "#ifndef _MULTIARRAYMODULE\ntypedef struct {\n\tPyObject_HEAD\n\tBool obval;\n} PyBoolScalarObject;\n#endif\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tsigned char obval;\n} PyByteScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tshort obval;\n} PyShortScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tint obval;\n} PyIntScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tlong obval;\n} PyLongScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tlonglong obval;\n} PyLongLongScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tunsigned char obval;\n} PyUByteScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tunsigned short obval;\n} PyUShortScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tunsigned int obval;\n} PyUIntScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tunsigned long obval;\n} PyULongScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tulonglong obval;\n} PyULongLongScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tfloat obval;\n} PyFloatScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tdouble obval;\n} PyDoubleScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tlongdouble obval;\n} PyLongDoubleScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tcfloat obval;\n} PyCFloatScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tcdouble obval;\n} PyCDoubleScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tclongdouble obval;\n} PyCLongDoubleScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tPyObject * obval;\n} PyObjectScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tchar obval;\n} PyScalarObject;\n\n#define PyStringScalarObject PyStringObject\n#define PyUnicodeScalarObject PyUnicodeObject\n\ntypedef struct {\n\tPyObject_VAR_HEAD\n\tchar *obval;\n\tPyArray_Descr *descr;\n\tint flags;\n\tPyObject *base;\n} PyVoidScalarObject;\n\n\n#define PyArrayScalar_False ((PyObject *)(&(_PyArrayScalar_BoolValues[0])))\n#define PyArrayScalar_True ((PyObject *)(&(_PyArrayScalar_BoolValues[1])))\n#define PyArrayScalar_FromLong(i) \\\n\t((PyObject *)(&(_PyArrayScalar_BoolValues[((i)!=0)])))\n#define PyArrayScalar_RETURN_BOOL_FROM_LONG(i)\t\t\t\\\n\treturn Py_INCREF(PyArrayScalar_FromLong(i)), \\\n\t\tPyArrayScalar_FromLong(i)\n#define PyArrayScalar_RETURN_FALSE\t\t\\\n\treturn Py_INCREF(PyArrayScalar_False),\t\\\n\t\tPyArrayScalar_False\n#define PyArrayScalar_RETURN_TRUE\t\t\\\n\treturn Py_INCREF(PyArrayScalar_True),\t\\\n\t\tPyArrayScalar_True\n\n#define PyArrayScalar_New(cls) \\\n\tPy##cls##ArrType_Type.tp_alloc(&Py##cls##ArrType_Type, 0)\n#define PyArrayScalar_VAL(obj, cls)\t\t\\\n\t((Py##cls##ScalarObject *)obj)->obval\n", + "source_code_before": "#ifndef _MULTIARRAYMODULE\ntypedef struct {\n\tPyObject_HEAD\n\tBool obval;\n} PyBoolScalarObject;\n#endif\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tsigned char obval;\n} PyByteScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tshort obval;\n} PyShortScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tint obval;\n} PyIntScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tlong obval;\n} PyLongScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tlonglong obval;\n} PyLongLongScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tunsigned char obval;\n} PyUByteScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tunsigned short obval;\n} PyUShortScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tunsigned int obval;\n} PyUIntScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tunsigned long obval;\n} PyULongScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tulonglong obval;\n} PyULongLongScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tfloat obval;\n} PyFloatScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tdouble obval;\n} PyDoubleScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tlongdouble obval;\n} PyLongDoubleScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tcfloat obval;\n} PyCFloatScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tcdouble obval;\n} PyCDoubleScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tclongdouble obval;\n} PyCLongDoubleScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tPyObject * obval;\n} PyObjectScalarObject;\n\n\ntypedef struct {\n\tPyObject_HEAD\n\tchar obval;\n} PyScalarObject;\n\n#define PyStringScalarObject PyStringObject\n#define PyUnicodeScalarObject PyUnicodeObject\n\ntypedef struct {\n\tPyObject_VAR_HEAD\n\tchar *obval;\n\tPyArray_Descr *descr;\n\tint flags;\n\tPyObject *base;\n} PyVoidScalarObject;\n\n\n#define PyArrayScalar_False ((PyObject *)&_PyArrayScalar_BoolValues[0])\n#define PyArrayScalar_True ((PyObject *)&_PyArrayScalar_BoolValues[1])\n#define PyArrayScalar_RETURN_BOOL_FROM_LONG(i)\t\t\t\\\n\treturn Py_INCREF(&_PyArrayScalar_BoolValues[((i)!=0)]),\t\\\n\t\t(PyObject *)&_PyArrayScalar_BoolValues[((i)!=0)]\n#define PyArrayScalar_RETURN_FALSE\t\t\\\n\treturn Py_INCREF(PyArrayScalar_False),\t\\\n\t\tPyArrayScalar_False\n#define PyArrayScalar_RETURN_TRUE\t\t\\\n\treturn Py_INCREF(PyArrayScalar_True),\t\\\n\t\tPyArrayScalar_True\n\n#define PyArrayScalar_New(cls) \\\n\tPy##cls##ArrType_Type.tp_alloc(&Py##cls##ArrType_Type, 0)\n#define PyArrayScalar_VAL(obj, cls)\t\t\\\n\t((Py##cls##ScalarObject *)obj)->obval\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": 83, + "complexity": 0, + "token_count": 218, + "diff_parsed": { + "added": [ + "#define PyArrayScalar_False ((PyObject *)(&(_PyArrayScalar_BoolValues[0])))", + "#define PyArrayScalar_True ((PyObject *)(&(_PyArrayScalar_BoolValues[1])))", + "#define PyArrayScalar_FromLong(i) \\", + "\t((PyObject *)(&(_PyArrayScalar_BoolValues[((i)!=0)])))", + "\treturn Py_INCREF(PyArrayScalar_FromLong(i)), \\", + "\t\tPyArrayScalar_FromLong(i)" + ], + "deleted": [ + "#define PyArrayScalar_False ((PyObject *)&_PyArrayScalar_BoolValues[0])", + "#define PyArrayScalar_True ((PyObject *)&_PyArrayScalar_BoolValues[1])", + "\treturn Py_INCREF(&_PyArrayScalar_BoolValues[((i)!=0)]),\t\\", + "\t\t(PyObject *)&_PyArrayScalar_BoolValues[((i)!=0)]" + ] + } + }, + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -824,10 +824,12 @@ static PyObject*\n \tbreak;\n }\n \n- if (out) \n+ if (out) {\n \tPyArrayScalar_RETURN_TRUE;\n- else\n+ }\n+ else {\n \tPyArrayScalar_RETURN_FALSE;\n+ }\n }\n /**end repeat**/\n \n", + "added_lines": 4, + "deleted_lines": 2, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/ufuncobject.h\"\n#include \"numpy/arrayscalars.h\"\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZENAME=BYTE*2,SHORT*2,INT*2,LONG*2#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n**/\n#if SIZEOF_@SIZE@ > SIZEOF_@SIZENAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n\t generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n**/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n\tgenerate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #neg=(1,0)*5#\n**/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n if (b == 0) {\n\tgenerate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if (b == -1 && a < 0 && a == -a) {\n\tgenerate_overflow_error();\n\t*out = a / b;\n }\n#endif\n else {\n\t*out = a / b;\n }\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\nstatic void\n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {\n if (a == 0 || b == 0) {\n\tif (b == 0) generate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if ((a > 0) == (b > 0)) {\n\t*out = a % b;\n }\n else { /* handled like Python does */\n\t*out = a % b;\n\tif (*out) *out += b;\n }\n#else\n *out = a % b;\n#endif\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n**/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n *(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/* b will always be positive in this call */\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n \n}\n/**end repeat**/\n\n\n\n/* QUESTION: Should we check for overflow / underflow in (l,r)shift? */\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n**/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_floor)(@name@);\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) \\\n *(outp) = _basic_@name@_floor((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\\\n (outp)->real = (a).real + (b).real;\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\\\n (outp)->real = (a).real - (b).real;\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do {\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) /\t\\\n ((a).real*(b).real + (b).imag*(b).imag);\t\t\t\\\n (outp)->imag = 0;\t\t\t\t\t\t\\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - _basic_@name@_floor(a/b)*b;\n} \n/**end repeat**/ \n\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_ctype_divmod(a, b, out, out2) {\t\\\n @name@_ctype_floor_divide(a, b, out);\t\\\n @name@_ctype_remainder(a, b, out2);\t\t\\\n }\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_pow)(@name@ a, @name@ b);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = _basic_@name@_pow(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #uns=(1,0)*5,0*3#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n#if @uns@\n generate_overflow_error();\n#endif\n *out = -a;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n/* Get the nc_powf, nc_pow, and nc_powl functions from \n the data area of the power ufunc in umathmodule. \n*/\n\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n out->real = a.real;\n out->imag = a.imag;\n}\nstatic void (*_basic_@name@_pow)(@name@ *, @name@ *, @name@ *);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out)\n{\n _basic_@name@_pow(&a, &b, out);\n}\n/**end repeat**/\n\n\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, floor_divide*6, true_divide*6, divmod*3, remainder*3#\n #fperr=1*70,0*50,1*52#\n #twoout=0*50,1*10,0*106,1*3,0*3#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*12, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*12, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n**/\n\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @twoout@\n @otyp@ out2;\n PyObject *obj;\n#endif\n\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @twoout@\n @name@_ctype_@oper@(arg1, arg2, &out, &out2);\n#else\n @name@_ctype_@oper@(arg1, arg2, &out);\n#endif\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n\n#if @twoout@\n ret = PyTuple_New(2);\n if (ret==NULL) return NULL;\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out;\n PyTuple_SET_ITEM(ret, 0, obj);\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out2;\n PyTuple_SET_ITEM(ret, 1, obj);\n#else\n ret = PyArrayScalar_New(@OName@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @OName@) = out;\n#endif\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float, double, longdouble, cfloat, cdouble, clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #otyp=float*4, double*6, float, double, longdouble, cfloat, cdouble, clongdouble#\n #OName=Float*4, Double*6, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #isint=(1,0)*5,0*6#\n #cmplx=0*13,1*3#\n**/\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n @otyp@ out1;\n int retstatus;\n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n }\n\n PyUFunc_clearfperr();\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @cmplx@\n if (arg2.real == 0 && arg1.real == 0) {\n\tout1.real = out.real = 1.0;\n\tout1.imag = out.imag = 0.0;\n }\n#else\n if (arg2 == 0) {\n\tout1 = out = 1;\n } \n#endif\n#if @isint@\n else if (arg2 < 0) {\n\t@name@_ctype_power(arg1, -arg2, &out);\n\tout1 = 1.0 / out;\n }\n#endif\n else {\n\t@name@_ctype_power(arg1, arg2, &out);\n }\n\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n\n#if @isint@\n if (arg2 < 0) {\n\tret = PyArrayScalar_New(@OName@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @OName@) = out1;\n }\n else {\n\tret = PyArrayScalar_New(@Name@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @Name@) = out;\n }\n#else\n ret = PyArrayScalar_New(@Name@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @Name@) = out;\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n#name=(cfloat,cdouble,clongdouble)*2#\n#oper=divmod*3,remainder*3#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3, byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*3, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n #oper=negative*16, positive*16, absolute*16, invert*10#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n#name=float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_invert NULL\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) {\n\tPyArrayScalar_RETURN_TRUE;\n }\n else {\n\tPyArrayScalar_RETURN_FALSE;\n }\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic int\nget_functions(void)\n{\n PyObject *mm, *obj;\n void **funcdata;\n char *signatures;\n int i, j;\n int ret = -1;\n\t\n /* Get the nc_pow functions */\n /* Get the pow functions */\n mm = PyImport_ImportModule(\"numpy.core.umath\");\n if (mm == NULL) return -1;\n \n obj = PyObject_GetAttrString(mm, \"power\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_pow = funcdata[j];\n _basic_double_pow = funcdata[j+1];\n _basic_longdouble_pow = funcdata[j+2];\n _basic_cfloat_pow = funcdata[j+3];\n _basic_cdouble_pow = funcdata[j+4];\n _basic_clongdouble_pow = funcdata[j+5];\n\n Py_DECREF(obj);\n\n /* Get the floor functions */\n\n obj = PyObject_GetAttrString(mm, \"floor\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_floor = funcdata[j];\n _basic_double_floor = funcdata[j+1];\n _basic_longdouble_floor = funcdata[j+2];\n\n Py_DECREF(obj);\n ret = 0;\n fail:\n Py_DECREF(mm);\n return ret;\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n if (get_functions() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/ufuncobject.h\"\n#include \"numpy/arrayscalars.h\"\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZENAME=BYTE*2,SHORT*2,INT*2,LONG*2#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n**/\n#if SIZEOF_@SIZE@ > SIZEOF_@SIZENAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n\t generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n**/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n\tgenerate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #neg=(1,0)*5#\n**/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n if (b == 0) {\n\tgenerate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if (b == -1 && a < 0 && a == -a) {\n\tgenerate_overflow_error();\n\t*out = a / b;\n }\n#endif\n else {\n\t*out = a / b;\n }\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\nstatic void\n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {\n if (a == 0 || b == 0) {\n\tif (b == 0) generate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if ((a > 0) == (b > 0)) {\n\t*out = a % b;\n }\n else { /* handled like Python does */\n\t*out = a % b;\n\tif (*out) *out += b;\n }\n#else\n *out = a % b;\n#endif\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n**/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n *(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/* b will always be positive in this call */\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n \n}\n/**end repeat**/\n\n\n\n/* QUESTION: Should we check for overflow / underflow in (l,r)shift? */\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n**/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_floor)(@name@);\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) \\\n *(outp) = _basic_@name@_floor((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\\\n (outp)->real = (a).real + (b).real;\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\\\n (outp)->real = (a).real - (b).real;\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do {\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) /\t\\\n ((a).real*(b).real + (b).imag*(b).imag);\t\t\t\\\n (outp)->imag = 0;\t\t\t\t\t\t\\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - _basic_@name@_floor(a/b)*b;\n} \n/**end repeat**/ \n\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_ctype_divmod(a, b, out, out2) {\t\\\n @name@_ctype_floor_divide(a, b, out);\t\\\n @name@_ctype_remainder(a, b, out2);\t\t\\\n }\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_pow)(@name@ a, @name@ b);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = _basic_@name@_pow(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #uns=(1,0)*5,0*3#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n#if @uns@\n generate_overflow_error();\n#endif\n *out = -a;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n/* Get the nc_powf, nc_pow, and nc_powl functions from \n the data area of the power ufunc in umathmodule. \n*/\n\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n out->real = a.real;\n out->imag = a.imag;\n}\nstatic void (*_basic_@name@_pow)(@name@ *, @name@ *, @name@ *);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out)\n{\n _basic_@name@_pow(&a, &b, out);\n}\n/**end repeat**/\n\n\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, floor_divide*6, true_divide*6, divmod*3, remainder*3#\n #fperr=1*70,0*50,1*52#\n #twoout=0*50,1*10,0*106,1*3,0*3#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*12, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*12, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n**/\n\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @twoout@\n @otyp@ out2;\n PyObject *obj;\n#endif\n\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @twoout@\n @name@_ctype_@oper@(arg1, arg2, &out, &out2);\n#else\n @name@_ctype_@oper@(arg1, arg2, &out);\n#endif\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n\n#if @twoout@\n ret = PyTuple_New(2);\n if (ret==NULL) return NULL;\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out;\n PyTuple_SET_ITEM(ret, 0, obj);\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out2;\n PyTuple_SET_ITEM(ret, 1, obj);\n#else\n ret = PyArrayScalar_New(@OName@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @OName@) = out;\n#endif\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float, double, longdouble, cfloat, cdouble, clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #otyp=float*4, double*6, float, double, longdouble, cfloat, cdouble, clongdouble#\n #OName=Float*4, Double*6, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #isint=(1,0)*5,0*6#\n #cmplx=0*13,1*3#\n**/\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n @otyp@ out1;\n int retstatus;\n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n }\n\n PyUFunc_clearfperr();\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @cmplx@\n if (arg2.real == 0 && arg1.real == 0) {\n\tout1.real = out.real = 1.0;\n\tout1.imag = out.imag = 0.0;\n }\n#else\n if (arg2 == 0) {\n\tout1 = out = 1;\n } \n#endif\n#if @isint@\n else if (arg2 < 0) {\n\t@name@_ctype_power(arg1, -arg2, &out);\n\tout1 = 1.0 / out;\n }\n#endif\n else {\n\t@name@_ctype_power(arg1, arg2, &out);\n }\n\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n\n#if @isint@\n if (arg2 < 0) {\n\tret = PyArrayScalar_New(@OName@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @OName@) = out1;\n }\n else {\n\tret = PyArrayScalar_New(@Name@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @Name@) = out;\n }\n#else\n ret = PyArrayScalar_New(@Name@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @Name@) = out;\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n#name=(cfloat,cdouble,clongdouble)*2#\n#oper=divmod*3,remainder*3#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3, byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*3, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n #oper=negative*16, positive*16, absolute*16, invert*10#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n#name=float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_invert NULL\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) \n\tPyArrayScalar_RETURN_TRUE;\n else\n\tPyArrayScalar_RETURN_FALSE;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic int\nget_functions(void)\n{\n PyObject *mm, *obj;\n void **funcdata;\n char *signatures;\n int i, j;\n int ret = -1;\n\t\n /* Get the nc_pow functions */\n /* Get the pow functions */\n mm = PyImport_ImportModule(\"numpy.core.umath\");\n if (mm == NULL) return -1;\n \n obj = PyObject_GetAttrString(mm, \"power\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_pow = funcdata[j];\n _basic_double_pow = funcdata[j+1];\n _basic_longdouble_pow = funcdata[j+2];\n _basic_cfloat_pow = funcdata[j+3];\n _basic_cdouble_pow = funcdata[j+4];\n _basic_clongdouble_pow = funcdata[j+5];\n\n Py_DECREF(obj);\n\n /* Get the floor functions */\n\n obj = PyObject_GetAttrString(mm, \"floor\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_floor = funcdata[j];\n _basic_double_floor = funcdata[j+1];\n _basic_longdouble_floor = funcdata[j+2];\n\n Py_DECREF(obj);\n ret = 0;\n fail:\n Py_DECREF(mm);\n return ret;\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n if (get_functions() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + " if (out) {", + " }", + " else {", + " }" + ], + "deleted": [ + " if (out)", + " else" + ] + } + } + ] + }, + { + "hash": "f399dfcc9cdbc454522c69852e188f2907364bfa", + "msg": "Fix up usage of platform-specific functions.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-04-29T21:09:04+00:00", + "author_timezone": 0, + "committer_date": "2006-04-29T21:09:04+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "40cc08de6d5fa4f7cc518c7caa97e196259e03a4" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 11, + "insertions": 53, + "lines": 64, + "files": 2, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/arrayobject.c", + "new_path": "numpy/core/src/arrayobject.c", + "filename": "arrayobject.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -3764,6 +3764,9 @@ _strings_richcompare(PyArrayObject *self, PyArrayObject *other, int cmp_op)\n return result;\n }\n \n+/* What do we do about VOID type arrays?\n+ */\n+\n static PyObject *\n array_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)\n {\n", + "added_lines": 3, + "deleted_lines": 0, + "source_code": "/*\n Provide multidimensional arrays as a basic object type in python.\n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004\n\nHeavily modified in 2005 with inspiration from Numarray\n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University\n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by\nSpace Science Telescope Institute\n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_)\n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear();\n priority = default_;\n }\n Py_XDECREF(ret);\n return priority;\n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a\n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n }\n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int\ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides,\n\t intp *src_dimensions, int src_nd, int elsize,\n\t int copies) {\n intp i, j;\n\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1,\n dest_dimensions+1, dest_nd-1,\n src, src_strides,\n src_dimensions, src_nd,\n elsize, copies) == -1)\n return -1;\n }\n return 0;\n }\n\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError,\n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) &&\n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] !=\n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src)\n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\n dest_strides_ptr = dest_strides;\n\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1)\n return NULL;\n\n new_data = (char *)_pya_malloc(stride);\n\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions,\n dest_nd, src->data, src_strides,\n src_dimensions, src_nd, elsize, copies);\n\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *,\n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int\nPyArray_INCREF(PyArrayObject *mp)\n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap)\n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n\n\n if ((numitems == 1) || (itemsize == srcstrides))\n memcpy(d1, s1, itemsize*numitems);\n else {\n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n }\n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG\n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i)\n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp\nPyArray_Size(PyObject *op)\n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n }\n\telse {\n return 0;\n }\n}\n\nstatic void\n_strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides, \n\t\t\t intp N, int elsize)\n{\n intp i, j;\n char *tout = dst;\n char *tin = src;\n\n#define _FAST_MOVE(_type_)\t\t\t\t \\\n\tfor (i=0; idescr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n\n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, dest);\n PyArray_INCREF(dest);\n return 0;\n }\n \n /* See if we can iterate over the largest dimension */\n if (!swap && (nd = dest->nd) == src->nd && (nd > 0) && \n PyArray_CompareLists(dest->dimensions, src->dimensions, nd)) { \n int maxaxis=0, maxdim=dest->dimensions[0];\n int i;\n for (i=1; idimensions[i] > maxdim) {\n maxaxis = i;\n maxdim = dest->dimensions[i];\n }\n }\n\n dit = (PyArrayIterObject *) \\\n PyArray_IterAllButAxis((PyObject *)dest, maxaxis);\n sit = (PyArrayIterObject *) \\\n PyArray_IterAllButAxis((PyObject *)src, maxaxis);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n index = dit->size;\n\t\tif (PyArray_ISALIGNED(dest) && PyArray_ISALIGNED(src)) {\n\t\t\twhile(index--) {\n\t\t\t\t/* strided copy of elsize bytes */\n\t\t\t\t_strided_byte_copy(dit->dataptr, \n\t\t\t\t\t\t dest->strides[maxaxis],\n\t\t\t\t\t\t sit->dataptr, \n\t\t\t\t\t\t src->strides[maxaxis],\n\t\t\t\t\t\t maxdim, elsize);\n\t\t\t\tPyArray_ITER_NEXT(dit);\n\t\t\t\tPyArray_ITER_NEXT(sit);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\twhile(index--) {\n\t\t\t\t/* strided copy of elsize bytes */\n\t\t\t\t_unaligned_strided_byte_copy(dit->dataptr, \n\t\t\t\t\t\t\t dest->strides[maxaxis],\n\t\t\t\t\t\t\t sit->dataptr, \n\t\t\t\t\t\t\t src->strides[maxaxis],\n\t\t\t\t\t\t\t maxdim, elsize);\n\t\t\t\tPyArray_ITER_NEXT(dit);\n\t\t\t\tPyArray_ITER_NEXT(sit);\n\t\t\t}\n\t\t}\t\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n return 0; \n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n\t\t\tmemmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, dest);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n }\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int\nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)\n{\n PyArrayObject *src;\n int ret;\n\t\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d,\n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t} \n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, PyArray_ORDER fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran == PyArray_ANYORDER) \n\t\tfortran = PyArray_ISFORTRAN(m1);\n \n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,\n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd,\n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran,\n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\n return (PyObject *)ret;\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif PyTypeNum_ISSTRING(type_num) { /* Eliminate NULL bytes */\n\t\tchar *dptr = data;\n\t\tdptr += itemsize-1;\n\t\twhile(itemsize && *dptr-- == 0) itemsize--;\n\t\tif (type_num == PyArray_UNICODE && itemsize) {\n\t\t\t/* make sure itemsize is a multiple of 4 */\n\t\t\t/* so round up to nearest multiple */\n\t\t\titemsize = (((itemsize-1) >> 2) + 1) << 2;\n\t\t}\n\t}\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) {\n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED;\n\t\t\tmemcpy(destptr, data, itemsize);\n\t\t\treturn obj;\n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=0;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use\n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE,length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifdef Py_UNICODE_WIDE\n\t\t\tmemcpy(destptr, data, itemsize);\n\t\t\tif (swap)\n\t\t\t\tbyte_swap_vector(destptr, length, 4);\n#else\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, \n\t\t\t\t\t\t\t itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, \n\t\t\t\t\t\t (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n#endif\n\t\t\treturn obj;\n\t\t}\n\t\telse {\n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, base);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this.\n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag\n*/\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp)\n{\n\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n\n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int\nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs,\n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/*\n copyies over from the old descr table for anything\n NULL or zero in what is given.\n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)\n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data,\n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError,\n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr,\n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element\"\\\n \" %d to file\",\n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj);\n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj),\n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\",\n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1) \n if (fwrite(sep, 1, n3, fp) < n3) {\n\t\t\t\t\tPyErr_Format(PyExc_IOError,\n\t\t\t\t\t\t \"problem writing \"\\\n\t\t\t\t\t\t \"separator to file\");\n\t\t\t\t\tPy_DECREF(strobj);\n\t\t\t\t\tPy_DECREF(it);\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self)\n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0)\n\t\treturn self->descr->f->getitem(self->data,self);\n\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n\n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void\narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an\n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE\n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n\n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\narray_length(PyArrayObject *self)\n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i)\n{\n\tchar *item;\n\tPyArrayObject *r;\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1,\n\t\t\t\t\t\t self->dimensions+1,\n\t\t\t\t\t\t self->strides+1, item,\n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\n/* contains optimization for 1-d arrays */\nstatic PyObject *\narray_item_nice(PyArrayObject *self, _int_or_ssize_t i)\n{\n\tif (self->nd == 1) {\n\t\tchar *item;\n if (i < 0) {\n\t\t\ti += self->dimensions[0];\n\t\t}\n\t\tif ((item = index2ptr(self, i)) == NULL) return NULL;\n\t\treturn PyArray_Scalar(item, self->descr, (PyObject *)self);\n\t}\n\telse {\n\t\treturn PyArray_Return((PyArrayObject *)\\\n\t\t\t\t array_big_item(self, (intp) i));\n\t}\n}\n\nstatic int\narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v)\n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret;\n }\n\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if PY_VERSION_HEX < 0x02050000\n #if SIZEOF_INT == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#else\n #if SIZEOF_SIZE_T == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#endif\n#ifndef array_ass_item\nstatic int\narray_ass_item(PyArrayObject *self, _int_or_ssize_t i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int\nparse_index(PyArrayObject *self, PyObject *op,\n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError,\n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\n nd_old = nd_new = 0;\n\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n PyArrayObject *arr;\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n /* arr might not have the right number of dimensions\n and need to be reshaped first by pre-pending ones */\n arr = *ret; \n if (arr->nd != mit->nd) {\n for (i=1; i<=arr->nd; i++) {\n permute.ptr[mit->nd-i] = arr->dimensions[arr->nd-i];\n }\n for (i=0; ind-arr->nd; i++) {\n permute.ptr[i] = 1;\n } \n new = PyArray_Newshape(arr, &permute, PyArray_ANYORDER);\n Py_DECREF(arr);\n *ret = (PyArrayObject *)new;\n if (new == NULL) return;\n }\n\n\t/* tuple for transpose is\n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of\n\t the broadcasted index array\n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the\n\t result\n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2)\n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call.\n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type,\n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret))\n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t\tif (arr == NULL) return -1;\n\t\t}\n\t}\n\t\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, arr);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS];\n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL)\n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0\n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from\n Python when using a[object] unless object is a standard slice object\n (not an extended one).\n\n*/\n\n/* There are two situations:\n\n 1 - the subscript is a standard view and a reference to the\n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned.\n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *);\n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op)\n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr,\n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis) {\n\t\t\t/* XXX: This leads to a small inconsistency\n\t\t\t XXX: with the nd>0 case where (x[...] is x)\n\t\t\t XXX: is false for nd>0 case. */\n\t\t\tPy_INCREF(self);\n\t\t\treturn (PyObject *)self;\n\t\t}\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op)) {\n\t\t\t\tPy_INCREF(self);\n\t\t\t\treturn (PyObject *)self;\n\t\t\t}\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset))\n == -1)\n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset,\n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL)\n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be\n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *);\n\nstatic int\narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)\n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr,\n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1;\n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to\n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op)\n{\n\t/* The following is just a copy of PyArray_Return with an\n\t additional logic in the nd == 0 case. More efficient\n\t implementation may be possible by refactoring\n\t array_subscript */\n\n\tPyArrayObject *mp;\n\n\t/* optimization for integer select and 1-d */\n\tif (self->nd == 1 && (PyInt_Check(op) || PyLong_Check(op))) {\n intp value;\n\t\tchar *item;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred()) \n\t\t\treturn NULL;\n else if (value < 0) {\n\t\t\tvalue += self->dimensions[0];\n\t\t}\n\t\tif ((item = index2ptr(self, value)) == NULL) return NULL;\n\t\treturn PyArray_Scalar(item, self->descr, (PyObject *)self);\n\t}\n\tmp = (PyArrayObject *)array_subscript(self, op);\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tBool noellipses = TRUE;\n\t\tif (op == Py_Ellipsis)\n\t\t\tnoellipses = FALSE;\n\t\telse if (PySequence_Check(op)) {\n\t\t\tint n, i;\n\t\t\tn = PySequence_Size(op);\n\t\t\tfor (i = 0; i < n; ++i) \n\t\t\t\tif (PySequence_GetItem(op, i) == Py_Ellipsis) {\n\t\t\t\t\tnoellipses = FALSE;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t\tif (noellipses) {\n\t\t\tPyObject *ret;\n\t\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\t\tPy_DECREF(mp);\n\t\t\treturn ret;\n\t\t}\n\t}\n\treturn (PyObject *)mp;\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t /*mp_length*/\n#else\n (inquiry)array_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic _int_or_ssize_t\narray_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp)\n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic _int_or_ssize_t\narray_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"accessing non-existing array segment\");\n return -1;\n }\n\n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic _int_or_ssize_t\narray_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (PyArray_CHKFLAGS(self, WRITEABLE))\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic _int_or_ssize_t\narray_getcharbuf(PyArrayObject *self, _int_or_ssize_t segment, const char **ptrptr)\n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError,\n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (writebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (segcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (charbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#else\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#endif\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n *square,\n *reciprocal,\n *ones_like,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum,\n\t\t*rint;\n} NumericOps;\n\nstatic NumericOps n_ops; /* NB: static objects inlitialized to zero */\n\n/* Dictionary can contain any of the numeric operations, by name.\n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n\n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint\nPyArray_SetNumericOps(PyObject *dict)\n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n SET(square);\n SET(reciprocal);\n SET(ones_like);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\n SET(true_divide);\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n\tSET(rint);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void)\n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL)\n\t\treturn NULL;\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n GET(square);\n GET(reciprocal);\n GET(ones_like);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide);\n GET(true_divide);\n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\tGET(rint);\n\treturn dict;\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,\n\t\t\t\t PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2)\n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic int\narray_power_is_scalar(PyObject *o2, double* exp)\n{\n PyObject *temp;\n const int optimize_fpexps = 1;\n\n if (PyInt_Check(o2)) {\n\t *exp = (double)PyInt_AsLong(o2);\n\t return 1;\n }\n if (optimize_fpexps && PyFloat_Check(o2)) {\n\t *exp = PyFloat_AsDouble(o2);\n\t return 1;\n }\n if ((PyArray_IsZeroDim(o2) && \n\t ((PyArray_ISINTEGER(o2) || \n\t (optimize_fpexps && PyArray_ISFLOAT(o2))))) || \n\tPyArray_IsScalar(o2, Integer) || \n\t(optimize_fpexps && PyArray_IsScalar(o2, Floating))) {\n\t temp = o2->ob_type->tp_as_number->nb_float(o2);\n\t if (temp != NULL) {\n\t\t *exp = PyFloat_AsDouble(o2);\n\t\t Py_DECREF(temp);\n\t\t return 1;\n\t }\n }\n return 0;\n}\n\n/* optimize float array or complex array to a scalar power */\nstatic PyObject *\nfast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) {\n\tdouble exp;\n\tif (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) || \n\t\t\t\t PyArray_ISCOMPLEX(a1))) {\n\t\tif (array_power_is_scalar(o2, &exp)) {\n\t\t\tPyObject *fastop = NULL;\n\t\t\tif (exp == 1.0) {\n\t\t\t\t/* we have to do this one special, as the \n\t\t\t\t \"copy\" method of array objects isn't set \n\t\t\t\t up early enough to be added\n\t\t\t\t by PyArray_SetNumericOps.\n\t\t\t\t*/\n\t\t\t\tif (inplace) {\n\t\t\t\t\treturn (PyObject *)a1;\n\t\t\t\t} else {\n\t\t\t\t\treturn PyArray_Copy(a1);\n\t\t\t\t}\n\t\t\t} else if (exp == -1.0) {\n\t\t\t\tfastop = n_ops.reciprocal;\n\t\t\t} else if (exp == 0.0) {\n\t\t\t\tfastop = n_ops.ones_like;\n\t\t\t} else if (exp == 0.5) {\n\t\t\t\tfastop = n_ops.sqrt;\n\t\t\t} else if (exp == 2.0) {\n\t\t\t\tfastop = n_ops.square;\n\t\t\t} else {\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tif (inplace) {\n\t\t\t\tPyArray_GenericInplaceUnaryFunction(a1, \n\t\t\t\t\t\t\t\t fastop);\n\t\t\t} else {\n\t\t\t\treturn PyArray_GenericUnaryFunction(a1, \n\t\t\t\t\t\t\t\t fastop);\n\t\t\t}\n\t\t}\n\t}\n\treturn NULL;\n}\n\nstatic PyObject *\narray_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n\t/* modulo is ignored! */\n\tPyObject *value;\n\tvalue = fast_scalar_power(a1, o2, 0);\n\tif (!value) {\n\t\tvalue = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);\n\t}\n\treturn value;\n}\n\n\nstatic PyObject *\narray_negative(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 1);\n if (!value) {\n value = PyArray_GenericInplaceBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int\narray_any_nonzero(PyArrayObject *mp)\n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2)\n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_float(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to a \"\\\n\t\t\t\t\"float; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_long(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/\n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected\n*/\n\n\nstatic PyObject *\narray_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t _int_or_ssize_t ihigh)\n{\n PyArrayObject *r;\n _int_or_ssize_t l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n self->dimensions[0] = l;\n\tif (r == NULL) return NULL;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS);\n return (PyObject *)r;\n}\n\n\nstatic int\narray_ass_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t\t_int_or_ssize_t ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res;\n int ret;\n\t\n res = PyArray_EnsureAnyArray(PyObject_RichCompare((PyObject *)self, \n\t\t\t\t\t\t\t el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\nstatic PySequenceMethods array_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (ssizeargfunc)NULL,\n\t(ssizeargfunc)array_item_nice,\n\t(ssizessizeargfunc)array_slice,\n (ssizeobjargproc)array_ass_item,\t /*sq_ass_item*/\n (ssizessizeobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(ssizeargfunc)NULL,\n#else\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t /*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n#endif\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int\ndump_data(char **string, int *n, int *max_n, char *data, int nd,\n intp *dimensions, intp *strides, PyArrayObject* self)\n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\n if (nd == 0) {\n\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata,\n\t\t self->nd, self->dimensions,\n self->strides, self) < 0) {\n\t\t_pya_free(string); return NULL;\n\t}\n\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void\nPyArray_SetStringFunction(PyObject *op, int repr)\n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_ReprFunction = op;\n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_StrFunction = op;\n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\n\n\n/*OBJECT_API\n */\nstatic int\nPyArray_CompareUCS4(PyArray_UCS4 *s1, PyArray_UCS4 *s2, register size_t len)\n{\n register PyArray_UCS4 c1, c2;\n while(len-- > 0) {\n c1 = *s1++;\n c2 = *s2++;\n if (c1 != c2) {\n return (c1 < c2) ? -1 : 1;\n\t\t}\n }\n\treturn 0;\n}\n\nstatic int\n_myunincmp(PyArray_UCS4 *s1, PyArray_UCS4 *s2, int len1, int len2)\n{\n\tPyArray_UCS4 *sptr;\n\tint val;\n\n\tval = PyArray_CompareUCS4(s1, s2, MIN(len1, len2));\n\tif ((val != 0) || (len1 == len2)) return val;\n\tif (len2 > len1) {sptr = s2+len1; val = -1;}\n\telse {sptr = s1+len2; val = 1;}\n\tif (*sptr != 0) return val;\n\n\tif (len2 > len1) {sptr = s2; val = -1;}\n\telse {sptr = s1; val = 1;}\n\tif (*sptr != 0) return val;\n\treturn 0;\n}\n\n\n\n/* Compare s1 and s2 which are not necessarily NULL-terminated. \n s1 is of length len1\n s2 is of length len2\n If they are NULL terminated, then stop comparison.\n*/\nstatic int\n_mystrncmp(char *s1, char *s2, int len1, int len2)\n{\n\tchar *sptr;\n\tint val;\n\n\tval = strncmp(s1, s2, MIN(len1, len2));\n\tif ((val != 0) || (len1 == len2)) return val;\n\tif (len2 > len1) {sptr = s2+len1; val = -1;}\n\telse {sptr = s1+len2; val = 1;}\n\tif (*sptr != 0) return val;\n\treturn 0;\n}\n\nstatic int\n_compare_strings(PyObject *result, PyArrayMultiIterObject *multi, \n\t\t int cmp_op, void *func)\n{\n\tPyArrayIterObject *iself, *iother;\n\tBool *dptr;\n\tintp size;\n\tint val;\n\tint N1, N2;\n\tint (*cmpfunc)(void *, void *, int, int);\n\t\n\tcmpfunc = func;\n\tdptr = (Bool *)PyArray_DATA(result);\n\tiself = multi->iters[0];\n\tiother = multi->iters[1];\n\tsize = multi->size;\n\tN1 = iself->ao->descr->elsize;\n\tN2 = iother->ao->descr->elsize;\n\tif ((void *)cmpfunc == (void *)_myunincmp) {\n\t\tN1 >>= 2;\n\t\tN2 >>= 2;\n\t}\n\twhile(size--) {\n\t\tval = cmpfunc((void *)iself->dataptr, (void *)iother->dataptr, \n\t\t\t N1, N2);\n\t\tswitch (cmp_op) {\n\t\tcase Py_EQ:\n\t\t\t*dptr = (val == 0);\n\t\t\tbreak;\n\t\tcase Py_NE:\n\t\t\t*dptr = (val != 0);\n\t\t\tbreak;\n\t\tcase Py_LT:\n\t\t\t*dptr = (val < 0);\n\t\t\tbreak;\n\t\tcase Py_LE:\n\t\t\t*dptr = (val <= 0);\n\t\t\tbreak;\n\t\tcase Py_GT:\n\t\t\t*dptr = (val > 0);\n\t\t\tbreak;\n\t\tcase Py_GE:\n\t\t\t*dptr = (val >= 0);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"bad comparison operator\");\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_NEXT(iself);\n\t\tPyArray_ITER_NEXT(iother);\n\t\tdptr += 1;\n\t}\n\treturn 0;\t\n}\n\nstatic PyObject *\n_strings_richcompare(PyArrayObject *self, PyArrayObject *other, int cmp_op)\n{\n PyObject *result;\n\tPyArrayMultiIterObject *mit;\n\tint val;\n\n /* Cast arrays to a common type */ \n if (self->descr->type != other->descr->type) {\n PyObject *new;\n if (self->descr->type_num == PyArray_STRING && \\\n other->descr->type_num == PyArray_UNICODE) {\n Py_INCREF(other);\n Py_INCREF(other->descr);\n new = PyArray_FromAny((PyObject *)self, other->descr, \n\t\t\t\t\t 0, 0, 0, NULL);\n if (new == NULL) return NULL;\n self = (PyArrayObject *)new;\n }\n else if (self->descr->type_num == PyArray_UNICODE &&\t\\\n other->descr->type_num == PyArray_STRING) {\n Py_INCREF(self);\n Py_INCREF(self->descr);\n new = PyArray_FromAny((PyObject *)other, self->descr, \n\t\t\t\t\t 0, 0, 0, NULL);\n if (new == NULL) return NULL;\n other = (PyArrayObject *)new;\n }\n else {\n PyErr_SetString(PyExc_TypeError, \n \"invalid string data-types \"\n \"in comparison\");\n return NULL;\n }\n }\n else { \n Py_INCREF(self);\n Py_INCREF(other);\n }\n\n /* Broad-cast the arrays to a common shape */\n mit = (PyArrayMultiIterObject *)PyArray_MultiIterNew(2, self, other);\n\tPy_DECREF(self);\n\tPy_DECREF(other);\n if (mit == NULL) return NULL;\n\t\n\tresult = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t PyArray_DescrFromType(PyArray_BOOL),\n\t\t\t\t mit->nd,\n\t\t\t\t mit->dimensions,\n\t\t\t\t NULL, NULL, 0, \n\t\t\t\t NULL);\n\tif (result == NULL) goto finish;\n\n\tif (self->descr->type_num == PyArray_STRING) {\n\t\tval = _compare_strings(result, mit, cmp_op, _mystrncmp);\n\t}\n\telse {\n\t\tval = _compare_strings(result, mit, cmp_op, _myunincmp);\n\t}\n\t\n\tif (val < 0) {Py_DECREF(result); result = NULL;}\n\t\n finish: \n\tPy_DECREF(mit);\n return result;\n}\n\n/* What do we do about VOID type arrays?\n */\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)\n{\n PyObject *array_other, *result = NULL;\n\tint typenum;\n\n switch (cmp_op)\n {\n case Py_LT:\n result = PyArray_GenericBinaryFunction(self, other,\n n_ops.less);\n break;\n case Py_LE:\n result = PyArray_GenericBinaryFunction(self, other,\n n_ops.less_equal);\n break;\n case Py_EQ:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then return False\n\t\t\t\t This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of False\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the\n\t\t\t two array objects can not be compared together so\n\t\t\t return zero\n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n break;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be\n\t\t\t\t compared and cannot be equal, therefore,\n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n break;\n case Py_GT:\n result = PyArray_GenericBinaryFunction(self, other,\n n_ops.greater);\n break;\n case Py_GE:\n result = PyArray_GenericBinaryFunction(self, other,\n n_ops.greater_equal);\n break;\n default:\n result = Py_NotImplemented;\n Py_INCREF(result);\n }\n if (result == Py_NotImplemented) {\n /* Try to handle string comparisons */\n if (self->descr->type_num == PyArray_OBJECT) return result;\n array_other = PyArray_FromObject(other,PyArray_NOTYPE, 0, 0);\n if (PyArray_ISSTRING(self) && PyArray_ISSTRING(array_other)) {\n result = _strings_richcompare(self, (PyArrayObject *)\n\t\t\t\t\t\t array_other, cmp_op);\n }\n Py_DECREF(array_other);\n }\n return result;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\tif (temp) *axis = PyArray_NDIM(temp)-1;\n\t\telse *axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL,\n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int\n_IsFortranContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap)\n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object\n\t If it is a writeable array, then return TRUE\n\t If we can find an array object\n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable\n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA))\n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly\n\t and unpickled array can be set and reset writeable\n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t\telse ret->flags &= ~WRITEABLE;\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not\n ever be able to walk outside of the memory implied numbytes and offset.\n\n The available memory is assumed to start at -offset and proceed\n to numbytes-offset. The strides are checked to ensure\n that accessing memory using striding will not try to reach beyond\n this memory for any of the axes.\n\n If numbytes is 0 it will be calculated using the dimensions and\n element-size.\n\n This function checks for walking beyond the beginning and right-end\n of the buffer and therefore works for any integer stride (positive\n or negative).\n*/\n\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\tintp byte_begin;\n\tintp begin;\n\tintp end;\n\n\tif (numbytes == 0)\n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\n\tbegin = -offset;\n\tend = numbytes - offset - elsize;\n\tfor (i=0; i end))\n\t\t\treturn FALSE;\n\t}\n\treturn TRUE;\n\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings\n depending on data and strides:\n\n If data is given, then flags is flags associated with data.\n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument\n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set).\n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired.\n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize,\n\t\t int inflag, int *objflags)\n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\n/* and update the dimensions and strides\n appropriately. Dimensions and strides are added\n to the end unless we have a FORTRAN array\n and then they are added to the beginning\n\n Strides are only added if given (because data is given).\n*/\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,\n\t\t\t intp *newstrides, int oldnd, int isfortran)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\tint tuple;\n\n\told = *des;\n\t*des = old->subarray->base;\n\n\n\tmydim = newdims + oldnd;\n\ttuple = PyTuple_Check(old->subarray->shape);\n\tif (tuple) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t}\n\telse {\n\t\tnumnew = 1;\n\t}\n\n\n\tnewnd = oldnd + numnew;\n\tif (newnd > MAX_DIMS) goto finish;\n\tif (isfortran) {\n\t\tmemmove(newdims+numnew, newdims, oldnd*sizeof(intp));\n\t\tmydim = newdims;\n\t}\n\n\tif (tuple) {\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\tif (isfortran) {\n\t\t\tmemmove(newstrides+numnew, newstrides,\n\t\t\t\toldnd*sizeof(intp));\n\t\t\tmystrides = newstrides;\n\t\t}\n\t\t/* Make new strides -- alwasy C-contiguous */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\n finish:\n\tPy_INCREF(*des);\n\tPy_DECREF(old);\n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,\n\t\t intp *dims, intp *strides, void *data,\n\t\t int flags, PyObject *obj)\n{\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tint isfortran=0;\n\t\tisfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || \\\n\t\t\t(!data && flags);\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims,\n\t\t\t\t\t\t newstrides, nd, isfortran);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims,\n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { \n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN;\n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse { /* we allow strides even when we create\n\t\t\t the memory, but be careful with this...\n\t\t */\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n\telse { self->dimensions = self->strides = NULL; }\n\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays\n\t\t e.g. shape=(0,) -- otherwise buffer exposure\n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in,\n\t\t\t\t\t this object won't own it\n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for\n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype.\n\t If obj is NULL, then call method with Py_None \n\t*/\n\tif ((subtype != &PyArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (strides != NULL) { /* did not allocate own data \n\t\t\t\t\t or funny strides */\n\t\t\t/* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tif (obj == NULL) obj=Py_None;\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n If refcheck is 0, then the reference count is not checked\n and assumed to be 1.\n You still must own this data and have no weak-references and no base\n object.\n*/\nstatic PyObject *\nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck,\n\t PyArray_ORDER fortran)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\n if (!PyArray_ISONESEGMENT(self)) {\n PyErr_SetString(PyExc_ValueError,\n \"resize only works on single-segment arrays\");\n return NULL;\n }\n\n\tif (fortran == PyArray_ANYORDER)\n\t\tfortran = PyArray_CORDER;\n \n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n\n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (refcheck) refcnt = REFCOUNT(self);\n\t\telse refcnt = 1;\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (newsize == 0) sd = self->descr->elsize;\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n\n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) {\n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0,\n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n\n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n\n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n self->flags, &(self->flags));\n\n\n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\n return Py_None;\n\n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\tPyArray_FillWithScalarFunc* fillwithscalar =\n\t\t\tarr->descr->f->fillwithscalar;\n\t\tif (fillwithscalar && PyArray_ISALIGNED(arr)) {\n\t\t\tcopyswap(fromptr, NULL, swap, arr);\n\t\t\tfillwithscalar(toptr, size, fromptr, arr);\n\t\t}\n\t\telse {\n\t\t\twhile (size--) {\n\t\t\t\tcopyswap(toptr, fromptr, swap, arr);\n\t\t\t\ttoptr += itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, arr);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"order\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n PyArray_ORDER order=PyArray_CORDER;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL;\n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous\n\t array of a specific type and shape.\n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims,\n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter,\n &strides,\n &PyArray_OrderConverter,\n &order))\n\t\tgoto fail;\n\n if (order == PyArray_FORTRANORDER) fortran = 1;\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"data-type with unspecified variable length\");\n\t\tgoto fail;\n\t}\n\t\n\tif (strides.ptr != NULL) {\n\t\tintp nb, off;\n\t\tif (strides.len != dims.len) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides, if given, must be \"\t\\\n\t\t\t\t\t\"the same length as shape\");\n\t\t\tgoto fail;\n\t\t}\n\n\t\tif (buffer.ptr == NULL) {\n\t\t\tnb = 0;\n\t\t\toff = 0;\n\t\t}\n\t\telse {\n\t\t\tnb = buffer.len;\n\t\t\toff = offset;\n\t\t}\n\t\t\n\n\t\tif (!PyArray_CheckStrides(itemsize, dims.len, \n\t\t\t\t\t nb, off,\n\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides is incompatible \"\t\\\n\t\t\t\t\t\"with shape of requested \"\t\\\n\t\t\t\t\t\"array and size of buffer\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\t\t\t\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len,\n\t\t\t\t\t dims.ptr,\n\t\t\t\t\t strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = (buffer.len-offset) / itemsize;\n }\n else if ((strides.ptr == NULL) && \\\n\t\t\t buffer.len < itemsize*\t\t\t\t\\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError,\n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t offset + (char *)buffer.ptr,\n\t\t\t\t\t buffer.flags, NULL);\n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base);\n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyArray_NewFlagsObject((PyObject *)self);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n\tint nd;\n\tPyObject *ret;\n\n /* Assumes C-order */\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n if (PyArray_DATA(ret) != PyArray_DATA(self)) {\n Py_DECREF(ret);\n PyErr_SetString(PyExc_AttributeError, \n \"incompatible shape for a non-contiguous array\");\n return -1;\n }\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret),\n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret),\n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes=0;\n\tintp offset=0;\n\tint buf_len;\n\tchar *buf;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base && PyArray_Check(new->base)) {\n\t\tnew = (PyArrayObject *)(new->base);\n\t}\n\t/* Get the available memory through the buffer\n\t interface on new->base or if that fails\n\t from the current new */\n\tif (new->base && PyObject_AsReadBuffer(new->base,\n\t\t\t\t\t (const void **)&buf,\n\t\t\t\t\t &buf_len) >= 0) {\n\t\toffset = self->data - buf;\n\t\tnumbytes = buf_len + offset;\n\t}\n\telse {\n\t\tPyErr_Clear();\n \t\tnumbytes = PyArray_MultiplyList(new->dimensions,\n\t\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\toffset = self->data - new->data;\n\t}\n\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes,\n\t\t\t\t offset,\n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self))\n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self)\n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0,\n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf,\n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse\n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse\n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed.\n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the\n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0)\n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n\telse if (newtype->elsize > self->descr->elsize) {\n\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update\n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\t/* We would decref newtype here --- temp will\n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tif (temp == NULL) return -1;\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\tPy_INCREF(temp->descr);\n\t\t/* Fool deallocator not to delete these*/\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype;\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA);\n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, \n\t\t\t\t\t\t (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num -\n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type,\n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new);\n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int\narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode,\n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr));\n memmove(selfit->dataptr, arrit->dataptr,\n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size)\n PyArray_ITER_RESET(arrit);\n }\n retval = 0;\n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size)\n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\",\n\t (getter)array_ndim_get,\n\t NULL,\n\t \"number of array dimensions\"},\n {\"flags\",\n\t (getter)array_flags_get,\n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\",\n\t (getter)array_shape_get,\n\t (setter)array_shape_set,\n\t \"tuple of array dimensions\"},\n {\"strides\",\n\t (getter)array_strides_get,\n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)array_data_get,\n\t (setter)array_data_set,\n\t \"pointer to start of data\"},\n {\"itemsize\",\n\t (getter)array_itemsize_get,\n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\",\n\t (getter)array_real_get,\n\t (setter)array_real_set,\n\t \"real part of array\"},\n {\"imag\",\n\t (getter)array_imag_get,\n\t (setter)array_imag_set,\n\t \"imaginary part of array\"},\n\t{\"flat\",\n\t (getter)array_flat_get,\n\t (setter)array_flat_set,\n\t \"a 1-d view of a contiguous array\"},\n\t{\"__array_data__\",\n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\",\n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n\t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */\n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] =\n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\nstatic PyTypeObject PyArray_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0,\t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n &array_as_sequence,\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str,\t /*tp_str*/\n\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n &array_as_buffer, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT\n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter,\t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n array_alloc,\t /* tp_alloc */\n (newfunc)array_new,\t\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int\ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple)\n{\n int d=0;\n PyObject *e;\n\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0)\n\t\treturn 1;\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize)\n{\n\tint n, r, i;\n\tPyObject *e;\n\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s)\n\t\t\t*itemsize = MAX(*itemsize, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype ---\n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately\n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE &&\n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\nstatic PyArray_Descr *\n_array_find_python_scalar_type(PyObject *op)\n{\n if (PyFloat_Check(op)) {\n return PyArray_DescrFromType(PyArray_DOUBLE);\n } else if (PyComplex_Check(op)) {\n return PyArray_DescrFromType(PyArray_CDOUBLE);\n } else if (PyInt_Check(op)) {\n /* bools are a subclass of int */\n if (PyBool_Check(op)) {\n return PyArray_DescrFromType(PyArray_BOOL);\n } else {\n return PyArray_DescrFromType(PyArray_LONG);\n }\n } else if (PyLong_Check(op)) {\n /* if integer can fit into a longlong then return that\n */\n if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n PyErr_Clear();\n return PyArray_DescrFromType(PyArray_OBJECT);\n }\n return PyArray_DescrFromType(PyArray_LONGLONG);\n }\n return NULL;\n}\n\n/* op is an object to be converted to an ndarray.\n\n minitype is the minimum type-descriptor needed.\n\n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n\n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\n\tif (minitype == NULL)\n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\n if (max < 0) goto deflt;\n\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n chktype = _array_find_python_scalar_type(op);\n if (chktype) {\n goto finish;\n }\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n\n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind,\n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n }\n\n\tif (PyInstance_Check(op)) goto deflt;\n\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\n finish:\n\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype;\n}\n\nstatic int\nAssign_Array(PyArrayObject *self, PyObject *v)\n{\n PyObject *e;\n int l, r;\n\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\n l=PyObject_Length(v);\n if(l < 0) return -1;\n\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1;\n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */\n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode)\n{\n PyArrayObject *ret;\n\tint itemsize;\n\tint type;\n\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= 4;\n\n\t\tif (itemsize != typecode->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(typecode);\n\t\t\ttypecode->elsize = itemsize;\n\t\t}\n\t}\n\n ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL,\n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\tif (ret == NULL) return NULL;\n\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode */\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string,\n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid input sequence\");\n\t\tgoto fail;\n }\n\n\tif (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {\n\t\tnd = max_depth;\n\t}\n\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid number of dimensions\");\n\t\tgoto fail;\n }\n\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\n if(!r) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int\nPyArray_ValidType(int type)\n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in))\n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, in);\n\t\t\tbptr += elsize;\n\t\t\tPyArray_ITER_NEXT(it_in);\n\t\t\tel += 1;\n\t\t\tif ((el == nels) || (index == 0)) {\n\t\t\t\t/* buffer filled, do cast */\n\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n out);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject *\nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING)\n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd,\n\t\t\t\t mp->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\n}\n\n/* The number of elements in out must be an integer multiple\n of the number of elements in mp.\n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1;\n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * mpsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr,\n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)\n{\n\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1)\n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse {\n if ((flags & ENSUREARRAY)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype,\n\t\t\t\t\t\t newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr;\n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\n\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong))\n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char))\n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long))\n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap)\n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n\n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL;\n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n\n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data,\n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr));\n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n\n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context)\n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, \n\t\t\t\t\t\t\t\t NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None,\n\t\t\t\t\t\t context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", \n\t\t\t\t\t\t typecode, context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", \n\t\t\t\t\t\t\t typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError,\n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n}\n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,\n int max_depth, int flags, PyObject *context)\n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op))\n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tif (flags & UPDATEIFCOPY) goto err;\n\t\tr = PyArray_FromScalar(op, newtype);\n\t} else if (newtype == NULL &&\n (newtype = _array_find_python_scalar_type(op))) {\n\t if (flags & UPDATEIFCOPY) goto err;\n r = Array_FromScalar(op, newtype);\n }\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, \n\t\t\t\t\t\tflags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (flags & UPDATEIFCOPY) goto err;\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\n\t/* Be sure we succeed here */\n\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n\n err:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"UPDATEIFCOPY used for non-array input.\");\n\treturn NULL;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int\nPyArray_ObjectType(PyObject *op, int minimum_type)\n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of\n CONTIGUOUS,\n FORTRAN,\n ALIGNED,\n WRITEABLE,\n NOTSWAPPED,\n ENSURECOPY,\n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should\n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or\n not it has such features.\n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well.\n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n\n FORTRAN can be set in the FLAGS to request a FORTRAN array.\n Fortran arrays are always behaved (aligned,\n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d).\n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array.\n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe.\n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,\n int max_depth, int requires, PyObject *context)\n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0,\n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place\n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op)) return op;\n\t\n\tif (PyArray_Check(op)) \n\t\treturn PyArray_View((PyArrayObject *)op, NULL, &PyArray_Type);\n\t\n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureAnyArray(PyObject *op)\n{\n\tif (op && PyArray_Check(op)) return op;\n\treturn PyArray_EnsureArray(op);\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int\nPyArray_CanCastSafely(int fromtype, int totype)\n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype))\n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode\n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\n\t\t*/\n\t}\n\treturn ret;\n}\n\n/*OBJECT_API\n See if array scalars can be cast.\n */\nstatic Bool\nPyArray_CanCastScalar(PyTypeObject *from, PyTypeObject *to)\n{\n\tint fromtype;\n\tint totype;\n\n\tfromtype = _typenum_fromtypeobj((PyObject *)from, 0);\n\ttotype = _typenum_fromtypeobj((PyObject *)to, 0);\n\tif (fromtype == PyArray_NOTYPE || totype == PyArray_NOTYPE) \n\t\treturn FALSE;\n\treturn (Bool) PyArray_CanCastSafely(fromtype, totype);\t\n}\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd;\n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D)\n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n\n/* don't use with PyArray_ITER_GOTO1D because factors are not\n adjusted */\n\n/*OBJECT_API\n Adjusts previously broadcasted iterators so that the largest axis is not iterated \n over. Returns dimension which is largest in the range [0,multi->nd). A -1 \n is returned if multi->nd == 0.\n */\nstatic int\nPyArray_RemoveLargest(PyArrayMultiIterObject *multi)\n{\n\tPyArrayIterObject *it;\n\tint i;\n\tint axis=0;\n\tintp longest;\n\n\tif (multi->nd == 0) return -1;\n\t\n\tlongest = multi->dimensions[0];\n\t/* Find longest dimension */\n\tfor (i=1; ind; i++) {\n\t\tif (multi->dimensions[i] > longest) {\n\t\t\taxis = i;\n\t\t\tlongest = multi->dimensions[i];\n\t\t}\n\t}\n\t\n\tfor (i=0; inumiter; i++) {\n\t\tit = multi->iters[i];\n\t\tit->contiguous = 0;\n\t\tif (it->size != 0)\n\t\t\tit->size /= (it->dims_m1[axis]+1);\n\t\tit->dims_m1[axis] = 0;\n\t\tit->backstrides[axis] = 0;\t\t\n\t}\n\n\treturn axis;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic _int_or_ssize_t\niter_length(PyArrayIterObject *self)\n{\n return self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, self->ao);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr,\n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, r);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1)\n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t 1, &n_steps,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail;\n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, r);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0,\n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap, self->ao);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size)\n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, self->ao);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, self->ao);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size)\n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)\n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, arrval);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, arrval);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, arrval);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size)\n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0,\n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)iter_length,\t\t /*mp_length*/\n#else\n (inquiry)iter_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op)\n{\n\n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options:\n 1) underlying array is contiguous\n -- return 1-d wrapper around it\n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, it->ao->data,\n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r);\n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n\n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\",\n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &iter_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t\t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular\n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators\n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++)\n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already\n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1)\n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"shape mismatch: objects\" \\\n\t\t\t\t\t\t\t\" cannot be broadcast\" \\\n\t\t\t\t\t\t\t\" to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t it->ao);\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tif (it->size != 0) {\n\t\t\t\tPyArray_ITER_RESET(it);\n\t\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t it->ao);\n\t\t\t}\n\t\t\telse coord[i] = 0;\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of\n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord,\n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t it->ao);\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t it->ao);\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so,\n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size.\n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere.\n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well.\n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0\n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t/* But, be sure to do it with a true array.\n\t */\n\tif (PyArray_CheckExact(arr)) {\n\t\tsub = array_subscript(arr, mit->indexobj);\n\t}\n\telse {\n\t\tPy_INCREF(arr);\n\t\tobj = PyArray_EnsureArray((PyObject *)arr);\n\t\tif (obj == NULL) goto fail;\n\t\tsub = array_subscript((PyArrayObject *)obj, mit->indexobj);\n\t\tPy_DECREF(obj);\n\t}\n\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects\n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been\n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj))\n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj,\n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1;\n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n intp indval;\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n indval = *indptr;\n\t\t\tif (indval < 0) indval += dimsize;\n\t\t\tif (indval < 0 || indval >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) indval, (int) (dimsize-1),\n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0,\n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n\tmit->index = 0;\n\tmit->ait = NULL;\n\tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY\n#undef SOBJ_ISFANCY\n#undef SOBJ_BADARRAY\n#undef SOBJ_TOOMANY\n#undef SOBJ_LISTTUP\n\n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple\n\t (with at least 1 list or arrayobject or Bool object), */\n\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i,\n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing\n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n\n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work.\n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a);\n mapiter is equivalent to a[indexobj].flat but the latter gets to use\n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t\t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t\t /* tp_iter */\n (iternextfunc)0,\t /* tp_iternext */\n 0,\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\n\tint i, err=0;\n\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\n /* fprintf(stderr, \"multi new...\");*/\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\n\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL)\n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i,\n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(multi->iters[i]);\n\tmulti->ob_type->tp_free((PyObject *)multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\",\n\t (getter)arraymultiter_size_get,\n\t NULL,\n\t \"total size of broadcasted result\"},\n {\"index\",\n\t (getter)arraymultiter_index_get,\n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter),\n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t\t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods,\t /* tp_methods */\n arraymultiter_members,\t\t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types.\n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these\n builtins will be attempted leading to problems.\n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically\n allocated).\n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless\n there is a reference-count problem\n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set.\n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base,\n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0)\n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\",\n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self)\n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\",\n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr)\n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr)\n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv))\n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\n\t/* Now return the state which is at least\n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize\n and alignment for EXTENDED arrays\n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\n\tif (endian != '|' && \n\t PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are:\n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n *** Leaves reference count of self unchanged --- does not DECREF self ***\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args)\n{\n\tchar endian=PyArray_SWAP;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS,\n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n\tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\ndescr_length(PyArray_Descr *self)\n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op)\n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError,\n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)descr_length,\t\t /*mp_length*/\n#else\n (inquiry)descr_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t\t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &descr_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t/* tp_iternext */\n arraydescr_methods,\t\t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n\n/** Array Flags Object **/\n\ntypedef struct PyArrayFlagsObject {\n PyObject_HEAD\n PyObject *arr;\n int flags;\n} PyArrayFlagsObject;\n\n/*OBJECT_API\n Get New ArrayFlagsObject\n*/\nstatic PyObject *\nPyArray_NewFlagsObject(PyObject *obj)\n{\n PyObject *flagobj;\n int flags;\n if (obj == NULL) {\n flags = CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n }\n else {\n flags = PyArray_FLAGS(obj);\n }\n flagobj = PyArrayFlags_Type.tp_alloc(&PyArrayFlags_Type, 0);\n if (flagobj == NULL) return NULL;\n Py_XINCREF(obj);\n ((PyArrayFlagsObject *)flagobj)->arr = obj;\n ((PyArrayFlagsObject *)flagobj)->flags = flags;\n\n return flagobj;\n}\n\nstatic void\narrayflags_dealloc(PyArrayFlagsObject *self)\n{\n\tPy_XDECREF(self->arr);\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n\n#define _define_get(UPPER, lower) \\\nstatic PyObject * \\\narrayflags_ ## lower ## _get(PyArrayFlagsObject *self) \\\n{ \\\n PyObject *item; \\\n item = ((self->flags & (UPPER)) == (UPPER)) ? Py_True : Py_False; \\\n Py_INCREF(item); \\\n return item; \\\n}\n\n_define_get(CONTIGUOUS, contiguous)\n_define_get(FORTRAN, fortran)\n_define_get(UPDATEIFCOPY, updateifcopy)\n_define_get(OWNDATA, owndata)\n_define_get(ALIGNED, aligned)\n_define_get(WRITEABLE, writeable)\n\n_define_get(ALIGNED|WRITEABLE, behaved)\n_define_get(ALIGNED|WRITEABLE|CONTIGUOUS, carray)\n\nstatic PyObject *\narrayflags_forc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) ||\n ((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_fnc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_farray_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & (ALIGNED|WRITEABLE|FORTRAN)) == \\\n (ALIGNED|WRITEABLE|FORTRAN)) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_num_get(PyArrayFlagsObject *self)\n{\n return PyInt_FromLong(self->flags);\n}\n\n/* relies on setflags order being write, align, uic */\nstatic int\narrayflags_updateifcopy_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False));\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_aligned_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_writeable_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None, Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\n\nstatic PyGetSetDef arrayflags_getsets[] = {\n\t{\"contiguous\",\n\t (getter)arrayflags_contiguous_get,\n\t NULL,\n\t \"\"},\n {\"fortran\",\n (getter)arrayflags_fortran_get,\n NULL,\n \"\"},\n {\"updateifcopy\",\n (getter)arrayflags_updateifcopy_get,\n (setter)arrayflags_updateifcopy_set,\n \"\"},\n {\"owndata\",\n (getter)arrayflags_owndata_get,\n NULL,\n \"\"},\n {\"aligned\",\n (getter)arrayflags_aligned_get,\n (setter)arrayflags_aligned_set,\n \"\"},\n {\"writeable\",\n (getter)arrayflags_writeable_get,\n (setter)arrayflags_writeable_set,\n \"\"},\n {\"fnc\",\n (getter)arrayflags_fnc_get,\n NULL,\n \"\"},\n {\"forc\",\n (getter)arrayflags_forc_get,\n NULL,\n \"\"},\n {\"behaved\",\n (getter)arrayflags_behaved_get,\n NULL,\n \"\"},\n {\"carray\",\n (getter)arrayflags_carray_get,\n NULL,\n \"\"},\n {\"farray\",\n (getter)arrayflags_farray_get,\n NULL,\n \"\"},\n {\"num\",\n (getter)arrayflags_num_get,\n NULL,\n \"\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyObject *\narrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)\n{\n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n\tswitch(n) {\n\tcase 1:\n\t\tswitch(key[0]) {\n\t\tcase 'C':\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tcase 'F':\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tcase 'W':\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tcase 'B':\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tcase 'O':\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tcase 'A':\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tcase 'U':\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tdefault:\n\t\t\tgoto fail;\n\t\t}\n\t\tbreak;\n\tcase 2:\n\t\tif (strncmp(key, \"CA\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FA\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 3:\n\t\tif (strncmp(key, \"FNC\", n)==0)\n\t\t\treturn arrayflags_fnc_get(self);\n\t\tbreak;\n\tcase 4:\n\t\tif (strncmp(key, \"FORC\", n)==0)\n\t\t\treturn arrayflags_forc_get(self);\n\t\tbreak;\n\tcase 6:\n\t\tif (strncmp(key, \"CARRAY\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FARRAY\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 7:\n\t\tif (strncmp(key,\"FORTRAN\",n)==0)\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tif (strncmp(key,\"BEHAVED\",n)==0)\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tif (strncmp(key,\"OWNDATA\",n)==0)\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tif (strncmp(key,\"ALIGNED\",n)==0)\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tbreak;\n\tcase 9:\t\n\t\tif (strncmp(key,\"WRITEABLE\",n)==0)\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tbreak;\n\tcase 10:\n\t\tif (strncmp(key,\"CONTIGUOUS\",n)==0)\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tbreak;\n\tcase 12:\n\t\tif (strncmp(key, \"UPDATEIFCOPY\", n)==0)\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tbreak;\n\t}\n\n fail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return NULL;\n}\n\nstatic int\narrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)\n{ \n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n if (((n==9) && (strncmp(key, \"WRITEABLE\", n)==0)) ||\n\t ((n==1) && (strncmp(key, \"W\", n)==0)))\n return arrayflags_writeable_set(self, item);\n else if (((n==7) && (strncmp(key, \"ALIGNED\", n)==0)) || \n ((n==1) && (strncmp(key, \"A\", n)==0)))\n return arrayflags_aligned_set(self, item);\n else if (((n==12) && (strncmp(key, \"UPDATEIFCOPY\", n)==0)) ||\n ((n==1) && (strncmp(key, \"U\", n)==0)))\n return arrayflags_updateifcopy_set(self, item); \n\nfail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return -1;\n}\n\nstatic char *\n_torf_(int flags, int val)\n{\n if ((flags & val) == val) return \"True\";\n else return \"False\"; \n}\n\nstatic PyObject *\narrayflags_print(PyArrayFlagsObject *self)\n{\n int fl = self->flags;\n \n return PyString_FromFormat(\" %s : %s\\n %s : %s\\n %s : %s\\n\"\\\n \" %s : %s\\n %s : %s\\n %s : %s\",\n \"CONTIGUOUS\", _torf_(fl, CONTIGUOUS),\n \"FORTRAN\", _torf_(fl, FORTRAN),\n \"OWNDATA\", _torf_(fl, OWNDATA),\n \"WRITEABLE\", _torf_(fl, WRITEABLE),\n \"ALIGNED\", _torf_(fl, ALIGNED),\n \"UPDATEIFCOPY\", _torf_(fl, UPDATEIFCOPY));\n}\n\n\nstatic PyMappingMethods arrayflags_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)NULL, \t\t /*mp_length*/\n#else\n (inquiry)NULL, \t\t /*mp_length*/\n#endif\n (binaryfunc)arrayflags_getitem,\t /*mp_subscript*/\n (objobjargproc)arrayflags_setitem, /*mp_ass_subscript*/\n};\n\n\nstatic PyObject *\narrayflags_new(PyTypeObject *self, PyObject *args, PyObject *kwds)\n{\n PyObject *arg=NULL;\n if (!PyArg_UnpackTuple(args, \"flagsobj\", 0, 1, &arg))\n return NULL;\n\n if ((arg != NULL) && PyArray_Check(arg)) {\n return PyArray_NewFlagsObject(arg);\n }\n else {\n return PyArray_NewFlagsObject(NULL);\n }\n}\n\nstatic PyTypeObject PyArrayFlags_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\n \"numpy.flagsobj\",\n sizeof(PyArrayFlagsObject),\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayflags_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t0,\t\t /* tp_compare */\n (reprfunc)arrayflags_print, /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &arrayflags_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arrayflags_print, /* tp_str */\n 0,\t \t /* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t /* tp_iternext */\n 0,\t \t /* tp_methods */\n 0,\t /* tp_members */\n arrayflags_getsets, /* tp_getset */\n 0,\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t /* tp_init */\n 0,\t /* tp_alloc */\n arrayflags_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "source_code_before": "/*\n Provide multidimensional arrays as a basic object type in python.\n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004\n\nHeavily modified in 2005 with inspiration from Numarray\n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University\n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by\nSpace Science Telescope Institute\n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_)\n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear();\n priority = default_;\n }\n Py_XDECREF(ret);\n return priority;\n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a\n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n }\n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int\ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides,\n\t intp *src_dimensions, int src_nd, int elsize,\n\t int copies) {\n intp i, j;\n\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1,\n dest_dimensions+1, dest_nd-1,\n src, src_strides,\n src_dimensions, src_nd,\n elsize, copies) == -1)\n return -1;\n }\n return 0;\n }\n\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError,\n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) &&\n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] !=\n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src)\n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\n dest_strides_ptr = dest_strides;\n\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1)\n return NULL;\n\n new_data = (char *)_pya_malloc(stride);\n\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions,\n dest_nd, src->data, src_strides,\n src_dimensions, src_nd, elsize, copies);\n\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *,\n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int\nPyArray_INCREF(PyArrayObject *mp)\n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap)\n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n\n\n if ((numitems == 1) || (itemsize == srcstrides))\n memcpy(d1, s1, itemsize*numitems);\n else {\n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n }\n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG\n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i)\n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp\nPyArray_Size(PyObject *op)\n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n }\n\telse {\n return 0;\n }\n}\n\nstatic void\n_strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides, \n\t\t\t intp N, int elsize)\n{\n intp i, j;\n char *tout = dst;\n char *tin = src;\n\n#define _FAST_MOVE(_type_)\t\t\t\t \\\n\tfor (i=0; idescr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n\n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, dest);\n PyArray_INCREF(dest);\n return 0;\n }\n \n /* See if we can iterate over the largest dimension */\n if (!swap && (nd = dest->nd) == src->nd && (nd > 0) && \n PyArray_CompareLists(dest->dimensions, src->dimensions, nd)) { \n int maxaxis=0, maxdim=dest->dimensions[0];\n int i;\n for (i=1; idimensions[i] > maxdim) {\n maxaxis = i;\n maxdim = dest->dimensions[i];\n }\n }\n\n dit = (PyArrayIterObject *) \\\n PyArray_IterAllButAxis((PyObject *)dest, maxaxis);\n sit = (PyArrayIterObject *) \\\n PyArray_IterAllButAxis((PyObject *)src, maxaxis);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n index = dit->size;\n\t\tif (PyArray_ISALIGNED(dest) && PyArray_ISALIGNED(src)) {\n\t\t\twhile(index--) {\n\t\t\t\t/* strided copy of elsize bytes */\n\t\t\t\t_strided_byte_copy(dit->dataptr, \n\t\t\t\t\t\t dest->strides[maxaxis],\n\t\t\t\t\t\t sit->dataptr, \n\t\t\t\t\t\t src->strides[maxaxis],\n\t\t\t\t\t\t maxdim, elsize);\n\t\t\t\tPyArray_ITER_NEXT(dit);\n\t\t\t\tPyArray_ITER_NEXT(sit);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\twhile(index--) {\n\t\t\t\t/* strided copy of elsize bytes */\n\t\t\t\t_unaligned_strided_byte_copy(dit->dataptr, \n\t\t\t\t\t\t\t dest->strides[maxaxis],\n\t\t\t\t\t\t\t sit->dataptr, \n\t\t\t\t\t\t\t src->strides[maxaxis],\n\t\t\t\t\t\t\t maxdim, elsize);\n\t\t\t\tPyArray_ITER_NEXT(dit);\n\t\t\t\tPyArray_ITER_NEXT(sit);\n\t\t\t}\n\t\t}\t\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n return 0; \n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n\t\t\tmemmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, dest);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n }\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int\nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)\n{\n PyArrayObject *src;\n int ret;\n\t\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d,\n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t} \n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, PyArray_ORDER fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran == PyArray_ANYORDER) \n\t\tfortran = PyArray_ISFORTRAN(m1);\n \n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,\n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd,\n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran,\n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\n return (PyObject *)ret;\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif PyTypeNum_ISSTRING(type_num) { /* Eliminate NULL bytes */\n\t\tchar *dptr = data;\n\t\tdptr += itemsize-1;\n\t\twhile(itemsize && *dptr-- == 0) itemsize--;\n\t\tif (type_num == PyArray_UNICODE && itemsize) {\n\t\t\t/* make sure itemsize is a multiple of 4 */\n\t\t\t/* so round up to nearest multiple */\n\t\t\titemsize = (((itemsize-1) >> 2) + 1) << 2;\n\t\t}\n\t}\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) {\n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED;\n\t\t\tmemcpy(destptr, data, itemsize);\n\t\t\treturn obj;\n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=0;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use\n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE,length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifdef Py_UNICODE_WIDE\n\t\t\tmemcpy(destptr, data, itemsize);\n\t\t\tif (swap)\n\t\t\t\tbyte_swap_vector(destptr, length, 4);\n#else\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, \n\t\t\t\t\t\t\t itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, \n\t\t\t\t\t\t (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n#endif\n\t\t\treturn obj;\n\t\t}\n\t\telse {\n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, base);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this.\n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag\n*/\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp)\n{\n\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n\n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int\nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs,\n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/*\n copyies over from the old descr table for anything\n NULL or zero in what is given.\n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)\n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data,\n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError,\n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr,\n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element\"\\\n \" %d to file\",\n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj);\n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj),\n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\",\n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1) \n if (fwrite(sep, 1, n3, fp) < n3) {\n\t\t\t\t\tPyErr_Format(PyExc_IOError,\n\t\t\t\t\t\t \"problem writing \"\\\n\t\t\t\t\t\t \"separator to file\");\n\t\t\t\t\tPy_DECREF(strobj);\n\t\t\t\t\tPy_DECREF(it);\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self)\n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0)\n\t\treturn self->descr->f->getitem(self->data,self);\n\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n\n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void\narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an\n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE\n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n\n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\narray_length(PyArrayObject *self)\n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i)\n{\n\tchar *item;\n\tPyArrayObject *r;\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1,\n\t\t\t\t\t\t self->dimensions+1,\n\t\t\t\t\t\t self->strides+1, item,\n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\n/* contains optimization for 1-d arrays */\nstatic PyObject *\narray_item_nice(PyArrayObject *self, _int_or_ssize_t i)\n{\n\tif (self->nd == 1) {\n\t\tchar *item;\n if (i < 0) {\n\t\t\ti += self->dimensions[0];\n\t\t}\n\t\tif ((item = index2ptr(self, i)) == NULL) return NULL;\n\t\treturn PyArray_Scalar(item, self->descr, (PyObject *)self);\n\t}\n\telse {\n\t\treturn PyArray_Return((PyArrayObject *)\\\n\t\t\t\t array_big_item(self, (intp) i));\n\t}\n}\n\nstatic int\narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v)\n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret;\n }\n\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if PY_VERSION_HEX < 0x02050000\n #if SIZEOF_INT == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#else\n #if SIZEOF_SIZE_T == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#endif\n#ifndef array_ass_item\nstatic int\narray_ass_item(PyArrayObject *self, _int_or_ssize_t i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int\nparse_index(PyArrayObject *self, PyObject *op,\n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError,\n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\n nd_old = nd_new = 0;\n\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n PyArrayObject *arr;\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n /* arr might not have the right number of dimensions\n and need to be reshaped first by pre-pending ones */\n arr = *ret; \n if (arr->nd != mit->nd) {\n for (i=1; i<=arr->nd; i++) {\n permute.ptr[mit->nd-i] = arr->dimensions[arr->nd-i];\n }\n for (i=0; ind-arr->nd; i++) {\n permute.ptr[i] = 1;\n } \n new = PyArray_Newshape(arr, &permute, PyArray_ANYORDER);\n Py_DECREF(arr);\n *ret = (PyArrayObject *)new;\n if (new == NULL) return;\n }\n\n\t/* tuple for transpose is\n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of\n\t the broadcasted index array\n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the\n\t result\n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2)\n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call.\n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type,\n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret))\n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t\tif (arr == NULL) return -1;\n\t\t}\n\t}\n\t\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, arr);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS];\n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL)\n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0\n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from\n Python when using a[object] unless object is a standard slice object\n (not an extended one).\n\n*/\n\n/* There are two situations:\n\n 1 - the subscript is a standard view and a reference to the\n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned.\n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *);\n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op)\n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr,\n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis) {\n\t\t\t/* XXX: This leads to a small inconsistency\n\t\t\t XXX: with the nd>0 case where (x[...] is x)\n\t\t\t XXX: is false for nd>0 case. */\n\t\t\tPy_INCREF(self);\n\t\t\treturn (PyObject *)self;\n\t\t}\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op)) {\n\t\t\t\tPy_INCREF(self);\n\t\t\t\treturn (PyObject *)self;\n\t\t\t}\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset))\n == -1)\n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset,\n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL)\n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be\n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *);\n\nstatic int\narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)\n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr,\n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1;\n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to\n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op)\n{\n\t/* The following is just a copy of PyArray_Return with an\n\t additional logic in the nd == 0 case. More efficient\n\t implementation may be possible by refactoring\n\t array_subscript */\n\n\tPyArrayObject *mp;\n\n\t/* optimization for integer select and 1-d */\n\tif (self->nd == 1 && (PyInt_Check(op) || PyLong_Check(op))) {\n intp value;\n\t\tchar *item;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred()) \n\t\t\treturn NULL;\n else if (value < 0) {\n\t\t\tvalue += self->dimensions[0];\n\t\t}\n\t\tif ((item = index2ptr(self, value)) == NULL) return NULL;\n\t\treturn PyArray_Scalar(item, self->descr, (PyObject *)self);\n\t}\n\tmp = (PyArrayObject *)array_subscript(self, op);\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tBool noellipses = TRUE;\n\t\tif (op == Py_Ellipsis)\n\t\t\tnoellipses = FALSE;\n\t\telse if (PySequence_Check(op)) {\n\t\t\tint n, i;\n\t\t\tn = PySequence_Size(op);\n\t\t\tfor (i = 0; i < n; ++i) \n\t\t\t\tif (PySequence_GetItem(op, i) == Py_Ellipsis) {\n\t\t\t\t\tnoellipses = FALSE;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t\tif (noellipses) {\n\t\t\tPyObject *ret;\n\t\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\t\tPy_DECREF(mp);\n\t\t\treturn ret;\n\t\t}\n\t}\n\treturn (PyObject *)mp;\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t /*mp_length*/\n#else\n (inquiry)array_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic _int_or_ssize_t\narray_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp)\n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic _int_or_ssize_t\narray_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"accessing non-existing array segment\");\n return -1;\n }\n\n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic _int_or_ssize_t\narray_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (PyArray_CHKFLAGS(self, WRITEABLE))\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic _int_or_ssize_t\narray_getcharbuf(PyArrayObject *self, _int_or_ssize_t segment, const char **ptrptr)\n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError,\n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (writebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (segcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (charbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#else\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#endif\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n *square,\n *reciprocal,\n *ones_like,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum,\n\t\t*rint;\n} NumericOps;\n\nstatic NumericOps n_ops; /* NB: static objects inlitialized to zero */\n\n/* Dictionary can contain any of the numeric operations, by name.\n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n\n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint\nPyArray_SetNumericOps(PyObject *dict)\n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n SET(square);\n SET(reciprocal);\n SET(ones_like);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\n SET(true_divide);\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n\tSET(rint);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void)\n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL)\n\t\treturn NULL;\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n GET(square);\n GET(reciprocal);\n GET(ones_like);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide);\n GET(true_divide);\n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\tGET(rint);\n\treturn dict;\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,\n\t\t\t\t PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2)\n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic int\narray_power_is_scalar(PyObject *o2, double* exp)\n{\n PyObject *temp;\n const int optimize_fpexps = 1;\n\n if (PyInt_Check(o2)) {\n\t *exp = (double)PyInt_AsLong(o2);\n\t return 1;\n }\n if (optimize_fpexps && PyFloat_Check(o2)) {\n\t *exp = PyFloat_AsDouble(o2);\n\t return 1;\n }\n if ((PyArray_IsZeroDim(o2) && \n\t ((PyArray_ISINTEGER(o2) || \n\t (optimize_fpexps && PyArray_ISFLOAT(o2))))) || \n\tPyArray_IsScalar(o2, Integer) || \n\t(optimize_fpexps && PyArray_IsScalar(o2, Floating))) {\n\t temp = o2->ob_type->tp_as_number->nb_float(o2);\n\t if (temp != NULL) {\n\t\t *exp = PyFloat_AsDouble(o2);\n\t\t Py_DECREF(temp);\n\t\t return 1;\n\t }\n }\n return 0;\n}\n\n/* optimize float array or complex array to a scalar power */\nstatic PyObject *\nfast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) {\n\tdouble exp;\n\tif (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) || \n\t\t\t\t PyArray_ISCOMPLEX(a1))) {\n\t\tif (array_power_is_scalar(o2, &exp)) {\n\t\t\tPyObject *fastop = NULL;\n\t\t\tif (exp == 1.0) {\n\t\t\t\t/* we have to do this one special, as the \n\t\t\t\t \"copy\" method of array objects isn't set \n\t\t\t\t up early enough to be added\n\t\t\t\t by PyArray_SetNumericOps.\n\t\t\t\t*/\n\t\t\t\tif (inplace) {\n\t\t\t\t\treturn (PyObject *)a1;\n\t\t\t\t} else {\n\t\t\t\t\treturn PyArray_Copy(a1);\n\t\t\t\t}\n\t\t\t} else if (exp == -1.0) {\n\t\t\t\tfastop = n_ops.reciprocal;\n\t\t\t} else if (exp == 0.0) {\n\t\t\t\tfastop = n_ops.ones_like;\n\t\t\t} else if (exp == 0.5) {\n\t\t\t\tfastop = n_ops.sqrt;\n\t\t\t} else if (exp == 2.0) {\n\t\t\t\tfastop = n_ops.square;\n\t\t\t} else {\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tif (inplace) {\n\t\t\t\tPyArray_GenericInplaceUnaryFunction(a1, \n\t\t\t\t\t\t\t\t fastop);\n\t\t\t} else {\n\t\t\t\treturn PyArray_GenericUnaryFunction(a1, \n\t\t\t\t\t\t\t\t fastop);\n\t\t\t}\n\t\t}\n\t}\n\treturn NULL;\n}\n\nstatic PyObject *\narray_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n\t/* modulo is ignored! */\n\tPyObject *value;\n\tvalue = fast_scalar_power(a1, o2, 0);\n\tif (!value) {\n\t\tvalue = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);\n\t}\n\treturn value;\n}\n\n\nstatic PyObject *\narray_negative(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 1);\n if (!value) {\n value = PyArray_GenericInplaceBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int\narray_any_nonzero(PyArrayObject *mp)\n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2)\n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_float(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to a \"\\\n\t\t\t\t\"float; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_long(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/\n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected\n*/\n\n\nstatic PyObject *\narray_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t _int_or_ssize_t ihigh)\n{\n PyArrayObject *r;\n _int_or_ssize_t l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n self->dimensions[0] = l;\n\tif (r == NULL) return NULL;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS);\n return (PyObject *)r;\n}\n\n\nstatic int\narray_ass_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t\t_int_or_ssize_t ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res;\n int ret;\n\t\n res = PyArray_EnsureAnyArray(PyObject_RichCompare((PyObject *)self, \n\t\t\t\t\t\t\t el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\nstatic PySequenceMethods array_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (ssizeargfunc)NULL,\n\t(ssizeargfunc)array_item_nice,\n\t(ssizessizeargfunc)array_slice,\n (ssizeobjargproc)array_ass_item,\t /*sq_ass_item*/\n (ssizessizeobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(ssizeargfunc)NULL,\n#else\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t /*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n#endif\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int\ndump_data(char **string, int *n, int *max_n, char *data, int nd,\n intp *dimensions, intp *strides, PyArrayObject* self)\n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\n if (nd == 0) {\n\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata,\n\t\t self->nd, self->dimensions,\n self->strides, self) < 0) {\n\t\t_pya_free(string); return NULL;\n\t}\n\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void\nPyArray_SetStringFunction(PyObject *op, int repr)\n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_ReprFunction = op;\n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_StrFunction = op;\n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\n\n\n/*OBJECT_API\n */\nstatic int\nPyArray_CompareUCS4(PyArray_UCS4 *s1, PyArray_UCS4 *s2, register size_t len)\n{\n register PyArray_UCS4 c1, c2;\n while(len-- > 0) {\n c1 = *s1++;\n c2 = *s2++;\n if (c1 != c2) {\n return (c1 < c2) ? -1 : 1;\n\t\t}\n }\n\treturn 0;\n}\n\nstatic int\n_myunincmp(PyArray_UCS4 *s1, PyArray_UCS4 *s2, int len1, int len2)\n{\n\tPyArray_UCS4 *sptr;\n\tint val;\n\n\tval = PyArray_CompareUCS4(s1, s2, MIN(len1, len2));\n\tif ((val != 0) || (len1 == len2)) return val;\n\tif (len2 > len1) {sptr = s2+len1; val = -1;}\n\telse {sptr = s1+len2; val = 1;}\n\tif (*sptr != 0) return val;\n\n\tif (len2 > len1) {sptr = s2; val = -1;}\n\telse {sptr = s1; val = 1;}\n\tif (*sptr != 0) return val;\n\treturn 0;\n}\n\n\n\n/* Compare s1 and s2 which are not necessarily NULL-terminated. \n s1 is of length len1\n s2 is of length len2\n If they are NULL terminated, then stop comparison.\n*/\nstatic int\n_mystrncmp(char *s1, char *s2, int len1, int len2)\n{\n\tchar *sptr;\n\tint val;\n\n\tval = strncmp(s1, s2, MIN(len1, len2));\n\tif ((val != 0) || (len1 == len2)) return val;\n\tif (len2 > len1) {sptr = s2+len1; val = -1;}\n\telse {sptr = s1+len2; val = 1;}\n\tif (*sptr != 0) return val;\n\treturn 0;\n}\n\nstatic int\n_compare_strings(PyObject *result, PyArrayMultiIterObject *multi, \n\t\t int cmp_op, void *func)\n{\n\tPyArrayIterObject *iself, *iother;\n\tBool *dptr;\n\tintp size;\n\tint val;\n\tint N1, N2;\n\tint (*cmpfunc)(void *, void *, int, int);\n\t\n\tcmpfunc = func;\n\tdptr = (Bool *)PyArray_DATA(result);\n\tiself = multi->iters[0];\n\tiother = multi->iters[1];\n\tsize = multi->size;\n\tN1 = iself->ao->descr->elsize;\n\tN2 = iother->ao->descr->elsize;\n\tif ((void *)cmpfunc == (void *)_myunincmp) {\n\t\tN1 >>= 2;\n\t\tN2 >>= 2;\n\t}\n\twhile(size--) {\n\t\tval = cmpfunc((void *)iself->dataptr, (void *)iother->dataptr, \n\t\t\t N1, N2);\n\t\tswitch (cmp_op) {\n\t\tcase Py_EQ:\n\t\t\t*dptr = (val == 0);\n\t\t\tbreak;\n\t\tcase Py_NE:\n\t\t\t*dptr = (val != 0);\n\t\t\tbreak;\n\t\tcase Py_LT:\n\t\t\t*dptr = (val < 0);\n\t\t\tbreak;\n\t\tcase Py_LE:\n\t\t\t*dptr = (val <= 0);\n\t\t\tbreak;\n\t\tcase Py_GT:\n\t\t\t*dptr = (val > 0);\n\t\t\tbreak;\n\t\tcase Py_GE:\n\t\t\t*dptr = (val >= 0);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"bad comparison operator\");\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_NEXT(iself);\n\t\tPyArray_ITER_NEXT(iother);\n\t\tdptr += 1;\n\t}\n\treturn 0;\t\n}\n\nstatic PyObject *\n_strings_richcompare(PyArrayObject *self, PyArrayObject *other, int cmp_op)\n{\n PyObject *result;\n\tPyArrayMultiIterObject *mit;\n\tint val;\n\n /* Cast arrays to a common type */ \n if (self->descr->type != other->descr->type) {\n PyObject *new;\n if (self->descr->type_num == PyArray_STRING && \\\n other->descr->type_num == PyArray_UNICODE) {\n Py_INCREF(other);\n Py_INCREF(other->descr);\n new = PyArray_FromAny((PyObject *)self, other->descr, \n\t\t\t\t\t 0, 0, 0, NULL);\n if (new == NULL) return NULL;\n self = (PyArrayObject *)new;\n }\n else if (self->descr->type_num == PyArray_UNICODE &&\t\\\n other->descr->type_num == PyArray_STRING) {\n Py_INCREF(self);\n Py_INCREF(self->descr);\n new = PyArray_FromAny((PyObject *)other, self->descr, \n\t\t\t\t\t 0, 0, 0, NULL);\n if (new == NULL) return NULL;\n other = (PyArrayObject *)new;\n }\n else {\n PyErr_SetString(PyExc_TypeError, \n \"invalid string data-types \"\n \"in comparison\");\n return NULL;\n }\n }\n else { \n Py_INCREF(self);\n Py_INCREF(other);\n }\n\n /* Broad-cast the arrays to a common shape */\n mit = (PyArrayMultiIterObject *)PyArray_MultiIterNew(2, self, other);\n\tPy_DECREF(self);\n\tPy_DECREF(other);\n if (mit == NULL) return NULL;\n\t\n\tresult = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t PyArray_DescrFromType(PyArray_BOOL),\n\t\t\t\t mit->nd,\n\t\t\t\t mit->dimensions,\n\t\t\t\t NULL, NULL, 0, \n\t\t\t\t NULL);\n\tif (result == NULL) goto finish;\n\n\tif (self->descr->type_num == PyArray_STRING) {\n\t\tval = _compare_strings(result, mit, cmp_op, _mystrncmp);\n\t}\n\telse {\n\t\tval = _compare_strings(result, mit, cmp_op, _myunincmp);\n\t}\n\t\n\tif (val < 0) {Py_DECREF(result); result = NULL;}\n\t\n finish: \n\tPy_DECREF(mit);\n return result;\n}\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)\n{\n PyObject *array_other, *result = NULL;\n\tint typenum;\n\n switch (cmp_op)\n {\n case Py_LT:\n result = PyArray_GenericBinaryFunction(self, other,\n n_ops.less);\n break;\n case Py_LE:\n result = PyArray_GenericBinaryFunction(self, other,\n n_ops.less_equal);\n break;\n case Py_EQ:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then return False\n\t\t\t\t This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of False\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the\n\t\t\t two array objects can not be compared together so\n\t\t\t return zero\n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n break;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be\n\t\t\t\t compared and cannot be equal, therefore,\n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n break;\n case Py_GT:\n result = PyArray_GenericBinaryFunction(self, other,\n n_ops.greater);\n break;\n case Py_GE:\n result = PyArray_GenericBinaryFunction(self, other,\n n_ops.greater_equal);\n break;\n default:\n result = Py_NotImplemented;\n Py_INCREF(result);\n }\n if (result == Py_NotImplemented) {\n /* Try to handle string comparisons */\n if (self->descr->type_num == PyArray_OBJECT) return result;\n array_other = PyArray_FromObject(other,PyArray_NOTYPE, 0, 0);\n if (PyArray_ISSTRING(self) && PyArray_ISSTRING(array_other)) {\n result = _strings_richcompare(self, (PyArrayObject *)\n\t\t\t\t\t\t array_other, cmp_op);\n }\n Py_DECREF(array_other);\n }\n return result;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\tif (temp) *axis = PyArray_NDIM(temp)-1;\n\t\telse *axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL,\n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int\n_IsFortranContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap)\n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object\n\t If it is a writeable array, then return TRUE\n\t If we can find an array object\n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable\n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA))\n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly\n\t and unpickled array can be set and reset writeable\n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t\telse ret->flags &= ~WRITEABLE;\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not\n ever be able to walk outside of the memory implied numbytes and offset.\n\n The available memory is assumed to start at -offset and proceed\n to numbytes-offset. The strides are checked to ensure\n that accessing memory using striding will not try to reach beyond\n this memory for any of the axes.\n\n If numbytes is 0 it will be calculated using the dimensions and\n element-size.\n\n This function checks for walking beyond the beginning and right-end\n of the buffer and therefore works for any integer stride (positive\n or negative).\n*/\n\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\tintp byte_begin;\n\tintp begin;\n\tintp end;\n\n\tif (numbytes == 0)\n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\n\tbegin = -offset;\n\tend = numbytes - offset - elsize;\n\tfor (i=0; i end))\n\t\t\treturn FALSE;\n\t}\n\treturn TRUE;\n\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings\n depending on data and strides:\n\n If data is given, then flags is flags associated with data.\n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument\n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set).\n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired.\n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize,\n\t\t int inflag, int *objflags)\n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\n/* and update the dimensions and strides\n appropriately. Dimensions and strides are added\n to the end unless we have a FORTRAN array\n and then they are added to the beginning\n\n Strides are only added if given (because data is given).\n*/\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,\n\t\t\t intp *newstrides, int oldnd, int isfortran)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\tint tuple;\n\n\told = *des;\n\t*des = old->subarray->base;\n\n\n\tmydim = newdims + oldnd;\n\ttuple = PyTuple_Check(old->subarray->shape);\n\tif (tuple) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t}\n\telse {\n\t\tnumnew = 1;\n\t}\n\n\n\tnewnd = oldnd + numnew;\n\tif (newnd > MAX_DIMS) goto finish;\n\tif (isfortran) {\n\t\tmemmove(newdims+numnew, newdims, oldnd*sizeof(intp));\n\t\tmydim = newdims;\n\t}\n\n\tif (tuple) {\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\tif (isfortran) {\n\t\t\tmemmove(newstrides+numnew, newstrides,\n\t\t\t\toldnd*sizeof(intp));\n\t\t\tmystrides = newstrides;\n\t\t}\n\t\t/* Make new strides -- alwasy C-contiguous */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\n finish:\n\tPy_INCREF(*des);\n\tPy_DECREF(old);\n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,\n\t\t intp *dims, intp *strides, void *data,\n\t\t int flags, PyObject *obj)\n{\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tint isfortran=0;\n\t\tisfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || \\\n\t\t\t(!data && flags);\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims,\n\t\t\t\t\t\t newstrides, nd, isfortran);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims,\n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { \n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN;\n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse { /* we allow strides even when we create\n\t\t\t the memory, but be careful with this...\n\t\t */\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n\telse { self->dimensions = self->strides = NULL; }\n\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays\n\t\t e.g. shape=(0,) -- otherwise buffer exposure\n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in,\n\t\t\t\t\t this object won't own it\n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for\n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype.\n\t If obj is NULL, then call method with Py_None \n\t*/\n\tif ((subtype != &PyArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (strides != NULL) { /* did not allocate own data \n\t\t\t\t\t or funny strides */\n\t\t\t/* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tif (obj == NULL) obj=Py_None;\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n If refcheck is 0, then the reference count is not checked\n and assumed to be 1.\n You still must own this data and have no weak-references and no base\n object.\n*/\nstatic PyObject *\nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck,\n\t PyArray_ORDER fortran)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\n if (!PyArray_ISONESEGMENT(self)) {\n PyErr_SetString(PyExc_ValueError,\n \"resize only works on single-segment arrays\");\n return NULL;\n }\n\n\tif (fortran == PyArray_ANYORDER)\n\t\tfortran = PyArray_CORDER;\n \n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n\n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (refcheck) refcnt = REFCOUNT(self);\n\t\telse refcnt = 1;\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (newsize == 0) sd = self->descr->elsize;\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n\n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) {\n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0,\n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n\n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n\n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n self->flags, &(self->flags));\n\n\n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\n return Py_None;\n\n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\tPyArray_FillWithScalarFunc* fillwithscalar =\n\t\t\tarr->descr->f->fillwithscalar;\n\t\tif (fillwithscalar && PyArray_ISALIGNED(arr)) {\n\t\t\tcopyswap(fromptr, NULL, swap, arr);\n\t\t\tfillwithscalar(toptr, size, fromptr, arr);\n\t\t}\n\t\telse {\n\t\t\twhile (size--) {\n\t\t\t\tcopyswap(toptr, fromptr, swap, arr);\n\t\t\t\ttoptr += itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, arr);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"order\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n PyArray_ORDER order=PyArray_CORDER;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL;\n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous\n\t array of a specific type and shape.\n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims,\n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter,\n &strides,\n &PyArray_OrderConverter,\n &order))\n\t\tgoto fail;\n\n if (order == PyArray_FORTRANORDER) fortran = 1;\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"data-type with unspecified variable length\");\n\t\tgoto fail;\n\t}\n\t\n\tif (strides.ptr != NULL) {\n\t\tintp nb, off;\n\t\tif (strides.len != dims.len) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides, if given, must be \"\t\\\n\t\t\t\t\t\"the same length as shape\");\n\t\t\tgoto fail;\n\t\t}\n\n\t\tif (buffer.ptr == NULL) {\n\t\t\tnb = 0;\n\t\t\toff = 0;\n\t\t}\n\t\telse {\n\t\t\tnb = buffer.len;\n\t\t\toff = offset;\n\t\t}\n\t\t\n\n\t\tif (!PyArray_CheckStrides(itemsize, dims.len, \n\t\t\t\t\t nb, off,\n\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides is incompatible \"\t\\\n\t\t\t\t\t\"with shape of requested \"\t\\\n\t\t\t\t\t\"array and size of buffer\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\t\t\t\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len,\n\t\t\t\t\t dims.ptr,\n\t\t\t\t\t strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = (buffer.len-offset) / itemsize;\n }\n else if ((strides.ptr == NULL) && \\\n\t\t\t buffer.len < itemsize*\t\t\t\t\\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError,\n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t offset + (char *)buffer.ptr,\n\t\t\t\t\t buffer.flags, NULL);\n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base);\n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyArray_NewFlagsObject((PyObject *)self);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n\tint nd;\n\tPyObject *ret;\n\n /* Assumes C-order */\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n if (PyArray_DATA(ret) != PyArray_DATA(self)) {\n Py_DECREF(ret);\n PyErr_SetString(PyExc_AttributeError, \n \"incompatible shape for a non-contiguous array\");\n return -1;\n }\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret),\n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret),\n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes=0;\n\tintp offset=0;\n\tint buf_len;\n\tchar *buf;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base && PyArray_Check(new->base)) {\n\t\tnew = (PyArrayObject *)(new->base);\n\t}\n\t/* Get the available memory through the buffer\n\t interface on new->base or if that fails\n\t from the current new */\n\tif (new->base && PyObject_AsReadBuffer(new->base,\n\t\t\t\t\t (const void **)&buf,\n\t\t\t\t\t &buf_len) >= 0) {\n\t\toffset = self->data - buf;\n\t\tnumbytes = buf_len + offset;\n\t}\n\telse {\n\t\tPyErr_Clear();\n \t\tnumbytes = PyArray_MultiplyList(new->dimensions,\n\t\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\toffset = self->data - new->data;\n\t}\n\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes,\n\t\t\t\t offset,\n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self))\n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self)\n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0,\n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf,\n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse\n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse\n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed.\n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the\n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0)\n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n\telse if (newtype->elsize > self->descr->elsize) {\n\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update\n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\t/* We would decref newtype here --- temp will\n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tif (temp == NULL) return -1;\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\tPy_INCREF(temp->descr);\n\t\t/* Fool deallocator not to delete these*/\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype;\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA);\n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, \n\t\t\t\t\t\t (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num -\n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type,\n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new);\n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int\narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode,\n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr));\n memmove(selfit->dataptr, arrit->dataptr,\n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size)\n PyArray_ITER_RESET(arrit);\n }\n retval = 0;\n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size)\n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\",\n\t (getter)array_ndim_get,\n\t NULL,\n\t \"number of array dimensions\"},\n {\"flags\",\n\t (getter)array_flags_get,\n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\",\n\t (getter)array_shape_get,\n\t (setter)array_shape_set,\n\t \"tuple of array dimensions\"},\n {\"strides\",\n\t (getter)array_strides_get,\n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)array_data_get,\n\t (setter)array_data_set,\n\t \"pointer to start of data\"},\n {\"itemsize\",\n\t (getter)array_itemsize_get,\n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\",\n\t (getter)array_real_get,\n\t (setter)array_real_set,\n\t \"real part of array\"},\n {\"imag\",\n\t (getter)array_imag_get,\n\t (setter)array_imag_set,\n\t \"imaginary part of array\"},\n\t{\"flat\",\n\t (getter)array_flat_get,\n\t (setter)array_flat_set,\n\t \"a 1-d view of a contiguous array\"},\n\t{\"__array_data__\",\n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\",\n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n\t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */\n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] =\n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\nstatic PyTypeObject PyArray_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0,\t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n &array_as_sequence,\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str,\t /*tp_str*/\n\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n &array_as_buffer, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT\n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter,\t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n array_alloc,\t /* tp_alloc */\n (newfunc)array_new,\t\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int\ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple)\n{\n int d=0;\n PyObject *e;\n\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0)\n\t\treturn 1;\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize)\n{\n\tint n, r, i;\n\tPyObject *e;\n\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s)\n\t\t\t*itemsize = MAX(*itemsize, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype ---\n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately\n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE &&\n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\nstatic PyArray_Descr *\n_array_find_python_scalar_type(PyObject *op)\n{\n if (PyFloat_Check(op)) {\n return PyArray_DescrFromType(PyArray_DOUBLE);\n } else if (PyComplex_Check(op)) {\n return PyArray_DescrFromType(PyArray_CDOUBLE);\n } else if (PyInt_Check(op)) {\n /* bools are a subclass of int */\n if (PyBool_Check(op)) {\n return PyArray_DescrFromType(PyArray_BOOL);\n } else {\n return PyArray_DescrFromType(PyArray_LONG);\n }\n } else if (PyLong_Check(op)) {\n /* if integer can fit into a longlong then return that\n */\n if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n PyErr_Clear();\n return PyArray_DescrFromType(PyArray_OBJECT);\n }\n return PyArray_DescrFromType(PyArray_LONGLONG);\n }\n return NULL;\n}\n\n/* op is an object to be converted to an ndarray.\n\n minitype is the minimum type-descriptor needed.\n\n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n\n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\n\tif (minitype == NULL)\n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\n if (max < 0) goto deflt;\n\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n chktype = _array_find_python_scalar_type(op);\n if (chktype) {\n goto finish;\n }\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n\n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind,\n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n }\n\n\tif (PyInstance_Check(op)) goto deflt;\n\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\n finish:\n\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype;\n}\n\nstatic int\nAssign_Array(PyArrayObject *self, PyObject *v)\n{\n PyObject *e;\n int l, r;\n\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\n l=PyObject_Length(v);\n if(l < 0) return -1;\n\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1;\n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */\n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode)\n{\n PyArrayObject *ret;\n\tint itemsize;\n\tint type;\n\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= 4;\n\n\t\tif (itemsize != typecode->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(typecode);\n\t\t\ttypecode->elsize = itemsize;\n\t\t}\n\t}\n\n ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL,\n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\tif (ret == NULL) return NULL;\n\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode */\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string,\n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid input sequence\");\n\t\tgoto fail;\n }\n\n\tif (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {\n\t\tnd = max_depth;\n\t}\n\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid number of dimensions\");\n\t\tgoto fail;\n }\n\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\n if(!r) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int\nPyArray_ValidType(int type)\n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in))\n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, in);\n\t\t\tbptr += elsize;\n\t\t\tPyArray_ITER_NEXT(it_in);\n\t\t\tel += 1;\n\t\t\tif ((el == nels) || (index == 0)) {\n\t\t\t\t/* buffer filled, do cast */\n\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n out);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject *\nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING)\n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd,\n\t\t\t\t mp->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\n}\n\n/* The number of elements in out must be an integer multiple\n of the number of elements in mp.\n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1;\n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * mpsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr,\n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)\n{\n\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1)\n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse {\n if ((flags & ENSUREARRAY)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype,\n\t\t\t\t\t\t newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr;\n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\n\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong))\n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char))\n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long))\n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap)\n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n\n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL;\n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n\n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data,\n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr));\n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n\n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context)\n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, \n\t\t\t\t\t\t\t\t NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None,\n\t\t\t\t\t\t context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", \n\t\t\t\t\t\t typecode, context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", \n\t\t\t\t\t\t\t typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError,\n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n}\n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,\n int max_depth, int flags, PyObject *context)\n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op))\n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tif (flags & UPDATEIFCOPY) goto err;\n\t\tr = PyArray_FromScalar(op, newtype);\n\t} else if (newtype == NULL &&\n (newtype = _array_find_python_scalar_type(op))) {\n\t if (flags & UPDATEIFCOPY) goto err;\n r = Array_FromScalar(op, newtype);\n }\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, \n\t\t\t\t\t\tflags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (flags & UPDATEIFCOPY) goto err;\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\n\t/* Be sure we succeed here */\n\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n\n err:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"UPDATEIFCOPY used for non-array input.\");\n\treturn NULL;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int\nPyArray_ObjectType(PyObject *op, int minimum_type)\n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of\n CONTIGUOUS,\n FORTRAN,\n ALIGNED,\n WRITEABLE,\n NOTSWAPPED,\n ENSURECOPY,\n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should\n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or\n not it has such features.\n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well.\n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n\n FORTRAN can be set in the FLAGS to request a FORTRAN array.\n Fortran arrays are always behaved (aligned,\n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d).\n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array.\n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe.\n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,\n int max_depth, int requires, PyObject *context)\n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0,\n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place\n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op)) return op;\n\t\n\tif (PyArray_Check(op)) \n\t\treturn PyArray_View((PyArrayObject *)op, NULL, &PyArray_Type);\n\t\n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureAnyArray(PyObject *op)\n{\n\tif (op && PyArray_Check(op)) return op;\n\treturn PyArray_EnsureArray(op);\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int\nPyArray_CanCastSafely(int fromtype, int totype)\n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype))\n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode\n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\n\t\t*/\n\t}\n\treturn ret;\n}\n\n/*OBJECT_API\n See if array scalars can be cast.\n */\nstatic Bool\nPyArray_CanCastScalar(PyTypeObject *from, PyTypeObject *to)\n{\n\tint fromtype;\n\tint totype;\n\n\tfromtype = _typenum_fromtypeobj((PyObject *)from, 0);\n\ttotype = _typenum_fromtypeobj((PyObject *)to, 0);\n\tif (fromtype == PyArray_NOTYPE || totype == PyArray_NOTYPE) \n\t\treturn FALSE;\n\treturn (Bool) PyArray_CanCastSafely(fromtype, totype);\t\n}\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd;\n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D)\n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n\n/* don't use with PyArray_ITER_GOTO1D because factors are not\n adjusted */\n\n/*OBJECT_API\n Adjusts previously broadcasted iterators so that the largest axis is not iterated \n over. Returns dimension which is largest in the range [0,multi->nd). A -1 \n is returned if multi->nd == 0.\n */\nstatic int\nPyArray_RemoveLargest(PyArrayMultiIterObject *multi)\n{\n\tPyArrayIterObject *it;\n\tint i;\n\tint axis=0;\n\tintp longest;\n\n\tif (multi->nd == 0) return -1;\n\t\n\tlongest = multi->dimensions[0];\n\t/* Find longest dimension */\n\tfor (i=1; ind; i++) {\n\t\tif (multi->dimensions[i] > longest) {\n\t\t\taxis = i;\n\t\t\tlongest = multi->dimensions[i];\n\t\t}\n\t}\n\t\n\tfor (i=0; inumiter; i++) {\n\t\tit = multi->iters[i];\n\t\tit->contiguous = 0;\n\t\tif (it->size != 0)\n\t\t\tit->size /= (it->dims_m1[axis]+1);\n\t\tit->dims_m1[axis] = 0;\n\t\tit->backstrides[axis] = 0;\t\t\n\t}\n\n\treturn axis;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic _int_or_ssize_t\niter_length(PyArrayIterObject *self)\n{\n return self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, self->ao);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr,\n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, r);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1)\n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t 1, &n_steps,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail;\n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, r);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0,\n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap, self->ao);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size)\n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, self->ao);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, self->ao);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size)\n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)\n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, arrval);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, arrval);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, arrval);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size)\n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0,\n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)iter_length,\t\t /*mp_length*/\n#else\n (inquiry)iter_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op)\n{\n\n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options:\n 1) underlying array is contiguous\n -- return 1-d wrapper around it\n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, it->ao->data,\n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r);\n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n\n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\",\n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &iter_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t\t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular\n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators\n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++)\n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already\n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1)\n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"shape mismatch: objects\" \\\n\t\t\t\t\t\t\t\" cannot be broadcast\" \\\n\t\t\t\t\t\t\t\" to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t it->ao);\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tif (it->size != 0) {\n\t\t\t\tPyArray_ITER_RESET(it);\n\t\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t it->ao);\n\t\t\t}\n\t\t\telse coord[i] = 0;\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of\n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord,\n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t it->ao);\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t it->ao);\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so,\n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size.\n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere.\n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well.\n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0\n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t/* But, be sure to do it with a true array.\n\t */\n\tif (PyArray_CheckExact(arr)) {\n\t\tsub = array_subscript(arr, mit->indexobj);\n\t}\n\telse {\n\t\tPy_INCREF(arr);\n\t\tobj = PyArray_EnsureArray((PyObject *)arr);\n\t\tif (obj == NULL) goto fail;\n\t\tsub = array_subscript((PyArrayObject *)obj, mit->indexobj);\n\t\tPy_DECREF(obj);\n\t}\n\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects\n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been\n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj))\n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj,\n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1;\n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n intp indval;\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n indval = *indptr;\n\t\t\tif (indval < 0) indval += dimsize;\n\t\t\tif (indval < 0 || indval >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) indval, (int) (dimsize-1),\n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0,\n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n\tmit->index = 0;\n\tmit->ait = NULL;\n\tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY\n#undef SOBJ_ISFANCY\n#undef SOBJ_BADARRAY\n#undef SOBJ_TOOMANY\n#undef SOBJ_LISTTUP\n\n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple\n\t (with at least 1 list or arrayobject or Bool object), */\n\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i,\n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing\n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n\n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work.\n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a);\n mapiter is equivalent to a[indexobj].flat but the latter gets to use\n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t\t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t\t /* tp_iter */\n (iternextfunc)0,\t /* tp_iternext */\n 0,\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\n\tint i, err=0;\n\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\n /* fprintf(stderr, \"multi new...\");*/\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\n\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL)\n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i,\n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(multi->iters[i]);\n\tmulti->ob_type->tp_free((PyObject *)multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\",\n\t (getter)arraymultiter_size_get,\n\t NULL,\n\t \"total size of broadcasted result\"},\n {\"index\",\n\t (getter)arraymultiter_index_get,\n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter),\n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t\t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods,\t /* tp_methods */\n arraymultiter_members,\t\t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types.\n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these\n builtins will be attempted leading to problems.\n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically\n allocated).\n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless\n there is a reference-count problem\n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set.\n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base,\n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0)\n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\",\n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self)\n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\",\n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr)\n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr)\n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv))\n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\n\t/* Now return the state which is at least\n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize\n and alignment for EXTENDED arrays\n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\n\tif (endian != '|' && \n\t PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are:\n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n *** Leaves reference count of self unchanged --- does not DECREF self ***\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args)\n{\n\tchar endian=PyArray_SWAP;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS,\n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n\tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\ndescr_length(PyArray_Descr *self)\n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op)\n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError,\n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)descr_length,\t\t /*mp_length*/\n#else\n (inquiry)descr_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t\t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &descr_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t/* tp_iternext */\n arraydescr_methods,\t\t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n\n/** Array Flags Object **/\n\ntypedef struct PyArrayFlagsObject {\n PyObject_HEAD\n PyObject *arr;\n int flags;\n} PyArrayFlagsObject;\n\n/*OBJECT_API\n Get New ArrayFlagsObject\n*/\nstatic PyObject *\nPyArray_NewFlagsObject(PyObject *obj)\n{\n PyObject *flagobj;\n int flags;\n if (obj == NULL) {\n flags = CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n }\n else {\n flags = PyArray_FLAGS(obj);\n }\n flagobj = PyArrayFlags_Type.tp_alloc(&PyArrayFlags_Type, 0);\n if (flagobj == NULL) return NULL;\n Py_XINCREF(obj);\n ((PyArrayFlagsObject *)flagobj)->arr = obj;\n ((PyArrayFlagsObject *)flagobj)->flags = flags;\n\n return flagobj;\n}\n\nstatic void\narrayflags_dealloc(PyArrayFlagsObject *self)\n{\n\tPy_XDECREF(self->arr);\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n\n#define _define_get(UPPER, lower) \\\nstatic PyObject * \\\narrayflags_ ## lower ## _get(PyArrayFlagsObject *self) \\\n{ \\\n PyObject *item; \\\n item = ((self->flags & (UPPER)) == (UPPER)) ? Py_True : Py_False; \\\n Py_INCREF(item); \\\n return item; \\\n}\n\n_define_get(CONTIGUOUS, contiguous)\n_define_get(FORTRAN, fortran)\n_define_get(UPDATEIFCOPY, updateifcopy)\n_define_get(OWNDATA, owndata)\n_define_get(ALIGNED, aligned)\n_define_get(WRITEABLE, writeable)\n\n_define_get(ALIGNED|WRITEABLE, behaved)\n_define_get(ALIGNED|WRITEABLE|CONTIGUOUS, carray)\n\nstatic PyObject *\narrayflags_forc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) ||\n ((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_fnc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_farray_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & (ALIGNED|WRITEABLE|FORTRAN)) == \\\n (ALIGNED|WRITEABLE|FORTRAN)) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_num_get(PyArrayFlagsObject *self)\n{\n return PyInt_FromLong(self->flags);\n}\n\n/* relies on setflags order being write, align, uic */\nstatic int\narrayflags_updateifcopy_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False));\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_aligned_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_writeable_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None, Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\n\nstatic PyGetSetDef arrayflags_getsets[] = {\n\t{\"contiguous\",\n\t (getter)arrayflags_contiguous_get,\n\t NULL,\n\t \"\"},\n {\"fortran\",\n (getter)arrayflags_fortran_get,\n NULL,\n \"\"},\n {\"updateifcopy\",\n (getter)arrayflags_updateifcopy_get,\n (setter)arrayflags_updateifcopy_set,\n \"\"},\n {\"owndata\",\n (getter)arrayflags_owndata_get,\n NULL,\n \"\"},\n {\"aligned\",\n (getter)arrayflags_aligned_get,\n (setter)arrayflags_aligned_set,\n \"\"},\n {\"writeable\",\n (getter)arrayflags_writeable_get,\n (setter)arrayflags_writeable_set,\n \"\"},\n {\"fnc\",\n (getter)arrayflags_fnc_get,\n NULL,\n \"\"},\n {\"forc\",\n (getter)arrayflags_forc_get,\n NULL,\n \"\"},\n {\"behaved\",\n (getter)arrayflags_behaved_get,\n NULL,\n \"\"},\n {\"carray\",\n (getter)arrayflags_carray_get,\n NULL,\n \"\"},\n {\"farray\",\n (getter)arrayflags_farray_get,\n NULL,\n \"\"},\n {\"num\",\n (getter)arrayflags_num_get,\n NULL,\n \"\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyObject *\narrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)\n{\n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n\tswitch(n) {\n\tcase 1:\n\t\tswitch(key[0]) {\n\t\tcase 'C':\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tcase 'F':\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tcase 'W':\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tcase 'B':\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tcase 'O':\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tcase 'A':\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tcase 'U':\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tdefault:\n\t\t\tgoto fail;\n\t\t}\n\t\tbreak;\n\tcase 2:\n\t\tif (strncmp(key, \"CA\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FA\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 3:\n\t\tif (strncmp(key, \"FNC\", n)==0)\n\t\t\treturn arrayflags_fnc_get(self);\n\t\tbreak;\n\tcase 4:\n\t\tif (strncmp(key, \"FORC\", n)==0)\n\t\t\treturn arrayflags_forc_get(self);\n\t\tbreak;\n\tcase 6:\n\t\tif (strncmp(key, \"CARRAY\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FARRAY\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 7:\n\t\tif (strncmp(key,\"FORTRAN\",n)==0)\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tif (strncmp(key,\"BEHAVED\",n)==0)\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tif (strncmp(key,\"OWNDATA\",n)==0)\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tif (strncmp(key,\"ALIGNED\",n)==0)\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tbreak;\n\tcase 9:\t\n\t\tif (strncmp(key,\"WRITEABLE\",n)==0)\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tbreak;\n\tcase 10:\n\t\tif (strncmp(key,\"CONTIGUOUS\",n)==0)\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tbreak;\n\tcase 12:\n\t\tif (strncmp(key, \"UPDATEIFCOPY\", n)==0)\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tbreak;\n\t}\n\n fail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return NULL;\n}\n\nstatic int\narrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)\n{ \n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n if (((n==9) && (strncmp(key, \"WRITEABLE\", n)==0)) ||\n\t ((n==1) && (strncmp(key, \"W\", n)==0)))\n return arrayflags_writeable_set(self, item);\n else if (((n==7) && (strncmp(key, \"ALIGNED\", n)==0)) || \n ((n==1) && (strncmp(key, \"A\", n)==0)))\n return arrayflags_aligned_set(self, item);\n else if (((n==12) && (strncmp(key, \"UPDATEIFCOPY\", n)==0)) ||\n ((n==1) && (strncmp(key, \"U\", n)==0)))\n return arrayflags_updateifcopy_set(self, item); \n\nfail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return -1;\n}\n\nstatic char *\n_torf_(int flags, int val)\n{\n if ((flags & val) == val) return \"True\";\n else return \"False\"; \n}\n\nstatic PyObject *\narrayflags_print(PyArrayFlagsObject *self)\n{\n int fl = self->flags;\n \n return PyString_FromFormat(\" %s : %s\\n %s : %s\\n %s : %s\\n\"\\\n \" %s : %s\\n %s : %s\\n %s : %s\",\n \"CONTIGUOUS\", _torf_(fl, CONTIGUOUS),\n \"FORTRAN\", _torf_(fl, FORTRAN),\n \"OWNDATA\", _torf_(fl, OWNDATA),\n \"WRITEABLE\", _torf_(fl, WRITEABLE),\n \"ALIGNED\", _torf_(fl, ALIGNED),\n \"UPDATEIFCOPY\", _torf_(fl, UPDATEIFCOPY));\n}\n\n\nstatic PyMappingMethods arrayflags_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)NULL, \t\t /*mp_length*/\n#else\n (inquiry)NULL, \t\t /*mp_length*/\n#endif\n (binaryfunc)arrayflags_getitem,\t /*mp_subscript*/\n (objobjargproc)arrayflags_setitem, /*mp_ass_subscript*/\n};\n\n\nstatic PyObject *\narrayflags_new(PyTypeObject *self, PyObject *args, PyObject *kwds)\n{\n PyObject *arg=NULL;\n if (!PyArg_UnpackTuple(args, \"flagsobj\", 0, 1, &arg))\n return NULL;\n\n if ((arg != NULL) && PyArray_Check(arg)) {\n return PyArray_NewFlagsObject(arg);\n }\n else {\n return PyArray_NewFlagsObject(NULL);\n }\n}\n\nstatic PyTypeObject PyArrayFlags_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\n \"numpy.flagsobj\",\n sizeof(PyArrayFlagsObject),\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayflags_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t0,\t\t /* tp_compare */\n (reprfunc)arrayflags_print, /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &arrayflags_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arrayflags_print, /* tp_str */\n 0,\t \t /* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t /* tp_iternext */\n 0,\t \t /* tp_methods */\n 0,\t /* tp_members */\n arrayflags_getsets, /* tp_getset */\n 0,\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t /* tp_init */\n 0,\t /* tp_alloc */\n arrayflags_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "methods": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 76, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 65, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 99, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 134, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 207, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 241, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 291, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 319, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 344, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 387, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 427, + "end_line": 509, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 516, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 593, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Size", + "long_name": "PyArray_Size( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 33, + "parameters": [ + "op" + ], + "start_line": 614, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "_strided_byte_copy", + "long_name": "_strided_byte_copy( char * dst , intp outstrides , char * src , intp instrides , intp N , int elsize)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 9, + "token_count": 207, + "parameters": [ + "dst", + "outstrides", + "src", + "instrides", + "N", + "elsize" + ], + "start_line": 625, + "end_line": 667, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "_unaligned_strided_byte_copy", + "long_name": "_unaligned_strided_byte_copy( char * dst , intp outstrides , char * src , intp instrides , intp N , int elsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 92, + "parameters": [ + "dst", + "outstrides", + "src", + "instrides", + "N", + "elsize" + ], + "start_line": 671, + "end_line": 701, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 119, + "complexity": 27, + "token_count": 737, + "parameters": [ + "dest", + "src" + ], + "start_line": 718, + "end_line": 853, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyObject", + "long_name": "PyArray_CopyObject( PyArrayObject * dest , PyObject * src_object)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 857, + "end_line": 871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDimsAndDataAndDescr", + "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 137, + "parameters": [ + "nd", + "d", + "descr", + "data" + ], + "start_line": 884, + "end_line": 910, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDims", + "long_name": "PyArray_FromDims( int nd , int * d , int type)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "nd", + "d", + "type" + ], + "start_line": 916, + "end_line": 930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewCopy", + "long_name": "PyArray_NewCopy( PyArrayObject * m1 , PyArray_ORDER fortran)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 939, + "end_line": 960, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 118, + "complexity": 24, + "token_count": 712, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 969, + "end_line": 1103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Return", + "long_name": "PyArray_Return( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 91, + "parameters": [ + "mp" + ], + "start_line": 1123, + "end_line": 1145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDataType", + "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 9, + "token_count": 229, + "parameters": [ + "type" + ], + "start_line": 1159, + "end_line": 1199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDescrForType", + "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 214, + "parameters": [ + "typenum", + "descr" + ], + "start_line": 1214, + "end_line": 1255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToFile", + "long_name": "PyArray_ToFile( PyArrayObject * self , FILE * fp , char * sep , char * format)", + "filename": "arrayobject.c", + "nloc": 96, + "complexity": 19, + "token_count": 624, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1262, + "end_line": 1360, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToList", + "long_name": "PyArray_ToList( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self" + ], + "start_line": 1366, + "end_line": 1395, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToString", + "long_name": "PyArray_ToString( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 170, + "parameters": [ + "self" + ], + "start_line": 1398, + "end_line": 1434, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_dealloc", + "long_name": "array_dealloc( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 1443, + "end_line": 1480, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "array_length", + "long_name": "array_length( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 1487, + "end_line": 1495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_big_item", + "long_name": "array_big_item( PyArrayObject * self , intp i)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 4, + "token_count": 151, + "parameters": [ + "self", + "i" + ], + "start_line": 1498, + "end_line": 1523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , _int_or_ssize_t i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 98, + "parameters": [ + "self", + "i" + ], + "start_line": 1527, + "end_line": 1541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_ass_big_item", + "long_name": "array_ass_big_item( PyArrayObject * self , intp i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1544, + "end_line": 1579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , _int_or_ssize_t i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1592, + "end_line": 1595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "slice_coerce_index", + "long_name": "slice_coerce_index( PyObject * o , intp * v)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "o", + "v" + ], + "start_line": 1601, + "end_line": 1609, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "slice_GetIndices", + "long_name": "slice_GetIndices( PySliceObject * r , intp length , intp * start , intp * stop , intp * step , intp * slicelength)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 24, + "token_count": 376, + "parameters": [ + "r", + "length", + "start", + "stop", + "step", + "slicelength" + ], + "start_line": 1615, + "end_line": 1665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "parse_subindex", + "long_name": "parse_subindex( PyObject * op , intp * step_size , intp * n_steps , intp max)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "step_size", + "n_steps", + "max" + ], + "start_line": 1672, + "end_line": 1717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "parse_index", + "long_name": "parse_index( PyArrayObject * self , PyObject * op , intp * dimensions , intp * strides , intp * offset_ptr)", + "filename": "arrayobject.c", + "nloc": 88, + "complexity": 20, + "token_count": 539, + "parameters": [ + "self", + "op", + "dimensions", + "strides", + "offset_ptr" + ], + "start_line": 1721, + "end_line": 1815, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "_swap_axes", + "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 300, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1818, + "end_line": 1872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 254, + "parameters": [ + "mit" + ], + "start_line": 1884, + "end_line": 1937, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetMap", + "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 389, + "parameters": [ + "mit", + "op" + ], + "start_line": 1940, + "end_line": 2002, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "count_new_axes_0d", + "long_name": "count_new_axes_0d( PyObject * tuple)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 7, + "token_count": 124, + "parameters": [ + "tuple" + ], + "start_line": 2005, + "end_line": 2032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "add_new_axes_0d", + "long_name": "add_new_axes_0d( PyArrayObject * arr , int newaxis_count)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 121, + "parameters": [ + "arr", + "newaxis_count" + ], + "start_line": 2035, + "end_line": 2054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 2066, + "end_line": 2128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 107, + "complexity": 28, + "token_count": 674, + "parameters": [ + "self", + "op" + ], + "start_line": 2152, + "end_line": 2277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2292, + "end_line": 2397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 16, + "token_count": 281, + "parameters": [ + "self", + "op" + ], + "start_line": 2406, + "end_line": 2460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , _int_or_ssize_t * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2483, + "end_line": 2495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2498, + "end_line": 2513, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2517, + "end_line": 2526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , _int_or_ssize_t segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2529, + "end_line": 2540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 1, + "token_count": 182, + "parameters": [ + "dict" + ], + "start_line": 2618, + "end_line": 2655, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 2, + "token_count": 203, + "parameters": [], + "start_line": 2665, + "end_line": 2708, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2711, + "end_line": 2734, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericAccumulateFunction", + "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2738, + "end_line": 2761, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericBinaryFunction", + "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 44, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2765, + "end_line": 2772, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericUnaryFunction", + "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 38, + "parameters": [ + "m1", + "op" + ], + "start_line": 2775, + "end_line": 2782, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceBinaryFunction", + "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 46, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2785, + "end_line": 2793, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceUnaryFunction", + "long_name": "PyArray_GenericInplaceUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 40, + "parameters": [ + "m1", + "op" + ], + "start_line": 2796, + "end_line": 2803, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2806, + "end_line": 2809, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_subtract", + "long_name": "array_subtract( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2812, + "end_line": 2815, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_multiply", + "long_name": "array_multiply( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2818, + "end_line": 2821, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_divide", + "long_name": "array_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2824, + "end_line": 2827, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_remainder", + "long_name": "array_remainder( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2830, + "end_line": 2833, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power_is_scalar", + "long_name": "array_power_is_scalar( PyObject * o2 , double * exp)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 12, + "token_count": 154, + "parameters": [ + "o2", + "exp" + ], + "start_line": 2836, + "end_line": 2862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "fast_scalar_power", + "long_name": "fast_scalar_power( PyArrayObject * a1 , PyObject * o2 , int inplace)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 12, + "token_count": 181, + "parameters": [ + "a1", + "o2", + "inplace" + ], + "start_line": 2866, + "end_line": 2904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2907, + "end_line": 2916, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2920, + "end_line": 2923, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_absolute", + "long_name": "array_absolute( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2926, + "end_line": 2929, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_invert", + "long_name": "array_invert( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2932, + "end_line": 2935, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_left_shift", + "long_name": "array_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2938, + "end_line": 2941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_right_shift", + "long_name": "array_right_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2944, + "end_line": 2947, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_bitwise_and", + "long_name": "array_bitwise_and( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2950, + "end_line": 2953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_bitwise_or", + "long_name": "array_bitwise_or( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2956, + "end_line": 2959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_bitwise_xor", + "long_name": "array_bitwise_xor( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2962, + "end_line": 2965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_add", + "long_name": "array_inplace_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2968, + "end_line": 2971, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_subtract", + "long_name": "array_inplace_subtract( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2974, + "end_line": 2977, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_multiply", + "long_name": "array_inplace_multiply( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2980, + "end_line": 2983, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_divide", + "long_name": "array_inplace_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2986, + "end_line": 2989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_remainder", + "long_name": "array_inplace_remainder( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2992, + "end_line": 2995, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2998, + "end_line": 3007, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3010, + "end_line": 3013, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_right_shift", + "long_name": "array_inplace_right_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3016, + "end_line": 3019, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_bitwise_and", + "long_name": "array_inplace_bitwise_and( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3022, + "end_line": 3025, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_bitwise_or", + "long_name": "array_inplace_bitwise_or( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3028, + "end_line": 3031, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_bitwise_xor", + "long_name": "array_inplace_bitwise_xor( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3034, + "end_line": 3037, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_floor_divide", + "long_name": "array_floor_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3040, + "end_line": 3043, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_true_divide", + "long_name": "array_true_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3046, + "end_line": 3049, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_floor_divide", + "long_name": "array_inplace_floor_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3052, + "end_line": 3056, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_true_divide", + "long_name": "array_inplace_true_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3059, + "end_line": 3063, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_any_nonzero", + "long_name": "array_any_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 95, + "parameters": [ + "mp" + ], + "start_line": 3067, + "end_line": 3085, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_array_nonzero", + "long_name": "_array_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 3, + "token_count": 72, + "parameters": [ + "mp" + ], + "start_line": 3088, + "end_line": 3105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_divmod", + "long_name": "array_divmod( PyArrayObject * op1 , PyObject * op2)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 89, + "parameters": [ + "op1", + "op2" + ], + "start_line": 3110, + "end_line": 3125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_int", + "long_name": "array_int( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 3129, + "end_line": 3155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_float", + "long_name": "array_float( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 3158, + "end_line": 3183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_long", + "long_name": "array_long( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3186, + "end_line": 3208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_oct", + "long_name": "array_oct( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3211, + "end_line": 3233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_hex", + "long_name": "array_hex( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3236, + "end_line": 3258, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_array_copy_nice", + "long_name": "_array_copy_nice( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 3261, + "end_line": 3265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 12, + "token_count": 268, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 3326, + "end_line": 3367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 3371, + "end_line": 3393, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 3396, + "end_line": 3409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "dump_data", + "long_name": "dump_data( char ** string , int * n , int * max_n , char * data , int nd , intp * dimensions , intp * strides , PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 7, + "token_count": 310, + "parameters": [ + "string", + "n", + "max_n", + "data", + "nd", + "dimensions", + "strides", + "self" + ], + "start_line": 3442, + "end_line": 3489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_repr_builtin", + "long_name": "array_repr_builtin( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 4, + "token_count": 224, + "parameters": [ + "self" + ], + "start_line": 3492, + "end_line": 3528, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetStringFunction", + "long_name": "PyArray_SetStringFunction( PyObject * op , int repr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 48, + "parameters": [ + "op", + "repr" + ], + "start_line": 3537, + "end_line": 3554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_repr", + "long_name": "array_repr( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 3557, + "end_line": 3569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_str", + "long_name": "array_str( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 3572, + "end_line": 3584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CompareUCS4", + "long_name": "PyArray_CompareUCS4( PyArray_UCS4 * s1 , PyArray_UCS4 * s2 , register size_t len)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 66, + "parameters": [ + "s1", + "s2", + "len" + ], + "start_line": 3591, + "end_line": 3602, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "_myunincmp", + "long_name": "_myunincmp( PyArray_UCS4 * s1 , PyArray_UCS4 * s2 , int len1 , int len2)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 7, + "token_count": 141, + "parameters": [ + "s1", + "s2", + "len1", + "len2" + ], + "start_line": 3605, + "end_line": 3620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_mystrncmp", + "long_name": "_mystrncmp( char * s1 , char * s2 , int len1 , int len2)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 5, + "token_count": 103, + "parameters": [ + "s1", + "s2", + "len1", + "len2" + ], + "start_line": 3630, + "end_line": 3641, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "_compare_strings", + "long_name": "_compare_strings( PyObject * result , PyArrayMultiIterObject * multi , int cmp_op , * func)", + "filename": "arrayobject.c", + "nloc": 53, + "complexity": 9, + "token_count": 293, + "parameters": [ + "result", + "multi", + "cmp_op", + "func" + ], + "start_line": 3644, + "end_line": 3697, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "_strings_richcompare", + "long_name": "_strings_richcompare( PyArrayObject * self , PyArrayObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 12, + "token_count": 360, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3700, + "end_line": 3765, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "array_richcompare", + "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 105, + "complexity": 23, + "token_count": 483, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3771, + "end_line": 3893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 123, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 9, + "token_count": 181, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3896, + "end_line": 3926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntTupleFromIntp", + "long_name": "PyArray_IntTupleFromIntp( int len , intp * vals)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 109, + "parameters": [ + "len", + "vals" + ], + "start_line": 3932, + "end_line": 3952, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3960, + "end_line": 3995, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 4001, + "end_line": 4020, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 4024, + "end_line": 4042, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 4045, + "end_line": 4062, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_IsWriteable", + "long_name": "_IsWriteable( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 107, + "parameters": [ + "ap" + ], + "start_line": 4065, + "end_line": 4098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_UpdateFlags", + "long_name": "PyArray_UpdateFlags( PyArrayObject * ret , int flagmask)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 11, + "token_count": 157, + "parameters": [ + "ret", + "flagmask" + ], + "start_line": 4105, + "end_line": 4132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 117, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 4152, + "end_line": 4172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 4192, + "end_line": 4216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_New", + "long_name": "PyArray_New( PyTypeObject * subtype , int nd , intp * dims , int type_num , intp * strides , * data , int itemsize , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 4, + "token_count": 128, + "parameters": [ + "subtype", + "nd", + "dims", + "type_num", + "strides", + "data", + "itemsize", + "flags", + "obj" + ], + "start_line": 4222, + "end_line": 4244, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd , int isfortran)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 10, + "token_count": 311, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd", + "isfortran" + ], + "start_line": 4255, + "end_line": 4317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 133, + "complexity": 29, + "token_count": 798, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 4325, + "end_line": 4492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 168, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape , int refcheck , PyArray_ORDER fortran)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 17, + "token_count": 524, + "parameters": [ + "self", + "newshape", + "refcheck", + "fortran" + ], + "start_line": 4505, + "end_line": 4608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 104, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillObjectArray", + "long_name": "PyArray_FillObjectArray( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 98, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4614, + "end_line": 4631, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 8, + "token_count": 279, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4635, + "end_line": 4685, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 22, + "token_count": 638, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4688, + "end_line": 4822, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4826, + "end_line": 4834, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ndim_get", + "long_name": "array_ndim_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4840, + "end_line": 4843, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flags_get", + "long_name": "array_flags_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 4846, + "end_line": 4849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_get", + "long_name": "array_shape_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4852, + "end_line": 4855, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_set", + "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 213, + "parameters": [ + "self", + "val" + ], + "start_line": 4859, + "end_line": 4895, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_strides_get", + "long_name": "array_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4899, + "end_line": 4902, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 9, + "token_count": 304, + "parameters": [ + "self", + "obj" + ], + "start_line": 4905, + "end_line": 4959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4963, + "end_line": 4970, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4973, + "end_line": 4979, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4983, + "end_line": 4989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_data_get", + "long_name": "array_data_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 82, + "parameters": [ + "self" + ], + "start_line": 4992, + "end_line": 5006, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_data_set", + "long_name": "array_data_set( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 9, + "token_count": 229, + "parameters": [ + "self", + "op" + ], + "start_line": 5009, + "end_line": 5053, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_itemsize_get", + "long_name": "array_itemsize_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 5057, + "end_line": 5060, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_size_get", + "long_name": "array_size_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 5063, + "end_line": 5074, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nbytes_get", + "long_name": "array_nbytes_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 5077, + "end_line": 5088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 5094, + "end_line": 5097, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_descr_get", + "long_name": "array_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 5100, + "end_line": 5104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "arg" + ], + "start_line": 5118, + "end_line": 5205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 5208, + "end_line": 5226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_struct_get", + "long_name": "array_struct_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 2, + "token_count": 130, + "parameters": [ + "self" + ], + "start_line": 5229, + "end_line": 5247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 5250, + "end_line": 5260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_real_get", + "long_name": "array_real_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 3, + "token_count": 129, + "parameters": [ + "self" + ], + "start_line": 5264, + "end_line": 5289, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_real_set", + "long_name": "array_real_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 4, + "token_count": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 5293, + "end_line": 5327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_imag_get", + "long_name": "array_imag_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self" + ], + "start_line": 5330, + "end_line": 5363, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 5366, + "end_line": 5403, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "array_flat_get", + "long_name": "array_flat_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 5406, + "end_line": 5409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flat_set", + "long_name": "array_flat_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 9, + "token_count": 344, + "parameters": [ + "self", + "val" + ], + "start_line": 5412, + "end_line": 5462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_alloc", + "long_name": "array_alloc( PyTypeObject * type , int nitems)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 1, + "token_count": 39, + "parameters": [ + "type", + "nitems" + ], + "start_line": 5552, + "end_line": 5559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "discover_depth", + "long_name": "discover_depth( PyObject * s , int max , int stop_at_string , int stop_at_tuple)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 19, + "token_count": 243, + "parameters": [ + "s", + "max", + "stop_at_string", + "stop_at_tuple" + ], + "start_line": 5647, + "end_line": 5680, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5683, + "end_line": 5705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "discover_dimensions", + "long_name": "discover_dimensions( PyObject * s , int nd , intp * d , int check_it)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 10, + "token_count": 188, + "parameters": [ + "s", + "nd", + "d", + "check_it" + ], + "start_line": 5712, + "end_line": 5738, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_array_small_type", + "long_name": "_array_small_type( PyArray_Descr * chktype , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 169, + "parameters": [ + "chktype", + "mintype" + ], + "start_line": 5744, + "end_line": 5776, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_python_scalar_type", + "long_name": "_array_find_python_scalar_type( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 8, + "token_count": 120, + "parameters": [ + "op" + ], + "start_line": 5779, + "end_line": 5802, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 28, + "token_count": 634, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5814, + "end_line": 5944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "Assign_Array", + "long_name": "Assign_Array( PyArrayObject * self , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 121, + "parameters": [ + "self", + "v" + ], + "start_line": 5947, + "end_line": 5970, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 189, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5975, + "end_line": 6013, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 24, + "token_count": 373, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 6018, + "end_line": 6085, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 68, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 6092, + "end_line": 6101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_bufferedcast", + "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 18, + "token_count": 525, + "parameters": [ + "out", + "in" + ], + "start_line": 6107, + "end_line": 6200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 6210, + "end_line": 6256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastTo", + "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 241, + "parameters": [ + "out", + "mp" + ], + "start_line": 6266, + "end_line": 6319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 31, + "token_count": 658, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 6324, + "end_line": 6450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 501, + "parameters": [ + "str" + ], + "start_line": 6454, + "end_line": 6562, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 6566, + "end_line": 6606, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 6610, + "end_line": 6748, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6752, + "end_line": 6795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 74, + "complexity": 24, + "token_count": 449, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6801, + "end_line": 6893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6898, + "end_line": 6901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ObjectType", + "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 69, + "parameters": [ + "op", + "minimum_type" + ], + "start_line": 6908, + "end_line": 6921, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6967, + "end_line": 6983, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "op" + ], + "start_line": 6996, + "end_line": 7015, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureAnyArray", + "long_name": "PyArray_EnsureAnyArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 3, + "token_count": 26, + "parameters": [ + "op" + ], + "start_line": 7019, + "end_line": 7023, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastSafely", + "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 39, + "token_count": 444, + "parameters": [ + "fromtype", + "totype" + ], + "start_line": 7029, + "end_line": 7117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 7122, + "end_line": 7150, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastScalar", + "long_name": "PyArray_CanCastScalar( PyTypeObject * from , PyTypeObject * to)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 3, + "token_count": 68, + "parameters": [ + "from", + "to" + ], + "start_line": 7156, + "end_line": 7166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterNew", + "long_name": "PyArray_IterNew( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 269, + "parameters": [ + "obj" + ], + "start_line": 7177, + "end_line": 7215, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterAllButAxis", + "long_name": "PyArray_IterAllButAxis( PyObject * obj , int axis)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 88, + "parameters": [ + "obj", + "axis" + ], + "start_line": 7223, + "end_line": 7240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RemoveLargest", + "long_name": "PyArray_RemoveLargest( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 6, + "token_count": 164, + "parameters": [ + "multi" + ], + "start_line": 7252, + "end_line": 7280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_next", + "long_name": "arrayiter_next( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 48, + "parameters": [ + "it" + ], + "start_line": 7285, + "end_line": 7295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_dealloc", + "long_name": "arrayiter_dealloc( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "it" + ], + "start_line": 7298, + "end_line": 7302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 7305, + "end_line": 7308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_Bool", + "long_name": "iter_subscript_Bool( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 7, + "token_count": 283, + "parameters": [ + "self", + "ind" + ], + "start_line": 7312, + "end_line": 7362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_int", + "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 52, + "complexity": 8, + "token_count": 352, + "parameters": [ + "self", + "ind" + ], + "start_line": 7365, + "end_line": 7419, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 7423, + "end_line": 7556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 134, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_Bool", + "long_name": "iter_ass_sub_Bool( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 5, + "token_count": 182, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7560, + "end_line": 7591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_int", + "long_name": "iter_ass_sub_int( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 8, + "token_count": 286, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7594, + "end_line": 7636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 7639, + "end_line": 7773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "iter_array", + "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 214, + "parameters": [ + "it", + "op" + ], + "start_line": 7790, + "end_line": 7835, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "iter_copy", + "long_name": "iter_copy( PyArrayIterObject * it , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "it", + "args" + ], + "start_line": 7840, + "end_line": 7844, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7860, + "end_line": 7875, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7940, + "end_line": 7956, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Broadcast", + "long_name": "PyArray_Broadcast( PyArrayMultiIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 13, + "token_count": 464, + "parameters": [ + "mit" + ], + "start_line": 7963, + "end_line": 8032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterReset", + "long_name": "PyArray_MapIterReset( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 5, + "token_count": 279, + "parameters": [ + "mit" + ], + "start_line": 8036, + "end_line": 8076, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 296, + "parameters": [ + "mit" + ], + "start_line": 8082, + "end_line": 8126, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterBind", + "long_name": "PyArray_MapIterBind( PyArrayMapIterObject * mit , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 109, + "complexity": 23, + "token_count": 718, + "parameters": [ + "mit", + "arr" + ], + "start_line": 8144, + "end_line": 8285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 142, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 8291, + "end_line": 8363, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 8366, + "end_line": 8492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 8496, + "end_line": 8505, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiIterNew", + "long_name": "PyArray_MultiIterNew( int n , ...)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 10, + "token_count": 245, + "parameters": [ + "n" + ], + "start_line": 8576, + "end_line": 8626, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_new", + "long_name": "arraymultiter_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 11, + "token_count": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8629, + "end_line": 8674, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_next", + "long_name": "arraymultiter_next( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 111, + "parameters": [ + "multi" + ], + "start_line": 8677, + "end_line": 8696, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_dealloc", + "long_name": "arraymultiter_dealloc( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 49, + "parameters": [ + "multi" + ], + "start_line": 8699, + "end_line": 8706, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_size_get", + "long_name": "arraymultiter_size_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8709, + "end_line": 8719, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_index_get", + "long_name": "arraymultiter_index_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8722, + "end_line": 8732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_shape_get", + "long_name": "arraymultiter_shape_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 8735, + "end_line": 8738, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_iters_get", + "long_name": "arraymultiter_iters_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 8741, + "end_line": 8753, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_reset", + "long_name": "arraymultiter_reset( PyArrayMultiIterObject * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 38, + "parameters": [ + "self", + "args" + ], + "start_line": 8783, + "end_line": 8790, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewFromType", + "long_name": "PyArray_DescrNewFromType( int type_num)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 1, + "token_count": 37, + "parameters": [ + "type_num" + ], + "start_line": 8849, + "end_line": 8858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNew", + "long_name": "PyArray_DescrNew( PyArray_Descr * base)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 151, + "parameters": [ + "base" + ], + "start_line": 8876, + "end_line": 8898, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_dealloc", + "long_name": "arraydescr_dealloc( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 8904, + "end_line": 8914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_subdescr_get", + "long_name": "arraydescr_subdescr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 8933, + "end_line": 8941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8944, + "end_line": 8959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8962, + "end_line": 8984, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8987, + "end_line": 8995, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8998, + "end_line": 9005, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 9008, + "end_line": 9027, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isbuiltin_get", + "long_name": "arraydescr_isbuiltin_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 9034, + "end_line": 9041, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isnative_get", + "long_name": "arraydescr_isnative_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 9044, + "end_line": 9051, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_fields_get", + "long_name": "arraydescr_fields_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 9054, + "end_line": 9061, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_new", + "long_name": "arraydescr_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 272, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 9109, + "end_line": 9161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 9167, + "end_line": 9228, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 9, + "token_count": 264, + "parameters": [ + "self", + "args" + ], + "start_line": 9236, + "end_line": 9279, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewByteorder", + "long_name": "PyArray_DescrNewByteorder( PyArray_Descr * self , char newendian)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 386, + "parameters": [ + "self", + "newendian" + ], + "start_line": 9300, + "end_line": 9366, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_newbyteorder", + "long_name": "arraydescr_newbyteorder( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 47, + "parameters": [ + "self", + "args" + ], + "start_line": 9377, + "end_line": 9385, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_str", + "long_name": "arraydescr_str( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 6, + "token_count": 287, + "parameters": [ + "self" + ], + "start_line": 9400, + "end_line": 9445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_repr", + "long_name": "arraydescr_repr( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 9448, + "end_line": 9457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_compare", + "long_name": "arraydescr_compare( PyArray_Descr * self , PyObject * other)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "other" + ], + "start_line": 9460, + "end_line": 9470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 9477, + "end_line": 9484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 9487, + "end_line": 9518, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFlagsObject", + "long_name": "PyArray_NewFlagsObject( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 3, + "token_count": 96, + "parameters": [ + "obj" + ], + "start_line": 9596, + "end_line": 9613, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_dealloc", + "long_name": "arrayflags_dealloc( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 9616, + "end_line": 9620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_forc_get", + "long_name": "arrayflags_forc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 9644, + "end_line": 9656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_fnc_get", + "long_name": "arrayflags_fnc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9659, + "end_line": 9671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_farray_get", + "long_name": "arrayflags_farray_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 9674, + "end_line": 9687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_num_get", + "long_name": "arrayflags_num_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 9690, + "end_line": 9693, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_updateifcopy_set", + "long_name": "arrayflags_updateifcopy_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9697, + "end_line": 9709, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_aligned_set", + "long_name": "arrayflags_aligned_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9712, + "end_line": 9725, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_writeable_set", + "long_name": "arrayflags_writeable_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9728, + "end_line": 9741, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_getitem", + "long_name": "arrayflags_getitem( PyArrayFlagsObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 75, + "complexity": 31, + "token_count": 431, + "parameters": [ + "self", + "ind" + ], + "start_line": 9797, + "end_line": 9872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_setitem", + "long_name": "arrayflags_setitem( PyArrayFlagsObject * self , PyObject * ind , PyObject * item)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 14, + "token_count": 219, + "parameters": [ + "self", + "ind", + "item" + ], + "start_line": 9875, + "end_line": 9895, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_torf_", + "long_name": "_torf_( int flags , int val)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 27, + "parameters": [ + "flags", + "val" + ], + "start_line": 9898, + "end_line": 9902, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_print", + "long_name": "arrayflags_print( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 1, + "token_count": 77, + "parameters": [ + "self" + ], + "start_line": 9905, + "end_line": 9917, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_new", + "long_name": "arrayflags_new( PyTypeObject * self , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9932, + "end_line": 9944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 76, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 65, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 99, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 134, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 207, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 241, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 291, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 319, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 344, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 387, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 427, + "end_line": 509, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 516, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 593, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Size", + "long_name": "PyArray_Size( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 33, + "parameters": [ + "op" + ], + "start_line": 614, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "_strided_byte_copy", + "long_name": "_strided_byte_copy( char * dst , intp outstrides , char * src , intp instrides , intp N , int elsize)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 9, + "token_count": 207, + "parameters": [ + "dst", + "outstrides", + "src", + "instrides", + "N", + "elsize" + ], + "start_line": 625, + "end_line": 667, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "_unaligned_strided_byte_copy", + "long_name": "_unaligned_strided_byte_copy( char * dst , intp outstrides , char * src , intp instrides , intp N , int elsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 92, + "parameters": [ + "dst", + "outstrides", + "src", + "instrides", + "N", + "elsize" + ], + "start_line": 671, + "end_line": 701, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 119, + "complexity": 27, + "token_count": 737, + "parameters": [ + "dest", + "src" + ], + "start_line": 718, + "end_line": 853, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyObject", + "long_name": "PyArray_CopyObject( PyArrayObject * dest , PyObject * src_object)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 857, + "end_line": 871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDimsAndDataAndDescr", + "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 137, + "parameters": [ + "nd", + "d", + "descr", + "data" + ], + "start_line": 884, + "end_line": 910, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDims", + "long_name": "PyArray_FromDims( int nd , int * d , int type)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "nd", + "d", + "type" + ], + "start_line": 916, + "end_line": 930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewCopy", + "long_name": "PyArray_NewCopy( PyArrayObject * m1 , PyArray_ORDER fortran)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 939, + "end_line": 960, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 118, + "complexity": 24, + "token_count": 712, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 969, + "end_line": 1103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Return", + "long_name": "PyArray_Return( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 91, + "parameters": [ + "mp" + ], + "start_line": 1123, + "end_line": 1145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDataType", + "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 9, + "token_count": 229, + "parameters": [ + "type" + ], + "start_line": 1159, + "end_line": 1199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDescrForType", + "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 214, + "parameters": [ + "typenum", + "descr" + ], + "start_line": 1214, + "end_line": 1255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToFile", + "long_name": "PyArray_ToFile( PyArrayObject * self , FILE * fp , char * sep , char * format)", + "filename": "arrayobject.c", + "nloc": 96, + "complexity": 19, + "token_count": 624, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1262, + "end_line": 1360, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToList", + "long_name": "PyArray_ToList( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self" + ], + "start_line": 1366, + "end_line": 1395, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToString", + "long_name": "PyArray_ToString( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 170, + "parameters": [ + "self" + ], + "start_line": 1398, + "end_line": 1434, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_dealloc", + "long_name": "array_dealloc( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 1443, + "end_line": 1480, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "array_length", + "long_name": "array_length( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 1487, + "end_line": 1495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_big_item", + "long_name": "array_big_item( PyArrayObject * self , intp i)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 4, + "token_count": 151, + "parameters": [ + "self", + "i" + ], + "start_line": 1498, + "end_line": 1523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , _int_or_ssize_t i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 98, + "parameters": [ + "self", + "i" + ], + "start_line": 1527, + "end_line": 1541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_ass_big_item", + "long_name": "array_ass_big_item( PyArrayObject * self , intp i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1544, + "end_line": 1579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , _int_or_ssize_t i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1592, + "end_line": 1595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "slice_coerce_index", + "long_name": "slice_coerce_index( PyObject * o , intp * v)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "o", + "v" + ], + "start_line": 1601, + "end_line": 1609, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "slice_GetIndices", + "long_name": "slice_GetIndices( PySliceObject * r , intp length , intp * start , intp * stop , intp * step , intp * slicelength)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 24, + "token_count": 376, + "parameters": [ + "r", + "length", + "start", + "stop", + "step", + "slicelength" + ], + "start_line": 1615, + "end_line": 1665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "parse_subindex", + "long_name": "parse_subindex( PyObject * op , intp * step_size , intp * n_steps , intp max)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "step_size", + "n_steps", + "max" + ], + "start_line": 1672, + "end_line": 1717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "parse_index", + "long_name": "parse_index( PyArrayObject * self , PyObject * op , intp * dimensions , intp * strides , intp * offset_ptr)", + "filename": "arrayobject.c", + "nloc": 88, + "complexity": 20, + "token_count": 539, + "parameters": [ + "self", + "op", + "dimensions", + "strides", + "offset_ptr" + ], + "start_line": 1721, + "end_line": 1815, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "_swap_axes", + "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 300, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1818, + "end_line": 1872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 254, + "parameters": [ + "mit" + ], + "start_line": 1884, + "end_line": 1937, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetMap", + "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 389, + "parameters": [ + "mit", + "op" + ], + "start_line": 1940, + "end_line": 2002, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "count_new_axes_0d", + "long_name": "count_new_axes_0d( PyObject * tuple)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 7, + "token_count": 124, + "parameters": [ + "tuple" + ], + "start_line": 2005, + "end_line": 2032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "add_new_axes_0d", + "long_name": "add_new_axes_0d( PyArrayObject * arr , int newaxis_count)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 121, + "parameters": [ + "arr", + "newaxis_count" + ], + "start_line": 2035, + "end_line": 2054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 2066, + "end_line": 2128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 107, + "complexity": 28, + "token_count": 674, + "parameters": [ + "self", + "op" + ], + "start_line": 2152, + "end_line": 2277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2292, + "end_line": 2397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 16, + "token_count": 281, + "parameters": [ + "self", + "op" + ], + "start_line": 2406, + "end_line": 2460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , _int_or_ssize_t * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2483, + "end_line": 2495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2498, + "end_line": 2513, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2517, + "end_line": 2526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , _int_or_ssize_t segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2529, + "end_line": 2540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 1, + "token_count": 182, + "parameters": [ + "dict" + ], + "start_line": 2618, + "end_line": 2655, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 2, + "token_count": 203, + "parameters": [], + "start_line": 2665, + "end_line": 2708, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2711, + "end_line": 2734, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericAccumulateFunction", + "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2738, + "end_line": 2761, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericBinaryFunction", + "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 44, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2765, + "end_line": 2772, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericUnaryFunction", + "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 38, + "parameters": [ + "m1", + "op" + ], + "start_line": 2775, + "end_line": 2782, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceBinaryFunction", + "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 46, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2785, + "end_line": 2793, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceUnaryFunction", + "long_name": "PyArray_GenericInplaceUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 40, + "parameters": [ + "m1", + "op" + ], + "start_line": 2796, + "end_line": 2803, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2806, + "end_line": 2809, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_subtract", + "long_name": "array_subtract( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2812, + "end_line": 2815, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_multiply", + "long_name": "array_multiply( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2818, + "end_line": 2821, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_divide", + "long_name": "array_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2824, + "end_line": 2827, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_remainder", + "long_name": "array_remainder( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2830, + "end_line": 2833, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power_is_scalar", + "long_name": "array_power_is_scalar( PyObject * o2 , double * exp)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 12, + "token_count": 154, + "parameters": [ + "o2", + "exp" + ], + "start_line": 2836, + "end_line": 2862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "fast_scalar_power", + "long_name": "fast_scalar_power( PyArrayObject * a1 , PyObject * o2 , int inplace)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 12, + "token_count": 181, + "parameters": [ + "a1", + "o2", + "inplace" + ], + "start_line": 2866, + "end_line": 2904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2907, + "end_line": 2916, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2920, + "end_line": 2923, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_absolute", + "long_name": "array_absolute( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2926, + "end_line": 2929, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_invert", + "long_name": "array_invert( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2932, + "end_line": 2935, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_left_shift", + "long_name": "array_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2938, + "end_line": 2941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_right_shift", + "long_name": "array_right_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2944, + "end_line": 2947, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_bitwise_and", + "long_name": "array_bitwise_and( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2950, + "end_line": 2953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_bitwise_or", + "long_name": "array_bitwise_or( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2956, + "end_line": 2959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_bitwise_xor", + "long_name": "array_bitwise_xor( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2962, + "end_line": 2965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_add", + "long_name": "array_inplace_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2968, + "end_line": 2971, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_subtract", + "long_name": "array_inplace_subtract( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2974, + "end_line": 2977, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_multiply", + "long_name": "array_inplace_multiply( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2980, + "end_line": 2983, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_divide", + "long_name": "array_inplace_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2986, + "end_line": 2989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_remainder", + "long_name": "array_inplace_remainder( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2992, + "end_line": 2995, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2998, + "end_line": 3007, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3010, + "end_line": 3013, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_right_shift", + "long_name": "array_inplace_right_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3016, + "end_line": 3019, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_bitwise_and", + "long_name": "array_inplace_bitwise_and( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3022, + "end_line": 3025, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_bitwise_or", + "long_name": "array_inplace_bitwise_or( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3028, + "end_line": 3031, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_bitwise_xor", + "long_name": "array_inplace_bitwise_xor( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3034, + "end_line": 3037, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_floor_divide", + "long_name": "array_floor_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3040, + "end_line": 3043, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_true_divide", + "long_name": "array_true_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3046, + "end_line": 3049, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_floor_divide", + "long_name": "array_inplace_floor_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3052, + "end_line": 3056, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_true_divide", + "long_name": "array_inplace_true_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3059, + "end_line": 3063, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_any_nonzero", + "long_name": "array_any_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 95, + "parameters": [ + "mp" + ], + "start_line": 3067, + "end_line": 3085, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_array_nonzero", + "long_name": "_array_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 3, + "token_count": 72, + "parameters": [ + "mp" + ], + "start_line": 3088, + "end_line": 3105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_divmod", + "long_name": "array_divmod( PyArrayObject * op1 , PyObject * op2)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 89, + "parameters": [ + "op1", + "op2" + ], + "start_line": 3110, + "end_line": 3125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_int", + "long_name": "array_int( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 3129, + "end_line": 3155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_float", + "long_name": "array_float( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 3158, + "end_line": 3183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_long", + "long_name": "array_long( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3186, + "end_line": 3208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_oct", + "long_name": "array_oct( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3211, + "end_line": 3233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_hex", + "long_name": "array_hex( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3236, + "end_line": 3258, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_array_copy_nice", + "long_name": "_array_copy_nice( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 3261, + "end_line": 3265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 12, + "token_count": 268, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 3326, + "end_line": 3367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 3371, + "end_line": 3393, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 3396, + "end_line": 3409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "dump_data", + "long_name": "dump_data( char ** string , int * n , int * max_n , char * data , int nd , intp * dimensions , intp * strides , PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 7, + "token_count": 310, + "parameters": [ + "string", + "n", + "max_n", + "data", + "nd", + "dimensions", + "strides", + "self" + ], + "start_line": 3442, + "end_line": 3489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_repr_builtin", + "long_name": "array_repr_builtin( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 4, + "token_count": 224, + "parameters": [ + "self" + ], + "start_line": 3492, + "end_line": 3528, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetStringFunction", + "long_name": "PyArray_SetStringFunction( PyObject * op , int repr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 48, + "parameters": [ + "op", + "repr" + ], + "start_line": 3537, + "end_line": 3554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_repr", + "long_name": "array_repr( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 3557, + "end_line": 3569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_str", + "long_name": "array_str( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 3572, + "end_line": 3584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CompareUCS4", + "long_name": "PyArray_CompareUCS4( PyArray_UCS4 * s1 , PyArray_UCS4 * s2 , register size_t len)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 66, + "parameters": [ + "s1", + "s2", + "len" + ], + "start_line": 3591, + "end_line": 3602, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "_myunincmp", + "long_name": "_myunincmp( PyArray_UCS4 * s1 , PyArray_UCS4 * s2 , int len1 , int len2)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 7, + "token_count": 141, + "parameters": [ + "s1", + "s2", + "len1", + "len2" + ], + "start_line": 3605, + "end_line": 3620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_mystrncmp", + "long_name": "_mystrncmp( char * s1 , char * s2 , int len1 , int len2)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 5, + "token_count": 103, + "parameters": [ + "s1", + "s2", + "len1", + "len2" + ], + "start_line": 3630, + "end_line": 3641, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "_compare_strings", + "long_name": "_compare_strings( PyObject * result , PyArrayMultiIterObject * multi , int cmp_op , * func)", + "filename": "arrayobject.c", + "nloc": 53, + "complexity": 9, + "token_count": 293, + "parameters": [ + "result", + "multi", + "cmp_op", + "func" + ], + "start_line": 3644, + "end_line": 3697, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "_strings_richcompare", + "long_name": "_strings_richcompare( PyArrayObject * self , PyArrayObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 12, + "token_count": 360, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3700, + "end_line": 3765, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "array_richcompare", + "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 105, + "complexity": 23, + "token_count": 483, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3768, + "end_line": 3890, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 123, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 9, + "token_count": 181, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3893, + "end_line": 3923, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntTupleFromIntp", + "long_name": "PyArray_IntTupleFromIntp( int len , intp * vals)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 109, + "parameters": [ + "len", + "vals" + ], + "start_line": 3929, + "end_line": 3949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3957, + "end_line": 3992, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 3998, + "end_line": 4017, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 4021, + "end_line": 4039, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 4042, + "end_line": 4059, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_IsWriteable", + "long_name": "_IsWriteable( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 107, + "parameters": [ + "ap" + ], + "start_line": 4062, + "end_line": 4095, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_UpdateFlags", + "long_name": "PyArray_UpdateFlags( PyArrayObject * ret , int flagmask)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 11, + "token_count": 157, + "parameters": [ + "ret", + "flagmask" + ], + "start_line": 4102, + "end_line": 4129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 117, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 4149, + "end_line": 4169, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 4189, + "end_line": 4213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_New", + "long_name": "PyArray_New( PyTypeObject * subtype , int nd , intp * dims , int type_num , intp * strides , * data , int itemsize , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 4, + "token_count": 128, + "parameters": [ + "subtype", + "nd", + "dims", + "type_num", + "strides", + "data", + "itemsize", + "flags", + "obj" + ], + "start_line": 4219, + "end_line": 4241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd , int isfortran)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 10, + "token_count": 311, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd", + "isfortran" + ], + "start_line": 4252, + "end_line": 4314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 133, + "complexity": 29, + "token_count": 798, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 4322, + "end_line": 4489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 168, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape , int refcheck , PyArray_ORDER fortran)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 17, + "token_count": 524, + "parameters": [ + "self", + "newshape", + "refcheck", + "fortran" + ], + "start_line": 4502, + "end_line": 4605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 104, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillObjectArray", + "long_name": "PyArray_FillObjectArray( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 98, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4611, + "end_line": 4628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 8, + "token_count": 279, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4632, + "end_line": 4682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 22, + "token_count": 638, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4685, + "end_line": 4819, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4823, + "end_line": 4831, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ndim_get", + "long_name": "array_ndim_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4837, + "end_line": 4840, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flags_get", + "long_name": "array_flags_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 4843, + "end_line": 4846, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_get", + "long_name": "array_shape_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4849, + "end_line": 4852, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_set", + "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 213, + "parameters": [ + "self", + "val" + ], + "start_line": 4856, + "end_line": 4892, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_strides_get", + "long_name": "array_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4896, + "end_line": 4899, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 9, + "token_count": 304, + "parameters": [ + "self", + "obj" + ], + "start_line": 4902, + "end_line": 4956, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4960, + "end_line": 4967, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4970, + "end_line": 4976, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4980, + "end_line": 4986, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_data_get", + "long_name": "array_data_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 82, + "parameters": [ + "self" + ], + "start_line": 4989, + "end_line": 5003, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_data_set", + "long_name": "array_data_set( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 9, + "token_count": 229, + "parameters": [ + "self", + "op" + ], + "start_line": 5006, + "end_line": 5050, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_itemsize_get", + "long_name": "array_itemsize_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 5054, + "end_line": 5057, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_size_get", + "long_name": "array_size_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 5060, + "end_line": 5071, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nbytes_get", + "long_name": "array_nbytes_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 5074, + "end_line": 5085, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 5091, + "end_line": 5094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_descr_get", + "long_name": "array_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 5097, + "end_line": 5101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "arg" + ], + "start_line": 5115, + "end_line": 5202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 5205, + "end_line": 5223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_struct_get", + "long_name": "array_struct_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 2, + "token_count": 130, + "parameters": [ + "self" + ], + "start_line": 5226, + "end_line": 5244, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 5247, + "end_line": 5257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_real_get", + "long_name": "array_real_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 3, + "token_count": 129, + "parameters": [ + "self" + ], + "start_line": 5261, + "end_line": 5286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_real_set", + "long_name": "array_real_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 4, + "token_count": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 5290, + "end_line": 5324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_imag_get", + "long_name": "array_imag_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self" + ], + "start_line": 5327, + "end_line": 5360, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 5363, + "end_line": 5400, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "array_flat_get", + "long_name": "array_flat_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 5403, + "end_line": 5406, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flat_set", + "long_name": "array_flat_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 9, + "token_count": 344, + "parameters": [ + "self", + "val" + ], + "start_line": 5409, + "end_line": 5459, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_alloc", + "long_name": "array_alloc( PyTypeObject * type , int nitems)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 1, + "token_count": 39, + "parameters": [ + "type", + "nitems" + ], + "start_line": 5549, + "end_line": 5556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "discover_depth", + "long_name": "discover_depth( PyObject * s , int max , int stop_at_string , int stop_at_tuple)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 19, + "token_count": 243, + "parameters": [ + "s", + "max", + "stop_at_string", + "stop_at_tuple" + ], + "start_line": 5644, + "end_line": 5677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5680, + "end_line": 5702, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "discover_dimensions", + "long_name": "discover_dimensions( PyObject * s , int nd , intp * d , int check_it)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 10, + "token_count": 188, + "parameters": [ + "s", + "nd", + "d", + "check_it" + ], + "start_line": 5709, + "end_line": 5735, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_array_small_type", + "long_name": "_array_small_type( PyArray_Descr * chktype , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 169, + "parameters": [ + "chktype", + "mintype" + ], + "start_line": 5741, + "end_line": 5773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_python_scalar_type", + "long_name": "_array_find_python_scalar_type( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 8, + "token_count": 120, + "parameters": [ + "op" + ], + "start_line": 5776, + "end_line": 5799, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 28, + "token_count": 634, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5811, + "end_line": 5941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "Assign_Array", + "long_name": "Assign_Array( PyArrayObject * self , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 121, + "parameters": [ + "self", + "v" + ], + "start_line": 5944, + "end_line": 5967, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 189, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5972, + "end_line": 6010, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 24, + "token_count": 373, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 6015, + "end_line": 6082, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 68, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 6089, + "end_line": 6098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_bufferedcast", + "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 18, + "token_count": 525, + "parameters": [ + "out", + "in" + ], + "start_line": 6104, + "end_line": 6197, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 6207, + "end_line": 6253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastTo", + "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 241, + "parameters": [ + "out", + "mp" + ], + "start_line": 6263, + "end_line": 6316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 31, + "token_count": 658, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 6321, + "end_line": 6447, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 501, + "parameters": [ + "str" + ], + "start_line": 6451, + "end_line": 6559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 6563, + "end_line": 6603, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 6607, + "end_line": 6745, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6749, + "end_line": 6792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 74, + "complexity": 24, + "token_count": 449, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6798, + "end_line": 6890, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6895, + "end_line": 6898, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ObjectType", + "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 69, + "parameters": [ + "op", + "minimum_type" + ], + "start_line": 6905, + "end_line": 6918, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6964, + "end_line": 6980, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "op" + ], + "start_line": 6993, + "end_line": 7012, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureAnyArray", + "long_name": "PyArray_EnsureAnyArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 3, + "token_count": 26, + "parameters": [ + "op" + ], + "start_line": 7016, + "end_line": 7020, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastSafely", + "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 39, + "token_count": 444, + "parameters": [ + "fromtype", + "totype" + ], + "start_line": 7026, + "end_line": 7114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 7119, + "end_line": 7147, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastScalar", + "long_name": "PyArray_CanCastScalar( PyTypeObject * from , PyTypeObject * to)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 3, + "token_count": 68, + "parameters": [ + "from", + "to" + ], + "start_line": 7153, + "end_line": 7163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterNew", + "long_name": "PyArray_IterNew( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 269, + "parameters": [ + "obj" + ], + "start_line": 7174, + "end_line": 7212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterAllButAxis", + "long_name": "PyArray_IterAllButAxis( PyObject * obj , int axis)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 88, + "parameters": [ + "obj", + "axis" + ], + "start_line": 7220, + "end_line": 7237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RemoveLargest", + "long_name": "PyArray_RemoveLargest( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 6, + "token_count": 164, + "parameters": [ + "multi" + ], + "start_line": 7249, + "end_line": 7277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_next", + "long_name": "arrayiter_next( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 48, + "parameters": [ + "it" + ], + "start_line": 7282, + "end_line": 7292, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_dealloc", + "long_name": "arrayiter_dealloc( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "it" + ], + "start_line": 7295, + "end_line": 7299, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 7302, + "end_line": 7305, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_Bool", + "long_name": "iter_subscript_Bool( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 7, + "token_count": 283, + "parameters": [ + "self", + "ind" + ], + "start_line": 7309, + "end_line": 7359, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_int", + "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 52, + "complexity": 8, + "token_count": 352, + "parameters": [ + "self", + "ind" + ], + "start_line": 7362, + "end_line": 7416, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 7420, + "end_line": 7553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 134, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_Bool", + "long_name": "iter_ass_sub_Bool( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 5, + "token_count": 182, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7557, + "end_line": 7588, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_int", + "long_name": "iter_ass_sub_int( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 8, + "token_count": 286, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7591, + "end_line": 7633, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 7636, + "end_line": 7770, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "iter_array", + "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 214, + "parameters": [ + "it", + "op" + ], + "start_line": 7787, + "end_line": 7832, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "iter_copy", + "long_name": "iter_copy( PyArrayIterObject * it , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "it", + "args" + ], + "start_line": 7837, + "end_line": 7841, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7857, + "end_line": 7872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7937, + "end_line": 7953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Broadcast", + "long_name": "PyArray_Broadcast( PyArrayMultiIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 13, + "token_count": 464, + "parameters": [ + "mit" + ], + "start_line": 7960, + "end_line": 8029, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterReset", + "long_name": "PyArray_MapIterReset( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 5, + "token_count": 279, + "parameters": [ + "mit" + ], + "start_line": 8033, + "end_line": 8073, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 296, + "parameters": [ + "mit" + ], + "start_line": 8079, + "end_line": 8123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterBind", + "long_name": "PyArray_MapIterBind( PyArrayMapIterObject * mit , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 109, + "complexity": 23, + "token_count": 718, + "parameters": [ + "mit", + "arr" + ], + "start_line": 8141, + "end_line": 8282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 142, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 8288, + "end_line": 8360, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 8363, + "end_line": 8489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 8493, + "end_line": 8502, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiIterNew", + "long_name": "PyArray_MultiIterNew( int n , ...)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 10, + "token_count": 245, + "parameters": [ + "n" + ], + "start_line": 8573, + "end_line": 8623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_new", + "long_name": "arraymultiter_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 11, + "token_count": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8626, + "end_line": 8671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_next", + "long_name": "arraymultiter_next( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 111, + "parameters": [ + "multi" + ], + "start_line": 8674, + "end_line": 8693, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_dealloc", + "long_name": "arraymultiter_dealloc( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 49, + "parameters": [ + "multi" + ], + "start_line": 8696, + "end_line": 8703, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_size_get", + "long_name": "arraymultiter_size_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8706, + "end_line": 8716, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_index_get", + "long_name": "arraymultiter_index_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8719, + "end_line": 8729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_shape_get", + "long_name": "arraymultiter_shape_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 8732, + "end_line": 8735, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_iters_get", + "long_name": "arraymultiter_iters_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 8738, + "end_line": 8750, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_reset", + "long_name": "arraymultiter_reset( PyArrayMultiIterObject * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 38, + "parameters": [ + "self", + "args" + ], + "start_line": 8780, + "end_line": 8787, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewFromType", + "long_name": "PyArray_DescrNewFromType( int type_num)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 1, + "token_count": 37, + "parameters": [ + "type_num" + ], + "start_line": 8846, + "end_line": 8855, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNew", + "long_name": "PyArray_DescrNew( PyArray_Descr * base)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 151, + "parameters": [ + "base" + ], + "start_line": 8873, + "end_line": 8895, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_dealloc", + "long_name": "arraydescr_dealloc( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 8901, + "end_line": 8911, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_subdescr_get", + "long_name": "arraydescr_subdescr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 8930, + "end_line": 8938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8941, + "end_line": 8956, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8959, + "end_line": 8981, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8984, + "end_line": 8992, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8995, + "end_line": 9002, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 9005, + "end_line": 9024, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isbuiltin_get", + "long_name": "arraydescr_isbuiltin_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 9031, + "end_line": 9038, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isnative_get", + "long_name": "arraydescr_isnative_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 9041, + "end_line": 9048, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_fields_get", + "long_name": "arraydescr_fields_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 9051, + "end_line": 9058, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_new", + "long_name": "arraydescr_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 272, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 9106, + "end_line": 9158, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 9164, + "end_line": 9225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 9, + "token_count": 264, + "parameters": [ + "self", + "args" + ], + "start_line": 9233, + "end_line": 9276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewByteorder", + "long_name": "PyArray_DescrNewByteorder( PyArray_Descr * self , char newendian)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 386, + "parameters": [ + "self", + "newendian" + ], + "start_line": 9297, + "end_line": 9363, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_newbyteorder", + "long_name": "arraydescr_newbyteorder( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 47, + "parameters": [ + "self", + "args" + ], + "start_line": 9374, + "end_line": 9382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_str", + "long_name": "arraydescr_str( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 6, + "token_count": 287, + "parameters": [ + "self" + ], + "start_line": 9397, + "end_line": 9442, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_repr", + "long_name": "arraydescr_repr( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 9445, + "end_line": 9454, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_compare", + "long_name": "arraydescr_compare( PyArray_Descr * self , PyObject * other)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "other" + ], + "start_line": 9457, + "end_line": 9467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 9474, + "end_line": 9481, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 9484, + "end_line": 9515, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFlagsObject", + "long_name": "PyArray_NewFlagsObject( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 3, + "token_count": 96, + "parameters": [ + "obj" + ], + "start_line": 9593, + "end_line": 9610, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_dealloc", + "long_name": "arrayflags_dealloc( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 9613, + "end_line": 9617, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_forc_get", + "long_name": "arrayflags_forc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 9641, + "end_line": 9653, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_fnc_get", + "long_name": "arrayflags_fnc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9656, + "end_line": 9668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_farray_get", + "long_name": "arrayflags_farray_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 9671, + "end_line": 9684, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_num_get", + "long_name": "arrayflags_num_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 9687, + "end_line": 9690, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_updateifcopy_set", + "long_name": "arrayflags_updateifcopy_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9694, + "end_line": 9706, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_aligned_set", + "long_name": "arrayflags_aligned_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9709, + "end_line": 9722, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_writeable_set", + "long_name": "arrayflags_writeable_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9725, + "end_line": 9738, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_getitem", + "long_name": "arrayflags_getitem( PyArrayFlagsObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 75, + "complexity": 31, + "token_count": 431, + "parameters": [ + "self", + "ind" + ], + "start_line": 9794, + "end_line": 9869, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_setitem", + "long_name": "arrayflags_setitem( PyArrayFlagsObject * self , PyObject * ind , PyObject * item)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 14, + "token_count": 219, + "parameters": [ + "self", + "ind", + "item" + ], + "start_line": 9872, + "end_line": 9892, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_torf_", + "long_name": "_torf_( int flags , int val)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 27, + "parameters": [ + "flags", + "val" + ], + "start_line": 9895, + "end_line": 9899, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_print", + "long_name": "arrayflags_print( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 1, + "token_count": 77, + "parameters": [ + "self" + ], + "start_line": 9902, + "end_line": 9914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_new", + "long_name": "arrayflags_new( PyTypeObject * self , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9929, + "end_line": 9941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 7945, + "complexity": 1739, + "token_count": 46293, + "diff_parsed": { + "added": [ + "/* What do we do about VOID type arrays?", + " */", + "" + ], + "deleted": [] + } + }, + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -272,6 +272,8 @@ static void\n #name=float, double, longdouble#\n **/\n static @name@ (*_basic_@name@_floor)(@name@);\n+static @name@ (*_basic_@name@_sqrt)(@name@);\n+static @name@ (*_basic_@name@_abs)(@name@);\n #define @name@_ctype_add(a, b, outp) *(outp) = a + b\n #define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n #define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n@@ -381,7 +383,6 @@ static void\n the data area of the power ufunc in umathmodule. \n */\n \n-\n /**begin repeat\n #name=cfloat, cdouble, clongdouble#\n **/\n@@ -400,27 +401,42 @@ static void\n /**end repeat**/\n \n \n+/**begin repeat\n+ #name=ubyte, ushort, uint, ulong, ulonglong#\n+**/\n+#define @name@_ctype_absolute @name@_ctype_positive\n+/**end repeat**/\n+\n \n-#define NOP\n /**begin repeat\n- #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n- #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n+ #name=byte, short, int, long, longlong#\n **/\n static void\n @name@_ctype_absolute(@name@ a, @name@ *out)\n {\n- *out = @fun@(a);\n+ *out = (a < 0 ? -a : a);\n }\n /**end repeat**/\n \n+/**begin repeat\n+ #name=float, double, longdouble#\n+**/\n+static void\n+@name@_ctype_absolute(@name@ a, @name@ *out)\n+{\n+ *out = _basic_@name@_abs(a);\n+}\n+/**end repeat**/\n+\n+\n /**begin repeat\n #name= cfloat, cdouble, clongdouble#\n- #sqrt= sqrtf, sqrt, sqrtl#\n+ #rname= float, double, longdouble#\n **/\n static void\n @name@_ctype_absolute(@name@ a, @name@ *out)\n {\n- out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n+ out->real = _basic_@rname@_sqrt(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n }\n /**end repeat**/\n@@ -922,24 +938,47 @@ get_functions(void)\n _basic_cfloat_pow = funcdata[j+3];\n _basic_cdouble_pow = funcdata[j+4];\n _basic_clongdouble_pow = funcdata[j+5];\n-\n Py_DECREF(obj);\n \n /* Get the floor functions */\n-\n obj = PyObject_GetAttrString(mm, \"floor\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n- \n i = 0;\n j = 0;\n- while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n+ while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n _basic_float_floor = funcdata[j];\n _basic_double_floor = funcdata[j+1];\n _basic_longdouble_floor = funcdata[j+2];\n+ Py_DECREF(obj);\n \n+ /* Get the sqrt functions */\n+ obj = PyObject_GetAttrString(mm, \"sqrt\");\n+ if (obj == NULL) goto fail;\n+ funcdata = ((PyUFuncObject *)obj)->data;\n+ signatures = ((PyUFuncObject *)obj)->types;\n+ i = 0;\n+ j = 0;\n+ while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n+ _basic_float_sqrt = funcdata[j];\n+ _basic_double_sqrt = funcdata[j+1];\n+ _basic_longdouble_sqrt = funcdata[j+2];\n Py_DECREF(obj);\n+\n+ /* Get the abs functions */\n+ obj = PyObject_GetAttrString(mm, \"absolute\");\n+ if (obj == NULL) goto fail;\n+ funcdata = ((PyUFuncObject *)obj)->data;\n+ signatures = ((PyUFuncObject *)obj)->types;\n+ i = 0;\n+ j = 0;\n+ while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n+ _basic_float_abs = funcdata[j];\n+ _basic_double_abs = funcdata[j+1];\n+ _basic_longdouble_abs = funcdata[j+2];\n+ Py_DECREF(obj);\n+\n ret = 0;\n fail:\n Py_DECREF(mm);\n", + "added_lines": 50, + "deleted_lines": 11, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/ufuncobject.h\"\n#include \"numpy/arrayscalars.h\"\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZENAME=BYTE*2,SHORT*2,INT*2,LONG*2#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n**/\n#if SIZEOF_@SIZE@ > SIZEOF_@SIZENAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n\t generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n**/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n\tgenerate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #neg=(1,0)*5#\n**/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n if (b == 0) {\n\tgenerate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if (b == -1 && a < 0 && a == -a) {\n\tgenerate_overflow_error();\n\t*out = a / b;\n }\n#endif\n else {\n\t*out = a / b;\n }\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\nstatic void\n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {\n if (a == 0 || b == 0) {\n\tif (b == 0) generate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if ((a > 0) == (b > 0)) {\n\t*out = a % b;\n }\n else { /* handled like Python does */\n\t*out = a % b;\n\tif (*out) *out += b;\n }\n#else\n *out = a % b;\n#endif\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n**/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n *(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/* b will always be positive in this call */\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n \n}\n/**end repeat**/\n\n\n\n/* QUESTION: Should we check for overflow / underflow in (l,r)shift? */\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n**/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_floor)(@name@);\nstatic @name@ (*_basic_@name@_sqrt)(@name@);\nstatic @name@ (*_basic_@name@_abs)(@name@);\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) \\\n *(outp) = _basic_@name@_floor((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\\\n (outp)->real = (a).real + (b).real;\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\\\n (outp)->real = (a).real - (b).real;\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do {\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) /\t\\\n ((a).real*(b).real + (b).imag*(b).imag);\t\t\t\\\n (outp)->imag = 0;\t\t\t\t\t\t\\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - _basic_@name@_floor(a/b)*b;\n} \n/**end repeat**/ \n\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_ctype_divmod(a, b, out, out2) {\t\\\n @name@_ctype_floor_divide(a, b, out);\t\\\n @name@_ctype_remainder(a, b, out2);\t\t\\\n }\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_pow)(@name@ a, @name@ b);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = _basic_@name@_pow(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #uns=(1,0)*5,0*3#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n#if @uns@\n generate_overflow_error();\n#endif\n *out = -a;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n/* Get the nc_powf, nc_pow, and nc_powl functions from \n the data area of the power ufunc in umathmodule. \n*/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n out->real = a.real;\n out->imag = a.imag;\n}\nstatic void (*_basic_@name@_pow)(@name@ *, @name@ *, @name@ *);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out)\n{\n _basic_@name@_pow(&a, &b, out);\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=ubyte, ushort, uint, ulong, ulonglong#\n**/\n#define @name@_ctype_absolute @name@_ctype_positive\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte, short, int, long, longlong#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = (a < 0 ? -a : a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = _basic_@name@_abs(a);\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #rname= float, double, longdouble#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = _basic_@rname@_sqrt(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, floor_divide*6, true_divide*6, divmod*3, remainder*3#\n #fperr=1*70,0*50,1*52#\n #twoout=0*50,1*10,0*106,1*3,0*3#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*12, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*12, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n**/\n\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @twoout@\n @otyp@ out2;\n PyObject *obj;\n#endif\n\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @twoout@\n @name@_ctype_@oper@(arg1, arg2, &out, &out2);\n#else\n @name@_ctype_@oper@(arg1, arg2, &out);\n#endif\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n\n#if @twoout@\n ret = PyTuple_New(2);\n if (ret==NULL) return NULL;\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out;\n PyTuple_SET_ITEM(ret, 0, obj);\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out2;\n PyTuple_SET_ITEM(ret, 1, obj);\n#else\n ret = PyArrayScalar_New(@OName@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @OName@) = out;\n#endif\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float, double, longdouble, cfloat, cdouble, clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #otyp=float*4, double*6, float, double, longdouble, cfloat, cdouble, clongdouble#\n #OName=Float*4, Double*6, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #isint=(1,0)*5,0*6#\n #cmplx=0*13,1*3#\n**/\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n @otyp@ out1;\n int retstatus;\n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n }\n\n PyUFunc_clearfperr();\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @cmplx@\n if (arg2.real == 0 && arg1.real == 0) {\n\tout1.real = out.real = 1.0;\n\tout1.imag = out.imag = 0.0;\n }\n#else\n if (arg2 == 0) {\n\tout1 = out = 1;\n } \n#endif\n#if @isint@\n else if (arg2 < 0) {\n\t@name@_ctype_power(arg1, -arg2, &out);\n\tout1 = 1.0 / out;\n }\n#endif\n else {\n\t@name@_ctype_power(arg1, arg2, &out);\n }\n\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n\n#if @isint@\n if (arg2 < 0) {\n\tret = PyArrayScalar_New(@OName@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @OName@) = out1;\n }\n else {\n\tret = PyArrayScalar_New(@Name@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @Name@) = out;\n }\n#else\n ret = PyArrayScalar_New(@Name@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @Name@) = out;\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n#name=(cfloat,cdouble,clongdouble)*2#\n#oper=divmod*3,remainder*3#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3, byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*3, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n #oper=negative*16, positive*16, absolute*16, invert*10#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n#name=float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_invert NULL\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) {\n\tPyArrayScalar_RETURN_TRUE;\n }\n else {\n\tPyArrayScalar_RETURN_FALSE;\n }\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic int\nget_functions(void)\n{\n PyObject *mm, *obj;\n void **funcdata;\n char *signatures;\n int i, j;\n int ret = -1;\n\t\n /* Get the nc_pow functions */\n /* Get the pow functions */\n mm = PyImport_ImportModule(\"numpy.core.umath\");\n if (mm == NULL) return -1;\n \n obj = PyObject_GetAttrString(mm, \"power\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_pow = funcdata[j];\n _basic_double_pow = funcdata[j+1];\n _basic_longdouble_pow = funcdata[j+2];\n _basic_cfloat_pow = funcdata[j+3];\n _basic_cdouble_pow = funcdata[j+4];\n _basic_clongdouble_pow = funcdata[j+5];\n Py_DECREF(obj);\n\n /* Get the floor functions */\n obj = PyObject_GetAttrString(mm, \"floor\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n _basic_float_floor = funcdata[j];\n _basic_double_floor = funcdata[j+1];\n _basic_longdouble_floor = funcdata[j+2];\n Py_DECREF(obj);\n\n /* Get the sqrt functions */\n obj = PyObject_GetAttrString(mm, \"sqrt\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n _basic_float_sqrt = funcdata[j];\n _basic_double_sqrt = funcdata[j+1];\n _basic_longdouble_sqrt = funcdata[j+2];\n Py_DECREF(obj);\n\n /* Get the abs functions */\n obj = PyObject_GetAttrString(mm, \"absolute\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n _basic_float_abs = funcdata[j];\n _basic_double_abs = funcdata[j+1];\n _basic_longdouble_abs = funcdata[j+2];\n Py_DECREF(obj);\n\n ret = 0;\n fail:\n Py_DECREF(mm);\n return ret;\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n if (get_functions() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/ufuncobject.h\"\n#include \"numpy/arrayscalars.h\"\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZENAME=BYTE*2,SHORT*2,INT*2,LONG*2#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n**/\n#if SIZEOF_@SIZE@ > SIZEOF_@SIZENAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n\t generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n**/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n\tgenerate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #neg=(1,0)*5#\n**/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n if (b == 0) {\n\tgenerate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if (b == -1 && a < 0 && a == -a) {\n\tgenerate_overflow_error();\n\t*out = a / b;\n }\n#endif\n else {\n\t*out = a / b;\n }\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\nstatic void\n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {\n if (a == 0 || b == 0) {\n\tif (b == 0) generate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if ((a > 0) == (b > 0)) {\n\t*out = a % b;\n }\n else { /* handled like Python does */\n\t*out = a % b;\n\tif (*out) *out += b;\n }\n#else\n *out = a % b;\n#endif\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n**/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n *(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/* b will always be positive in this call */\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n \n}\n/**end repeat**/\n\n\n\n/* QUESTION: Should we check for overflow / underflow in (l,r)shift? */\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n**/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_floor)(@name@);\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) \\\n *(outp) = _basic_@name@_floor((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\\\n (outp)->real = (a).real + (b).real;\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\\\n (outp)->real = (a).real - (b).real;\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do {\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) /\t\\\n ((a).real*(b).real + (b).imag*(b).imag);\t\t\t\\\n (outp)->imag = 0;\t\t\t\t\t\t\\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - _basic_@name@_floor(a/b)*b;\n} \n/**end repeat**/ \n\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_ctype_divmod(a, b, out, out2) {\t\\\n @name@_ctype_floor_divide(a, b, out);\t\\\n @name@_ctype_remainder(a, b, out2);\t\t\\\n }\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_pow)(@name@ a, @name@ b);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = _basic_@name@_pow(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #uns=(1,0)*5,0*3#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n#if @uns@\n generate_overflow_error();\n#endif\n *out = -a;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n/* Get the nc_powf, nc_pow, and nc_powl functions from \n the data area of the power ufunc in umathmodule. \n*/\n\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n out->real = a.real;\n out->imag = a.imag;\n}\nstatic void (*_basic_@name@_pow)(@name@ *, @name@ *, @name@ *);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out)\n{\n _basic_@name@_pow(&a, &b, out);\n}\n/**end repeat**/\n\n\n\n#define NOP\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl# \n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = @fun@(a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #sqrt= sqrtf, sqrt, sqrtl#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = @sqrt@(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, floor_divide*6, true_divide*6, divmod*3, remainder*3#\n #fperr=1*70,0*50,1*52#\n #twoout=0*50,1*10,0*106,1*3,0*3#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*12, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*12, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n**/\n\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @twoout@\n @otyp@ out2;\n PyObject *obj;\n#endif\n\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @twoout@\n @name@_ctype_@oper@(arg1, arg2, &out, &out2);\n#else\n @name@_ctype_@oper@(arg1, arg2, &out);\n#endif\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n\n#if @twoout@\n ret = PyTuple_New(2);\n if (ret==NULL) return NULL;\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out;\n PyTuple_SET_ITEM(ret, 0, obj);\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out2;\n PyTuple_SET_ITEM(ret, 1, obj);\n#else\n ret = PyArrayScalar_New(@OName@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @OName@) = out;\n#endif\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float, double, longdouble, cfloat, cdouble, clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #otyp=float*4, double*6, float, double, longdouble, cfloat, cdouble, clongdouble#\n #OName=Float*4, Double*6, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #isint=(1,0)*5,0*6#\n #cmplx=0*13,1*3#\n**/\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n @otyp@ out1;\n int retstatus;\n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n }\n\n PyUFunc_clearfperr();\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @cmplx@\n if (arg2.real == 0 && arg1.real == 0) {\n\tout1.real = out.real = 1.0;\n\tout1.imag = out.imag = 0.0;\n }\n#else\n if (arg2 == 0) {\n\tout1 = out = 1;\n } \n#endif\n#if @isint@\n else if (arg2 < 0) {\n\t@name@_ctype_power(arg1, -arg2, &out);\n\tout1 = 1.0 / out;\n }\n#endif\n else {\n\t@name@_ctype_power(arg1, arg2, &out);\n }\n\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n\n#if @isint@\n if (arg2 < 0) {\n\tret = PyArrayScalar_New(@OName@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @OName@) = out1;\n }\n else {\n\tret = PyArrayScalar_New(@Name@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @Name@) = out;\n }\n#else\n ret = PyArrayScalar_New(@Name@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @Name@) = out;\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n#name=(cfloat,cdouble,clongdouble)*2#\n#oper=divmod*3,remainder*3#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3, byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*3, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n #oper=negative*16, positive*16, absolute*16, invert*10#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n#name=float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_invert NULL\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) {\n\tPyArrayScalar_RETURN_TRUE;\n }\n else {\n\tPyArrayScalar_RETURN_FALSE;\n }\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic int\nget_functions(void)\n{\n PyObject *mm, *obj;\n void **funcdata;\n char *signatures;\n int i, j;\n int ret = -1;\n\t\n /* Get the nc_pow functions */\n /* Get the pow functions */\n mm = PyImport_ImportModule(\"numpy.core.umath\");\n if (mm == NULL) return -1;\n \n obj = PyObject_GetAttrString(mm, \"power\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_pow = funcdata[j];\n _basic_double_pow = funcdata[j+1];\n _basic_longdouble_pow = funcdata[j+2];\n _basic_cfloat_pow = funcdata[j+3];\n _basic_cdouble_pow = funcdata[j+4];\n _basic_clongdouble_pow = funcdata[j+5];\n\n Py_DECREF(obj);\n\n /* Get the floor functions */\n\n obj = PyObject_GetAttrString(mm, \"floor\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_floor = funcdata[j];\n _basic_double_floor = funcdata[j+1];\n _basic_longdouble_floor = funcdata[j+2];\n\n Py_DECREF(obj);\n ret = 0;\n fail:\n Py_DECREF(mm);\n return ret;\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n if (get_functions() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "static @name@ (*_basic_@name@_sqrt)(@name@);", + "static @name@ (*_basic_@name@_abs)(@name@);", + "/**begin repeat", + " #name=ubyte, ushort, uint, ulong, ulonglong#", + "**/", + "#define @name@_ctype_absolute @name@_ctype_positive", + "/**end repeat**/", + "", + " #name=byte, short, int, long, longlong#", + " *out = (a < 0 ? -a : a);", + "/**begin repeat", + " #name=float, double, longdouble#", + "**/", + "static void", + "@name@_ctype_absolute(@name@ a, @name@ *out)", + "{", + " *out = _basic_@name@_abs(a);", + "}", + "/**end repeat**/", + "", + "", + " #rname= float, double, longdouble#", + " out->real = _basic_@rname@_sqrt(a.real*a.real + a.imag*a.imag);", + " while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}", + " Py_DECREF(obj);", + " /* Get the sqrt functions */", + " obj = PyObject_GetAttrString(mm, \"sqrt\");", + " if (obj == NULL) goto fail;", + " funcdata = ((PyUFuncObject *)obj)->data;", + " signatures = ((PyUFuncObject *)obj)->types;", + " i = 0;", + " j = 0;", + " while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}", + " _basic_float_sqrt = funcdata[j];", + " _basic_double_sqrt = funcdata[j+1];", + " _basic_longdouble_sqrt = funcdata[j+2];", + "", + " /* Get the abs functions */", + " obj = PyObject_GetAttrString(mm, \"absolute\");", + " if (obj == NULL) goto fail;", + " funcdata = ((PyUFuncObject *)obj)->data;", + " signatures = ((PyUFuncObject *)obj)->types;", + " i = 0;", + " j = 0;", + " while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}", + " _basic_float_abs = funcdata[j];", + " _basic_double_abs = funcdata[j+1];", + " _basic_longdouble_abs = funcdata[j+2];", + " Py_DECREF(obj);", + "" + ], + "deleted": [ + "", + "#define NOP", + " #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#", + " #fun= abs, NOP, abs, NOP, abs, NOP, labs, NOP, llabs, NOP, fabsf, fabs, fabsl#", + " *out = @fun@(a);", + " #sqrt= sqrtf, sqrt, sqrtl#", + " out->real = @sqrt@(a.real*a.real + a.imag*a.imag);", + "", + "", + "", + " while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}" + ] + } + } + ] + }, + { + "hash": "f6a6d8fde5eb4a02505c02980b74812f26d16642", + "msg": "Implement int, float, long, oct, hex", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-04-29T22:32:00+00:00", + "author_timezone": 0, + "committer_date": "2006-04-29T22:32:00+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "f399dfcc9cdbc454522c69852e188f2907364bfa" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 4, + "insertions": 34, + "lines": 38, + "files": 2, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/core/src/arrayobject.c", + "new_path": "numpy/core/src/arrayobject.c", + "filename": "arrayobject.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -9123,8 +9123,17 @@ arraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n \t\tconv = NULL;\n \t\tif PyDict_Check(odescr)\n \t\t\tconv = _convert_from_dict(odescr, 1);\n-\t\telse if PyList_Check(odescr)\n+\t\telse if PyList_Check(odescr) {\n \t\t\tconv = _convert_from_list(odescr, 1, 0);\n+\t\t\tif ((conv == NULL) && \n+\t\t\t (!PyErr_Occurred())) {\n+\t\t\t\tPyErr_SetString(PyExc_ValueError,\n+\t\t\t\t\t\t\"cannot specify align=1 \"\\\n+\t\t\t\t\t\t\"with array_descriptor \"\\\n+\t\t\t\t\t\t\"specification of the data-\"\\\n+\t\t\t\t\t\t\"type.\");\n+\t\t\t}\n+\t\t}\n \t\telse if PyString_Check(odescr)\n \t\t\tconv = _convert_from_commastring(odescr, 1);\n \t\telse {\n", + "added_lines": 10, + "deleted_lines": 1, + "source_code": "/*\n Provide multidimensional arrays as a basic object type in python.\n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004\n\nHeavily modified in 2005 with inspiration from Numarray\n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University\n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by\nSpace Science Telescope Institute\n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_)\n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear();\n priority = default_;\n }\n Py_XDECREF(ret);\n return priority;\n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a\n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n }\n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int\ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides,\n\t intp *src_dimensions, int src_nd, int elsize,\n\t int copies) {\n intp i, j;\n\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1,\n dest_dimensions+1, dest_nd-1,\n src, src_strides,\n src_dimensions, src_nd,\n elsize, copies) == -1)\n return -1;\n }\n return 0;\n }\n\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError,\n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) &&\n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] !=\n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src)\n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\n dest_strides_ptr = dest_strides;\n\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1)\n return NULL;\n\n new_data = (char *)_pya_malloc(stride);\n\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions,\n dest_nd, src->data, src_strides,\n src_dimensions, src_nd, elsize, copies);\n\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *,\n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int\nPyArray_INCREF(PyArrayObject *mp)\n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap)\n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n\n\n if ((numitems == 1) || (itemsize == srcstrides))\n memcpy(d1, s1, itemsize*numitems);\n else {\n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n }\n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG\n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i)\n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp\nPyArray_Size(PyObject *op)\n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n }\n\telse {\n return 0;\n }\n}\n\nstatic void\n_strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides, \n\t\t\t intp N, int elsize)\n{\n intp i, j;\n char *tout = dst;\n char *tin = src;\n\n#define _FAST_MOVE(_type_)\t\t\t\t \\\n\tfor (i=0; idescr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n\n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, dest);\n PyArray_INCREF(dest);\n return 0;\n }\n \n /* See if we can iterate over the largest dimension */\n if (!swap && (nd = dest->nd) == src->nd && (nd > 0) && \n PyArray_CompareLists(dest->dimensions, src->dimensions, nd)) { \n int maxaxis=0, maxdim=dest->dimensions[0];\n int i;\n for (i=1; idimensions[i] > maxdim) {\n maxaxis = i;\n maxdim = dest->dimensions[i];\n }\n }\n\n dit = (PyArrayIterObject *) \\\n PyArray_IterAllButAxis((PyObject *)dest, maxaxis);\n sit = (PyArrayIterObject *) \\\n PyArray_IterAllButAxis((PyObject *)src, maxaxis);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n index = dit->size;\n\t\tif (PyArray_ISALIGNED(dest) && PyArray_ISALIGNED(src)) {\n\t\t\twhile(index--) {\n\t\t\t\t/* strided copy of elsize bytes */\n\t\t\t\t_strided_byte_copy(dit->dataptr, \n\t\t\t\t\t\t dest->strides[maxaxis],\n\t\t\t\t\t\t sit->dataptr, \n\t\t\t\t\t\t src->strides[maxaxis],\n\t\t\t\t\t\t maxdim, elsize);\n\t\t\t\tPyArray_ITER_NEXT(dit);\n\t\t\t\tPyArray_ITER_NEXT(sit);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\twhile(index--) {\n\t\t\t\t/* strided copy of elsize bytes */\n\t\t\t\t_unaligned_strided_byte_copy(dit->dataptr, \n\t\t\t\t\t\t\t dest->strides[maxaxis],\n\t\t\t\t\t\t\t sit->dataptr, \n\t\t\t\t\t\t\t src->strides[maxaxis],\n\t\t\t\t\t\t\t maxdim, elsize);\n\t\t\t\tPyArray_ITER_NEXT(dit);\n\t\t\t\tPyArray_ITER_NEXT(sit);\n\t\t\t}\n\t\t}\t\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n return 0; \n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n\t\t\tmemmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, dest);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n }\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int\nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)\n{\n PyArrayObject *src;\n int ret;\n\t\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d,\n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t} \n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, PyArray_ORDER fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran == PyArray_ANYORDER) \n\t\tfortran = PyArray_ISFORTRAN(m1);\n \n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,\n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd,\n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran,\n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\n return (PyObject *)ret;\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif PyTypeNum_ISSTRING(type_num) { /* Eliminate NULL bytes */\n\t\tchar *dptr = data;\n\t\tdptr += itemsize-1;\n\t\twhile(itemsize && *dptr-- == 0) itemsize--;\n\t\tif (type_num == PyArray_UNICODE && itemsize) {\n\t\t\t/* make sure itemsize is a multiple of 4 */\n\t\t\t/* so round up to nearest multiple */\n\t\t\titemsize = (((itemsize-1) >> 2) + 1) << 2;\n\t\t}\n\t}\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) {\n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED;\n\t\t\tmemcpy(destptr, data, itemsize);\n\t\t\treturn obj;\n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=0;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use\n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE,length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifdef Py_UNICODE_WIDE\n\t\t\tmemcpy(destptr, data, itemsize);\n\t\t\tif (swap)\n\t\t\t\tbyte_swap_vector(destptr, length, 4);\n#else\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, \n\t\t\t\t\t\t\t itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, \n\t\t\t\t\t\t (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n#endif\n\t\t\treturn obj;\n\t\t}\n\t\telse {\n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, base);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this.\n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag\n*/\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp)\n{\n\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n\n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int\nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs,\n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/*\n copyies over from the old descr table for anything\n NULL or zero in what is given.\n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)\n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data,\n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError,\n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr,\n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element\"\\\n \" %d to file\",\n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj);\n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj),\n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\",\n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1) \n if (fwrite(sep, 1, n3, fp) < n3) {\n\t\t\t\t\tPyErr_Format(PyExc_IOError,\n\t\t\t\t\t\t \"problem writing \"\\\n\t\t\t\t\t\t \"separator to file\");\n\t\t\t\t\tPy_DECREF(strobj);\n\t\t\t\t\tPy_DECREF(it);\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self)\n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0)\n\t\treturn self->descr->f->getitem(self->data,self);\n\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n\n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void\narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an\n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE\n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n\n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\narray_length(PyArrayObject *self)\n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i)\n{\n\tchar *item;\n\tPyArrayObject *r;\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1,\n\t\t\t\t\t\t self->dimensions+1,\n\t\t\t\t\t\t self->strides+1, item,\n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\n/* contains optimization for 1-d arrays */\nstatic PyObject *\narray_item_nice(PyArrayObject *self, _int_or_ssize_t i)\n{\n\tif (self->nd == 1) {\n\t\tchar *item;\n if (i < 0) {\n\t\t\ti += self->dimensions[0];\n\t\t}\n\t\tif ((item = index2ptr(self, i)) == NULL) return NULL;\n\t\treturn PyArray_Scalar(item, self->descr, (PyObject *)self);\n\t}\n\telse {\n\t\treturn PyArray_Return((PyArrayObject *)\\\n\t\t\t\t array_big_item(self, (intp) i));\n\t}\n}\n\nstatic int\narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v)\n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret;\n }\n\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if PY_VERSION_HEX < 0x02050000\n #if SIZEOF_INT == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#else\n #if SIZEOF_SIZE_T == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#endif\n#ifndef array_ass_item\nstatic int\narray_ass_item(PyArrayObject *self, _int_or_ssize_t i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int\nparse_index(PyArrayObject *self, PyObject *op,\n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError,\n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\n nd_old = nd_new = 0;\n\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n PyArrayObject *arr;\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n /* arr might not have the right number of dimensions\n and need to be reshaped first by pre-pending ones */\n arr = *ret; \n if (arr->nd != mit->nd) {\n for (i=1; i<=arr->nd; i++) {\n permute.ptr[mit->nd-i] = arr->dimensions[arr->nd-i];\n }\n for (i=0; ind-arr->nd; i++) {\n permute.ptr[i] = 1;\n } \n new = PyArray_Newshape(arr, &permute, PyArray_ANYORDER);\n Py_DECREF(arr);\n *ret = (PyArrayObject *)new;\n if (new == NULL) return;\n }\n\n\t/* tuple for transpose is\n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of\n\t the broadcasted index array\n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the\n\t result\n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2)\n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call.\n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type,\n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret))\n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t\tif (arr == NULL) return -1;\n\t\t}\n\t}\n\t\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, arr);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS];\n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL)\n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0\n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from\n Python when using a[object] unless object is a standard slice object\n (not an extended one).\n\n*/\n\n/* There are two situations:\n\n 1 - the subscript is a standard view and a reference to the\n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned.\n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *);\n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op)\n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr,\n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis) {\n\t\t\t/* XXX: This leads to a small inconsistency\n\t\t\t XXX: with the nd>0 case where (x[...] is x)\n\t\t\t XXX: is false for nd>0 case. */\n\t\t\tPy_INCREF(self);\n\t\t\treturn (PyObject *)self;\n\t\t}\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op)) {\n\t\t\t\tPy_INCREF(self);\n\t\t\t\treturn (PyObject *)self;\n\t\t\t}\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset))\n == -1)\n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset,\n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL)\n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be\n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *);\n\nstatic int\narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)\n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr,\n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1;\n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to\n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op)\n{\n\t/* The following is just a copy of PyArray_Return with an\n\t additional logic in the nd == 0 case. More efficient\n\t implementation may be possible by refactoring\n\t array_subscript */\n\n\tPyArrayObject *mp;\n\n\t/* optimization for integer select and 1-d */\n\tif (self->nd == 1 && (PyInt_Check(op) || PyLong_Check(op))) {\n intp value;\n\t\tchar *item;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred()) \n\t\t\treturn NULL;\n else if (value < 0) {\n\t\t\tvalue += self->dimensions[0];\n\t\t}\n\t\tif ((item = index2ptr(self, value)) == NULL) return NULL;\n\t\treturn PyArray_Scalar(item, self->descr, (PyObject *)self);\n\t}\n\tmp = (PyArrayObject *)array_subscript(self, op);\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tBool noellipses = TRUE;\n\t\tif (op == Py_Ellipsis)\n\t\t\tnoellipses = FALSE;\n\t\telse if (PySequence_Check(op)) {\n\t\t\tint n, i;\n\t\t\tn = PySequence_Size(op);\n\t\t\tfor (i = 0; i < n; ++i) \n\t\t\t\tif (PySequence_GetItem(op, i) == Py_Ellipsis) {\n\t\t\t\t\tnoellipses = FALSE;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t\tif (noellipses) {\n\t\t\tPyObject *ret;\n\t\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\t\tPy_DECREF(mp);\n\t\t\treturn ret;\n\t\t}\n\t}\n\treturn (PyObject *)mp;\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t /*mp_length*/\n#else\n (inquiry)array_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic _int_or_ssize_t\narray_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp)\n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic _int_or_ssize_t\narray_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"accessing non-existing array segment\");\n return -1;\n }\n\n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic _int_or_ssize_t\narray_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (PyArray_CHKFLAGS(self, WRITEABLE))\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic _int_or_ssize_t\narray_getcharbuf(PyArrayObject *self, _int_or_ssize_t segment, const char **ptrptr)\n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError,\n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (writebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (segcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (charbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#else\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#endif\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n *square,\n *reciprocal,\n *ones_like,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum,\n\t\t*rint;\n} NumericOps;\n\nstatic NumericOps n_ops; /* NB: static objects inlitialized to zero */\n\n/* Dictionary can contain any of the numeric operations, by name.\n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n\n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint\nPyArray_SetNumericOps(PyObject *dict)\n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n SET(square);\n SET(reciprocal);\n SET(ones_like);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\n SET(true_divide);\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n\tSET(rint);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void)\n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL)\n\t\treturn NULL;\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n GET(square);\n GET(reciprocal);\n GET(ones_like);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide);\n GET(true_divide);\n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\tGET(rint);\n\treturn dict;\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,\n\t\t\t\t PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2)\n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic int\narray_power_is_scalar(PyObject *o2, double* exp)\n{\n PyObject *temp;\n const int optimize_fpexps = 1;\n\n if (PyInt_Check(o2)) {\n\t *exp = (double)PyInt_AsLong(o2);\n\t return 1;\n }\n if (optimize_fpexps && PyFloat_Check(o2)) {\n\t *exp = PyFloat_AsDouble(o2);\n\t return 1;\n }\n if ((PyArray_IsZeroDim(o2) && \n\t ((PyArray_ISINTEGER(o2) || \n\t (optimize_fpexps && PyArray_ISFLOAT(o2))))) || \n\tPyArray_IsScalar(o2, Integer) || \n\t(optimize_fpexps && PyArray_IsScalar(o2, Floating))) {\n\t temp = o2->ob_type->tp_as_number->nb_float(o2);\n\t if (temp != NULL) {\n\t\t *exp = PyFloat_AsDouble(o2);\n\t\t Py_DECREF(temp);\n\t\t return 1;\n\t }\n }\n return 0;\n}\n\n/* optimize float array or complex array to a scalar power */\nstatic PyObject *\nfast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) {\n\tdouble exp;\n\tif (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) || \n\t\t\t\t PyArray_ISCOMPLEX(a1))) {\n\t\tif (array_power_is_scalar(o2, &exp)) {\n\t\t\tPyObject *fastop = NULL;\n\t\t\tif (exp == 1.0) {\n\t\t\t\t/* we have to do this one special, as the \n\t\t\t\t \"copy\" method of array objects isn't set \n\t\t\t\t up early enough to be added\n\t\t\t\t by PyArray_SetNumericOps.\n\t\t\t\t*/\n\t\t\t\tif (inplace) {\n\t\t\t\t\treturn (PyObject *)a1;\n\t\t\t\t} else {\n\t\t\t\t\treturn PyArray_Copy(a1);\n\t\t\t\t}\n\t\t\t} else if (exp == -1.0) {\n\t\t\t\tfastop = n_ops.reciprocal;\n\t\t\t} else if (exp == 0.0) {\n\t\t\t\tfastop = n_ops.ones_like;\n\t\t\t} else if (exp == 0.5) {\n\t\t\t\tfastop = n_ops.sqrt;\n\t\t\t} else if (exp == 2.0) {\n\t\t\t\tfastop = n_ops.square;\n\t\t\t} else {\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tif (inplace) {\n\t\t\t\tPyArray_GenericInplaceUnaryFunction(a1, \n\t\t\t\t\t\t\t\t fastop);\n\t\t\t} else {\n\t\t\t\treturn PyArray_GenericUnaryFunction(a1, \n\t\t\t\t\t\t\t\t fastop);\n\t\t\t}\n\t\t}\n\t}\n\treturn NULL;\n}\n\nstatic PyObject *\narray_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n\t/* modulo is ignored! */\n\tPyObject *value;\n\tvalue = fast_scalar_power(a1, o2, 0);\n\tif (!value) {\n\t\tvalue = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);\n\t}\n\treturn value;\n}\n\n\nstatic PyObject *\narray_negative(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 1);\n if (!value) {\n value = PyArray_GenericInplaceBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int\narray_any_nonzero(PyArrayObject *mp)\n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2)\n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_float(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to a \"\\\n\t\t\t\t\"float; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_long(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/\n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected\n*/\n\n\nstatic PyObject *\narray_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t _int_or_ssize_t ihigh)\n{\n PyArrayObject *r;\n _int_or_ssize_t l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n self->dimensions[0] = l;\n\tif (r == NULL) return NULL;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS);\n return (PyObject *)r;\n}\n\n\nstatic int\narray_ass_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t\t_int_or_ssize_t ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res;\n int ret;\n\t\n res = PyArray_EnsureAnyArray(PyObject_RichCompare((PyObject *)self, \n\t\t\t\t\t\t\t el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\nstatic PySequenceMethods array_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (ssizeargfunc)NULL,\n\t(ssizeargfunc)array_item_nice,\n\t(ssizessizeargfunc)array_slice,\n (ssizeobjargproc)array_ass_item,\t /*sq_ass_item*/\n (ssizessizeobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(ssizeargfunc)NULL,\n#else\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t /*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n#endif\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int\ndump_data(char **string, int *n, int *max_n, char *data, int nd,\n intp *dimensions, intp *strides, PyArrayObject* self)\n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\n if (nd == 0) {\n\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata,\n\t\t self->nd, self->dimensions,\n self->strides, self) < 0) {\n\t\t_pya_free(string); return NULL;\n\t}\n\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void\nPyArray_SetStringFunction(PyObject *op, int repr)\n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_ReprFunction = op;\n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_StrFunction = op;\n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\n\n\n/*OBJECT_API\n */\nstatic int\nPyArray_CompareUCS4(PyArray_UCS4 *s1, PyArray_UCS4 *s2, register size_t len)\n{\n register PyArray_UCS4 c1, c2;\n while(len-- > 0) {\n c1 = *s1++;\n c2 = *s2++;\n if (c1 != c2) {\n return (c1 < c2) ? -1 : 1;\n\t\t}\n }\n\treturn 0;\n}\n\nstatic int\n_myunincmp(PyArray_UCS4 *s1, PyArray_UCS4 *s2, int len1, int len2)\n{\n\tPyArray_UCS4 *sptr;\n\tint val;\n\n\tval = PyArray_CompareUCS4(s1, s2, MIN(len1, len2));\n\tif ((val != 0) || (len1 == len2)) return val;\n\tif (len2 > len1) {sptr = s2+len1; val = -1;}\n\telse {sptr = s1+len2; val = 1;}\n\tif (*sptr != 0) return val;\n\n\tif (len2 > len1) {sptr = s2; val = -1;}\n\telse {sptr = s1; val = 1;}\n\tif (*sptr != 0) return val;\n\treturn 0;\n}\n\n\n\n/* Compare s1 and s2 which are not necessarily NULL-terminated. \n s1 is of length len1\n s2 is of length len2\n If they are NULL terminated, then stop comparison.\n*/\nstatic int\n_mystrncmp(char *s1, char *s2, int len1, int len2)\n{\n\tchar *sptr;\n\tint val;\n\n\tval = strncmp(s1, s2, MIN(len1, len2));\n\tif ((val != 0) || (len1 == len2)) return val;\n\tif (len2 > len1) {sptr = s2+len1; val = -1;}\n\telse {sptr = s1+len2; val = 1;}\n\tif (*sptr != 0) return val;\n\treturn 0;\n}\n\nstatic int\n_compare_strings(PyObject *result, PyArrayMultiIterObject *multi, \n\t\t int cmp_op, void *func)\n{\n\tPyArrayIterObject *iself, *iother;\n\tBool *dptr;\n\tintp size;\n\tint val;\n\tint N1, N2;\n\tint (*cmpfunc)(void *, void *, int, int);\n\t\n\tcmpfunc = func;\n\tdptr = (Bool *)PyArray_DATA(result);\n\tiself = multi->iters[0];\n\tiother = multi->iters[1];\n\tsize = multi->size;\n\tN1 = iself->ao->descr->elsize;\n\tN2 = iother->ao->descr->elsize;\n\tif ((void *)cmpfunc == (void *)_myunincmp) {\n\t\tN1 >>= 2;\n\t\tN2 >>= 2;\n\t}\n\twhile(size--) {\n\t\tval = cmpfunc((void *)iself->dataptr, (void *)iother->dataptr, \n\t\t\t N1, N2);\n\t\tswitch (cmp_op) {\n\t\tcase Py_EQ:\n\t\t\t*dptr = (val == 0);\n\t\t\tbreak;\n\t\tcase Py_NE:\n\t\t\t*dptr = (val != 0);\n\t\t\tbreak;\n\t\tcase Py_LT:\n\t\t\t*dptr = (val < 0);\n\t\t\tbreak;\n\t\tcase Py_LE:\n\t\t\t*dptr = (val <= 0);\n\t\t\tbreak;\n\t\tcase Py_GT:\n\t\t\t*dptr = (val > 0);\n\t\t\tbreak;\n\t\tcase Py_GE:\n\t\t\t*dptr = (val >= 0);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"bad comparison operator\");\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_NEXT(iself);\n\t\tPyArray_ITER_NEXT(iother);\n\t\tdptr += 1;\n\t}\n\treturn 0;\t\n}\n\nstatic PyObject *\n_strings_richcompare(PyArrayObject *self, PyArrayObject *other, int cmp_op)\n{\n PyObject *result;\n\tPyArrayMultiIterObject *mit;\n\tint val;\n\n /* Cast arrays to a common type */ \n if (self->descr->type != other->descr->type) {\n PyObject *new;\n if (self->descr->type_num == PyArray_STRING && \\\n other->descr->type_num == PyArray_UNICODE) {\n Py_INCREF(other);\n Py_INCREF(other->descr);\n new = PyArray_FromAny((PyObject *)self, other->descr, \n\t\t\t\t\t 0, 0, 0, NULL);\n if (new == NULL) return NULL;\n self = (PyArrayObject *)new;\n }\n else if (self->descr->type_num == PyArray_UNICODE &&\t\\\n other->descr->type_num == PyArray_STRING) {\n Py_INCREF(self);\n Py_INCREF(self->descr);\n new = PyArray_FromAny((PyObject *)other, self->descr, \n\t\t\t\t\t 0, 0, 0, NULL);\n if (new == NULL) return NULL;\n other = (PyArrayObject *)new;\n }\n else {\n PyErr_SetString(PyExc_TypeError, \n \"invalid string data-types \"\n \"in comparison\");\n return NULL;\n }\n }\n else { \n Py_INCREF(self);\n Py_INCREF(other);\n }\n\n /* Broad-cast the arrays to a common shape */\n mit = (PyArrayMultiIterObject *)PyArray_MultiIterNew(2, self, other);\n\tPy_DECREF(self);\n\tPy_DECREF(other);\n if (mit == NULL) return NULL;\n\t\n\tresult = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t PyArray_DescrFromType(PyArray_BOOL),\n\t\t\t\t mit->nd,\n\t\t\t\t mit->dimensions,\n\t\t\t\t NULL, NULL, 0, \n\t\t\t\t NULL);\n\tif (result == NULL) goto finish;\n\n\tif (self->descr->type_num == PyArray_STRING) {\n\t\tval = _compare_strings(result, mit, cmp_op, _mystrncmp);\n\t}\n\telse {\n\t\tval = _compare_strings(result, mit, cmp_op, _myunincmp);\n\t}\n\t\n\tif (val < 0) {Py_DECREF(result); result = NULL;}\n\t\n finish: \n\tPy_DECREF(mit);\n return result;\n}\n\n/* What do we do about VOID type arrays?\n */\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)\n{\n PyObject *array_other, *result = NULL;\n\tint typenum;\n\n switch (cmp_op)\n {\n case Py_LT:\n result = PyArray_GenericBinaryFunction(self, other,\n n_ops.less);\n break;\n case Py_LE:\n result = PyArray_GenericBinaryFunction(self, other,\n n_ops.less_equal);\n break;\n case Py_EQ:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then return False\n\t\t\t\t This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of False\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the\n\t\t\t two array objects can not be compared together so\n\t\t\t return zero\n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n break;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be\n\t\t\t\t compared and cannot be equal, therefore,\n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n break;\n case Py_GT:\n result = PyArray_GenericBinaryFunction(self, other,\n n_ops.greater);\n break;\n case Py_GE:\n result = PyArray_GenericBinaryFunction(self, other,\n n_ops.greater_equal);\n break;\n default:\n result = Py_NotImplemented;\n Py_INCREF(result);\n }\n if (result == Py_NotImplemented) {\n /* Try to handle string comparisons */\n if (self->descr->type_num == PyArray_OBJECT) return result;\n array_other = PyArray_FromObject(other,PyArray_NOTYPE, 0, 0);\n if (PyArray_ISSTRING(self) && PyArray_ISSTRING(array_other)) {\n result = _strings_richcompare(self, (PyArrayObject *)\n\t\t\t\t\t\t array_other, cmp_op);\n }\n Py_DECREF(array_other);\n }\n return result;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\tif (temp) *axis = PyArray_NDIM(temp)-1;\n\t\telse *axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL,\n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int\n_IsFortranContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap)\n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object\n\t If it is a writeable array, then return TRUE\n\t If we can find an array object\n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable\n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA))\n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly\n\t and unpickled array can be set and reset writeable\n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t\telse ret->flags &= ~WRITEABLE;\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not\n ever be able to walk outside of the memory implied numbytes and offset.\n\n The available memory is assumed to start at -offset and proceed\n to numbytes-offset. The strides are checked to ensure\n that accessing memory using striding will not try to reach beyond\n this memory for any of the axes.\n\n If numbytes is 0 it will be calculated using the dimensions and\n element-size.\n\n This function checks for walking beyond the beginning and right-end\n of the buffer and therefore works for any integer stride (positive\n or negative).\n*/\n\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\tintp byte_begin;\n\tintp begin;\n\tintp end;\n\n\tif (numbytes == 0)\n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\n\tbegin = -offset;\n\tend = numbytes - offset - elsize;\n\tfor (i=0; i end))\n\t\t\treturn FALSE;\n\t}\n\treturn TRUE;\n\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings\n depending on data and strides:\n\n If data is given, then flags is flags associated with data.\n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument\n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set).\n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired.\n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize,\n\t\t int inflag, int *objflags)\n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\n/* and update the dimensions and strides\n appropriately. Dimensions and strides are added\n to the end unless we have a FORTRAN array\n and then they are added to the beginning\n\n Strides are only added if given (because data is given).\n*/\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,\n\t\t\t intp *newstrides, int oldnd, int isfortran)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\tint tuple;\n\n\told = *des;\n\t*des = old->subarray->base;\n\n\n\tmydim = newdims + oldnd;\n\ttuple = PyTuple_Check(old->subarray->shape);\n\tif (tuple) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t}\n\telse {\n\t\tnumnew = 1;\n\t}\n\n\n\tnewnd = oldnd + numnew;\n\tif (newnd > MAX_DIMS) goto finish;\n\tif (isfortran) {\n\t\tmemmove(newdims+numnew, newdims, oldnd*sizeof(intp));\n\t\tmydim = newdims;\n\t}\n\n\tif (tuple) {\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\tif (isfortran) {\n\t\t\tmemmove(newstrides+numnew, newstrides,\n\t\t\t\toldnd*sizeof(intp));\n\t\t\tmystrides = newstrides;\n\t\t}\n\t\t/* Make new strides -- alwasy C-contiguous */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\n finish:\n\tPy_INCREF(*des);\n\tPy_DECREF(old);\n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,\n\t\t intp *dims, intp *strides, void *data,\n\t\t int flags, PyObject *obj)\n{\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tint isfortran=0;\n\t\tisfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || \\\n\t\t\t(!data && flags);\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims,\n\t\t\t\t\t\t newstrides, nd, isfortran);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims,\n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { \n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN;\n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse { /* we allow strides even when we create\n\t\t\t the memory, but be careful with this...\n\t\t */\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n\telse { self->dimensions = self->strides = NULL; }\n\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays\n\t\t e.g. shape=(0,) -- otherwise buffer exposure\n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in,\n\t\t\t\t\t this object won't own it\n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for\n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype.\n\t If obj is NULL, then call method with Py_None \n\t*/\n\tif ((subtype != &PyArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (strides != NULL) { /* did not allocate own data \n\t\t\t\t\t or funny strides */\n\t\t\t/* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tif (obj == NULL) obj=Py_None;\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n If refcheck is 0, then the reference count is not checked\n and assumed to be 1.\n You still must own this data and have no weak-references and no base\n object.\n*/\nstatic PyObject *\nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck,\n\t PyArray_ORDER fortran)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\n if (!PyArray_ISONESEGMENT(self)) {\n PyErr_SetString(PyExc_ValueError,\n \"resize only works on single-segment arrays\");\n return NULL;\n }\n\n\tif (fortran == PyArray_ANYORDER)\n\t\tfortran = PyArray_CORDER;\n \n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n\n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (refcheck) refcnt = REFCOUNT(self);\n\t\telse refcnt = 1;\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (newsize == 0) sd = self->descr->elsize;\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n\n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) {\n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0,\n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n\n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n\n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n self->flags, &(self->flags));\n\n\n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\n return Py_None;\n\n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\tPyArray_FillWithScalarFunc* fillwithscalar =\n\t\t\tarr->descr->f->fillwithscalar;\n\t\tif (fillwithscalar && PyArray_ISALIGNED(arr)) {\n\t\t\tcopyswap(fromptr, NULL, swap, arr);\n\t\t\tfillwithscalar(toptr, size, fromptr, arr);\n\t\t}\n\t\telse {\n\t\t\twhile (size--) {\n\t\t\t\tcopyswap(toptr, fromptr, swap, arr);\n\t\t\t\ttoptr += itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, arr);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"order\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n PyArray_ORDER order=PyArray_CORDER;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL;\n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous\n\t array of a specific type and shape.\n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims,\n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter,\n &strides,\n &PyArray_OrderConverter,\n &order))\n\t\tgoto fail;\n\n if (order == PyArray_FORTRANORDER) fortran = 1;\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"data-type with unspecified variable length\");\n\t\tgoto fail;\n\t}\n\t\n\tif (strides.ptr != NULL) {\n\t\tintp nb, off;\n\t\tif (strides.len != dims.len) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides, if given, must be \"\t\\\n\t\t\t\t\t\"the same length as shape\");\n\t\t\tgoto fail;\n\t\t}\n\n\t\tif (buffer.ptr == NULL) {\n\t\t\tnb = 0;\n\t\t\toff = 0;\n\t\t}\n\t\telse {\n\t\t\tnb = buffer.len;\n\t\t\toff = offset;\n\t\t}\n\t\t\n\n\t\tif (!PyArray_CheckStrides(itemsize, dims.len, \n\t\t\t\t\t nb, off,\n\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides is incompatible \"\t\\\n\t\t\t\t\t\"with shape of requested \"\t\\\n\t\t\t\t\t\"array and size of buffer\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\t\t\t\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len,\n\t\t\t\t\t dims.ptr,\n\t\t\t\t\t strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = (buffer.len-offset) / itemsize;\n }\n else if ((strides.ptr == NULL) && \\\n\t\t\t buffer.len < itemsize*\t\t\t\t\\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError,\n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t offset + (char *)buffer.ptr,\n\t\t\t\t\t buffer.flags, NULL);\n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base);\n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyArray_NewFlagsObject((PyObject *)self);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n\tint nd;\n\tPyObject *ret;\n\n /* Assumes C-order */\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n if (PyArray_DATA(ret) != PyArray_DATA(self)) {\n Py_DECREF(ret);\n PyErr_SetString(PyExc_AttributeError, \n \"incompatible shape for a non-contiguous array\");\n return -1;\n }\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret),\n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret),\n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes=0;\n\tintp offset=0;\n\tint buf_len;\n\tchar *buf;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base && PyArray_Check(new->base)) {\n\t\tnew = (PyArrayObject *)(new->base);\n\t}\n\t/* Get the available memory through the buffer\n\t interface on new->base or if that fails\n\t from the current new */\n\tif (new->base && PyObject_AsReadBuffer(new->base,\n\t\t\t\t\t (const void **)&buf,\n\t\t\t\t\t &buf_len) >= 0) {\n\t\toffset = self->data - buf;\n\t\tnumbytes = buf_len + offset;\n\t}\n\telse {\n\t\tPyErr_Clear();\n \t\tnumbytes = PyArray_MultiplyList(new->dimensions,\n\t\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\toffset = self->data - new->data;\n\t}\n\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes,\n\t\t\t\t offset,\n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self))\n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self)\n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0,\n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf,\n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse\n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse\n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed.\n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the\n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0)\n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n\telse if (newtype->elsize > self->descr->elsize) {\n\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update\n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\t/* We would decref newtype here --- temp will\n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tif (temp == NULL) return -1;\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\tPy_INCREF(temp->descr);\n\t\t/* Fool deallocator not to delete these*/\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype;\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA);\n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, \n\t\t\t\t\t\t (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num -\n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type,\n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new);\n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int\narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode,\n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr));\n memmove(selfit->dataptr, arrit->dataptr,\n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size)\n PyArray_ITER_RESET(arrit);\n }\n retval = 0;\n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size)\n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\",\n\t (getter)array_ndim_get,\n\t NULL,\n\t \"number of array dimensions\"},\n {\"flags\",\n\t (getter)array_flags_get,\n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\",\n\t (getter)array_shape_get,\n\t (setter)array_shape_set,\n\t \"tuple of array dimensions\"},\n {\"strides\",\n\t (getter)array_strides_get,\n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)array_data_get,\n\t (setter)array_data_set,\n\t \"pointer to start of data\"},\n {\"itemsize\",\n\t (getter)array_itemsize_get,\n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\",\n\t (getter)array_real_get,\n\t (setter)array_real_set,\n\t \"real part of array\"},\n {\"imag\",\n\t (getter)array_imag_get,\n\t (setter)array_imag_set,\n\t \"imaginary part of array\"},\n\t{\"flat\",\n\t (getter)array_flat_get,\n\t (setter)array_flat_set,\n\t \"a 1-d view of a contiguous array\"},\n\t{\"__array_data__\",\n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\",\n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n\t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */\n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] =\n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\nstatic PyTypeObject PyArray_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0,\t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n &array_as_sequence,\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str,\t /*tp_str*/\n\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n &array_as_buffer, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT\n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter,\t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n array_alloc,\t /* tp_alloc */\n (newfunc)array_new,\t\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int\ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple)\n{\n int d=0;\n PyObject *e;\n\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0)\n\t\treturn 1;\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize)\n{\n\tint n, r, i;\n\tPyObject *e;\n\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s)\n\t\t\t*itemsize = MAX(*itemsize, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype ---\n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately\n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE &&\n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\nstatic PyArray_Descr *\n_array_find_python_scalar_type(PyObject *op)\n{\n if (PyFloat_Check(op)) {\n return PyArray_DescrFromType(PyArray_DOUBLE);\n } else if (PyComplex_Check(op)) {\n return PyArray_DescrFromType(PyArray_CDOUBLE);\n } else if (PyInt_Check(op)) {\n /* bools are a subclass of int */\n if (PyBool_Check(op)) {\n return PyArray_DescrFromType(PyArray_BOOL);\n } else {\n return PyArray_DescrFromType(PyArray_LONG);\n }\n } else if (PyLong_Check(op)) {\n /* if integer can fit into a longlong then return that\n */\n if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n PyErr_Clear();\n return PyArray_DescrFromType(PyArray_OBJECT);\n }\n return PyArray_DescrFromType(PyArray_LONGLONG);\n }\n return NULL;\n}\n\n/* op is an object to be converted to an ndarray.\n\n minitype is the minimum type-descriptor needed.\n\n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n\n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\n\tif (minitype == NULL)\n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\n if (max < 0) goto deflt;\n\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n chktype = _array_find_python_scalar_type(op);\n if (chktype) {\n goto finish;\n }\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n\n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind,\n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n }\n\n\tif (PyInstance_Check(op)) goto deflt;\n\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\n finish:\n\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype;\n}\n\nstatic int\nAssign_Array(PyArrayObject *self, PyObject *v)\n{\n PyObject *e;\n int l, r;\n\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\n l=PyObject_Length(v);\n if(l < 0) return -1;\n\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1;\n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */\n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode)\n{\n PyArrayObject *ret;\n\tint itemsize;\n\tint type;\n\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= 4;\n\n\t\tif (itemsize != typecode->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(typecode);\n\t\t\ttypecode->elsize = itemsize;\n\t\t}\n\t}\n\n ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL,\n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\tif (ret == NULL) return NULL;\n\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode */\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string,\n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid input sequence\");\n\t\tgoto fail;\n }\n\n\tif (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {\n\t\tnd = max_depth;\n\t}\n\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid number of dimensions\");\n\t\tgoto fail;\n }\n\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\n if(!r) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int\nPyArray_ValidType(int type)\n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in))\n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, in);\n\t\t\tbptr += elsize;\n\t\t\tPyArray_ITER_NEXT(it_in);\n\t\t\tel += 1;\n\t\t\tif ((el == nels) || (index == 0)) {\n\t\t\t\t/* buffer filled, do cast */\n\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n out);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject *\nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING)\n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd,\n\t\t\t\t mp->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\n}\n\n/* The number of elements in out must be an integer multiple\n of the number of elements in mp.\n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1;\n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * mpsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr,\n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)\n{\n\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1)\n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse {\n if ((flags & ENSUREARRAY)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype,\n\t\t\t\t\t\t newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr;\n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\n\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong))\n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char))\n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long))\n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap)\n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n\n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL;\n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n\n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data,\n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr));\n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n\n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context)\n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, \n\t\t\t\t\t\t\t\t NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None,\n\t\t\t\t\t\t context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", \n\t\t\t\t\t\t typecode, context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", \n\t\t\t\t\t\t\t typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError,\n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n}\n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,\n int max_depth, int flags, PyObject *context)\n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op))\n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tif (flags & UPDATEIFCOPY) goto err;\n\t\tr = PyArray_FromScalar(op, newtype);\n\t} else if (newtype == NULL &&\n (newtype = _array_find_python_scalar_type(op))) {\n\t if (flags & UPDATEIFCOPY) goto err;\n r = Array_FromScalar(op, newtype);\n }\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, \n\t\t\t\t\t\tflags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (flags & UPDATEIFCOPY) goto err;\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\n\t/* Be sure we succeed here */\n\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n\n err:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"UPDATEIFCOPY used for non-array input.\");\n\treturn NULL;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int\nPyArray_ObjectType(PyObject *op, int minimum_type)\n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of\n CONTIGUOUS,\n FORTRAN,\n ALIGNED,\n WRITEABLE,\n NOTSWAPPED,\n ENSURECOPY,\n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should\n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or\n not it has such features.\n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well.\n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n\n FORTRAN can be set in the FLAGS to request a FORTRAN array.\n Fortran arrays are always behaved (aligned,\n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d).\n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array.\n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe.\n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,\n int max_depth, int requires, PyObject *context)\n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0,\n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place\n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op)) return op;\n\t\n\tif (PyArray_Check(op)) \n\t\treturn PyArray_View((PyArrayObject *)op, NULL, &PyArray_Type);\n\t\n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureAnyArray(PyObject *op)\n{\n\tif (op && PyArray_Check(op)) return op;\n\treturn PyArray_EnsureArray(op);\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int\nPyArray_CanCastSafely(int fromtype, int totype)\n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype))\n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode\n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\n\t\t*/\n\t}\n\treturn ret;\n}\n\n/*OBJECT_API\n See if array scalars can be cast.\n */\nstatic Bool\nPyArray_CanCastScalar(PyTypeObject *from, PyTypeObject *to)\n{\n\tint fromtype;\n\tint totype;\n\n\tfromtype = _typenum_fromtypeobj((PyObject *)from, 0);\n\ttotype = _typenum_fromtypeobj((PyObject *)to, 0);\n\tif (fromtype == PyArray_NOTYPE || totype == PyArray_NOTYPE) \n\t\treturn FALSE;\n\treturn (Bool) PyArray_CanCastSafely(fromtype, totype);\t\n}\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd;\n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D)\n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n\n/* don't use with PyArray_ITER_GOTO1D because factors are not\n adjusted */\n\n/*OBJECT_API\n Adjusts previously broadcasted iterators so that the largest axis is not iterated \n over. Returns dimension which is largest in the range [0,multi->nd). A -1 \n is returned if multi->nd == 0.\n */\nstatic int\nPyArray_RemoveLargest(PyArrayMultiIterObject *multi)\n{\n\tPyArrayIterObject *it;\n\tint i;\n\tint axis=0;\n\tintp longest;\n\n\tif (multi->nd == 0) return -1;\n\t\n\tlongest = multi->dimensions[0];\n\t/* Find longest dimension */\n\tfor (i=1; ind; i++) {\n\t\tif (multi->dimensions[i] > longest) {\n\t\t\taxis = i;\n\t\t\tlongest = multi->dimensions[i];\n\t\t}\n\t}\n\t\n\tfor (i=0; inumiter; i++) {\n\t\tit = multi->iters[i];\n\t\tit->contiguous = 0;\n\t\tif (it->size != 0)\n\t\t\tit->size /= (it->dims_m1[axis]+1);\n\t\tit->dims_m1[axis] = 0;\n\t\tit->backstrides[axis] = 0;\t\t\n\t}\n\n\treturn axis;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic _int_or_ssize_t\niter_length(PyArrayIterObject *self)\n{\n return self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, self->ao);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr,\n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, r);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1)\n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t 1, &n_steps,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail;\n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, r);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0,\n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap, self->ao);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size)\n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, self->ao);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, self->ao);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size)\n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)\n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, arrval);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, arrval);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, arrval);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size)\n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0,\n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)iter_length,\t\t /*mp_length*/\n#else\n (inquiry)iter_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op)\n{\n\n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options:\n 1) underlying array is contiguous\n -- return 1-d wrapper around it\n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, it->ao->data,\n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r);\n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n\n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\",\n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &iter_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t\t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular\n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators\n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++)\n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already\n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1)\n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"shape mismatch: objects\" \\\n\t\t\t\t\t\t\t\" cannot be broadcast\" \\\n\t\t\t\t\t\t\t\" to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t it->ao);\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tif (it->size != 0) {\n\t\t\t\tPyArray_ITER_RESET(it);\n\t\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t it->ao);\n\t\t\t}\n\t\t\telse coord[i] = 0;\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of\n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord,\n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t it->ao);\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t it->ao);\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so,\n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size.\n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere.\n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well.\n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0\n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t/* But, be sure to do it with a true array.\n\t */\n\tif (PyArray_CheckExact(arr)) {\n\t\tsub = array_subscript(arr, mit->indexobj);\n\t}\n\telse {\n\t\tPy_INCREF(arr);\n\t\tobj = PyArray_EnsureArray((PyObject *)arr);\n\t\tif (obj == NULL) goto fail;\n\t\tsub = array_subscript((PyArrayObject *)obj, mit->indexobj);\n\t\tPy_DECREF(obj);\n\t}\n\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects\n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been\n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj))\n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj,\n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1;\n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n intp indval;\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n indval = *indptr;\n\t\t\tif (indval < 0) indval += dimsize;\n\t\t\tif (indval < 0 || indval >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) indval, (int) (dimsize-1),\n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0,\n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n\tmit->index = 0;\n\tmit->ait = NULL;\n\tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY\n#undef SOBJ_ISFANCY\n#undef SOBJ_BADARRAY\n#undef SOBJ_TOOMANY\n#undef SOBJ_LISTTUP\n\n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple\n\t (with at least 1 list or arrayobject or Bool object), */\n\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i,\n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing\n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n\n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work.\n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a);\n mapiter is equivalent to a[indexobj].flat but the latter gets to use\n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t\t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t\t /* tp_iter */\n (iternextfunc)0,\t /* tp_iternext */\n 0,\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\n\tint i, err=0;\n\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\n /* fprintf(stderr, \"multi new...\");*/\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\n\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL)\n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i,\n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(multi->iters[i]);\n\tmulti->ob_type->tp_free((PyObject *)multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\",\n\t (getter)arraymultiter_size_get,\n\t NULL,\n\t \"total size of broadcasted result\"},\n {\"index\",\n\t (getter)arraymultiter_index_get,\n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter),\n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t\t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods,\t /* tp_methods */\n arraymultiter_members,\t\t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types.\n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these\n builtins will be attempted leading to problems.\n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically\n allocated).\n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless\n there is a reference-count problem\n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set.\n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base,\n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0)\n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\",\n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self)\n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\",\n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr)\n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr) {\n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\t\tif ((conv == NULL) && \n\t\t\t (!PyErr_Occurred())) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"cannot specify align=1 \"\\\n\t\t\t\t\t\t\"with array_descriptor \"\\\n\t\t\t\t\t\t\"specification of the data-\"\\\n\t\t\t\t\t\t\"type.\");\n\t\t\t}\n\t\t}\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv))\n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\n\t/* Now return the state which is at least\n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize\n and alignment for EXTENDED arrays\n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\n\tif (endian != '|' && \n\t PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are:\n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n *** Leaves reference count of self unchanged --- does not DECREF self ***\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args)\n{\n\tchar endian=PyArray_SWAP;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS,\n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n\tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\ndescr_length(PyArray_Descr *self)\n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op)\n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError,\n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)descr_length,\t\t /*mp_length*/\n#else\n (inquiry)descr_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t\t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &descr_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t/* tp_iternext */\n arraydescr_methods,\t\t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n\n/** Array Flags Object **/\n\ntypedef struct PyArrayFlagsObject {\n PyObject_HEAD\n PyObject *arr;\n int flags;\n} PyArrayFlagsObject;\n\n/*OBJECT_API\n Get New ArrayFlagsObject\n*/\nstatic PyObject *\nPyArray_NewFlagsObject(PyObject *obj)\n{\n PyObject *flagobj;\n int flags;\n if (obj == NULL) {\n flags = CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n }\n else {\n flags = PyArray_FLAGS(obj);\n }\n flagobj = PyArrayFlags_Type.tp_alloc(&PyArrayFlags_Type, 0);\n if (flagobj == NULL) return NULL;\n Py_XINCREF(obj);\n ((PyArrayFlagsObject *)flagobj)->arr = obj;\n ((PyArrayFlagsObject *)flagobj)->flags = flags;\n\n return flagobj;\n}\n\nstatic void\narrayflags_dealloc(PyArrayFlagsObject *self)\n{\n\tPy_XDECREF(self->arr);\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n\n#define _define_get(UPPER, lower) \\\nstatic PyObject * \\\narrayflags_ ## lower ## _get(PyArrayFlagsObject *self) \\\n{ \\\n PyObject *item; \\\n item = ((self->flags & (UPPER)) == (UPPER)) ? Py_True : Py_False; \\\n Py_INCREF(item); \\\n return item; \\\n}\n\n_define_get(CONTIGUOUS, contiguous)\n_define_get(FORTRAN, fortran)\n_define_get(UPDATEIFCOPY, updateifcopy)\n_define_get(OWNDATA, owndata)\n_define_get(ALIGNED, aligned)\n_define_get(WRITEABLE, writeable)\n\n_define_get(ALIGNED|WRITEABLE, behaved)\n_define_get(ALIGNED|WRITEABLE|CONTIGUOUS, carray)\n\nstatic PyObject *\narrayflags_forc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) ||\n ((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_fnc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_farray_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & (ALIGNED|WRITEABLE|FORTRAN)) == \\\n (ALIGNED|WRITEABLE|FORTRAN)) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_num_get(PyArrayFlagsObject *self)\n{\n return PyInt_FromLong(self->flags);\n}\n\n/* relies on setflags order being write, align, uic */\nstatic int\narrayflags_updateifcopy_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False));\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_aligned_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_writeable_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None, Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\n\nstatic PyGetSetDef arrayflags_getsets[] = {\n\t{\"contiguous\",\n\t (getter)arrayflags_contiguous_get,\n\t NULL,\n\t \"\"},\n {\"fortran\",\n (getter)arrayflags_fortran_get,\n NULL,\n \"\"},\n {\"updateifcopy\",\n (getter)arrayflags_updateifcopy_get,\n (setter)arrayflags_updateifcopy_set,\n \"\"},\n {\"owndata\",\n (getter)arrayflags_owndata_get,\n NULL,\n \"\"},\n {\"aligned\",\n (getter)arrayflags_aligned_get,\n (setter)arrayflags_aligned_set,\n \"\"},\n {\"writeable\",\n (getter)arrayflags_writeable_get,\n (setter)arrayflags_writeable_set,\n \"\"},\n {\"fnc\",\n (getter)arrayflags_fnc_get,\n NULL,\n \"\"},\n {\"forc\",\n (getter)arrayflags_forc_get,\n NULL,\n \"\"},\n {\"behaved\",\n (getter)arrayflags_behaved_get,\n NULL,\n \"\"},\n {\"carray\",\n (getter)arrayflags_carray_get,\n NULL,\n \"\"},\n {\"farray\",\n (getter)arrayflags_farray_get,\n NULL,\n \"\"},\n {\"num\",\n (getter)arrayflags_num_get,\n NULL,\n \"\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyObject *\narrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)\n{\n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n\tswitch(n) {\n\tcase 1:\n\t\tswitch(key[0]) {\n\t\tcase 'C':\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tcase 'F':\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tcase 'W':\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tcase 'B':\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tcase 'O':\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tcase 'A':\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tcase 'U':\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tdefault:\n\t\t\tgoto fail;\n\t\t}\n\t\tbreak;\n\tcase 2:\n\t\tif (strncmp(key, \"CA\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FA\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 3:\n\t\tif (strncmp(key, \"FNC\", n)==0)\n\t\t\treturn arrayflags_fnc_get(self);\n\t\tbreak;\n\tcase 4:\n\t\tif (strncmp(key, \"FORC\", n)==0)\n\t\t\treturn arrayflags_forc_get(self);\n\t\tbreak;\n\tcase 6:\n\t\tif (strncmp(key, \"CARRAY\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FARRAY\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 7:\n\t\tif (strncmp(key,\"FORTRAN\",n)==0)\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tif (strncmp(key,\"BEHAVED\",n)==0)\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tif (strncmp(key,\"OWNDATA\",n)==0)\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tif (strncmp(key,\"ALIGNED\",n)==0)\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tbreak;\n\tcase 9:\t\n\t\tif (strncmp(key,\"WRITEABLE\",n)==0)\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tbreak;\n\tcase 10:\n\t\tif (strncmp(key,\"CONTIGUOUS\",n)==0)\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tbreak;\n\tcase 12:\n\t\tif (strncmp(key, \"UPDATEIFCOPY\", n)==0)\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tbreak;\n\t}\n\n fail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return NULL;\n}\n\nstatic int\narrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)\n{ \n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n if (((n==9) && (strncmp(key, \"WRITEABLE\", n)==0)) ||\n\t ((n==1) && (strncmp(key, \"W\", n)==0)))\n return arrayflags_writeable_set(self, item);\n else if (((n==7) && (strncmp(key, \"ALIGNED\", n)==0)) || \n ((n==1) && (strncmp(key, \"A\", n)==0)))\n return arrayflags_aligned_set(self, item);\n else if (((n==12) && (strncmp(key, \"UPDATEIFCOPY\", n)==0)) ||\n ((n==1) && (strncmp(key, \"U\", n)==0)))\n return arrayflags_updateifcopy_set(self, item); \n\nfail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return -1;\n}\n\nstatic char *\n_torf_(int flags, int val)\n{\n if ((flags & val) == val) return \"True\";\n else return \"False\"; \n}\n\nstatic PyObject *\narrayflags_print(PyArrayFlagsObject *self)\n{\n int fl = self->flags;\n \n return PyString_FromFormat(\" %s : %s\\n %s : %s\\n %s : %s\\n\"\\\n \" %s : %s\\n %s : %s\\n %s : %s\",\n \"CONTIGUOUS\", _torf_(fl, CONTIGUOUS),\n \"FORTRAN\", _torf_(fl, FORTRAN),\n \"OWNDATA\", _torf_(fl, OWNDATA),\n \"WRITEABLE\", _torf_(fl, WRITEABLE),\n \"ALIGNED\", _torf_(fl, ALIGNED),\n \"UPDATEIFCOPY\", _torf_(fl, UPDATEIFCOPY));\n}\n\n\nstatic PyMappingMethods arrayflags_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)NULL, \t\t /*mp_length*/\n#else\n (inquiry)NULL, \t\t /*mp_length*/\n#endif\n (binaryfunc)arrayflags_getitem,\t /*mp_subscript*/\n (objobjargproc)arrayflags_setitem, /*mp_ass_subscript*/\n};\n\n\nstatic PyObject *\narrayflags_new(PyTypeObject *self, PyObject *args, PyObject *kwds)\n{\n PyObject *arg=NULL;\n if (!PyArg_UnpackTuple(args, \"flagsobj\", 0, 1, &arg))\n return NULL;\n\n if ((arg != NULL) && PyArray_Check(arg)) {\n return PyArray_NewFlagsObject(arg);\n }\n else {\n return PyArray_NewFlagsObject(NULL);\n }\n}\n\nstatic PyTypeObject PyArrayFlags_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\n \"numpy.flagsobj\",\n sizeof(PyArrayFlagsObject),\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayflags_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t0,\t\t /* tp_compare */\n (reprfunc)arrayflags_print, /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &arrayflags_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arrayflags_print, /* tp_str */\n 0,\t \t /* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t /* tp_iternext */\n 0,\t \t /* tp_methods */\n 0,\t /* tp_members */\n arrayflags_getsets, /* tp_getset */\n 0,\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t /* tp_init */\n 0,\t /* tp_alloc */\n arrayflags_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "source_code_before": "/*\n Provide multidimensional arrays as a basic object type in python.\n\nBased on Original Numeric implementation\nCopyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\nwith contributions from many Numeric Python developers 1995-2004\n\nHeavily modified in 2005 with inspiration from Numarray\n\nby\n\nTravis Oliphant\nAssistant Professor at\nBrigham Young University\n\nmaintainer email: oliphant.travis@ieee.org\n\nNumarray design (which provided guidance) by\nSpace Science Telescope Institute\n (J. Todd Miller, Perry Greenfield, Rick White)\n*/\n\n/*OBJECT_API\n Get Priority from object\n*/\nstatic double\nPyArray_GetPriority(PyObject *obj, double default_)\n{\n PyObject *ret;\n double priority=PyArray_PRIORITY;\n\n\tif (PyArray_CheckExact(obj))\n\t\treturn priority;\n\n ret = PyObject_GetAttrString(obj, \"__array_priority__\");\n if (ret != NULL) priority = PyFloat_AsDouble(ret);\n if (PyErr_Occurred()) {\n PyErr_Clear();\n priority = default_;\n }\n Py_XDECREF(ret);\n return priority;\n}\n\n/* Backward compatibility only */\n/* In both Zero and One\n\n ***You must free the memory once you are done with it\n using PyDataMem_FREE(ptr) or you create a memory leak***\n\n If arr is an Object array you are getting a\n BORROWED reference to Zero or One.\n Do not DECREF.\n Please INCREF if you will be hanging on to it.\n\n The memory for the ptr still must be freed in any case;\n*/\n\n\n/*OBJECT_API\n Get pointer to zero of correct type for array.\n*/\nstatic char *\nPyArray_Zero(PyArrayObject *arr)\n{\n char *zeroval;\n int ret, storeflags;\n PyObject *obj;\n\n zeroval = PyDataMem_NEW(arr->descr->elsize);\n if (zeroval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n\tobj=PyInt_FromLong((long) 0);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(zeroval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return zeroval;\n }\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, zeroval, arr);\n\tarr->flags = storeflags;\n\tPy_DECREF(obj);\n\tif (ret < 0) {\n\t\tPyDataMem_FREE(zeroval);\n\t\treturn NULL;\n\t}\n return zeroval;\n}\n\n/*OBJECT_API\n Get pointer to one of correct type for array\n*/\nstatic char *\nPyArray_One(PyArrayObject *arr)\n{\n char *oneval;\n int ret, storeflags;\n PyObject *obj;\n\n oneval = PyDataMem_NEW(arr->descr->elsize);\n if (oneval == NULL) {\n PyErr_SetNone(PyExc_MemoryError);\n return NULL;\n }\n\n obj = PyInt_FromLong((long) 1);\n if (PyArray_ISOBJECT(arr)) {\n memcpy(oneval, &obj, sizeof(PyObject *));\n Py_DECREF(obj);\n return oneval;\n }\n\n\tstoreflags = arr->flags;\n\tarr->flags |= BEHAVED_FLAGS;\n ret = arr->descr->f->setitem(obj, oneval, arr);\n\tarr->flags = storeflags;\n Py_DECREF(obj);\n if (ret < 0) {\n PyDataMem_FREE(oneval);\n return NULL;\n }\n return oneval;\n}\n\n/* End deprecated */\n\n\nstatic int\ndo_sliced_copy(char *dest, intp *dest_strides, intp *dest_dimensions,\n\t int dest_nd, char *src, intp *src_strides,\n\t intp *src_dimensions, int src_nd, int elsize,\n\t int copies) {\n intp i, j;\n\n if (src_nd == 0 && dest_nd == 0) {\n for(j=0; j src_nd) {\n for(i=0; i<*dest_dimensions; i++, dest += *dest_strides) {\n if (do_sliced_copy(dest, dest_strides+1,\n dest_dimensions+1, dest_nd-1,\n src, src_strides,\n src_dimensions, src_nd,\n elsize, copies) == -1)\n return -1;\n }\n return 0;\n }\n\n if (dest_nd == 1) {\n if (*dest_dimensions != *src_dimensions) {\n PyErr_SetString(PyExc_ValueError,\n \"matrices are not aligned for copy\");\n return -1;\n }\n for(i=0; i<*dest_dimensions; i++, src += *src_strides) {\n for(j=0; j 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize) &&\n ((*src_strides)[*src_nd-1] == *elsize)) {\n if ((*dest_dimensions)[*dest_nd-1] !=\n (*src_dimensions)[*src_nd-1]) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"matrices are not aligned\");\n return -1;\n }\n *elsize *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1; *src_nd-=1;\n } else {\n break;\n }\n }\n if (*src_nd == 0) {\n while (*dest_nd > 0) {\n if (((*dest_strides)[*dest_nd-1] == *elsize)) {\n *copies *= (*dest_dimensions)[*dest_nd-1];\n *dest_nd-=1;\n } else {\n break;\n }\n }\n }\n return 0;\n}\n\nstatic char *\ncontiguous_data(PyArrayObject *src)\n{\n intp dest_strides[MAX_DIMS], *dest_strides_ptr;\n intp *dest_dimensions=src->dimensions;\n int dest_nd=src->nd;\n intp *src_strides = src->strides;\n intp *src_dimensions=src->dimensions;\n int src_nd=src->nd;\n int elsize=src->descr->elsize;\n int copies=1;\n int ret, i;\n intp stride=elsize;\n char *new_data;\n\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\n dest_strides_ptr = dest_strides;\n\n if (optimize_slices(&dest_strides_ptr, &dest_dimensions, &dest_nd,\n &src_strides, &src_dimensions, &src_nd,\n &elsize, &copies) == -1)\n return NULL;\n\n new_data = (char *)_pya_malloc(stride);\n\n ret = do_sliced_copy(new_data, dest_strides_ptr, dest_dimensions,\n dest_nd, src->data, src_strides,\n src_dimensions, src_nd, elsize, copies);\n\n if (ret != -1) { return new_data; }\n else { _pya_free(new_data); return NULL; }\n}\n\n/* end Helper functions */\n\n\nstatic PyObject *PyArray_New(PyTypeObject *, int nd, intp *,\n int, intp *, void *, int, int, PyObject *);\n\n/* C-API functions */\n\n/* Used for arrays of python objects to increment the reference count of */\n/* every python object in the array. */\n/*OBJECT_API\n For object arrays, increment all internal references.\n*/\nstatic int\nPyArray_INCREF(PyArrayObject *mp)\n{\n\tintp i, n;\n\n PyObject **data, **data2;\n\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\n if (PyArray_ISONESEGMENT(mp)) {\n data = (PyObject **)mp->data;\n } else {\n if ((data = (PyObject **)contiguous_data(mp)) == NULL)\n return -1;\n }\n\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; i 0; n--, a += 1) {\n b = a + 1;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 4:\n for (a = (char*)p ; n > 0; n--, a += 2) {\n b = a + 3;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n case 8:\n for (a = (char*)p ; n > 0; n--, a += 4) {\n b = a + 7;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b-- = c;\n c = *a; *a++ = *b; *b = c;\n }\n break;\n default:\n m = size / 2;\n for (a = (char *)p ; n > 0; n--, a += m) {\n b = a + (size-1);\n for (j=0; j 1, then dst must be contiguous */\nstatic void\ncopy_and_swap(void *dst, void *src, int itemsize, intp numitems,\n intp srcstrides, int swap)\n{\n int i;\n char *s1 = (char *)src;\n char *d1 = (char *)dst;\n\n\n if ((numitems == 1) || (itemsize == srcstrides))\n memcpy(d1, s1, itemsize*numitems);\n else {\n for (i = 0; i < numitems; i++) {\n memcpy(d1, s1, itemsize);\n d1 += itemsize;\n s1 += srcstrides;\n }\n }\n\n if (swap)\n byte_swap_vector(d1, numitems, itemsize);\n}\n\n\n#ifndef Py_UNICODE_WIDE\n#include \"ucsnarrow.c\"\n#endif\n\n\nstatic PyArray_Descr **userdescrs=NULL;\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\n\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\n\n\n/* Helper functions */\n\n/*OBJECT_API*/\nstatic intp\nPyArray_PyIntAsIntp(PyObject *o)\n{\n\tlonglong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tintp ret;\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t\tgoto finish;\n\t}\n\n#if SIZEOF_INTP == SIZEOF_LONG\n\tdescr = &LONG_Descr;\n#elif SIZEOF_INTP == SIZEOF_INT\n\tdescr = &INT_Descr;\n#else\n\tdescr = &LONGLONG_DESCR;\n#endif\n\tarr = NULL;\n\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((intp *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj != NULL) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONGLONG > SIZEOF_INTP)\n\tif ((long_value < MIN_INTP) || (long_value > MAX_INTP)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C intp\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (intp) long_value;\n}\n\n\nstatic PyObject *array_int(PyArrayObject *v);\n\n/*OBJECT_API*/\nstatic int\nPyArray_PyIntAsInt(PyObject *o)\n{\n\tlong long_value = -1;\n\tPyObject *obj;\n\tstatic char *msg = \"an integer is required\";\n\tPyObject *arr;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t\tgoto finish;\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t\tgoto finish;\n\t}\n\n\tdescr = &INT_Descr;\n\tarr=NULL;\n\tif (PyArray_Check(o)) {\n\t\tif (PyArray_SIZE(o)!=1 || !PyArray_ISINTEGER(o)) {\n\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\n\t\tPy_INCREF(descr);\n\t\tarr = PyArray_FromScalar(o, descr);\n\t}\n\tif (arr != NULL) {\n\t\tret = *((int *)PyArray_DATA(arr));\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\tif (o->ob_type->tp_as_number != NULL &&\t\t\\\n\t o->ob_type->tp_as_number->nb_int != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_int(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse if (o->ob_type->tp_as_number != NULL &&\t\t\t\\\n\t\t o->ob_type->tp_as_number->nb_long != NULL) {\n\t\tobj = o->ob_type->tp_as_number->nb_long(o);\n\t\tif (obj == NULL) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\n finish:\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\n#if (SIZEOF_LONG > SIZEOF_INT)\n\tif ((long_value < INT_MIN) || (long_value > INT_MAX)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"integer won't fit into a C int\");\n\t\treturn -1;\n\t}\n#endif\n\treturn (int) long_value;\n}\n\nstatic char *\nindex2ptr(PyArrayObject *mp, intp i)\n{\n\tif(mp->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n\tif (i==0 && mp->dimensions[0] > 0)\n\t\treturn mp->data;\n\n if (mp->nd>0 && i>0 && i < mp->dimensions[0]) {\n return mp->data+i*mp->strides[0];\n }\n PyErr_SetString(PyExc_IndexError,\"index out of bounds\");\n return NULL;\n}\n\n/*OBJECT_API\n Compute the size of an array (in number of items)\n*/\nstatic intp\nPyArray_Size(PyObject *op)\n{\n if (PyArray_Check(op)) {\n return PyArray_SIZE((PyArrayObject *)op);\n }\n\telse {\n return 0;\n }\n}\n\nstatic void\n_strided_byte_copy(char *dst, intp outstrides, char *src, intp instrides, \n\t\t\t intp N, int elsize)\n{\n intp i, j;\n char *tout = dst;\n char *tin = src;\n\n#define _FAST_MOVE(_type_)\t\t\t\t \\\n\tfor (i=0; idescr->f->copyswap;\n\tcopyswapn = dest->descr->f->copyswapn;\n\n elsize = dest->descr->elsize;\n\n if ((PyArray_ISCONTIGUOUS(dest) && PyArray_ISCONTIGUOUS(src))\t\\\n\t || (PyArray_ISFORTRAN(dest) && PyArray_ISFORTRAN(src))) {\n\n PyArray_XDECREF(dest);\n dptr = dest->data;\n sbytes = ssize * src->descr->elsize;\n while(ncopies--) {\n memmove(dptr, src->data, sbytes);\n dptr += sbytes;\n }\n\t\tif (swap)\n\t\t\tcopyswapn(dest->data, NULL, dsize, 1, dest);\n PyArray_INCREF(dest);\n return 0;\n }\n \n /* See if we can iterate over the largest dimension */\n if (!swap && (nd = dest->nd) == src->nd && (nd > 0) && \n PyArray_CompareLists(dest->dimensions, src->dimensions, nd)) { \n int maxaxis=0, maxdim=dest->dimensions[0];\n int i;\n for (i=1; idimensions[i] > maxdim) {\n maxaxis = i;\n maxdim = dest->dimensions[i];\n }\n }\n\n dit = (PyArrayIterObject *) \\\n PyArray_IterAllButAxis((PyObject *)dest, maxaxis);\n sit = (PyArrayIterObject *) \\\n PyArray_IterAllButAxis((PyObject *)src, maxaxis);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n index = dit->size;\n\t\tif (PyArray_ISALIGNED(dest) && PyArray_ISALIGNED(src)) {\n\t\t\twhile(index--) {\n\t\t\t\t/* strided copy of elsize bytes */\n\t\t\t\t_strided_byte_copy(dit->dataptr, \n\t\t\t\t\t\t dest->strides[maxaxis],\n\t\t\t\t\t\t sit->dataptr, \n\t\t\t\t\t\t src->strides[maxaxis],\n\t\t\t\t\t\t maxdim, elsize);\n\t\t\t\tPyArray_ITER_NEXT(dit);\n\t\t\t\tPyArray_ITER_NEXT(sit);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\twhile(index--) {\n\t\t\t\t/* strided copy of elsize bytes */\n\t\t\t\t_unaligned_strided_byte_copy(dit->dataptr, \n\t\t\t\t\t\t\t dest->strides[maxaxis],\n\t\t\t\t\t\t\t sit->dataptr, \n\t\t\t\t\t\t\t src->strides[maxaxis],\n\t\t\t\t\t\t\t maxdim, elsize);\n\t\t\t\tPyArray_ITER_NEXT(dit);\n\t\t\t\tPyArray_ITER_NEXT(sit);\n\t\t\t}\n\t\t}\t\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n return 0; \n }\n\n dit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)dest);\n sit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)src);\n\n if ((dit == NULL) || (sit == NULL)) {\n Py_XDECREF(dit);\n Py_XDECREF(sit);\n return -1;\n }\n\n PyArray_XDECREF(dest);\n while(ncopies--) {\n index = ssize;\n while(index--) {\n\t\t\tmemmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, dest);\n PyArray_ITER_NEXT(dit);\n PyArray_ITER_NEXT(sit);\n }\n PyArray_ITER_RESET(sit);\n }\n PyArray_INCREF(dest);\n Py_DECREF(dit);\n Py_DECREF(sit);\n\treturn 0;\n}\n\n\nstatic int\nPyArray_CopyObject(PyArrayObject *dest, PyObject *src_object)\n{\n PyArrayObject *src;\n int ret;\n\t\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n dest->descr, 0,\n dest->nd, FORTRAN_IF(dest), NULL);\n if (src == NULL) return -1;\n\n ret = PyArray_CopyInto(dest, src);\n Py_DECREF(src);\n return ret;\n}\n\n\n/* These are also old calls (should use PyArray_New) */\n\n/* They all zero-out the memory as previously done */\n\n/* steals reference to descr -- and enforces native byteorder on it.*/\n/*OBJECT_API\n Like FromDimsAndData but uses the Descr structure instead of typecode\n as input.\n*/\nstatic PyObject *\nPyArray_FromDimsAndDataAndDescr(int nd, int *d,\n PyArray_Descr *descr,\n char *data)\n{\n\tPyObject *ret;\n#if SIZEOF_INTP != SIZEOF_INT\n\tint i;\n\tintp newd[MAX_DIMS];\n#endif\n\n\tif (!PyArray_ISNBO(descr->byteorder))\n\t\tdescr->byteorder = '=';\n\n#if SIZEOF_INTP != SIZEOF_INT\n\tfor (i=0; itype_num != PyArray_OBJECT)) {\n\t\tmemset(PyArray_DATA(ret), 0, PyArray_NBYTES(ret));\n\t} \n\treturn ret;\n}\n\n/* end old calls */\n\n\n/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, PyArray_ORDER fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran == PyArray_ANYORDER) \n\t\tfortran = PyArray_ISFORTRAN(m1);\n \n\tPy_INCREF(m1->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(m1->ob_type,\n\t\t\t\t\t\t m1->descr,\n\t\t\t\t\t\t m1->nd,\n\t\t\t\t\t\t m1->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran,\n\t\t\t\t\t\t (PyObject *)m1);\n\tif (ret == NULL) return NULL;\n if (PyArray_CopyInto(ret, m1) == -1) {\n Py_DECREF(ret);\n return NULL;\n }\n\n return (PyObject *)ret;\n}\n\nstatic PyObject *array_big_item(PyArrayObject *, intp);\n\n/* Does nothing with descr (cannot be NULL) */\n/*OBJECT_API\n Get scalar-equivalent to a region of memory described by a descriptor.\n*/\nstatic PyObject *\nPyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n{\n\tPyTypeObject *type;\n\tPyObject *obj;\n void *destptr;\n PyArray_CopySwapFunc *copyswap;\n\tint type_num;\n\tint itemsize;\n\tint swap;\n\n\ttype_num = descr->type_num;\n\tif (type_num == PyArray_BOOL)\n\t\tPyArrayScalar_RETURN_BOOL_FROM_LONG(*(Bool*)data);\n\telse if (type_num == PyArray_OBJECT) {\n\t\tPy_INCREF(*((PyObject **)data));\n\t\treturn *((PyObject **)data);\n\t}\n\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\n\tif PyTypeNum_ISSTRING(type_num) { /* Eliminate NULL bytes */\n\t\tchar *dptr = data;\n\t\tdptr += itemsize-1;\n\t\twhile(itemsize && *dptr-- == 0) itemsize--;\n\t\tif (type_num == PyArray_UNICODE && itemsize) {\n\t\t\t/* make sure itemsize is a multiple of 4 */\n\t\t\t/* so round up to nearest multiple */\n\t\t\titemsize = (((itemsize-1) >> 2) + 1) << 2;\n\t\t}\n\t}\n\tif (type->tp_itemsize != 0) /* String type */\n\t\tobj = type->tp_alloc(type, itemsize);\n\telse\n\t\tobj = type->tp_alloc(type, 0);\n\tif (obj == NULL) return NULL;\n\tif PyTypeNum_ISEXTENDED(type_num) {\n\t\tif (type_num == PyArray_STRING) {\n\t\t\tdestptr = PyString_AS_STRING(obj);\n\t\t\t((PyStringObject *)obj)->ob_shash = -1;\n\t\t\t((PyStringObject *)obj)->ob_sstate =\t\\\n\t\t\t\tSSTATE_NOT_INTERNED;\n\t\t\tmemcpy(destptr, data, itemsize);\n\t\t\treturn obj;\n\t\t}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize >> 2;\n#ifndef Py_UNICODE_WIDE\n\t\t\tchar *buffer;\n\t\t\tint alloc=0;\n\t\t\tlength *= 2;\n#endif\n\t\t\t/* Need an extra slot and need to use\n\t\t\t Python memory manager */\n\t\t\tuni->str = NULL;\n\t\t\tdestptr = PyMem_NEW(Py_UNICODE,length+1);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tuni->str = (Py_UNICODE *)destptr;\n\t\t\tuni->str[0] = 0;\n\t\t\tuni->str[length] = 0;\n\t\t\tuni->length = length;\n\t\t\tuni->hash = -1;\n\t\t\tuni->defenc = NULL;\n#ifdef Py_UNICODE_WIDE\n\t\t\tmemcpy(destptr, data, itemsize);\n\t\t\tif (swap)\n\t\t\t\tbyte_swap_vector(destptr, length, 4);\n#else\n\t\t\t/* need aligned data buffer */\n\t\t\tif (!PyArray_ISBEHAVED(base)) {\n\t\t\t\tbuffer = _pya_malloc(itemsize);\n\t\t\t\tif (buffer == NULL)\n\t\t\t\t\treturn PyErr_NoMemory();\n\t\t\t\talloc = 1;\n\t\t\t\tmemcpy(buffer, data, itemsize);\n\t\t\t\tif (!PyArray_ISNOTSWAPPED(base)) {\n\t\t\t\t\tbyte_swap_vector(buffer, \n\t\t\t\t\t\t\t itemsize >> 2, 4);\n\t\t\t\t}\n\t\t\t}\n\t\t\telse buffer = data;\n\n /* Allocated enough for 2-characters per itemsize.\n\t\t\t Now convert from the data-buffer\n */\n\t\t\tlength = PyUCS2Buffer_FromUCS4(uni->str, \n\t\t\t\t\t\t (PyArray_UCS4 *)buffer,\n\t\t\t\t\t\t itemsize >> 2);\n\t\t\tif (alloc) _pya_free(buffer);\n\t\t\t/* Resize the unicode result */\n\t\t\tif (MyPyUnicode_Resize(uni, length) < 0) {\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\treturn NULL;\n\t\t\t}\n#endif\n\t\t\treturn obj;\n\t\t}\n\t\telse {\n\t\t\tPyVoidScalarObject *vobj = (PyVoidScalarObject *)obj;\n\t\t\tvobj->base = NULL;\n\t\t\tvobj->descr = descr;\n\t\t\tPy_INCREF(descr);\n\t\t\tvobj->obval = NULL;\n\t\t\tvobj->ob_size = itemsize;\n\t\t\tvobj->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t\tswap = 0;\n\t\t\tif (descr->fields) {\n\t\t\t\tif (base) {\n\t\t\t\t\tPy_INCREF(base);\n\t\t\t\t\tvobj->base = base;\n\t\t\t\t\tvobj->flags = PyArray_FLAGS(base);\n\t\t\t\t\tvobj->flags &= ~OWNDATA;\n\t\t\t\t\tvobj->obval = data;\n\t\t\t\t\treturn obj;\n\t\t\t\t}\n\t\t\t}\n\t\t\tdestptr = PyDataMem_NEW(itemsize);\n\t\t\tif (destptr == NULL) {\n Py_DECREF(obj);\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tvobj->obval = destptr;\n\t\t}\n\t}\n\telse {\n\t\tdestptr = _SOFFSET_(obj, type_num);\n\t}\n\t/* copyswap for OBJECT increments the reference count */\n copyswap(destptr, data, swap, base);\n\treturn obj;\n}\n\n/* returns an Array-Scalar Object of the type of arr\n from the given pointer to memory -- main Scalar creation function\n default new method calls this.\n*/\n\n/* Ideally, here the descriptor would contain all the information needed.\n So, that we simply need the data and the descriptor, and perhaps\n a flag\n*/\n\n\n/* Return Python scalar if 0-d array object is encountered */\n\n/*OBJECT_API\n Return either an array or the appropriate Python object if the array\n is 0d and matches a Python type.\n*/\nstatic PyObject *\nPyArray_Return(PyArrayObject *mp)\n{\n\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\n\tif (mp->nd == 0) {\n\t\tPyObject *ret;\n\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\tPy_DECREF(mp);\n\t\treturn ret;\n\t}\n\telse {\n\t\treturn (PyObject *)mp;\n\t}\n}\n\n/*\n returns typenum to associate with this type >=PyArray_USERDEF.\n Also creates a copy of the VOID_DESCR table inserting it's typeobject in\n and it's typenum in the appropriate place.\n\n needs the userdecrs table and PyArray_NUMUSER variables\n defined in arratypes.inc\n*/\n/*OBJECT_API\n Register Data type\n*/\nstatic int\nPyArray_RegisterDataType(PyTypeObject *type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\tint typenum;\n\tint i;\n\n\tif ((type == &PyVoidArrType_Type) ||\t\t\t\\\n\t !PyType_IsSubtype(type, &PyVoidArrType_Type)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"can only register void subtypes\");\n\t\treturn -1;\n\t}\n\t/* See if this type is already registered */\n\tfor (i=0; itypeobj == type)\n\t\t\treturn descr->type_num;\n\t}\n\tdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\ttypenum = PyArray_USERDEF + PyArray_NUMUSERTYPES;\n\tdescr->type_num = typenum;\n descr->typeobj = type;\n\tobj = PyObject_GetAttrString((PyObject *)type,\"itemsize\");\n\tif (obj) {\n\t\ti = PyInt_AsLong(obj);\n\t\tif ((i < 0) && (PyErr_Occurred())) PyErr_Clear();\n\t\telse descr->elsize = i;\n\t\tPy_DECREF(obj);\n\t}\n\tPy_INCREF(type);\n\tuserdescrs = realloc(userdescrs,\n\t\t\t (PyArray_NUMUSERTYPES+1)*sizeof(void *));\n if (userdescrs == NULL) {\n PyErr_SetString(PyExc_MemoryError, \"RegisterDataType\");\n\t\tPy_DECREF(descr);\n return -1;\n }\n\tuserdescrs[PyArray_NUMUSERTYPES++] = descr;\n\treturn typenum;\n}\n\n\n/*\n copyies over from the old descr table for anything\n NULL or zero in what is given.\n DECREF's the Descr already there.\n places a pointer to the new one into the slot.\n*/\n\n/* steals a reference to descr */\n/*OBJECT_API\n Insert Descr Table\n*/\nstatic int\nPyArray_RegisterDescrForType(int typenum, PyArray_Descr *descr)\n{\n\tPyArray_Descr *old;\n\n\tif (!PyTypeNum_ISUSERDEF(typenum)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"data type not registered\");\n\t\tPy_DECREF(descr);\n\t\treturn -1;\n\t}\n\told = userdescrs[typenum-PyArray_USERDEF];\n\tdescr->typeobj = old->typeobj;\n\tdescr->type_num = typenum;\n\n\tif (descr->f == NULL) descr->f = old->f;\n\tif (descr->fields == NULL) {\n\t\tdescr->fields = old->fields;\n\t\tPy_XINCREF(descr->fields);\n\t}\n\tif (descr->subarray == NULL && old->subarray) {\n\t\tdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(descr->subarray, old->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(descr->subarray->shape);\n\t\tPy_INCREF(descr->subarray->base);\n\t}\n Py_XINCREF(descr->typeobj);\n\n#define _ZERO_CHECK(member) \\\n\tif (descr->member == 0) descr->member = old->member\n\n\t_ZERO_CHECK(kind);\n\t_ZERO_CHECK(type);\n _ZERO_CHECK(byteorder);\n\t_ZERO_CHECK(elsize);\n\t_ZERO_CHECK(alignment);\n#undef _ZERO_CHECK\n\n\tPy_DECREF(old);\n\tuserdescrs[typenum-PyArray_USERDEF] = descr;\n\treturn 0;\n}\n\n\n/*OBJECT_API\n To File\n*/\nstatic int\nPyArray_ToFile(PyArrayObject *self, FILE *fp, char *sep, char *format)\n{\n intp size;\n intp n, n2;\n int n3, n4;\n PyArrayIterObject *it;\n PyObject *obj, *strobj, *tupobj;\n\n\tn3 = (sep ? strlen((const char *)sep) : 0);\n\tif (n3 == 0) { /* binary data */\n if (PyArray_ISOBJECT(self)) {\n PyErr_SetString(PyExc_ValueError, \"cannot write \"\\\n\t\t\t\t\t\"object arrays to a file in \"\t\\\n\t\t\t\t\t\"binary mode\");\n return -1;\n }\n\n if (PyArray_ISCONTIGUOUS(self)) {\n size = PyArray_SIZE(self);\n if ((n=fwrite((const void *)self->data,\n (size_t) self->descr->elsize,\n (size_t) size, fp)) < size) {\n PyErr_Format(PyExc_ValueError,\n \"%ld requested and %ld written\",\n (long) size, (long) n);\n return -1;\n }\n }\n else {\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n while(it->index < it->size) {\n if (fwrite((const void *)it->dataptr,\n (size_t) self->descr->elsize,\n 1, fp) < 1) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element\"\\\n \" %d to file\",\n\t\t\t\t\t\t (int)it->index);\n Py_DECREF(it);\n return -1;\n }\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n }\n else { /* text data */\n it=(PyArrayIterObject *) \\\n PyArray_IterNew((PyObject *)self);\n\t\tn4 = (format ? strlen((const char *)format) : 0);\n while(it->index < it->size) {\n obj = self->descr->f->getitem(it->dataptr, self);\n if (obj == NULL) {Py_DECREF(it); return -1;}\n\t\t\tif (n4 == 0) { /* standard writing */\n\t\t\t\tstrobj = PyObject_Str(obj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n\t\t\telse { /* use format string */\n\t\t\t\ttupobj = PyTuple_New(1);\n\t\t\t\tif (tupobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t\tPyTuple_SET_ITEM(tupobj,0,obj);\n\t\t\t\tobj = PyString_FromString((const char *)format);\n\t\t\t\tif (obj == NULL) {Py_DECREF(tupobj);\n\t\t\t\t\tPy_DECREF(it); return -1;}\n\t\t\t\tstrobj = PyString_Format(obj, tupobj);\n\t\t\t\tPy_DECREF(obj);\n\t\t\t\tPy_DECREF(tupobj);\n\t\t\t\tif (strobj == NULL) {Py_DECREF(it); return -1;}\n\t\t\t}\n if ((n=fwrite(PyString_AS_STRING(strobj),\n 1, n2=PyString_GET_SIZE(strobj),\n fp)) < n2) {\n PyErr_Format(PyExc_IOError,\n \"problem writing element %d\"\\\n \" to file\",\n\t\t\t\t\t (int) it->index);\n Py_DECREF(strobj);\n Py_DECREF(it);\n return -1;\n }\n /* write separator for all but last one */\n if (it->index != it->size-1) \n if (fwrite(sep, 1, n3, fp) < n3) {\n\t\t\t\t\tPyErr_Format(PyExc_IOError,\n\t\t\t\t\t\t \"problem writing \"\\\n\t\t\t\t\t\t \"separator to file\");\n\t\t\t\t\tPy_DECREF(strobj);\n\t\t\t\t\tPy_DECREF(it);\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n Py_DECREF(strobj);\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n return 0;\n}\n\n/*OBJECT_API\n To List\n*/\nstatic PyObject *\nPyArray_ToList(PyArrayObject *self)\n{\n PyObject *lp;\n PyArrayObject *v;\n intp sz, i;\n\n if (!PyArray_Check(self)) return (PyObject *)self;\n\n if (self->nd == 0)\n\t\treturn self->descr->f->getitem(self->data,self);\n\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\n for (i=0; ind >= self->nd) {\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"array_item not returning smaller-\" \\\n\t\t\t\t\t\"dimensional array\");\n Py_DECREF(v);\n\t\t\tPy_DECREF(lp);\n\t\t\treturn NULL;\n\t\t}\n PyList_SetItem(lp, i, PyArray_ToList(v));\n\t\tPy_DECREF(v);\n }\n\n return lp;\n}\n\nstatic PyObject *\nPyArray_ToString(PyArrayObject *self)\n{\n intp numbytes;\n intp index;\n char *dptr;\n int elsize;\n PyObject *ret;\n PyArrayIterObject *it;\n\n\t/* if (PyArray_TYPE(self) == PyArray_OBJECT) {\n\t\t PyErr_SetString(PyExc_ValueError, \"a string for the data\" \\\n\t\t \"in an object array is not appropriate\");\n\t\t return NULL;\n\t\t }\n\t*/\n\n numbytes = PyArray_NBYTES(self);\n if (PyArray_ISONESEGMENT(self)) {\n ret = PyString_FromStringAndSize(self->data, (int) numbytes);\n }\n else {\n it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n if (it==NULL) return NULL;\n ret = PyString_FromStringAndSize(NULL, (int) numbytes);\n if (ret == NULL) {Py_DECREF(it); return NULL;}\n dptr = PyString_AS_STRING(ret);\n index = it->size;\n elsize = self->descr->elsize;\n while(index--) {\n memcpy(dptr, it->dataptr, elsize);\n dptr += elsize;\n PyArray_ITER_NEXT(it);\n }\n Py_DECREF(it);\n }\n\treturn ret;\n}\n\n\n/*********************** end C-API functions **********************/\n\n\n/* array object functions */\n\nstatic void\narray_dealloc(PyArrayObject *self) {\n\n if (self->weakreflist != NULL)\n PyObject_ClearWeakRefs((PyObject *)self);\n\n if(self->base) {\n\t\t/* UPDATEIFCOPY means that base points to an\n\t\t array that should be updated with the contents\n\t\t of this array upon destruction.\n self->base->flags must have been WRITEABLE\n (checked previously) and it was locked here\n thus, unlock it.\n\t\t*/\n\t\tif (self->flags & UPDATEIFCOPY) {\n ((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tPy_INCREF(self); /* hold on to self in next call */\n PyArray_CopyInto((PyArrayObject *)self->base, self);\n\t\t\t/* Don't need to DECREF -- because we are deleting\n\t\t\t self already... */\n\t\t}\n\t\t/* In any case base is pointing to something that we need\n\t\t to DECREF -- either a view or a buffer object */\n Py_DECREF(self->base);\n }\n\n if ((self->flags & OWN_DATA) && self->data) {\n\t\t/* Free internal references if an Object array */\n\t\tif (PyArray_ISOBJECT(self))\n\t\t\tPyArray_XDECREF(self);\n PyDataMem_FREE(self->data);\n }\n\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\narray_length(PyArrayObject *self)\n{\n if (self->nd != 0) {\n return self->dimensions[0];\n } else {\n\t\tPyErr_SetString(PyExc_TypeError, \"len() of unsized object\");\n\t\treturn -1;\n }\n}\n\nstatic PyObject *\narray_big_item(PyArrayObject *self, intp i)\n{\n\tchar *item;\n\tPyArrayObject *r;\n\n\tif(self->nd == 0) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can't be indexed\");\n\t\treturn NULL;\n\t}\n if ((item = index2ptr(self, i)) == NULL) return NULL;\n\n\tPy_INCREF(self->descr);\n\tr = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t self->nd-1,\n\t\t\t\t\t\t self->dimensions+1,\n\t\t\t\t\t\t self->strides+1, item,\n\t\t\t\t\t\t self->flags,\n\t\t\t\t\t\t (PyObject *)self);\n\tif (r == NULL) return NULL;\n\tPy_INCREF(self);\n\tr->base = (PyObject *)self;\n PyArray_UpdateFlags(r, CONTIGUOUS | FORTRAN);\n\treturn (PyObject *)r;\n}\n\n/* contains optimization for 1-d arrays */\nstatic PyObject *\narray_item_nice(PyArrayObject *self, _int_or_ssize_t i)\n{\n\tif (self->nd == 1) {\n\t\tchar *item;\n if (i < 0) {\n\t\t\ti += self->dimensions[0];\n\t\t}\n\t\tif ((item = index2ptr(self, i)) == NULL) return NULL;\n\t\treturn PyArray_Scalar(item, self->descr, (PyObject *)self);\n\t}\n\telse {\n\t\treturn PyArray_Return((PyArrayObject *)\\\n\t\t\t\t array_big_item(self, (intp) i));\n\t}\n}\n\nstatic int\narray_ass_big_item(PyArrayObject *self, intp i, PyObject *v)\n{\n PyArrayObject *tmp;\n char *item;\n int ret;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"can't delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if (self->nd == 0) {\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n if (i < 0) i = i+self->dimensions[0];\n\n if (self->nd > 1) {\n if((tmp = (PyArrayObject *)array_big_item(self, i)) == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n return ret;\n }\n\n if ((item = index2ptr(self, i)) == NULL) return -1;\n if (self->descr->f->setitem(v, item, self) == -1) return -1;\n return 0;\n}\n\n#if PY_VERSION_HEX < 0x02050000\n #if SIZEOF_INT == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#else\n #if SIZEOF_SIZE_T == SIZEOF_INTP\n #define array_ass_item array_ass_big_item\n #endif\n#endif\n#ifndef array_ass_item\nstatic int\narray_ass_item(PyArrayObject *self, _int_or_ssize_t i, PyObject *v)\n{\n\treturn array_ass_big_item(self, (intp) i, v);\n}\n#endif\n\n\n/* -------------------------------------------------------------- */\nstatic int\nslice_coerce_index(PyObject *o, intp *v)\n{\n\t*v = PyArray_PyIntAsIntp(o);\n\tif (error_converting(*v)) {\n\t\tPyErr_Clear();\n\t\treturn 0;\n\t}\n\treturn 1;\n}\n\n\n/* This is basically PySlice_GetIndicesEx, but with our coercion\n * of indices to integers (plus, that function is new in Python 2.3) */\nstatic int\nslice_GetIndices(PySliceObject *r, intp length,\n intp *start, intp *stop, intp *step,\n intp *slicelength)\n{\n\tintp defstart, defstop;\n\n\tif (r->step == Py_None) {\n\t\t*step = 1;\n\t} else {\n\t\tif (!slice_coerce_index(r->step, step)) return -1;\n\t\tif (*step == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"slice step cannot be zero\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\n\tif (r->start == Py_None) {\n\t\t*start = *step < 0 ? length-1 : 0;\n\t} else {\n\t\tif (!slice_coerce_index(r->start, start)) return -1;\n\t\tif (*start < 0) *start += length;\n\t\tif (*start < 0) *start = (*step < 0) ? -1 : 0;\n\t\tif (*start >= length) {\n\t\t\t*start = (*step < 0) ? length - 1 : length;\n\t\t}\n\t}\n\n\tif (r->stop == Py_None) {\n\t\t*stop = defstop;\n\t} else {\n\t\tif (!slice_coerce_index(r->stop, stop)) return -1;\n\t\tif (*stop < 0) *stop += length;\n if (*stop < 0) *stop = -1;\n if (*stop > length) *stop = length;\n\t}\n\n\tif ((*step < 0 && *stop >= *start) || \\\n\t (*step > 0 && *start >= *stop)) {\n\t\t*slicelength = 0;\n\t} else if (*step < 0) {\n\t\t*slicelength = (*stop - *start + 1) / (*step) + 1;\n\t} else {\n\t\t*slicelength = (*stop - *start - 1) / (*step) + 1;\n\t}\n\n\treturn 0;\n}\n\n#define PseudoIndex -1\n#define RubberIndex -2\n#define SingleIndex -3\n\nstatic intp\nparse_subindex(PyObject *op, intp *step_size, intp *n_steps, intp max)\n{\n\tintp index;\n\n\tif (op == Py_None) {\n\t\t*n_steps = PseudoIndex;\n\t\tindex = 0;\n\t} else if (op == Py_Ellipsis) {\n\t\t*n_steps = RubberIndex;\n\t\tindex = 0;\n\t} else if (PySlice_Check(op)) {\n\t\tintp stop;\n\t\tif (slice_GetIndices((PySliceObject *)op, max,\n\t\t\t\t &index, &stop, step_size, n_steps) < 0) {\n\t\t\tif (!PyErr_Occurred()) {\n\t\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\t\"invalid slice\");\n\t\t\t}\n\t\t\tgoto fail;\n\t\t}\n\t\tif (*n_steps <= 0) {\n\t\t\t*n_steps = 0;\n\t\t\t*step_size = 1;\n\t\t\tindex = 0;\n\t\t}\n\t} else {\n\t\tindex = PyArray_PyIntAsIntp(op);\n\t\tif (error_converting(index)) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"each subindex must be either a \"\\\n\t\t\t\t\t\"slice, an integer, Ellipsis, or \"\\\n\t\t\t\t\t\"newaxis\");\n\t\t\tgoto fail;\n\t\t}\n\t\t*n_steps = SingleIndex;\n\t\t*step_size = 0;\n\t\tif (index < 0) index += max;\n\t\tif (index >= max || index < 0) {\n\t\t\tPyErr_SetString(PyExc_IndexError, \"invalid index\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\treturn index;\n fail:\n\treturn -1;\n}\n\n\nstatic int\nparse_index(PyArrayObject *self, PyObject *op,\n intp *dimensions, intp *strides, intp *offset_ptr)\n{\n int i, j, n;\n int nd_old, nd_new, n_add, n_pseudo;\n\tintp n_steps, start, offset, step_size;\n PyObject *op1=NULL;\n int is_slice;\n\n\n if (PySlice_Check(op) || op == Py_Ellipsis || op == Py_None) {\n n = 1;\n op1 = op;\n Py_INCREF(op);\n /* this relies on the fact that n==1 for loop below */\n is_slice = 1;\n }\n else {\n if (!PySequence_Check(op)) {\n PyErr_SetString(PyExc_IndexError,\n \"index must be either an int \"\\\n \"or a sequence\");\n return -1;\n }\n n = PySequence_Length(op);\n is_slice = 0;\n }\n\n nd_old = nd_new = 0;\n\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\n if (n_steps == PseudoIndex) {\n dimensions[nd_new] = 1; strides[nd_new] = 0; nd_new++;\n } else {\n if (n_steps == RubberIndex) {\n for(j=i+1, n_pseudo=0; jnd-(n-i-n_pseudo-1+nd_old);\n if (n_add < 0) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = \\\n self->strides[nd_old];\n nd_new++; nd_old++;\n }\n } else {\n if (nd_old >= self->nd) {\n PyErr_SetString(PyExc_IndexError,\n \"too many indices\");\n return -1;\n }\n offset += self->strides[nd_old]*start;\n nd_old++;\n if (n_steps != SingleIndex) {\n dimensions[nd_new] = n_steps;\n strides[nd_new] = step_size * \\\n self->strides[nd_old-1];\n nd_new++;\n }\n }\n }\n }\n if (i < n) return -1;\n n_add = self->nd-nd_old;\n for(j=0; jdimensions[nd_old];\n strides[nd_new] = self->strides[nd_old];\n nd_new++; nd_old++;\n }\n *offset_ptr = offset;\n return nd_new;\n}\n\nstatic void\n_swap_axes(PyArrayMapIterObject *mit, PyArrayObject **ret)\n{\n\tPyObject *new;\n\tint n1, n2, n3, val;\n\tint i;\n\tPyArray_Dims permute;\n\tintp d[MAX_DIMS];\n PyArrayObject *arr;\n\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\n\n /* arr might not have the right number of dimensions\n and need to be reshaped first by pre-pending ones */\n arr = *ret; \n if (arr->nd != mit->nd) {\n for (i=1; i<=arr->nd; i++) {\n permute.ptr[mit->nd-i] = arr->dimensions[arr->nd-i];\n }\n for (i=0; ind-arr->nd; i++) {\n permute.ptr[i] = 1;\n } \n new = PyArray_Newshape(arr, &permute, PyArray_ANYORDER);\n Py_DECREF(arr);\n *ret = (PyArrayObject *)new;\n if (new == NULL) return;\n }\n\n\t/* tuple for transpose is\n\t (n1,..,n1+n2-1,0,..,n1-1,n1+n2,...,n3-1)\n\t n1 is the number of dimensions of\n\t the broadcasted index array\n\t n2 is the number of dimensions skipped at the\n\t start\n\t n3 is the number of dimensions of the\n\t result\n\t*/\n\tn1 = mit->iters[0]->nd_m1 + 1;\n\tn2 = mit->iteraxes[0];\n\tn3 = mit->nd;\n\tval = n1;\n\ti = 0;\n\twhile(val < n1+n2)\n\t\tpermute.ptr[i++] = val++;\n\tval = 0;\n\twhile(val < n1)\n\t\tpermute.ptr[i++] = val++;\n\tval = n1+n2;\n\twhile(val < n3)\n\t\tpermute.ptr[i++] = val++;\n\n\tnew = PyArray_Transpose(*ret, &permute);\n\tPy_DECREF(*ret);\n\t*ret = (PyArrayObject *)new;\n}\n\n/* Prototypes for Mapping calls --- not part of the C-API\n because only useful as part of a getitem call.\n*/\n\nstatic void PyArray_MapIterReset(PyArrayMapIterObject *);\nstatic void PyArray_MapIterNext(PyArrayMapIterObject *);\nstatic void PyArray_MapIterBind(PyArrayMapIterObject *, PyArrayObject *);\nstatic PyObject* PyArray_MapIterNew(PyObject *, int, int);\n\nstatic PyObject *\nPyArray_GetMap(PyArrayMapIterObject *mit)\n{\n\n\tPyArrayObject *ret, *temp;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\t/* Unbound map iterator --- Bind should have been called */\n\tif (mit->ait == NULL) return NULL;\n\n\t/* This relies on the map iterator object telling us the shape\n\t of the new array in nd and dimensions.\n\t*/\n\ttemp = mit->ait->ao;\n\tPy_INCREF(temp->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(temp->ob_type,\n\t\t\t\t temp->descr,\n\t\t\t\t mit->nd, mit->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t PyArray_ISFORTRAN(temp),\n\t\t\t\t (PyObject *)temp);\n\tif (ret == NULL) return NULL;\n\n\t/* Now just iterate through the new array filling it in\n\t with the next object from the original array as\n\t defined by the mapping iterator */\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ret))\n\t == NULL) {\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\tindex = it->size;\n\tswap = (PyArray_ISNOTSWAPPED(temp) != PyArray_ISNOTSWAPPED(ret));\n copyswap = ret->descr->f->copyswap;\n\tPyArray_MapIterReset(mit);\n\twhile (index--) {\n copyswap(it->dataptr, mit->dataptr, swap, ret);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\n\t/* check for consecutive axes */\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, &ret);\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\nstatic int\nPyArray_SetMap(PyArrayMapIterObject *mit, PyObject *op)\n{\n\tPyObject *arr=NULL;\n\tPyArrayIterObject *it;\n\tint index;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\tPyArray_Descr *descr;\n\n\t/* Unbound Map Iterator */\n\tif (mit->ait == NULL) return -1;\n\n\tdescr = mit->ait->ao->descr;\n\tPy_INCREF(descr);\n\tarr = PyArray_FromAny(op, descr, 0, 0, FORCECAST, NULL);\n\tif (arr == NULL) return -1;\n\n\tif ((mit->subspace != NULL) && (mit->consec)) {\n\t\tif (mit->iteraxes[0] > 0) { /* then we need to swap */\n\t\t\t_swap_axes(mit, (PyArrayObject **)&arr);\n\t\t\tif (arr == NULL) return -1;\n\t\t}\n\t}\n\t\n\n\tif ((it = (PyArrayIterObject *)PyArray_IterNew(arr))==NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn -1;\n\t}\n\n\tindex = mit->size;\n\tswap = (PyArray_ISNOTSWAPPED(mit->ait->ao) != \\\n\t\t(PyArray_ISNOTSWAPPED(arr)));\n\n copyswap = PyArray_DESCR(arr)->f->copyswap;\n\tPyArray_MapIterReset(mit);\n /* Need to decref OBJECT arrays */\n if (PyTypeNum_ISOBJECT(descr->type_num)) {\n while (index--) {\n Py_XDECREF(*((PyObject **)mit->dataptr));\n Py_INCREF(*((PyObject **)it->dataptr));\n memmove(mit->dataptr, it->dataptr, sizeof(PyObject *));\n PyArray_MapIterNext(mit);\n PyArray_ITER_NEXT(it);\n if (it->index == it->size)\n PyArray_ITER_RESET(it);\n }\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(it);\n return 0;\n }\n\twhile(index--) {\n\t\tmemmove(mit->dataptr, it->dataptr, PyArray_ITEMSIZE(arr));\n copyswap(mit->dataptr, NULL, swap, arr);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t\tif (it->index == it->size)\n\t\t\tPyArray_ITER_RESET(it);\n\t}\n\tPy_DECREF(arr);\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nint\ncount_new_axes_0d(PyObject *tuple)\n{\n\tint i, argument_count;\n\tint ellipsis_count = 0;\n\tint newaxis_count = 0;\n\n\targument_count = PyTuple_GET_SIZE(tuple);\n\n\tfor (i = 0; i < argument_count; ++i) {\n\t\tPyObject *arg = PyTuple_GET_ITEM(tuple, i);\n\t\tif (arg == Py_Ellipsis && !ellipsis_count) ellipsis_count++;\n\t\telse if (arg == Py_None) newaxis_count++;\n\t\telse break;\n\t}\n\tif (i < argument_count) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"0-d arrays can only use a single ()\"\n\t\t\t\t\" or a list of newaxes (and a single ...)\"\n\t\t\t\t\" as an index\");\n\t\treturn -1;\n\t}\n\tif (newaxis_count > MAX_DIMS) {\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"too many dimensions\");\n\t\treturn -1;\n\t}\n\treturn newaxis_count;\n}\n\nstatic PyObject *\nadd_new_axes_0d(PyArrayObject *arr, int newaxis_count)\n{\n\tPyArrayObject *other;\n\tintp dimensions[MAX_DIMS];\n\tint i;\n\tfor (i = 0; i < newaxis_count; ++i) {\n\t\tdimensions[i] = 1;\n\t}\n\tPy_INCREF(arr->descr);\n\tif ((other = (PyArrayObject *)\n\t PyArray_NewFromDescr(arr->ob_type, arr->descr,\n\t\t\t\t newaxis_count, dimensions,\n\t\t\t\t NULL, arr->data,\n\t\t\t\t arr->flags,\n\t\t\t\t (PyObject *)arr)) == NULL)\n\t\treturn NULL;\n\tother->base = (PyObject *)arr;\n\tPy_INCREF(arr);\n\treturn (PyObject *)other;\n}\n\n\n/* This checks the args for any fancy indexing objects */\n\n#define SOBJ_NOTFANCY 0\n#define SOBJ_ISFANCY 1\n#define SOBJ_BADARRAY 2\n#define SOBJ_TOOMANY 3\n#define SOBJ_LISTTUP 4\n\nstatic int\nfancy_indexing_check(PyObject *args)\n{\n\tint i, n;\n\tPyObject *obj;\n\tint retval = SOBJ_NOTFANCY;\n\n\tif (PyTuple_Check(args)) {\n\t\tn = PyTuple_GET_SIZE(args);\n\t\tif (n >= MAX_DIMS) return SOBJ_TOOMANY;\n\t\tfor (i=0; i=MAX_DIMS) return SOBJ_ISFANCY;\n\t\tfor (i=0; i SOBJ_ISFANCY) return retval;\n\t\t}\n\t}\n\n\treturn retval;\n}\n\n/* Called when treating array object like a mapping -- called first from\n Python when using a[object] unless object is a standard slice object\n (not an extended one).\n\n*/\n\n/* There are two situations:\n\n 1 - the subscript is a standard view and a reference to the\n array can be returned\n\n 2 - the subscript uses Boolean masks or integer indexing and\n therefore a new array is created and returned.\n\n*/\n\n/* Always returns arrays */\n\nstatic PyObject *iter_subscript(PyArrayIterObject *, PyObject *);\n\n\nstatic PyObject *\narray_subscript(PyArrayObject *self, PyObject *op)\n{\n intp dimensions[MAX_DIMS], strides[MAX_DIMS];\n\tintp offset;\n int nd, oned, fancy;\n\tintp i;\n PyArrayObject *other;\n\tPyArrayMapIterObject *mit;\n\n\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_GetField(self, descr,\n\t\t\t\t\t\t\t\toffset);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(op));\n\t\treturn NULL;\n\t}\n if (self->nd == 0) {\n\t\tif (op == Py_Ellipsis) {\n\t\t\t/* XXX: This leads to a small inconsistency\n\t\t\t XXX: with the nd>0 case where (x[...] is x)\n\t\t\t XXX: is false for nd>0 case. */\n\t\t\tPy_INCREF(self);\n\t\t\treturn (PyObject *)self;\n\t\t}\n\t\tif (op == Py_None)\n\t\t\treturn add_new_axes_0d(self, 1);\n\t\tif (PyTuple_Check(op)) {\n\t\t\tif (0 == PyTuple_GET_SIZE(op)) {\n\t\t\t\tPy_INCREF(self);\n\t\t\t\treturn (PyObject *)self;\n\t\t\t}\n\t\t\tif ((nd = count_new_axes_0d(op)) == -1)\n\t\t\t\treturn NULL;\n\t\t\treturn add_new_axes_0d(self, nd);\n\t\t}\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return NULL;\n }\n if (PyArray_IsScalar(op, Integer) || PyInt_Check(op) || \\\n PyLong_Check(op)) {\n intp value;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred())\n\t\t\tPyErr_Clear();\n else if (value >= 0) {\n\t\t\treturn array_big_item(self, value);\n }\n else /* (value < 0) */ {\n\t\t\tvalue += self->dimensions[0];\n\t\t\treturn array_big_item(self, value);\n\t\t}\n }\n\n\tfancy = fancy_indexing_check(op);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(op) &&\t\\\n\t\t\t\t\t PyTuple_GET_SIZE(op) > 1));\n\n\t\t/* wrap arguments into a mapiter object */\n\t\tmit = (PyArrayMapIterObject *)\\\n\t\t\tPyArray_MapIterNew(op, oned, fancy);\n\t\tif (mit == NULL) return NULL;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tPyObject *rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return NULL;}\n\t\t\trval = iter_subscript(it, mit->indexobj);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n other = (PyArrayObject *)PyArray_GetMap(mit);\n Py_DECREF(mit);\n return (PyObject *)other;\n }\n\n\ti = PyArray_PyIntAsIntp(op);\n\tif (!error_converting(i)) {\n\t\tif (i < 0 && self->nd > 0) i = i+self->dimensions[0];\n\t\treturn array_big_item(self, i);\n\t}\n\tPyErr_Clear();\n\n\t/* Standard (view-based) Indexing */\n if ((nd = parse_index(self, op, dimensions, strides, &offset))\n == -1)\n return NULL;\n\n\t/* This will only work if new array will be a view */\n\tPy_INCREF(self->descr);\n\tif ((other = (PyArrayObject *)\t\t\t\t\t\\\n\t PyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t nd, dimensions,\n\t\t\t\t strides, self->data+offset,\n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self)) == NULL)\n\t\treturn NULL;\n\n\n\tother->base = (PyObject *)self;\n\tPy_INCREF(self);\n\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\n\treturn (PyObject *)other;\n}\n\n\n/* Another assignment hacked by using CopyObject. */\n\n/* This only works if subscript returns a standard view. */\n\n/* Again there are two cases. In the first case, PyArray_CopyObject\n can be used. In the second case, a new indexing function has to be\n used.\n*/\n\nstatic int iter_ass_subscript(PyArrayIterObject *, PyObject *, PyObject *);\n\nstatic int\narray_ass_sub(PyArrayObject *self, PyObject *index, PyObject *op)\n{\n int ret, oned, fancy;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\n if (op == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n\n if (PyArray_IsScalar(index, Integer) || PyInt_Check(index) ||\t\\\n PyLong_Check(index)) {\n intp value;\n value = PyArray_PyIntAsIntp(index);\n if (PyErr_Occurred())\n PyErr_Clear();\n\t\telse\n\t\t\treturn array_ass_big_item(self, value, op);\n }\n\n\tif (PyString_Check(index) || PyUnicode_Check(index)) {\n\t\tif (self->descr->fields) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->descr->fields, index);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tint offset;\n\t\t\t\tPyObject *title;\n\n\t\t\t\tif (PyArg_ParseTuple(obj, \"Oi|O\",\n\t\t\t\t\t\t &descr, &offset, &title)) {\n\t\t\t\t\tPy_INCREF(descr);\n\t\t\t\t\treturn PyArray_SetField(self, descr,\n\t\t\t\t\t\t\t\toffset, op);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"field named %s not found.\",\n\t\t\t PyString_AsString(index));\n\t\treturn -1;\n\t}\n\n if (self->nd == 0) {\n\t\tif (index == Py_Ellipsis || index == Py_None ||\t\t\\\n\t\t (PyTuple_Check(index) && (0 == PyTuple_GET_SIZE(index) || \\\n\t\t\t\t\t count_new_axes_0d(index) > 0)))\n\t\t\treturn self->descr->f->setitem(op, self->data, self);\n PyErr_SetString(PyExc_IndexError,\n \"0-d arrays can't be indexed.\");\n return -1;\n }\n\n\tfancy = fancy_indexing_check(index);\n\n\tif (fancy != SOBJ_NOTFANCY) {\n\t\toned = ((self->nd == 1) && !(PyTuple_Check(index) && \\\n\t\t\t\t\t PyTuple_GET_SIZE(index) > 1));\n\n\t\tmit = (PyArrayMapIterObject *)\t\t\t\\\n\t\t\tPyArray_MapIterNew(index, oned, fancy);\n\t\tif (mit == NULL) return -1;\n\t\tif (oned) {\n\t\t\tPyArrayIterObject *it;\n\t\t\tint rval;\n\t\t\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\t\t\tif (it == NULL) {Py_DECREF(mit); return -1;}\n\t\t\trval = iter_ass_subscript(it, mit->indexobj, op);\n\t\t\tPy_DECREF(it);\n\t\t\tPy_DECREF(mit);\n\t\t\treturn rval;\n\t\t}\n PyArray_MapIterBind(mit, self);\n ret = PyArray_SetMap(mit, op);\n Py_DECREF(mit);\n return ret;\n }\n\n\ti = PyArray_PyIntAsIntp(index);\n\tif (!error_converting(i)) {\n\t\treturn array_ass_big_item(self, i, op);\n\t}\n\tPyErr_Clear();\n\n\t/* Rest of standard (view-based) indexing */\n\n if ((tmp = (PyArrayObject *)array_subscript(self, index)) == NULL)\n return -1;\n\tif (PyArray_ISOBJECT(self) && (tmp->nd == 0)) {\n\t\tret = tmp->descr->f->setitem(op, tmp->data, tmp);\n\t}\n\telse {\n\t\tret = PyArray_CopyObject(tmp, op);\n\t}\n\tPy_DECREF(tmp);\n return ret;\n}\n\n\n/* There are places that require that array_subscript return a PyArrayObject\n and not possibly a scalar. Thus, this is the function exposed to\n Python so that 0-dim arrays are passed as scalars\n*/\n\nstatic PyObject *\narray_subscript_nice(PyArrayObject *self, PyObject *op)\n{\n\t/* The following is just a copy of PyArray_Return with an\n\t additional logic in the nd == 0 case. More efficient\n\t implementation may be possible by refactoring\n\t array_subscript */\n\n\tPyArrayObject *mp;\n\n\t/* optimization for integer select and 1-d */\n\tif (self->nd == 1 && (PyInt_Check(op) || PyLong_Check(op))) {\n intp value;\n\t\tchar *item;\n value = PyArray_PyIntAsIntp(op);\n\t\tif (PyErr_Occurred()) \n\t\t\treturn NULL;\n else if (value < 0) {\n\t\t\tvalue += self->dimensions[0];\n\t\t}\n\t\tif ((item = index2ptr(self, value)) == NULL) return NULL;\n\t\treturn PyArray_Scalar(item, self->descr, (PyObject *)self);\n\t}\n\tmp = (PyArrayObject *)array_subscript(self, op);\n\n\tif (mp == NULL) return NULL;\n\n if (PyErr_Occurred()) {\n Py_XDECREF(mp);\n return NULL;\n }\n\n\tif (!PyArray_Check(mp)) return (PyObject *)mp;\n\t\n\tif (mp->nd == 0) {\n\t\tBool noellipses = TRUE;\n\t\tif (op == Py_Ellipsis)\n\t\t\tnoellipses = FALSE;\n\t\telse if (PySequence_Check(op)) {\n\t\t\tint n, i;\n\t\t\tn = PySequence_Size(op);\n\t\t\tfor (i = 0; i < n; ++i) \n\t\t\t\tif (PySequence_GetItem(op, i) == Py_Ellipsis) {\n\t\t\t\t\tnoellipses = FALSE;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t}\n\t\tif (noellipses) {\n\t\t\tPyObject *ret;\n\t\t\tret = PyArray_ToScalar(mp->data, mp);\n\t\t\tPy_DECREF(mp);\n\t\t\treturn ret;\n\t\t}\n\t}\n\treturn (PyObject *)mp;\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t /*mp_length*/\n#else\n (inquiry)array_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)array_subscript_nice,\t/*mp_subscript*/\n (objobjargproc)array_ass_sub,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\n/*************************************************************************\n **************** Implement Buffer Protocol ****************************\n *************************************************************************/\n\n/* removed multiple segment interface */\n\nstatic _int_or_ssize_t\narray_getsegcount(PyArrayObject *self, _int_or_ssize_t *lenp)\n{\n if (lenp)\n *lenp = PyArray_NBYTES(self);\n\n if (PyArray_ISONESEGMENT(self)) {\n return 1;\n }\n\n if (lenp)\n *lenp = 0;\n return 0;\n}\n\nstatic _int_or_ssize_t\narray_getreadbuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (segment != 0) {\n PyErr_SetString(PyExc_ValueError,\n \"accessing non-existing array segment\");\n return -1;\n }\n\n if (PyArray_ISONESEGMENT(self)) {\n *ptrptr = self->data;\n return PyArray_NBYTES(self);\n }\n PyErr_SetString(PyExc_ValueError, \"array is not a single segment\");\n *ptrptr = NULL;\n return -1;\n}\n\n\nstatic _int_or_ssize_t\narray_getwritebuf(PyArrayObject *self, _int_or_ssize_t segment, void **ptrptr)\n{\n if (PyArray_CHKFLAGS(self, WRITEABLE))\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_ValueError, \"array cannot be \"\\\n \"accessed as a writeable buffer\");\n return -1;\n }\n}\n\nstatic _int_or_ssize_t\narray_getcharbuf(PyArrayObject *self, _int_or_ssize_t segment, const char **ptrptr)\n{\n if (self->descr->type_num == PyArray_STRING || \\\n\t self->descr->type_num == PyArray_UNICODE)\n return array_getreadbuf(self, segment, (void **) ptrptr);\n else {\n PyErr_SetString(PyExc_TypeError,\n \"non-character array cannot be interpreted \"\\\n \"as character buffer\");\n return -1;\n }\n}\n\nstatic PyBufferProcs array_as_buffer = {\n#if PY_VERSION_HEX >= 0x02050000\n (readbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (writebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (segcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (charbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#else\n (getreadbufferproc)array_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)array_getwritebuf, /*bf_getwritebuffer*/\n (getsegcountproc)array_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)array_getcharbuf, /*bf_getcharbuffer*/\n#endif\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Number Protocol ****************************\n *************************************************************************/\n\n\ntypedef struct {\n PyObject *add,\n *subtract,\n *multiply,\n *divide,\n *remainder,\n *power,\n *square,\n *reciprocal,\n *ones_like,\n\t\t*sqrt,\n *negative,\n *absolute,\n *invert,\n *left_shift,\n *right_shift,\n *bitwise_and,\n *bitwise_xor,\n *bitwise_or,\n *less,\n *less_equal,\n *equal,\n *not_equal,\n *greater,\n *greater_equal,\n *floor_divide,\n *true_divide,\n\t\t*logical_or,\n\t\t*logical_and,\n\t\t*floor,\n\t\t*ceil,\n\t\t*maximum,\n\t\t*minimum,\n\t\t*rint;\n} NumericOps;\n\nstatic NumericOps n_ops; /* NB: static objects inlitialized to zero */\n\n/* Dictionary can contain any of the numeric operations, by name.\n Those not present will not be changed\n */\n\n#define SET(op) temp=PyDict_GetItemString(dict, #op);\t\\\n\tif (temp != NULL) {\t\t\t\t\\\n\t\tif (!(PyCallable_Check(temp))) return -1; \\\n Py_XDECREF(n_ops.op); \\\n\t\tn_ops.op = temp; \\\n\t}\n\n\n/*OBJECT_API\n Set internal structure with number functions that all arrays will use\n*/\nint\nPyArray_SetNumericOps(PyObject *dict)\n{\n PyObject *temp = NULL;\n SET(add);\n SET(subtract);\n SET(multiply);\n SET(divide);\n SET(remainder);\n SET(power);\n SET(square);\n SET(reciprocal);\n SET(ones_like);\n\tSET(sqrt);\n SET(negative);\n SET(absolute);\n SET(invert);\n SET(left_shift);\n SET(right_shift);\n SET(bitwise_and);\n SET(bitwise_or);\n SET(bitwise_xor);\n SET(less);\n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\n SET(true_divide);\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\n\tSET(rint);\n return 0;\n}\n\n#define GET(op) if (n_ops.op &&\t\t\t\t\t\t\\\n\t\t (PyDict_SetItemString(dict, #op, n_ops.op)==-1))\t\\\n\t\tgoto fail;\n\n/*OBJECT_API\n Get dictionary showing number functions that all arrays will use\n*/\nstatic PyObject *\nPyArray_GetNumericOps(void)\n{\n\tPyObject *dict;\n\tif ((dict = PyDict_New())==NULL)\n\t\treturn NULL;\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\n GET(square);\n GET(reciprocal);\n GET(ones_like);\n\tGET(sqrt);\n GET(negative);\n GET(absolute);\n GET(invert);\n GET(left_shift);\n GET(right_shift);\n GET(bitwise_and);\n GET(bitwise_or);\n GET(bitwise_xor);\n GET(less);\n GET(less_equal);\n GET(equal);\n GET(not_equal);\n GET(greater);\n GET(greater_equal);\n GET(floor_divide);\n GET(true_divide);\n\tGET(logical_or);\n\tGET(logical_and);\n\tGET(floor);\n\tGET(ceil);\n\tGET(maximum);\n\tGET(minimum);\n\tGET(rint);\n\treturn dict;\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\n}\n\nstatic PyObject *\nPyArray_GenericReduceFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"reduce\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericAccumulateFunction(PyArrayObject *m1, PyObject *op, int axis,\n\t\t\t\t int rtype)\n{\n\tPyObject *args, *ret=NULL, *meth;\n\tif (op == NULL) {\n\t\tPy_INCREF(Py_NotImplemented);\n\t\treturn Py_NotImplemented;\n\t}\n\tif (rtype == PyArray_NOTYPE)\n\t\targs = Py_BuildValue(\"(Oi)\", m1, axis);\n\telse {\n\t\tPyArray_Descr *descr;\n\t\tdescr = PyArray_DescrFromType(rtype);\n\t\targs = Py_BuildValue(\"(Oic)\", m1, axis, descr->type);\n\t\tPy_DECREF(descr);\n\t}\n\tmeth = PyObject_GetAttrString(op, \"accumulate\");\n\tif (meth && PyCallable_Check(meth)) {\n\t\tret = PyObject_Call(meth, args, NULL);\n\t}\n\tPy_DECREF(args);\n\tPy_DECREF(meth);\n\treturn ret;\n}\n\n\nstatic PyObject *\nPyArray_GenericBinaryFunction(PyArrayObject *m1, PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m2);\n}\n\nstatic PyObject *\nPyArray_GenericUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"(O)\", m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceBinaryFunction(PyArrayObject *m1,\n\t\t\t\t PyObject *m2, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OOO\", m1, m2, m1);\n}\n\nstatic PyObject *\nPyArray_GenericInplaceUnaryFunction(PyArrayObject *m1, PyObject *op)\n{\n if (op == NULL) {\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n }\n return PyObject_CallFunction(op, \"OO\", m1, m1);\n}\n\nstatic PyObject *\narray_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_subtract(PyArrayObject *m1, PyObject *m2)\n{\n\treturn PyArray_GenericBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic int\narray_power_is_scalar(PyObject *o2, double* exp)\n{\n PyObject *temp;\n const int optimize_fpexps = 1;\n\n if (PyInt_Check(o2)) {\n\t *exp = (double)PyInt_AsLong(o2);\n\t return 1;\n }\n if (optimize_fpexps && PyFloat_Check(o2)) {\n\t *exp = PyFloat_AsDouble(o2);\n\t return 1;\n }\n if ((PyArray_IsZeroDim(o2) && \n\t ((PyArray_ISINTEGER(o2) || \n\t (optimize_fpexps && PyArray_ISFLOAT(o2))))) || \n\tPyArray_IsScalar(o2, Integer) || \n\t(optimize_fpexps && PyArray_IsScalar(o2, Floating))) {\n\t temp = o2->ob_type->tp_as_number->nb_float(o2);\n\t if (temp != NULL) {\n\t\t *exp = PyFloat_AsDouble(o2);\n\t\t Py_DECREF(temp);\n\t\t return 1;\n\t }\n }\n return 0;\n}\n\n/* optimize float array or complex array to a scalar power */\nstatic PyObject *\nfast_scalar_power(PyArrayObject *a1, PyObject *o2, int inplace) {\n\tdouble exp;\n\tif (PyArray_Check(a1) && (PyArray_ISFLOAT(a1) || \n\t\t\t\t PyArray_ISCOMPLEX(a1))) {\n\t\tif (array_power_is_scalar(o2, &exp)) {\n\t\t\tPyObject *fastop = NULL;\n\t\t\tif (exp == 1.0) {\n\t\t\t\t/* we have to do this one special, as the \n\t\t\t\t \"copy\" method of array objects isn't set \n\t\t\t\t up early enough to be added\n\t\t\t\t by PyArray_SetNumericOps.\n\t\t\t\t*/\n\t\t\t\tif (inplace) {\n\t\t\t\t\treturn (PyObject *)a1;\n\t\t\t\t} else {\n\t\t\t\t\treturn PyArray_Copy(a1);\n\t\t\t\t}\n\t\t\t} else if (exp == -1.0) {\n\t\t\t\tfastop = n_ops.reciprocal;\n\t\t\t} else if (exp == 0.0) {\n\t\t\t\tfastop = n_ops.ones_like;\n\t\t\t} else if (exp == 0.5) {\n\t\t\t\tfastop = n_ops.sqrt;\n\t\t\t} else if (exp == 2.0) {\n\t\t\t\tfastop = n_ops.square;\n\t\t\t} else {\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tif (inplace) {\n\t\t\t\tPyArray_GenericInplaceUnaryFunction(a1, \n\t\t\t\t\t\t\t\t fastop);\n\t\t\t} else {\n\t\t\t\treturn PyArray_GenericUnaryFunction(a1, \n\t\t\t\t\t\t\t\t fastop);\n\t\t\t}\n\t\t}\n\t}\n\treturn NULL;\n}\n\nstatic PyObject *\narray_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n\t/* modulo is ignored! */\n\tPyObject *value;\n\tvalue = fast_scalar_power(a1, o2, 0);\n\tif (!value) {\n\t\tvalue = PyArray_GenericBinaryFunction(a1, o2, n_ops.power);\n\t}\n\treturn value;\n}\n\n\nstatic PyObject *\narray_negative(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.negative);\n}\n\nstatic PyObject *\narray_absolute(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.absolute);\n}\n\nstatic PyObject *\narray_invert(PyArrayObject *m1)\n{\n return PyArray_GenericUnaryFunction(m1, n_ops.invert);\n}\n\nstatic PyObject *\narray_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_inplace_add(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.add);\n}\n\nstatic PyObject *\narray_inplace_subtract(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.subtract);\n}\n\nstatic PyObject *\narray_inplace_multiply(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.multiply);\n}\n\nstatic PyObject *\narray_inplace_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.divide);\n}\n\nstatic PyObject *\narray_inplace_remainder(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.remainder);\n}\n\nstatic PyObject *\narray_inplace_power(PyArrayObject *a1, PyObject *o2, PyObject *modulo)\n{\n /* modulo is ignored! */\n PyObject *value;\n value = fast_scalar_power(a1, o2, 1);\n if (!value) {\n value = PyArray_GenericInplaceBinaryFunction(a1, o2, n_ops.power);\n }\n return value;\n}\n\nstatic PyObject *\narray_inplace_left_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.left_shift);\n}\n\nstatic PyObject *\narray_inplace_right_shift(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.right_shift);\n}\n\nstatic PyObject *\narray_inplace_bitwise_and(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_and);\n}\n\nstatic PyObject *\narray_inplace_bitwise_or(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_or);\n}\n\nstatic PyObject *\narray_inplace_bitwise_xor(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.bitwise_xor);\n}\n\nstatic PyObject *\narray_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.true_divide);\n}\n\nstatic PyObject *\narray_inplace_floor_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.floor_divide);\n}\n\nstatic PyObject *\narray_inplace_true_divide(PyArrayObject *m1, PyObject *m2)\n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2,\n\t\t\t\t\t\t n_ops.true_divide);\n}\n\n/* Array evaluates as \"TRUE\" if any of the elements are non-zero*/\nstatic int\narray_any_nonzero(PyArrayObject *mp)\n{\n\tintp index;\n\tPyArrayIterObject *it;\n\tBool anyTRUE = FALSE;\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)mp);\n\tif (it==NULL) return anyTRUE;\n\tindex = it->size;\n\twhile(index--) {\n\t\tif (mp->descr->f->nonzero(it->dataptr, mp)) {\n\t\t\tanyTRUE = TRUE;\n\t\t\tbreak;\n\t\t}\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\treturn anyTRUE;\n}\n\nstatic int\n_array_nonzero(PyArrayObject *mp)\n{\n\tintp n;\n\tn = PyArray_SIZE(mp);\n\tif (n == 1) {\n\t\treturn mp->descr->f->nonzero(mp->data, mp);\n\t}\n\telse if (n == 0) {\n\t\treturn 0;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"The truth value of an array \" \\\n\t\t\t\t\"with more than one element is ambiguous. \" \\\n\t\t\t\t\"Use a.any() or a.all()\");\n\t\treturn -1;\n\t}\n}\n\n\n\nstatic PyObject *\narray_divmod(PyArrayObject *op1, PyObject *op2)\n{\n PyObject *divp, *modp, *result;\n\n divp = array_floor_divide(op1, op2);\n if (divp == NULL) return NULL;\n modp = array_remainder(op1, op2);\n if (modp == NULL) {\n Py_DECREF(divp);\n return NULL;\n }\n result = Py_BuildValue(\"OO\", divp, modp);\n Py_DECREF(divp);\n Py_DECREF(modp);\n return result;\n}\n\n\nstatic PyObject *\narray_int(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can be\"\\\n\t\t\t\t\" converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_int == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to int\");\n Py_DECREF(pv);\n return NULL;\n }\n\n pv2 = pv->ob_type->tp_as_number->nb_int(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_float(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv == NULL) return NULL;\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to a \"\\\n\t\t\t\t\"float; scalar object is not a number\");\n Py_DECREF(pv);\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_float == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to float\");\n Py_DECREF(pv);\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_float(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_long(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_long == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to long\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_long(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_oct == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to oct\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_oct(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\narray_hex(PyArrayObject *v)\n{\n PyObject *pv, *pv2;\n if (PyArray_SIZE(v) != 1) {\n PyErr_SetString(PyExc_TypeError, \"only length-1 arrays can \"\\\n\t\t\t\t\"be converted to Python scalars\");\n return NULL;\n }\n pv = v->descr->f->getitem(v->data, v);\n if (pv->ob_type->tp_as_number == 0) {\n PyErr_SetString(PyExc_TypeError, \"cannot convert to an int; \"\\\n\t\t\t\t\"scalar object is not a number\");\n return NULL;\n }\n if (pv->ob_type->tp_as_number->nb_hex == 0) {\n PyErr_SetString(PyExc_TypeError, \"don't know how to convert \"\\\n\t\t\t\t\"scalar number to hex\");\n return NULL;\n }\n pv2 = pv->ob_type->tp_as_number->nb_hex(pv);\n Py_DECREF(pv);\n return pv2;\n}\n\nstatic PyObject *\n_array_copy_nice(PyArrayObject *self)\n{\n\treturn PyArray_Return((PyArrayObject *)\t\t\\\n\t\t\t PyArray_Copy(self));\n}\n\nstatic PyNumberMethods array_as_number = {\n (binaryfunc)array_add,\t\t /*nb_add*/\n (binaryfunc)array_subtract,\t\t /*nb_subtract*/\n (binaryfunc)array_multiply,\t\t /*nb_multiply*/\n (binaryfunc)array_divide,\t\t /*nb_divide*/\n (binaryfunc)array_remainder,\t /*nb_remainder*/\n (binaryfunc)array_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)array_power,\t\t /*nb_power*/\n (unaryfunc)array_negative, /*nb_neg*/\n (unaryfunc)_array_copy_nice,\t\t /*nb_pos*/\n (unaryfunc)array_absolute,\t\t /*(unaryfunc)array_abs,*/\n (inquiry)_array_nonzero,\t\t /*nb_nonzero*/\n (unaryfunc)array_invert,\t\t /*nb_invert*/\n (binaryfunc)array_left_shift,\t /*nb_lshift*/\n (binaryfunc)array_right_shift,\t /*nb_rshift*/\n (binaryfunc)array_bitwise_and,\t /*nb_and*/\n (binaryfunc)array_bitwise_xor,\t /*nb_xor*/\n (binaryfunc)array_bitwise_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)array_int,\t\t /*nb_int*/\n (unaryfunc)array_long,\t\t /*nb_long*/\n (unaryfunc)array_float,\t\t /*nb_float*/\n (unaryfunc)array_oct,\t\t /*nb_oct*/\n (unaryfunc)array_hex,\t\t /*nb_hex*/\n\n /*This code adds augmented assignment functionality*/\n /*that was made available in Python 2.0*/\n (binaryfunc)array_inplace_add,\t /*inplace_add*/\n (binaryfunc)array_inplace_subtract,\t /*inplace_subtract*/\n (binaryfunc)array_inplace_multiply,\t /*inplace_multiply*/\n (binaryfunc)array_inplace_divide,\t /*inplace_divide*/\n (binaryfunc)array_inplace_remainder, /*inplace_remainder*/\n (ternaryfunc)array_inplace_power,\t /*inplace_power*/\n (binaryfunc)array_inplace_left_shift, /*inplace_lshift*/\n (binaryfunc)array_inplace_right_shift, /*inplace_rshift*/\n (binaryfunc)array_inplace_bitwise_and, /*inplace_and*/\n (binaryfunc)array_inplace_bitwise_xor, /*inplace_xor*/\n (binaryfunc)array_inplace_bitwise_or, /*inplace_or*/\n\n (binaryfunc)array_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)array_true_divide,\t /*nb_true_divide*/\n (binaryfunc)array_inplace_floor_divide, /*nb_inplace_floor_divide*/\n (binaryfunc)array_inplace_true_divide, /*nb_inplace_true_divide*/\n\n};\n\n/****************** End of Buffer Protocol *******************************/\n\n\n/*************************************************************************\n **************** Implement Sequence Protocol **************************\n *************************************************************************/\n\n/* Some of this is repeated in the array_as_mapping protocol. But\n we fill it in here so that PySequence_XXXX calls work as expected\n*/\n\n\nstatic PyObject *\narray_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t _int_or_ssize_t ihigh)\n{\n PyArrayObject *r;\n _int_or_ssize_t l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n\n l=self->dimensions[0];\n if (ihigh < 0) ihigh += l;\n if (ilow < 0) ilow += l;\n if (ilow < 0) ilow = 0;\n else if (ilow > l) ilow = l;\n if (ihigh < 0) ihigh = 0;\n else if (ihigh > l) ihigh = l;\n if (ihigh < ilow) ihigh = ilow;\n\n if (ihigh != ilow) {\n data = index2ptr(self, ilow);\n if (data == NULL) return NULL;\n } else {\n data = self->data;\n }\n\n self->dimensions[0] = ihigh-ilow;\n\tPy_INCREF(self->descr);\n r = (PyArrayObject *)\t\t\t\t\t\t\\\n\t\tPyArray_NewFromDescr(self->ob_type, self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides, data,\n\t\t\t\t self->flags, (PyObject *)self);\n self->dimensions[0] = l;\n\tif (r == NULL) return NULL;\n r->base = (PyObject *)self;\n Py_INCREF(self);\n\tPyArray_UpdateFlags(r, UPDATE_ALL_FLAGS);\n return (PyObject *)r;\n}\n\n\nstatic int\narray_ass_slice(PyArrayObject *self, _int_or_ssize_t ilow, \n\t\t_int_or_ssize_t ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\n if (v == NULL) {\n PyErr_SetString(PyExc_ValueError,\n \"cannot delete array elements\");\n return -1;\n }\n\tif (!PyArray_ISWRITEABLE(self)) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"array is not writeable\");\n\t\treturn -1;\n\t}\n if ((tmp = (PyArrayObject *)array_slice(self, ilow, ihigh)) \\\n == NULL)\n return -1;\n ret = PyArray_CopyObject(tmp, v);\n Py_DECREF(tmp);\n\n return ret;\n}\n\nstatic int\narray_contains(PyArrayObject *self, PyObject *el)\n{\n /* equivalent to (self == el).any() */\n\n PyObject *res;\n int ret;\n\t\n res = PyArray_EnsureAnyArray(PyObject_RichCompare((PyObject *)self, \n\t\t\t\t\t\t\t el, Py_EQ));\n if (res == NULL) return -1;\n ret = array_any_nonzero((PyArrayObject *)res);\n Py_DECREF(res);\n return ret;\n}\n\nstatic PySequenceMethods array_as_sequence = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (ssizeargfunc)NULL,\n\t(ssizeargfunc)array_item_nice,\n\t(ssizessizeargfunc)array_slice,\n (ssizeobjargproc)array_ass_item,\t /*sq_ass_item*/\n (ssizessizeobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(ssizeargfunc)NULL,\n#else\n (inquiry)array_length,\t\t/*sq_length*/\n (binaryfunc)NULL, /* sq_concat is handled by nb_add*/\n (intargfunc)NULL, /* sq_repeat is handled nb_multiply*/\n (intargfunc)array_item_nice,\t\t/*sq_item*/\n (intintargfunc)array_slice,\t\t/*sq_slice*/\n (intobjargproc)array_ass_item,\t /*sq_ass_item*/\n (intintobjargproc)array_ass_slice,\t/*sq_ass_slice*/\n\t(objobjproc) array_contains, /* sq_contains */\n\t(binaryfunc) NULL, /* sg_inplace_concat */\n\t(intargfunc) NULL /* sg_inplace_repeat */\n#endif\n};\n\n\n/****************** End of Sequence Protocol ****************************/\n\n\nstatic int\ndump_data(char **string, int *n, int *max_n, char *data, int nd,\n intp *dimensions, intp *strides, PyArrayObject* self)\n{\n PyArray_Descr *descr=self->descr;\n PyObject *op, *sp;\n char *ostring;\n int i, N;\n\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\n if (nd == 0) {\n\n if ((op = descr->f->getitem(data, self)) == NULL) return -1;\n sp = PyObject_Repr(op);\n if (sp == NULL) {Py_DECREF(op); return -1;}\n ostring = PyString_AsString(sp);\n N = PyString_Size(sp)*sizeof(char);\n *n += N;\n CHECK_MEMORY\n memmove(*string+(*n-N), ostring, N);\n Py_DECREF(sp);\n Py_DECREF(op);\n return 0;\n } else {\n CHECK_MEMORY\n (*string)[*n] = '[';\n *n += 1;\n for(i=0; idata,\n\t\t self->nd, self->dimensions,\n self->strides, self) < 0) {\n\t\t_pya_free(string); return NULL;\n\t}\n\n\tif (PyArray_ISEXTENDED(self)) {\n\t\tchar buf[100];\n\t\tsnprintf(buf, sizeof(buf), \"%d\", self->descr->elsize);\n\t\tsprintf(string+n, \", '%c%s')\", self->descr->type, buf);\n\t\tret = PyString_FromStringAndSize(string, n+6+strlen(buf));\n\t}\n\telse {\n\t\tsprintf(string+n, \", '%c')\", self->descr->type);\n\t\tret = PyString_FromStringAndSize(string, n+6);\n\t}\n\n\n _pya_free(string);\n return ret;\n}\n\nstatic PyObject *PyArray_StrFunction=NULL;\nstatic PyObject *PyArray_ReprFunction=NULL;\n\n/*OBJECT_API\n Set the array print function to be a Python function.\n*/\nstatic void\nPyArray_SetStringFunction(PyObject *op, int repr)\n{\n if (repr) {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_ReprFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_ReprFunction = op;\n } else {\n\t\t/* Dispose of previous callback */\n Py_XDECREF(PyArray_StrFunction);\n\t\t/* Add a reference to new callback */\n Py_XINCREF(op);\n\t\t/* Remember new callback */\n PyArray_StrFunction = op;\n }\n}\n\nstatic PyObject *\narray_repr(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_ReprFunction == NULL) {\n s = array_repr_builtin(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_ReprFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\nstatic PyObject *\narray_str(PyArrayObject *self)\n{\n PyObject *s, *arglist;\n\n if (PyArray_StrFunction == NULL) {\n s = array_repr(self);\n } else {\n arglist = Py_BuildValue(\"(O)\", self);\n s = PyEval_CallObject(PyArray_StrFunction, arglist);\n Py_DECREF(arglist);\n }\n return s;\n}\n\n\n\n/*OBJECT_API\n */\nstatic int\nPyArray_CompareUCS4(PyArray_UCS4 *s1, PyArray_UCS4 *s2, register size_t len)\n{\n register PyArray_UCS4 c1, c2;\n while(len-- > 0) {\n c1 = *s1++;\n c2 = *s2++;\n if (c1 != c2) {\n return (c1 < c2) ? -1 : 1;\n\t\t}\n }\n\treturn 0;\n}\n\nstatic int\n_myunincmp(PyArray_UCS4 *s1, PyArray_UCS4 *s2, int len1, int len2)\n{\n\tPyArray_UCS4 *sptr;\n\tint val;\n\n\tval = PyArray_CompareUCS4(s1, s2, MIN(len1, len2));\n\tif ((val != 0) || (len1 == len2)) return val;\n\tif (len2 > len1) {sptr = s2+len1; val = -1;}\n\telse {sptr = s1+len2; val = 1;}\n\tif (*sptr != 0) return val;\n\n\tif (len2 > len1) {sptr = s2; val = -1;}\n\telse {sptr = s1; val = 1;}\n\tif (*sptr != 0) return val;\n\treturn 0;\n}\n\n\n\n/* Compare s1 and s2 which are not necessarily NULL-terminated. \n s1 is of length len1\n s2 is of length len2\n If they are NULL terminated, then stop comparison.\n*/\nstatic int\n_mystrncmp(char *s1, char *s2, int len1, int len2)\n{\n\tchar *sptr;\n\tint val;\n\n\tval = strncmp(s1, s2, MIN(len1, len2));\n\tif ((val != 0) || (len1 == len2)) return val;\n\tif (len2 > len1) {sptr = s2+len1; val = -1;}\n\telse {sptr = s1+len2; val = 1;}\n\tif (*sptr != 0) return val;\n\treturn 0;\n}\n\nstatic int\n_compare_strings(PyObject *result, PyArrayMultiIterObject *multi, \n\t\t int cmp_op, void *func)\n{\n\tPyArrayIterObject *iself, *iother;\n\tBool *dptr;\n\tintp size;\n\tint val;\n\tint N1, N2;\n\tint (*cmpfunc)(void *, void *, int, int);\n\t\n\tcmpfunc = func;\n\tdptr = (Bool *)PyArray_DATA(result);\n\tiself = multi->iters[0];\n\tiother = multi->iters[1];\n\tsize = multi->size;\n\tN1 = iself->ao->descr->elsize;\n\tN2 = iother->ao->descr->elsize;\n\tif ((void *)cmpfunc == (void *)_myunincmp) {\n\t\tN1 >>= 2;\n\t\tN2 >>= 2;\n\t}\n\twhile(size--) {\n\t\tval = cmpfunc((void *)iself->dataptr, (void *)iother->dataptr, \n\t\t\t N1, N2);\n\t\tswitch (cmp_op) {\n\t\tcase Py_EQ:\n\t\t\t*dptr = (val == 0);\n\t\t\tbreak;\n\t\tcase Py_NE:\n\t\t\t*dptr = (val != 0);\n\t\t\tbreak;\n\t\tcase Py_LT:\n\t\t\t*dptr = (val < 0);\n\t\t\tbreak;\n\t\tcase Py_LE:\n\t\t\t*dptr = (val <= 0);\n\t\t\tbreak;\n\t\tcase Py_GT:\n\t\t\t*dptr = (val > 0);\n\t\t\tbreak;\n\t\tcase Py_GE:\n\t\t\t*dptr = (val >= 0);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\t\"bad comparison operator\");\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_NEXT(iself);\n\t\tPyArray_ITER_NEXT(iother);\n\t\tdptr += 1;\n\t}\n\treturn 0;\t\n}\n\nstatic PyObject *\n_strings_richcompare(PyArrayObject *self, PyArrayObject *other, int cmp_op)\n{\n PyObject *result;\n\tPyArrayMultiIterObject *mit;\n\tint val;\n\n /* Cast arrays to a common type */ \n if (self->descr->type != other->descr->type) {\n PyObject *new;\n if (self->descr->type_num == PyArray_STRING && \\\n other->descr->type_num == PyArray_UNICODE) {\n Py_INCREF(other);\n Py_INCREF(other->descr);\n new = PyArray_FromAny((PyObject *)self, other->descr, \n\t\t\t\t\t 0, 0, 0, NULL);\n if (new == NULL) return NULL;\n self = (PyArrayObject *)new;\n }\n else if (self->descr->type_num == PyArray_UNICODE &&\t\\\n other->descr->type_num == PyArray_STRING) {\n Py_INCREF(self);\n Py_INCREF(self->descr);\n new = PyArray_FromAny((PyObject *)other, self->descr, \n\t\t\t\t\t 0, 0, 0, NULL);\n if (new == NULL) return NULL;\n other = (PyArrayObject *)new;\n }\n else {\n PyErr_SetString(PyExc_TypeError, \n \"invalid string data-types \"\n \"in comparison\");\n return NULL;\n }\n }\n else { \n Py_INCREF(self);\n Py_INCREF(other);\n }\n\n /* Broad-cast the arrays to a common shape */\n mit = (PyArrayMultiIterObject *)PyArray_MultiIterNew(2, self, other);\n\tPy_DECREF(self);\n\tPy_DECREF(other);\n if (mit == NULL) return NULL;\n\t\n\tresult = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t PyArray_DescrFromType(PyArray_BOOL),\n\t\t\t\t mit->nd,\n\t\t\t\t mit->dimensions,\n\t\t\t\t NULL, NULL, 0, \n\t\t\t\t NULL);\n\tif (result == NULL) goto finish;\n\n\tif (self->descr->type_num == PyArray_STRING) {\n\t\tval = _compare_strings(result, mit, cmp_op, _mystrncmp);\n\t}\n\telse {\n\t\tval = _compare_strings(result, mit, cmp_op, _myunincmp);\n\t}\n\t\n\tif (val < 0) {Py_DECREF(result); result = NULL;}\n\t\n finish: \n\tPy_DECREF(mit);\n return result;\n}\n\n/* What do we do about VOID type arrays?\n */\n\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op)\n{\n PyObject *array_other, *result = NULL;\n\tint typenum;\n\n switch (cmp_op)\n {\n case Py_LT:\n result = PyArray_GenericBinaryFunction(self, other,\n n_ops.less);\n break;\n case Py_LE:\n result = PyArray_GenericBinaryFunction(self, other,\n n_ops.less_equal);\n break;\n case Py_EQ:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\treturn Py_False;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then return False\n\t\t\t\t This fixes code that used to\n\t\t\t\t allow equality comparisons between arrays\n\t\t\t\t and other objects which would give a result\n\t\t\t\t of False\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_False);\n\t\t\t\t\treturn Py_False;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n result = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.equal);\n /* If the comparison results in NULL, then the\n\t\t\t two array objects can not be compared together so\n\t\t\t return zero\n */\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\n break;\n case Py_NE:\n\t\t\tif (other == Py_None) {\n\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\treturn Py_True;\n\t\t\t}\n /* Try to convert other to an array */\n\t\t\tif (!PyArray_Check(other)) {\n\t\t\t\ttypenum = self->descr->type_num;\n\t\t\t\tif (typenum != PyArray_OBJECT) {\n\t\t\t\t\ttypenum = PyArray_NOTYPE;\n\t\t\t\t}\n\t\t\t\tarray_other = PyArray_FromObject(other,\n typenum, 0, 0);\n\t\t\t\t/* If not successful, then objects cannot be\n\t\t\t\t compared and cannot be equal, therefore,\n\t\t\t\t return True;\n\t\t\t\t*/\n\t\t\t\tif ((array_other == NULL) ||\t\\\n\t\t\t\t (array_other == Py_None)) {\n\t\t\t\t\tPy_XDECREF(array_other);\n\t\t\t\t\tPyErr_Clear();\n\t\t\t\t\tPy_INCREF(Py_True);\n\t\t\t\t\treturn Py_True;\n\t\t\t\t}\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPy_INCREF(other);\n\t\t\t\tarray_other = other;\n\t\t\t}\n\t\t\tresult = PyArray_GenericBinaryFunction(self,\n\t\t\t\t\t\t\t array_other,\n\t\t\t\t\t\t\t n_ops.not_equal);\n\t\t\tPy_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n break;\n case Py_GT:\n result = PyArray_GenericBinaryFunction(self, other,\n n_ops.greater);\n break;\n case Py_GE:\n result = PyArray_GenericBinaryFunction(self, other,\n n_ops.greater_equal);\n break;\n default:\n result = Py_NotImplemented;\n Py_INCREF(result);\n }\n if (result == Py_NotImplemented) {\n /* Try to handle string comparisons */\n if (self->descr->type_num == PyArray_OBJECT) return result;\n array_other = PyArray_FromObject(other,PyArray_NOTYPE, 0, 0);\n if (PyArray_ISSTRING(self) && PyArray_ISSTRING(array_other)) {\n result = _strings_richcompare(self, (PyArrayObject *)\n\t\t\t\t\t\t array_other, cmp_op);\n }\n Py_DECREF(array_other);\n }\n return result;\n}\n\nstatic PyObject *\n_check_axis(PyArrayObject *arr, int *axis, int flags)\n{\n\tPyObject *temp;\n\tint n = arr->nd;\n\n\tif ((*axis >= MAX_DIMS) || (n==0)) {\n\t\ttemp = PyArray_Ravel(arr,0);\n\t\tif (temp) *axis = PyArray_NDIM(temp)-1;\n\t\telse *axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_CheckFromAny((PyObject *)arr, NULL,\n 0, 0, flags, NULL);\n\t\t\tif (temp == NULL) return NULL;\n\t\t}\n\t\telse {\n\t\t\tPy_INCREF(arr);\n\t\t\ttemp = (PyObject *)arr;\n\t\t}\n\t}\n\tif (*axis < 0) *axis += n;\n\tif ((*axis < 0) || (*axis >= n)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"axis(=%d) out of bounds\", *axis);\n\t\tPy_DECREF(temp);\n\t\treturn NULL;\n\t}\n\treturn temp;\n}\n\n#include \"arraymethods.c\"\n\n/* Lifted from numarray */\nstatic PyObject *\nPyArray_IntTupleFromIntp(int len, intp *vals)\n{\n\tint i;\n PyObject *intTuple = PyTuple_New(len);\n if (!intTuple) goto fail;\n for(i=0; i= SIZEOF_INTP\n\t\tif (!(op = PyNumber_Int(seq))) return -1;\n#else\n\t\tif (!(op = PyNumber_Long(seq))) return -1;\n#endif\n\t\tnd = 1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\tvals[0] = (intp ) PyInt_AsLong(op);\n#else\n\t\tvals[0] = (intp ) PyLong_AsLongLong(op);\n#endif\n\t\tPy_DECREF(op);\n\t} else {\n\t\tfor(i=0; i < MIN(nd,maxvals); i++) {\n\t\t\top = PySequence_GetItem(seq, i);\n\t\t\tif (op == NULL) return -1;\n#if SIZEOF_LONG >= SIZEOF_INTP\n\t\t\tvals[i]=(intp )PyInt_AsLong(op);\n#else\n\t\t\tvals[i]=(intp )PyLong_AsLongLong(op);\n#endif\n\t\t\tPy_DECREF(op);\n\t\t\tif(PyErr_Occurred()) return -1;\n\t\t}\n\t}\n\treturn nd;\n}\n\n\n/* Check whether the given array is stored contiguously (row-wise) in\n memory. */\nstatic int\n_IsContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\n\nstatic int\n_IsFortranContiguous(PyArrayObject *ap)\n{\n\tregister intp sd;\n\tregister intp dim;\n\tregister int i;\n\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return (ap->dimensions[0] == 1 || \\\n\t\t\t\t sd == ap->strides[0]);\n\tfor (i=0; i< ap->nd; ++i) {\n\t\tdim = ap->dimensions[i];\n\t\t/* contiguous by definition */\n\t\tif (dim == 0) return 1;\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= dim;\n\t}\n\treturn 1;\n}\n\nstatic int\n_IsAligned(PyArrayObject *ap)\n{\n\tint i, alignment, aligned=1;\n\tintp ptr;\n\tint type = ap->descr->type_num;\n\n\tif ((type == PyArray_STRING) || (type == PyArray_VOID))\n\t\treturn 1;\n\n\talignment = ap->descr->alignment;\n\tif (alignment == 1) return 1;\n\n\tptr = (intp) ap->data;\n aligned = (ptr % alignment) == 0;\n for (i=0; i nd; i++)\n aligned &= ((ap->strides[i] % alignment) == 0);\n return aligned != 0;\n}\n\nstatic Bool\n_IsWriteable(PyArrayObject *ap)\n{\n\tPyObject *base=ap->base;\n\tvoid *dummy;\n\tint n;\n\n\t/* If we own our own data, then no-problem */\n\tif ((base == NULL) || (ap->flags & OWN_DATA)) return TRUE;\n\n\t/* Get to the final base object\n\t If it is a writeable array, then return TRUE\n\t If we can find an array object\n\t or a writeable buffer object as the final base object\n\t or a string object (for pickling support memory savings).\n\t - this last could be removed if a proper pickleable\n\t buffer was added to Python.\n\t*/\n\n\twhile(PyArray_Check(base)) {\n\t\tif (PyArray_CHKFLAGS(base, OWN_DATA))\n\t\t\treturn (Bool) (PyArray_ISWRITEABLE(base));\n\t\tbase = PyArray_BASE(base);\n\t}\n\n\t/* here so pickle support works seamlessly\n\t and unpickled array can be set and reset writeable\n\t -- could be abused -- */\n\tif PyString_Check(base) return TRUE;\n\n\tif (PyObject_AsWriteBuffer(base, &dummy, &n) < 0)\n\t\treturn FALSE;\n\n\treturn TRUE;\n}\n\n\n/*OBJECT_API\n Update Several Flags at once.\n*/\nstatic void\nPyArray_UpdateFlags(PyArrayObject *ret, int flagmask)\n{\n\n\tif (flagmask & FORTRAN) {\n\t\tif (_IsFortranContiguous(ret)) {\n\t\t\tret->flags |= FORTRAN;\n\t\t\tif (ret->nd > 1) ret->flags &= ~CONTIGUOUS;\n\t\t}\n\t\telse ret->flags &= ~FORTRAN;\n\t}\n\tif (flagmask & CONTIGUOUS) {\n\t\tif (_IsContiguous(ret)) {\n\t\t\tret->flags |= CONTIGUOUS;\n\t\t\tif (ret->nd > 1) ret->flags &= ~FORTRAN;\n\t\t}\n\t\telse ret->flags &= ~CONTIGUOUS;\n\t}\n\tif (flagmask & ALIGNED) {\n\t\tif (_IsAligned(ret)) ret->flags |= ALIGNED;\n\t\telse ret->flags &= ~ALIGNED;\n\t}\n\t/* This is not checked by default WRITEABLE is not part of UPDATE_ALL_FLAGS */\n\tif (flagmask & WRITEABLE) {\n\t if (_IsWriteable(ret)) ret->flags |= WRITEABLE;\n\t\telse ret->flags &= ~WRITEABLE;\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not\n ever be able to walk outside of the memory implied numbytes and offset.\n\n The available memory is assumed to start at -offset and proceed\n to numbytes-offset. The strides are checked to ensure\n that accessing memory using striding will not try to reach beyond\n this memory for any of the axes.\n\n If numbytes is 0 it will be calculated using the dimensions and\n element-size.\n\n This function checks for walking beyond the beginning and right-end\n of the buffer and therefore works for any integer stride (positive\n or negative).\n*/\n\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, intp offset,\n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\tintp byte_begin;\n\tintp begin;\n\tintp end;\n\n\tif (numbytes == 0)\n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\n\tbegin = -offset;\n\tend = numbytes - offset - elsize;\n\tfor (i=0; i end))\n\t\t\treturn FALSE;\n\t}\n\treturn TRUE;\n\n}\n\n\n/* This is the main array creation routine. */\n\n/* Flags argument has multiple related meanings\n depending on data and strides:\n\n If data is given, then flags is flags associated with data.\n If strides is not given, then a contiguous strides array will be created\n and the CONTIGUOUS bit will be set. If the flags argument\n has the FORTRAN bit set, then a FORTRAN-style strides array will be\n created (and of course the FORTRAN flag bit will be set).\n\n If data is not given but created here, then flags will be DEFAULT_FLAGS\n and a non-zero flags argument can be used to indicate a FORTRAN style\n array is desired.\n*/\n\nstatic intp\n_array_fill_strides(intp *strides, intp *dims, int nd, intp itemsize,\n\t\t int inflag, int *objflags)\n{\n\tint i;\n\t/* Only make Fortran strides if not contiguous as well */\n\tif ((inflag & FORTRAN) && !(inflag & CONTIGUOUS)) {\n\t\tfor (i=0; i 1) *objflags &= ~CONTIGUOUS;\n\t\telse *objflags |= CONTIGUOUS;\n\t}\n\telse {\n\t\tfor (i=nd-1;i>=0;i--) {\n\t\t\tstrides[i] = itemsize;\n\t\t\titemsize *= dims[i] ? dims[i] : 1;\n\t\t}\n\t\t*objflags |= CONTIGUOUS;\n\t\tif (nd > 1) *objflags &= ~FORTRAN;\n\t\telse *objflags |= FORTRAN;\n\t}\n\treturn itemsize;\n}\n\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_New(PyTypeObject *subtype, int nd, intp *dims, int type_num,\n intp *strides, void *data, int itemsize, int flags,\n\t PyObject *obj)\n{\n\tPyArray_Descr *descr;\n\tPyObject *new;\n\n\tdescr = PyArray_DescrFromType(type_num);\n\tif (descr == NULL) return NULL;\n\tif (descr->elsize == 0) {\n\t\tif (itemsize < 1) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data type must provide an itemsize\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(descr);\n\t\tdescr->elsize = itemsize;\n\t}\n\tnew = PyArray_NewFromDescr(subtype, descr, nd, dims, strides,\n\t\t\t\t data, flags, obj);\n\treturn new;\n}\n\n/* Change a sub-array field to the base descriptor */\n/* and update the dimensions and strides\n appropriately. Dimensions and strides are added\n to the end unless we have a FORTRAN array\n and then they are added to the beginning\n\n Strides are only added if given (because data is given).\n*/\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims,\n\t\t\t intp *newstrides, int oldnd, int isfortran)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\tint tuple;\n\n\told = *des;\n\t*des = old->subarray->base;\n\n\n\tmydim = newdims + oldnd;\n\ttuple = PyTuple_Check(old->subarray->shape);\n\tif (tuple) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t}\n\telse {\n\t\tnumnew = 1;\n\t}\n\n\n\tnewnd = oldnd + numnew;\n\tif (newnd > MAX_DIMS) goto finish;\n\tif (isfortran) {\n\t\tmemmove(newdims+numnew, newdims, oldnd*sizeof(intp));\n\t\tmydim = newdims;\n\t}\n\n\tif (tuple) {\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\tif (isfortran) {\n\t\t\tmemmove(newstrides+numnew, newstrides,\n\t\t\t\toldnd*sizeof(intp));\n\t\t\tmystrides = newstrides;\n\t\t}\n\t\t/* Make new strides -- alwasy C-contiguous */\n\t\ttempsize = (*des)->elsize;\n\t\tfor (i=numnew-1; i>=0; i--) {\n\t\t\tmystrides[i] = tempsize;\n\t\t\ttempsize *= mydim[i] ? mydim[i] : 1;\n\t\t}\n\t}\n\n finish:\n\tPy_INCREF(*des);\n\tPy_DECREF(old);\n\treturn newnd;\n}\n\n\n/* steals a reference to descr (even on failure) */\n/*OBJECT_API\n Generic new array creation routine.\n*/\nstatic PyObject *\nPyArray_NewFromDescr(PyTypeObject *subtype, PyArray_Descr *descr, int nd,\n\t\t intp *dims, intp *strides, void *data,\n\t\t int flags, PyObject *obj)\n{\n\tPyArrayObject *self;\n\tregister int i;\n\tintp sd;\n\n\tif (descr->subarray) {\n\t\tPyObject *ret;\n\t\tintp newdims[2*MAX_DIMS];\n\t\tintp *newstrides=NULL;\n\t\tint isfortran=0;\n\t\tisfortran = (data && (flags & FORTRAN) && !(flags & CONTIGUOUS)) || \\\n\t\t\t(!data && flags);\n\t\tmemcpy(newdims, dims, nd*sizeof(intp));\n\t\tif (strides) {\n\t\t\tnewstrides = newdims + MAX_DIMS;\n\t\t\tmemcpy(newstrides, strides, nd*sizeof(intp));\n\t\t}\n\t\tnd =_update_descr_and_dimensions(&descr, newdims,\n\t\t\t\t\t\t newstrides, nd, isfortran);\n\t\tret = PyArray_NewFromDescr(subtype, descr, nd, newdims,\n\t\t\t\t\t newstrides,\n\t\t\t\t\t data, flags, obj);\n\t\treturn ret;\n\t}\n\n\tif (nd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"number of dimensions must be >=0\");\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n if (nd > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError,\n \"maximum number of dimensions is %d\", MAX_DIMS);\n\t\tPy_DECREF(descr);\n return NULL;\n\t}\n\n\t/* Check dimensions */\n\tfor (i=nd-1;i>=0;i--) {\n\t\tif (dims[i] < 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"negative dimensions \"\t\\\n\t\t\t\t\t\"are not allowed\");\n\t\t\tPy_DECREF(descr);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { \n\t\tself->flags = DEFAULT_FLAGS;\n\t\tif (flags) {\n\t\t\tself->flags |= FORTRAN;\n\t\t\tif (nd > 1) self->flags &= ~CONTIGUOUS;\n\t\t\tflags = FORTRAN;\n\t\t}\n\t}\n\telse self->flags = (flags & ~UPDATEIFCOPY);\n\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\n\tif (nd > 0) {\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, dims, sizeof(intp)*nd);\n\t\tif (strides == NULL) { /* fill it in */\n\t\t\tsd = _array_fill_strides(self->strides, dims, nd, sd,\n\t\t\t\t\t\t flags, &(self->flags));\n\t\t}\n\t\telse { /* we allow strides even when we create\n\t\t\t the memory, but be careful with this...\n\t\t */\n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t}\n\telse { self->dimensions = self->strides = NULL; }\n\n\tif (data == NULL) {\n\n\t\t/* Allocate something even for zero-space arrays\n\t\t e.g. shape=(0,) -- otherwise buffer exposure\n\t\t (a.data) doesn't work as it should. */\n\n\t\tif (sd==0) sd = descr->elsize;\n\n\t\tif ((data = PyDataMem_NEW(sd))==NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\tgoto fail;\n\t\t}\n\t\tself->flags |= OWN_DATA;\n\n\t\t/* It is bad to have unitialized OBJECT pointers */\n /* which could also be sub-fields of a VOID array */\n\t\tif (descr->hasobject) {\n if (descr != &OBJECT_Descr) {\n PyErr_SetString(PyExc_TypeError,\n \"fields with object members \" \\\n \"not yet supported.\");\n goto fail;\n }\n\t\t\tmemset(data, 0, sd);\n\t\t}\n\t}\n\telse {\n self->flags &= ~OWN_DATA; /* If data is passed in,\n\t\t\t\t\t this object won't own it\n\t\t\t\t\t by default.\n\t\t\t\t\t Caller must arrange for\n\t\t\t\t\t this to be reset if truly\n\t\t\t\t\t desired */\n }\n self->data = data;\n\n /* call the __array_finalize__\n\t method if a subtype.\n\t If obj is NULL, then call method with Py_None \n\t*/\n\tif ((subtype != &PyArray_Type)) {\n\t\tPyObject *res, *func, *args;\n\t\tstatic PyObject *str=NULL;\n\n\t\tif (str == NULL) {\n\t\t\tstr = PyString_InternFromString(\"__array_finalize__\");\n\t\t}\n\t\tif (strides != NULL) { /* did not allocate own data \n\t\t\t\t\t or funny strides */\n\t\t\t/* update flags before calling back into\n\t\t\t Python */\n\t\t\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\t}\n\t\tfunc = PyObject_GetAttr((PyObject *)self, str);\n\t\tif (func) {\n\t\t\targs = PyTuple_New(1);\n\t\t\tif (obj == NULL) obj=Py_None;\n\t\t\tPy_INCREF(obj);\n\t\t\tPyTuple_SET_ITEM(args, 0, obj);\n\t\t\tres = PyObject_Call(func, args, NULL);\n\t\t\tPy_DECREF(args);\n\t\t\tPy_DECREF(func);\n\t\t\tif (res == NULL) goto fail;\n\t\t\telse Py_DECREF(res);\n\t\t}\n\t}\n\n\treturn (PyObject *)self;\n\n fail:\n\tPy_DECREF(self);\n\treturn NULL;\n}\n\n\n\n/*OBJECT_API\n Resize (reallocate data). Only works if nothing else is referencing\n this array and it is contiguous.\n If refcheck is 0, then the reference count is not checked\n and assumed to be 1.\n You still must own this data and have no weak-references and no base\n object.\n*/\nstatic PyObject *\nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape, int refcheck,\n\t PyArray_ORDER fortran)\n{\n intp oldsize, newsize;\n int new_nd=newshape->len, k, n, elsize;\n int refcnt;\n intp* new_dimensions=newshape->ptr;\n intp new_strides[MAX_DIMS];\n intp sd;\n intp *dimptr;\n char *new_data;\n\n if (!PyArray_ISONESEGMENT(self)) {\n PyErr_SetString(PyExc_ValueError,\n \"resize only works on single-segment arrays\");\n return NULL;\n }\n\n\tif (fortran == PyArray_ANYORDER)\n\t\tfortran = PyArray_CORDER;\n \n newsize = PyArray_MultiplyList(new_dimensions, new_nd);\n oldsize = PyArray_SIZE(self);\n\n\tif (oldsize != newsize) {\n\t\tif (!(self->flags & OWN_DATA)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize this array: \"\t\\\n\t\t\t\t\t\"it does not own its data\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (refcheck) refcnt = REFCOUNT(self);\n\t\telse refcnt = 1;\n\t\tif ((refcnt > 2) || (self->base != NULL) || \\\n\t\t (self->weakreflist != NULL)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"cannot resize an array that has \"\\\n\t\t\t\t\t\"been referenced or is referencing\\n\"\\\n\t\t\t\t\t\"another array in this way. Use the \"\\\n\t\t\t\t\t\"resize function\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (newsize == 0) sd = self->descr->elsize;\n\t\telse sd = newsize * self->descr->elsize;\n\t\t/* Reallocate space if needed */\n\t\tnew_data = PyDataMem_RENEW(self->data, sd);\n\t\tif (new_data == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n\t\t\t\t\t\"cannot allocate memory for array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tself->data = new_data;\n\t}\n\n if ((newsize > oldsize) && PyArray_ISWRITEABLE(self)) {\n\t\t/* Fill new memory with zeros */\n elsize = self->descr->elsize;\n\t\tif ((PyArray_TYPE(self) == PyArray_OBJECT)) {\n\t\t\tPyObject *zero = PyInt_FromLong(0);\n PyObject **optr;\n\t\t\toptr = ((PyObject **)self->data) + oldsize;\n\t\t\tn = newsize - oldsize;\n\t\t\tfor (k=0; kdata+oldsize*elsize, 0,\n\t\t\t (newsize-oldsize)*elsize);\n\t\t}\n\t}\n\n if (self->nd != new_nd) { /* Different number of dimensions. */\n self->nd = new_nd;\n\n /* Need new dimensions and strides arrays */\n dimptr = PyDimMem_RENEW(self->dimensions, 2*new_nd);\n if (dimptr == NULL) {\n\t\t\tPyErr_SetString(PyExc_MemoryError,\n \"cannot allocate memory for array \" \\\n \"(array may be corrupted)\");\n return NULL;\n }\n self->dimensions = dimptr;\n\t\tself->strides = dimptr + new_nd;\n }\n\n /* make new_strides variable */\n sd = (intp) self->descr->elsize;\n sd = _array_fill_strides(new_strides, new_dimensions, new_nd, sd,\n self->flags, &(self->flags));\n\n\n memmove(self->dimensions, new_dimensions, new_nd*sizeof(intp));\n memmove(self->strides, new_strides, new_nd*sizeof(intp));\n\n Py_INCREF(Py_None);\n return Py_None;\n\n}\n\n\n/* Assumes contiguous */\n/*OBJECT_API*/\nstatic void\nPyArray_FillObjectArray(PyArrayObject *arr, PyObject *obj)\n{\n PyObject **optr;\n intp i,n;\n optr = (PyObject **)(arr->data);\n n = PyArray_SIZE(arr);\n if (obj == NULL) {\n for (i=0; ielsize;\n\tPy_INCREF(descr);\n\tnewarr = PyArray_FromAny(obj, descr, 0,0, ALIGNED, NULL);\n\tif (newarr == NULL) return -1;\n\tfromptr = PyArray_DATA(newarr);\n\tsize=PyArray_SIZE(arr);\n\tswap=!PyArray_ISNOTSWAPPED(arr);\n\tcopyswap = arr->descr->f->copyswap;\n\tif (PyArray_ISONESEGMENT(arr)) {\n\t\tchar *toptr=PyArray_DATA(arr);\n\t\tPyArray_FillWithScalarFunc* fillwithscalar =\n\t\t\tarr->descr->f->fillwithscalar;\n\t\tif (fillwithscalar && PyArray_ISALIGNED(arr)) {\n\t\t\tcopyswap(fromptr, NULL, swap, arr);\n\t\t\tfillwithscalar(toptr, size, fromptr, arr);\n\t\t}\n\t\telse {\n\t\t\twhile (size--) {\n\t\t\t\tcopyswap(toptr, fromptr, swap, arr);\n\t\t\t\ttoptr += itemsize;\n\t\t\t}\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\n\t\titer = (PyArrayIterObject *)\\\n\t\t\tPyArray_IterNew((PyObject *)arr);\n\t\tif (iter == NULL) {\n\t\t\tPy_DECREF(newarr);\n\t\t\treturn -1;\n\t\t}\n\t\twhile(size--) {\n\t\t\tcopyswap(iter->dataptr, fromptr, swap, arr);\n\t\t\tPyArray_ITER_NEXT(iter);\n\t\t}\n\t\tPy_DECREF(iter);\n\t}\n\tPy_DECREF(newarr);\n\treturn 0;\n}\n\nstatic PyObject *\narray_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tstatic char *kwlist[] = {\"shape\", \"dtype\", \"buffer\", /* XXX ? */\n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"order\", NULL};\n\tPyArray_Descr *descr=NULL;\n\tint type_num;\n\tint itemsize;\n PyArray_Dims dims = {NULL, 0};\n PyArray_Dims strides = {NULL, 0};\n PyArray_Chunk buffer;\n\tlonglong offset=0;\n PyArray_ORDER order=PyArray_CORDER;\n\tint fortran = 0;\n\tPyArrayObject *ret;\n\n\tbuffer.ptr = NULL;\n /* Usually called with shape and type\n but can also be called with buffer, strides, and swapped info\n */\n\n\t/* For now, let's just use this to create an empty, contiguous\n\t array of a specific type and shape.\n\t*/\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &dims,\n PyArray_DescrConverter,\n\t\t\t\t\t &descr,\n PyArray_BufferConverter,\n &buffer,\n\t\t\t\t\t &offset,\n &PyArray_IntpConverter,\n &strides,\n &PyArray_OrderConverter,\n &order))\n\t\tgoto fail;\n\n if (order == PyArray_FORTRANORDER) fortran = 1;\n\n\tif (descr == NULL)\n\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\n\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"data-type with unspecified variable length\");\n\t\tgoto fail;\n\t}\n\t\n\tif (strides.ptr != NULL) {\n\t\tintp nb, off;\n\t\tif (strides.len != dims.len) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides, if given, must be \"\t\\\n\t\t\t\t\t\"the same length as shape\");\n\t\t\tgoto fail;\n\t\t}\n\n\t\tif (buffer.ptr == NULL) {\n\t\t\tnb = 0;\n\t\t\toff = 0;\n\t\t}\n\t\telse {\n\t\t\tnb = buffer.len;\n\t\t\toff = offset;\n\t\t}\n\t\t\n\n\t\tif (!PyArray_CheckStrides(itemsize, dims.len, \n\t\t\t\t\t nb, off,\n\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"strides is incompatible \"\t\\\n\t\t\t\t\t\"with shape of requested \"\t\\\n\t\t\t\t\t\"array and size of buffer\");\n\t\t\tgoto fail;\n\t\t}\n\t}\n\t\t\t\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t (int)dims.len,\n\t\t\t\t\t dims.ptr,\n\t\t\t\t\t strides.ptr, NULL, fortran, NULL);\n if (ret == NULL) {descr=NULL;goto fail;}\n if (type_num == PyArray_OBJECT) { /* place Py_None */\n PyArray_FillObjectArray(ret, Py_None);\n }\n }\n else { /* buffer given -- use it */\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = (buffer.len-offset) / itemsize;\n }\n else if ((strides.ptr == NULL) && \\\n\t\t\t buffer.len < itemsize*\t\t\t\t\\\n PyArray_MultiplyList(dims.ptr, dims.len)) {\n PyErr_SetString(PyExc_TypeError,\n \"buffer is too small for \" \\\n \"requested array\");\n goto fail;\n }\n if (type_num == PyArray_OBJECT) {\n PyErr_SetString(PyExc_TypeError, \"cannot construct \"\\\n \"an object array from buffer data\");\n goto fail;\n }\n /* get writeable and aligned */\n if (fortran) buffer.flags |= FORTRAN;\n ret = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(subtype, descr,\n\t\t\t\t\t dims.len, dims.ptr,\n\t\t\t\t\t strides.ptr,\n\t\t\t\t\t offset + (char *)buffer.ptr,\n\t\t\t\t\t buffer.flags, NULL);\n if (ret == NULL) {descr=NULL; goto fail;}\n PyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n ret->base = buffer.base;\n Py_INCREF(buffer.base);\n }\n\n PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(descr);\n if (dims.ptr) PyDimMem_FREE(dims.ptr);\n if (strides.ptr) PyDimMem_FREE(strides.ptr);\n return NULL;\n}\n\n\nstatic PyObject *\narray_iter(PyArrayObject *arr)\n{\n\tif (arr->nd == 0) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"iteration over a scalar (0-dim array)\");\n\t\treturn NULL;\n\t}\n\treturn PySeqIter_New((PyObject *)arr);\n}\n\n\n/******************* array attribute get and set routines ******************/\n\nstatic PyObject *\narray_ndim_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong(self->nd);\n}\n\nstatic PyObject *\narray_flags_get(PyArrayObject *self)\n{\n return PyArray_NewFlagsObject((PyObject *)self);\n}\n\nstatic PyObject *\narray_shape_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\n\nstatic int\narray_shape_set(PyArrayObject *self, PyObject *val)\n{\n\tint nd;\n\tPyObject *ret;\n\n /* Assumes C-order */\n\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\n if (PyArray_DATA(ret) != PyArray_DATA(self)) {\n Py_DECREF(ret);\n PyErr_SetString(PyExc_AttributeError, \n \"incompatible shape for a non-contiguous array\");\n return -1;\n }\n\n\t/* Free old dimensions and strides */\n\tPyDimMem_FREE(self->dimensions);\n\tnd = PyArray_NDIM(ret);\n\tself->nd = nd;\n\tif (nd > 0) { /* create new dimensions and strides */\n\t\tself->dimensions = PyDimMem_NEW(2*nd);\n\t\tif (self->dimensions == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\tPyErr_SetString(PyExc_MemoryError,\"\");\n\t\t\treturn -1;\n\t\t}\n\t\tself->strides = self->dimensions + nd;\n\t\tmemcpy(self->dimensions, PyArray_DIMS(ret),\n\t\t nd*sizeof(intp));\n\t\tmemcpy(self->strides, PyArray_STRIDES(ret),\n\t\t nd*sizeof(intp));\n\t}\n\telse {self->dimensions=NULL; self->strides=NULL;}\n\tPy_DECREF(ret);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_strides_get(PyArrayObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic int\narray_strides_set(PyArrayObject *self, PyObject *obj)\n{\n\tPyArray_Dims newstrides = {NULL, 0};\n\tPyArrayObject *new;\n\tintp numbytes=0;\n\tintp offset=0;\n\tint buf_len;\n\tchar *buf;\n\n\tif (!PyArray_IntpConverter(obj, &newstrides) || \\\n\t newstrides.ptr == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"invalid strides\");\n\t\treturn -1;\n\t}\n\tif (newstrides.len != self->nd) {\n\t\tPyErr_Format(PyExc_ValueError, \"strides must be \"\t\\\n\t\t\t \" same length as shape (%d)\", self->nd);\n\t\tgoto fail;\n\t}\n\tnew = self;\n\twhile(new->base && PyArray_Check(new->base)) {\n\t\tnew = (PyArrayObject *)(new->base);\n\t}\n\t/* Get the available memory through the buffer\n\t interface on new->base or if that fails\n\t from the current new */\n\tif (new->base && PyObject_AsReadBuffer(new->base,\n\t\t\t\t\t (const void **)&buf,\n\t\t\t\t\t &buf_len) >= 0) {\n\t\toffset = self->data - buf;\n\t\tnumbytes = buf_len + offset;\n\t}\n\telse {\n\t\tPyErr_Clear();\n \t\tnumbytes = PyArray_MultiplyList(new->dimensions,\n\t\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\toffset = self->data - new->data;\n\t}\n\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes,\n\t\t\t\t offset,\n\t\t\t\t self->dimensions, newstrides.ptr)) {\n\t\tPyErr_SetString(PyExc_ValueError, \"strides is not \"\\\n\t\t\t\t\"compatible with available memory\");\n\t\tgoto fail;\n\t}\n\tmemcpy(self->strides, newstrides.ptr, sizeof(intp)*newstrides.len);\n\tPyArray_UpdateFlags(self, CONTIGUOUS | FORTRAN);\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn 0;\n\n fail:\n\tPyDimMem_FREE(newstrides.ptr);\n\treturn -1;\n}\n\n\nstatic PyObject *\narray_protocol_strides_get(PyArrayObject *self)\n{\n\tif PyArray_ISCONTIGUOUS(self) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyArray_IntTupleFromIntp(self->nd, self->strides);\n}\n\nstatic PyObject *\narray_priority_get(PyArrayObject *self)\n{\n\tif (PyArray_CheckExact(self))\n\t\treturn PyFloat_FromDouble(PyArray_PRIORITY);\n\telse\n\t\treturn PyFloat_FromDouble(PyArray_SUBTYPE_PRIORITY);\n}\n\n\nstatic PyObject *\narray_dataptr_get(PyArrayObject *self)\n{\n\treturn Py_BuildValue(\"NO\",\n\t\t\t PyString_FromFormat(\"%p\", self->data),\n\t\t\t (self->flags & WRITEABLE ? Py_False :\n\t\t\t Py_True));\n}\n\nstatic PyObject *\narray_data_get(PyArrayObject *self)\n{\n\tintp nbytes;\n\tif (!(PyArray_ISONESEGMENT(self))) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot get single-\"\\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn NULL;\n\t}\n\tnbytes = PyArray_NBYTES(self);\n\tif PyArray_ISWRITEABLE(self)\n\t\treturn PyBuffer_FromReadWriteObject((PyObject *)self, 0,\n\t\t\t\t\t\t (int) nbytes);\n\telse\n\t\treturn PyBuffer_FromObject((PyObject *)self, 0, (int) nbytes);\n}\n\nstatic int\narray_data_set(PyArrayObject *self, PyObject *op)\n{\n\tvoid *buf;\n\tint buf_len;\n\tint writeable=1;\n\n\tif (PyObject_AsWriteBuffer(op, &buf, &buf_len) < 0) {\n\t\twriteable = 0;\n\t\tif (PyObject_AsReadBuffer(op, (const void **)&buf,\n\t\t\t\t\t &buf_len) < 0) {\n\t\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\t\"object does not have single-segment \" \\\n\t\t\t\t\t\"buffer interface\");\n\t\t\treturn -1;\n\t\t}\n\t}\n\tif (!PyArray_ISONESEGMENT(self)) {\n\t\tPyErr_SetString(PyExc_AttributeError, \"cannot set single-\" \\\n\t\t\t\t\"segment buffer for discontiguous array\");\n\t\treturn -1;\n\t}\n\tif (PyArray_NBYTES(self) > buf_len) {\n\t\tPyErr_SetString(PyExc_AttributeError,\n\t\t\t\t\"not enough data for array\");\n\t\treturn -1;\n\t}\n\tif (self->flags & OWN_DATA) {\n\t\tPyArray_XDECREF(self);\n\t\tPyDataMem_FREE(self->data);\n\t}\n\tif (self->base) {\n\t\tif (self->flags & UPDATEIFCOPY) {\n\t\t\t((PyArrayObject *)self->base)->flags |= WRITEABLE;\n\t\t\tself->flags &= ~UPDATEIFCOPY;\n\t\t}\n\t\tPy_DECREF(self->base);\n\t}\n\tPy_INCREF(op);\n\tself->base = op;\n\tself->data = buf;\n\tself->flags = CARRAY_FLAGS;\n\tif (!writeable)\n\t\tself->flags &= ~WRITEABLE;\n\treturn 0;\n}\n\n\nstatic PyObject *\narray_itemsize_get(PyArrayObject *self)\n{\n\treturn PyInt_FromLong((long) self->descr->elsize);\n}\n\nstatic PyObject *\narray_size_get(PyArrayObject *self)\n{\n\tintp size=PyArray_SIZE(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) size);\n#else\n\tif (size > MAX_LONG || size < MIN_LONG)\n\t\treturn PyLong_FromLongLong(size);\n\telse\n\t\treturn PyInt_FromLong((long) size);\n#endif\n}\n\nstatic PyObject *\narray_nbytes_get(PyArrayObject *self)\n{\n intp nbytes = PyArray_NBYTES(self);\n#if SIZEOF_INTP <= SIZEOF_LONG\n return PyInt_FromLong((long) nbytes);\n#else\n\tif (nbytes > MAX_LONG || nbytes < MIN_LONG)\n\t\treturn PyLong_FromLongLong(nbytes);\n\telse\n\t\treturn PyInt_FromLong((long) nbytes);\n#endif\n}\n\n\nstatic PyObject *arraydescr_protocol_typestr_get(PyArray_Descr *);\n\nstatic PyObject *\narray_typestr_get(PyArrayObject *self)\n{\n\treturn arraydescr_protocol_typestr_get(self->descr);\n}\n\nstatic PyObject *\narray_descr_get(PyArrayObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n/* If the type is changed.\n Also needing change: strides, itemsize\n\n Either itemsize is exactly the same\n or the array is single-segment (contiguous or fortran) with\n compatibile dimensions\n\n The shape and strides will be adjusted in that case as well.\n*/\n\nstatic int\narray_descr_set(PyArrayObject *self, PyObject *arg)\n{\n PyArray_Descr *newtype=NULL;\n intp newdim;\n int index;\n char *msg = \"new type not compatible with array.\";\n\n if (!(PyArray_DescrConverter(arg, &newtype)) ||\n newtype == NULL) {\n PyErr_SetString(PyExc_TypeError, \"invalid data-type for array\");\n\t\treturn -1;\n }\n\tif (newtype->type_num == PyArray_OBJECT || \\\n\t self->descr->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_TypeError, \\\n\t\t\t\t\"Cannot change descriptor for object\"\\\n\t\t\t\t\"array.\");\n\t\tPy_DECREF(newtype);\n\t\treturn -1;\n\t}\n\n\tif ((newtype->elsize != self->descr->elsize) &&\t\t\\\n\t (self->nd == 0 || !PyArray_ISONESEGMENT(self) || \\\n\t newtype->subarray)) goto fail;\n\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\n\tif (newtype->elsize < self->descr->elsize) {\n\t\t/* if it is compatible increase the size of the\n\t\t dimension at end (or at the front for FORTRAN)\n\t\t*/\n\t\tif (self->descr->elsize % newtype->elsize != 0)\n\t\t\tgoto fail;\n\t\tnewdim = self->descr->elsize / newtype->elsize;\n\t\tself->dimensions[index] *= newdim;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n\telse if (newtype->elsize > self->descr->elsize) {\n\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\n\t\tself->dimensions[index] = newdim / newtype->elsize;\n\t\tself->strides[index] = newtype->elsize;\n\t}\n\n /* fall through -- adjust type*/\n\n\tPy_DECREF(self->descr);\n\tif (newtype->subarray) {\n\t\t/* create new array object from data and update\n\t\t dimensions, strides and descr from it */\n\t\tPyArrayObject *temp;\n\n\t\t/* We would decref newtype here --- temp will\n\t\t steal a reference to it */\n\t\ttemp = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, newtype, self->nd,\n\t\t\t\t\t self->dimensions, self->strides,\n\t\t\t\t\t self->data, self->flags, NULL);\n\t\tif (temp == NULL) return -1;\n\t\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tnewtype = temp->descr;\n\t\tPy_INCREF(temp->descr);\n\t\t/* Fool deallocator not to delete these*/\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype;\n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\n return 0;\n\n fail:\n\tPyErr_SetString(PyExc_ValueError, msg);\n\tPy_DECREF(newtype);\n\treturn -1;\n}\n\nstatic PyObject *\narray_protocol_descr_get(PyArrayObject *self)\n{\n\tPyObject *res;\n\tPyObject *dobj;\n\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"descr\");\n\tif (res) return res;\n\tPyErr_Clear();\n\n\t/* get default */\n\tdobj = PyTuple_New(2);\n\tif (dobj == NULL) return NULL;\n\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\tPyTuple_SET_ITEM(dobj, 1, array_typestr_get(self));\n\tres = PyList_New(1);\n\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\tPyList_SET_ITEM(res, 0, dobj);\n\treturn res;\n}\n\nstatic PyObject *\narray_struct_get(PyArrayObject *self)\n{\n PyArrayInterface *inter;\n\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = self->nd;\n inter->typekind = self->descr->kind;\n inter->itemsize = self->descr->elsize;\n inter->flags = self->flags;\n /* reset unused flags */\n\tinter->flags &= ~(UPDATEIFCOPY | OWNDATA);\n\tif (PyArray_ISNOTSWAPPED(self)) inter->flags |= NOTSWAPPED;\n inter->strides = self->strides;\n inter->shape = self->dimensions;\n inter->data = self->data;\n\tPy_INCREF(self);\n return PyCObject_FromVoidPtrAndDesc(inter, self, gentype_struct_free);\n}\n\nstatic PyObject *\narray_base_get(PyArrayObject *self)\n{\n\tif (self->base == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\telse {\n\t\tPy_INCREF(self->base);\n\t\treturn self->base;\n\t}\n}\n\n\nstatic PyObject *\narray_real_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *)ret;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n}\n\n\nstatic int\narray_real_set(PyArrayObject *self, PyObject *val)\n{\n\tPyArrayObject *ret;\n\tPyArrayObject *new;\n\tint rint;\n\n\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\tif (new == NULL) return -1;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data,\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, \n\t\t\t\t\t\t (PyObject *)self);\n\t\tif (ret == NULL) {Py_DECREF(new); return -1;}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\tret = self;\n\t}\n\trint = PyArray_CopyInto(ret, new);\n\tPy_DECREF(ret);\n\tPy_DECREF(new);\n\treturn rint;\n}\n\nstatic PyObject *\narray_imag_get(PyArrayObject *self)\n{\n\tPyArrayObject *ret;\n PyArray_Descr *type;\n\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\ttype = PyArray_DescrFromType(self->descr->type_num -\n\t\t\t\t\t PyArray_NUM_FLOATTYPE);\n\t\tret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t type,\n\t\t\t\t\t self->nd,\n\t\t\t\t\t self->dimensions,\n\t\t\t\t\t self->strides,\n\t\t\t\t\t self->data + type->elsize,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) return NULL;\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\treturn (PyObject *) ret;\n\t}\n\telse {\n\t\ttype = self->descr;\n\t\tPy_INCREF(type);\n\t\tret = (PyArrayObject *)PyArray_Zeros(self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t type,\n\t\t\t\t\t\t PyArray_ISFORTRAN(self));\n\t\tret->flags &= ~WRITEABLE;\n\t\treturn (PyObject *)ret;\n\t}\n}\n\nstatic int\narray_imag_set(PyArrayObject *self, PyObject *val)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyArrayObject *ret;\n\t\tPyArrayObject *new;\n\t\tint rint;\n\n\t\tnew = (PyArrayObject *)PyArray_FromAny(val, NULL, 0, 0, 0, NULL);\n\t\tif (new == NULL) return -1;\n\t\tret = (PyArrayObject *)PyArray_New(self->ob_type,\n\t\t\t\t\t\t self->nd,\n\t\t\t\t\t\t self->dimensions,\n\t\t\t\t\t\t self->descr->type_num - \\\n\t\t\t\t\t\t PyArray_NUM_FLOATTYPE,\n\t\t\t\t\t\t self->strides,\n\t\t\t\t\t\t self->data +\t\t\\\n\t\t\t\t\t\t (self->descr->elsize >> 1),\n\t\t\t\t\t\t 0,\n\t\t\t\t\t\t self->flags, (PyObject *)self);\n\t\tif (ret == NULL) {\n\t\t\tPy_DECREF(new);\n\t\t\treturn -1;\n\t\t}\n\t\tret->flags &= ~CONTIGUOUS;\n\t\tret->flags &= ~FORTRAN;\n\t\tPy_INCREF(self);\n\t\tret->base = (PyObject *)self;\n\t\trint = PyArray_CopyInto(ret, new);\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn rint;\n\t}\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError, \"does not have imaginary \" \\\n\t\t\t\t\"part to set\");\n\t\treturn -1;\n\t}\n}\n\nstatic PyObject *\narray_flat_get(PyArrayObject *self)\n{\n return PyArray_IterNew((PyObject *)self);\n}\n\nstatic int\narray_flat_set(PyArrayObject *self, PyObject *val)\n{\n\tPyObject *arr=NULL;\n\tint retval = -1;\n\tPyArrayIterObject *selfit=NULL, *arrit=NULL;\n\tPyArray_Descr *typecode;\n int swap;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->descr;\n\tPy_INCREF(typecode);\n\tarr = PyArray_FromAny(val, typecode,\n\t\t\t 0, 0, FORCECAST | FORTRAN_IF(self), NULL);\n\tif (arr == NULL) return -1;\n\tarrit = (PyArrayIterObject *)PyArray_IterNew(arr);\n\tif (arrit == NULL) goto exit;\n\tselfit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (selfit == NULL) goto exit;\n\n swap = PyArray_ISNOTSWAPPED(self) != PyArray_ISNOTSWAPPED(arr);\n copyswap = self->descr->f->copyswap;\n if (PyArray_ISOBJECT(self)) {\n while(selfit->index < selfit->size) {\n Py_XDECREF(*((PyObject **)selfit->dataptr));\n Py_INCREF(*((PyObject **)arrit->dataptr));\n memmove(selfit->dataptr, arrit->dataptr,\n sizeof(PyObject *));\n PyArray_ITER_NEXT(selfit);\n PyArray_ITER_NEXT(arrit);\n if (arrit->index == arrit->size)\n PyArray_ITER_RESET(arrit);\n }\n retval = 0;\n goto exit;\n }\n\n\twhile(selfit->index < selfit->size) {\n\t\tmemmove(selfit->dataptr, arrit->dataptr, self->descr->elsize);\n copyswap(selfit->dataptr, NULL, swap, self);\n\t\tPyArray_ITER_NEXT(selfit);\n\t\tPyArray_ITER_NEXT(arrit);\n\t\tif (arrit->index == arrit->size)\n\t\t\tPyArray_ITER_RESET(arrit);\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(selfit);\n\tPy_XDECREF(arrit);\n\tPy_XDECREF(arr);\n\treturn retval;\n}\n\nstatic PyGetSetDef array_getsetlist[] = {\n {\"ndim\",\n\t (getter)array_ndim_get,\n\t NULL,\n\t \"number of array dimensions\"},\n {\"flags\",\n\t (getter)array_flags_get,\n NULL,\n\t \"special dictionary of flags\"},\n {\"shape\",\n\t (getter)array_shape_get,\n\t (setter)array_shape_set,\n\t \"tuple of array dimensions\"},\n {\"strides\",\n\t (getter)array_strides_get,\n\t (setter)array_strides_set,\n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)array_data_get,\n\t (setter)array_data_set,\n\t \"pointer to start of data\"},\n {\"itemsize\",\n\t (getter)array_itemsize_get,\n\t NULL,\n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)array_size_get,\n\t NULL,\n \"number of elements in the array\"},\n {\"nbytes\",\n (getter)array_nbytes_get,\n NULL,\n \"number of bytes in the array\"},\n\t{\"base\",\n\t (getter)array_base_get,\n\t NULL,\n\t \"base object\"},\n\t{\"dtype\",\n\t (getter)array_descr_get,\n\t (setter)array_descr_set,\n\t \"get(set) data-type-descriptor for array\"},\n {\"real\",\n\t (getter)array_real_get,\n\t (setter)array_real_set,\n\t \"real part of array\"},\n {\"imag\",\n\t (getter)array_imag_get,\n\t (setter)array_imag_set,\n\t \"imaginary part of array\"},\n\t{\"flat\",\n\t (getter)array_flat_get,\n\t (setter)array_flat_set,\n\t \"a 1-d view of a contiguous array\"},\n\t{\"__array_data__\",\n\t (getter)array_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)array_protocol_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\",\n\t (getter)array_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)array_protocol_strides_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)array_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t{\"__array_priority__\",\n\t (getter)array_priority_get,\n\t NULL,\n\t \"Array priority\"},\n\t{NULL, NULL, NULL, NULL}, /* Sentinel */\n};\n\n/****************** end of attribute get and set routines *******************/\n\n\nstatic PyObject *\narray_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n /* nitems will always be 0 */\n obj = (PyObject *)_pya_malloc(sizeof(PyArrayObject));\n PyObject_Init(obj, type);\n return obj;\n}\n\n\nstatic char Arraytype__doc__[] =\n \"A array object represents a multidimensional, homogeneous array\\n\"\n\t\" of fixed-size items. An associated data-type-descriptor object\\n\"\n\t\" details the data-type in an array (including byteorder and any\\n\"\n\t\" fields). An array can be constructed using the numpy.array\\n\"\n\t\" command. Arrays are sequence, mapping and numeric objects.\\n\"\n\t\" More information is available in the numpy module and by looking\\n\"\n\t\" at the methods and attributes of an array.\\n\\n\"\n\t\" ndarray.__new__(subtype, shape=, dtype=int_, buffer=None, \\n\"\n\t\" offset=0, strides=None, fortran=False)\\n\\n\"\n\t\" There are two modes of creating an array using __new__:\\n\"\n\t\" 1) If buffer is None, then only shape, dtype, and fortran \\n\"\n\t\" are used\\n\"\n\t\" 2) If buffer is an object exporting the buffer interface, then\\n\"\n\t\" all keywords are interpreted.\\n\"\n\t\" The dtype parameter can be any object that can be interpreted \\n\"\n\t\" as a numpy.dtype object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\nstatic PyTypeObject PyArray_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n /* methods */\n (destructor)array_dealloc,\t\t /*tp_dealloc */\n (printfunc)NULL,\t\t\t /*tp_print*/\n 0,\t\t\t\t\t /*tp_getattr*/\n 0,\t\t\t\t\t /*tp_setattr*/\n (cmpfunc)0,\t\t /*tp_compare*/\n (reprfunc)array_repr,\t\t /*tp_repr*/\n &array_as_number,\t\t\t /*tp_as_number*/\n &array_as_sequence,\t /*tp_as_sequence*/\n &array_as_mapping,\t\t\t /*tp_as_mapping*/\n (hashfunc)0,\t\t\t /*tp_hash*/\n (ternaryfunc)0,\t\t\t /*tp_call*/\n (reprfunc)array_str,\t /*tp_str*/\n\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n &array_as_buffer, \t /*tp_as_buffer*/\n (Py_TPFLAGS_DEFAULT\n | Py_TPFLAGS_BASETYPE\n | Py_TPFLAGS_CHECKTYPES), /*tp_flags*/\n /*Documentation string */\n Arraytype__doc__,\t\t\t /*tp_doc*/\n\n (traverseproc)0,\t\t\t /*tp_traverse */\n (inquiry)0,\t\t\t /*tp_clear */\n (richcmpfunc)array_richcompare,\t /*tp_richcompare */\n offsetof(PyArrayObject, weakreflist), /*tp_weaklistoffset */\n\n /* Iterator support (use standard) */\n\n (getiterfunc)array_iter,\t /* tp_iter */\n (iternextfunc)0,\t\t\t /* tp_iternext */\n\n /* Sub-classing (new-style object) support */\n\n array_methods,\t\t\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n array_getsetlist,\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n array_alloc,\t /* tp_alloc */\n (newfunc)array_new,\t\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/* The rest of this code is to build the right kind of array from a python */\n/* object. */\n\nstatic int\ndiscover_depth(PyObject *s, int max, int stop_at_string, int stop_at_tuple)\n{\n int d=0;\n PyObject *e;\n\n if(max < 1) return -1;\n\n if(! PySequence_Check(s) || PyInstance_Check(s) || \\\n\t PySequence_Length(s) < 0) {\n PyErr_Clear(); return 0;\n }\n if (PyArray_Check(s))\n\t\treturn PyArray_NDIM(s);\n if(PyString_Check(s) || PyBuffer_Check(s) || PyUnicode_Check(s))\n\t\treturn stop_at_string ? 0:1;\n\tif (stop_at_tuple && PyTuple_Check(s)) return 0;\n\tif ((e=PyObject_GetAttrString(s, \"__array_shape__\")) != NULL) {\n\t\tif (PyTuple_Check(e)) d=PyTuple_GET_SIZE(e);\n\t\telse d=-1;\n\t\tPy_DECREF(e);\n\t\tif (d>-1) return d;\n\t}\n\telse PyErr_Clear();\n\n if (PySequence_Length(s) == 0)\n\t\treturn 1;\n if ((e=PySequence_GetItem(s,0)) == NULL) return -1;\n if(e!=s) {\n\t\td=discover_depth(e, max-1, stop_at_string, stop_at_tuple);\n\t\tif(d >= 0) d++;\n\t}\n Py_DECREF(e);\n return d;\n}\n\nstatic int\ndiscover_itemsize(PyObject *s, int nd, int *itemsize)\n{\n\tint n, r, i;\n\tPyObject *e;\n\n\tn = PyObject_Length(s);\n\n\tif ((nd == 0) || PyString_Check(s) ||\t\t\\\n\t PyUnicode_Check(s) || PyBuffer_Check(s)) {\n\t\tif PyUnicode_Check(s)\n\t\t\t*itemsize = MAX(*itemsize, 4*n);\n\t\telse\n\t\t\t*itemsize = MAX(*itemsize, n);\n\t\treturn 0;\n\t}\n\tfor (i=0; i n_lower) n_lower = d[1];\n }\n d[1] = n_lower;\n\n return 0;\n}\n\n/* new reference */\n/* doesn't alter refcount of chktype or mintype ---\n unless one of them is returned */\nstatic PyArray_Descr *\n_array_small_type(PyArray_Descr *chktype, PyArray_Descr* mintype)\n{\n\tPyArray_Descr *outtype;\n\n\tif (chktype->type_num > mintype->type_num) outtype = chktype;\n\telse outtype = mintype;\n\n\tPy_INCREF(outtype);\n\tif (PyTypeNum_ISEXTENDED(outtype->type_num) &&\t\t\\\n\t (PyTypeNum_ISEXTENDED(mintype->type_num) ||\t\t\\\n\t mintype->type_num==0)) {\n\t\tint testsize = outtype->elsize;\n\t\tregister int chksize, minsize;\n\t\tchksize = chktype->elsize;\n\t\tminsize = mintype->elsize;\n\t\t/* Handle string->unicode case separately\n\t\t because string itemsize is twice as large */\n\t\tif (outtype->type_num == PyArray_UNICODE &&\n\t\t mintype->type_num == PyArray_STRING) {\n\t\t\ttestsize = MAX(chksize, 4*minsize);\n\t\t}\n\t\telse {\n\t\t\ttestsize = MAX(chksize, minsize);\n\t\t}\n\t\tif (testsize != outtype->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(outtype);\n\t\t\touttype->elsize = testsize;\n\t\t\tPy_XDECREF(outtype->fields);\n\t\t\touttype->fields = NULL;\n\t\t}\n\t}\n\treturn outtype;\n}\n\nstatic PyArray_Descr *\n_array_find_python_scalar_type(PyObject *op)\n{\n if (PyFloat_Check(op)) {\n return PyArray_DescrFromType(PyArray_DOUBLE);\n } else if (PyComplex_Check(op)) {\n return PyArray_DescrFromType(PyArray_CDOUBLE);\n } else if (PyInt_Check(op)) {\n /* bools are a subclass of int */\n if (PyBool_Check(op)) {\n return PyArray_DescrFromType(PyArray_BOOL);\n } else {\n return PyArray_DescrFromType(PyArray_LONG);\n }\n } else if (PyLong_Check(op)) {\n /* if integer can fit into a longlong then return that\n */\n if ((PyLong_AsLongLong(op) == -1) && PyErr_Occurred()) {\n PyErr_Clear();\n return PyArray_DescrFromType(PyArray_OBJECT);\n }\n return PyArray_DescrFromType(PyArray_LONGLONG);\n }\n return NULL;\n}\n\n/* op is an object to be converted to an ndarray.\n\n minitype is the minimum type-descriptor needed.\n\n max is the maximum number of dimensions -- used for recursive call\n to avoid infinite recursion...\n\n*/\n\nstatic PyArray_Descr *\n_array_find_type(PyObject *op, PyArray_Descr *minitype, int max)\n{\n int l;\n PyObject *ip;\n\tPyArray_Descr *chktype=NULL;\n\tPyArray_Descr *outtype;\n\n\tif (minitype == NULL)\n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\n if (max < 0) goto deflt;\n\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\n\n chktype = _array_find_python_scalar_type(op);\n if (chktype) {\n goto finish;\n }\n\n\tif ((ip=PyObject_GetAttrString(op, \"__array_typestr__\"))!=NULL) {\n\t\tif (PyString_Check(ip)) {\n\t\t\tchktype =_array_typedescr_fromstr(PyString_AS_STRING(ip));\n\t\t}\n\t\tPy_DECREF(ip);\n if (chktype) goto finish;\n\t}\n\telse PyErr_Clear();\n\n if ((ip=PyObject_GetAttrString(op, \"__array_struct__\")) != NULL) {\n PyArrayInterface *inter;\n char buf[40];\n if (PyCObject_Check(ip)) {\n inter=(PyArrayInterface *)PyCObject_AsVoidPtr(ip);\n if (inter->version == 2) {\n snprintf(buf, 40, \"|%c%d\", inter->typekind,\n\t\t\t\t\t inter->itemsize);\n\t\t\t\tchktype = _array_typedescr_fromstr(buf);\n }\n }\n Py_DECREF(ip);\n if (chktype) goto finish;\n }\n\telse PyErr_Clear();\n\n if (PyString_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_STRING);\n\t\tchktype->elsize = PyString_GET_SIZE(op);\n\t\tgoto finish;\n }\n\n\tif (PyUnicode_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_UNICODE);\n\t\tchktype->elsize = PyUnicode_GET_DATA_SIZE(op);\n#ifndef Py_UNICODE_WIDE\n\t\tchktype->elsize <<= 1;\n#endif\n\t\tgoto finish;\n\t}\n\n\tif (PyBuffer_Check(op)) {\n\t\tchktype = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tchktype->elsize = op->ob_type->tp_as_sequence->sq_length(op);\n PyErr_Clear();\n\t\tgoto finish;\n\t}\n\n if (PyObject_HasAttrString(op, \"__array__\")) {\n ip = PyObject_CallMethod(op, \"__array__\", NULL);\n if(ip && PyArray_Check(ip)) {\n\t\t\tchktype = PyArray_DESCR(ip);\n\t\t\tPy_INCREF(chktype);\n Py_DECREF(ip);\n\t\t\tgoto finish;\n\t\t}\n Py_XDECREF(ip);\n\t\tif (PyErr_Occurred()) PyErr_Clear();\n }\n\n\tif (PyInstance_Check(op)) goto deflt;\n\n if (PySequence_Check(op)) {\n\n l = PyObject_Length(op);\n if (l < 0 && PyErr_Occurred()) {\n\t\t\tPyErr_Clear();\n\t\t\tgoto deflt;\n\t\t}\n if (l == 0 && minitype->type_num == PyArray_BOOL) {\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = PyArray_DescrFromType(PyArray_INTP);\n\t\t}\n while (--l >= 0) {\n\t\t\tPyArray_Descr *newtype;\n ip = PySequence_GetItem(op, l);\n if (ip==NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tgoto deflt;\n\t\t\t}\n\t\t\tchktype = _array_find_type(ip, minitype, max-1);\n\t\t\tnewtype = _array_small_type(chktype, minitype);\n\t\t\tPy_DECREF(minitype);\n\t\t\tminitype = newtype;\n\t\t\tPy_DECREF(chktype);\n Py_DECREF(ip);\n }\n\t\tchktype = minitype;\n\t\tPy_INCREF(minitype);\n\t\tgoto finish;\n }\n\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\n finish:\n\n\touttype = _array_small_type(chktype, minitype);\n\tPy_DECREF(chktype);\n\tPy_DECREF(minitype);\n\treturn outtype;\n}\n\nstatic int\nAssign_Array(PyArrayObject *self, PyObject *v)\n{\n PyObject *e;\n int l, r;\n\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\n l=PyObject_Length(v);\n if(l < 0) return -1;\n\n while(--l >= 0)\n {\n e=PySequence_GetItem(v,l);\n if (e == NULL) return -1;\n\t\t\tr = PySequence_SetItem((PyObject*)self,l,e);\n Py_DECREF(e);\n if(r == -1) return -1;\n }\n return 0;\n}\n\n/* \"Array Scalars don't call this code\" */\n/* steals reference to typecode -- no NULL*/\nstatic PyObject *\nArray_FromScalar(PyObject *op, PyArray_Descr *typecode)\n{\n PyArrayObject *ret;\n\tint itemsize;\n\tint type;\n\n\titemsize = typecode->elsize;\n\ttype = typecode->type_num;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\titemsize = PyObject_Length(op);\n\t\tif (type == PyArray_UNICODE) itemsize *= 4;\n\n\t\tif (itemsize != typecode->elsize) {\n\t\t\tPyArray_DESCR_REPLACE(typecode);\n\t\t\ttypecode->elsize = itemsize;\n\t\t}\n\t}\n\n ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t\t 0, NULL,\n\t\t\t\t\t\t NULL, NULL, 0, NULL);\n\tif (ret == NULL) return NULL;\n\tif (ret->nd > 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"shape-mismatch on array construction\");\n\t\tPy_DECREF(ret);\n\t\treturn NULL;\n\t}\n\n ret->descr->f->setitem(op, ret->data, ret);\n\n if (PyErr_Occurred()) {\n Py_DECREF(ret);\n return NULL;\n } else {\n return (PyObject *)ret;\n }\n}\n\n\n/* steals reference to typecode */\nstatic PyObject *\nArray_FromSequence(PyObject *s, PyArray_Descr *typecode, int fortran,\n\t\t int min_depth, int max_depth)\n{\n PyArrayObject *r;\n int nd;\n\tintp d[MAX_DIMS];\n\tint stop_at_string;\n\tint stop_at_tuple;\n\tint type = typecode->type_num;\n\tint itemsize = typecode->elsize;\n\n\tstop_at_string = ((type == PyArray_OBJECT) ||\t\\\n\t\t\t (type == PyArray_STRING) ||\t\\\n\t\t\t (type == PyArray_UNICODE) || \\\n\t\t\t (type == PyArray_VOID));\n\n\tstop_at_tuple = (type == PyArray_VOID && ((typecode->fields &&\t\\\n\t\t\t\t\t\t typecode->fields!=Py_None) \\\n\t\t\t\t\t\t || (typecode->subarray)));\n\n if (!((nd=discover_depth(s, MAX_DIMS+1, stop_at_string,\n\t\t\t\t stop_at_tuple)) > 0)) {\n\t\tif (nd==0)\n\t\t\treturn Array_FromScalar(s, typecode);\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid input sequence\");\n\t\tgoto fail;\n }\n\n\tif (max_depth && PyTypeNum_ISOBJECT(type) && (nd > max_depth)) {\n\t\tnd = max_depth;\n\t}\n\n if ((max_depth && nd > max_depth) ||\t\\\n\t (min_depth && nd < min_depth)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"invalid number of dimensions\");\n\t\tgoto fail;\n }\n\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) goto fail;\n\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) goto fail;\n\t\tif (type == PyArray_UNICODE) itemsize*=4;\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\n r=(PyArrayObject*)PyArray_NewFromDescr(&PyArray_Type, typecode,\n\t\t\t\t\t nd, d,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t fortran, NULL);\n\n if(!r) return NULL;\n if(Assign_Array(r,s) == -1) {\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\n\n fail:\n\tPy_DECREF(typecode);\n\treturn NULL;\n}\n\n\n/*OBJECT_API\n Is the typenum valid?\n*/\nstatic int\nPyArray_ValidType(int type)\n{\n\tPyArray_Descr *descr;\n\tint res=TRUE;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr==NULL) res = FALSE;\n\tPy_DECREF(descr);\n\treturn res;\n}\n\n\n/* If the output is not a CARRAY, then it is buffered also */\n\nstatic int\n_bufferedcast(PyArrayObject *out, PyArrayObject *in)\n{\n\tchar *inbuffer, *bptr, *optr;\n\tchar *outbuffer=NULL;\n\tPyArrayIterObject *it_in=NULL, *it_out=NULL;\n\tregister intp i, index;\n\tintp ncopies = PyArray_SIZE(out) / PyArray_SIZE(in);\n\tint elsize=in->descr->elsize;\n\tint nels = PyArray_BUFSIZE;\n\tint el;\n\tint inswap, outswap=0;\n\tint obuf=!PyArray_ISCARRAY(out);\n\tint oelsize = out->descr->elsize;\n\tPyArray_VectorUnaryFunc *castfunc;\n PyArray_CopySwapFunc *in_csn;\n PyArray_CopySwapFunc *out_csn;\n\tint retval = -1;\n\n\tcastfunc = in->descr->f->cast[out->descr->type_num];\n in_csn = in->descr->f->copyswap;\n out_csn = out->descr->f->copyswap;\n\n\t/* If the input or output is STRING, UNICODE, or VOID */\n\t/* then getitem and setitem are used for the cast */\n\t/* and byteswapping is handled by those methods */\n\n\tinswap = !(PyArray_ISFLEXIBLE(in) || PyArray_ISNOTSWAPPED(in));\n\n\tinbuffer = PyDataMem_NEW(PyArray_BUFSIZE*elsize);\n\tif (inbuffer == NULL) return -1;\n\tif (PyArray_ISOBJECT(in))\n\t\tmemset(inbuffer, 0, PyArray_BUFSIZE*elsize);\n\tit_in = (PyArrayIterObject *)PyArray_IterNew((PyObject *)in);\n\tif (it_in == NULL) goto exit;\n\n\tif (obuf) {\n\t\toutswap = !(PyArray_ISFLEXIBLE(out) || \\\n\t\t\t PyArray_ISNOTSWAPPED(out));\n\t\toutbuffer = PyDataMem_NEW(PyArray_BUFSIZE*oelsize);\n\t\tif (outbuffer == NULL) goto exit;\n\t\tif (PyArray_ISOBJECT(out))\n\t\t\tmemset(outbuffer, 0, PyArray_BUFSIZE*oelsize);\n\n\t\tit_out = (PyArrayIterObject *)PyArray_IterNew((PyObject *)out);\n\t\tif (it_out == NULL) goto exit;\n\n\t\tnels = MIN(nels, PyArray_BUFSIZE);\n\t}\n\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\n\twhile(ncopies--) {\n\t\tindex = it_in->size;\n\t\tPyArray_ITER_RESET(it_in);\n\t\twhile(index--) {\n in_csn(bptr, it_in->dataptr, inswap, in);\n\t\t\tbptr += elsize;\n\t\t\tPyArray_ITER_NEXT(it_in);\n\t\t\tel += 1;\n\t\t\tif ((el == nels) || (index == 0)) {\n\t\t\t\t/* buffer filled, do cast */\n\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\n\t\t\t\tif (obuf) {\n\t\t\t\t\t/* Copy from outbuffer to array */\n\t\t\t\t\tfor(i=0; idataptr,\n optr, outswap,\n out);\n\t\t\t\t\t\toptr += oelsize;\n\t\t\t\t\t\tPyArray_ITER_NEXT(it_out);\n\t\t\t\t\t}\n\t\t\t\t\toptr = outbuffer;\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\toptr += out->descr->elsize * nels;\n\t\t\t\t}\n\t\t\t\tel = 0;\n\t\t\t\tbptr = inbuffer;\n\t\t\t}\n\t\t}\n\t}\n\tretval = 0;\n exit:\n\tPy_XDECREF(it_in);\n\tPyDataMem_FREE(inbuffer);\n\tPyDataMem_FREE(outbuffer);\n\tif (obuf) {\n\t\tPy_XDECREF(it_out);\n\t}\n\treturn retval;\n}\n\n\n/* For backward compatibility */\n\n/* steals reference to at --- cannot be NULL*/\n/*OBJECT_API\n Cast an array using typecode structure.\n*/\nstatic PyObject *\nPyArray_CastToType(PyArrayObject *mp, PyArray_Descr *at, int fortran)\n{\n\tPyObject *out;\n\tint ret;\n\tPyArray_Descr *mpd;\n\n\tmpd = mp->descr;\n\n\tif (((mpd == at) || ((mpd->type_num == at->type_num) &&\t\t\\\n\t\t\t PyArray_EquivByteorders(mpd->byteorder,\\\n\t\t\t\t\t\t at->byteorder) &&\t\\\n\t\t\t ((mpd->elsize == at->elsize) ||\t\t\\\n\t\t\t (at->elsize==0)))) &&\t\t\t\\\n\t PyArray_ISBEHAVED_RO(mp)) {\n\t\tPy_DECREF(at);\n\t\tPy_INCREF(mp);\n\t\treturn (PyObject *)mp;\n\t}\n\n\tif (at->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(at);\n\t\tif (at == NULL) return NULL;\n\t\tif (mpd->type_num == PyArray_STRING &&\t\\\n\t\t at->type_num == PyArray_UNICODE)\n\t\t\tat->elsize = mpd->elsize << 2;\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING)\n\t\t\tat->elsize = mpd->elsize >> 2;\n\t\tif (at->type_num == PyArray_VOID)\n\t\t\tat->elsize = mpd->elsize;\n\t}\n\n\tout = PyArray_NewFromDescr(mp->ob_type, at,\n\t\t\t\t mp->nd,\n\t\t\t\t mp->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t fortran,\n\t\t\t\t (PyObject *)mp);\n\n\tif (out == NULL) return NULL;\n\tret = PyArray_CastTo((PyArrayObject *)out, mp);\n\tif (ret != -1) return out;\n\n\tPy_DECREF(out);\n\treturn NULL;\n\n}\n\n/* The number of elements in out must be an integer multiple\n of the number of elements in mp.\n*/\n\n/*OBJECT_API\n Cast to an already created array.\n*/\nstatic int\nPyArray_CastTo(PyArrayObject *out, PyArrayObject *mp)\n{\n\n\tint simple;\n\tintp mpsize = PyArray_SIZE(mp);\n\tintp outsize = PyArray_SIZE(out);\n\n\tif (mpsize == 0) return 0;\n\tif (!PyArray_ISWRITEABLE(out)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array is not writeable\");\n\t\treturn -1;\n\t}\n\tif (outsize % mpsize != 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"output array must have an integer-multiple\"\\\n\t\t\t\t\" of the number of elements in the input \"\\\n\t\t\t\t\"array\");\n\t\treturn -1;\n\t}\n\n\tif (out->descr->type_num >= PyArray_NTYPES) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"Can only cast to builtin types.\");\n\t\treturn -1;\n\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * mpsize;\n\t\tintp ncopies = outsize / mpsize;\n\n\t\twhile(ncopies--) {\n\t\t\tinptr = mp->data;\n\t\t\tmp->descr->f->cast[out->descr->type_num](inptr,\n\t\t\t\t\t\t\t optr,\n\t\t\t\t\t\t\t mpsize,\n\t\t\t\t\t\t\t mp, out);\n\t\t\toptr += obytes;\n\t\t}\n\t\treturn 0;\n\t}\n\n\t/* If not a well-behaved cast, then use buffers */\n\tif (_bufferedcast(out, mp) == -1) {\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n\n/* steals reference to newtype --- acc. NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromArray(PyArrayObject *arr, PyArray_Descr *newtype, int flags)\n{\n\n\tPyArrayObject *ret=NULL;\n\tint type, itemsize;\n\tint copy = 0;\n\tint arrflags;\n\tPyArray_Descr *oldtype;\n\tchar *msg = \"cannot copy back to a read-only array\";\n PyTypeObject *subtype;\n\n\toldtype = PyArray_DESCR(arr);\n\n subtype = arr->ob_type;\n\n\tif (newtype == NULL) {newtype = oldtype; Py_INCREF(oldtype);}\n\ttype = newtype->type_num;\n\titemsize = newtype->elsize;\n\n\t/* Don't copy if sizes are compatible */\n\tif ((flags & ENSURECOPY) || PyArray_EquivTypes(oldtype, newtype)) {\n\t\tarrflags = arr->flags;\n\n\t\tcopy = (flags & ENSURECOPY) || \\\n\t\t\t((flags & CONTIGUOUS) && (!(arrflags & CONTIGUOUS))) \\\n\t\t\t|| ((flags & ALIGNED) && (!(arrflags & ALIGNED))) \\\n\t\t\t|| (arr->nd > 1 &&\t\t\t\t\\\n\t\t\t ((flags & FORTRAN) && (!(arrflags & FORTRAN)))) \\\n\t\t\t|| ((flags & WRITEABLE) && (!(arrflags & WRITEABLE)));\n\n\t\tif (copy) {\n if ((flags & UPDATEIFCOPY) && \\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n\t\t\tret = (PyArrayObject *) \\\n\t\t\t\tPyArray_NewFromDescr(subtype, newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n\t\t\tif (PyArray_CopyInto(ret, arr) == -1)\n\t\t\t\t{Py_DECREF(ret); return NULL;}\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\t/* If no copy then just increase the reference\n\t\t count and return the input */\n\t\telse {\n if ((flags & ENSUREARRAY)) {\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t\tPy_INCREF(arr->descr);\n\t\t\t\tret = (PyArrayObject *)\t\t\t\\\n PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t\t\t arr->descr,\n\t\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t\t arr->strides,\n\t\t\t\t\t\t\t arr->data,\n\t\t\t\t\t\t\t arr->flags,NULL);\n if (ret == NULL) return NULL;\n ret->base = (PyObject *)arr;\n }\n else {\n ret = arr;\n }\n\t\t\tPy_INCREF(arr);\n\t\t}\n\t}\n\n\t/* The desired output type is different than the input\n\t array type */\n\telse {\n\t\t/* Cast to the desired type if we can do it safely\n\t\t Also cast if source is a ndim-0 array to mimic\n\t\t behavior with Python scalars */\n\t\tif (flags & FORCECAST || PyArray_NDIM(arr)==0 ||\n\t\t PyArray_CanCastTo(oldtype, newtype)) {\n if ((flags & UPDATEIFCOPY) &&\t\t\\\n (!PyArray_ISWRITEABLE(arr))) {\n\t\t\t\tPy_DECREF(newtype);\n PyErr_SetString(PyExc_ValueError, msg);\n return NULL;\n }\n if ((flags & ENSUREARRAY)) {\n subtype = &PyArray_Type;\n }\n ret = (PyArrayObject *)\\\n PyArray_NewFromDescr(subtype,\n\t\t\t\t\t\t newtype,\n\t\t\t\t\t\t arr->nd,\n\t\t\t\t\t\t arr->dimensions,\n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t flags & FORTRAN,\n\t\t\t\t\t\t (PyObject *)arr);\n if (ret == NULL) return NULL;\n if (PyArray_CastTo(ret, arr) < 0) {\n Py_DECREF(ret);\n return NULL;\n }\n\t\t\tif (flags & UPDATEIFCOPY) {\n\t\t\t\tret->flags |= UPDATEIFCOPY;\n\t\t\t\tret->base = (PyObject *)arr;\n PyArray_FLAGS(ret->base) &= ~WRITEABLE;\n\t\t\t\tPy_INCREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"array cannot be safely cast \" \\\n\t\t\t\t\t\"to required type\");\n\t\t\tret = NULL;\n\t\t}\n\t}\n\treturn (PyObject *)ret;\n}\n\n/* new reference */\nstatic PyArray_Descr *\n_array_typedescr_fromstr(char *str)\n{\n\tPyArray_Descr *descr;\n\tint type_num;\n\tchar typechar;\n\tint size;\n\tchar msg[] = \"unsupported typestring\";\n\tint swap;\n\tchar swapchar;\n\n\tswapchar = str[0];\n\tstr += 1;\n\n#define _MY_FAIL {\t\t\t\t \\\n\t\tPyErr_SetString(PyExc_ValueError, msg); \\\n\t\treturn NULL;\t\t\t\t\\\n\t}\n\n\ttypechar = str[0];\n\tsize = atoi(str + 1);\n\tswitch (typechar) {\n\tcase 'b':\n\t\tif (size == sizeof(Bool))\n\t\t\ttype_num = PyArray_BOOL;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'u':\n\t\tif (size == sizeof(uintp))\n\t\t\ttype_num = PyArray_UINTP;\n\t\telse if (size == sizeof(char))\n\t\t\ttype_num = PyArray_UBYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_USHORT;\n\t\telse if (size == sizeof(ulong))\n\t\t\ttype_num = PyArray_ULONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_UINT;\n\t\telse if (size == sizeof(ulonglong))\n\t\t\ttype_num = PyArray_ULONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'i':\n\t\tif (size == sizeof(intp))\n\t\t\ttype_num = PyArray_INTP;\n\t\telse if (size == sizeof(char))\n\t\t type_num = PyArray_BYTE;\n\t\telse if (size == sizeof(short))\n\t\t\ttype_num = PyArray_SHORT;\n\t\telse if (size == sizeof(long))\n\t\t\ttype_num = PyArray_LONG;\n\t\telse if (size == sizeof(int))\n\t\t\ttype_num = PyArray_INT;\n\t\telse if (size == sizeof(longlong))\n\t\t\ttype_num = PyArray_LONGLONG;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'f':\n\t\tif (size == sizeof(float))\n\t\t\ttype_num = PyArray_FLOAT;\n\t\telse if (size == sizeof(double))\n\t\t\ttype_num = PyArray_DOUBLE;\n\t\telse if (size == sizeof(longdouble))\n\t\t\ttype_num = PyArray_LONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'c':\n\t\tif (size == sizeof(float)*2)\n\t\t\ttype_num = PyArray_CFLOAT;\n\t\telse if (size == sizeof(double)*2)\n\t\t\ttype_num = PyArray_CDOUBLE;\n\t\telse if (size == sizeof(longdouble)*2)\n\t\t\ttype_num = PyArray_CLONGDOUBLE;\n\t\telse _MY_FAIL\n\t\t\tbreak;\n\tcase 'O':\n\t\tif (size == sizeof(PyObject *))\n\t\t\ttype_num = PyArray_OBJECT;\n\t\telse _MY_FAIL\n\t break;\n\tcase PyArray_STRINGLTR:\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase PyArray_UNICODELTR:\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize <<= 2;\n\t\tbreak;\n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\n#undef _MY_FAIL\n\n descr = PyArray_DescrFromType(type_num);\n if (descr == NULL) return NULL;\n swap = !PyArray_ISNBO(swapchar);\n if (descr->elsize == 0 || swap) {\n\t /* Need to make a new PyArray_Descr */\n\t PyArray_DESCR_REPLACE(descr);\n\t if (descr==NULL) return NULL;\n\t if (descr->elsize == 0)\n\t\t descr->elsize = size;\n\t if (swap)\n\t\t descr->byteorder = swapchar;\n }\n return descr;\n}\n\n/* OBJECT_API */\nstatic PyObject *\nPyArray_FromStructInterface(PyObject *input)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r;\n\tchar endian = PyArray_NATBYTE;\n\n attr = PyObject_GetAttrString(input, \"__array_struct__\");\n if (attr == NULL) {\n\t\tPyErr_Clear();\n\t\treturn Py_NotImplemented;\n\t}\n if (!PyCObject_Check(attr) || \\\n ((inter=((PyArrayInterface *)\\\n\t\t PyCObject_AsVoidPtr(attr)))->version != 2)) {\n PyErr_SetString(PyExc_ValueError, \"invalid __array_struct__\");\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\tif ((inter->flags & NOTSWAPPED) != NOTSWAPPED) {\n\t\tendian = PyArray_OPPBYTE;\n\t\tinter->flags &= ~NOTSWAPPED;\n\t}\n\n snprintf(buf, 40, \"%c%c%d\", endian, inter->typekind, inter->itemsize);\n if (!(thetype=_array_typedescr_fromstr(buf))) {\n\t\tPy_DECREF(attr);\n return NULL;\n }\n\n r = PyArray_NewFromDescr(&PyArray_Type, thetype,\n\t\t\t\t inter->nd, inter->shape,\n\t\t\t\t inter->strides, inter->data,\n\t\t\t\t inter->flags, NULL);\n\tPy_INCREF(input);\n\tPyArray_BASE(r) = input;\n Py_DECREF(attr);\n PyArray_UpdateFlags((PyArrayObject *)r, UPDATE_ALL_FLAGS);\n return r;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromInterface(PyObject *input)\n{\n\tPyObject *attr=NULL, *item=NULL;\n PyObject *tstr=NULL, *shape=NULL;\n PyArrayObject *ret;\n\tPyArray_Descr *type=NULL;\n\tchar *data;\n\tint buffer_len;\n\tint res, i, n;\n\tintp dims[MAX_DIMS], strides[MAX_DIMS];\n\tint dataflags = BEHAVED_FLAGS;\n\n\t/* Get the memory from __array_data__ and __array_offset__ */\n\t/* Get the shape */\n\t/* Get the typestring -- ignore array_descr */\n\t/* Get the strides */\n\n shape = PyObject_GetAttrString(input, \"__array_shape__\");\n if (shape == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n tstr = PyObject_GetAttrString(input, \"__array_typestr__\");\n if (tstr == NULL) {Py_DECREF(shape); PyErr_Clear(); return Py_NotImplemented;}\n\n\tattr = PyObject_GetAttrString(input, \"__array_data__\");\n\tif ((attr == NULL) || (attr==Py_None) || (!PyTuple_Check(attr))) {\n\t\tif (attr && (attr != Py_None)) item=attr;\n\t\telse item=input;\n\t\tres = PyObject_AsWriteBuffer(item, (void **)&data,\n\t\t\t\t\t &buffer_len);\n\t\tif (res < 0) {\n\t\t\tPyErr_Clear();\n\t\t\tres = PyObject_AsReadBuffer(item, (const void **)&data,\n\t\t\t\t\t\t &buffer_len);\n\t\t\tif (res < 0) goto fail;\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t\tPy_XDECREF(attr);\n\t\tattr = PyObject_GetAttrString(input, \"__array_offset__\");\n\t\tif (attr) {\n\t\t\tlong num = PyInt_AsLong(attr);\n\t\t\tif (error_converting(num)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"__array_offset__ \"\\\n\t\t\t\t\t\t\"must be an integer\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tdata += num;\n\t\t}\n\t\telse PyErr_Clear();\n\t}\n\telse {\n\t\tif (PyTuple_GET_SIZE(attr) != 2) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ must return \"\t\\\n\t\t\t\t\t\"a 2-tuple with ('data pointer \"\\\n\t\t\t\t\t\"string', read-only flag)\");\n\t\t\tgoto fail;\n\t\t}\n\t\tres = sscanf(PyString_AsString(PyTuple_GET_ITEM(attr,0)),\n\t\t\t \"%p\", (void **)&data);\n\t\tif (res < 1) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_data__ string cannot be \" \\\n\t\t\t\t\t\"converted\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (PyObject_IsTrue(PyTuple_GET_ITEM(attr,1))) {\n\t\t\tdataflags &= ~WRITEABLE;\n\t\t}\n\t}\n\tPy_XDECREF(attr);\n\tattr = tstr;\n\tif (!PyString_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_typestr__ must be a string\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tgoto fail;\n\t}\n\ttype = _array_typedescr_fromstr(PyString_AS_STRING(attr));\n\tPy_DECREF(attr); attr=NULL; tstr=NULL;\n\tif (type==NULL) goto fail;\n\tattr = shape;\n\tif (!PyTuple_Check(attr)) {\n\t\tPyErr_SetString(PyExc_TypeError, \"__array_shape__ must be a tuple\");\n\t\tPy_INCREF(attr); /* decref'd twice below */\n\t\tPy_DECREF(type);\n\t\tgoto fail;\n\t}\n\tn = PyTuple_GET_SIZE(attr);\n\tfor (i=0; ibase = input;\n\n\tattr = PyObject_GetAttrString(input, \"__array_strides__\");\n\tif (attr != NULL && attr != Py_None) {\n\t\tif (!PyTuple_Check(attr)) {\n\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\"__array_strides__ must be a tuple\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tif (n != PyTuple_GET_SIZE(attr)) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"mismatch in length of \"\\\n\t\t\t\t\t\"__array_strides__ and \"\\\n\t\t\t\t\t\"__array_shape__\");\n\t\t\tPy_DECREF(attr);\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t\tfor (i=0; istrides, strides, n*sizeof(intp));\n\t}\n\telse PyErr_Clear();\n\tPyArray_UpdateFlags(ret, UPDATE_ALL_FLAGS);\n\treturn (PyObject *)ret;\n\n fail:\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* OBJECT_API*/\nstatic PyObject *\nPyArray_FromArrayAttr(PyObject *op, PyArray_Descr *typecode, PyObject *context)\n{\n PyObject *new;\n PyObject *array_meth;\n\n array_meth = PyObject_GetAttrString(op, \"__array__\");\n if (array_meth == NULL) {PyErr_Clear(); return Py_NotImplemented;}\n if (context == NULL) {\n if (typecode == NULL) new = PyObject_CallFunction(array_meth, \n\t\t\t\t\t\t\t\t NULL);\n else new = PyObject_CallFunction(array_meth, \"O\", typecode);\n }\n else {\n if (typecode == NULL) {\n new = PyObject_CallFunction(array_meth, \"OO\", Py_None,\n\t\t\t\t\t\t context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"\");\n }\n }\n else {\n new = PyObject_CallFunction(array_meth, \"OO\", \n\t\t\t\t\t\t typecode, context);\n if (new == NULL && \\\n\t\t\t PyErr_ExceptionMatches(PyExc_TypeError)) {\n PyErr_Clear();\n new = PyObject_CallFunction(array_meth, \"O\", \n\t\t\t\t\t\t\t typecode);\n }\n }\n }\n Py_DECREF(array_meth);\n if (new == NULL) return NULL;\n if (!PyArray_Check(new)) {\n PyErr_SetString(PyExc_ValueError,\n \"object __array__ method not \" \\\n \"producing an array\");\n Py_DECREF(new);\n return NULL;\n }\n return new;\n}\n\n/* Does not check for ENSURECOPY and NOTSWAPPED in flags */\n/* Steals a reference to newtype --- which can be NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromAny(PyObject *op, PyArray_Descr *newtype, int min_depth,\n int max_depth, int flags, PyObject *context)\n{\n /* This is the main code to make a NumPy array from a Python\n Object. It is called from lot's of different places which\n is why there are so many checks. The comments try to\n explain some of the checks. */\n\n PyObject *r=NULL;\n int seq = FALSE;\n\n\t/* Is input object already an array? */\n\t/* This is where the flags are used */\n if (PyArray_Check(op))\n\t\tr = PyArray_FromArray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tif (flags & UPDATEIFCOPY) goto err;\n\t\tr = PyArray_FromScalar(op, newtype);\n\t} else if (newtype == NULL &&\n (newtype = _array_find_python_scalar_type(op))) {\n\t if (flags & UPDATEIFCOPY) goto err;\n r = Array_FromScalar(op, newtype);\n }\n else if (((r = PyArray_FromStructInterface(op))!=Py_NotImplemented)|| \\\n ((r = PyArray_FromInterface(op)) != Py_NotImplemented) || \\\n ((r = PyArray_FromArrayAttr(op, newtype, context)) \\\n != Py_NotImplemented)) {\n PyObject *new;\n if (r == NULL) return NULL;\n if (newtype != NULL || flags != 0) {\n new = PyArray_FromArray((PyArrayObject *)r, newtype, \n\t\t\t\t\t\tflags);\n Py_DECREF(r);\n r = new;\n }\n }\n\telse {\n\t\tif (flags & UPDATEIFCOPY) goto err;\n\t\tif (newtype == NULL) {\n\t\t\tnewtype = _array_find_type(op, NULL, MAX_DIMS);\n\t\t}\n\t\tif (PySequence_Check(op)) {\n\t\t\t/* necessary but not sufficient */\n\n\t\t\tPy_INCREF(newtype);\n\t\t\tr = Array_FromSequence(op, newtype, flags & FORTRAN,\n\t\t\t\t\t min_depth, max_depth);\n\t\t\tif (PyErr_Occurred() && r == NULL) {\n /* It wasn't really a sequence after all.\n * Try interpreting it as a scalar */\n\t\t\t\tPyErr_Clear();\n\t\t\t}\n else {\n\t\t\t\tseq = TRUE;\n\t\t\t\tPy_DECREF(newtype);\n\t\t\t}\n }\n if (!seq)\n\t\t\tr = Array_FromScalar(op, newtype);\n\t}\n\n /* If we didn't succeed return NULL */\n if (r == NULL) return NULL;\n\n\t/* Be sure we succeed here */\n\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"internal error: PyArray_FromAny \"\\\n\t\t\t\t\"not producing an array\");\n\t\tPy_DECREF(r);\n return NULL;\n }\n\n if (min_depth != 0 && ((PyArrayObject *)r)->nd < min_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object of too small depth for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n if (max_depth != 0 && ((PyArrayObject *)r)->nd > max_depth) {\n PyErr_SetString(PyExc_ValueError,\n \"object too deep for desired array\");\n Py_DECREF(r);\n return NULL;\n }\n return r;\n\n err:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"UPDATEIFCOPY used for non-array input.\");\n\treturn NULL;\n}\n\n/* new reference -- accepts NULL for mintype*/\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrFromObject(PyObject *op, PyArray_Descr *mintype)\n{\n\treturn _array_find_type(op, mintype, MAX_DIMS);\n}\n\n/*OBJECT_API\n Return the typecode of the array a Python object would be converted\n to\n*/\nstatic int\nPyArray_ObjectType(PyObject *op, int minimum_type)\n{\n\tPyArray_Descr *intype;\n\tPyArray_Descr *outtype;\n\tint ret;\n\n\tintype = PyArray_DescrFromType(minimum_type);\n\tif (intype == NULL) PyErr_Clear();\n\touttype = _array_find_type(op, intype, MAX_DIMS);\n\tret = outtype->type_num;\n\tPy_DECREF(outtype);\n\tPy_DECREF(intype);\n\treturn ret;\n}\n\n\n/* flags is any of\n CONTIGUOUS,\n FORTRAN,\n ALIGNED,\n WRITEABLE,\n NOTSWAPPED,\n ENSURECOPY,\n UPDATEIFCOPY,\n FORCECAST,\n ENSUREARRAY\n\n or'd (|) together\n\n Any of these flags present means that the returned array should\n guarantee that aspect of the array. Otherwise the returned array\n won't guarantee it -- it will depend on the object as to whether or\n not it has such features.\n\n Note that ENSURECOPY is enough\n to guarantee CONTIGUOUS, ALIGNED and WRITEABLE\n and therefore it is redundant to include those as well.\n\n BEHAVED_FLAGS == ALIGNED | WRITEABLE\n CARRAY_FLAGS = CONTIGUOUS | BEHAVED_FLAGS\n FARRAY_FLAGS = FORTRAN | BEHAVED_FLAGS\n\n FORTRAN can be set in the FLAGS to request a FORTRAN array.\n Fortran arrays are always behaved (aligned,\n notswapped, and writeable) and not (C) CONTIGUOUS (if > 1d).\n\n UPDATEIFCOPY flag sets this flag in the returned array if a copy is\n made and the base argument points to the (possibly) misbehaved array.\n When the new array is deallocated, the original array held in base\n is updated with the contents of the new array.\n\n FORCECAST will cause a cast to occur regardless of whether or not\n it is safe.\n*/\n\n\n/* steals a reference to descr -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_CheckFromAny(PyObject *op, PyArray_Descr *descr, int min_depth,\n int max_depth, int requires, PyObject *context)\n{\n\tif (requires & NOTSWAPPED) {\n\t\tif (!descr && PyArray_Check(op) && \\\n\t\t !PyArray_ISNBO(PyArray_DESCR(op)->byteorder)) {\n\t\t\tdescr = PyArray_DescrNew(PyArray_DESCR(op));\n\t\t}\n\t\telse if ((descr && !PyArray_ISNBO(descr->byteorder))) {\n\t\t\tPyArray_DESCR_REPLACE(descr);\n\t\t}\n\t\tdescr->byteorder = PyArray_NATIVE;\n\t}\n\n\treturn PyArray_FromAny(op, descr, min_depth, max_depth,\n requires, context);\n}\n\n/* This is a quick wrapper around PyArray_FromAny(op, NULL, 0, 0,\n ENSUREARRAY) */\n/* that special cases Arrays and PyArray_Scalars up front */\n/* It *steals a reference* to the object */\n/* It also guarantees that the result is PyArray_Type */\n\n/* Because it decrefs op if any conversion needs to take place\n so it can be used like PyArray_EnsureArray(some_function(...)) */\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureArray(PyObject *op)\n{\n PyObject *new;\n\n if (op == NULL) return NULL;\n\n if (PyArray_CheckExact(op)) return op;\n\t\n\tif (PyArray_Check(op)) \n\t\treturn PyArray_View((PyArrayObject *)op, NULL, &PyArray_Type);\n\t\n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FromAny(op, NULL, 0, 0, ENSUREARRAY, NULL);\n Py_DECREF(op);\n return new;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_EnsureAnyArray(PyObject *op)\n{\n\tif (op && PyArray_Check(op)) return op;\n\treturn PyArray_EnsureArray(op);\n}\n\n/*OBJECT_API\n Check the type coercion rules.\n*/\nstatic int\nPyArray_CanCastSafely(int fromtype, int totype)\n{\n\tPyArray_Descr *from, *to;\n\tregister int felsize, telsize;\n\n if (fromtype == totype) return 1;\n if (fromtype == PyArray_BOOL) return 1;\n\tif (totype == PyArray_BOOL) return 0;\n if (totype == PyArray_OBJECT || totype == PyArray_VOID) return 1;\n\tif (fromtype == PyArray_OBJECT || fromtype == PyArray_VOID) return 0;\n\n\tfrom = PyArray_DescrFromType(fromtype);\n\tto = PyArray_DescrFromType(totype);\n\ttelsize = to->elsize;\n\tfelsize = from->elsize;\n\tPy_DECREF(from);\n\tPy_DECREF(to);\n\n switch(fromtype) {\n case PyArray_BYTE:\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_UBYTE:\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\tif (PyTypeNum_ISINTEGER(totype)) {\n\t\t\tif (PyTypeNum_ISSIGNED(totype)) {\n\t\t\t\treturn (telsize > felsize);\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn (telsize >= felsize);\n\t\t\t}\n\t\t}\n\t\telse if (PyTypeNum_ISFLOAT(totype)) {\n if (felsize < 8)\n return (telsize > felsize);\n else\n return (telsize >= felsize);\n\t\t}\n\t\telse if (PyTypeNum_ISCOMPLEX(totype)) {\n if (felsize < 8)\n return ((telsize >> 1) > felsize);\n else\n return ((telsize >> 1) >= felsize);\n\t\t}\n\t\telse return totype > fromtype;\n case PyArray_FLOAT:\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\tif (PyTypeNum_ISCOMPLEX(totype))\n\t\t\treturn ((telsize >> 1) >= felsize);\n\t\telse\n\t\t\treturn (totype > fromtype);\n case PyArray_CFLOAT:\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn (totype > fromtype);\n\tcase PyArray_STRING:\n\tcase PyArray_UNICODE:\n\t\treturn (totype > fromtype);\n default:\n return 0;\n }\n}\n\n/* leaves reference count alone --- cannot be NULL*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CanCastTo(PyArray_Descr *from, PyArray_Descr *to)\n{\n\tint fromtype=from->type_num;\n\tint totype=to->type_num;\n\tBool ret;\n\n\tret = (Bool) PyArray_CanCastSafely(fromtype, totype);\n\tif (ret) { /* Check String and Unicode more closely */\n\t\tif (fromtype == PyArray_STRING) {\n\t\t\tif (totype == PyArray_STRING) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t\telse if (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize << 2 \\\n\t\t\t\t <= to->elsize);\n\t\t\t}\n\t\t}\n\t\telse if (fromtype == PyArray_UNICODE) {\n\t\t\tif (totype == PyArray_UNICODE) {\n\t\t\t\tret = (from->elsize <= to->elsize);\n\t\t\t}\n\t\t}\n\t\t/* TODO: If totype is STRING or unicode\n\t\t see if the length is long enough to hold the\n\t\t stringified value of the object.\n\t\t*/\n\t}\n\treturn ret;\n}\n\n/*OBJECT_API\n See if array scalars can be cast.\n */\nstatic Bool\nPyArray_CanCastScalar(PyTypeObject *from, PyTypeObject *to)\n{\n\tint fromtype;\n\tint totype;\n\n\tfromtype = _typenum_fromtypeobj((PyObject *)from, 0);\n\ttotype = _typenum_fromtypeobj((PyObject *)to, 0);\n\tif (fromtype == PyArray_NOTYPE || totype == PyArray_NOTYPE) \n\t\treturn FALSE;\n\treturn (Bool) PyArray_CanCastSafely(fromtype, totype);\t\n}\n\n\n/*********************** Element-wise Array Iterator ***********************/\n/* Aided by Peter J. Verveer's nd_image package and numpy's arraymap ****/\n/* and Python's array iterator ***/\n\n/*OBJECT_API\n Get Iterator.\n*/\nstatic PyObject *\nPyArray_IterNew(PyObject *obj)\n{\n PyArrayIterObject *it;\n\tint i, nd;\n\tPyArrayObject *ao = (PyArrayObject *)obj;\n\n if (!PyArray_Check(ao)) {\n PyErr_BadInternalCall();\n return NULL;\n }\n\n it = (PyArrayIterObject *)_pya_malloc(sizeof(PyArrayIterObject));\n PyObject_Init((PyObject *)it, &PyArrayIter_Type);\n /* it = PyObject_New(PyArrayIterObject, &PyArrayIter_Type);*/\n if (it == NULL)\n return NULL;\n\n\tnd = ao->nd;\n\tPyArray_UpdateFlags(ao, CONTIGUOUS);\n\tit->contiguous = 0;\n\tif PyArray_ISCONTIGUOUS(ao) it->contiguous = 1;\n Py_INCREF(ao);\n it->ao = ao;\n\tit->size = PyArray_SIZE(ao);\n\tit->nd_m1 = nd - 1;\n\tit->factors[nd-1] = 1;\n\tfor (i=0; i < nd; i++) {\n\t\tit->dims_m1[i] = it->ao->dimensions[i] - 1;\n\t\tit->strides[i] = it->ao->strides[i];\n\t\tit->backstrides[i] = it->strides[i] *\t\\\n\t\t\tit->dims_m1[i];\n\t\tif (i > 0)\n\t\t\tit->factors[nd-i-1] = it->factors[nd-i] *\t\\\n\t\t\t\tit->ao->dimensions[nd-i];\n\t}\n\tPyArray_ITER_RESET(it);\n\n return (PyObject *)it;\n}\n\n\n/*OBJECT_API\n Get Iterator that iterates over all but one axis (don't use this with\n PyArray_ITER_GOTO1D)\n*/\nstatic PyObject *\nPyArray_IterAllButAxis(PyObject *obj, int axis)\n{\n\tPyArrayIterObject *it;\n\tit = (PyArrayIterObject *)PyArray_IterNew(obj);\n\tif (it == NULL) return NULL;\n\n\t/* adjust so that will not iterate over axis */\n\tit->contiguous = 0;\n\tif (it->size != 0) {\n\t\tit->size /= PyArray_DIM(obj,axis);\n\t}\n\tit->dims_m1[axis] = 0;\n\tit->backstrides[axis] = 0;\n\n\t/* (won't fix factors so don't use\n\t PyArray_ITER_GOTO1D with this iterator) */\n\treturn (PyObject *)it;\n}\n\n\n/* don't use with PyArray_ITER_GOTO1D because factors are not\n adjusted */\n\n/*OBJECT_API\n Adjusts previously broadcasted iterators so that the largest axis is not iterated \n over. Returns dimension which is largest in the range [0,multi->nd). A -1 \n is returned if multi->nd == 0.\n */\nstatic int\nPyArray_RemoveLargest(PyArrayMultiIterObject *multi)\n{\n\tPyArrayIterObject *it;\n\tint i;\n\tint axis=0;\n\tintp longest;\n\n\tif (multi->nd == 0) return -1;\n\t\n\tlongest = multi->dimensions[0];\n\t/* Find longest dimension */\n\tfor (i=1; ind; i++) {\n\t\tif (multi->dimensions[i] > longest) {\n\t\t\taxis = i;\n\t\t\tlongest = multi->dimensions[i];\n\t\t}\n\t}\n\t\n\tfor (i=0; inumiter; i++) {\n\t\tit = multi->iters[i];\n\t\tit->contiguous = 0;\n\t\tif (it->size != 0)\n\t\t\tit->size /= (it->dims_m1[axis]+1);\n\t\tit->dims_m1[axis] = 0;\n\t\tit->backstrides[axis] = 0;\t\t\n\t}\n\n\treturn axis;\n}\n\n/* Returns an array scalar holding the element desired */\n\nstatic PyObject *\narrayiter_next(PyArrayIterObject *it)\n{\n\tPyObject *ret;\n\n\tif (it->index < it->size) {\n\t\tret = PyArray_ToScalar(it->dataptr, it->ao);\n\t\tPyArray_ITER_NEXT(it);\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narrayiter_dealloc(PyArrayIterObject *it)\n{\n Py_XDECREF(it->ao);\n _pya_free(it);\n}\n\nstatic _int_or_ssize_t\niter_length(PyArrayIterObject *self)\n{\n return self->size;\n}\n\n\nstatic PyObject *\niter_subscript_Bool(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tint index, strides, itemsize;\n\tintp count=0;\n\tchar *dptr, *optr;\n\tPyObject *r;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn NULL;\n\t}\n\tindex = (ind->dimensions[0]);\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\t/* Get size of return array */\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0)\n\t\t\tcount++;\n\t\tdptr += strides;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t self->ao->descr, 1, &count,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\t/* Set up loop */\n\toptr = PyArray_DATA(r);\n\tindex = ind->dimensions[0];\n\tdptr = ind->data;\n\n copyswap = self->ao->descr->f->copyswap;\n\t/* Loop over Boolean array */\n\tswap = !(PyArray_ISNOTSWAPPED(self->ao));\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(optr, self->dataptr, swap, self->ao);\n\t\t\toptr += itemsize;\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\nstatic PyObject *\niter_subscript_int(PyArrayIterObject *self, PyArrayObject *ind)\n{\n\tintp num;\n\tPyObject *r;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint swap;\n\tchar *optr;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\titemsize = self->ao->descr->elsize;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\tPy_INCREF(self->ao->descr);\n\tr = PyArray_NewFromDescr(self->ao->ob_type, self->ao->descr,\n\t\t\t\t ind->nd, ind->dimensions,\n\t\t\t\t NULL, NULL,\n\t\t\t\t 0, (PyObject *)self->ao);\n\tif (r==NULL) return NULL;\n\n\toptr = PyArray_DATA(r);\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) {Py_DECREF(r); return NULL;}\n\tindex = ind_it->size;\n copyswap = PyArray_DESCR(r)->f->copyswap;\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif (num < 0 || num >= self->size) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\tPy_DECREF(r);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn NULL;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(optr, self->dataptr, swap, r);\n\t\toptr += itemsize;\n\t\tPyArray_ITER_NEXT(ind_it);\n\t}\n\tPy_DECREF(ind_it);\n\tPyArray_ITER_RESET(self);\n\treturn r;\n}\n\n\nstatic PyObject *\niter_subscript(PyArrayIterObject *self, PyObject *ind)\n{\n\tPyArray_Descr *indtype=NULL;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *r;\n\tchar *dptr;\n\tint size;\n\tPyObject *obj = NULL;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tobj = iter_subscript(self, ind);\n\t\tPy_DECREF(ind);\n\t\treturn obj;\n\t}\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto fail;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\t/* Tuples >1d not accepted --- i.e. no newaxis */\n\t/* Could implement this with adjusted strides\n\t and dimensions in iterator */\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\tPyArray_ITER_RESET(self);\n\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n\t\t\treturn PyArray_ToScalar(self->dataptr, self->ao);\n\t\t}\n\t\telse { /* empty array */\n\t\t\tintp ii = 0;\n\t\t\tPy_INCREF(self->ao->descr);\n\t\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t\t 1, &ii,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)self->ao);\n\t\t\treturn r;\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1)\n\t\t\tgoto fail;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start)\n\t\tif (n_steps == SingleIndex) { /* Integer */\n\t\t\tr = PyArray_ToScalar(self->dataptr, self->ao);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\treturn r;\n\t\t}\n\t\tsize = self->ao->descr->elsize;\n\t\tPy_INCREF(self->ao->descr);\n\t\tr = PyArray_NewFromDescr(self->ao->ob_type,\n\t\t\t\t\t self->ao->descr,\n\t\t\t\t\t 1, &n_steps,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)self->ao);\n\t\tif (r==NULL) goto fail;\n\t\tdptr = PyArray_DATA(r);\n swap = !PyArray_ISNOTSWAPPED(self->ao);\n copyswap = PyArray_DESCR(r)->f->copyswap;\n\t\twhile(n_steps--) {\n copyswap(dptr, self->dataptr, swap, r);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tdptr += size;\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\treturn r;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer) || PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tr = iter_subscript_Bool(self, (PyArrayObject *)obj);\n\t\t\tPy_DECREF(indtype);\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tnew = PyArray_FromAny(obj, indtype, 0, 0,\n FORCECAST | ALIGNED, NULL);\n\t\t\tif (new==NULL) goto fail;\n Py_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tr = iter_subscript_int(self, (PyArrayObject *)obj);\n\t\t}\n\t\telse {\n\t\t\tgoto fail;\n\t\t}\n\t\tPy_DECREF(obj);\n\t\treturn r;\n\t}\n\telse Py_DECREF(indtype);\n\n\n fail:\n\tif (!PyErr_Occurred())\n\t\tPyErr_SetString(PyExc_IndexError, \"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\treturn NULL;\n\n}\n\n\nstatic int\niter_ass_sub_Bool(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tint index, strides, itemsize;\n\tchar *dptr;\n PyArray_CopySwapFunc *copyswap;\n\n\tif (ind->nd != 1) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"boolean index array should have 1 dimension\");\n\t\treturn -1;\n\t}\n\titemsize = self->ao->descr->elsize;\n\tindex = ind->dimensions[0];\n\tstrides = ind->strides[0];\n\tdptr = ind->data;\n\tPyArray_ITER_RESET(self);\n\t/* Loop over Boolean array */\n copyswap = self->ao->descr->f->copyswap;\n\twhile(index--) {\n\t\tif (*((Bool *)dptr) != 0) {\n copyswap(self->dataptr, val->dataptr, swap, self->ao);\n\t\t\tPyArray_ITER_NEXT(val);\n\t\t\tif (val->index==val->size)\n\t\t\t\tPyArray_ITER_RESET(val);\n\t\t}\n\t\tdptr += strides;\n\t\tPyArray_ITER_NEXT(self);\n\t}\n\tPyArray_ITER_RESET(self);\n\treturn 0;\n}\n\nstatic int\niter_ass_sub_int(PyArrayIterObject *self, PyArrayObject *ind,\n\t\t PyArrayIterObject *val, int swap)\n{\n\tPyArray_Descr *typecode;\n\tintp num;\n\tPyArrayIterObject *ind_it;\n\tint itemsize;\n\tint index;\n PyArray_CopySwapFunc *copyswap;\n\n\ttypecode = self->ao->descr;\n\titemsize = typecode->elsize;\n copyswap = self->ao->descr->f->copyswap;\n\tif (ind->nd == 0) {\n\t\tnum = *((intp *)ind->data);\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, self->ao);\n\t\treturn 0;\n\t}\n\tind_it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)ind);\n\tif (ind_it == NULL) return -1;\n\tindex = ind_it->size;\n\twhile(index--) {\n\t\tnum = *((intp *)(ind_it->dataptr));\n\t\tif (num < 0) num += self->size;\n\t\tif ((num < 0) || (num >= self->size)) {\n\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t \"index %d out of bounds\"\t\t\\\n\t\t\t\t \" 0<=index<%d\", (int) num,\n\t\t\t\t (int) self->size);\n\t\t\tPy_DECREF(ind_it);\n\t\t\treturn -1;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, num);\n copyswap(self->dataptr, val->dataptr, swap, self->ao);\n\t\tPyArray_ITER_NEXT(ind_it);\n\t\tPyArray_ITER_NEXT(val);\n\t\tif (val->index == val->size)\n\t\t\tPyArray_ITER_RESET(val);\n\t}\n\tPy_DECREF(ind_it);\n\treturn 0;\n}\n\nstatic int\niter_ass_subscript(PyArrayIterObject *self, PyObject *ind, PyObject *val)\n{\n\tPyObject *arrval=NULL;\n\tPyArrayIterObject *val_it=NULL;\n\tPyArray_Descr *type;\n\tPyArray_Descr *indtype=NULL;\n\tint swap, retval=-1;\n\tint itemsize;\n\tintp start, step_size;\n\tintp n_steps;\n\tPyObject *obj=NULL;\n PyArray_CopySwapFunc *copyswap;\n\n\n\tif (ind == Py_Ellipsis) {\n\t\tind = PySlice_New(NULL, NULL, NULL);\n\t\tretval = iter_ass_subscript(self, ind, val);\n\t\tPy_DECREF(ind);\n\t\treturn retval;\n\t}\n\n\tif (PyTuple_Check(ind)) {\n\t\tint len;\n\t\tlen = PyTuple_GET_SIZE(ind);\n\t\tif (len > 1) goto finish;\n\t\tind = PyTuple_GET_ITEM(ind, 0);\n\t}\n\n\ttype = self->ao->descr;\n\titemsize = type->elsize;\n\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0, NULL);\n\tif (arrval==NULL) return -1;\n\tval_it = (PyArrayIterObject *)PyArray_IterNew(arrval);\n\tif (val_it==NULL) goto finish;\n\n\t/* Check for Boolean -- this is first becasue\n\t Bool is a subclass of Int */\n\n copyswap = PyArray_DESCR(arrval)->f->copyswap;\n\tswap = (PyArray_ISNOTSWAPPED(self->ao)!=PyArray_ISNOTSWAPPED(arrval));\n\tif (PyBool_Check(ind)) {\n\t\tif (PyObject_IsTrue(ind)) {\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, arrval);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\n\tif (PyLong_Check(ind) || PyInt_Check(ind) || PySlice_Check(ind)) {\n\t\tstart = parse_subindex(ind, &step_size, &n_steps,\n\t\t\t\t self->size);\n\t\tif (start == -1) goto finish;\n\t\tif (n_steps == RubberIndex || n_steps == PseudoIndex) {\n\t\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\t\"cannot use Ellipsis or newaxes here\");\n\t\t\tgoto finish;\n\t\t}\n\t\tPyArray_ITER_GOTO1D(self, start);\n\t\tif (n_steps == SingleIndex) { /* Integer */\n copyswap(self->dataptr, PyArray_DATA(arrval),\n swap, arrval);\n\t\t\tPyArray_ITER_RESET(self);\n\t\t\tretval=0;\n\t\t\tgoto finish;\n\t\t}\n\t\twhile(n_steps--) {\n copyswap(self->dataptr, val_it->dataptr,\n swap, arrval);\n\t\t\tstart += step_size;\n\t\t\tPyArray_ITER_GOTO1D(self, start)\n\t\t\tPyArray_ITER_NEXT(val_it);\n\t\t\tif (val_it->index == val_it->size)\n\t\t\t\tPyArray_ITER_RESET(val_it);\n\t\t}\n\t\tPyArray_ITER_RESET(self);\n\t\tretval = 0;\n\t\tgoto finish;\n\t}\n\n\t/* convert to INTP array if Integer array scalar or List */\n\n\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\tif (PyArray_IsScalar(ind, Integer)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromScalar(ind, indtype);\n\t}\n\telse if (PyList_Check(ind)) {\n\t\tPy_INCREF(indtype);\n\t\tobj = PyArray_FromAny(ind, indtype, 0, 0, FORCECAST, NULL);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\n\tif (PyArray_Check(obj)) {\n\t\t/* Check for Boolean object */\n\t\tif (PyArray_TYPE(obj)==PyArray_BOOL) {\n\t\t\tif (iter_ass_sub_Bool(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t\t/* Check for integer array */\n\t\telse if (PyArray_ISINTEGER(obj)) {\n\t\t\tPyObject *new;\n\t\t\tPy_INCREF(indtype);\n\t\t\tnew = PyArray_CheckFromAny(obj, indtype, 0, 0,\n FORCECAST | BEHAVED_NS_FLAGS, NULL);\n\t\t\tPy_DECREF(obj);\n\t\t\tobj = new;\n\t\t\tif (new==NULL) goto finish;\n\t\t\tif (iter_ass_sub_int(self, (PyArrayObject *)obj,\n\t\t\t\t\t val_it, swap) < 0)\n\t\t\t\tgoto finish;\n\t\t\tretval=0;\n\t\t}\n\t}\n\n finish:\n\tif (!PyErr_Occurred() && retval < 0)\n\t\tPyErr_SetString(PyExc_IndexError,\n\t\t\t\t\"unsupported iterator index\");\n\tPy_XDECREF(indtype);\n\tPy_XDECREF(obj);\n\tPy_XDECREF(val_it);\n\tPy_XDECREF(arrval);\n\treturn retval;\n\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)iter_length,\t\t /*mp_length*/\n#else\n (inquiry)iter_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)iter_subscript,\t /*mp_subscript*/\n (objobjargproc)iter_ass_subscript,\t/*mp_ass_subscript*/\n};\n\nstatic char doc_iter_array[] = \"__array__(type=None)\\n Get array \"\\\n \"from iterator\";\n\nstatic PyObject *\niter_array(PyArrayIterObject *it, PyObject *op)\n{\n\n PyObject *r;\n intp size;\n\n /* Any argument ignored */\n\n /* Two options:\n 1) underlying array is contiguous\n -- return 1-d wrapper around it\n 2) underlying array is not contiguous\n -- make new 1-d contiguous array with updateifcopy flag set\n to copy back to the old array\n */\n\n size = PyArray_SIZE(it->ao);\n\tPy_INCREF(it->ao->descr);\n if (PyArray_ISCONTIGUOUS(it->ao)) {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, it->ao->data,\n\t\t\t\t\t it->ao->flags,\n\t\t\t\t\t (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n }\n else {\n r = PyArray_NewFromDescr(it->ao->ob_type,\n\t\t\t\t\t it->ao->descr,\n\t\t\t\t\t 1, &size,\n\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t 0, (PyObject *)it->ao);\n\t\tif (r==NULL) return NULL;\n\t\tif (PyArray_CopyInto((PyArrayObject *)r, it->ao) < 0) {\n\t\t\tPy_DECREF(r);\n\t\t\treturn NULL;\n\t\t}\n PyArray_FLAGS(r) |= UPDATEIFCOPY;\n it->ao->flags &= ~WRITEABLE;\n }\n Py_INCREF(it->ao);\n PyArray_BASE(r) = (PyObject *)it->ao;\n return r;\n\n}\n\nstatic char doc_iter_copy[] = \"copy()\\n Get a copy of 1-d array\";\n\nstatic PyObject *\niter_copy(PyArrayIterObject *it, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\treturn PyArray_Flatten(it->ao, 0);\n}\n\nstatic PyMethodDef iter_methods[] = {\n /* to get array */\n {\"__array__\", (PyCFunction)iter_array, 1, doc_iter_array},\n\t{\"copy\", (PyCFunction)iter_copy, 1, doc_iter_copy},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyMemberDef iter_members[] = {\n\t{\"base\", T_OBJECT, offsetof(PyArrayIterObject, ao), RO, NULL},\n {\"index\", T_INT, offsetof(PyArrayIterObject, index), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\niter_coords_get(PyArrayIterObject *self)\n{\n int nd;\n nd = self->ao->nd;\n if (self->contiguous) { /* coordinates not kept track of --- need to generate\n from index */\n intp val;\n int i;\n val = self->index;\n for (i=0;icoordinates[i] = val / self->factors[i];\n val = val % self->factors[i];\n }\n }\n return PyArray_IntTupleFromIntp(nd, self->coordinates);\n}\n\nstatic PyGetSetDef iter_getsets[] = {\n\t{\"coords\",\n\t (getter)iter_coords_get,\n\t NULL,\n\t \"An N-d tuple of current coordinates.\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.flatiter\",\t\t /* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayiter_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &iter_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arrayiter_next,\t\t/* tp_iternext */\n iter_methods,\t\t\t\t/* tp_methods */\n iter_members,\t\t /* tp_members */\n iter_getsets, /* tp_getset */\n\n};\n\n/** END of Array Iterator **/\n\n\n\n/*********************** Subscript Array Iterator *************************\n * *\n * This object handles subscript behavior for array objects. *\n * It is an iterator object with a next method *\n * It abstracts the n-dimensional mapping behavior to make the looping *\n * code more understandable (maybe) *\n * and so that indexing can be set up ahead of time *\n */\n\n/* convert an indexing object to an INTP indexing array iterator\n if possible -- otherwise, it is a Slice or Ellipsis object\n and has to be interpreted on bind to a particular\n array so leave it NULL for now.\n */\nstatic int\n_convert_obj(PyObject *obj, PyArrayIterObject **iter)\n{\n\tPyArray_Descr *indtype;\n\tPyObject *arr;\n\n\tif (PySlice_Check(obj) || (obj == Py_Ellipsis))\n\t\t*iter = NULL;\n\telse {\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(obj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) return -1;\n\t\t*iter = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tPy_DECREF(arr);\n\t\tif (*iter == NULL) return -1;\n\t}\n\treturn 0;\n}\n\n/* Adjust dimensionality and strides for index object iterators\n --- i.e. broadcast\n */\n/*OBJECT_API*/\nstatic int\nPyArray_Broadcast(PyArrayMultiIterObject *mit)\n{\n\tint i, nd, k, j;\n\tintp tmp;\n\tPyArrayIterObject *it;\n\n\t/* Discover the broadcast number of dimensions */\n\tfor (i=0, nd=0; inumiter; i++)\n\t\tnd = MAX(nd, mit->iters[i]->ao->nd);\n\tmit->nd = nd;\n\n\t/* Discover the broadcast shape in each dimension */\n\tfor (i=0; idimensions[i] = 1;\n\t\tfor (j=0; jnumiter; j++) {\n\t\t\tit = mit->iters[j];\n\t\t\t/* This prepends 1 to shapes not already\n\t\t\t equal to nd */\n\t\t\tk = i + it->ao->nd - nd;\n\t\t\tif (k>=0) {\n\t\t\t\ttmp = it->ao->dimensions[k];\n\t\t\t\tif (tmp == 1) continue;\n\t\t\t\tif (mit->dimensions[i] == 1)\n\t\t\t\t\tmit->dimensions[i] = tmp;\n\t\t\t\telse if (mit->dimensions[i] != tmp) {\n\t\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\t\"shape mismatch: objects\" \\\n\t\t\t\t\t\t\t\" cannot be broadcast\" \\\n\t\t\t\t\t\t\t\" to a single shape\");\n\t\t\t\t\treturn -1;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/* Reset the iterator dimensions and strides of each iterator\n\t object -- using 0 valued strides for broadcasting */\n\n\ttmp = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tmit->size = tmp;\n\tfor (i=0; inumiter; i++) {\n\t\tit = mit->iters[i];\n\t\tit->nd_m1 = mit->nd - 1;\n\t\tit->size = tmp;\n\t\tnd = it->ao->nd;\n\t\tit->factors[mit->nd-1] = 1;\n\t\tfor (j=0; j < mit->nd; j++) {\n\t\t\tit->dims_m1[j] = mit->dimensions[j] - 1;\n\t\t\tk = j + nd - mit->nd;\n\t\t\t/* If this dimension was added or shape\n\t\t\t of underlying array was 1 */\n\t\t\tif ((k < 0) || \\\n\t\t\t it->ao->dimensions[k] != mit->dimensions[j]) {\n\t\t\t\tit->contiguous = 0;\n\t\t\t\tit->strides[j] = 0;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tit->strides[j] = it->ao->strides[k];\n\t\t\t}\n\t\t\tit->backstrides[j] = it->strides[j] *\t\\\n\t\t\t\tit->dims_m1[j];\n\t\t\tif (j > 0)\n\t\t\t\tit->factors[mit->nd-j-1] =\t\t\\\n\t\t\t\t\tit->factors[mit->nd-j] *\t\\\n\t\t\t\t\tmit->dimensions[mit->nd-j];\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn 0;\n}\n\n/* Reset the map iterator to the beginning */\nstatic void\nPyArray_MapIterReset(PyArrayMapIterObject *mit)\n{\n\tint i,j; intp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index = 0;\n\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\n\tif (mit->subspace != NULL) {\n\t\tmemcpy(coord, mit->bscoord, sizeof(intp)*mit->ait->ao->nd);\n\t\tPyArray_ITER_RESET(mit->subspace);\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_RESET(it);\n\t\t\tj = mit->iteraxes[i];\n\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t it->ao);\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tif (it->size != 0) {\n\t\t\t\tPyArray_ITER_RESET(it);\n\t\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t it->ao);\n\t\t\t}\n\t\t\telse coord[i] = 0;\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* This function needs to update the state of the map iterator\n and point mit->dataptr to the memory-location of the next object\n*/\nstatic void\nPyArray_MapIterNext(PyArrayMapIterObject *mit)\n{\n\tint i, j;\n\tintp coord[MAX_DIMS];\n\tPyArrayIterObject *it;\n\tPyArray_CopySwapFunc *copyswap;\n\n\tmit->index += 1;\n\tif (mit->index >= mit->size) return;\n\tcopyswap = mit->iters[0]->ao->descr->f->copyswap;\n\t/* Sub-space iteration */\n\tif (mit->subspace != NULL) {\n\t\tPyArray_ITER_NEXT(mit->subspace);\n\t\tif (mit->subspace->index == mit->subspace->size) {\n\t\t\t/* reset coord to coordinates of\n\t\t\t beginning of the subspace */\n\t\t\tmemcpy(coord, mit->bscoord,\n\t\t\t sizeof(intp)*mit->ait->ao->nd);\n\t\t\tPyArray_ITER_RESET(mit->subspace);\n\t\t\tfor (i=0; inumiter; i++) {\n\t\t\t\tit = mit->iters[i];\n\t\t\t\tPyArray_ITER_NEXT(it);\n\t\t\t\tj = mit->iteraxes[i];\n\t\t\t\tcopyswap(coord+j,it->dataptr,\n\t\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t\t it->ao);\n\t\t\t}\n\t\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\t\tmit->subspace->dataptr = mit->ait->dataptr;\n\t\t}\n\t\tmit->dataptr = mit->subspace->dataptr;\n\t}\n\telse {\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = mit->iters[i];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tcopyswap(coord+i,it->dataptr,\n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t it->ao);\n\t\t}\n\t\tPyArray_ITER_GOTO(mit->ait, coord);\n\t\tmit->dataptr = mit->ait->dataptr;\n\t}\n\treturn;\n}\n\n/* Bind a mapiteration to a particular array */\n\n/* Determine if subspace iteration is necessary. If so,\n 1) Fill in mit->iteraxes\n\t 2) Create subspace iterator\n\t 3) Update nd, dimensions, and size.\n\n Subspace iteration is necessary if: arr->nd > mit->numiter\n*/\n\n/* Need to check for index-errors somewhere.\n\n Let's do it at bind time and also convert all <0 values to >0 here\n as well.\n*/\nstatic void\nPyArray_MapIterBind(PyArrayMapIterObject *mit, PyArrayObject *arr)\n{\n\tint subnd;\n\tPyObject *sub, *obj=NULL;\n\tint i, j, n, curraxis, ellipexp, noellip;\n\tPyArrayIterObject *it;\n\tintp dimsize;\n\tintp *indptr;\n\n\tsubnd = arr->nd - mit->numiter;\n\tif (subnd < 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"too many indices for array\");\n\t\treturn;\n\t}\n\n\tmit->ait = (PyArrayIterObject *)PyArray_IterNew((PyObject *)arr);\n\tif (mit->ait == NULL) return;\n\n\t/* If this is just a view, then do nothing more */\n\t/* views are handled by just adjusting the strides\n\t and dimensions of the object.\n\t*/\n\n\t/* no subspace iteration needed. Finish up and Return */\n\tif (subnd == 0) {\n\t\tn = arr->nd;\n\t\tfor (i=0; iiteraxes[i] = i;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* all indexing arrays have been converted to 0\n\t therefore we can extract the subspace with a simple\n\t getitem call which will use view semantics\n\t*/\n\t/* But, be sure to do it with a true array.\n\t */\n\tif (PyArray_CheckExact(arr)) {\n\t\tsub = array_subscript(arr, mit->indexobj);\n\t}\n\telse {\n\t\tPy_INCREF(arr);\n\t\tobj = PyArray_EnsureArray((PyObject *)arr);\n\t\tif (obj == NULL) goto fail;\n\t\tsub = array_subscript((PyArrayObject *)obj, mit->indexobj);\n\t\tPy_DECREF(obj);\n\t}\n\n\tif (sub == NULL) goto fail;\n\tmit->subspace = (PyArrayIterObject *)PyArray_IterNew(sub);\n\tPy_DECREF(sub);\n\tif (mit->subspace == NULL) goto fail;\n\n\t/* Expand dimensions of result */\n\tn = mit->subspace->ao->nd;\n\tfor (i=0; idimensions[mit->nd+i] = mit->subspace->ao->dimensions[i];\n\tmit->nd += n;\n\n\t/* Now, we still need to interpret the ellipsis and slice objects\n\t to determine which axes the indexing arrays are referring to\n\t*/\n\tn = PyTuple_GET_SIZE(mit->indexobj);\n\n\t/* The number of dimensions an ellipsis takes up */\n\tellipexp = arr->nd - n + 1;\n\t/* Now fill in iteraxes -- remember indexing arrays have been\n converted to 0's in mit->indexobj */\n\tcurraxis = 0;\n\tj = 0;\n\tnoellip = 1; /* Only expand the first ellipsis */\n\tmemset(mit->bscoord, 0, sizeof(intp)*arr->nd);\n\tfor (i=0; iindexobj, i);\n\t\tif (PyInt_Check(obj) || PyLong_Check(obj))\n\t\t\tmit->iteraxes[j++] = curraxis++;\n\t\telse if (noellip && obj == Py_Ellipsis) {\n\t\t\tcurraxis += ellipexp;\n\t\t\tnoellip = 0;\n\t\t}\n\t\telse {\n\t\t\tintp start=0;\n\t\t\tintp stop, step;\n\t\t\t/* Should be slice object or\n\t\t\t another Ellipsis */\n\t\t\tif (obj == Py_Ellipsis) {\n\t\t\t\tmit->bscoord[curraxis] = 0;\n\t\t\t}\n\t\t\telse if (!PySlice_Check(obj) || \\\n\t\t\t\t (slice_GetIndices((PySliceObject *)obj,\n\t\t\t\t\t\t arr->dimensions[curraxis],\n\t\t\t\t\t\t &start, &stop, &step,\n\t\t\t\t\t\t &dimsize) < 0)) {\n\t\t\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t\t\t \"unexpected object \"\t\\\n\t\t\t\t\t \"(%s) in selection position %d\",\n\t\t\t\t\t obj->ob_type->tp_name, i);\n\t\t\t goto fail;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tmit->bscoord[curraxis] = start;\n\t\t\t}\n\t\t\tcurraxis += 1;\n\t\t}\n\t}\n finish:\n\t/* Here check the indexes (now that we have iteraxes) */\n\tmit->size = PyArray_MultiplyList(mit->dimensions, mit->nd);\n\tfor (i=0; inumiter; i++) {\n intp indval;\n\t\tit = mit->iters[i];\n\t\tPyArray_ITER_RESET(it);\n\t\tdimsize = arr->dimensions[mit->iteraxes[i]];\n\t\twhile(it->index < it->size) {\n\t\t\tindptr = ((intp *)it->dataptr);\n indval = *indptr;\n\t\t\tif (indval < 0) indval += dimsize;\n\t\t\tif (indval < 0 || indval >= dimsize) {\n\t\t\t\tPyErr_Format(PyExc_IndexError,\n\t\t\t\t\t \"index (%d) out of range \"\\\n\t\t\t\t\t \"(0<=index<=%d) in dimension %d\",\n\t\t\t\t\t (int) indval, (int) (dimsize-1),\n\t\t\t\t\t mit->iteraxes[i]);\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyArray_ITER_RESET(it);\n\t}\n\treturn;\n\n fail:\n\tPy_XDECREF(mit->subspace);\n\tPy_XDECREF(mit->ait);\n\tmit->subspace = NULL;\n\tmit->ait = NULL;\n\treturn;\n}\n\n/* This function takes a Boolean array and constructs index objects and\n iterators as if nonzero(Bool) had been called\n*/\nstatic int\n_nonzero_indices(PyObject *myBool, PyArrayIterObject **iters)\n{\n\tPyArray_Descr *typecode;\n\tPyArrayObject *ba =NULL, *new=NULL;\n\tint nd, j;\n\tintp size, i, count;\n\tBool *ptr;\n\tintp coords[MAX_DIMS], dims_m1[MAX_DIMS];\n\tintp *dptr[MAX_DIMS];\n\n\ttypecode=PyArray_DescrFromType(PyArray_BOOL);\n\tba = (PyArrayObject *)PyArray_FromAny(myBool, typecode, 0, 0,\n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\tif (ba == NULL) return -1;\n\tnd = ba->nd;\n\tfor (j=0; jdata;\n\tcount = 0;\n\n\t/* pre-determine how many nonzero entries there are */\n\tfor (i=0; iao->data;\n\t\tcoords[j] = 0;\n\t\tdims_m1[j] = ba->dimensions[j]-1;\n\t}\n\n\tptr = (Bool *)ba->data;\n\n\tif (count == 0) goto finish;\n\n\t/* Loop through the Boolean array and copy coordinates\n\t for non-zero entries */\n\tfor (i=0; i=0; j--) {\n\t\t\tif (coords[j] < dims_m1[j]) {\n\t\t\t\tcoords[j]++;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tcoords[j] = 0;\n\t\t\t}\n\t\t}\n\t}\n\n finish:\n\tPy_DECREF(ba);\n\treturn nd;\n\n fail:\n\tfor (j=0; jiters[i] = NULL;\n\tmit->index = 0;\n\tmit->ait = NULL;\n\tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\n\tif (fancy == SOBJ_LISTTUP) {\n\t\tPyObject *newobj;\n\t\tnewobj = PySequence_Tuple(indexobj);\n\t\tif (newobj == NULL) goto fail;\n\t\tPy_DECREF(indexobj);\n\t\tindexobj = newobj;\n\t\tmit->indexobj = indexobj;\n\t}\n\n#undef SOBJ_NOTFANCY\n#undef SOBJ_ISFANCY\n#undef SOBJ_BADARRAY\n#undef SOBJ_TOOMANY\n#undef SOBJ_LISTTUP\n\n\tif (oned) return (PyObject *)mit;\n\n\t/* Must have some kind of fancy indexing if we are here */\n\t/* indexobj is either a list, an arrayobject, or a tuple\n\t (with at least 1 list or arrayobject or Bool object), */\n\n\t/* convert all inputs to iterators */\n\tif (PyArray_Check(indexobj) &&\t\t\t\\\n\t (PyArray_TYPE(indexobj) == PyArray_BOOL)) {\n\t\tmit->numiter = _nonzero_indices(indexobj, mit->iters);\n\t\tif (mit->numiter < 0) goto fail;\n\t\tmit->nd = 1;\n\t\tmit->dimensions[0] = mit->iters[0]->dims_m1[0]+1;\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = PyTuple_New(mit->numiter);\n\t\tif (mit->indexobj == NULL) goto fail;\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tPyTuple_SET_ITEM(mit->indexobj, i,\n\t\t\t\t\t PyInt_FromLong(0));\n\t\t}\n\t}\n\n\telse if (PyArray_Check(indexobj) || !PyTuple_Check(indexobj)) {\n\t\tmit->numiter = 1;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tarr = PyArray_FromAny(indexobj, indtype, 0, 0, FORCECAST, NULL);\n\t\tif (arr == NULL) goto fail;\n\t\tmit->iters[0] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\tif (mit->iters[0] == NULL) {Py_DECREF(arr); goto fail;}\n\t\tmit->nd = PyArray_NDIM(arr);\n\t\tmemcpy(mit->dimensions,PyArray_DIMS(arr),mit->nd*sizeof(intp));\n\t\tmit->size = PyArray_SIZE(arr);\n\t\tPy_DECREF(arr);\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = Py_BuildValue(\"(N)\", PyInt_FromLong(0));\n\t}\n\telse { /* must be a tuple */\n\t\tPyObject *obj;\n\t\tPyArrayIterObject *iter;\n\t\tPyObject *new;\n\t\t/* Make a copy of the tuple -- we will be replacing\n\t\t index objects with 0's */\n\t\tn = PyTuple_GET_SIZE(indexobj);\n\t\tnew = PyTuple_New(n);\n\t\tif (new == NULL) goto fail;\n\t\tstarted = 0;\n\t\tnonindex = 0;\n\t\tfor (i=0; iconsec = 0;\n\t\t\t\tmit->iters[(mit->numiter)++] = iter;\n\t\t\t\tPyTuple_SET_ITEM(new,i,\n\t\t\t\t\t\t PyInt_FromLong(0));\n\t\t\t}\n\t\t\telse {\n\t\t\t\tif (started) nonindex = 1;\n\t\t\t\tPy_INCREF(obj);\n\t\t\t\tPyTuple_SET_ITEM(new,i,obj);\n\t\t\t}\n\t\t}\n\t\tPy_DECREF(mit->indexobj);\n\t\tmit->indexobj = new;\n\t\t/* Store the number of iterators actually converted */\n\t\t/* These will be mapped to actual axes at bind time */\n\t\tif (PyArray_Broadcast((PyArrayMultiIterObject *)mit) < 0)\n\t\t\tgoto fail;\n\t}\n\n return (PyObject *)mit;\n\n fail:\n Py_DECREF(mit);\n\treturn NULL;\n}\n\n\nstatic void\narraymapiter_dealloc(PyArrayMapIterObject *mit)\n{\n\tint i;\n\tPy_XDECREF(mit->indexobj);\n Py_XDECREF(mit->ait);\n\tPy_XDECREF(mit->subspace);\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(mit->iters[i]);\n _pya_free(mit);\n}\n\n/* The mapiter object must be created new each time. It does not work\n to bind to a new array, and continue.\n\n This was the orginal intention, but currently that does not work.\n Do not expose the MapIter_Type to Python.\n\n It's not very useful anyway, since mapiter(indexobj); mapiter.bind(a);\n mapiter is equivalent to a[indexobj].flat but the latter gets to use\n slice syntax.\n*/\n\nstatic PyTypeObject PyArrayMapIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.mapiter\",\t\t\t/* tp_name */\n sizeof(PyArrayIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymapiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t\t\t/* tp_as_sequence */\n 0,\t\t\t\t\t/* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n (traverseproc)0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t\t\t /* tp_iter */\n (iternextfunc)0,\t /* tp_iternext */\n 0,\t /* tp_methods */\n 0,\t\t\t\t\t /* tp_members */\n 0,\t\t\t /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n 0,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n\n};\n\n/** END of Subscript Iterator **/\n\n\n/*OBJECT_API\n Get MultiIterator,\n*/\nstatic PyObject *\nPyArray_MultiIterNew(int n, ...)\n{\n va_list va;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *current;\n\tPyObject *arr;\n\n\tint i, err=0;\n\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need between 2 and (%d) \"\t\t\t\\\n\t\t\t \"array objects (inclusive).\", MAX_DIMS);\n\t}\n\n /* fprintf(stderr, \"multi new...\");*/\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tfor (i=0; iiters[i] = NULL;\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\n va_start(va, n);\n\tfor (i=0; iiters[i] = (PyArrayIterObject *)PyArray_IterNew(arr);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t}\n\n\tva_end(va);\n\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\n\tif (kwds != NULL) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"keyword arguments not accepted.\");\n\t\treturn NULL;\n\t}\n\n\tn = PyTuple_Size(args);\n\tif (n < 2 || n > MAX_DIMS) {\n\t\tif (PyErr_Occurred()) return NULL;\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need at least two and fewer than (%d) \"\t\\\n\t\t\t \"array objects.\", MAX_DIMS);\n\t\treturn NULL;\n\t}\n\n\tmulti = _pya_malloc(sizeof(PyArrayMultiIterObject));\n if (multi == NULL) return PyErr_NoMemory();\n\tPyObject_Init((PyObject *)multi, &PyArrayMultiIter_Type);\n\n\tmulti->numiter = n;\n\tmulti->index = 0;\n\tfor (i=0; iiters[i] = NULL;\n\tfor (i=0; iiters[i] =\t\t\t\t\t\\\n\t\t (PyArrayIterObject *)PyArray_IterNew(arr))==NULL)\n\t\t\tgoto fail;\n\t\tPy_DECREF(arr);\n\t}\n\tif (PyArray_Broadcast(multi) < 0) goto fail;\n\tPyArray_MultiIter_RESET(multi);\n\n return (PyObject *)multi;\n\n fail:\n Py_DECREF(multi);\n\treturn NULL;\n}\n\nstatic PyObject *\narraymultiter_next(PyArrayMultiIterObject *multi)\n{\n\tPyObject *ret;\n\tint i, n;\n\n\tn = multi->numiter;\n\tret = PyTuple_New(n);\n\tif (ret == NULL) return NULL;\n\tif (multi->index < multi->size) {\n\t\tfor (i=0; i < n; i++) {\n\t\t\tPyArrayIterObject *it=multi->iters[i];\n\t\t\tPyTuple_SET_ITEM(ret, i,\n\t\t\t\t\t PyArray_ToScalar(it->dataptr, it->ao));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tmulti->index++;\n\t\treturn ret;\n\t}\n return NULL;\n}\n\nstatic void\narraymultiter_dealloc(PyArrayMultiIterObject *multi)\n{\n\tint i;\n\n\tfor (i=0; inumiter; i++)\n\t\tPy_XDECREF(multi->iters[i]);\n\tmulti->ob_type->tp_free((PyObject *)multi);\n}\n\nstatic PyObject *\narraymultiter_size_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->size);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->size);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->size);\n#endif\n}\n\nstatic PyObject *\narraymultiter_index_get(PyArrayMultiIterObject *self)\n{\n#if SIZEOF_INTP <= SIZEOF_LONG\n\treturn PyInt_FromLong((long) self->index);\n#else\n\tif (self->size < MAX_LONG)\n\t\treturn PyInt_FromLong((long) self->index);\n\telse\n\t\treturn PyLong_FromLongLong((longlong) self->index);\n#endif\n}\n\nstatic PyObject *\narraymultiter_shape_get(PyArrayMultiIterObject *self)\n{\n\treturn PyArray_IntTupleFromIntp(self->nd, self->dimensions);\n}\n\nstatic PyObject *\narraymultiter_iters_get(PyArrayMultiIterObject *self)\n{\n\tPyObject *res;\n\tint i, n;\n\tn = self->numiter;\n\tres = PyTuple_New(n);\n\tif (res == NULL) return res;\n\tfor (i=0; iiters[i]);\n\t\tPyTuple_SET_ITEM(res, i, (PyObject *)self->iters[i]);\n\t}\n\treturn res;\n}\n\nstatic PyGetSetDef arraymultiter_getsetlist[] = {\n {\"size\",\n\t (getter)arraymultiter_size_get,\n\t NULL,\n\t \"total size of broadcasted result\"},\n {\"index\",\n\t (getter)arraymultiter_index_get,\n NULL,\n\t \"current index in broadcasted result\"},\n\t{\"shape\",\n\t (getter)arraymultiter_shape_get,\n\t NULL,\n\t \"shape of broadcasted result\"},\n\t{\"iters\",\n\t (getter)arraymultiter_iters_get,\n\t NULL,\n\t \"tuple of individual iterators\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyMemberDef arraymultiter_members[] = {\n\t{\"numiter\", T_INT, offsetof(PyArrayMultiIterObject, numiter),\n\t RO, NULL},\n\t{\"nd\", T_INT, offsetof(PyArrayMultiIterObject, nd), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraymultiter_reset(PyArrayMultiIterObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\n\tPyArray_MultiIter_RESET(self);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyMethodDef arraymultiter_methods[] = {\n\t{\"reset\", (PyCFunction) arraymultiter_reset, METH_VARARGS, NULL},\n\t{NULL, NULL},\n};\n\nstatic PyTypeObject PyArrayMultiIter_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.broadcast\",\t\t\t /* tp_name */\n sizeof(PyArrayMultiIterObject), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraymultiter_dealloc,\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n 0,\t\t\t\t\t/* tp_compare */\n 0,\t\t\t\t\t/* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0, /* tp_as_sequence */\n 0,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n 0,\t\t\t\t\t/* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n (iternextfunc)arraymultiter_next,\t/* tp_iternext */\n arraymultiter_methods,\t /* tp_methods */\n arraymultiter_members,\t\t /* tp_members */\n arraymultiter_getsetlist, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n (initproc)0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraymultiter_new,\t /* tp_new */\n _pya_free,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNewFromType(int type_num)\n{\n\tPyArray_Descr *old;\n\tPyArray_Descr *new;\n\n\told = PyArray_DescrFromType(type_num);\n\tnew = PyArray_DescrNew(old);\n\tPy_DECREF(old);\n\treturn new;\n}\n\n/*** Array Descr Objects for dynamic types **/\n\n/** There are some statically-defined PyArray_Descr objects corresponding\n to the basic built-in types.\n These can and should be DECREF'd and INCREF'd as appropriate, anyway.\n If a mistake is made in reference counting, deallocation on these\n builtins will be attempted leading to problems.\n\n This let's us deal with all PyArray_Descr objects using reference\n counting (regardless of whether they are statically or dynamically\n allocated).\n**/\n\n/* base cannot be NULL */\n/*OBJECT_API*/\nstatic PyArray_Descr *\nPyArray_DescrNew(PyArray_Descr *base)\n{\n\tPyArray_Descr *new;\n\n\tnew = PyObject_New(PyArray_Descr, &PyArrayDescr_Type);\n\tif (new == NULL) return NULL;\n\t/* Don't copy PyObject_HEAD part */\n\tmemcpy((char *)new+sizeof(PyObject),\n\t (char *)base+sizeof(PyObject),\n\t sizeof(PyArray_Descr)-sizeof(PyObject));\n\n\tif (new->fields == Py_None) new->fields = NULL;\n\tPy_XINCREF(new->fields);\n\tif (new->subarray) {\n\t\tnew->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tmemcpy(new->subarray, base->subarray,\n\t\t sizeof(PyArray_ArrayDescr));\n\t\tPy_INCREF(new->subarray->shape);\n\t\tPy_INCREF(new->subarray->base);\n\t}\n\tPy_INCREF(new->typeobj);\n\treturn new;\n}\n\n/* should never be called for builtin-types unless\n there is a reference-count problem\n*/\nstatic void\narraydescr_dealloc(PyArray_Descr *self)\n{\n\tPy_XDECREF(self->typeobj);\n\tPy_XDECREF(self->fields);\n\tif (self->subarray) {\n\t\tPy_DECREF(self->subarray->shape);\n\t\tPy_DECREF(self->subarray->base);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n/* we need to be careful about setting attributes because these\n objects are pointed to by arrays that depend on them for interpreting\n data. Currently no attributes of dtype objects can be set.\n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"type\", T_OBJECT, offsetof(PyArray_Descr, typeobj), RO, NULL},\n\t{\"kind\", T_CHAR, offsetof(PyArray_Descr, kind), RO, NULL},\n\t{\"char\", T_CHAR, offsetof(PyArray_Descr, type), RO, NULL},\n\t{\"num\", T_INT, offsetof(PyArray_Descr, type_num), RO, NULL},\n\t{\"byteorder\", T_CHAR, offsetof(PyArray_Descr, byteorder), RO, NULL},\n\t{\"itemsize\", T_INT, offsetof(PyArray_Descr, elsize), RO, NULL},\n\t{\"alignment\", T_INT, offsetof(PyArray_Descr, alignment), RO, NULL},\n {\"hasobject\", T_UBYTE, offsetof(PyArray_Descr, hasobject), RO, NULL},\n\t{NULL},\n};\n\nstatic PyObject *\narraydescr_subdescr_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn Py_BuildValue(\"OO\", (PyObject *)self->subarray->base,\n\t\t\t self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_typestr_get(PyArray_Descr *self)\n{\n char basic_=self->kind;\n char endian = self->byteorder;\n\tint size=self->elsize;\n\n if (endian == '=') {\n endian = '<';\n if (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n }\n\n\tif (self->type_num == PyArray_UNICODE) {\n\t\tsize >>= 2;\n\t}\n return PyString_FromFormat(\"%c%c%d\", endian, basic_, size);\n}\n\nstatic PyObject *\narraydescr_typename_get(PyArray_Descr *self)\n{\n int len;\n PyTypeObject *typeobj = self->typeobj;\n\tPyObject *res;\n\tstatic int suffix_len=0;\n\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) {\n\t\tres = PyString_FromString(typeobj->tp_name);\n\t}\n\telse {\n\t\tif (suffix_len == 0)\n\t\t\tsuffix_len = strlen(\"scalar\");\n\t\tlen = strlen(typeobj->tp_name) - suffix_len;\n\t\tres = PyString_FromStringAndSize(typeobj->tp_name, len);\n\t}\n\tif (PyTypeNum_ISEXTENDED(self->type_num) && self->elsize != 0) {\n\t\tPyObject *p;\n\t\tp = PyString_FromFormat(\"%d\", self->elsize * 8);\n\t\tPyString_ConcatAndDel(&res, p);\n\t}\n\treturn res;\n}\n\nstatic PyObject *\narraydescr_base_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n\t\tPy_INCREF(self);\n return (PyObject *)self;\n\t}\n Py_INCREF(self->subarray->base);\n return (PyObject *)(self->subarray->base);\n}\n\nstatic PyObject *\narraydescr_shape_get(PyArray_Descr *self)\n{\n\tif (self->subarray == NULL) {\n return Py_BuildValue(\"(N)\", PyInt_FromLong(1));\n\t}\n Py_INCREF(self->subarray->shape);\n return (PyObject *)(self->subarray->shape);\n}\n\nstatic PyObject *\narraydescr_protocol_descr_get(PyArray_Descr *self)\n{\n\tPyObject *dobj, *res;\n\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\t/* get default */\n\t\tdobj = PyTuple_New(2);\n\t\tif (dobj == NULL) return NULL;\n\t\tPyTuple_SET_ITEM(dobj, 0, PyString_FromString(\"\"));\n\t\tPyTuple_SET_ITEM(dobj, 1, \\\n\t\t\t\t arraydescr_protocol_typestr_get(self));\n\t\tres = PyList_New(1);\n\t\tif (res == NULL) {Py_DECREF(dobj); return NULL;}\n\t\tPyList_SET_ITEM(res, 0, dobj);\n\t\treturn res;\n\t}\n\n return PyObject_CallMethod(_numpy_internal, \"_array_descr\",\n\t\t\t\t \"O\", self);\n}\n\n/* returns 1 for a builtin type\n and 2 for a user-defined data-type descriptor\n return 0 if neither (i.e. it's a copy of one)\n*/\nstatic PyObject *\narraydescr_isbuiltin_get(PyArray_Descr *self)\n{\n\tlong val;\n\tval = 0;\n\tif (self->fields == Py_None) val = 1;\n\tif (PyTypeNum_ISUSERDEF(self->type_num)) val = 2;\n\treturn PyInt_FromLong(val);\n}\n\nstatic PyObject *\narraydescr_isnative_get(PyArray_Descr *self)\n{\n\tPyObject *ret;\n\n\tret = (PyArray_ISNBO(self->byteorder) ? Py_True : Py_False);\n\tPy_INCREF(ret);\n\treturn ret;\n}\n\nstatic PyObject *\narraydescr_fields_get(PyArray_Descr *self)\n{\n\tif (self->fields == NULL || self->fields == Py_None) {\n\t\tPy_INCREF(Py_None);\n\t\treturn Py_None;\n\t}\n\treturn PyDictProxy_New(self->fields);\n}\n\nstatic PyGetSetDef arraydescr_getsets[] = {\n\t{\"subdtype\",\n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"descr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"str\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\n {\"name\",\n (getter)arraydescr_typename_get,\n NULL,\n \"The name of the true data-type\"},\n\t{\"base\",\n\t (getter)arraydescr_base_get,\n\t NULL,\n\t \"The base data-type or self if no subdtype\"},\n {\"shape\",\n (getter)arraydescr_shape_get,\n NULL,\n \"The shape of the subdtype or (1,)\"},\n\t{\"isbuiltin\",\n\t (getter)arraydescr_isbuiltin_get,\n\t NULL,\n\t \"Is this a buillt-in data-type descriptor?\"},\n\t{\"isnative\",\n\t (getter)arraydescr_isnative_get,\n\t NULL,\n\t \"Is the byte-order of this descriptor native?\"},\n\t{\"fields\",\n\t (getter)arraydescr_fields_get,\n\t NULL,\n\t NULL},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyArray_Descr *_convert_from_list(PyObject *obj, int align, int try_descr);\nstatic PyArray_Descr *_convert_from_dict(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_commastring(PyObject *obj, int align);\nstatic PyArray_Descr *_convert_from_array_descr(PyObject *obj);\n\nstatic PyObject *\narraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\tPyObject *odescr;\n\tPyArray_Descr *descr, *conv;\n\tint align=0;\n\tBool copy=FALSE;\n\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",\n\t\t\t\t\t kwlist, &odescr, &align,\n\t\t\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\n\tif (align) {\n\t\tconv = NULL;\n\t\tif PyDict_Check(odescr)\n\t\t\tconv = _convert_from_dict(odescr, 1);\n\t\telse if PyList_Check(odescr)\n\t\t\tconv = _convert_from_list(odescr, 1, 0);\n\t\telse if PyString_Check(odescr)\n\t\t\tconv = _convert_from_commastring(odescr, 1);\n\t\telse {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"align can only be non-zero for\" \\\n\t\t\t\t\t\"dictionary, list, and string objects.\");\n\t\t}\n\t\tif (conv) return (PyObject *)conv;\n\t\tif (!PyErr_Occurred()) {\n\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\"data-type-descriptor not understood\");\n\t\t}\n\t\treturn NULL;\n\t}\n\n\tif PyList_Check(odescr) {\n\t\tconv = _convert_from_array_descr(odescr);\n\t\tif (!conv) {\n\t\t\tPyErr_Clear();\n\t\t\tconv = _convert_from_list(odescr, 0, 0);\n\t\t}\n\t\treturn (PyObject *)conv;\n\t}\n\n\tif (!PyArray_DescrConverter(odescr, &conv))\n\t\treturn NULL;\n\t/* Get a new copy of it unless it's already a copy */\n\tif (copy && conv->fields == Py_None) {\n\t\tdescr = PyArray_DescrNew(conv);\n\t\tPy_DECREF(conv);\n\t\tconv = descr;\n\t}\n\treturn (PyObject *)conv;\n}\n\nstatic char doc_arraydescr_reduce[] = \"self.__reduce__() for pickling.\";\n\n/* return a tuple of (callable object, args, state) */\nstatic PyObject *\narraydescr_reduce(PyArray_Descr *self, PyObject *args)\n{\n\tPyObject *ret, *mod, *obj;\n\tPyObject *state;\n\tchar endian;\n\tint elsize, alignment;\n\n\tret = PyTuple_New(3);\n\tif (ret == NULL) return NULL;\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) {Py_DECREF(ret); return NULL;}\n\tobj = PyObject_GetAttrString(mod, \"dtype\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) {Py_DECREF(ret); return NULL;}\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tif (PyTypeNum_ISUSERDEF(self->type_num) ||\t\t\\\n\t ((self->type_num == PyArray_VOID &&\t\t\t\\\n\t self->typeobj != &PyVoidArrType_Type))) {\n\t\tobj = (PyObject *)self->typeobj;\n\t\tPy_INCREF(obj);\n\t}\n\telse {\n\t\telsize = self->elsize;\n\t\tif (self->type_num == PyArray_UNICODE) {\n\t\t\telsize >>= 2;\n\t\t}\n\t\tobj = PyString_FromFormat(\"%c%d\",self->kind, elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\n\t/* Now return the state which is at least\n\t byteorder, subarray, and fields */\n\tendian = self->byteorder;\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\tstate = PyTuple_New(5);\n\tPyTuple_SET_ITEM(state, 0, PyString_FromFormat(\"%c\", endian));\n\tPyTuple_SET_ITEM(state, 1, arraydescr_subdescr_get(self));\n\tif (self->fields && self->fields != Py_None) {\n\t\tPy_INCREF(self->fields);\n\t\tPyTuple_SET_ITEM(state, 2, self->fields);\n\t}\n\telse {\n\t\tPyTuple_SET_ITEM(state, 2, Py_None);\n\t\tPy_INCREF(Py_None);\n\t}\n\n\t/* for extended types it also includes elsize and alignment */\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\telsize = self->elsize;\n\t\talignment = self->alignment;\n\t}\n\telse {elsize = -1; alignment = -1;}\n\n\tPyTuple_SET_ITEM(state, 3, PyInt_FromLong(elsize));\n\tPyTuple_SET_ITEM(state, 4, PyInt_FromLong(alignment));\n\n\tPyTuple_SET_ITEM(ret, 2, state);\n\treturn ret;\n}\n\n/* state is at least byteorder, subarray, and fields but could include elsize\n and alignment for EXTENDED arrays\n*/\nstatic char doc_arraydescr_setstate[] = \"self.__setstate__() for pickling.\";\n\nstatic PyObject *\narraydescr_setstate(PyArray_Descr *self, PyObject *args)\n{\n\tint elsize = -1, alignment = -1;\n\tchar endian;\n\tPyObject *subarray, *fields;\n\n\tif (self->fields == Py_None) {Py_INCREF(Py_None); return Py_None;}\n\n\tif (!PyArg_ParseTuple(args, \"(cOOii)\", &endian, &subarray, &fields,\n\t\t\t &elsize, &alignment)) return NULL;\n\n\tif (endian != '|' && \n\t PyArray_IsNativeByteOrder(endian)) endian = '=';\n\n\tself->byteorder = endian;\n\tif (self->subarray) {\n\t\tPy_XDECREF(self->subarray->base);\n\t\tPy_XDECREF(self->subarray->shape);\n\t\t_pya_free(self->subarray);\n\t}\n\tself->subarray = NULL;\n\n\tif (subarray != Py_None) {\n\t\tself->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tself->subarray->base = (PyArray_Descr *)PyTuple_GET_ITEM(subarray, 0);\n\t\tPy_INCREF(self->subarray->base);\n\t\tself->subarray->shape = PyTuple_GET_ITEM(subarray, 1);\n\t\tPy_INCREF(self->subarray->shape);\n\t}\n\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* returns a copy of the PyArray_Descr structure with the byteorder\n altered:\n no arguments: The byteorder is swapped (in all subfields as well)\n single argument: The byteorder is forced to the given state\n (in all subfields as well)\n\n Valid states: ('big', '>') or ('little' or '<')\n\t\t ('native', or '=')\n\n\t\t If a descr structure with | is encountered it's own\n\t\t byte-order is not changed but any fields are:\n*/\n\n/*OBJECT_API\n Deep bytorder change of a data-type descriptor\n *** Leaves reference count of self unchanged --- does not DECREF self ***\n*/\nstatic PyArray_Descr *\nPyArray_DescrNewByteorder(PyArray_Descr *self, char newendian)\n{\n\tPyArray_Descr *new;\n\tchar endian;\n\n\tnew = PyArray_DescrNew(self);\n\tendian = new->byteorder;\n\tif (endian != PyArray_IGNORE) {\n\t\tif (newendian == PyArray_SWAP) { /* swap byteorder */\n\t\t\tif PyArray_ISNBO(endian) endian = PyArray_OPPBYTE;\n\t\t\telse endian = PyArray_NATBYTE;\n\t\t\tnew->byteorder = endian;\n\t\t}\n\t\telse if (newendian != PyArray_IGNORE) {\n\t\t\tnew->byteorder = newendian;\n\t\t}\n\t}\n\tif (new->fields) {\n\t\tPyObject *newfields;\n\t\tPyObject *key, *value;\n\t\tPyObject *newvalue;\n\t\tPyObject *old;\n\t\tPyArray_Descr *newdescr;\n\t\tint pos = 0, len, i;\n\t\tnewfields = PyDict_New();\n\t\t/* make new dictionary with replaced */\n\t\t/* PyArray_Descr Objects */\n\t\twhile(PyDict_Next(self->fields, &pos, &key, &value)) {\n\t\t\tif (PyInt_Check(key) &&\t\t\t\\\n\t\t\t PyInt_AsLong(key) == -1) {\n\t\t\t\tPyDict_SetItem(newfields, key, value);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!PyString_Check(key) ||\t \\\n\t\t\t !PyTuple_Check(value) ||\t\t\t\\\n\t\t\t ((len=PyTuple_GET_SIZE(value)) < 2))\n\t\t\t\tcontinue;\n\n\t\t\told = PyTuple_GET_ITEM(value, 0);\n\t\t\tif (!PyArray_DescrCheck(old)) continue;\n\t\t\tnewdescr = PyArray_DescrNewByteorder\t\t\\\n\t\t\t\t((PyArray_Descr *)old, newendian);\n\t\t\tif (newdescr == NULL) {\n\t\t\t\tPy_DECREF(newfields); Py_DECREF(new);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tnewvalue = PyTuple_New(len);\n\t\t\tPyTuple_SET_ITEM(newvalue, 0,\t\t\\\n\t\t\t\t\t (PyObject *)newdescr);\n\t\t\tfor(i=1; ifields);\n\t\tnew->fields = newfields;\n\t}\n\tif (new->subarray) {\n\t\tPy_DECREF(new->subarray->base);\n\t\tnew->subarray->base = PyArray_DescrNewByteorder \\\n\t\t\t(self->subarray->base, newendian);\n\t}\n\treturn new;\n}\n\n\nstatic char doc_arraydescr_newbyteorder[] = \"self.newbyteorder()\"\n\t\" returns a copy of the dtype object\\n\"\n\t\" with altered byteorders. If is not given all byteorders\\n\"\n\t\" are swapped. Otherwise endian can be '>', '<', or '=' to force\\n\"\n\t\" a byteorder. Descriptors in all fields are also updated in the\\n\"\n\t\" new dtype object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args)\n{\n\tchar endian=PyArray_SWAP;\n\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\n\treturn (PyObject *)PyArray_DescrNewByteorder(self, endian);\n}\n\nstatic PyMethodDef arraydescr_methods[] = {\n /* for pickling */\n {\"__reduce__\", (PyCFunction)arraydescr_reduce, METH_VARARGS,\n\t doc_arraydescr_reduce},\n\t{\"__setstate__\", (PyCFunction)arraydescr_setstate, METH_VARARGS,\n\t doc_arraydescr_setstate},\n\n\t{\"newbyteorder\", (PyCFunction)arraydescr_newbyteorder, METH_VARARGS,\n\t doc_arraydescr_newbyteorder},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\nstatic PyObject *\narraydescr_str(PyArray_Descr *self)\n{\n\tPyObject *sub;\n\n\tif (self->fields && self->fields != Py_None) {\n\t\tPyObject *lst;\n\t\tlst = arraydescr_protocol_descr_get(self);\n\t\tif (!lst) {\n\t\t\tsub = PyString_FromString(\"\");\n\t\t\tPyErr_Clear();\n\t\t}\n\t\telse sub = PyObject_Str(lst);\n\t\tPy_XDECREF(lst);\n\t\tif (self->type_num != PyArray_VOID) {\n\t\t\tPyObject *p;\n\t\t\tPyObject *t=PyString_FromString(\"'\");\n\t\t\tp = arraydescr_protocol_typestr_get(self);\n\t\t\tPyString_Concat(&p, t);\n\t\t\tPyString_ConcatAndDel(&t, p);\n\t\t\tp = PyString_FromString(\"(\");\n\t\t\tPyString_ConcatAndDel(&p, t);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\", \"));\n\t\t\tPyString_ConcatAndDel(&p, sub);\n\t\t\tPyString_ConcatAndDel(&p, PyString_FromString(\")\"));\n\t\t\tsub = p;\n\t\t}\n\t}\n\telse if (self->subarray) {\n\t\tPyObject *p;\n\t\tPyObject *t = PyString_FromString(\"(\");\n\t\tp = arraydescr_str(self->subarray->base);\n\t\tPyString_ConcatAndDel(&t, p);\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\",\"));\n\t\tPyString_ConcatAndDel(&t, PyObject_Str(self->subarray->shape));\n\t\tPyString_ConcatAndDel(&t, PyString_FromString(\")\"));\n\t\tsub = t;\n\t}\n\telse {\n\t\tPyObject *t=PyString_FromString(\"'\");\n\t\tsub = arraydescr_protocol_typestr_get(self);\n\t\tPyString_Concat(&sub, t);\n\t\tPyString_ConcatAndDel(&t, sub);\n\t\tsub = t;\n\t}\n\treturn sub;\n}\n\nstatic PyObject *\narraydescr_repr(PyArray_Descr *self)\n{\n\tPyObject *sub, *s;\n\ts = PyString_FromString(\"dtype(\");\n sub = arraydescr_str(self);\n\tPyString_ConcatAndDel(&s, sub);\n\tsub = PyString_FromString(\")\");\n\tPyString_ConcatAndDel(&s, sub);\n\treturn s;\n}\n\nstatic int\narraydescr_compare(PyArray_Descr *self, PyObject *other)\n{\n\tif (!PyArray_DescrCheck(other)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"not a dtype object.\");\n\t\treturn -1;\n\t}\n\tif (PyArray_EquivTypes(self, (PyArray_Descr *)other)) return 0;\n\tif (PyArray_CanCastTo(self, (PyArray_Descr *)other)) return -1;\n\treturn 1;\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic _int_or_ssize_t\ndescr_length(PyArray_Descr *self)\n{\n\n\tif (self->fields && self->fields != Py_None)\n\t\t/* Remove the last entry (root) */\n\t\treturn PyDict_Size(self->fields) - 1;\n\telse return 0;\n}\n\nstatic PyObject *\ndescr_subscript(PyArray_Descr *self, PyObject *op)\n{\n\n\tif (self->fields) {\n\t\tif (PyString_Check(op) || PyUnicode_Check(op)) {\n\t\t\tPyObject *obj;\n\t\t\tobj = PyDict_GetItem(self->fields, op);\n\t\t\tif (obj != NULL) {\n\t\t\t\tPyObject *descr;\n\t\t\t\tdescr = PyTuple_GET_ITEM(obj, 0);\n\t\t\t\tPy_INCREF(descr);\n\t\t\t\treturn descr;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t\t\t \"field named \\'%s\\' not found.\",\n\t\t\t\t\t PyString_AsString(op));\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t PyErr_SetString(PyExc_ValueError,\n\t\t\t\t \"only strings or unicode values allowed \" \\\n\t\t\t\t \"for getting fields.\");\n\t\t}\n\t}\n\telse {\n\t\tPyErr_Format(PyExc_KeyError,\n\t\t\t \"there are no fields in dtype %s.\",\n\t\t\t PyString_AsString(arraydescr_str(self)));\n\t}\n\treturn NULL;\n}\n\nstatic PyMappingMethods descr_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)descr_length,\t\t /*mp_length*/\n#else\n (inquiry)descr_length,\t\t /*mp_length*/\n#endif\n (binaryfunc)descr_subscript,\t /*mp_subscript*/\n (objobjargproc)NULL,\t /*mp_ass_subscript*/\n};\n\n/****************** End of Mapping Protocol ******************************/\n\n\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtype\",\t\t\t /* tp_name */\n sizeof(PyArray_Descr), /* tp_basicsize */\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arraydescr_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t(cmpfunc)arraydescr_compare,\t\t/* tp_compare */\n (reprfunc)arraydescr_repr,\t /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &descr_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arraydescr_str, /* tp_str */\n 0,\t\t/* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t/* tp_iternext */\n arraydescr_methods,\t\t /* tp_methods */\n arraydescr_members,\t /* tp_members */\n arraydescr_getsets, /* tp_getset */\n 0,\t\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0,\t\t /* tp_init */\n 0,\t /* tp_alloc */\n arraydescr_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n\n\n/** Array Flags Object **/\n\ntypedef struct PyArrayFlagsObject {\n PyObject_HEAD\n PyObject *arr;\n int flags;\n} PyArrayFlagsObject;\n\n/*OBJECT_API\n Get New ArrayFlagsObject\n*/\nstatic PyObject *\nPyArray_NewFlagsObject(PyObject *obj)\n{\n PyObject *flagobj;\n int flags;\n if (obj == NULL) {\n flags = CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n }\n else {\n flags = PyArray_FLAGS(obj);\n }\n flagobj = PyArrayFlags_Type.tp_alloc(&PyArrayFlags_Type, 0);\n if (flagobj == NULL) return NULL;\n Py_XINCREF(obj);\n ((PyArrayFlagsObject *)flagobj)->arr = obj;\n ((PyArrayFlagsObject *)flagobj)->flags = flags;\n\n return flagobj;\n}\n\nstatic void\narrayflags_dealloc(PyArrayFlagsObject *self)\n{\n\tPy_XDECREF(self->arr);\n\tself->ob_type->tp_free((PyObject *)self);\n}\n\n\n#define _define_get(UPPER, lower) \\\nstatic PyObject * \\\narrayflags_ ## lower ## _get(PyArrayFlagsObject *self) \\\n{ \\\n PyObject *item; \\\n item = ((self->flags & (UPPER)) == (UPPER)) ? Py_True : Py_False; \\\n Py_INCREF(item); \\\n return item; \\\n}\n\n_define_get(CONTIGUOUS, contiguous)\n_define_get(FORTRAN, fortran)\n_define_get(UPDATEIFCOPY, updateifcopy)\n_define_get(OWNDATA, owndata)\n_define_get(ALIGNED, aligned)\n_define_get(WRITEABLE, writeable)\n\n_define_get(ALIGNED|WRITEABLE, behaved)\n_define_get(ALIGNED|WRITEABLE|CONTIGUOUS, carray)\n\nstatic PyObject *\narrayflags_forc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) ||\n ((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_fnc_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & FORTRAN) == FORTRAN) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_farray_get(PyArrayFlagsObject *self)\n{\n PyObject *item;\n \n if (((self->flags & (ALIGNED|WRITEABLE|FORTRAN)) == \\\n (ALIGNED|WRITEABLE|FORTRAN)) &&\n !((self->flags & CONTIGUOUS) == CONTIGUOUS))\n item = Py_True;\n else\n item = Py_False;\n \n Py_INCREF(item);\n return item;\n}\n\nstatic PyObject *\narrayflags_num_get(PyArrayFlagsObject *self)\n{\n return PyInt_FromLong(self->flags);\n}\n\n/* relies on setflags order being write, align, uic */\nstatic int\narrayflags_updateifcopy_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False));\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_aligned_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", Py_None, \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\nstatic int\narrayflags_writeable_set(PyArrayFlagsObject *self, PyObject *obj)\n{\n PyObject *res;\n if (self->arr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"Cannot set flags on array scalars.\");\n return -1;\n }\n res = PyObject_CallMethod(self->arr, \"setflags\", \"OOO\", \n (PyObject_IsTrue(obj) ? Py_True : Py_False),\n Py_None, Py_None);\n if (res == NULL) return -1;\n Py_DECREF(res);\n return 0;\n}\n\n\nstatic PyGetSetDef arrayflags_getsets[] = {\n\t{\"contiguous\",\n\t (getter)arrayflags_contiguous_get,\n\t NULL,\n\t \"\"},\n {\"fortran\",\n (getter)arrayflags_fortran_get,\n NULL,\n \"\"},\n {\"updateifcopy\",\n (getter)arrayflags_updateifcopy_get,\n (setter)arrayflags_updateifcopy_set,\n \"\"},\n {\"owndata\",\n (getter)arrayflags_owndata_get,\n NULL,\n \"\"},\n {\"aligned\",\n (getter)arrayflags_aligned_get,\n (setter)arrayflags_aligned_set,\n \"\"},\n {\"writeable\",\n (getter)arrayflags_writeable_get,\n (setter)arrayflags_writeable_set,\n \"\"},\n {\"fnc\",\n (getter)arrayflags_fnc_get,\n NULL,\n \"\"},\n {\"forc\",\n (getter)arrayflags_forc_get,\n NULL,\n \"\"},\n {\"behaved\",\n (getter)arrayflags_behaved_get,\n NULL,\n \"\"},\n {\"carray\",\n (getter)arrayflags_carray_get,\n NULL,\n \"\"},\n {\"farray\",\n (getter)arrayflags_farray_get,\n NULL,\n \"\"},\n {\"num\",\n (getter)arrayflags_num_get,\n NULL,\n \"\"},\n\t{NULL, NULL, NULL, NULL},\n};\n\nstatic PyObject *\narrayflags_getitem(PyArrayFlagsObject *self, PyObject *ind)\n{\n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n\tswitch(n) {\n\tcase 1:\n\t\tswitch(key[0]) {\n\t\tcase 'C':\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tcase 'F':\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tcase 'W':\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tcase 'B':\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tcase 'O':\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tcase 'A':\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tcase 'U':\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tdefault:\n\t\t\tgoto fail;\n\t\t}\n\t\tbreak;\n\tcase 2:\n\t\tif (strncmp(key, \"CA\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FA\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 3:\n\t\tif (strncmp(key, \"FNC\", n)==0)\n\t\t\treturn arrayflags_fnc_get(self);\n\t\tbreak;\n\tcase 4:\n\t\tif (strncmp(key, \"FORC\", n)==0)\n\t\t\treturn arrayflags_forc_get(self);\n\t\tbreak;\n\tcase 6:\n\t\tif (strncmp(key, \"CARRAY\", n)==0)\n\t\t\treturn arrayflags_carray_get(self);\n\t\tif (strncmp(key, \"FARRAY\", n)==0)\n\t\t\treturn arrayflags_farray_get(self);\n\t\tbreak;\n\tcase 7:\n\t\tif (strncmp(key,\"FORTRAN\",n)==0)\n\t\t\treturn arrayflags_fortran_get(self);\n\t\tif (strncmp(key,\"BEHAVED\",n)==0)\n\t\t\treturn arrayflags_behaved_get(self);\n\t\tif (strncmp(key,\"OWNDATA\",n)==0)\n\t\t\treturn arrayflags_owndata_get(self);\n\t\tif (strncmp(key,\"ALIGNED\",n)==0)\n\t\t\treturn arrayflags_aligned_get(self);\n\t\tbreak;\n\tcase 9:\t\n\t\tif (strncmp(key,\"WRITEABLE\",n)==0)\n\t\t\treturn arrayflags_writeable_get(self);\n\t\tbreak;\n\tcase 10:\n\t\tif (strncmp(key,\"CONTIGUOUS\",n)==0)\n\t\t\treturn arrayflags_contiguous_get(self);\n\t\tbreak;\n\tcase 12:\n\t\tif (strncmp(key, \"UPDATEIFCOPY\", n)==0)\n\t\t\treturn arrayflags_updateifcopy_get(self);\n\t\tbreak;\n\t}\n\n fail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return NULL;\n}\n\nstatic int\narrayflags_setitem(PyArrayFlagsObject *self, PyObject *ind, PyObject *item)\n{ \n char *key;\n int n;\n if (!PyString_Check(ind)) goto fail;\n key = PyString_AS_STRING(ind);\n n = PyString_GET_SIZE(ind);\n if (((n==9) && (strncmp(key, \"WRITEABLE\", n)==0)) ||\n\t ((n==1) && (strncmp(key, \"W\", n)==0)))\n return arrayflags_writeable_set(self, item);\n else if (((n==7) && (strncmp(key, \"ALIGNED\", n)==0)) || \n ((n==1) && (strncmp(key, \"A\", n)==0)))\n return arrayflags_aligned_set(self, item);\n else if (((n==12) && (strncmp(key, \"UPDATEIFCOPY\", n)==0)) ||\n ((n==1) && (strncmp(key, \"U\", n)==0)))\n return arrayflags_updateifcopy_set(self, item); \n\nfail:\n PyErr_SetString(PyExc_KeyError, \"Unknown flag\");\n return -1;\n}\n\nstatic char *\n_torf_(int flags, int val)\n{\n if ((flags & val) == val) return \"True\";\n else return \"False\"; \n}\n\nstatic PyObject *\narrayflags_print(PyArrayFlagsObject *self)\n{\n int fl = self->flags;\n \n return PyString_FromFormat(\" %s : %s\\n %s : %s\\n %s : %s\\n\"\\\n \" %s : %s\\n %s : %s\\n %s : %s\",\n \"CONTIGUOUS\", _torf_(fl, CONTIGUOUS),\n \"FORTRAN\", _torf_(fl, FORTRAN),\n \"OWNDATA\", _torf_(fl, OWNDATA),\n \"WRITEABLE\", _torf_(fl, WRITEABLE),\n \"ALIGNED\", _torf_(fl, ALIGNED),\n \"UPDATEIFCOPY\", _torf_(fl, UPDATEIFCOPY));\n}\n\n\nstatic PyMappingMethods arrayflags_as_mapping = {\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)NULL, \t\t /*mp_length*/\n#else\n (inquiry)NULL, \t\t /*mp_length*/\n#endif\n (binaryfunc)arrayflags_getitem,\t /*mp_subscript*/\n (objobjargproc)arrayflags_setitem, /*mp_ass_subscript*/\n};\n\n\nstatic PyObject *\narrayflags_new(PyTypeObject *self, PyObject *args, PyObject *kwds)\n{\n PyObject *arg=NULL;\n if (!PyArg_UnpackTuple(args, \"flagsobj\", 0, 1, &arg))\n return NULL;\n\n if ((arg != NULL) && PyArray_Check(arg)) {\n return PyArray_NewFlagsObject(arg);\n }\n else {\n return PyArray_NewFlagsObject(NULL);\n }\n}\n\nstatic PyTypeObject PyArrayFlags_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\n \"numpy.flagsobj\",\n sizeof(PyArrayFlagsObject),\n 0,\t\t\t\t\t /* tp_itemsize */\n /* methods */\n (destructor)arrayflags_dealloc,\t\t/* tp_dealloc */\n 0,\t\t\t\t\t/* tp_print */\n 0,\t\t\t\t\t/* tp_getattr */\n 0,\t\t\t\t\t/* tp_setattr */\n\t0,\t\t /* tp_compare */\n (reprfunc)arrayflags_print, /* tp_repr */\n 0,\t\t\t\t\t/* tp_as_number */\n 0,\t\t\t /* tp_as_sequence */\n &arrayflags_as_mapping,\t /* tp_as_mapping */\n 0,\t\t\t\t\t/* tp_hash */\n 0,\t\t\t\t\t/* tp_call */\n (reprfunc)arrayflags_print, /* tp_str */\n 0,\t \t /* tp_getattro */\n 0,\t\t\t\t\t/* tp_setattro */\n 0,\t\t\t\t\t/* tp_as_buffer */\n Py_TPFLAGS_DEFAULT, /* tp_flags */\n 0,\t\t\t\t\t/* tp_doc */\n 0,\t /* tp_traverse */\n 0,\t\t\t\t\t/* tp_clear */\n 0,\t\t\t\t\t/* tp_richcompare */\n 0,\t\t\t\t\t/* tp_weaklistoffset */\n 0,\t /* tp_iter */\n 0,\t\t /* tp_iternext */\n 0,\t \t /* tp_methods */\n 0,\t /* tp_members */\n arrayflags_getsets, /* tp_getset */\n 0,\t\t\t\t /* tp_base */\n 0,\t\t\t\t\t /* tp_dict */\n 0,\t\t\t\t\t /* tp_descr_get */\n 0,\t\t\t\t\t /* tp_descr_set */\n 0,\t\t\t\t\t /* tp_dictoffset */\n 0, \t /* tp_init */\n 0,\t /* tp_alloc */\n arrayflags_new,\t /* tp_new */\n 0,\t /* tp_free */\n 0,\t\t\t\t\t /* tp_is_gc */\n 0,\t\t\t\t\t /* tp_bases */\n 0,\t\t\t\t\t /* tp_mro */\n 0,\t\t\t\t\t /* tp_cache */\n 0,\t\t\t\t\t /* tp_subclasses */\n 0\t\t\t\t\t /* tp_weaklist */\n};\n", + "methods": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 76, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 65, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 99, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 134, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 207, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 241, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 291, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 319, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 344, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 387, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 427, + "end_line": 509, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 516, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 593, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Size", + "long_name": "PyArray_Size( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 33, + "parameters": [ + "op" + ], + "start_line": 614, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "_strided_byte_copy", + "long_name": "_strided_byte_copy( char * dst , intp outstrides , char * src , intp instrides , intp N , int elsize)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 9, + "token_count": 207, + "parameters": [ + "dst", + "outstrides", + "src", + "instrides", + "N", + "elsize" + ], + "start_line": 625, + "end_line": 667, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "_unaligned_strided_byte_copy", + "long_name": "_unaligned_strided_byte_copy( char * dst , intp outstrides , char * src , intp instrides , intp N , int elsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 92, + "parameters": [ + "dst", + "outstrides", + "src", + "instrides", + "N", + "elsize" + ], + "start_line": 671, + "end_line": 701, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 119, + "complexity": 27, + "token_count": 737, + "parameters": [ + "dest", + "src" + ], + "start_line": 718, + "end_line": 853, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyObject", + "long_name": "PyArray_CopyObject( PyArrayObject * dest , PyObject * src_object)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 857, + "end_line": 871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDimsAndDataAndDescr", + "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 137, + "parameters": [ + "nd", + "d", + "descr", + "data" + ], + "start_line": 884, + "end_line": 910, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDims", + "long_name": "PyArray_FromDims( int nd , int * d , int type)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "nd", + "d", + "type" + ], + "start_line": 916, + "end_line": 930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewCopy", + "long_name": "PyArray_NewCopy( PyArrayObject * m1 , PyArray_ORDER fortran)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 939, + "end_line": 960, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 118, + "complexity": 24, + "token_count": 712, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 969, + "end_line": 1103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Return", + "long_name": "PyArray_Return( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 91, + "parameters": [ + "mp" + ], + "start_line": 1123, + "end_line": 1145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDataType", + "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 9, + "token_count": 229, + "parameters": [ + "type" + ], + "start_line": 1159, + "end_line": 1199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDescrForType", + "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 214, + "parameters": [ + "typenum", + "descr" + ], + "start_line": 1214, + "end_line": 1255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToFile", + "long_name": "PyArray_ToFile( PyArrayObject * self , FILE * fp , char * sep , char * format)", + "filename": "arrayobject.c", + "nloc": 96, + "complexity": 19, + "token_count": 624, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1262, + "end_line": 1360, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToList", + "long_name": "PyArray_ToList( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self" + ], + "start_line": 1366, + "end_line": 1395, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToString", + "long_name": "PyArray_ToString( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 170, + "parameters": [ + "self" + ], + "start_line": 1398, + "end_line": 1434, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_dealloc", + "long_name": "array_dealloc( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 1443, + "end_line": 1480, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "array_length", + "long_name": "array_length( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 1487, + "end_line": 1495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_big_item", + "long_name": "array_big_item( PyArrayObject * self , intp i)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 4, + "token_count": 151, + "parameters": [ + "self", + "i" + ], + "start_line": 1498, + "end_line": 1523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , _int_or_ssize_t i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 98, + "parameters": [ + "self", + "i" + ], + "start_line": 1527, + "end_line": 1541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_ass_big_item", + "long_name": "array_ass_big_item( PyArrayObject * self , intp i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1544, + "end_line": 1579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , _int_or_ssize_t i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1592, + "end_line": 1595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "slice_coerce_index", + "long_name": "slice_coerce_index( PyObject * o , intp * v)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "o", + "v" + ], + "start_line": 1601, + "end_line": 1609, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "slice_GetIndices", + "long_name": "slice_GetIndices( PySliceObject * r , intp length , intp * start , intp * stop , intp * step , intp * slicelength)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 24, + "token_count": 376, + "parameters": [ + "r", + "length", + "start", + "stop", + "step", + "slicelength" + ], + "start_line": 1615, + "end_line": 1665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "parse_subindex", + "long_name": "parse_subindex( PyObject * op , intp * step_size , intp * n_steps , intp max)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "step_size", + "n_steps", + "max" + ], + "start_line": 1672, + "end_line": 1717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "parse_index", + "long_name": "parse_index( PyArrayObject * self , PyObject * op , intp * dimensions , intp * strides , intp * offset_ptr)", + "filename": "arrayobject.c", + "nloc": 88, + "complexity": 20, + "token_count": 539, + "parameters": [ + "self", + "op", + "dimensions", + "strides", + "offset_ptr" + ], + "start_line": 1721, + "end_line": 1815, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "_swap_axes", + "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 300, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1818, + "end_line": 1872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 254, + "parameters": [ + "mit" + ], + "start_line": 1884, + "end_line": 1937, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetMap", + "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 389, + "parameters": [ + "mit", + "op" + ], + "start_line": 1940, + "end_line": 2002, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "count_new_axes_0d", + "long_name": "count_new_axes_0d( PyObject * tuple)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 7, + "token_count": 124, + "parameters": [ + "tuple" + ], + "start_line": 2005, + "end_line": 2032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "add_new_axes_0d", + "long_name": "add_new_axes_0d( PyArrayObject * arr , int newaxis_count)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 121, + "parameters": [ + "arr", + "newaxis_count" + ], + "start_line": 2035, + "end_line": 2054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 2066, + "end_line": 2128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 107, + "complexity": 28, + "token_count": 674, + "parameters": [ + "self", + "op" + ], + "start_line": 2152, + "end_line": 2277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2292, + "end_line": 2397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 16, + "token_count": 281, + "parameters": [ + "self", + "op" + ], + "start_line": 2406, + "end_line": 2460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , _int_or_ssize_t * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2483, + "end_line": 2495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2498, + "end_line": 2513, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2517, + "end_line": 2526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , _int_or_ssize_t segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2529, + "end_line": 2540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 1, + "token_count": 182, + "parameters": [ + "dict" + ], + "start_line": 2618, + "end_line": 2655, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 2, + "token_count": 203, + "parameters": [], + "start_line": 2665, + "end_line": 2708, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2711, + "end_line": 2734, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericAccumulateFunction", + "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2738, + "end_line": 2761, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericBinaryFunction", + "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 44, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2765, + "end_line": 2772, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericUnaryFunction", + "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 38, + "parameters": [ + "m1", + "op" + ], + "start_line": 2775, + "end_line": 2782, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceBinaryFunction", + "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 46, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2785, + "end_line": 2793, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceUnaryFunction", + "long_name": "PyArray_GenericInplaceUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 40, + "parameters": [ + "m1", + "op" + ], + "start_line": 2796, + "end_line": 2803, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2806, + "end_line": 2809, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_subtract", + "long_name": "array_subtract( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2812, + "end_line": 2815, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_multiply", + "long_name": "array_multiply( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2818, + "end_line": 2821, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_divide", + "long_name": "array_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2824, + "end_line": 2827, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_remainder", + "long_name": "array_remainder( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2830, + "end_line": 2833, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power_is_scalar", + "long_name": "array_power_is_scalar( PyObject * o2 , double * exp)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 12, + "token_count": 154, + "parameters": [ + "o2", + "exp" + ], + "start_line": 2836, + "end_line": 2862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "fast_scalar_power", + "long_name": "fast_scalar_power( PyArrayObject * a1 , PyObject * o2 , int inplace)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 12, + "token_count": 181, + "parameters": [ + "a1", + "o2", + "inplace" + ], + "start_line": 2866, + "end_line": 2904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2907, + "end_line": 2916, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2920, + "end_line": 2923, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_absolute", + "long_name": "array_absolute( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2926, + "end_line": 2929, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_invert", + "long_name": "array_invert( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2932, + "end_line": 2935, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_left_shift", + "long_name": "array_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2938, + "end_line": 2941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_right_shift", + "long_name": "array_right_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2944, + "end_line": 2947, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_bitwise_and", + "long_name": "array_bitwise_and( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2950, + "end_line": 2953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_bitwise_or", + "long_name": "array_bitwise_or( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2956, + "end_line": 2959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_bitwise_xor", + "long_name": "array_bitwise_xor( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2962, + "end_line": 2965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_add", + "long_name": "array_inplace_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2968, + "end_line": 2971, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_subtract", + "long_name": "array_inplace_subtract( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2974, + "end_line": 2977, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_multiply", + "long_name": "array_inplace_multiply( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2980, + "end_line": 2983, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_divide", + "long_name": "array_inplace_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2986, + "end_line": 2989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_remainder", + "long_name": "array_inplace_remainder( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2992, + "end_line": 2995, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2998, + "end_line": 3007, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3010, + "end_line": 3013, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_right_shift", + "long_name": "array_inplace_right_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3016, + "end_line": 3019, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_bitwise_and", + "long_name": "array_inplace_bitwise_and( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3022, + "end_line": 3025, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_bitwise_or", + "long_name": "array_inplace_bitwise_or( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3028, + "end_line": 3031, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_bitwise_xor", + "long_name": "array_inplace_bitwise_xor( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3034, + "end_line": 3037, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_floor_divide", + "long_name": "array_floor_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3040, + "end_line": 3043, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_true_divide", + "long_name": "array_true_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3046, + "end_line": 3049, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_floor_divide", + "long_name": "array_inplace_floor_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3052, + "end_line": 3056, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_true_divide", + "long_name": "array_inplace_true_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3059, + "end_line": 3063, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_any_nonzero", + "long_name": "array_any_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 95, + "parameters": [ + "mp" + ], + "start_line": 3067, + "end_line": 3085, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_array_nonzero", + "long_name": "_array_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 3, + "token_count": 72, + "parameters": [ + "mp" + ], + "start_line": 3088, + "end_line": 3105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_divmod", + "long_name": "array_divmod( PyArrayObject * op1 , PyObject * op2)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 89, + "parameters": [ + "op1", + "op2" + ], + "start_line": 3110, + "end_line": 3125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_int", + "long_name": "array_int( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 3129, + "end_line": 3155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_float", + "long_name": "array_float( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 3158, + "end_line": 3183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_long", + "long_name": "array_long( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3186, + "end_line": 3208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_oct", + "long_name": "array_oct( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3211, + "end_line": 3233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_hex", + "long_name": "array_hex( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3236, + "end_line": 3258, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_array_copy_nice", + "long_name": "_array_copy_nice( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 3261, + "end_line": 3265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 12, + "token_count": 268, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 3326, + "end_line": 3367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 3371, + "end_line": 3393, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 3396, + "end_line": 3409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "dump_data", + "long_name": "dump_data( char ** string , int * n , int * max_n , char * data , int nd , intp * dimensions , intp * strides , PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 7, + "token_count": 310, + "parameters": [ + "string", + "n", + "max_n", + "data", + "nd", + "dimensions", + "strides", + "self" + ], + "start_line": 3442, + "end_line": 3489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_repr_builtin", + "long_name": "array_repr_builtin( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 4, + "token_count": 224, + "parameters": [ + "self" + ], + "start_line": 3492, + "end_line": 3528, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetStringFunction", + "long_name": "PyArray_SetStringFunction( PyObject * op , int repr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 48, + "parameters": [ + "op", + "repr" + ], + "start_line": 3537, + "end_line": 3554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_repr", + "long_name": "array_repr( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 3557, + "end_line": 3569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_str", + "long_name": "array_str( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 3572, + "end_line": 3584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CompareUCS4", + "long_name": "PyArray_CompareUCS4( PyArray_UCS4 * s1 , PyArray_UCS4 * s2 , register size_t len)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 66, + "parameters": [ + "s1", + "s2", + "len" + ], + "start_line": 3591, + "end_line": 3602, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "_myunincmp", + "long_name": "_myunincmp( PyArray_UCS4 * s1 , PyArray_UCS4 * s2 , int len1 , int len2)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 7, + "token_count": 141, + "parameters": [ + "s1", + "s2", + "len1", + "len2" + ], + "start_line": 3605, + "end_line": 3620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_mystrncmp", + "long_name": "_mystrncmp( char * s1 , char * s2 , int len1 , int len2)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 5, + "token_count": 103, + "parameters": [ + "s1", + "s2", + "len1", + "len2" + ], + "start_line": 3630, + "end_line": 3641, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "_compare_strings", + "long_name": "_compare_strings( PyObject * result , PyArrayMultiIterObject * multi , int cmp_op , * func)", + "filename": "arrayobject.c", + "nloc": 53, + "complexity": 9, + "token_count": 293, + "parameters": [ + "result", + "multi", + "cmp_op", + "func" + ], + "start_line": 3644, + "end_line": 3697, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "_strings_richcompare", + "long_name": "_strings_richcompare( PyArrayObject * self , PyArrayObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 12, + "token_count": 360, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3700, + "end_line": 3765, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "array_richcompare", + "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 105, + "complexity": 23, + "token_count": 483, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3771, + "end_line": 3893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 123, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 9, + "token_count": 181, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3896, + "end_line": 3926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntTupleFromIntp", + "long_name": "PyArray_IntTupleFromIntp( int len , intp * vals)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 109, + "parameters": [ + "len", + "vals" + ], + "start_line": 3932, + "end_line": 3952, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3960, + "end_line": 3995, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 4001, + "end_line": 4020, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 4024, + "end_line": 4042, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 4045, + "end_line": 4062, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_IsWriteable", + "long_name": "_IsWriteable( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 107, + "parameters": [ + "ap" + ], + "start_line": 4065, + "end_line": 4098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_UpdateFlags", + "long_name": "PyArray_UpdateFlags( PyArrayObject * ret , int flagmask)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 11, + "token_count": 157, + "parameters": [ + "ret", + "flagmask" + ], + "start_line": 4105, + "end_line": 4132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 117, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 4152, + "end_line": 4172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 4192, + "end_line": 4216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_New", + "long_name": "PyArray_New( PyTypeObject * subtype , int nd , intp * dims , int type_num , intp * strides , * data , int itemsize , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 4, + "token_count": 128, + "parameters": [ + "subtype", + "nd", + "dims", + "type_num", + "strides", + "data", + "itemsize", + "flags", + "obj" + ], + "start_line": 4222, + "end_line": 4244, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd , int isfortran)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 10, + "token_count": 311, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd", + "isfortran" + ], + "start_line": 4255, + "end_line": 4317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 133, + "complexity": 29, + "token_count": 798, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 4325, + "end_line": 4492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 168, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape , int refcheck , PyArray_ORDER fortran)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 17, + "token_count": 524, + "parameters": [ + "self", + "newshape", + "refcheck", + "fortran" + ], + "start_line": 4505, + "end_line": 4608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 104, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillObjectArray", + "long_name": "PyArray_FillObjectArray( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 98, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4614, + "end_line": 4631, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 8, + "token_count": 279, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4635, + "end_line": 4685, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 22, + "token_count": 638, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4688, + "end_line": 4822, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4826, + "end_line": 4834, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ndim_get", + "long_name": "array_ndim_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4840, + "end_line": 4843, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flags_get", + "long_name": "array_flags_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 4846, + "end_line": 4849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_get", + "long_name": "array_shape_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4852, + "end_line": 4855, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_set", + "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 213, + "parameters": [ + "self", + "val" + ], + "start_line": 4859, + "end_line": 4895, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_strides_get", + "long_name": "array_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4899, + "end_line": 4902, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 9, + "token_count": 304, + "parameters": [ + "self", + "obj" + ], + "start_line": 4905, + "end_line": 4959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4963, + "end_line": 4970, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4973, + "end_line": 4979, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4983, + "end_line": 4989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_data_get", + "long_name": "array_data_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 82, + "parameters": [ + "self" + ], + "start_line": 4992, + "end_line": 5006, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_data_set", + "long_name": "array_data_set( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 9, + "token_count": 229, + "parameters": [ + "self", + "op" + ], + "start_line": 5009, + "end_line": 5053, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_itemsize_get", + "long_name": "array_itemsize_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 5057, + "end_line": 5060, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_size_get", + "long_name": "array_size_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 5063, + "end_line": 5074, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nbytes_get", + "long_name": "array_nbytes_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 5077, + "end_line": 5088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 5094, + "end_line": 5097, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_descr_get", + "long_name": "array_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 5100, + "end_line": 5104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "arg" + ], + "start_line": 5118, + "end_line": 5205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 5208, + "end_line": 5226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_struct_get", + "long_name": "array_struct_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 2, + "token_count": 130, + "parameters": [ + "self" + ], + "start_line": 5229, + "end_line": 5247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 5250, + "end_line": 5260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_real_get", + "long_name": "array_real_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 3, + "token_count": 129, + "parameters": [ + "self" + ], + "start_line": 5264, + "end_line": 5289, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_real_set", + "long_name": "array_real_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 4, + "token_count": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 5293, + "end_line": 5327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_imag_get", + "long_name": "array_imag_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self" + ], + "start_line": 5330, + "end_line": 5363, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 5366, + "end_line": 5403, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "array_flat_get", + "long_name": "array_flat_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 5406, + "end_line": 5409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flat_set", + "long_name": "array_flat_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 9, + "token_count": 344, + "parameters": [ + "self", + "val" + ], + "start_line": 5412, + "end_line": 5462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_alloc", + "long_name": "array_alloc( PyTypeObject * type , int nitems)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 1, + "token_count": 39, + "parameters": [ + "type", + "nitems" + ], + "start_line": 5552, + "end_line": 5559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "discover_depth", + "long_name": "discover_depth( PyObject * s , int max , int stop_at_string , int stop_at_tuple)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 19, + "token_count": 243, + "parameters": [ + "s", + "max", + "stop_at_string", + "stop_at_tuple" + ], + "start_line": 5647, + "end_line": 5680, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5683, + "end_line": 5705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "discover_dimensions", + "long_name": "discover_dimensions( PyObject * s , int nd , intp * d , int check_it)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 10, + "token_count": 188, + "parameters": [ + "s", + "nd", + "d", + "check_it" + ], + "start_line": 5712, + "end_line": 5738, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_array_small_type", + "long_name": "_array_small_type( PyArray_Descr * chktype , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 169, + "parameters": [ + "chktype", + "mintype" + ], + "start_line": 5744, + "end_line": 5776, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_python_scalar_type", + "long_name": "_array_find_python_scalar_type( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 8, + "token_count": 120, + "parameters": [ + "op" + ], + "start_line": 5779, + "end_line": 5802, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 28, + "token_count": 634, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5814, + "end_line": 5944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "Assign_Array", + "long_name": "Assign_Array( PyArrayObject * self , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 121, + "parameters": [ + "self", + "v" + ], + "start_line": 5947, + "end_line": 5970, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 189, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5975, + "end_line": 6013, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 24, + "token_count": 373, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 6018, + "end_line": 6085, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 68, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 6092, + "end_line": 6101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_bufferedcast", + "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 18, + "token_count": 525, + "parameters": [ + "out", + "in" + ], + "start_line": 6107, + "end_line": 6200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 6210, + "end_line": 6256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastTo", + "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 241, + "parameters": [ + "out", + "mp" + ], + "start_line": 6266, + "end_line": 6319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 31, + "token_count": 658, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 6324, + "end_line": 6450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 501, + "parameters": [ + "str" + ], + "start_line": 6454, + "end_line": 6562, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 6566, + "end_line": 6606, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 6610, + "end_line": 6748, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6752, + "end_line": 6795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 74, + "complexity": 24, + "token_count": 449, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6801, + "end_line": 6893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6898, + "end_line": 6901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ObjectType", + "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 69, + "parameters": [ + "op", + "minimum_type" + ], + "start_line": 6908, + "end_line": 6921, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6967, + "end_line": 6983, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "op" + ], + "start_line": 6996, + "end_line": 7015, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureAnyArray", + "long_name": "PyArray_EnsureAnyArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 3, + "token_count": 26, + "parameters": [ + "op" + ], + "start_line": 7019, + "end_line": 7023, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastSafely", + "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 39, + "token_count": 444, + "parameters": [ + "fromtype", + "totype" + ], + "start_line": 7029, + "end_line": 7117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 7122, + "end_line": 7150, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastScalar", + "long_name": "PyArray_CanCastScalar( PyTypeObject * from , PyTypeObject * to)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 3, + "token_count": 68, + "parameters": [ + "from", + "to" + ], + "start_line": 7156, + "end_line": 7166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterNew", + "long_name": "PyArray_IterNew( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 269, + "parameters": [ + "obj" + ], + "start_line": 7177, + "end_line": 7215, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterAllButAxis", + "long_name": "PyArray_IterAllButAxis( PyObject * obj , int axis)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 88, + "parameters": [ + "obj", + "axis" + ], + "start_line": 7223, + "end_line": 7240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RemoveLargest", + "long_name": "PyArray_RemoveLargest( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 6, + "token_count": 164, + "parameters": [ + "multi" + ], + "start_line": 7252, + "end_line": 7280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_next", + "long_name": "arrayiter_next( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 48, + "parameters": [ + "it" + ], + "start_line": 7285, + "end_line": 7295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_dealloc", + "long_name": "arrayiter_dealloc( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "it" + ], + "start_line": 7298, + "end_line": 7302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 7305, + "end_line": 7308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_Bool", + "long_name": "iter_subscript_Bool( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 7, + "token_count": 283, + "parameters": [ + "self", + "ind" + ], + "start_line": 7312, + "end_line": 7362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_int", + "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 52, + "complexity": 8, + "token_count": 352, + "parameters": [ + "self", + "ind" + ], + "start_line": 7365, + "end_line": 7419, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 7423, + "end_line": 7556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 134, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_Bool", + "long_name": "iter_ass_sub_Bool( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 5, + "token_count": 182, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7560, + "end_line": 7591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_int", + "long_name": "iter_ass_sub_int( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 8, + "token_count": 286, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7594, + "end_line": 7636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 7639, + "end_line": 7773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "iter_array", + "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 214, + "parameters": [ + "it", + "op" + ], + "start_line": 7790, + "end_line": 7835, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "iter_copy", + "long_name": "iter_copy( PyArrayIterObject * it , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "it", + "args" + ], + "start_line": 7840, + "end_line": 7844, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7860, + "end_line": 7875, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7940, + "end_line": 7956, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Broadcast", + "long_name": "PyArray_Broadcast( PyArrayMultiIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 13, + "token_count": 464, + "parameters": [ + "mit" + ], + "start_line": 7963, + "end_line": 8032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterReset", + "long_name": "PyArray_MapIterReset( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 5, + "token_count": 279, + "parameters": [ + "mit" + ], + "start_line": 8036, + "end_line": 8076, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 296, + "parameters": [ + "mit" + ], + "start_line": 8082, + "end_line": 8126, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterBind", + "long_name": "PyArray_MapIterBind( PyArrayMapIterObject * mit , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 109, + "complexity": 23, + "token_count": 718, + "parameters": [ + "mit", + "arr" + ], + "start_line": 8144, + "end_line": 8285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 142, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 8291, + "end_line": 8363, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 8366, + "end_line": 8492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 8496, + "end_line": 8505, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiIterNew", + "long_name": "PyArray_MultiIterNew( int n , ...)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 10, + "token_count": 245, + "parameters": [ + "n" + ], + "start_line": 8576, + "end_line": 8626, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_new", + "long_name": "arraymultiter_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 11, + "token_count": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8629, + "end_line": 8674, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_next", + "long_name": "arraymultiter_next( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 111, + "parameters": [ + "multi" + ], + "start_line": 8677, + "end_line": 8696, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_dealloc", + "long_name": "arraymultiter_dealloc( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 49, + "parameters": [ + "multi" + ], + "start_line": 8699, + "end_line": 8706, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_size_get", + "long_name": "arraymultiter_size_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8709, + "end_line": 8719, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_index_get", + "long_name": "arraymultiter_index_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8722, + "end_line": 8732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_shape_get", + "long_name": "arraymultiter_shape_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 8735, + "end_line": 8738, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_iters_get", + "long_name": "arraymultiter_iters_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 8741, + "end_line": 8753, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_reset", + "long_name": "arraymultiter_reset( PyArrayMultiIterObject * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 38, + "parameters": [ + "self", + "args" + ], + "start_line": 8783, + "end_line": 8790, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewFromType", + "long_name": "PyArray_DescrNewFromType( int type_num)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 1, + "token_count": 37, + "parameters": [ + "type_num" + ], + "start_line": 8849, + "end_line": 8858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNew", + "long_name": "PyArray_DescrNew( PyArray_Descr * base)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 151, + "parameters": [ + "base" + ], + "start_line": 8876, + "end_line": 8898, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_dealloc", + "long_name": "arraydescr_dealloc( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 8904, + "end_line": 8914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_subdescr_get", + "long_name": "arraydescr_subdescr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 8933, + "end_line": 8941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8944, + "end_line": 8959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8962, + "end_line": 8984, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8987, + "end_line": 8995, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8998, + "end_line": 9005, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 9008, + "end_line": 9027, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isbuiltin_get", + "long_name": "arraydescr_isbuiltin_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 9034, + "end_line": 9041, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isnative_get", + "long_name": "arraydescr_isnative_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 9044, + "end_line": 9051, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_fields_get", + "long_name": "arraydescr_fields_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 9054, + "end_line": 9061, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_new", + "long_name": "arraydescr_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 15, + "token_count": 304, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 9109, + "end_line": 9170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 9176, + "end_line": 9237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 9, + "token_count": 264, + "parameters": [ + "self", + "args" + ], + "start_line": 9245, + "end_line": 9288, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewByteorder", + "long_name": "PyArray_DescrNewByteorder( PyArray_Descr * self , char newendian)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 386, + "parameters": [ + "self", + "newendian" + ], + "start_line": 9309, + "end_line": 9375, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_newbyteorder", + "long_name": "arraydescr_newbyteorder( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 47, + "parameters": [ + "self", + "args" + ], + "start_line": 9386, + "end_line": 9394, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_str", + "long_name": "arraydescr_str( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 6, + "token_count": 287, + "parameters": [ + "self" + ], + "start_line": 9409, + "end_line": 9454, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_repr", + "long_name": "arraydescr_repr( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 9457, + "end_line": 9466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_compare", + "long_name": "arraydescr_compare( PyArray_Descr * self , PyObject * other)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "other" + ], + "start_line": 9469, + "end_line": 9479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 9486, + "end_line": 9493, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 9496, + "end_line": 9527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFlagsObject", + "long_name": "PyArray_NewFlagsObject( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 3, + "token_count": 96, + "parameters": [ + "obj" + ], + "start_line": 9605, + "end_line": 9622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_dealloc", + "long_name": "arrayflags_dealloc( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 9625, + "end_line": 9629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_forc_get", + "long_name": "arrayflags_forc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 9653, + "end_line": 9665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_fnc_get", + "long_name": "arrayflags_fnc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9668, + "end_line": 9680, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_farray_get", + "long_name": "arrayflags_farray_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 9683, + "end_line": 9696, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_num_get", + "long_name": "arrayflags_num_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 9699, + "end_line": 9702, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_updateifcopy_set", + "long_name": "arrayflags_updateifcopy_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9706, + "end_line": 9718, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_aligned_set", + "long_name": "arrayflags_aligned_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9721, + "end_line": 9734, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_writeable_set", + "long_name": "arrayflags_writeable_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9737, + "end_line": 9750, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_getitem", + "long_name": "arrayflags_getitem( PyArrayFlagsObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 75, + "complexity": 31, + "token_count": 431, + "parameters": [ + "self", + "ind" + ], + "start_line": 9806, + "end_line": 9881, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_setitem", + "long_name": "arrayflags_setitem( PyArrayFlagsObject * self , PyObject * ind , PyObject * item)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 14, + "token_count": 219, + "parameters": [ + "self", + "ind", + "item" + ], + "start_line": 9884, + "end_line": 9904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_torf_", + "long_name": "_torf_( int flags , int val)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 27, + "parameters": [ + "flags", + "val" + ], + "start_line": 9907, + "end_line": 9911, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_print", + "long_name": "arrayflags_print( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 1, + "token_count": 77, + "parameters": [ + "self" + ], + "start_line": 9914, + "end_line": 9926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_new", + "long_name": "arrayflags_new( PyTypeObject * self , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9941, + "end_line": 9953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 76, + "parameters": [ + "obj", + "default_" + ], + "start_line": 28, + "end_line": 44, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zero", + "long_name": "PyArray_Zero( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 65, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_One", + "long_name": "PyArray_One( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 148, + "parameters": [ + "arr" + ], + "start_line": 99, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "do_sliced_copy", + "long_name": "do_sliced_copy( char * dest , intp * dest_strides , intp * dest_dimensions , int dest_nd , char * src , intp * src_strides , intp * src_dimensions , int src_nd , int elsize , int copies)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 313, + "parameters": [ + "dest", + "dest_strides", + "dest_dimensions", + "dest_nd", + "src", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 134, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "optimize_slices", + "long_name": "optimize_slices( intp ** dest_strides , intp ** dest_dimensions , int * dest_nd , intp ** src_strides , intp ** src_dimensions , int * src_nd , int * elsize , int * copies)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 8, + "token_count": 214, + "parameters": [ + "dest_strides", + "dest_dimensions", + "dest_nd", + "src_strides", + "src_dimensions", + "src_nd", + "elsize", + "copies" + ], + "start_line": 207, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "contiguous_data", + "long_name": "contiguous_data( PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 4, + "token_count": 215, + "parameters": [ + "src" + ], + "start_line": 241, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "PyArray_INCREF", + "long_name": "PyArray_INCREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 291, + "end_line": 313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_XDECREF", + "long_name": "PyArray_XDECREF( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 6, + "token_count": 125, + "parameters": [ + "mp" + ], + "start_line": 319, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "byte_swap_vector", + "long_name": "byte_swap_vector( * p , int n , int size)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 10, + "token_count": 340, + "parameters": [ + "p", + "n", + "size" + ], + "start_line": 344, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "copy_and_swap", + "long_name": "copy_and_swap( * dst , * src , int itemsize , intp numitems , intp srcstrides , int swap)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 120, + "parameters": [ + "dst", + "src", + "itemsize", + "numitems", + "srcstrides", + "swap" + ], + "start_line": 387, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 21, + "token_count": 413, + "parameters": [ + "o" + ], + "start_line": 427, + "end_line": 509, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 67, + "complexity": 19, + "token_count": 406, + "parameters": [ + "o" + ], + "start_line": 516, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 75, + "top_nesting_level": 0 + }, + { + "name": "index2ptr", + "long_name": "index2ptr( PyArrayObject * mp , intp i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 7, + "token_count": 98, + "parameters": [ + "mp", + "i" + ], + "start_line": 593, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Size", + "long_name": "PyArray_Size( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 33, + "parameters": [ + "op" + ], + "start_line": 614, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "_strided_byte_copy", + "long_name": "_strided_byte_copy( char * dst , intp outstrides , char * src , intp instrides , intp N , int elsize)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 9, + "token_count": 207, + "parameters": [ + "dst", + "outstrides", + "src", + "instrides", + "N", + "elsize" + ], + "start_line": 625, + "end_line": 667, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "_unaligned_strided_byte_copy", + "long_name": "_unaligned_strided_byte_copy( char * dst , intp outstrides , char * src , intp instrides , intp N , int elsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 92, + "parameters": [ + "dst", + "outstrides", + "src", + "instrides", + "N", + "elsize" + ], + "start_line": 671, + "end_line": 701, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 119, + "complexity": 27, + "token_count": 737, + "parameters": [ + "dest", + "src" + ], + "start_line": 718, + "end_line": 853, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyObject", + "long_name": "PyArray_CopyObject( PyArrayObject * dest , PyObject * src_object)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 857, + "end_line": 871, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDimsAndDataAndDescr", + "long_name": "PyArray_FromDimsAndDataAndDescr( int nd , int * d , PyArray_Descr * descr , char * data)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 137, + "parameters": [ + "nd", + "d", + "descr", + "data" + ], + "start_line": 884, + "end_line": 910, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromDims", + "long_name": "PyArray_FromDims( int nd , int * d , int type)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 69, + "parameters": [ + "nd", + "d", + "type" + ], + "start_line": 916, + "end_line": 930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewCopy", + "long_name": "PyArray_NewCopy( PyArrayObject * m1 , PyArray_ORDER fortran)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 939, + "end_line": 960, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 118, + "complexity": 24, + "token_count": 712, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 969, + "end_line": 1103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Return", + "long_name": "PyArray_Return( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 91, + "parameters": [ + "mp" + ], + "start_line": 1123, + "end_line": 1145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDataType", + "long_name": "PyArray_RegisterDataType( PyTypeObject * type)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 9, + "token_count": 229, + "parameters": [ + "type" + ], + "start_line": 1159, + "end_line": 1199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RegisterDescrForType", + "long_name": "PyArray_RegisterDescrForType( int typenum , PyArray_Descr * descr)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 214, + "parameters": [ + "typenum", + "descr" + ], + "start_line": 1214, + "end_line": 1255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToFile", + "long_name": "PyArray_ToFile( PyArrayObject * self , FILE * fp , char * sep , char * format)", + "filename": "arrayobject.c", + "nloc": 96, + "complexity": 19, + "token_count": 624, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1262, + "end_line": 1360, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToList", + "long_name": "PyArray_ToList( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self" + ], + "start_line": 1366, + "end_line": 1395, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToString", + "long_name": "PyArray_ToString( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 170, + "parameters": [ + "self" + ], + "start_line": 1398, + "end_line": 1434, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_dealloc", + "long_name": "array_dealloc( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 7, + "token_count": 144, + "parameters": [ + "self" + ], + "start_line": 1443, + "end_line": 1480, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "array_length", + "long_name": "array_length( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 1487, + "end_line": 1495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_big_item", + "long_name": "array_big_item( PyArrayObject * self , intp i)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 4, + "token_count": 151, + "parameters": [ + "self", + "i" + ], + "start_line": 1498, + "end_line": 1523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_item_nice", + "long_name": "array_item_nice( PyArrayObject * self , _int_or_ssize_t i)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 4, + "token_count": 98, + "parameters": [ + "self", + "i" + ], + "start_line": 1527, + "end_line": 1541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_ass_big_item", + "long_name": "array_ass_big_item( PyArrayObject * self , intp i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 32, + "complexity": 9, + "token_count": 200, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1544, + "end_line": 1579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "array_ass_item", + "long_name": "array_ass_item( PyArrayObject * self , _int_or_ssize_t i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1592, + "end_line": 1595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "slice_coerce_index", + "long_name": "slice_coerce_index( PyObject * o , intp * v)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 40, + "parameters": [ + "o", + "v" + ], + "start_line": 1601, + "end_line": 1609, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "slice_GetIndices", + "long_name": "slice_GetIndices( PySliceObject * r , intp length , intp * start , intp * stop , intp * step , intp * slicelength)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 24, + "token_count": 376, + "parameters": [ + "r", + "length", + "start", + "stop", + "step", + "slicelength" + ], + "start_line": 1615, + "end_line": 1665, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "parse_subindex", + "long_name": "parse_subindex( PyObject * op , intp * step_size , intp * n_steps , intp max)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "step_size", + "n_steps", + "max" + ], + "start_line": 1672, + "end_line": 1717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "parse_index", + "long_name": "parse_index( PyArrayObject * self , PyObject * op , intp * dimensions , intp * strides , intp * offset_ptr)", + "filename": "arrayobject.c", + "nloc": 88, + "complexity": 20, + "token_count": 539, + "parameters": [ + "self", + "op", + "dimensions", + "strides", + "offset_ptr" + ], + "start_line": 1721, + "end_line": 1815, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 95, + "top_nesting_level": 0 + }, + { + "name": "_swap_axes", + "long_name": "_swap_axes( PyArrayMapIterObject * mit , PyArrayObject ** ret)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 300, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1818, + "end_line": 1872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 254, + "parameters": [ + "mit" + ], + "start_line": 1884, + "end_line": 1937, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetMap", + "long_name": "PyArray_SetMap( PyArrayMapIterObject * mit , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 389, + "parameters": [ + "mit", + "op" + ], + "start_line": 1940, + "end_line": 2002, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "count_new_axes_0d", + "long_name": "count_new_axes_0d( PyObject * tuple)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 7, + "token_count": 124, + "parameters": [ + "tuple" + ], + "start_line": 2005, + "end_line": 2032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "add_new_axes_0d", + "long_name": "add_new_axes_0d( PyArrayObject * arr , int newaxis_count)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 121, + "parameters": [ + "arr", + "newaxis_count" + ], + "start_line": 2035, + "end_line": 2054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "fancy_indexing_check", + "long_name": "fancy_indexing_check( PyObject * args)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 22, + "token_count": 295, + "parameters": [ + "args" + ], + "start_line": 2066, + "end_line": 2128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 107, + "complexity": 28, + "token_count": 674, + "parameters": [ + "self", + "op" + ], + "start_line": 2152, + "end_line": 2277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 93, + "complexity": 28, + "token_count": 588, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 2292, + "end_line": 2397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 106, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 16, + "token_count": 281, + "parameters": [ + "self", + "op" + ], + "start_line": 2406, + "end_line": 2460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , _int_or_ssize_t * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2483, + "end_line": 2495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_getreadbuf", + "long_name": "array_getreadbuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2498, + "end_line": 2513, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_getwritebuf", + "long_name": "array_getwritebuf( PyArrayObject * self , _int_or_ssize_t segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2517, + "end_line": 2526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_getcharbuf", + "long_name": "array_getcharbuf( PyArrayObject * self , _int_or_ssize_t segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2529, + "end_line": 2540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetNumericOps", + "long_name": "PyArray_SetNumericOps( PyObject * dict)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 1, + "token_count": 182, + "parameters": [ + "dict" + ], + "start_line": 2618, + "end_line": 2655, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 2, + "token_count": 203, + "parameters": [], + "start_line": 2665, + "end_line": 2708, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericReduceFunction", + "long_name": "PyArray_GenericReduceFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2711, + "end_line": 2734, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericAccumulateFunction", + "long_name": "PyArray_GenericAccumulateFunction( PyArrayObject * m1 , PyObject * op , int axis , int rtype)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 5, + "token_count": 141, + "parameters": [ + "m1", + "op", + "axis", + "rtype" + ], + "start_line": 2738, + "end_line": 2761, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericBinaryFunction", + "long_name": "PyArray_GenericBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 44, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2765, + "end_line": 2772, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericUnaryFunction", + "long_name": "PyArray_GenericUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 38, + "parameters": [ + "m1", + "op" + ], + "start_line": 2775, + "end_line": 2782, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceBinaryFunction", + "long_name": "PyArray_GenericInplaceBinaryFunction( PyArrayObject * m1 , PyObject * m2 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 46, + "parameters": [ + "m1", + "m2", + "op" + ], + "start_line": 2785, + "end_line": 2793, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GenericInplaceUnaryFunction", + "long_name": "PyArray_GenericInplaceUnaryFunction( PyArrayObject * m1 , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 40, + "parameters": [ + "m1", + "op" + ], + "start_line": 2796, + "end_line": 2803, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_add", + "long_name": "array_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2806, + "end_line": 2809, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_subtract", + "long_name": "array_subtract( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2812, + "end_line": 2815, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_multiply", + "long_name": "array_multiply( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2818, + "end_line": 2821, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_divide", + "long_name": "array_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2824, + "end_line": 2827, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_remainder", + "long_name": "array_remainder( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2830, + "end_line": 2833, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power_is_scalar", + "long_name": "array_power_is_scalar( PyObject * o2 , double * exp)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 12, + "token_count": 154, + "parameters": [ + "o2", + "exp" + ], + "start_line": 2836, + "end_line": 2862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "fast_scalar_power", + "long_name": "fast_scalar_power( PyArrayObject * a1 , PyObject * o2 , int inplace)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 12, + "token_count": 181, + "parameters": [ + "a1", + "o2", + "inplace" + ], + "start_line": 2866, + "end_line": 2904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2907, + "end_line": 2916, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_negative", + "long_name": "array_negative( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2920, + "end_line": 2923, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_absolute", + "long_name": "array_absolute( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2926, + "end_line": 2929, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_invert", + "long_name": "array_invert( PyArrayObject * m1)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "m1" + ], + "start_line": 2932, + "end_line": 2935, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_left_shift", + "long_name": "array_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2938, + "end_line": 2941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_right_shift", + "long_name": "array_right_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2944, + "end_line": 2947, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_bitwise_and", + "long_name": "array_bitwise_and( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2950, + "end_line": 2953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_bitwise_or", + "long_name": "array_bitwise_or( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2956, + "end_line": 2959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_bitwise_xor", + "long_name": "array_bitwise_xor( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2962, + "end_line": 2965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_add", + "long_name": "array_inplace_add( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2968, + "end_line": 2971, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_subtract", + "long_name": "array_inplace_subtract( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2974, + "end_line": 2977, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_multiply", + "long_name": "array_inplace_multiply( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2980, + "end_line": 2983, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_divide", + "long_name": "array_inplace_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2986, + "end_line": 2989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_remainder", + "long_name": "array_inplace_remainder( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2992, + "end_line": 2995, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_power", + "long_name": "array_inplace_power( PyArrayObject * a1 , PyObject * o2 , PyObject * modulo)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 54, + "parameters": [ + "a1", + "o2", + "modulo" + ], + "start_line": 2998, + "end_line": 3007, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_left_shift", + "long_name": "array_inplace_left_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3010, + "end_line": 3013, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_right_shift", + "long_name": "array_inplace_right_shift( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3016, + "end_line": 3019, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_bitwise_and", + "long_name": "array_inplace_bitwise_and( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3022, + "end_line": 3025, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_bitwise_or", + "long_name": "array_inplace_bitwise_or( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3028, + "end_line": 3031, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_bitwise_xor", + "long_name": "array_inplace_bitwise_xor( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3034, + "end_line": 3037, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_floor_divide", + "long_name": "array_floor_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3040, + "end_line": 3043, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_true_divide", + "long_name": "array_true_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3046, + "end_line": 3049, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_floor_divide", + "long_name": "array_inplace_floor_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3052, + "end_line": 3056, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_inplace_true_divide", + "long_name": "array_inplace_true_divide( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 3059, + "end_line": 3063, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_any_nonzero", + "long_name": "array_any_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 95, + "parameters": [ + "mp" + ], + "start_line": 3067, + "end_line": 3085, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_array_nonzero", + "long_name": "_array_nonzero( PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 3, + "token_count": 72, + "parameters": [ + "mp" + ], + "start_line": 3088, + "end_line": 3105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_divmod", + "long_name": "array_divmod( PyArrayObject * op1 , PyObject * op2)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 89, + "parameters": [ + "op1", + "op2" + ], + "start_line": 3110, + "end_line": 3125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_int", + "long_name": "array_int( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 3129, + "end_line": 3155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "array_float", + "long_name": "array_float( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 5, + "token_count": 145, + "parameters": [ + "v" + ], + "start_line": 3158, + "end_line": 3183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_long", + "long_name": "array_long( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3186, + "end_line": 3208, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_oct", + "long_name": "array_oct( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3211, + "end_line": 3233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_hex", + "long_name": "array_hex( PyArrayObject * v)", + "filename": "arrayobject.c", + "nloc": 23, + "complexity": 4, + "token_count": 126, + "parameters": [ + "v" + ], + "start_line": 3236, + "end_line": 3258, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_array_copy_nice", + "long_name": "_array_copy_nice( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 3261, + "end_line": 3265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_slice", + "long_name": "array_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 12, + "token_count": 268, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 3326, + "end_line": 3367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , _int_or_ssize_t ilow , _int_or_ssize_t ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 3371, + "end_line": 3393, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 3396, + "end_line": 3409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "dump_data", + "long_name": "dump_data( char ** string , int * n , int * max_n , char * data , int nd , intp * dimensions , intp * strides , PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 7, + "token_count": 310, + "parameters": [ + "string", + "n", + "max_n", + "data", + "nd", + "dimensions", + "strides", + "self" + ], + "start_line": 3442, + "end_line": 3489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 0 + }, + { + "name": "array_repr_builtin", + "long_name": "array_repr_builtin( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 4, + "token_count": 224, + "parameters": [ + "self" + ], + "start_line": 3492, + "end_line": 3528, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SetStringFunction", + "long_name": "PyArray_SetStringFunction( PyObject * op , int repr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 48, + "parameters": [ + "op", + "repr" + ], + "start_line": 3537, + "end_line": 3554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_repr", + "long_name": "array_repr( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 3557, + "end_line": 3569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_str", + "long_name": "array_str( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 59, + "parameters": [ + "self" + ], + "start_line": 3572, + "end_line": 3584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CompareUCS4", + "long_name": "PyArray_CompareUCS4( PyArray_UCS4 * s1 , PyArray_UCS4 * s2 , register size_t len)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 66, + "parameters": [ + "s1", + "s2", + "len" + ], + "start_line": 3591, + "end_line": 3602, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "_myunincmp", + "long_name": "_myunincmp( PyArray_UCS4 * s1 , PyArray_UCS4 * s2 , int len1 , int len2)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 7, + "token_count": 141, + "parameters": [ + "s1", + "s2", + "len1", + "len2" + ], + "start_line": 3605, + "end_line": 3620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_mystrncmp", + "long_name": "_mystrncmp( char * s1 , char * s2 , int len1 , int len2)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 5, + "token_count": 103, + "parameters": [ + "s1", + "s2", + "len1", + "len2" + ], + "start_line": 3630, + "end_line": 3641, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "_compare_strings", + "long_name": "_compare_strings( PyObject * result , PyArrayMultiIterObject * multi , int cmp_op , * func)", + "filename": "arrayobject.c", + "nloc": 53, + "complexity": 9, + "token_count": 293, + "parameters": [ + "result", + "multi", + "cmp_op", + "func" + ], + "start_line": 3644, + "end_line": 3697, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "_strings_richcompare", + "long_name": "_strings_richcompare( PyArrayObject * self , PyArrayObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 12, + "token_count": 360, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3700, + "end_line": 3765, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "array_richcompare", + "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 105, + "complexity": 23, + "token_count": 483, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3771, + "end_line": 3893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 123, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 9, + "token_count": 181, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3896, + "end_line": 3926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntTupleFromIntp", + "long_name": "PyArray_IntTupleFromIntp( int len , intp * vals)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 109, + "parameters": [ + "len", + "vals" + ], + "start_line": 3932, + "end_line": 3952, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpFromSequence", + "long_name": "PyArray_IntpFromSequence( PyObject * seq , intp * vals , int maxvals)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 11, + "token_count": 203, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3960, + "end_line": 3995, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 128, + "parameters": [ + "ap" + ], + "start_line": 4001, + "end_line": 4020, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 7, + "token_count": 126, + "parameters": [ + "ap" + ], + "start_line": 4024, + "end_line": 4042, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "_IsAligned", + "long_name": "_IsAligned( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 119, + "parameters": [ + "ap" + ], + "start_line": 4045, + "end_line": 4062, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_IsWriteable", + "long_name": "_IsWriteable( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 107, + "parameters": [ + "ap" + ], + "start_line": 4065, + "end_line": 4098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_UpdateFlags", + "long_name": "PyArray_UpdateFlags( PyArrayObject * ret , int flagmask)", + "filename": "arrayobject.c", + "nloc": 26, + "complexity": 11, + "token_count": 157, + "parameters": [ + "ret", + "flagmask" + ], + "start_line": 4105, + "end_line": 4132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckStrides", + "long_name": "PyArray_CheckStrides( int elsize , int nd , intp numbytes , intp offset , intp * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 5, + "token_count": 117, + "parameters": [ + "elsize", + "nd", + "numbytes", + "offset", + "dims", + "newstrides" + ], + "start_line": 4152, + "end_line": 4172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_array_fill_strides", + "long_name": "_array_fill_strides( intp * strides , intp * dims , int nd , intp itemsize , int inflag , int * objflags)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 9, + "token_count": 171, + "parameters": [ + "strides", + "dims", + "nd", + "itemsize", + "inflag", + "objflags" + ], + "start_line": 4192, + "end_line": 4216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_New", + "long_name": "PyArray_New( PyTypeObject * subtype , int nd , intp * dims , int type_num , intp * strides , * data , int itemsize , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 4, + "token_count": 128, + "parameters": [ + "subtype", + "nd", + "dims", + "type_num", + "strides", + "data", + "itemsize", + "flags", + "obj" + ], + "start_line": 4222, + "end_line": 4244, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_update_descr_and_dimensions", + "long_name": "_update_descr_and_dimensions( PyArray_Descr ** des , intp * newdims , intp * newstrides , int oldnd , int isfortran)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 10, + "token_count": 311, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd", + "isfortran" + ], + "start_line": 4255, + "end_line": 4317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFromDescr", + "long_name": "PyArray_NewFromDescr( PyTypeObject * subtype , PyArray_Descr * descr , int nd , intp * dims , intp * strides , * data , int flags , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 133, + "complexity": 29, + "token_count": 798, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 4325, + "end_line": 4492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 168, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape , int refcheck , PyArray_ORDER fortran)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 17, + "token_count": 524, + "parameters": [ + "self", + "newshape", + "refcheck", + "fortran" + ], + "start_line": 4505, + "end_line": 4608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 104, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillObjectArray", + "long_name": "PyArray_FillObjectArray( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 18, + "complexity": 4, + "token_count": 98, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4614, + "end_line": 4631, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FillWithScalar", + "long_name": "PyArray_FillWithScalar( PyArrayObject * arr , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 8, + "token_count": 279, + "parameters": [ + "arr", + "obj" + ], + "start_line": 4635, + "end_line": 4685, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 22, + "token_count": 638, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 4688, + "end_line": 4822, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "array_iter", + "long_name": "array_iter( PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 38, + "parameters": [ + "arr" + ], + "start_line": 4826, + "end_line": 4834, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_ndim_get", + "long_name": "array_ndim_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 4840, + "end_line": 4843, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flags_get", + "long_name": "array_flags_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 4846, + "end_line": 4849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_get", + "long_name": "array_shape_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4852, + "end_line": 4855, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_shape_set", + "long_name": "array_shape_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 213, + "parameters": [ + "self", + "val" + ], + "start_line": 4859, + "end_line": 4895, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "array_strides_get", + "long_name": "array_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 4899, + "end_line": 4902, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_strides_set", + "long_name": "array_strides_set( PyArrayObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 49, + "complexity": 9, + "token_count": 304, + "parameters": [ + "self", + "obj" + ], + "start_line": 4905, + "end_line": 4959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_strides_get", + "long_name": "array_protocol_strides_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4963, + "end_line": 4970, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "array_priority_get", + "long_name": "array_priority_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4973, + "end_line": 4979, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_dataptr_get", + "long_name": "array_dataptr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 4983, + "end_line": 4989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_data_get", + "long_name": "array_data_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 82, + "parameters": [ + "self" + ], + "start_line": 4992, + "end_line": 5006, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "array_data_set", + "long_name": "array_data_set( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 9, + "token_count": 229, + "parameters": [ + "self", + "op" + ], + "start_line": 5009, + "end_line": 5053, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_itemsize_get", + "long_name": "array_itemsize_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self" + ], + "start_line": 5057, + "end_line": 5060, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_size_get", + "long_name": "array_size_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 5063, + "end_line": 5074, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_nbytes_get", + "long_name": "array_nbytes_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 4, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 5077, + "end_line": 5088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typestr_get", + "long_name": "array_typestr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 5094, + "end_line": 5097, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_descr_get", + "long_name": "array_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 5100, + "end_line": 5104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "array_descr_set", + "long_name": "array_descr_set( PyArrayObject * self , PyObject * arg)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 449, + "parameters": [ + "self", + "arg" + ], + "start_line": 5118, + "end_line": 5205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "array_protocol_descr_get", + "long_name": "array_protocol_descr_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 4, + "token_count": 117, + "parameters": [ + "self" + ], + "start_line": 5208, + "end_line": 5226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_struct_get", + "long_name": "array_struct_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 2, + "token_count": 130, + "parameters": [ + "self" + ], + "start_line": 5229, + "end_line": 5247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_base_get", + "long_name": "array_base_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 5250, + "end_line": 5260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_real_get", + "long_name": "array_real_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 25, + "complexity": 3, + "token_count": 129, + "parameters": [ + "self" + ], + "start_line": 5264, + "end_line": 5289, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "array_real_set", + "long_name": "array_real_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 4, + "token_count": 191, + "parameters": [ + "self", + "val" + ], + "start_line": 5293, + "end_line": 5327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 35, + "top_nesting_level": 0 + }, + { + "name": "array_imag_get", + "long_name": "array_imag_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self" + ], + "start_line": 5330, + "end_line": 5363, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "array_imag_set", + "long_name": "array_imag_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 4, + "token_count": 207, + "parameters": [ + "self", + "val" + ], + "start_line": 5366, + "end_line": 5403, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "array_flat_get", + "long_name": "array_flat_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 5406, + "end_line": 5409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_flat_set", + "long_name": "array_flat_set( PyArrayObject * self , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 9, + "token_count": 344, + "parameters": [ + "self", + "val" + ], + "start_line": 5412, + "end_line": 5462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "array_alloc", + "long_name": "array_alloc( PyTypeObject * type , int nitems)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 1, + "token_count": 39, + "parameters": [ + "type", + "nitems" + ], + "start_line": 5552, + "end_line": 5559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "discover_depth", + "long_name": "discover_depth( PyObject * s , int max , int stop_at_string , int stop_at_tuple)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 19, + "token_count": 243, + "parameters": [ + "s", + "max", + "stop_at_string", + "stop_at_tuple" + ], + "start_line": 5647, + "end_line": 5680, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "discover_itemsize", + "long_name": "discover_itemsize( PyObject * s , int nd , int * itemsize)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 158, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 5683, + "end_line": 5705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "discover_dimensions", + "long_name": "discover_dimensions( PyObject * s , int nd , intp * d , int check_it)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 10, + "token_count": 188, + "parameters": [ + "s", + "nd", + "d", + "check_it" + ], + "start_line": 5712, + "end_line": 5738, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_array_small_type", + "long_name": "_array_small_type( PyArray_Descr * chktype , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 169, + "parameters": [ + "chktype", + "mintype" + ], + "start_line": 5744, + "end_line": 5776, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_python_scalar_type", + "long_name": "_array_find_python_scalar_type( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 8, + "token_count": 120, + "parameters": [ + "op" + ], + "start_line": 5779, + "end_line": 5802, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 28, + "token_count": 634, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 5814, + "end_line": 5944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "Assign_Array", + "long_name": "Assign_Array( PyArrayObject * self , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 121, + "parameters": [ + "self", + "v" + ], + "start_line": 5947, + "end_line": 5970, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "Array_FromScalar", + "long_name": "Array_FromScalar( PyObject * op , PyArray_Descr * typecode)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 189, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5975, + "end_line": 6013, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "Array_FromSequence", + "long_name": "Array_FromSequence( PyObject * s , PyArray_Descr * typecode , int fortran , int min_depth , int max_depth)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 24, + "token_count": 373, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 6018, + "end_line": 6085, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 68, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ValidType", + "long_name": "PyArray_ValidType( int type)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 41, + "parameters": [ + "type" + ], + "start_line": 6092, + "end_line": 6101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_bufferedcast", + "long_name": "_bufferedcast( PyArrayObject * out , PyArrayObject * in)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 18, + "token_count": 525, + "parameters": [ + "out", + "in" + ], + "start_line": 6107, + "end_line": 6200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastToType", + "long_name": "PyArray_CastToType( PyArrayObject * mp , PyArray_Descr * at , int fortran)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 16, + "token_count": 276, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 6210, + "end_line": 6256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CastTo", + "long_name": "PyArray_CastTo( PyArrayObject * out , PyArrayObject * mp)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 11, + "token_count": 241, + "parameters": [ + "out", + "mp" + ], + "start_line": 6266, + "end_line": 6319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArray", + "long_name": "PyArray_FromArray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 111, + "complexity": 31, + "token_count": 658, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 6324, + "end_line": 6450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 501, + "parameters": [ + "str" + ], + "start_line": 6454, + "end_line": 6562, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromStructInterface", + "long_name": "PyArray_FromStructInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 6, + "token_count": 234, + "parameters": [ + "input" + ], + "start_line": 6566, + "end_line": 6606, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromInterface", + "long_name": "PyArray_FromInterface( PyObject * input)", + "filename": "arrayobject.c", + "nloc": 129, + "complexity": 28, + "token_count": 793, + "parameters": [ + "input" + ], + "start_line": 6610, + "end_line": 6748, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromArrayAttr", + "long_name": "PyArray_FromArrayAttr( PyObject * op , PyArray_Descr * typecode , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 43, + "complexity": 11, + "token_count": 223, + "parameters": [ + "op", + "typecode", + "context" + ], + "start_line": 6752, + "end_line": 6795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 74, + "complexity": 24, + "token_count": 449, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags", + "context" + ], + "start_line": 6801, + "end_line": 6893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 93, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrFromObject", + "long_name": "PyArray_DescrFromObject( PyObject * op , PyArray_Descr * mintype)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 22, + "parameters": [ + "op", + "mintype" + ], + "start_line": 6898, + "end_line": 6901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ObjectType", + "long_name": "PyArray_ObjectType( PyObject * op , int minimum_type)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 69, + "parameters": [ + "op", + "minimum_type" + ], + "start_line": 6908, + "end_line": 6921, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CheckFromAny", + "long_name": "PyArray_CheckFromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires , PyObject * context)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 7, + "token_count": 111, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires", + "context" + ], + "start_line": 6967, + "end_line": 6983, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "op" + ], + "start_line": 6996, + "end_line": 7015, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureAnyArray", + "long_name": "PyArray_EnsureAnyArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 3, + "token_count": 26, + "parameters": [ + "op" + ], + "start_line": 7019, + "end_line": 7023, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastSafely", + "long_name": "PyArray_CanCastSafely( int fromtype , int totype)", + "filename": "arrayobject.c", + "nloc": 86, + "complexity": 39, + "token_count": 444, + "parameters": [ + "fromtype", + "totype" + ], + "start_line": 7029, + "end_line": 7117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastTo", + "long_name": "PyArray_CanCastTo( PyArray_Descr * from , PyArray_Descr * to)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 7, + "token_count": 132, + "parameters": [ + "from", + "to" + ], + "start_line": 7122, + "end_line": 7150, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CanCastScalar", + "long_name": "PyArray_CanCastScalar( PyTypeObject * from , PyTypeObject * to)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 3, + "token_count": 68, + "parameters": [ + "from", + "to" + ], + "start_line": 7156, + "end_line": 7166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterNew", + "long_name": "PyArray_IterNew( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 34, + "complexity": 6, + "token_count": 269, + "parameters": [ + "obj" + ], + "start_line": 7177, + "end_line": 7215, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IterAllButAxis", + "long_name": "PyArray_IterAllButAxis( PyObject * obj , int axis)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 88, + "parameters": [ + "obj", + "axis" + ], + "start_line": 7223, + "end_line": 7240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_RemoveLargest", + "long_name": "PyArray_RemoveLargest( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 24, + "complexity": 6, + "token_count": 164, + "parameters": [ + "multi" + ], + "start_line": 7252, + "end_line": 7280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_next", + "long_name": "arrayiter_next( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 48, + "parameters": [ + "it" + ], + "start_line": 7285, + "end_line": 7295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arrayiter_dealloc", + "long_name": "arrayiter_dealloc( PyArrayIterObject * it)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 20, + "parameters": [ + "it" + ], + "start_line": 7298, + "end_line": 7302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_length", + "long_name": "iter_length( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 7305, + "end_line": 7308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_Bool", + "long_name": "iter_subscript_Bool( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 44, + "complexity": 7, + "token_count": 283, + "parameters": [ + "self", + "ind" + ], + "start_line": 7312, + "end_line": 7362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript_int", + "long_name": "iter_subscript_int( PyArrayIterObject * self , PyArrayObject * ind)", + "filename": "arrayobject.c", + "nloc": 52, + "complexity": 8, + "token_count": 352, + "parameters": [ + "self", + "ind" + ], + "start_line": 7365, + "end_line": 7419, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "iter_subscript", + "long_name": "iter_subscript( PyArrayIterObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 113, + "complexity": 23, + "token_count": 668, + "parameters": [ + "self", + "ind" + ], + "start_line": 7423, + "end_line": 7556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 134, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_Bool", + "long_name": "iter_ass_sub_Bool( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 30, + "complexity": 5, + "token_count": 182, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7560, + "end_line": 7591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_sub_int", + "long_name": "iter_ass_sub_int( PyArrayIterObject * self , PyArrayObject * ind , PyArrayIterObject * val , int swap)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 8, + "token_count": 286, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 7594, + "end_line": 7636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "iter_ass_subscript", + "long_name": "iter_ass_subscript( PyArrayIterObject * self , PyObject * ind , PyObject * val)", + "filename": "arrayobject.c", + "nloc": 115, + "complexity": 27, + "token_count": 698, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 7639, + "end_line": 7773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 135, + "top_nesting_level": 0 + }, + { + "name": "iter_array", + "long_name": "iter_array( PyArrayIterObject * it , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 33, + "complexity": 5, + "token_count": 214, + "parameters": [ + "it", + "op" + ], + "start_line": 7790, + "end_line": 7835, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "iter_copy", + "long_name": "iter_copy( PyArrayIterObject * it , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "it", + "args" + ], + "start_line": 7840, + "end_line": 7844, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "iter_coords_get", + "long_name": "iter_coords_get( PyArrayIterObject * self)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self" + ], + "start_line": 7860, + "end_line": 7875, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 106, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7940, + "end_line": 7956, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Broadcast", + "long_name": "PyArray_Broadcast( PyArrayMultiIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 58, + "complexity": 13, + "token_count": 464, + "parameters": [ + "mit" + ], + "start_line": 7963, + "end_line": 8032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterReset", + "long_name": "PyArray_MapIterReset( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 38, + "complexity": 5, + "token_count": 279, + "parameters": [ + "mit" + ], + "start_line": 8036, + "end_line": 8076, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 296, + "parameters": [ + "mit" + ], + "start_line": 8082, + "end_line": 8126, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterBind", + "long_name": "PyArray_MapIterBind( PyArrayMapIterObject * mit , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 109, + "complexity": 23, + "token_count": 718, + "parameters": [ + "mit", + "arr" + ], + "start_line": 8144, + "end_line": 8285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 142, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 462, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 8291, + "end_line": 8363, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned , int fancy)", + "filename": "arrayobject.c", + "nloc": 104, + "complexity": 24, + "token_count": 726, + "parameters": [ + "indexobj", + "oned", + "fancy" + ], + "start_line": 8366, + "end_line": 8492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 127, + "top_nesting_level": 0 + }, + { + "name": "arraymapiter_dealloc", + "long_name": "arraymapiter_dealloc( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 62, + "parameters": [ + "mit" + ], + "start_line": 8496, + "end_line": 8505, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiIterNew", + "long_name": "PyArray_MultiIterNew( int n , ...)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 10, + "token_count": 245, + "parameters": [ + "n" + ], + "start_line": 8576, + "end_line": 8626, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_new", + "long_name": "arraymultiter_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 11, + "token_count": 267, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8629, + "end_line": 8674, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_next", + "long_name": "arraymultiter_next( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 111, + "parameters": [ + "multi" + ], + "start_line": 8677, + "end_line": 8696, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_dealloc", + "long_name": "arraymultiter_dealloc( PyArrayMultiIterObject * multi)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 49, + "parameters": [ + "multi" + ], + "start_line": 8699, + "end_line": 8706, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_size_get", + "long_name": "arraymultiter_size_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8709, + "end_line": 8719, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_index_get", + "long_name": "arraymultiter_index_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "self" + ], + "start_line": 8722, + "end_line": 8732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_shape_get", + "long_name": "arraymultiter_shape_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 8735, + "end_line": 8738, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_iters_get", + "long_name": "arraymultiter_iters_get( PyArrayMultiIterObject * self)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 8741, + "end_line": 8753, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arraymultiter_reset", + "long_name": "arraymultiter_reset( PyArrayMultiIterObject * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 38, + "parameters": [ + "self", + "args" + ], + "start_line": 8783, + "end_line": 8790, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewFromType", + "long_name": "PyArray_DescrNewFromType( int type_num)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 1, + "token_count": 37, + "parameters": [ + "type_num" + ], + "start_line": 8849, + "end_line": 8858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNew", + "long_name": "PyArray_DescrNew( PyArray_Descr * base)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 151, + "parameters": [ + "base" + ], + "start_line": 8876, + "end_line": 8898, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_dealloc", + "long_name": "arraydescr_dealloc( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 8904, + "end_line": 8914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_subdescr_get", + "long_name": "arraydescr_subdescr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 8933, + "end_line": 8941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_typestr_get", + "long_name": "arraydescr_protocol_typestr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 79, + "parameters": [ + "self" + ], + "start_line": 8944, + "end_line": 8959, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_typename_get", + "long_name": "arraydescr_typename_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 22, + "complexity": 5, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 8962, + "end_line": 8984, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_base_get", + "long_name": "arraydescr_base_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self" + ], + "start_line": 8987, + "end_line": 8995, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_shape_get", + "long_name": "arraydescr_shape_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 51, + "parameters": [ + "self" + ], + "start_line": 8998, + "end_line": 9005, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_protocol_descr_get", + "long_name": "arraydescr_protocol_descr_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 119, + "parameters": [ + "self" + ], + "start_line": 9008, + "end_line": 9027, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isbuiltin_get", + "long_name": "arraydescr_isbuiltin_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 9034, + "end_line": 9041, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_isnative_get", + "long_name": "arraydescr_isnative_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 9044, + "end_line": 9051, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_fields_get", + "long_name": "arraydescr_fields_get( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 3, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 9054, + "end_line": 9061, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_new", + "long_name": "arraydescr_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 48, + "complexity": 13, + "token_count": 272, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 9109, + "end_line": 9161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 54, + "complexity": 13, + "token_count": 395, + "parameters": [ + "self", + "args" + ], + "start_line": 9167, + "end_line": 9228, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 9, + "token_count": 264, + "parameters": [ + "self", + "args" + ], + "start_line": 9236, + "end_line": 9279, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 44, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrNewByteorder", + "long_name": "PyArray_DescrNewByteorder( PyArray_Descr * self , char newendian)", + "filename": "arrayobject.c", + "nloc": 63, + "complexity": 16, + "token_count": 386, + "parameters": [ + "self", + "newendian" + ], + "start_line": 9300, + "end_line": 9366, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_newbyteorder", + "long_name": "arraydescr_newbyteorder( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 47, + "parameters": [ + "self", + "args" + ], + "start_line": 9377, + "end_line": 9385, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_str", + "long_name": "arraydescr_str( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 45, + "complexity": 6, + "token_count": 287, + "parameters": [ + "self" + ], + "start_line": 9400, + "end_line": 9445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_repr", + "long_name": "arraydescr_repr( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 9448, + "end_line": 9457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_compare", + "long_name": "arraydescr_compare( PyArray_Descr * self , PyObject * other)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "other" + ], + "start_line": 9460, + "end_line": 9470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "descr_length", + "long_name": "descr_length( PyArray_Descr * self)", + "filename": "arrayobject.c", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 9477, + "end_line": 9484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "descr_subscript", + "long_name": "descr_subscript( PyArray_Descr * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 31, + "complexity": 5, + "token_count": 126, + "parameters": [ + "self", + "op" + ], + "start_line": 9487, + "end_line": 9518, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "PyArray_NewFlagsObject", + "long_name": "PyArray_NewFlagsObject( PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 3, + "token_count": 96, + "parameters": [ + "obj" + ], + "start_line": 9596, + "end_line": 9613, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_dealloc", + "long_name": "arrayflags_dealloc( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 9616, + "end_line": 9620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_forc_get", + "long_name": "arrayflags_forc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self" + ], + "start_line": 9644, + "end_line": 9656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_fnc_get", + "long_name": "arrayflags_fnc_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9659, + "end_line": 9671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_farray_get", + "long_name": "arrayflags_farray_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 9674, + "end_line": 9687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_num_get", + "long_name": "arrayflags_num_get( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 9690, + "end_line": 9693, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_updateifcopy_set", + "long_name": "arrayflags_updateifcopy_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9697, + "end_line": 9709, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_aligned_set", + "long_name": "arrayflags_aligned_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9712, + "end_line": 9725, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_writeable_set", + "long_name": "arrayflags_writeable_set( PyArrayFlagsObject * self , PyObject * obj)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 4, + "token_count": 83, + "parameters": [ + "self", + "obj" + ], + "start_line": 9728, + "end_line": 9741, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_getitem", + "long_name": "arrayflags_getitem( PyArrayFlagsObject * self , PyObject * ind)", + "filename": "arrayobject.c", + "nloc": 75, + "complexity": 31, + "token_count": 431, + "parameters": [ + "self", + "ind" + ], + "start_line": 9797, + "end_line": 9872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_setitem", + "long_name": "arrayflags_setitem( PyArrayFlagsObject * self , PyObject * ind , PyObject * item)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 14, + "token_count": 219, + "parameters": [ + "self", + "ind", + "item" + ], + "start_line": 9875, + "end_line": 9895, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "_torf_", + "long_name": "_torf_( int flags , int val)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 2, + "token_count": 27, + "parameters": [ + "flags", + "val" + ], + "start_line": 9898, + "end_line": 9902, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_print", + "long_name": "arrayflags_print( PyArrayFlagsObject * self)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 1, + "token_count": 77, + "parameters": [ + "self" + ], + "start_line": 9905, + "end_line": 9917, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "arrayflags_new", + "long_name": "arrayflags_new( PyTypeObject * self , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 72, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 9932, + "end_line": 9944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "arraydescr_new", + "long_name": "arraydescr_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 57, + "complexity": 15, + "token_count": 304, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 9109, + "end_line": 9170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 62, + "top_nesting_level": 0 + } + ], + "nloc": 7954, + "complexity": 1741, + "token_count": 46325, + "diff_parsed": { + "added": [ + "\t\telse if PyList_Check(odescr) {", + "\t\t\tif ((conv == NULL) &&", + "\t\t\t (!PyErr_Occurred())) {", + "\t\t\t\tPyErr_SetString(PyExc_ValueError,", + "\t\t\t\t\t\t\"cannot specify align=1 \"\\", + "\t\t\t\t\t\t\"with array_descriptor \"\\", + "\t\t\t\t\t\t\"specification of the data-\"\\", + "\t\t\t\t\t\t\"type.\");", + "\t\t\t}", + "\t\t}" + ], + "deleted": [ + "\t\telse if PyList_Check(odescr)" + ] + } + }, + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -764,12 +764,33 @@ static int\n }\n /**end repeat**/\n \n+/**begin repeat\n+ #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3#\n+ #Name=(Byte,UByte,Short,UShort,Int,UInt,Long,ULong,LongLong,ULongLong,Float,Double,LongDouble,CFloat,CDouble,CLongDouble)*3#\n+ #cmplx=(,,,,,,,,,,,,,.real,.real,.real)*3#\n+ #which=int*16,long*16,float*16#\n+ #func=PyInt_FromLong*16,(PyLong_FromLongLong, PyLong_FromUnsignedLongLong)*5,PyLong_FromDouble*6,PyFloat_FromDouble*16#\n+**/\n+static PyObject *\n+@name@_@which@(PyObject *obj)\n+{\n+ return @func@((PyArrayScalar_VAL(obj, @Name@))@cmplx@);\n+}\n+/**end repeat**/\n+\n \n /**begin repeat\n- #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n- #oper=int*16, long*16, float*16, oct*16, hex*16#\n+ #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*2#\n+ #oper=oct*16, hex*16#\n **/\n-#define @name@_@oper@ NULL\n+static PyObject *\n+@name@_@oper@(PyObject *obj)\n+{\n+ PyObject *pyint;\n+ pyint = @name@_int(obj);\n+ if (pyint == NULL) return NULL;\n+ return PyInt_Type.tp_as_number->nb_@oper@(pyint);\n+}\n /**end repeat**/\n \n \n", + "added_lines": 24, + "deleted_lines": 3, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/ufuncobject.h\"\n#include \"numpy/arrayscalars.h\"\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZENAME=BYTE*2,SHORT*2,INT*2,LONG*2#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n**/\n#if SIZEOF_@SIZE@ > SIZEOF_@SIZENAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n\t generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n**/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n\tgenerate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #neg=(1,0)*5#\n**/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n if (b == 0) {\n\tgenerate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if (b == -1 && a < 0 && a == -a) {\n\tgenerate_overflow_error();\n\t*out = a / b;\n }\n#endif\n else {\n\t*out = a / b;\n }\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\nstatic void\n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {\n if (a == 0 || b == 0) {\n\tif (b == 0) generate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if ((a > 0) == (b > 0)) {\n\t*out = a % b;\n }\n else { /* handled like Python does */\n\t*out = a % b;\n\tif (*out) *out += b;\n }\n#else\n *out = a % b;\n#endif\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n**/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n *(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/* b will always be positive in this call */\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n \n}\n/**end repeat**/\n\n\n\n/* QUESTION: Should we check for overflow / underflow in (l,r)shift? */\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n**/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_floor)(@name@);\nstatic @name@ (*_basic_@name@_sqrt)(@name@);\nstatic @name@ (*_basic_@name@_abs)(@name@);\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) \\\n *(outp) = _basic_@name@_floor((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\\\n (outp)->real = (a).real + (b).real;\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\\\n (outp)->real = (a).real - (b).real;\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do {\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) /\t\\\n ((a).real*(b).real + (b).imag*(b).imag);\t\t\t\\\n (outp)->imag = 0;\t\t\t\t\t\t\\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - _basic_@name@_floor(a/b)*b;\n} \n/**end repeat**/ \n\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_ctype_divmod(a, b, out, out2) {\t\\\n @name@_ctype_floor_divide(a, b, out);\t\\\n @name@_ctype_remainder(a, b, out2);\t\t\\\n }\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_pow)(@name@ a, @name@ b);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = _basic_@name@_pow(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #uns=(1,0)*5,0*3#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n#if @uns@\n generate_overflow_error();\n#endif\n *out = -a;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n/* Get the nc_powf, nc_pow, and nc_powl functions from \n the data area of the power ufunc in umathmodule. \n*/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n out->real = a.real;\n out->imag = a.imag;\n}\nstatic void (*_basic_@name@_pow)(@name@ *, @name@ *, @name@ *);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out)\n{\n _basic_@name@_pow(&a, &b, out);\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=ubyte, ushort, uint, ulong, ulonglong#\n**/\n#define @name@_ctype_absolute @name@_ctype_positive\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte, short, int, long, longlong#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = (a < 0 ? -a : a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = _basic_@name@_abs(a);\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #rname= float, double, longdouble#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = _basic_@rname@_sqrt(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, floor_divide*6, true_divide*6, divmod*3, remainder*3#\n #fperr=1*70,0*50,1*52#\n #twoout=0*50,1*10,0*106,1*3,0*3#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*12, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*12, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n**/\n\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @twoout@\n @otyp@ out2;\n PyObject *obj;\n#endif\n\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @twoout@\n @name@_ctype_@oper@(arg1, arg2, &out, &out2);\n#else\n @name@_ctype_@oper@(arg1, arg2, &out);\n#endif\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n\n#if @twoout@\n ret = PyTuple_New(2);\n if (ret==NULL) return NULL;\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out;\n PyTuple_SET_ITEM(ret, 0, obj);\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out2;\n PyTuple_SET_ITEM(ret, 1, obj);\n#else\n ret = PyArrayScalar_New(@OName@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @OName@) = out;\n#endif\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float, double, longdouble, cfloat, cdouble, clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #otyp=float*4, double*6, float, double, longdouble, cfloat, cdouble, clongdouble#\n #OName=Float*4, Double*6, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #isint=(1,0)*5,0*6#\n #cmplx=0*13,1*3#\n**/\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n @otyp@ out1;\n int retstatus;\n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n }\n\n PyUFunc_clearfperr();\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @cmplx@\n if (arg2.real == 0 && arg1.real == 0) {\n\tout1.real = out.real = 1.0;\n\tout1.imag = out.imag = 0.0;\n }\n#else\n if (arg2 == 0) {\n\tout1 = out = 1;\n } \n#endif\n#if @isint@\n else if (arg2 < 0) {\n\t@name@_ctype_power(arg1, -arg2, &out);\n\tout1 = 1.0 / out;\n }\n#endif\n else {\n\t@name@_ctype_power(arg1, arg2, &out);\n }\n\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n\n#if @isint@\n if (arg2 < 0) {\n\tret = PyArrayScalar_New(@OName@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @OName@) = out1;\n }\n else {\n\tret = PyArrayScalar_New(@Name@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @Name@) = out;\n }\n#else\n ret = PyArrayScalar_New(@Name@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @Name@) = out;\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n#name=(cfloat,cdouble,clongdouble)*2#\n#oper=divmod*3,remainder*3#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3, byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*3, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n #oper=negative*16, positive*16, absolute*16, invert*10#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n#name=float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_invert NULL\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3#\n #Name=(Byte,UByte,Short,UShort,Int,UInt,Long,ULong,LongLong,ULongLong,Float,Double,LongDouble,CFloat,CDouble,CLongDouble)*3#\n #cmplx=(,,,,,,,,,,,,,.real,.real,.real)*3#\n #which=int*16,long*16,float*16#\n #func=PyInt_FromLong*16,(PyLong_FromLongLong, PyLong_FromUnsignedLongLong)*5,PyLong_FromDouble*6,PyFloat_FromDouble*16#\n**/\nstatic PyObject *\n@name@_@which@(PyObject *obj)\n{\n return @func@((PyArrayScalar_VAL(obj, @Name@))@cmplx@);\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*2#\n #oper=oct*16, hex*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *obj)\n{\n PyObject *pyint;\n pyint = @name@_int(obj);\n if (pyint == NULL) return NULL;\n return PyInt_Type.tp_as_number->nb_@oper@(pyint);\n}\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) {\n\tPyArrayScalar_RETURN_TRUE;\n }\n else {\n\tPyArrayScalar_RETURN_FALSE;\n }\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic int\nget_functions(void)\n{\n PyObject *mm, *obj;\n void **funcdata;\n char *signatures;\n int i, j;\n int ret = -1;\n\t\n /* Get the nc_pow functions */\n /* Get the pow functions */\n mm = PyImport_ImportModule(\"numpy.core.umath\");\n if (mm == NULL) return -1;\n \n obj = PyObject_GetAttrString(mm, \"power\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_pow = funcdata[j];\n _basic_double_pow = funcdata[j+1];\n _basic_longdouble_pow = funcdata[j+2];\n _basic_cfloat_pow = funcdata[j+3];\n _basic_cdouble_pow = funcdata[j+4];\n _basic_clongdouble_pow = funcdata[j+5];\n Py_DECREF(obj);\n\n /* Get the floor functions */\n obj = PyObject_GetAttrString(mm, \"floor\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n _basic_float_floor = funcdata[j];\n _basic_double_floor = funcdata[j+1];\n _basic_longdouble_floor = funcdata[j+2];\n Py_DECREF(obj);\n\n /* Get the sqrt functions */\n obj = PyObject_GetAttrString(mm, \"sqrt\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n _basic_float_sqrt = funcdata[j];\n _basic_double_sqrt = funcdata[j+1];\n _basic_longdouble_sqrt = funcdata[j+2];\n Py_DECREF(obj);\n\n /* Get the abs functions */\n obj = PyObject_GetAttrString(mm, \"absolute\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n _basic_float_abs = funcdata[j];\n _basic_double_abs = funcdata[j+1];\n _basic_longdouble_abs = funcdata[j+2];\n Py_DECREF(obj);\n\n ret = 0;\n fail:\n Py_DECREF(mm);\n return ret;\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n if (get_functions() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/ufuncobject.h\"\n#include \"numpy/arrayscalars.h\"\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZENAME=BYTE*2,SHORT*2,INT*2,LONG*2#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n**/\n#if SIZEOF_@SIZE@ > SIZEOF_@SIZENAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n\t generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n**/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n\tgenerate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #neg=(1,0)*5#\n**/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n if (b == 0) {\n\tgenerate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if (b == -1 && a < 0 && a == -a) {\n\tgenerate_overflow_error();\n\t*out = a / b;\n }\n#endif\n else {\n\t*out = a / b;\n }\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\nstatic void\n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {\n if (a == 0 || b == 0) {\n\tif (b == 0) generate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if ((a > 0) == (b > 0)) {\n\t*out = a % b;\n }\n else { /* handled like Python does */\n\t*out = a % b;\n\tif (*out) *out += b;\n }\n#else\n *out = a % b;\n#endif\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n**/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n *(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/* b will always be positive in this call */\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n \n}\n/**end repeat**/\n\n\n\n/* QUESTION: Should we check for overflow / underflow in (l,r)shift? */\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n**/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_floor)(@name@);\nstatic @name@ (*_basic_@name@_sqrt)(@name@);\nstatic @name@ (*_basic_@name@_abs)(@name@);\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) \\\n *(outp) = _basic_@name@_floor((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\\\n (outp)->real = (a).real + (b).real;\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\\\n (outp)->real = (a).real - (b).real;\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do {\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) /\t\\\n ((a).real*(b).real + (b).imag*(b).imag);\t\t\t\\\n (outp)->imag = 0;\t\t\t\t\t\t\\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - _basic_@name@_floor(a/b)*b;\n} \n/**end repeat**/ \n\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_ctype_divmod(a, b, out, out2) {\t\\\n @name@_ctype_floor_divide(a, b, out);\t\\\n @name@_ctype_remainder(a, b, out2);\t\t\\\n }\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_pow)(@name@ a, @name@ b);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = _basic_@name@_pow(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #uns=(1,0)*5,0*3#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n#if @uns@\n generate_overflow_error();\n#endif\n *out = -a;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n/* Get the nc_powf, nc_pow, and nc_powl functions from \n the data area of the power ufunc in umathmodule. \n*/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n out->real = a.real;\n out->imag = a.imag;\n}\nstatic void (*_basic_@name@_pow)(@name@ *, @name@ *, @name@ *);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out)\n{\n _basic_@name@_pow(&a, &b, out);\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=ubyte, ushort, uint, ulong, ulonglong#\n**/\n#define @name@_ctype_absolute @name@_ctype_positive\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte, short, int, long, longlong#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = (a < 0 ? -a : a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = _basic_@name@_abs(a);\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #rname= float, double, longdouble#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = _basic_@rname@_sqrt(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, floor_divide*6, true_divide*6, divmod*3, remainder*3#\n #fperr=1*70,0*50,1*52#\n #twoout=0*50,1*10,0*106,1*3,0*3#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*12, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*12, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n**/\n\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @twoout@\n @otyp@ out2;\n PyObject *obj;\n#endif\n\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @twoout@\n @name@_ctype_@oper@(arg1, arg2, &out, &out2);\n#else\n @name@_ctype_@oper@(arg1, arg2, &out);\n#endif\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n\n#if @twoout@\n ret = PyTuple_New(2);\n if (ret==NULL) return NULL;\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out;\n PyTuple_SET_ITEM(ret, 0, obj);\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out2;\n PyTuple_SET_ITEM(ret, 1, obj);\n#else\n ret = PyArrayScalar_New(@OName@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @OName@) = out;\n#endif\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float, double, longdouble, cfloat, cdouble, clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #otyp=float*4, double*6, float, double, longdouble, cfloat, cdouble, clongdouble#\n #OName=Float*4, Double*6, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #isint=(1,0)*5,0*6#\n #cmplx=0*13,1*3#\n**/\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n @otyp@ out1;\n int retstatus;\n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n }\n\n PyUFunc_clearfperr();\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @cmplx@\n if (arg2.real == 0 && arg1.real == 0) {\n\tout1.real = out.real = 1.0;\n\tout1.imag = out.imag = 0.0;\n }\n#else\n if (arg2 == 0) {\n\tout1 = out = 1;\n } \n#endif\n#if @isint@\n else if (arg2 < 0) {\n\t@name@_ctype_power(arg1, -arg2, &out);\n\tout1 = 1.0 / out;\n }\n#endif\n else {\n\t@name@_ctype_power(arg1, arg2, &out);\n }\n\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n\n#if @isint@\n if (arg2 < 0) {\n\tret = PyArrayScalar_New(@OName@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @OName@) = out1;\n }\n else {\n\tret = PyArrayScalar_New(@Name@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @Name@) = out;\n }\n#else\n ret = PyArrayScalar_New(@Name@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @Name@) = out;\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n#name=(cfloat,cdouble,clongdouble)*2#\n#oper=divmod*3,remainder*3#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3, byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*3, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n #oper=negative*16, positive*16, absolute*16, invert*10#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n#name=float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_invert NULL\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#\n #oper=int*16, long*16, float*16, oct*16, hex*16#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) {\n\tPyArrayScalar_RETURN_TRUE;\n }\n else {\n\tPyArrayScalar_RETURN_FALSE;\n }\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic int\nget_functions(void)\n{\n PyObject *mm, *obj;\n void **funcdata;\n char *signatures;\n int i, j;\n int ret = -1;\n\t\n /* Get the nc_pow functions */\n /* Get the pow functions */\n mm = PyImport_ImportModule(\"numpy.core.umath\");\n if (mm == NULL) return -1;\n \n obj = PyObject_GetAttrString(mm, \"power\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_pow = funcdata[j];\n _basic_double_pow = funcdata[j+1];\n _basic_longdouble_pow = funcdata[j+2];\n _basic_cfloat_pow = funcdata[j+3];\n _basic_cdouble_pow = funcdata[j+4];\n _basic_clongdouble_pow = funcdata[j+5];\n Py_DECREF(obj);\n\n /* Get the floor functions */\n obj = PyObject_GetAttrString(mm, \"floor\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n _basic_float_floor = funcdata[j];\n _basic_double_floor = funcdata[j+1];\n _basic_longdouble_floor = funcdata[j+2];\n Py_DECREF(obj);\n\n /* Get the sqrt functions */\n obj = PyObject_GetAttrString(mm, \"sqrt\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n _basic_float_sqrt = funcdata[j];\n _basic_double_sqrt = funcdata[j+1];\n _basic_longdouble_sqrt = funcdata[j+2];\n Py_DECREF(obj);\n\n /* Get the abs functions */\n obj = PyObject_GetAttrString(mm, \"absolute\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n _basic_float_abs = funcdata[j];\n _basic_double_abs = funcdata[j+1];\n _basic_longdouble_abs = funcdata[j+2];\n Py_DECREF(obj);\n\n ret = 0;\n fail:\n Py_DECREF(mm);\n return ret;\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n if (get_functions() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "/**begin repeat", + " #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3#", + " #Name=(Byte,UByte,Short,UShort,Int,UInt,Long,ULong,LongLong,ULongLong,Float,Double,LongDouble,CFloat,CDouble,CLongDouble)*3#", + " #cmplx=(,,,,,,,,,,,,,.real,.real,.real)*3#", + " #which=int*16,long*16,float*16#", + " #func=PyInt_FromLong*16,(PyLong_FromLongLong, PyLong_FromUnsignedLongLong)*5,PyLong_FromDouble*6,PyFloat_FromDouble*16#", + "**/", + "static PyObject *", + "@name@_@which@(PyObject *obj)", + "{", + " return @func@((PyArrayScalar_VAL(obj, @Name@))@cmplx@);", + "}", + "/**end repeat**/", + "", + " #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*2#", + " #oper=oct*16, hex*16#", + "static PyObject *", + "@name@_@oper@(PyObject *obj)", + "{", + " PyObject *pyint;", + " pyint = @name@_int(obj);", + " if (pyint == NULL) return NULL;", + " return PyInt_Type.tp_as_number->nb_@oper@(pyint);", + "}" + ], + "deleted": [ + " #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*5#", + " #oper=int*16, long*16, float*16, oct*16, hex*16#", + "#define @name@_@oper@ NULL" + ] + } + } + ] + }, + { + "hash": "b3bf22851ebe0096dcf504f9576ce6d14ff42817", + "msg": "Fix absolute which does not contain the needed functions...", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-04-29T22:39:27+00:00", + "author_timezone": 0, + "committer_date": "2006-04-29T22:39:27+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "f6a6d8fde5eb4a02505c02980b74812f26d16642" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 26, + "insertions": 1, + "lines": 27, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalarmathmodule.c.src", + "new_path": "numpy/core/src/scalarmathmodule.c.src", + "filename": "scalarmathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -273,7 +273,6 @@ static void\n **/\n static @name@ (*_basic_@name@_floor)(@name@);\n static @name@ (*_basic_@name@_sqrt)(@name@);\n-static @name@ (*_basic_@name@_abs)(@name@);\n #define @name@_ctype_add(a, b, outp) *(outp) = a + b\n #define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n #define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n@@ -409,7 +408,7 @@ static void\n \n \n /**begin repeat\n- #name=byte, short, int, long, longlong#\n+ #name=byte, short, int, long, longlong, float, double, longdouble#\n **/\n static void\n @name@_ctype_absolute(@name@ a, @name@ *out)\n@@ -418,17 +417,6 @@ static void\n }\n /**end repeat**/\n \n-/**begin repeat\n- #name=float, double, longdouble#\n-**/\n-static void\n-@name@_ctype_absolute(@name@ a, @name@ *out)\n-{\n- *out = _basic_@name@_abs(a);\n-}\n-/**end repeat**/\n-\n-\n /**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #rname= float, double, longdouble#\n@@ -987,19 +975,6 @@ get_functions(void)\n _basic_longdouble_sqrt = funcdata[j+2];\n Py_DECREF(obj);\n \n- /* Get the abs functions */\n- obj = PyObject_GetAttrString(mm, \"absolute\");\n- if (obj == NULL) goto fail;\n- funcdata = ((PyUFuncObject *)obj)->data;\n- signatures = ((PyUFuncObject *)obj)->types;\n- i = 0;\n- j = 0;\n- while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n- _basic_float_abs = funcdata[j];\n- _basic_double_abs = funcdata[j+1];\n- _basic_longdouble_abs = funcdata[j+2];\n- Py_DECREF(obj);\n-\n ret = 0;\n fail:\n Py_DECREF(mm);\n", + "added_lines": 1, + "deleted_lines": 26, + "source_code": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/ufuncobject.h\"\n#include \"numpy/arrayscalars.h\"\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZENAME=BYTE*2,SHORT*2,INT*2,LONG*2#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n**/\n#if SIZEOF_@SIZE@ > SIZEOF_@SIZENAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n\t generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n**/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n\tgenerate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #neg=(1,0)*5#\n**/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n if (b == 0) {\n\tgenerate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if (b == -1 && a < 0 && a == -a) {\n\tgenerate_overflow_error();\n\t*out = a / b;\n }\n#endif\n else {\n\t*out = a / b;\n }\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\nstatic void\n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {\n if (a == 0 || b == 0) {\n\tif (b == 0) generate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if ((a > 0) == (b > 0)) {\n\t*out = a % b;\n }\n else { /* handled like Python does */\n\t*out = a % b;\n\tif (*out) *out += b;\n }\n#else\n *out = a % b;\n#endif\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n**/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n *(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/* b will always be positive in this call */\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n \n}\n/**end repeat**/\n\n\n\n/* QUESTION: Should we check for overflow / underflow in (l,r)shift? */\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n**/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_floor)(@name@);\nstatic @name@ (*_basic_@name@_sqrt)(@name@);\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) \\\n *(outp) = _basic_@name@_floor((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\\\n (outp)->real = (a).real + (b).real;\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\\\n (outp)->real = (a).real - (b).real;\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do {\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) /\t\\\n ((a).real*(b).real + (b).imag*(b).imag);\t\t\t\\\n (outp)->imag = 0;\t\t\t\t\t\t\\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - _basic_@name@_floor(a/b)*b;\n} \n/**end repeat**/ \n\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_ctype_divmod(a, b, out, out2) {\t\\\n @name@_ctype_floor_divide(a, b, out);\t\\\n @name@_ctype_remainder(a, b, out2);\t\t\\\n }\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_pow)(@name@ a, @name@ b);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = _basic_@name@_pow(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #uns=(1,0)*5,0*3#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n#if @uns@\n generate_overflow_error();\n#endif\n *out = -a;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n/* Get the nc_powf, nc_pow, and nc_powl functions from \n the data area of the power ufunc in umathmodule. \n*/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n out->real = a.real;\n out->imag = a.imag;\n}\nstatic void (*_basic_@name@_pow)(@name@ *, @name@ *, @name@ *);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out)\n{\n _basic_@name@_pow(&a, &b, out);\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=ubyte, ushort, uint, ulong, ulonglong#\n**/\n#define @name@_ctype_absolute @name@_ctype_positive\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte, short, int, long, longlong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = (a < 0 ? -a : a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #rname= float, double, longdouble#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = _basic_@rname@_sqrt(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, floor_divide*6, true_divide*6, divmod*3, remainder*3#\n #fperr=1*70,0*50,1*52#\n #twoout=0*50,1*10,0*106,1*3,0*3#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*12, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*12, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n**/\n\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @twoout@\n @otyp@ out2;\n PyObject *obj;\n#endif\n\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @twoout@\n @name@_ctype_@oper@(arg1, arg2, &out, &out2);\n#else\n @name@_ctype_@oper@(arg1, arg2, &out);\n#endif\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n\n#if @twoout@\n ret = PyTuple_New(2);\n if (ret==NULL) return NULL;\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out;\n PyTuple_SET_ITEM(ret, 0, obj);\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out2;\n PyTuple_SET_ITEM(ret, 1, obj);\n#else\n ret = PyArrayScalar_New(@OName@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @OName@) = out;\n#endif\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float, double, longdouble, cfloat, cdouble, clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #otyp=float*4, double*6, float, double, longdouble, cfloat, cdouble, clongdouble#\n #OName=Float*4, Double*6, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #isint=(1,0)*5,0*6#\n #cmplx=0*13,1*3#\n**/\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n @otyp@ out1;\n int retstatus;\n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n }\n\n PyUFunc_clearfperr();\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @cmplx@\n if (arg2.real == 0 && arg1.real == 0) {\n\tout1.real = out.real = 1.0;\n\tout1.imag = out.imag = 0.0;\n }\n#else\n if (arg2 == 0) {\n\tout1 = out = 1;\n } \n#endif\n#if @isint@\n else if (arg2 < 0) {\n\t@name@_ctype_power(arg1, -arg2, &out);\n\tout1 = 1.0 / out;\n }\n#endif\n else {\n\t@name@_ctype_power(arg1, arg2, &out);\n }\n\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n\n#if @isint@\n if (arg2 < 0) {\n\tret = PyArrayScalar_New(@OName@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @OName@) = out1;\n }\n else {\n\tret = PyArrayScalar_New(@Name@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @Name@) = out;\n }\n#else\n ret = PyArrayScalar_New(@Name@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @Name@) = out;\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n#name=(cfloat,cdouble,clongdouble)*2#\n#oper=divmod*3,remainder*3#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3, byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*3, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n #oper=negative*16, positive*16, absolute*16, invert*10#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n#name=float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_invert NULL\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3#\n #Name=(Byte,UByte,Short,UShort,Int,UInt,Long,ULong,LongLong,ULongLong,Float,Double,LongDouble,CFloat,CDouble,CLongDouble)*3#\n #cmplx=(,,,,,,,,,,,,,.real,.real,.real)*3#\n #which=int*16,long*16,float*16#\n #func=PyInt_FromLong*16,(PyLong_FromLongLong, PyLong_FromUnsignedLongLong)*5,PyLong_FromDouble*6,PyFloat_FromDouble*16#\n**/\nstatic PyObject *\n@name@_@which@(PyObject *obj)\n{\n return @func@((PyArrayScalar_VAL(obj, @Name@))@cmplx@);\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*2#\n #oper=oct*16, hex*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *obj)\n{\n PyObject *pyint;\n pyint = @name@_int(obj);\n if (pyint == NULL) return NULL;\n return PyInt_Type.tp_as_number->nb_@oper@(pyint);\n}\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) {\n\tPyArrayScalar_RETURN_TRUE;\n }\n else {\n\tPyArrayScalar_RETURN_FALSE;\n }\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic int\nget_functions(void)\n{\n PyObject *mm, *obj;\n void **funcdata;\n char *signatures;\n int i, j;\n int ret = -1;\n\t\n /* Get the nc_pow functions */\n /* Get the pow functions */\n mm = PyImport_ImportModule(\"numpy.core.umath\");\n if (mm == NULL) return -1;\n \n obj = PyObject_GetAttrString(mm, \"power\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_pow = funcdata[j];\n _basic_double_pow = funcdata[j+1];\n _basic_longdouble_pow = funcdata[j+2];\n _basic_cfloat_pow = funcdata[j+3];\n _basic_cdouble_pow = funcdata[j+4];\n _basic_clongdouble_pow = funcdata[j+5];\n Py_DECREF(obj);\n\n /* Get the floor functions */\n obj = PyObject_GetAttrString(mm, \"floor\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n _basic_float_floor = funcdata[j];\n _basic_double_floor = funcdata[j+1];\n _basic_longdouble_floor = funcdata[j+2];\n Py_DECREF(obj);\n\n /* Get the sqrt functions */\n obj = PyObject_GetAttrString(mm, \"sqrt\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n _basic_float_sqrt = funcdata[j];\n _basic_double_sqrt = funcdata[j+1];\n _basic_longdouble_sqrt = funcdata[j+2];\n Py_DECREF(obj);\n\n ret = 0;\n fail:\n Py_DECREF(mm);\n return ret;\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n if (get_functions() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "source_code_before": "/* -*- c -*- */\n\n/* The purpose of this module is to add faster math for array scalars\n that does not go through the ufunc machinery \n\n but still supports error-modes. \n*/\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#include \"numpy/ufuncobject.h\"\n#include \"numpy/arrayscalars.h\"\n\n\n/** numarray adapted routines.... **/\n\nstatic int ulonglong_overflow(ulonglong a, ulonglong b)\n{\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n return z || (x>>32) || (y>>32) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>64) || (y>>64) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n return 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n ulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n if (a0 < 0) { a = -a0; } else { a = a0; }\n if (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n ah = (a >> 32);\n al = (a & 0xFFFFFFFFL);\n bh = (b >> 32);\n bl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n ah = (a >> 64);\n al = (a & 0xFFFFFFFFFFFFFFFFL);\n bh = (b >> 64);\n bl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n ah = al = bh = bl = 0;\n#endif\n\n w = al*bl;\n x = bh*al;\n y = ah*bl;\n z = ah*bh;\n\n /*\n ulonglong c = ((x + y)<<32) + w;\n if ((a0 < 0) ^ (b0 < 0))\n *c = -c;\n else\n *c = c\n */\n\n#if SIZEOF_LONGLONG == 64\n return z || (x>>31) || (y>>31) ||\n\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n return z || (x>>63) || (y>>63) ||\n\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n return 0;\n#endif\n}\n/** end direct numarray code **/\n\n\n/* Basic operations:\n\nBINARY:\n\nadd, subtract, multiply, divide, remainder, divmod, power, \nfloor_divide, true_divide\n\nlshift, rshift, and, or, xor (integers only)\n\nUNARY:\n\nnegative, positive, absolute, nonzero, invert, int, long, float, oct, hex\n\n*/\n\n/**begin repeat\n #name=byte,short,int,long,longlong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if ((*out^a) >= 0 || (*out^b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if ((*out^a) >= 0 || (*out^~b) >= 0)\n\treturn;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n/**begin repeat\n #name=ubyte,ushort,uint,ulong,ulonglong#\n**/\nstatic void\n@name@_ctype_add(@name@ a, @name@ b, @name@ *out) {\n *out = a + b;\n if (*out >= a && *out >= b)\n\treturn;\n generate_overflow_error();\n return;\n}\nstatic void\n@name@_ctype_subtract(@name@ a, @name@ b, @name@ *out) {\n *out = a - b;\n if (a >= b) return;\n generate_overflow_error();\n return;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong#\n #big=(int,uint)*2,(longlong,ulonglong)*2#\n #NAME=BYTE,UBYTE,SHORT,USHORT,INT,UINT,LONG,ULONG#\n #SIZENAME=BYTE*2,SHORT*2,INT*2,LONG*2#\n #SIZE=INT*4,LONGLONG*4#\n #neg=(1,0)*4#\n**/\n#if SIZEOF_@SIZE@ > SIZEOF_@SIZENAME@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n @big@ temp;\n temp = ((@big@) a) * ((@big@) b);\n *out = (@name@) temp;\n#if @neg@\n if (temp > MAX_@NAME@ || temp < MIN_@NAME@)\n#else\n if (temp > MAX_@NAME@) \n#endif\n\t generate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=int,uint,long,ulong,longlong,ulonglong#\n #SIZE=INT*2,LONG*2,LONGLONG*2#\n #char=(s,u)*3#\n**/\n#if SIZEOF_LONGLONG == SIZEOF_@SIZE@\nstatic void\n@name@_ctype_multiply(@name@ a, @name@ b, @name@ *out) {\n *out = a * b;\n if (@char@longlong_overflow(a, b))\n\tgenerate_overflow_error();\n return;\n}\n#endif\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #neg=(1,0)*5#\n**/\nstatic void\n@name@_ctype_divide(@name@ a, @name@ b, @name@ *out) {\n if (b == 0) {\n\tgenerate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if (b == -1 && a < 0 && a == -a) {\n\tgenerate_overflow_error();\n\t*out = a / b;\n }\n#endif\n else {\n\t*out = a / b;\n }\n}\n#define @name@_ctype_floor_divide @name@_ctype_divide\nstatic void\n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) {\n if (a == 0 || b == 0) {\n\tif (b == 0) generate_divbyzero_error();\n\t*out = 0;\n }\n#if @neg@\n else if ((a > 0) == (b > 0)) {\n\t*out = a % b;\n }\n else { /* handled like Python does */\n\t*out = a % b;\n\tif (*out) *out += b;\n }\n#else\n *out = a % b;\n#endif\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #otyp=float*4, double*6#\n**/\n#define @name@_ctype_true_divide(a, b, out)\t\\\n *(out) = ((@otyp@) (a)) / ((@otyp@) (b));\n/**end repeat**/\n\n/* b will always be positive in this call */\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n**/\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n \n}\n/**end repeat**/\n\n\n\n/* QUESTION: Should we check for overflow / underflow in (l,r)shift? */\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*5#\n #oper=and*10, xor*10, or*10, lshift*10, rshift*10#\n #op=&*10, ^*10, |*10, <<*10, >>*10#\n**/\n#define @name@_ctype_@oper@(arg1, arg2, out) *(out) = (arg1) @op@ (arg2)\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_floor)(@name@);\nstatic @name@ (*_basic_@name@_sqrt)(@name@);\nstatic @name@ (*_basic_@name@_abs)(@name@);\n#define @name@_ctype_add(a, b, outp) *(outp) = a + b\n#define @name@_ctype_subtract(a, b, outp) *(outp) = a - b\n#define @name@_ctype_multiply(a, b, outp) *(outp) = a * b\n#define @name@_ctype_divide(a, b, outp) *(outp) = a / b\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) \\\n *(outp) = _basic_@name@_floor((a) / (b))\n/**end repeat**/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n #rtype=float, double, longdouble#\n #c=f,,l#\n**/\n#define @name@_ctype_add(a, b, outp) do{\t\\\n (outp)->real = (a).real + (b).real;\t\t\\\n (outp)->imag = (a).imag + (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_subtract(a, b, outp) do{\t\\\n (outp)->real = (a).real - (b).real;\t\t\\\n (outp)->imag = (a).imag - (b).imag;\t\t\\\n }while(0)\n#define @name@_ctype_multiply(a, b, outp) do{\t\t\t\\\n (outp)->real = (a).real * (b).real - (a).imag * (b).imag;\t\\\n (outp)->imag = (a).real * (b).imag + (a).imag * (b).real;\t\\\n }while(0)\n#define @name@_ctype_divide(a, b, outp) do{\t\t\t\\\n @rtype@ d = (a).real*(b).real + (b).imag*(b).imag;\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag)/d;\t\\\n (outp)->imag = ((a).imag*(b).real - (a).real*(b).imag)/d;\t\\\n }while(0)\n#define @name@_ctype_true_divide @name@_ctype_divide\n#define @name@_ctype_floor_divide(a, b, outp) do {\t\t\\\n (outp)->real = ((a).real*(b).real + (a).imag*(b).imag) /\t\\\n ((a).real*(b).real + (b).imag*(b).imag);\t\t\t\\\n (outp)->imag = 0;\t\t\t\t\t\t\\\n }while(0)\n/**end repeat**/\n\n/**begin repeat\n #name=float,double,longdouble#\n**/\nstatic void \n@name@_ctype_remainder(@name@ a, @name@ b, @name@ *out) { \n *out = a - _basic_@name@_floor(a/b)*b;\n} \n/**end repeat**/ \n\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_ctype_divmod(a, b, out, out2) {\t\\\n @name@_ctype_floor_divide(a, b, out);\t\\\n @name@_ctype_remainder(a, b, out2);\t\t\\\n }\n/**end repeat**/\n\n/**begin repeat\n #name= float, double, longdouble#\n**/\nstatic @name@ (*_basic_@name@_pow)(@name@ a, @name@ b);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out) {\n *out = _basic_@name@_pow(a, b);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n #uns=(1,0)*5,0*3#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n#if @uns@\n generate_overflow_error();\n#endif\n *out = -a;\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_negative(@name@ a, @name@ *out)\n{\n out->real = -a.real;\n out->imag = -a.imag;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong, float, double, longdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n *out = a;\n}\n/**end repeat**/\n\n/* Get the nc_powf, nc_pow, and nc_powl functions from \n the data area of the power ufunc in umathmodule. \n*/\n\n/**begin repeat\n #name=cfloat, cdouble, clongdouble#\n**/\nstatic void\n@name@_ctype_positive(@name@ a, @name@ *out)\n{\n out->real = a.real;\n out->imag = a.imag;\n}\nstatic void (*_basic_@name@_pow)(@name@ *, @name@ *, @name@ *);\nstatic void\n@name@_ctype_power(@name@ a, @name@ b, @name@ *out)\n{\n _basic_@name@_pow(&a, &b, out);\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=ubyte, ushort, uint, ulong, ulonglong#\n**/\n#define @name@_ctype_absolute @name@_ctype_positive\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte, short, int, long, longlong#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = (a < 0 ? -a : a);\n}\n/**end repeat**/\n\n/**begin repeat\n #name=float, double, longdouble#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n *out = _basic_@name@_abs(a);\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name= cfloat, cdouble, clongdouble#\n #rname= float, double, longdouble#\n**/\nstatic void\n@name@_ctype_absolute(@name@ a, @name@ *out)\n{\n out->real = _basic_@rname@_sqrt(a.real*a.real + a.imag*a.imag);\n out->imag = 0;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte, ubyte, short, ushort, int, uint, long, ulong, longlong, ulonglong#\n**/\n#define @name@_ctype_invert(a, out) *(out) = ~a;\n/**end repeat**/\n\n/*** END OF BASIC CODE **/\n\n\n/* The general strategy for commutative binary operators is to\n\n1) Convert the types to the common type if both are scalars (0 return)\n2) If both are not scalars use ufunc machinery (-2 return)\n3) If both are scalars but cannot be cast to the right type \nreturn NotImplmented (-1 return)\n\n4) Perform the function on the C-type.\n5) If an error condition occurred, check to see\nwhat the current error-handling is and handle the error.\n\n6) Construct and return the output scalar.\n*/\n\t \n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #NAME=BYTE, UBYTE, SHORT, USHORT, INT, UINT, LONG, ULONG, LONGLONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n**/ \n\nstatic int\n_@name@_convert_to_ctype(PyObject *a, @name@ *arg1)\n{\n PyObject *temp; \n\n if (PyArray_IsScalar(a, @Name@)) {\n\t*arg1 = PyArrayScalar_VAL(a, @Name@);\n\treturn 0;\n }\n else if (PyArray_IsScalar(a, Generic)) {\n\tPyArray_Descr *descr1;\n\tint ret;\n\tif (!PyArray_IsScalar(a, Number)) return -1;\n\tdescr1 = PyArray_DescrFromTypeObject((PyObject *)(a->ob_type));\n \tif (PyArray_CanCastSafely(descr1->type_num, PyArray_@NAME@)) {\n\t PyArray_CastScalarDirect(a, descr1, arg1, PyArray_@NAME@);\n\t ret = 0;\n\t}\n\telse ret = -1;\n\tPy_DECREF(descr1);\n\treturn ret;\n }\n else if ((temp = PyArray_ScalarFromObject(a)) != NULL) {\n\treturn _@name@_convert_to_ctype(temp, arg1);\n }\n return -2;\n}\t\n\nstatic int\n_@name@_convert2_to_ctypes(PyObject *a, @name@ *arg1, \n\t\t\t PyObject *b, @name@ *arg2)\n{\n int ret;\n ret = _@name@_convert_to_ctype(a, arg1);\n if (ret < 0) return ret;\n ret = _@name@_convert_to_ctype(b, arg2);\n if (ret < 0) return ret;\n return 0;\n}\n\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*13, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*13, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n #oper=add*10, subtract*10, multiply*10, divide*10, remainder*10, divmod*10, floor_divide*10, lshift*10, rshift*10, and*10, or*10, xor*10, true_divide*10, add*6, subtract*6, multiply*6, divide*6, floor_divide*6, true_divide*6, divmod*3, remainder*3#\n #fperr=1*70,0*50,1*52#\n #twoout=0*50,1*10,0*106,1*3,0*3#\n #otyp=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong)*12, float*4, double*6, (float, double, longdouble, cfloat, cdouble, clongdouble)*6, (float, double, longdouble)*2#\n #OName=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong)*12, Float*4, Double*6, (Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*6, (Float, Double, LongDouble)*2#\n**/\n\nstatic PyObject *\n@name@_@oper@(PyObject *a, PyObject *b)\n{\n PyObject *ret;\n @name@ arg1, arg2;\n @otyp@ out;\n#if @twoout@\n @otyp@ out2;\n PyObject *obj;\n#endif\n\n#if @fperr@\n int retstatus;\n#endif \n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a,b);\n }\n\n#if @fperr@\n PyUFunc_clearfperr();\n#endif\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @twoout@\n @name@_ctype_@oper@(arg1, arg2, &out, &out2);\n#else\n @name@_ctype_@oper@(arg1, arg2, &out);\n#endif\n\n#if @fperr@\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n#endif\n\n#if @twoout@\n ret = PyTuple_New(2);\n if (ret==NULL) return NULL;\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out;\n PyTuple_SET_ITEM(ret, 0, obj);\n obj = PyArrayScalar_New(@OName@);\n if (obj == NULL) {Py_DECREF(ret); return NULL;}\n PyArrayScalar_VAL(ret, @OName@) = out2;\n PyTuple_SET_ITEM(ret, 1, obj);\n#else\n ret = PyArrayScalar_New(@OName@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @OName@) = out;\n#endif\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float, double, longdouble, cfloat, cdouble, clongdouble#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #otyp=float*4, double*6, float, double, longdouble, cfloat, cdouble, clongdouble#\n #OName=Float*4, Double*6, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n #isint=(1,0)*5,0*6#\n #cmplx=0*13,1*3#\n**/\n\nstatic PyObject *\n@name@_power(PyObject *a, PyObject *b, PyObject *c)\n{\n PyObject *ret;\n @name@ arg1, arg2, out;\n @otyp@ out1;\n int retstatus;\n\t\n switch(_@name@_convert2_to_ctypes(a, &arg1, b, &arg2)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n Py_INCREF(Py_NotImplemented);\n return Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_power(a,b,NULL);\n }\n\n PyUFunc_clearfperr();\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* as a function call. */\n#if @cmplx@\n if (arg2.real == 0 && arg1.real == 0) {\n\tout1.real = out.real = 1.0;\n\tout1.imag = out.imag = 0.0;\n }\n#else\n if (arg2 == 0) {\n\tout1 = out = 1;\n } \n#endif\n#if @isint@\n else if (arg2 < 0) {\n\t@name@_ctype_power(arg1, -arg2, &out);\n\tout1 = 1.0 / out;\n }\n#endif\n else {\n\t@name@_ctype_power(arg1, arg2, &out);\n }\n\n /* Check status flag. If it is set, then look up what to do */\n retstatus = PyUFunc_getfperr();\n if (retstatus) {\n\tint bufsize, errmask;\n\tPyObject *errobj;\n\tif (PyUFunc_GetPyValues(\"@name@_scalars\", &bufsize, &errmask, \n\t\t\t\t&errobj) < 0) \n\t return NULL;\n\tif (PyUFunc_handlefperr(errmask, errobj, retstatus))\n\t return NULL;\n }\n\n#if @isint@\n if (arg2 < 0) {\n\tret = PyArrayScalar_New(@OName@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @OName@) = out1;\n }\n else {\n\tret = PyArrayScalar_New(@Name@);\n\tif (ret==NULL) return NULL;\n\tPyArrayScalar_VAL(ret, @Name@) = out;\n }\n#else\n ret = PyArrayScalar_New(@Name@);\n if (ret==NULL) return NULL;\n PyArrayScalar_VAL(ret, @Name@) = out;\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n\n/**begin repeat\n#name=(cfloat,cdouble,clongdouble)*2#\n#oper=divmod*3,remainder*3#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n/**begin repeat\n #name=(float,double,longdouble,cfloat,cdouble,clongdouble)*6#\n #oper=lshift*6, rshift*6, and*6, or*6, xor*6, index*6#\n**/\n#define @name@_@oper@ NULL\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3, byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=(Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble)*3, Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n #oper=negative*16, positive*16, absolute*16, invert*10#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *a)\n{\n @name@ arg1, out;\n PyObject *ret;\n\t\n switch(_@name@_convert_to_ctype(a, &arg1)) {\n case 0:\n break;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use default handling */\n\tif (PyErr_Occurred()) return NULL;\n return PyGenericArrType_Type.tp_as_number->nb_@oper@(a);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n @name@_ctype_@oper@(arg1, &out);\n\n ret = PyArrayScalar_New(@Name@);\n PyArrayScalar_VAL(ret, @Name@) = out;\n\n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n#name=float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\n#define @name@_invert NULL\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=1*13,0*3#\n**/\nstatic int\n@name@_nonzero(PyObject *a)\n{\n int ret;\n @name@ arg1;\n\t\n if (_@name@_convert_to_ctype(a, &arg1) < 0) {\n\tif (PyErr_Occurred()) return -1;\n return PyGenericArrType_Type.tp_as_number->nb_nonzero(a);\n }\n \n /* here we do the actual calculation with arg1 and arg2 */\n /* make it a function call. */\n\n#if @simp@\n ret = (arg1 != 0);\n#else \n ret = ((arg1.real != 0) || (arg1.imag != 0));\n#endif\n \n return ret;\n}\n/**end repeat**/\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*3#\n #Name=(Byte,UByte,Short,UShort,Int,UInt,Long,ULong,LongLong,ULongLong,Float,Double,LongDouble,CFloat,CDouble,CLongDouble)*3#\n #cmplx=(,,,,,,,,,,,,,.real,.real,.real)*3#\n #which=int*16,long*16,float*16#\n #func=PyInt_FromLong*16,(PyLong_FromLongLong, PyLong_FromUnsignedLongLong)*5,PyLong_FromDouble*6,PyFloat_FromDouble*16#\n**/\nstatic PyObject *\n@name@_@which@(PyObject *obj)\n{\n return @func@((PyArrayScalar_VAL(obj, @Name@))@cmplx@);\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=(byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble)*2#\n #oper=oct*16, hex*16#\n**/\nstatic PyObject *\n@name@_@oper@(PyObject *obj)\n{\n PyObject *pyint;\n pyint = @name@_int(obj);\n if (pyint == NULL) return NULL;\n return PyInt_Type.tp_as_number->nb_@oper@(pyint);\n}\n/**end repeat**/\n\n\n#if PY_VERSION_HEX >= 0x02050000\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong#\n #Name=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong#\n**/\nstatic Py_ssize_t\n@name@_index(PyObject *a)\n{\n return PyArrayScalar_VAL(a, @Name@); \n}\n/**end repeat**/\n#endif\n\n\n/**begin repeat\n #oper=le,ge,lt,gt,eq,ne#\n #op=<=,>=,<,>,==,!=#\n**/\n#define def_cmp_@oper@(arg1, arg2) (arg1 @op@ arg2)\n#define cmplx_cmp_@oper@(arg1, arg2) ((arg1.real == arg2.real) ?\t\\\n\t\t\t\t arg1.imag @op@ arg2.imag :\t\\\n\t\t\t\t arg1.real @op@ arg2.real)\n/**end repeat**/\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #simp=def*13,cmplx*3#\n**/\nstatic PyObject*\n@name@_richcompare(PyObject *self, PyObject *other, int cmp_op)\n{\n @name@ arg1, arg2;\n int out=0;\n\t\n switch(_@name@_convert2_to_ctypes(self, &arg1, other, &arg2)) {\n case 0:\n\tbreak;\n case -1: /* can't cast both safely use different add function */\n\tPy_INCREF(Py_NotImplemented);\n\treturn Py_NotImplemented;\n case -2: /* use ufunc */\n\tif (PyErr_Occurred()) return NULL;\n\treturn PyGenericArrType_Type.tp_richcompare(self, other, cmp_op);\n }\n\n /* here we do the actual calculation with arg1 and arg2 */\n switch (cmp_op) {\n case Py_EQ:\n\tout = @simp@_cmp_eq(arg1, arg2);\n\tbreak;\n case Py_NE:\n\tout = @simp@_cmp_ne(arg1, arg2);\n\tbreak;\n case Py_LE:\n\tout = @simp@_cmp_le(arg1, arg2);\n\tbreak;\n case Py_GE:\n\tout = @simp@_cmp_ge(arg1, arg2);\n\tbreak;\n case Py_LT:\n\tout = @simp@_cmp_lt(arg1, arg2);\n\tbreak;\n case Py_GT:\n\tout = @simp@_cmp_gt(arg1, arg2);\n\tbreak;\n }\n \n if (out) {\n\tPyArrayScalar_RETURN_TRUE;\n }\n else {\n\tPyArrayScalar_RETURN_FALSE;\n }\n}\n/**end repeat**/\n\n\n/**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n**/\nstatic PyNumberMethods @name@_as_number = {\n (binaryfunc)@name@_add, /*nb_add*/\n (binaryfunc)@name@_subtract, /*nb_subtract*/\n (binaryfunc)@name@_multiply, /*nb_multiply*/\n (binaryfunc)@name@_divide, /*nb_divide*/\n (binaryfunc)@name@_remainder, /*nb_remainder*/\n (binaryfunc)@name@_divmod, /*nb_divmod*/\n (ternaryfunc)@name@_power, /*nb_power*/\n (unaryfunc)@name@_negative,\n (unaryfunc)@name@_positive, /*nb_pos*/\n (unaryfunc)@name@_absolute, /*nb_abs*/\n (inquiry)@name@_nonzero, /*nb_nonzero*/\n (unaryfunc)@name@_invert, /*nb_invert*/\n (binaryfunc)@name@_lshift, /*nb_lshift*/\n (binaryfunc)@name@_rshift, /*nb_rshift*/\n (binaryfunc)@name@_and, /*nb_and*/\n (binaryfunc)@name@_xor, /*nb_xor*/\n (binaryfunc)@name@_or, /*nb_or*/\n 0, /*nb_coerce*/\n (unaryfunc)@name@_int, /*nb_int*/\n (unaryfunc)@name@_long, /*nb_long*/\n (unaryfunc)@name@_float, /*nb_float*/\n (unaryfunc)@name@_oct, /*nb_oct*/\n (unaryfunc)@name@_hex, /*nb_hex*/\n 0, /*inplace_add*/\n 0, /*inplace_subtract*/\n 0, /*inplace_multiply*/\n 0, /*inplace_divide*/\n 0, /*inplace_remainder*/\n 0, /*inplace_power*/\n 0, /*inplace_lshift*/\n 0, /*inplace_rshift*/\n 0, /*inplace_and*/\n 0, /*inplace_xor*/\n 0, /*inplace_or*/\n (binaryfunc)@name@_floor_divide, /*nb_floor_divide*/\n (binaryfunc)@name@_true_divide, /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n#if PY_VERSION_HEX >= 0x02050000\n (lenfunc)@name@_index, /*nb_index*/\n#endif\n};\n/**end repeat**/\n\nstatic void\nadd_scalarmath(void)\n{\n /**begin repeat\n #name=byte,ubyte,short,ushort,int,uint,long,ulong,longlong,ulonglong,float,double,longdouble,cfloat,cdouble,clongdouble#\n #NAME=Byte, UByte, Short, UShort, Int, UInt, Long, ULong, LongLong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n **/\n Py@NAME@ArrType_Type.tp_as_number = &(@name@_as_number);\n Py@NAME@ArrType_Type.tp_richcompare = @name@_richcompare;\n /**end repeat**/\n}\n\nstatic int\nget_functions(void)\n{\n PyObject *mm, *obj;\n void **funcdata;\n char *signatures;\n int i, j;\n int ret = -1;\n\t\n /* Get the nc_pow functions */\n /* Get the pow functions */\n mm = PyImport_ImportModule(\"numpy.core.umath\");\n if (mm == NULL) return -1;\n \n obj = PyObject_GetAttrString(mm, \"power\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n \n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=3; j++;}\n _basic_float_pow = funcdata[j];\n _basic_double_pow = funcdata[j+1];\n _basic_longdouble_pow = funcdata[j+2];\n _basic_cfloat_pow = funcdata[j+3];\n _basic_cdouble_pow = funcdata[j+4];\n _basic_clongdouble_pow = funcdata[j+5];\n Py_DECREF(obj);\n\n /* Get the floor functions */\n obj = PyObject_GetAttrString(mm, \"floor\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n _basic_float_floor = funcdata[j];\n _basic_double_floor = funcdata[j+1];\n _basic_longdouble_floor = funcdata[j+2];\n Py_DECREF(obj);\n\n /* Get the sqrt functions */\n obj = PyObject_GetAttrString(mm, \"sqrt\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n _basic_float_sqrt = funcdata[j];\n _basic_double_sqrt = funcdata[j+1];\n _basic_longdouble_sqrt = funcdata[j+2];\n Py_DECREF(obj);\n\n /* Get the abs functions */\n obj = PyObject_GetAttrString(mm, \"absolute\");\n if (obj == NULL) goto fail;\n funcdata = ((PyUFuncObject *)obj)->data;\n signatures = ((PyUFuncObject *)obj)->types;\n i = 0;\n j = 0;\n while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}\n _basic_float_abs = funcdata[j];\n _basic_double_abs = funcdata[j+1];\n _basic_longdouble_abs = funcdata[j+2];\n Py_DECREF(obj);\n\n ret = 0;\n fail:\n Py_DECREF(mm);\n return ret;\n}\n\nstatic void *saved_tables[9];\n\nchar doc_alterpyscalars[] = \"\";\n\nstatic PyObject *\nalter_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = PyLongArrType_Type.tp_as_number;\n\t PyInt_Type.tp_compare = PyLongArrType_Type.tp_compare;\n\t PyInt_Type.tp_richcompare = PyLongArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = PyDoubleArrType_Type.tp_as_number;\n\t PyFloat_Type.tp_compare = PyDoubleArrType_Type.tp_compare;\n\t PyFloat_Type.tp_richcompare = PyDoubleArrType_Type.tp_richcompare;\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = PyCDoubleArrType_Type.tp_as_number;\n\t PyComplex_Type.tp_compare = PyCDoubleArrType_Type.tp_compare;\n\t PyComplex_Type.tp_richcompare =\t\t\\\n\t\tPyCDoubleArrType_Type.tp_richcompare;\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nchar doc_restorepyscalars[] = \"\";\nstatic PyObject *\nrestore_pyscalars(PyObject *dummy, PyObject *args)\n{\n int n;\n PyObject *obj;\n n = PyTuple_GET_SIZE(args);\n while(n--) {\n\tobj = PyTuple_GET_ITEM(args, n);\n\tif (obj == (PyObject *)(&PyInt_Type)) {\n\t PyInt_Type.tp_as_number = saved_tables[0];\n\t PyInt_Type.tp_compare = saved_tables[1];\n\t PyInt_Type.tp_richcompare = saved_tables[2];\n\t}\n\telse if (obj == (PyObject *)(&PyFloat_Type)) {\n\t PyFloat_Type.tp_as_number = saved_tables[3];\n\t PyFloat_Type.tp_compare = saved_tables[4];\n\t PyFloat_Type.tp_richcompare = saved_tables[5];\n\t}\n\telse if (obj == (PyObject *)(&PyComplex_Type)) {\n\t PyComplex_Type.tp_as_number = saved_tables[6];\n\t PyComplex_Type.tp_compare = saved_tables[7];\n\t PyComplex_Type.tp_richcompare = saved_tables[8];\n\t} \n\telse {\n\t PyErr_SetString(PyExc_ValueError, \n\t\t\t \"arguments must be int, float, or complex\");\n\t return NULL;\n\t}\n }\n Py_INCREF(Py_None);\n return Py_None;\n}\n\nstatic struct PyMethodDef methods[] = {\n {\"alter_scalars\", (PyCFunction) alter_pyscalars,\n METH_VARARGS, doc_alterpyscalars},\n {\"restore_scalars\", (PyCFunction) restore_pyscalars,\n METH_VARARGS, doc_restorepyscalars},\n {NULL, NULL, 0}\n};\n\nPyMODINIT_FUNC initscalarmath(void) {\n PyObject *m;\n\n m = Py_InitModule(\"scalarmath\", methods);\n\t\n if (import_array() < 0) return;\n if (import_umath() < 0) return;\n\n if (get_functions() < 0) return;\n\n add_scalarmath();\n\n saved_tables[0] = PyInt_Type.tp_as_number;\n saved_tables[1] = PyInt_Type.tp_compare;\n saved_tables[2] = PyInt_Type.tp_richcompare;\n saved_tables[3] = PyFloat_Type.tp_as_number;\n saved_tables[4] = PyFloat_Type.tp_compare;\n saved_tables[5] = PyFloat_Type.tp_richcompare;\n saved_tables[6] = PyComplex_Type.tp_as_number;\n saved_tables[7] = PyComplex_Type.tp_compare;\n saved_tables[8] = PyComplex_Type.tp_richcompare;\n\n return;\n}\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + " #name=byte, short, int, long, longlong, float, double, longdouble#" + ], + "deleted": [ + "static @name@ (*_basic_@name@_abs)(@name@);", + " #name=byte, short, int, long, longlong#", + "/**begin repeat", + " #name=float, double, longdouble#", + "**/", + "static void", + "@name@_ctype_absolute(@name@ a, @name@ *out)", + "{", + " *out = _basic_@name@_abs(a);", + "}", + "/**end repeat**/", + "", + "", + " /* Get the abs functions */", + " obj = PyObject_GetAttrString(mm, \"absolute\");", + " if (obj == NULL) goto fail;", + " funcdata = ((PyUFuncObject *)obj)->data;", + " signatures = ((PyUFuncObject *)obj)->types;", + " i = 0;", + " j = 0;", + " while(signatures[i] != PyArray_FLOAT) {i+=2; j++;}", + " _basic_float_abs = funcdata[j];", + " _basic_double_abs = funcdata[j+1];", + " _basic_longdouble_abs = funcdata[j+2];", + " Py_DECREF(obj);", + "" + ] + } + } + ] + }, + { + "hash": "ab513918819e227187168222ca8a81dc996d89ca", + "msg": "Changed rundocs to closely follow procedure outlined in the docs for imp.load_module. This fixed a bizzare error where tests would run fine the first time through, but would fail the second time through when loading from a pyc file.", + "author": { + "name": "Tim Hochberg", + "email": "tim_hochberg@local" + }, + "committer": { + "name": "Tim Hochberg", + "email": "tim_hochberg@local" + }, + "author_date": "2006-04-30T21:46:36+00:00", + "author_timezone": 0, + "committer_date": "2006-04-30T21:46:36+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "b3bf22851ebe0096dcf504f9576ce6d14ff42817" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 1, + "insertions": 6, + "lines": 7, + "files": 1, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/testing/numpytest.py", + "new_path": "numpy/testing/numpytest.py", + "filename": "numpytest.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -176,7 +176,12 @@ def rundocs(self, filename=None):\n f = get_frame(1)\n filename = f.f_globals['__file__']\n name = os.path.splitext(os.path.basename(filename))[0]\n- m = imp.load_module(name, open(filename), filename,('.py','U',1))\n+ path = [os.path.dirname(filename)]\n+ file, pathname, description = imp.find_module(name, path)\n+ try:\n+ m = imp.load_module(name, file, pathname, description)\n+ finally:\n+ file.close()\n tests = doctest.DocTestFinder().find(m)\n runner = doctest.DocTestRunner(verbose=False)\n for test in tests:\n", + "added_lines": 6, + "deleted_lines": 1, + "source_code": "\nimport os\nimport re\nimport sys\nimport imp\nimport glob\nimport types\nimport unittest\nimport traceback\n\n__all__ = ['set_package_path', 'set_local_path', 'restore_path',\n 'IgnoreException', 'NumpyTestCase', 'NumpyTest',\n 'ScipyTestCase', 'ScipyTest', # for backward compatibility\n 'importall'\n ]\n\nDEBUG=0\nget_frame = sys._getframe\nfrom utils import jiffies\n\n\nclass IgnoreException(Exception):\n \"Ignoring this exception due to disabled feature\"\n\n\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path for test_file %r' % (d1, testfile)\n sys.path.insert(0,d1)\n return\n\n\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n return\n\n\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n return\n\n\ndef output_exception(printstream = sys.stdout):\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print>>printstream, \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n return\n\n\nclass _dummy_stream:\n def __init__(self,stream):\n self.data = []\n self.stream = stream\n def write(self,message):\n if not self.data and not message.startswith('E'):\n self.stream.write(message)\n self.stream.flush()\n message = ''\n self.data.append(message)\n def writeln(self,message):\n self.write(message+'\\n')\n\n\nclass NumpyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = get_frame(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'NumpyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>sys.stderr,yellow_text('Warning: %s' % (message))\n sys.stderr.flush()\n def info(self, message):\n print>>sys.stdout, message\n sys.stdout.flush()\n\n def rundocs(self, filename=None):\n \"\"\" Run doc string tests found in filename.\n \"\"\"\n import doctest\n if filename is None:\n f = get_frame(1)\n filename = f.f_globals['__file__']\n name = os.path.splitext(os.path.basename(filename))[0]\n path = [os.path.dirname(filename)]\n file, pathname, description = imp.find_module(name, path)\n try:\n m = imp.load_module(name, file, pathname, description)\n finally:\n file.close()\n tests = doctest.DocTestFinder().find(m)\n runner = doctest.DocTestRunner(verbose=False)\n for test in tests:\n runner.run(test)\n return\n\nScipyTestCase = NumpyTestCase\n\ndef _get_all_method_names(cls):\n names = dir(cls)\n if sys.version[:3]<='2.1':\n for b in cls.__bases__:\n for n in dir(b)+_get_all_method_names(b):\n if n not in names:\n names.append(n)\n return names\n\n\n# for debug build--check for memory leaks during the test.\nclass _SciPyTextTestResult(unittest._TextTestResult):\n def startTest(self, test):\n unittest._TextTestResult.startTest(self, test)\n if self.showAll:\n N = len(sys.getobjects(0))\n self._totnumobj = N\n self._totrefcnt = sys.gettotalrefcount()\n return\n\n def stopTest(self, test):\n if self.showAll:\n N = len(sys.getobjects(0))\n self.stream.write(\"objects: %d ===> %d; \" % (self._totnumobj, N))\n self.stream.write(\"refcnts: %d ===> %d\\n\" % (self._totrefcnt,\n sys.gettotalrefcount()))\n return\n\nclass SciPyTextTestRunner(unittest.TextTestRunner):\n def _makeResult(self):\n return _SciPyTextTestResult(self.stream, self.descriptions, self.verbosity)\n\n\nclass NumpyTest:\n \"\"\" Numpy tests site manager.\n\n Usage:\n >>> NumpyTest().test(level=1,verbosity=1)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n See .rename() method to redefine name mapping between test_*.py files\n and names of submodules. Pattern test_*.py can be overwritten by\n redefining .get_testfile() method.\n\n test_*.py files are supposed to define a classes, derived\n from NumpyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check. The names of TestCase\n classes must have a prefix test. This can be overwritten by\n redefining .check_testcase_name() method.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported.\n \"\"\"\n _check_testcase_name = re.compile(r'test.*').match\n def check_testcase_name(self, name):\n \"\"\" Return True if name matches TestCase class.\n \"\"\"\n return not not self._check_testcase_name(name)\n\n testfile_patterns = ['test_%(modulename)s.py']\n def get_testfile(self, module, verbosity = 0):\n \"\"\" Return path to module test file.\n \"\"\"\n mstr = self._module_str\n short_module_name = self._get_short_module_name(module)\n d = os.path.split(module.__file__)[0]\n test_dir = os.path.join(d,'tests')\n local_test_dir = os.path.join(os.getcwd(),'tests')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)):\n test_dir = local_test_dir\n for pat in self.testfile_patterns:\n fn = os.path.join(test_dir, pat % {'modulename':short_module_name})\n if os.path.isfile(fn):\n return fn\n if verbosity>1:\n self.warn('No test file found in %s for module %s' \\\n % (test_dir, mstr(module)))\n return\n\n def __init__(self, package=None):\n if package is None:\n from numpy.distutils.misc_util import get_frame\n f = get_frame(1)\n package = f.f_locals.get('__name__',f.f_globals.get('__name__',None))\n assert package is not None\n self.package = package\n self._rename_map = {}\n\n def rename(self, **kws):\n \"\"\" Apply renaming submodule test file test_.py to test_.py.\n Usage: self.rename(name='newname') before calling self.test() method.\n If 'newname' is None, then no tests will be executed for a given module.\n \"\"\"\n for k,v in kws.items():\n self._rename_map[k] = v\n return\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_short_module_name(self, module):\n d,f = os.path.split(module.__file__)\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n short_module_name = self._rename_map.get(short_module_name,short_module_name)\n return short_module_name\n\n def _get_module_tests(self,module,level,verbosity):\n mstr = self._module_str\n\n short_module_name = self._get_short_module_name(module)\n if short_module_name is None:\n return []\n\n test_file = self.get_testfile(module, verbosity)\n\n if test_file is None:\n return []\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n if verbosity>1:\n self.warn(test_file)\n self.warn(' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module)))\n return []\n\n if test_file in self.test_files:\n return []\n\n parent_module_name = '.'.join(module.__name__.split('.')[:-1])\n test_module_name,ext = os.path.splitext(os.path.basename(test_file))\n test_dir_module = parent_module_name+'.tests'\n test_module_name = test_dir_module+'.'+test_module_name\n\n if not sys.modules.has_key(test_dir_module):\n sys.modules[test_dir_module] = imp.new_module(test_dir_module)\n\n old_sys_path = sys.path[:]\n try:\n f = open(test_file,'r')\n test_module = imp.load_module(test_module_name, f,\n test_file, ('.py', 'r', 1))\n f.close()\n except:\n sys.path[:] = old_sys_path\n self.warn('FAILURE importing tests for %s' % (mstr(module)))\n output_exception(sys.stderr)\n return []\n sys.path[:] = old_sys_path\n\n self.test_files.append(test_file)\n\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__',\n verbosity=1):\n mstr = self._module_str\n suite_list = []\n if hasattr(test_module,'test_suite'):\n suite_list.extend(test_module.test_suite(level)._tests)\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or not self.check_testcase_name(obj.__name__):\n continue\n for mthname in self._get_method_names(obj,level):\n suite = obj(mthname)\n if getattr(suite,'isrunnable',lambda mthname:1)(mthname):\n suite_list.append(suite)\n if verbosity>=0:\n self.info(' Found %s tests for %s' % (len(suite_list),module_name))\n return suite_list\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Numpy module test suite with level and verbosity.\n\n level:\n None --- do nothing, return None\n < 0 --- scan for tests of level=abs(level),\n don't run them, return TestSuite-list\n > 0 --- scan for tests of level, run them,\n return TestRunner\n\n verbosity:\n >= 0 --- show information messages\n > 1 --- show warnings on missing tests\n \"\"\"\n if level is None: # Do nothing.\n return\n\n if isinstance(self.package, str):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n package_name = this_package.__name__\n\n modules = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None:\n continue\n if not hasattr(module,'__file__'):\n continue\n if os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n modules.append(module)\n\n self.test_files = []\n suites = []\n for module in modules:\n suites.extend(self._get_module_tests(module, abs(level), verbosity))\n\n suites.extend(self._get_suite_list(sys.modules[package_name],\n abs(level), verbosity=verbosity))\n\n all_tests = unittest.TestSuite(suites)\n if level<0:\n return all_tests\n\n runner = unittest.TextTestRunner(verbosity=verbosity)\n # Use the builtin displayhook. If the tests are being run\n # under IPython (for instance), any doctest test suites will\n # fail otherwise.\n old_displayhook = sys.displayhook\n sys.displayhook = sys.__displayhook__\n try:\n runner.run(all_tests)\n finally:\n sys.displayhook = old_displayhook\n return runner\n\n def run(self):\n \"\"\" Run Numpy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n self.warn('Failed to import optparse module, ignoring.')\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n return\n\n def warn(self, message):\n from numpy.distutils.misc_util import yellow_text\n print>>sys.stderr,yellow_text('Warning: %s' % (message))\n sys.stderr.flush()\n def info(self, message):\n print>>sys.stdout, message\n sys.stdout.flush()\n\nScipyTest = NumpyTest\n\ndef importall(package):\n \"\"\"\n Try recursively to import all subpackages under package.\n \"\"\"\n if isinstance(package,str):\n package = __import__(package)\n\n package_name = package.__name__\n package_dir = os.path.dirname(package.__file__)\n for subpackage_name in os.listdir(package_dir):\n subdir = os.path.join(package_dir, subpackage_name)\n if not os.path.isdir(subdir):\n continue\n if not os.path.isfile(os.path.join(subdir,'__init__.py')):\n continue\n name = package_name+'.'+subpackage_name\n try:\n exec 'import %s as m' % (name)\n except Exception, msg:\n print 'Failed importing %s: %s' %(name, msg)\n continue\n importall(m)\n return\n", + "source_code_before": "\nimport os\nimport re\nimport sys\nimport imp\nimport glob\nimport types\nimport unittest\nimport traceback\n\n__all__ = ['set_package_path', 'set_local_path', 'restore_path',\n 'IgnoreException', 'NumpyTestCase', 'NumpyTest',\n 'ScipyTestCase', 'ScipyTest', # for backward compatibility\n 'importall'\n ]\n\nDEBUG=0\nget_frame = sys._getframe\nfrom utils import jiffies\n\n\nclass IgnoreException(Exception):\n \"Ignoring this exception due to disabled feature\"\n\n\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path for test_file %r' % (d1, testfile)\n sys.path.insert(0,d1)\n return\n\n\ndef set_local_path(reldir='', level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.join(os.path.dirname(os.path.abspath(testfile)),reldir)\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n return\n\n\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n return\n\n\ndef output_exception(printstream = sys.stdout):\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print>>printstream, \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n return\n\n\nclass _dummy_stream:\n def __init__(self,stream):\n self.data = []\n self.stream = stream\n def write(self,message):\n if not self.data and not message.startswith('E'):\n self.stream.write(message)\n self.stream.flush()\n message = ''\n self.data.append(message)\n def writeln(self,message):\n self.write(message+'\\n')\n\n\nclass NumpyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = get_frame(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'NumpyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>sys.stderr,yellow_text('Warning: %s' % (message))\n sys.stderr.flush()\n def info(self, message):\n print>>sys.stdout, message\n sys.stdout.flush()\n\n def rundocs(self, filename=None):\n \"\"\" Run doc string tests found in filename.\n \"\"\"\n import doctest\n if filename is None:\n f = get_frame(1)\n filename = f.f_globals['__file__']\n name = os.path.splitext(os.path.basename(filename))[0]\n m = imp.load_module(name, open(filename), filename,('.py','U',1))\n tests = doctest.DocTestFinder().find(m)\n runner = doctest.DocTestRunner(verbose=False)\n for test in tests:\n runner.run(test)\n return\n\nScipyTestCase = NumpyTestCase\n\ndef _get_all_method_names(cls):\n names = dir(cls)\n if sys.version[:3]<='2.1':\n for b in cls.__bases__:\n for n in dir(b)+_get_all_method_names(b):\n if n not in names:\n names.append(n)\n return names\n\n\n# for debug build--check for memory leaks during the test.\nclass _SciPyTextTestResult(unittest._TextTestResult):\n def startTest(self, test):\n unittest._TextTestResult.startTest(self, test)\n if self.showAll:\n N = len(sys.getobjects(0))\n self._totnumobj = N\n self._totrefcnt = sys.gettotalrefcount()\n return\n\n def stopTest(self, test):\n if self.showAll:\n N = len(sys.getobjects(0))\n self.stream.write(\"objects: %d ===> %d; \" % (self._totnumobj, N))\n self.stream.write(\"refcnts: %d ===> %d\\n\" % (self._totrefcnt,\n sys.gettotalrefcount()))\n return\n\nclass SciPyTextTestRunner(unittest.TextTestRunner):\n def _makeResult(self):\n return _SciPyTextTestResult(self.stream, self.descriptions, self.verbosity)\n\n\nclass NumpyTest:\n \"\"\" Numpy tests site manager.\n\n Usage:\n >>> NumpyTest().test(level=1,verbosity=1)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n See .rename() method to redefine name mapping between test_*.py files\n and names of submodules. Pattern test_*.py can be overwritten by\n redefining .get_testfile() method.\n\n test_*.py files are supposed to define a classes, derived\n from NumpyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check. The names of TestCase\n classes must have a prefix test. This can be overwritten by\n redefining .check_testcase_name() method.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported.\n \"\"\"\n _check_testcase_name = re.compile(r'test.*').match\n def check_testcase_name(self, name):\n \"\"\" Return True if name matches TestCase class.\n \"\"\"\n return not not self._check_testcase_name(name)\n\n testfile_patterns = ['test_%(modulename)s.py']\n def get_testfile(self, module, verbosity = 0):\n \"\"\" Return path to module test file.\n \"\"\"\n mstr = self._module_str\n short_module_name = self._get_short_module_name(module)\n d = os.path.split(module.__file__)[0]\n test_dir = os.path.join(d,'tests')\n local_test_dir = os.path.join(os.getcwd(),'tests')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)):\n test_dir = local_test_dir\n for pat in self.testfile_patterns:\n fn = os.path.join(test_dir, pat % {'modulename':short_module_name})\n if os.path.isfile(fn):\n return fn\n if verbosity>1:\n self.warn('No test file found in %s for module %s' \\\n % (test_dir, mstr(module)))\n return\n\n def __init__(self, package=None):\n if package is None:\n from numpy.distutils.misc_util import get_frame\n f = get_frame(1)\n package = f.f_locals.get('__name__',f.f_globals.get('__name__',None))\n assert package is not None\n self.package = package\n self._rename_map = {}\n\n def rename(self, **kws):\n \"\"\" Apply renaming submodule test file test_.py to test_.py.\n Usage: self.rename(name='newname') before calling self.test() method.\n If 'newname' is None, then no tests will be executed for a given module.\n \"\"\"\n for k,v in kws.items():\n self._rename_map[k] = v\n return\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_short_module_name(self, module):\n d,f = os.path.split(module.__file__)\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n if short_module_name=='__init__':\n short_module_name = module.__name__.split('.')[-1]\n short_module_name = self._rename_map.get(short_module_name,short_module_name)\n return short_module_name\n\n def _get_module_tests(self,module,level,verbosity):\n mstr = self._module_str\n\n short_module_name = self._get_short_module_name(module)\n if short_module_name is None:\n return []\n\n test_file = self.get_testfile(module, verbosity)\n\n if test_file is None:\n return []\n\n if not os.path.isfile(test_file):\n if short_module_name[:5]=='info_' \\\n and short_module_name[5:]==module.__name__.split('.')[-2]:\n return []\n if short_module_name in ['__cvs_version__','__svn_version__']:\n return []\n if short_module_name[-8:]=='_version' \\\n and short_module_name[:-8]==module.__name__.split('.')[-2]:\n return []\n if verbosity>1:\n self.warn(test_file)\n self.warn(' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module)))\n return []\n\n if test_file in self.test_files:\n return []\n\n parent_module_name = '.'.join(module.__name__.split('.')[:-1])\n test_module_name,ext = os.path.splitext(os.path.basename(test_file))\n test_dir_module = parent_module_name+'.tests'\n test_module_name = test_dir_module+'.'+test_module_name\n\n if not sys.modules.has_key(test_dir_module):\n sys.modules[test_dir_module] = imp.new_module(test_dir_module)\n\n old_sys_path = sys.path[:]\n try:\n f = open(test_file,'r')\n test_module = imp.load_module(test_module_name, f,\n test_file, ('.py', 'r', 1))\n f.close()\n except:\n sys.path[:] = old_sys_path\n self.warn('FAILURE importing tests for %s' % (mstr(module)))\n output_exception(sys.stderr)\n return []\n sys.path[:] = old_sys_path\n\n self.test_files.append(test_file)\n\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__',\n verbosity=1):\n mstr = self._module_str\n suite_list = []\n if hasattr(test_module,'test_suite'):\n suite_list.extend(test_module.test_suite(level)._tests)\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or not self.check_testcase_name(obj.__name__):\n continue\n for mthname in self._get_method_names(obj,level):\n suite = obj(mthname)\n if getattr(suite,'isrunnable',lambda mthname:1)(mthname):\n suite_list.append(suite)\n if verbosity>=0:\n self.info(' Found %s tests for %s' % (len(suite_list),module_name))\n return suite_list\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Numpy module test suite with level and verbosity.\n\n level:\n None --- do nothing, return None\n < 0 --- scan for tests of level=abs(level),\n don't run them, return TestSuite-list\n > 0 --- scan for tests of level, run them,\n return TestRunner\n\n verbosity:\n >= 0 --- show information messages\n > 1 --- show warnings on missing tests\n \"\"\"\n if level is None: # Do nothing.\n return\n\n if isinstance(self.package, str):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n package_name = this_package.__name__\n\n modules = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None:\n continue\n if not hasattr(module,'__file__'):\n continue\n if os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n modules.append(module)\n\n self.test_files = []\n suites = []\n for module in modules:\n suites.extend(self._get_module_tests(module, abs(level), verbosity))\n\n suites.extend(self._get_suite_list(sys.modules[package_name],\n abs(level), verbosity=verbosity))\n\n all_tests = unittest.TestSuite(suites)\n if level<0:\n return all_tests\n\n runner = unittest.TextTestRunner(verbosity=verbosity)\n # Use the builtin displayhook. If the tests are being run\n # under IPython (for instance), any doctest test suites will\n # fail otherwise.\n old_displayhook = sys.displayhook\n sys.displayhook = sys.__displayhook__\n try:\n runner.run(all_tests)\n finally:\n sys.displayhook = old_displayhook\n return runner\n\n def run(self):\n \"\"\" Run Numpy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n self.warn('Failed to import optparse module, ignoring.')\n return self.test()\n usage = r'usage: %prog [-v ] [-l ]'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n return\n\n def warn(self, message):\n from numpy.distutils.misc_util import yellow_text\n print>>sys.stderr,yellow_text('Warning: %s' % (message))\n sys.stderr.flush()\n def info(self, message):\n print>>sys.stdout, message\n sys.stdout.flush()\n\nScipyTest = NumpyTest\n\ndef importall(package):\n \"\"\"\n Try recursively to import all subpackages under package.\n \"\"\"\n if isinstance(package,str):\n package = __import__(package)\n\n package_name = package.__name__\n package_dir = os.path.dirname(package.__file__)\n for subpackage_name in os.listdir(package_dir):\n subdir = os.path.join(package_dir, subpackage_name)\n if not os.path.isdir(subdir):\n continue\n if not os.path.isfile(os.path.join(subdir,'__init__.py')):\n continue\n name = package_name+'.'+subpackage_name\n try:\n exec 'import %s as m' % (name)\n except Exception, msg:\n print 'Failed importing %s: %s' %(name, msg)\n continue\n importall(m)\n return\n", + "methods": [ + { + "name": "set_package_path", + "long_name": "set_package_path( level = 1 )", + "filename": "numpytest.py", + "nloc": 15, + "complexity": 4, + "token_count": 143, + "parameters": [ + "level" + ], + "start_line": 26, + "end_line": 57, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "set_local_path", + "long_name": "set_local_path( reldir = '' , level = 1 )", + "filename": "numpytest.py", + "nloc": 11, + "complexity": 3, + "token_count": 92, + "parameters": [ + "reldir", + "level" + ], + "start_line": 60, + "end_line": 76, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "restore_path", + "long_name": "restore_path( )", + "filename": "numpytest.py", + "nloc": 5, + "complexity": 2, + "token_count": 26, + "parameters": [], + "start_line": 79, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "output_exception", + "long_name": "output_exception( printstream = sys . stdout )", + "filename": "numpytest.py", + "nloc": 10, + "complexity": 2, + "token_count": 77, + "parameters": [ + "printstream" + ], + "start_line": 86, + "end_line": 97, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , stream )", + "filename": "numpytest.py", + "nloc": 3, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "stream" + ], + "start_line": 101, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "write", + "long_name": "write( self , message )", + "filename": "numpytest.py", + "nloc": 6, + "complexity": 3, + "token_count": 47, + "parameters": [ + "self", + "message" + ], + "start_line": 104, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "writeln", + "long_name": "writeln( self , message )", + "filename": "numpytest.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "message" + ], + "start_line": 110, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "measure", + "long_name": "measure( self , code_str , times = 1 )", + "filename": "numpytest.py", + "nloc": 13, + "complexity": 2, + "token_count": 80, + "parameters": [ + "self", + "code_str", + "times" + ], + "start_line": 116, + "end_line": 131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , result = None )", + "filename": "numpytest.py", + "nloc": 27, + "complexity": 7, + "token_count": 248, + "parameters": [ + "self", + "result" + ], + "start_line": 133, + "end_line": 161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "numpytest.py", + "nloc": 4, + "complexity": 1, + "token_count": 37, + "parameters": [ + "self", + "message" + ], + "start_line": 163, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "numpytest.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "message" + ], + "start_line": 167, + "end_line": 169, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "rundocs", + "long_name": "rundocs( self , filename = None )", + "filename": "numpytest.py", + "nloc": 17, + "complexity": 4, + "token_count": 134, + "parameters": [ + "self", + "filename" + ], + "start_line": 171, + "end_line": 189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "_get_all_method_names", + "long_name": "_get_all_method_names( cls )", + "filename": "numpytest.py", + "nloc": 8, + "complexity": 5, + "token_count": 56, + "parameters": [ + "cls" + ], + "start_line": 193, + "end_line": 200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "startTest", + "long_name": "startTest( self , test )", + "filename": "numpytest.py", + "nloc": 7, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self", + "test" + ], + "start_line": 205, + "end_line": 211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "stopTest", + "long_name": "stopTest( self , test )", + "filename": "numpytest.py", + "nloc": 7, + "complexity": 2, + "token_count": 60, + "parameters": [ + "self", + "test" + ], + "start_line": 213, + "end_line": 219, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "_makeResult", + "long_name": "_makeResult( self )", + "filename": "numpytest.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 222, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_testcase_name", + "long_name": "check_testcase_name( self , name )", + "filename": "numpytest.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "name" + ], + "start_line": 252, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_testfile", + "long_name": "get_testfile( self , module , verbosity = 0 )", + "filename": "numpytest.py", + "nloc": 17, + "complexity": 5, + "token_count": 164, + "parameters": [ + "self", + "module", + "verbosity" + ], + "start_line": 258, + "end_line": 276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , package = None )", + "filename": "numpytest.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "package" + ], + "start_line": 278, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "rename", + "long_name": "rename( self , ** kws )", + "filename": "numpytest.py", + "nloc": 4, + "complexity": 2, + "token_count": 29, + "parameters": [ + "self", + "kws" + ], + "start_line": 287, + "end_line": 294, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_module_str", + "long_name": "_module_str( self , module )", + "filename": "numpytest.py", + "nloc": 5, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "module" + ], + "start_line": 296, + "end_line": 300, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_method_names", + "long_name": "_get_method_names( self , clsobj , level )", + "filename": "numpytest.py", + "nloc": 22, + "complexity": 11, + "token_count": 142, + "parameters": [ + "self", + "clsobj", + "level" + ], + "start_line": 302, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "_get_short_module_name", + "long_name": "_get_short_module_name( self , module )", + "filename": "numpytest.py", + "nloc": 7, + "complexity": 2, + "token_count": 74, + "parameters": [ + "self", + "module" + ], + "start_line": 325, + "end_line": 331, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "_get_module_tests", + "long_name": "_get_module_tests( self , module , level , verbosity )", + "filename": "numpytest.py", + "nloc": 44, + "complexity": 13, + "token_count": 365, + "parameters": [ + "self", + "module", + "level", + "verbosity" + ], + "start_line": 333, + "end_line": 386, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 1 + }, + { + "name": "_get_suite_list", + "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' , verbosity = 1 )", + "filename": "numpytest.py", + "nloc": 19, + "complexity": 9, + "token_count": 162, + "parameters": [ + "self", + "test_module", + "level", + "module_name", + "verbosity" + ], + "start_line": 388, + "end_line": 406, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "test", + "long_name": "test( self , level = 1 , verbosity = 1 )", + "filename": "numpytest.py", + "nloc": 35, + "complexity": 11, + "token_count": 235, + "parameters": [ + "self", + "level", + "verbosity" + ], + "start_line": 408, + "end_line": 465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "numpytest.py", + "nloc": 21, + "complexity": 2, + "token_count": 109, + "parameters": [ + "self" + ], + "start_line": 467, + "end_line": 490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "numpytest.py", + "nloc": 4, + "complexity": 1, + "token_count": 37, + "parameters": [ + "self", + "message" + ], + "start_line": 492, + "end_line": 495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "numpytest.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "message" + ], + "start_line": 496, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "importall", + "long_name": "importall( package )", + "filename": "numpytest.py", + "nloc": 19, + "complexity": 6, + "token_count": 126, + "parameters": [ + "package" + ], + "start_line": 502, + "end_line": 524, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "set_package_path", + "long_name": "set_package_path( level = 1 )", + "filename": "numpytest.py", + "nloc": 15, + "complexity": 4, + "token_count": 143, + "parameters": [ + "level" + ], + "start_line": 26, + "end_line": 57, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "set_local_path", + "long_name": "set_local_path( reldir = '' , level = 1 )", + "filename": "numpytest.py", + "nloc": 11, + "complexity": 3, + "token_count": 92, + "parameters": [ + "reldir", + "level" + ], + "start_line": 60, + "end_line": 76, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "restore_path", + "long_name": "restore_path( )", + "filename": "numpytest.py", + "nloc": 5, + "complexity": 2, + "token_count": 26, + "parameters": [], + "start_line": 79, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "output_exception", + "long_name": "output_exception( printstream = sys . stdout )", + "filename": "numpytest.py", + "nloc": 10, + "complexity": 2, + "token_count": 77, + "parameters": [ + "printstream" + ], + "start_line": 86, + "end_line": 97, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , stream )", + "filename": "numpytest.py", + "nloc": 3, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "stream" + ], + "start_line": 101, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "write", + "long_name": "write( self , message )", + "filename": "numpytest.py", + "nloc": 6, + "complexity": 3, + "token_count": 47, + "parameters": [ + "self", + "message" + ], + "start_line": 104, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "writeln", + "long_name": "writeln( self , message )", + "filename": "numpytest.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "message" + ], + "start_line": 110, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "measure", + "long_name": "measure( self , code_str , times = 1 )", + "filename": "numpytest.py", + "nloc": 13, + "complexity": 2, + "token_count": 80, + "parameters": [ + "self", + "code_str", + "times" + ], + "start_line": 116, + "end_line": 131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , result = None )", + "filename": "numpytest.py", + "nloc": 27, + "complexity": 7, + "token_count": 248, + "parameters": [ + "self", + "result" + ], + "start_line": 133, + "end_line": 161, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "numpytest.py", + "nloc": 4, + "complexity": 1, + "token_count": 37, + "parameters": [ + "self", + "message" + ], + "start_line": 163, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "numpytest.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "message" + ], + "start_line": 167, + "end_line": 169, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "rundocs", + "long_name": "rundocs( self , filename = None )", + "filename": "numpytest.py", + "nloc": 12, + "complexity": 3, + "token_count": 108, + "parameters": [ + "self", + "filename" + ], + "start_line": 171, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "_get_all_method_names", + "long_name": "_get_all_method_names( cls )", + "filename": "numpytest.py", + "nloc": 8, + "complexity": 5, + "token_count": 56, + "parameters": [ + "cls" + ], + "start_line": 188, + "end_line": 195, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "startTest", + "long_name": "startTest( self , test )", + "filename": "numpytest.py", + "nloc": 7, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self", + "test" + ], + "start_line": 200, + "end_line": 206, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "stopTest", + "long_name": "stopTest( self , test )", + "filename": "numpytest.py", + "nloc": 7, + "complexity": 2, + "token_count": 60, + "parameters": [ + "self", + "test" + ], + "start_line": 208, + "end_line": 214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "_makeResult", + "long_name": "_makeResult( self )", + "filename": "numpytest.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 217, + "end_line": 218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_testcase_name", + "long_name": "check_testcase_name( self , name )", + "filename": "numpytest.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "name" + ], + "start_line": 247, + "end_line": 250, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "get_testfile", + "long_name": "get_testfile( self , module , verbosity = 0 )", + "filename": "numpytest.py", + "nloc": 17, + "complexity": 5, + "token_count": 164, + "parameters": [ + "self", + "module", + "verbosity" + ], + "start_line": 253, + "end_line": 271, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , package = None )", + "filename": "numpytest.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "package" + ], + "start_line": 273, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "rename", + "long_name": "rename( self , ** kws )", + "filename": "numpytest.py", + "nloc": 4, + "complexity": 2, + "token_count": 29, + "parameters": [ + "self", + "kws" + ], + "start_line": 282, + "end_line": 289, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_module_str", + "long_name": "_module_str( self , module )", + "filename": "numpytest.py", + "nloc": 5, + "complexity": 2, + "token_count": 43, + "parameters": [ + "self", + "module" + ], + "start_line": 291, + "end_line": 295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_method_names", + "long_name": "_get_method_names( self , clsobj , level )", + "filename": "numpytest.py", + "nloc": 22, + "complexity": 11, + "token_count": 142, + "parameters": [ + "self", + "clsobj", + "level" + ], + "start_line": 297, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "_get_short_module_name", + "long_name": "_get_short_module_name( self , module )", + "filename": "numpytest.py", + "nloc": 7, + "complexity": 2, + "token_count": 74, + "parameters": [ + "self", + "module" + ], + "start_line": 320, + "end_line": 326, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "_get_module_tests", + "long_name": "_get_module_tests( self , module , level , verbosity )", + "filename": "numpytest.py", + "nloc": 44, + "complexity": 13, + "token_count": 365, + "parameters": [ + "self", + "module", + "level", + "verbosity" + ], + "start_line": 328, + "end_line": 381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 1 + }, + { + "name": "_get_suite_list", + "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' , verbosity = 1 )", + "filename": "numpytest.py", + "nloc": 19, + "complexity": 9, + "token_count": 162, + "parameters": [ + "self", + "test_module", + "level", + "module_name", + "verbosity" + ], + "start_line": 383, + "end_line": 401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "test", + "long_name": "test( self , level = 1 , verbosity = 1 )", + "filename": "numpytest.py", + "nloc": 35, + "complexity": 11, + "token_count": 235, + "parameters": [ + "self", + "level", + "verbosity" + ], + "start_line": 403, + "end_line": 460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "numpytest.py", + "nloc": 21, + "complexity": 2, + "token_count": 109, + "parameters": [ + "self" + ], + "start_line": 462, + "end_line": 485, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "warn", + "long_name": "warn( self , message )", + "filename": "numpytest.py", + "nloc": 4, + "complexity": 1, + "token_count": 37, + "parameters": [ + "self", + "message" + ], + "start_line": 487, + "end_line": 490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "info", + "long_name": "info( self , message )", + "filename": "numpytest.py", + "nloc": 3, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "message" + ], + "start_line": 491, + "end_line": 493, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "importall", + "long_name": "importall( package )", + "filename": "numpytest.py", + "nloc": 19, + "complexity": 6, + "token_count": 126, + "parameters": [ + "package" + ], + "start_line": 497, + "end_line": 519, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "rundocs", + "long_name": "rundocs( self , filename = None )", + "filename": "numpytest.py", + "nloc": 17, + "complexity": 4, + "token_count": 134, + "parameters": [ + "self", + "filename" + ], + "start_line": 171, + "end_line": 189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + } + ], + "nloc": 401, + "complexity": 109, + "token_count": 2852, + "diff_parsed": { + "added": [ + " path = [os.path.dirname(filename)]", + " file, pathname, description = imp.find_module(name, path)", + " try:", + " m = imp.load_module(name, file, pathname, description)", + " finally:", + " file.close()" + ], + "deleted": [ + " m = imp.load_module(name, open(filename), filename,('.py','U',1))" + ] + } + } + ] + }, + { + "hash": "7a10bcdf14827bef1ba4b79fd4bd4f92bc9e84be", + "msg": "Made only/skip f2py options active when using -h option.", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2006-05-01T16:56:11+00:00", + "author_timezone": 0, + "committer_date": "2006-05-01T16:56:11+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "ab513918819e227187168222ca8a81dc996d89ca" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 0, + "insertions": 6, + "lines": 6, + "files": 1, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/f2py/crackfortran.py", + "new_path": "numpy/f2py/crackfortran.py", + "filename": "crackfortran.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -2365,10 +2365,16 @@ def determineexprtype(expr,vars,rules={}):\n return t\n ######\n def crack2fortrangen(block,tab='\\n'):\n+ global skipfuncs, onlyfuncs\n setmesstext(block)\n ret=''\n if type(block) is type([]):\n for g in block:\n+ if g['block'] in ['function','subroutine']:\n+ if g['name'] in skipfuncs:\n+ continue\n+ if onlyfuncs and g['name'] not in onlyfuncs:\n+ continue\n ret=ret+crack2fortrangen(g,tab)\n return ret\n prefix=''\n", + "added_lines": 6, + "deleted_lines": 0, + "source_code": "#!/usr/bin/env python\n\"\"\"\ncrackfortran --- read fortran (77,90) code and extract declaration information.\n Usage is explained in the comment block below.\n\nCopyright 1999-2004 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the\nterms of the NumPy License.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n$Date: 2005/09/27 07:13:49 $\nPearu Peterson\n\"\"\"\n__version__ = \"$Revision: 1.177 $\"[10:-1]\n\nimport __version__\nf2py_version = __version__.version\n\n\"\"\"\n Usage of crackfortran:\n ======================\n Command line keys: -quiet,-verbose,-fix,-f77,-f90,-show,-h \n -m ,--ignore-contains\n Functions: crackfortran, crack2fortran\n The following Fortran statements/constructions are supported\n (or will be if needed):\n block data,byte,call,character,common,complex,contains,data,\n dimension,double complex,double precision,end,external,function,\n implicit,integer,intent,interface,intrinsic,\n logical,module,optional,parameter,private,public,\n program,real,(sequence?),subroutine,type,use,virtual,\n include,pythonmodule\n Note: 'virtual' is mapped to 'dimension'.\n Note: 'implicit integer (z) static (z)' is 'implicit static (z)' (this is minor bug).\n Note: code after 'contains' will be ignored until its scope ends.\n Note: 'common' statement is extended: dimensions are moved to variable definitions\n Note: f2py directive: f2py is read as \n Note: pythonmodule is introduced to represent Python module\n\n Usage:\n `postlist=crackfortran(files,funcs)`\n `postlist` contains declaration information read from the list of files `files`.\n `crack2fortran(postlist)` returns a fortran code to be saved to pyf-file\n\n `postlist` has the following structure:\n *** it is a list of dictionaries containing `blocks':\n B = {'block','body','vars','parent_block'[,'name','prefix','args','result',\n 'implicit','externals','interfaced','common','sortvars',\n 'commonvars','note']}\n B['block'] = 'interface' | 'function' | 'subroutine' | 'module' |\n 'program' | 'block data' | 'type' | 'pythonmodule'\n B['body'] --- list containing `subblocks' with the same structure as `blocks'\n B['parent_block'] --- dictionary of a parent block:\n C['body'][]['parent_block'] is C\n B['vars'] --- dictionary of variable definitions\n B['sortvars'] --- dictionary of variable definitions sorted by dependence (independent first)\n B['name'] --- name of the block (not if B['block']=='interface')\n B['prefix'] --- prefix string (only if B['block']=='function')\n B['args'] --- list of argument names if B['block']== 'function' | 'subroutine'\n B['result'] --- name of the return value (only if B['block']=='function')\n B['implicit'] --- dictionary {'a':,'b':...} | None\n B['externals'] --- list of variables being external\n B['interfaced'] --- list of variables being external and defined\n B['common'] --- dictionary of common blocks (list of objects)\n B['commonvars'] --- list of variables used in common blocks (dimensions are moved to variable definitions)\n B['from'] --- string showing the 'parents' of the current block\n B['use'] --- dictionary of modules used in current block:\n {:{['only':<0|1>],['map':{:,...}]}}\n B['note'] --- list of LaTeX comments on the block\n B['f2pyenhancements'] --- optional dictionary\n {'threadsafe':'','fortranname':,\n 'callstatement':|,\n 'callprotoargument':,\n 'usercode':|,\n 'pymethoddef:'\n }\n B['entry'] --- dictionary {entryname:argslist,..}\n B['varnames'] --- list of variable names given in the order of reading the\n Fortran code, useful for derived types.\n *** Variable definition is a dictionary\n D = B['vars'][] =\n {'typespec'[,'attrspec','kindselector','charselector','=','typename']}\n D['typespec'] = 'byte' | 'character' | 'complex' | 'double complex' |\n 'double precision' | 'integer' | 'logical' | 'real' | 'type'\n D['attrspec'] --- list of attributes (e.g. 'dimension()',\n 'external','intent(in|out|inout|hide|c|callback|cache)',\n 'optional','required', etc)\n K = D['kindselector'] = {['*','kind']} (only if D['typespec'] =\n 'complex' | 'integer' | 'logical' | 'real' )\n C = D['charselector'] = {['*','len','kind']}\n (only if D['typespec']=='character')\n D['='] --- initialization expression string\n D['typename'] --- name of the type if D['typespec']=='type'\n D['dimension'] --- list of dimension bounds\n D['intent'] --- list of intent specifications\n D['depend'] --- list of variable names on which current variable depends on\n D['check'] --- list of C-expressions; if C-expr returns zero, exception is raised\n D['note'] --- list of LaTeX comments on the variable\n *** Meaning of kind/char selectors (few examples):\n D['typespec>']*K['*']\n D['typespec'](kind=K['kind'])\n character*C['*']\n character(len=C['len'],kind=C['kind'])\n (see also fortran type declaration statement formats below)\n\n Fortran 90 type declaration statement format (F77 is subset of F90)\n====================================================================\n (Main source: IBM XL Fortran 5.1 Language Reference Manual)\n type declaration = [[]::] \n = byte |\n character[] |\n complex[] |\n double complex |\n double precision |\n integer[] |\n logical[] |\n real[] |\n type()\n = * |\n ([len=][,[kind=]]) |\n (kind=[,len=])\n = * |\n ([kind=])\n = comma separated list of attributes.\n Only the following attributes are used in\n building up the interface:\n external\n (parameter --- affects '=' key)\n optional\n intent\n Other attributes are ignored.\n = in | out | inout\n = comma separated list of dimension bounds.\n = [[*][()] | [()]*]\n [// | =] [,]\n\n In addition, the following attributes are used: check,depend,note\n\n TODO:\n * Apply 'parameter' attribute (e.g. 'integer parameter :: i=2' 'real x(i)'\n -> 'real x(2)')\n The above may be solved by creating appropriate preprocessor program, for example.\n\"\"\"\n#\nimport sys,string,fileinput,re,pprint,os,copy\nfrom auxfuncs import *\n\n# Global flags:\nstrictf77=1 # Ignore `!' comments unless line[0]=='!'\nsourcecodeform='fix' # 'fix','free'\nquiet=0 # Be verbose if 0 (Obsolete: not used any more)\nverbose=1 # Be quiet if 0, extra verbose if > 1.\ntabchar=4*' '\npyffilename=''\nf77modulename=''\nskipemptyends=0 # for old F77 programs without 'program' statement\nignorecontains=1\ndolowercase=1\ndebug=[]\n## do_analyze = 1\n\n###### global variables\n\n## use reload(crackfortran) to reset these variables\n\ngroupcounter=0\ngrouplist={groupcounter:[]}\nneededmodule=-1\nexpectbegin=1\nskipblocksuntil=-1\nusermodules=[]\nf90modulevars={}\ngotnextfile=1\nfilepositiontext=''\ncurrentfilename=''\nskipfunctions=[]\nskipfuncs=[]\nonlyfuncs=[]\ninclude_paths=[]\nprevious_context = None\n\n###### Some helper functions\ndef show(o,f=0):pprint.pprint(o)\nerrmess=sys.stderr.write\ndef outmess(line,flag=1):\n global filepositiontext\n if not verbose: return\n if not quiet:\n if flag:sys.stdout.write(filepositiontext)\n sys.stdout.write(line)\nre._MAXCACHE=50\ndefaultimplicitrules={}\nfor c in \"abcdefghopqrstuvwxyz$_\": defaultimplicitrules[c]={'typespec':'real'}\nfor c in \"ijklmn\": defaultimplicitrules[c]={'typespec':'integer'}\ndel c\nbadnames={}\ninvbadnames={}\nfor n in ['int','double','float','char','short','long','void','case','while',\n 'return','signed','unsigned','if','for','typedef','sizeof','union',\n 'struct','static','register','new','break','do','goto','switch',\n 'continue','else','inline','extern','delete','const','auto',\n 'len','rank','shape','index','slen','size','_i',\n 'flen','fshape',\n 'string','complex_double','float_double','stdin','stderr','stdout',\n 'type','default']:\n badnames[n]=n+'_bn'\n invbadnames[n+'_bn']=n\ndef rmbadname1(name):\n if badnames.has_key(name):\n errmess('rmbadname1: Replacing \"%s\" with \"%s\".\\n'%(name,badnames[name]))\n return badnames[name]\n return name\ndef rmbadname(names): return map(rmbadname1,names)\n\ndef undo_rmbadname1(name):\n if invbadnames.has_key(name):\n errmess('undo_rmbadname1: Replacing \"%s\" with \"%s\".\\n'\\\n %(name,invbadnames[name]))\n return invbadnames[name]\n return name\ndef undo_rmbadname(names): return map(undo_rmbadname1,names)\n\ndef getextension(name):\n i=string.rfind(name,'.')\n if i==-1: return ''\n if '\\\\' in name[i:]: return ''\n if '/' in name[i:]: return ''\n return name[i+1:]\n\nis_f_file = re.compile(r'.*[.](for|ftn|f77|f)\\Z',re.I).match\n_has_f_header = re.compile(r'-[*]-\\s*fortran\\s*-[*]-',re.I).search\n_has_f90_header = re.compile(r'-[*]-\\s*f90\\s*-[*]-',re.I).search\n_has_fix_header = re.compile(r'-[*]-\\s*fix\\s*-[*]-',re.I).search\n_free_f90_start = re.compile(r'[^c*]\\s*[^\\s\\d\\t]',re.I).match\ndef is_free_format(file):\n \"\"\"Check if file is in free format Fortran.\"\"\"\n # f90 allows both fixed and free format, assuming fixed unless\n # signs of free format are detected.\n result = 0\n f = open(file,'r')\n line = f.readline()\n n = 15 # the number of non-comment lines to scan for hints\n if _has_f_header(line):\n n = 0\n elif _has_f90_header(line):\n n = 0\n result = 1\n while n>0 and line:\n if line[0]!='!':\n n -= 1\n if (line[0]!='\\t' and _free_f90_start(line[:5])) or line[-2:-1]=='&':\n result = 1\n break\n line = f.readline()\n f.close()\n return result\n\n\n####### Read fortran (77,90) code\ndef readfortrancode(ffile,dowithline=show,istop=1):\n \"\"\"\n Read fortran codes from files and\n 1) Get rid of comments, line continuations, and empty lines; lower cases.\n 2) Call dowithline(line) on every line.\n 3) Recursively call itself when statement \\\"include ''\\\" is met.\n \"\"\"\n global gotnextfile,filepositiontext,currentfilename,sourcecodeform,strictf77,\\\n beginpattern,quiet,verbose,dolowercase,include_paths\n if not istop:\n saveglobals=gotnextfile,filepositiontext,currentfilename,sourcecodeform,strictf77,\\\n beginpattern,quiet,verbose,dolowercase\n if ffile==[]: return\n localdolowercase = dolowercase\n cont=0\n finalline=''\n ll=''\n commentline=re.compile(r'(?P([^\"]*\"[^\"]*\"[^\"!]*|[^\\']*\\'[^\\']*\\'[^\\'!]*|[^!]*))!{1}(?P.*)')\n includeline=re.compile(r'\\s*include\\s*(\\'|\")(?P[^\\'\"]*)(\\'|\")',re.I)\n cont1=re.compile(r'(?P.*)&\\s*\\Z')\n cont2=re.compile(r'(\\s*&|)(?P.*)')\n mline_mark = re.compile(r\".*?'''\")\n if istop: dowithline('',-1)\n ll,l1='',''\n spacedigits=[' ']+map(str,range(10))\n filepositiontext=''\n fin=fileinput.FileInput(ffile)\n while 1:\n l=fin.readline()\n if not l: break\n if fin.isfirstline():\n filepositiontext=''\n currentfilename=fin.filename()\n gotnextfile=1\n l1=l\n strictf77=0\n sourcecodeform='fix'\n ext = os.path.splitext(currentfilename)[1]\n if is_f_file(currentfilename) and \\\n not (_has_f90_header(l) or _has_fix_header(l)):\n strictf77=1\n elif is_free_format(currentfilename) and not _has_fix_header(l):\n sourcecodeform='free'\n if strictf77: beginpattern=beginpattern77\n else: beginpattern=beginpattern90\n outmess('\\tReading file %s (format:%s%s)\\n'\\\n %(`currentfilename`,sourcecodeform,\n strictf77 and ',strict' or ''))\n\n l=string.expandtabs(l).replace('\\xa0',' ')\n while not l=='': # Get rid of newline characters\n if l[-1] not in \"\\n\\r\\f\": break\n l=l[:-1]\n if not strictf77:\n r=commentline.match(l)\n if r:\n l=r.group('line')+' ' # Strip comments starting with `!'\n rl=r.group('rest')\n if string.lower(rl[:4])=='f2py': # f2py directive\n l = l + 4*' '\n r=commentline.match(rl[4:])\n if r: l=l+r('line')\n else: l = l + rl[4:]\n if string.strip(l)=='': # Skip empty line\n cont=0\n continue\n if sourcecodeform=='fix':\n if l[0] in ['*','c','!','C','#']:\n if string.lower(l[1:5])=='f2py': # f2py directive\n l=' '+l[5:]\n else: # Skip comment line\n cont=0\n continue\n elif strictf77:\n if len(l)>72: l=l[:72]\n if not (l[0] in spacedigits):\n raise 'readfortrancode: Found non-(space,digit) char in the first column.\\n\\tAre you sure that this code is in fix form?\\n\\tline=%s'%`l`\n\n if (not cont or strictf77) and (len(l)>5 and not l[5]==' '):\n # Continuation of a previous line\n ll=ll+l[6:]\n finalline=''\n origfinalline=''\n else:\n if not strictf77:\n # F90 continuation\n r=cont1.match(l)\n if r: l=r.group('line') # Continuation follows ..\n if cont:\n ll=ll+cont2.match(l).group('line')\n finalline=''\n origfinalline=''\n else:\n l=' '+l[5:] # clean up line beginning from possible digits.\n if localdolowercase: finalline=string.lower(ll)\n else: finalline=ll\n origfinalline=ll\n ll=l\n cont=(r is not None)\n else:\n l=' '+l[5:] # clean up line beginning from possible digits.\n if localdolowercase: finalline=string.lower(ll)\n else: finalline=ll\n origfinalline =ll\n ll=l\n\n elif sourcecodeform=='free':\n if not cont and ext=='.pyf' and mline_mark.match(l):\n l = l + '\\n'\n while 1:\n lc = fin.readline()\n if not lc:\n errmess('Unexpected end of file when reading multiline\\n')\n break\n l = l + lc\n if mline_mark.match(lc):\n break\n l = l.rstrip()\n r=cont1.match(l)\n if r: l=r.group('line') # Continuation follows ..\n if cont:\n ll=ll+cont2.match(l).group('line')\n finalline=''\n origfinalline=''\n else:\n if localdolowercase: finalline=string.lower(ll)\n else: finalline=ll\n origfinalline =ll\n ll=l\n cont=(r is not None)\n else:\n raise ValueError,\"Flag sourcecodeform must be either 'fix' or 'free': %s\"%`sourcecodeform`\n filepositiontext='Line #%d in %s:\"%s\"\\n\\t' % (fin.filelineno()-1,currentfilename,l1)\n m=includeline.match(origfinalline)\n if m:\n fn=m.group('name')\n if os.path.isfile(fn):\n readfortrancode(fn,dowithline=dowithline,istop=0)\n else:\n include_dirs = [os.path.dirname(currentfilename)] + include_paths\n foundfile = 0\n for inc_dir in include_dirs:\n fn1 = os.path.join(inc_dir,fn)\n if os.path.isfile(fn1):\n foundfile = 1\n readfortrancode(fn1,dowithline=dowithline,istop=0)\n break\n if not foundfile:\n outmess('readfortrancode: could not find include file %s. Ignoring.\\n'%(`fn`))\n else:\n dowithline(finalline)\n l1=ll\n if localdolowercase:\n finalline=string.lower(ll)\n else: finalline=ll\n origfinalline = ll\n filepositiontext='Line #%d in %s:\"%s\"\\n\\t' % (fin.filelineno()-1,currentfilename,l1)\n m=includeline.match(origfinalline)\n if m:\n fn=m.group('name')\n fn1=os.path.join(os.path.dirname(currentfilename),fn)\n if os.path.isfile(fn):\n readfortrancode(fn,dowithline=dowithline,istop=0)\n elif os.path.isfile(fn1):\n readfortrancode(fn1,dowithline=dowithline,istop=0)\n else:\n outmess('readfortrancode: could not find include file %s. Ignoring.\\n'%(`fn`))\n else:\n dowithline(finalline)\n filepositiontext=''\n fin.close()\n if istop: dowithline('',1)\n else:\n gotnextfile,filepositiontext,currentfilename,sourcecodeform,strictf77,\\\n beginpattern,quiet,verbose,dolowercase=saveglobals\n\n########### Crack line\nbeforethisafter=r'\\s*(?P%s(?=\\s*(\\b(%s)\\b)))'+ \\\n r'\\s*(?P(\\b(%s)\\b))'+ \\\n r'\\s*(?P%s)\\s*\\Z'\n##\nfortrantypes='character|logical|integer|real|complex|double\\s*(precision\\s*(complex|)|complex)|type(?=\\s*\\([\\w\\s,=(*)]*\\))|byte'\ntypespattern=re.compile(beforethisafter%('',fortrantypes,fortrantypes,'.*'),re.I),'type'\ntypespattern4implicit=re.compile(beforethisafter%('',fortrantypes+'|static|automatic|undefined',fortrantypes+'|static|automatic|undefined','.*'),re.I)\n#\nfunctionpattern=re.compile(beforethisafter%('([a-z]+[\\w\\s(=*+-/)]*?|)','function','function','.*'),re.I),'begin'\nsubroutinepattern=re.compile(beforethisafter%('[a-z\\s]*?','subroutine','subroutine','.*'),re.I),'begin'\n#modulepattern=re.compile(beforethisafter%('[a-z\\s]*?','module','module','.*'),re.I),'begin'\n#\ngroupbegins77=r'program|block\\s*data'\nbeginpattern77=re.compile(beforethisafter%('',groupbegins77,groupbegins77,'.*'),re.I),'begin'\ngroupbegins90=groupbegins77+r'|module|python\\s*module|interface|type(?!\\s*\\()'\nbeginpattern90=re.compile(beforethisafter%('',groupbegins90,groupbegins90,'.*'),re.I),'begin'\ngroupends=r'end|endprogram|endblockdata|endmodule|endpythonmodule|endinterface'\nendpattern=re.compile(beforethisafter%('',groupends,groupends,'[\\w\\s]*'),re.I),'end'\n#endifs='end\\s*(if|do|where|select|while|forall)'\nendifs='(end\\s*(if|do|where|select|while|forall))|(module\\s*procedure)'\nendifpattern=re.compile(beforethisafter%('[\\w]*?',endifs,endifs,'[\\w\\s]*'),re.I),'endif'\n#\nimplicitpattern=re.compile(beforethisafter%('','implicit','implicit','.*'),re.I),'implicit'\ndimensionpattern=re.compile(beforethisafter%('','dimension|virtual','dimension|virtual','.*'),re.I),'dimension'\nexternalpattern=re.compile(beforethisafter%('','external','external','.*'),re.I),'external'\noptionalpattern=re.compile(beforethisafter%('','optional','optional','.*'),re.I),'optional'\nrequiredpattern=re.compile(beforethisafter%('','required','required','.*'),re.I),'required'\npublicpattern=re.compile(beforethisafter%('','public','public','.*'),re.I),'public'\nprivatepattern=re.compile(beforethisafter%('','private','private','.*'),re.I),'private'\nintrisicpattern=re.compile(beforethisafter%('','intrisic','intrisic','.*'),re.I),'intrisic'\nintentpattern=re.compile(beforethisafter%('','intent|depend|note|check','intent|depend|note|check','\\s*\\(.*?\\).*'),re.I),'intent'\nparameterpattern=re.compile(beforethisafter%('','parameter','parameter','\\s*\\(.*'),re.I),'parameter'\ndatapattern=re.compile(beforethisafter%('','data','data','.*'),re.I),'data'\ncallpattern=re.compile(beforethisafter%('','call','call','.*'),re.I),'call'\nentrypattern=re.compile(beforethisafter%('','entry','entry','.*'),re.I),'entry'\ncallfunpattern=re.compile(beforethisafter%('','callfun','callfun','.*'),re.I),'callfun'\ncommonpattern=re.compile(beforethisafter%('','common','common','.*'),re.I),'common'\nusepattern=re.compile(beforethisafter%('','use','use','.*'),re.I),'use'\ncontainspattern=re.compile(beforethisafter%('','contains','contains',''),re.I),'contains'\nformatpattern=re.compile(beforethisafter%('','format','format','.*'),re.I),'format'\n## Non-fortran and f2py-specific statements\nf2pyenhancementspattern=re.compile(beforethisafter%('','threadsafe|fortranname|callstatement|callprotoargument|usercode|pymethoddef','threadsafe|fortranname|callstatement|callprotoargument|usercode|pymethoddef','.*'),re.I|re.S),'f2pyenhancements'\nmultilinepattern = re.compile(r\"\\s*(?P''')(?P.*?)(?P''')\\s*\\Z\",re.S),'multiline'\n##\n\ndef _simplifyargs(argsline):\n a = []\n for n in string.split(markoutercomma(argsline),'@,@'):\n for r in '(),':\n n = string.replace(n,r,'_')\n a.append(n)\n return string.join(a,',')\n\ncrackline_re_1 = re.compile(r'\\s*(?P\\b[a-z]+[\\w]*\\b)\\s*[=].*',re.I)\ndef crackline(line,reset=0):\n \"\"\"\n reset=-1 --- initialize\n reset=0 --- crack the line\n reset=1 --- final check if mismatch of blocks occured\n\n Cracked data is saved in grouplist[0].\n \"\"\"\n global beginpattern,groupcounter,groupname,groupcache,grouplist,gotnextfile,\\\n filepositiontext,currentfilename,neededmodule,expectbegin,skipblocksuntil,\\\n skipemptyends,previous_context\n if ';' in line and not (f2pyenhancementspattern[0].match(line) or\n multilinepattern[0].match(line)):\n for l in line.split(';'):\n assert reset==0,`reset` # XXX: non-zero reset values need testing\n crackline(l,reset)\n return\n if reset<0:\n groupcounter=0\n groupname={groupcounter:''}\n groupcache={groupcounter:{}}\n grouplist={groupcounter:[]}\n groupcache[groupcounter]['body']=[]\n groupcache[groupcounter]['vars']={}\n groupcache[groupcounter]['block']=''\n groupcache[groupcounter]['name']=''\n neededmodule=-1\n skipblocksuntil=-1\n return\n if reset>0:\n fl=0\n if f77modulename and neededmodule==groupcounter: fl=2\n while groupcounter>fl:\n outmess('crackline: groupcounter=%s groupname=%s\\n'%(`groupcounter`,`groupname`))\n outmess('crackline: Mismatch of blocks encountered. Trying to fix it by assuming \"end\" statement.\\n')\n grouplist[groupcounter-1].append(groupcache[groupcounter])\n grouplist[groupcounter-1][-1]['body']=grouplist[groupcounter]\n del grouplist[groupcounter]\n groupcounter=groupcounter-1\n if f77modulename and neededmodule==groupcounter:\n grouplist[groupcounter-1].append(groupcache[groupcounter])\n grouplist[groupcounter-1][-1]['body']=grouplist[groupcounter]\n del grouplist[groupcounter]\n groupcounter=groupcounter-1 # end interface\n grouplist[groupcounter-1].append(groupcache[groupcounter])\n grouplist[groupcounter-1][-1]['body']=grouplist[groupcounter]\n del grouplist[groupcounter]\n groupcounter=groupcounter-1 # end module\n neededmodule=-1\n return\n if line=='': return\n flag=0\n for pat in [dimensionpattern,externalpattern,intentpattern,optionalpattern,\n requiredpattern,\n parameterpattern,datapattern,publicpattern,privatepattern,\n intrisicpattern,\n endifpattern,endpattern,\n formatpattern,\n beginpattern,functionpattern,subroutinepattern,\n implicitpattern,typespattern,commonpattern,\n callpattern,usepattern,containspattern,\n entrypattern,\n f2pyenhancementspattern,\n multilinepattern\n ]:\n m = pat[0].match(line)\n if m:\n break\n flag=flag+1\n if not m:\n re_1 = crackline_re_1\n if 0<=skipblocksuntil<=groupcounter:return\n if groupcache[groupcounter].has_key('externals'):\n for name in groupcache[groupcounter]['externals']:\n if invbadnames.has_key(name):\n name=invbadnames[name]\n if groupcache[groupcounter].has_key('interfaced') and name in groupcache[groupcounter]['interfaced']: continue\n m1=re.match(r'(?P[^\"]*)\\b%s\\b\\s*@\\(@(?P[^@]*)@\\)@.*\\Z'%name,markouterparen(line),re.I)\n if m1:\n m2 = re_1.match(m1.group('before'))\n a = _simplifyargs(m1.group('args'))\n if m2:\n line='callfun %s(%s) result (%s)'%(name,a,m2.group('result'))\n else: line='callfun %s(%s)'%(name,a)\n m = callfunpattern[0].match(line)\n if not m:\n outmess('crackline: could not resolve function call for line=%s.\\n'%`line`)\n return\n analyzeline(m,'callfun',line)\n return\n if verbose>1:\n previous_context = None\n outmess('crackline:%d: No pattern for line\\n'%(groupcounter))\n return\n elif pat[1]=='end':\n if 0<=skipblocksuntil(@\\(@.*?@\\)@|[*][\\d*]+|[*]\\s*@\\(@.*?@\\)@|))(?P.*)\\Z',re.I)\nnameargspattern=re.compile(r'\\s*(?P\\b[\\w$]+\\b)\\s*(@\\(@\\s*(?P[\\w\\s,]*)\\s*@\\)@|)\\s*(result(\\s*@\\(@\\s*(?P\\b[\\w$]+\\b)\\s*@\\)@|))*\\s*\\Z',re.I)\ncallnameargspattern=re.compile(r'\\s*(?P\\b[\\w$]+\\b)\\s*@\\(@\\s*(?P.*)\\s*@\\)@\\s*\\Z',re.I)\nreal16pattern = re.compile(r'([-+]?(?:\\d+(?:\\.\\d*)?|\\d*\\.\\d+))[dD]((?:[-+]?\\d+)?)')\nreal8pattern = re.compile(r'([-+]?((?:\\d+(?:\\.\\d*)?|\\d*\\.\\d+))[eE]((?:[-+]?\\d+)?)|(\\d+\\.\\d*))')\n\n_intentcallbackpattern = re.compile(r'intent\\s*\\(.*?\\bcallback\\b',re.I)\ndef _is_intent_callback(vdecl):\n for a in vdecl.get('attrspec',[]):\n if _intentcallbackpattern.match(a):\n return 1\n return 0\n\ndef _resolvenameargspattern(line):\n line = markouterparen(line)\n m1=nameargspattern.match(line)\n if m1: return m1.group('name'),m1.group('args'),m1.group('result')\n m1=callnameargspattern.match(line)\n if m1: return m1.group('name'),m1.group('args'),None\n return None,[],None\n\ndef analyzeline(m,case,line):\n global groupcounter,groupname,groupcache,grouplist,filepositiontext,\\\n currentfilename,f77modulename,neededinterface,neededmodule,expectbegin,\\\n gotnextfile,previous_context\n block=m.group('this')\n if case != 'multiline':\n previous_context = None\n if expectbegin and case not in ['begin','call','callfun','type'] \\\n and not skipemptyends and groupcounter<1:\n newname=string.split(os.path.basename(currentfilename),'.')[0]\n outmess('analyzeline: no group yet. Creating program group with name \"%s\".\\n'%newname)\n gotnextfile=0\n groupcounter=groupcounter+1\n groupname[groupcounter]='program'\n groupcache[groupcounter]={}\n grouplist[groupcounter]=[]\n groupcache[groupcounter]['body']=[]\n groupcache[groupcounter]['vars']={}\n groupcache[groupcounter]['block']='program'\n groupcache[groupcounter]['name']=newname\n groupcache[groupcounter]['from']='fromsky'\n expectbegin=0\n if case in ['begin','call','callfun']:\n # Crack line => block,name,args,result\n block = block.lower()\n if re.match(r'block\\s*data',block,re.I): block='block data'\n if re.match(r'python\\s*module',block,re.I): block='python module'\n name,args,result = _resolvenameargspattern(m.group('after'))\n if name is None:\n if block=='block data':\n name = '_BLOCK_DATA_'\n else:\n name = ''\n if block not in ['interface','block data']:\n outmess('analyzeline: No name/args pattern found for line.\\n')\n\n previous_context = (block,name,groupcounter)\n if args: args=rmbadname(map(string.strip,string.split(markoutercomma(args),'@,@')))\n else: args=[]\n if '' in args:\n while '' in args:\n args.remove('')\n outmess('analyzeline: argument list is malformed (missing argument).\\n')\n\n # end of crack line => block,name,args,result\n needmodule=0\n needinterface=0\n\n if case in ['call','callfun']:\n needinterface=1\n if not groupcache[groupcounter].has_key('args'): return\n if name not in groupcache[groupcounter]['args']:\n return\n for it in grouplist[groupcounter]:\n if it['name']==name: return\n if name in groupcache[groupcounter]['interfaced']: return\n block={'call':'subroutine','callfun':'function'}[case]\n if f77modulename and neededmodule==-1 and groupcounter<=1:\n neededmodule=groupcounter+2\n needmodule=1\n needinterface=1\n # Create new block(s)\n groupcounter=groupcounter+1\n groupcache[groupcounter]={}\n grouplist[groupcounter]=[]\n if needmodule:\n if verbose>1:\n outmess('analyzeline: Creating module block %s\\n'%`f77modulename`,0)\n groupname[groupcounter]='module'\n groupcache[groupcounter]['block']='python module'\n groupcache[groupcounter]['name']=f77modulename\n groupcache[groupcounter]['from']=''\n groupcache[groupcounter]['body']=[]\n groupcache[groupcounter]['externals']=[]\n groupcache[groupcounter]['interfaced']=[]\n groupcache[groupcounter]['vars']={}\n groupcounter=groupcounter+1\n groupcache[groupcounter]={}\n grouplist[groupcounter]=[]\n if needinterface:\n if verbose>1:\n outmess('analyzeline: Creating additional interface block.\\n',0)\n groupname[groupcounter]='interface'\n groupcache[groupcounter]['block']='interface'\n groupcache[groupcounter]['name']='unknown_interface'\n groupcache[groupcounter]['from']='%s:%s'%(groupcache[groupcounter-1]['from'],groupcache[groupcounter-1]['name'])\n groupcache[groupcounter]['body']=[]\n groupcache[groupcounter]['externals']=[]\n groupcache[groupcounter]['interfaced']=[]\n groupcache[groupcounter]['vars']={}\n groupcounter=groupcounter+1\n groupcache[groupcounter]={}\n grouplist[groupcounter]=[]\n groupname[groupcounter]=block\n groupcache[groupcounter]['block']=block\n if not name: name='unknown_'+block\n groupcache[groupcounter]['prefix']=m.group('before')\n groupcache[groupcounter]['name']=rmbadname1(name)\n groupcache[groupcounter]['result']=result\n if groupcounter==1:\n groupcache[groupcounter]['from']=currentfilename\n else:\n if f77modulename and groupcounter==3:\n groupcache[groupcounter]['from']='%s:%s'%(groupcache[groupcounter-1]['from'],currentfilename)\n else:\n groupcache[groupcounter]['from']='%s:%s'%(groupcache[groupcounter-1]['from'],groupcache[groupcounter-1]['name'])\n for k in groupcache[groupcounter].keys():\n if not groupcache[groupcounter][k]: del groupcache[groupcounter][k]\n groupcache[groupcounter]['args']=args\n groupcache[groupcounter]['body']=[]\n groupcache[groupcounter]['externals']=[]\n groupcache[groupcounter]['interfaced']=[]\n groupcache[groupcounter]['vars']={}\n groupcache[groupcounter]['entry']={}\n # end of creation\n if block=='type':\n groupcache[groupcounter]['varnames'] = []\n\n if case in ['call','callfun']: # set parents variables\n if name not in groupcache[groupcounter-2]['externals']:\n groupcache[groupcounter-2]['externals'].append(name)\n groupcache[groupcounter]['vars']=copy.deepcopy(groupcache[groupcounter-2]['vars'])\n #try: del groupcache[groupcounter]['vars'][groupcache[groupcounter-2]['name']]\n #except: pass\n try: del groupcache[groupcounter]['vars'][name][groupcache[groupcounter]['vars'][name]['attrspec'].index('external')]\n except: pass\n if block in ['function','subroutine']: # set global attributes\n try: groupcache[groupcounter]['vars'][name]=appenddecl(groupcache[groupcounter]['vars'][name],groupcache[groupcounter-2]['vars'][''])\n except: pass\n if case=='callfun': # return type\n if result and groupcache[groupcounter]['vars'].has_key(result):\n if not name==result:\n groupcache[groupcounter]['vars'][name]=appenddecl(groupcache[groupcounter]['vars'][name],groupcache[groupcounter]['vars'][result])\n #if groupcounter>1: # name is interfaced\n try: groupcache[groupcounter-2]['interfaced'].append(name)\n except: pass\n if block=='function':\n t=typespattern[0].match(m.group('before')+' '+name)\n if t:\n typespec,selector,attr,edecl=cracktypespec0(t.group('this'),t.group('after'))\n updatevars(typespec,selector,attr,edecl)\n if case in ['call','callfun']:\n grouplist[groupcounter-1].append(groupcache[groupcounter])\n grouplist[groupcounter-1][-1]['body']=grouplist[groupcounter]\n del grouplist[groupcounter]\n groupcounter=groupcounter-1 # end routine\n grouplist[groupcounter-1].append(groupcache[groupcounter])\n grouplist[groupcounter-1][-1]['body']=grouplist[groupcounter]\n del grouplist[groupcounter]\n groupcounter=groupcounter-1 # end interface\n elif case=='entry':\n name,args,result=_resolvenameargspattern(m.group('after'))\n if name is not None:\n if args:\n args=rmbadname(map(string.strip,string.split(markoutercomma(args),'@,@')))\n else: args=[]\n assert result is None,`result`\n groupcache[groupcounter]['entry'][name] = args\n previous_context = ('entry',name,groupcounter)\n elif case=='type':\n typespec,selector,attr,edecl=cracktypespec0(block,m.group('after'))\n last_name = updatevars(typespec,selector,attr,edecl)\n if last_name is not None:\n previous_context = ('variable',last_name,groupcounter)\n elif case in ['dimension','intent','optional','required','external','public','private','intrisic']:\n edecl=groupcache[groupcounter]['vars']\n ll=m.group('after').strip()\n i=string.find(ll,'::')\n if i<0 and case=='intent':\n i=string.find(markouterparen(ll),'@)@')-2\n ll=ll[:i+1]+'::'+ll[i+1:]\n i=string.find(ll,'::')\n if ll[i:]=='::' and groupcache[groupcounter].has_key('args'):\n outmess('All arguments will have attribute %s%s\\n'%(m.group('this'),ll[:i]))\n ll = ll + string.join(groupcache[groupcounter]['args'],',')\n if i<0:i=0;pl=''\n else: pl=string.strip(ll[:i]);ll=ll[i+2:]\n ch = string.split(markoutercomma(pl),'@,@')\n if len(ch)>1:\n pl = ch[0]\n outmess('analyzeline: cannot handle multiple attributes without type specification. Ignoring %r.\\n' % (','.join(ch[1:])))\n last_name = None\n for e in map(string.strip,string.split(markoutercomma(ll),'@,@')):\n m1=namepattern.match(e)\n if not m1:\n if case in ['public','private']: k=''\n else:\n print m.groupdict()\n outmess('analyzeline: no name pattern found in %s statement for %s. Skipping.\\n'%(case,`e`))\n continue\n else:\n k=rmbadname1(m1.group('name'))\n if not edecl.has_key(k): edecl[k]={}\n if case=='dimension': ap=case+m1.group('after')\n if case=='intent':\n ap=m.group('this')+pl\n if _intentcallbackpattern.match(ap):\n if k not in groupcache[groupcounter]['args']:\n if groupcounter>1 and \\\n string.find(groupcache[groupcounter-2]['name'],\n '__user__')==-1:\n outmess('analyzeline: appending intent(callback) %s'\\\n ' to %s arguments\\n' % (k,groupcache[groupcounter]['name']))\n groupcache[groupcounter]['args'].append(k)\n else:\n errmess('analyzeline: intent(callback) %s is already'\\\n ' in argument list' % (k))\n if case in ['optional','required','public','external','private','intrisic']: ap=case\n if edecl[k].has_key('attrspec'): edecl[k]['attrspec'].append(ap)\n else: edecl[k]['attrspec']=[ap]\n if case=='external':\n if groupcache[groupcounter]['block']=='program':\n outmess('analyzeline: ignoring program arguments\\n')\n continue\n if k not in groupcache[groupcounter]['args']:\n #outmess('analyzeline: ignoring external %s (not in arguments list)\\n'%(`k`))\n continue\n if not groupcache[groupcounter].has_key('externals'):\n groupcache[groupcounter]['externals']=[]\n groupcache[groupcounter]['externals'].append(k)\n last_name = k\n groupcache[groupcounter]['vars']=edecl\n if last_name is not None:\n previous_context = ('variable',last_name,groupcounter)\n elif case=='parameter':\n edecl=groupcache[groupcounter]['vars']\n ll=string.strip(m.group('after'))[1:-1]\n last_name = None\n for e in string.split(markoutercomma(ll),'@,@'):\n try:\n k,initexpr=map(string.strip,string.split(e,'='))\n except:\n outmess('analyzeline: could not extract name,expr in parameter statement \"%s\" of \"%s\"\\n'%(e,ll));continue\n params = get_parameters(edecl)\n k=rmbadname1(k)\n if not edecl.has_key(k): edecl[k]={}\n if edecl[k].has_key('=') and (not edecl[k]['=']==initexpr):\n outmess('analyzeline: Overwriting the value of parameter \"%s\" (\"%s\") with \"%s\".\\n'%(k,edecl[k]['='],initexpr))\n t = determineexprtype(initexpr,params)\n if t:\n if t.get('typespec')=='real':\n tt = list(initexpr)\n for m in real16pattern.finditer(initexpr):\n tt[m.start():m.end()] = list(\\\n initexpr[m.start():m.end()].lower().replace('d', 'e'))\n initexpr = \"\".join(tt)\n elif t.get('typespec')=='complex':\n initexpr = initexpr[1:].lower().replace('d','e').\\\n replace(',','+1j*(')\n try:\n v = eval(initexpr,{},params)\n except (SyntaxError,NameError),msg:\n errmess('analyzeline: Failed to evaluate %r. Ignoring: %s\\n'\\\n % (initexpr, msg))\n continue\n edecl[k]['='] = repr(v)\n if edecl[k].has_key('attrspec'):\n edecl[k]['attrspec'].append('parameter')\n else: edecl[k]['attrspec']=['parameter']\n last_name = k\n groupcache[groupcounter]['vars']=edecl\n if last_name is not None:\n previous_context = ('variable',last_name,groupcounter)\n elif case=='implicit':\n if string.lower(string.strip(m.group('after')))=='none':\n groupcache[groupcounter]['implicit']=None\n elif m.group('after'):\n if groupcache[groupcounter].has_key('implicit'):\n impl=groupcache[groupcounter]['implicit']\n else: impl={}\n if impl is None:\n outmess('analyzeline: Overwriting earlier \"implicit none\" statement.\\n')\n impl={}\n for e in string.split(markoutercomma(m.group('after')),'@,@'):\n decl={}\n m1=re.match(r'\\s*(?P.*?)\\s*(\\(\\s*(?P[a-z-, ]+)\\s*\\)\\s*|)\\Z',e,re.I)\n if not m1:\n outmess('analyzeline: could not extract info of implicit statement part \"%s\"\\n'%(e));continue\n m2=typespattern4implicit.match(m1.group('this'))\n if not m2:\n outmess('analyzeline: could not extract types pattern of implicit statement part \"%s\"\\n'%(e));continue\n typespec,selector,attr,edecl=cracktypespec0(m2.group('this'),m2.group('after'))\n kindselect,charselect,typename=cracktypespec(typespec,selector)\n decl['typespec']=typespec\n decl['kindselector']=kindselect\n decl['charselector']=charselect\n decl['typename']=typename\n for k in decl.keys():\n if not decl[k]: del decl[k]\n for r in string.split(markoutercomma(m1.group('after')),'@,@'):\n if '-' in r:\n try: begc,endc=map(string.strip,string.split(r,'-'))\n except:\n outmess('analyzeline: expected \"-\" instead of \"%s\" in range list of implicit statement\\n'%r);continue\n else: begc=endc=string.strip(r)\n if not len(begc)==len(endc)==1:\n outmess('analyzeline: expected \"-\" instead of \"%s\" in range list of implicit statement (2)\\n'%r);continue\n for o in range(ord(begc),ord(endc)+1):\n impl[chr(o)]=decl\n groupcache[groupcounter]['implicit']=impl\n elif case=='data':\n ll=[]\n dl='';il='';f=0;fc=1\n for c in m.group('after'):\n if c==\"'\": fc=not fc\n if c=='/' and fc: f=f+1;continue\n if f==0: dl=dl+c\n elif f==1: il=il+c\n elif f==2:\n dl = dl.strip()\n if dl.startswith(','):\n dl = dl[1:].strip()\n ll.append([dl,il])\n dl=c;il='';f=0\n if f==2:\n dl = dl.strip()\n if dl.startswith(','):\n dl = dl[1:].strip()\n ll.append([dl,il])\n vars={}\n if groupcache[groupcounter].has_key('vars'):\n vars=groupcache[groupcounter]['vars']\n last_name = None\n for l in ll:\n l=map(string.strip,l)\n if l[0][0]==',':l[0]=l[0][1:]\n if l[0][0]=='(':\n outmess('analyzeline: implied-DO list \"%s\" is not supported. Skipping.\\n'%l[0])\n continue\n #if '(' in l[0]:\n # #outmess('analyzeline: ignoring this data statement.\\n')\n # continue\n i=0;j=0;llen=len(l[1])\n for v in rmbadname(map(string.strip,string.split(markoutercomma(l[0]),'@,@'))):\n if v[0]=='(':\n outmess('analyzeline: implied-DO list \"%s\" is not supported. Skipping.\\n'%v)\n # XXX: subsequent init expressions may get wrong values.\n # Ignoring since data statements are irrelevant for wrapping.\n continue\n fc=0\n while (i=3:\n bn = string.strip(bn)\n if not bn: bn='_BLNK_'\n cl.append([bn,ol])\n f=f-2;bn='';ol=''\n if f%2: bn=bn+c\n else: ol=ol+c\n bn = string.strip(bn)\n if not bn: bn='_BLNK_'\n cl.append([bn,ol])\n commonkey={}\n if groupcache[groupcounter].has_key('common'):\n commonkey=groupcache[groupcounter]['common']\n for c in cl:\n if commonkey.has_key(c[0]):\n outmess('analyzeline: previously defined common block encountered. Skipping.\\n')\n continue\n commonkey[c[0]]=[]\n for i in map(string.strip,string.split(markoutercomma(c[1]),'@,@')):\n if i: commonkey[c[0]].append(i)\n groupcache[groupcounter]['common']=commonkey\n previous_context = ('common',bn,groupcounter)\n elif case=='use':\n m1=re.match(r'\\A\\s*(?P\\b[\\w]+\\b)\\s*((,(\\s*\\bonly\\b\\s*:|(?P))\\s*(?P.*))|)\\s*\\Z',m.group('after'),re.I)\n if m1:\n mm=m1.groupdict()\n if not groupcache[groupcounter].has_key('use'): groupcache[groupcounter]['use']={}\n name=m1.group('name')\n groupcache[groupcounter]['use'][name]={}\n isonly=0\n if mm.has_key('list') and mm['list'] is not None:\n if mm.has_key('notonly') and mm['notonly'] is None:isonly=1\n groupcache[groupcounter]['use'][name]['only']=isonly\n ll=map(string.strip,string.split(mm['list'],','))\n rl={}\n for l in ll:\n if '=' in l:\n m2=re.match(r'\\A\\s*(?P\\b[\\w]+\\b)\\s*=\\s*>\\s*(?P\\b[\\w]+\\b)\\s*\\Z',l,re.I)\n if m2: rl[string.strip(m2.group('local'))]=string.strip(m2.group('use'))\n else:\n outmess('analyzeline: Not local=>use pattern found in %s\\n'%`l`)\n else:\n rl[l]=l\n groupcache[groupcounter]['use'][name]['map']=rl\n else:\n pass\n\n else:\n print m.groupdict()\n outmess('analyzeline: Could not crack the use statement.\\n')\n elif case in ['f2pyenhancements']:\n if not groupcache[groupcounter].has_key ('f2pyenhancements'):\n groupcache[groupcounter]['f2pyenhancements'] = {}\n d = groupcache[groupcounter]['f2pyenhancements']\n if m.group('this')=='usercode' and d.has_key('usercode'):\n if type(d['usercode']) is type(''):\n d['usercode'] = [d['usercode']]\n d['usercode'].append(m.group('after'))\n else:\n d[m.group('this')] = m.group('after')\n elif case=='multiline':\n if previous_context is None:\n if verbose:\n outmess('analyzeline: No context for multiline block.\\n')\n return\n gc = groupcounter\n #gc = previous_context[2]\n appendmultiline(groupcache[gc],\n previous_context[:2],\n m.group('this'))\n else:\n if verbose>1:\n print m.groupdict()\n outmess('analyzeline: No code implemented for line.\\n')\n\ndef appendmultiline(group, context_name,ml):\n if not group.has_key('f2pymultilines'):\n group['f2pymultilines'] = {}\n d = group['f2pymultilines']\n if not d.has_key(context_name):\n d[context_name] = []\n d[context_name].append(ml)\n return\n\ndef cracktypespec0(typespec,ll):\n selector=None\n attr=None\n if re.match(r'double\\s*complex',typespec,re.I): typespec='double complex'\n elif re.match(r'double\\s*precision',typespec,re.I): typespec='double precision'\n else: typespec=string.lower(string.strip(typespec))\n m1=selectpattern.match(markouterparen(ll))\n if not m1:\n outmess('cracktypespec0: no kind/char_selector pattern found for line.\\n')\n return\n d=m1.groupdict()\n for k in d.keys(): d[k]=unmarkouterparen(d[k])\n if typespec in ['complex','integer','logical','real','character','type']:\n selector=d['this']\n ll=d['after']\n i=string.find(ll,'::')\n if i>=0:\n attr=string.strip(ll[:i])\n ll=ll[i+2:]\n return typespec,selector,attr,ll\n#####\nnamepattern=re.compile(r'\\s*(?P\\b[\\w]+\\b)\\s*(?P.*)\\s*\\Z',re.I)\nkindselector=re.compile(r'\\s*(\\(\\s*(kind\\s*=)?\\s*(?P.*)\\s*\\)|[*]\\s*(?P.*?))\\s*\\Z',re.I)\ncharselector=re.compile(r'\\s*(\\((?P.*)\\)|[*]\\s*(?P.*))\\s*\\Z',re.I)\nlenkindpattern=re.compile(r'\\s*(kind\\s*=\\s*(?P.*?)\\s*(@,@\\s*len\\s*=\\s*(?P.*)|)|(len\\s*=\\s*|)(?P.*?)\\s*(@,@\\s*(kind\\s*=\\s*|)(?P.*)|))\\s*\\Z',re.I)\nlenarraypattern=re.compile(r'\\s*(@\\(@\\s*(?!/)\\s*(?P.*?)\\s*@\\)@\\s*[*]\\s*(?P.*?)|([*]\\s*(?P.*?)|)\\s*(@\\(@\\s*(?!/)\\s*(?P.*?)\\s*@\\)@|))\\s*(=\\s*(?P.*?)|(@\\(@|)/\\s*(?P.*?)\\s*/(@\\)@|)|)\\s*\\Z',re.I)\ndef removespaces(expr):\n expr=string.strip(expr)\n if len(expr)<=1: return expr\n expr2=expr[0]\n for i in range(1,len(expr)-1):\n if expr[i]==' ' and \\\n ((expr[i+1] in \"()[]{}= \") or (expr[i-1] in \"()[]{}= \")): continue\n expr2=expr2+expr[i]\n expr2=expr2+expr[-1]\n return expr2\ndef markinnerspaces(line):\n l='';f=0\n cc='\\''\n cc1='\"'\n cb=''\n for c in line:\n if cb=='\\\\' and c in ['\\\\','\\'','\"']:\n l=l+c;\n cb=c\n continue\n if f==0 and c in ['\\'','\"']: cc=c; cc1={'\\'':'\"','\"':'\\''}[c]\n if c==cc:f=f+1\n elif c==cc:f=f-1\n elif c==' ' and f==1: l=l+'@_@'; continue\n l=l+c;cb=c\n return l\ndef updatevars(typespec,selector,attrspec,entitydecl):\n global groupcache,groupcounter\n last_name = None\n kindselect,charselect,typename=cracktypespec(typespec,selector)\n if attrspec:\n attrspec=map(string.strip,string.split(markoutercomma(attrspec),'@,@'))\n l = []\n c = re.compile(r'(?P[a-zA-Z]+)')\n for a in attrspec:\n m = c.match(a)\n if m:\n s = string.lower(m.group('start'))\n a = s + a[len(s):]\n l.append(a)\n attrspec = l\n el=map(string.strip,string.split(markoutercomma(entitydecl),'@,@'))\n el1=[]\n for e in el:\n for e1 in map(string.strip,string.split(markoutercomma(removespaces(markinnerspaces(e)),comma=' '),'@ @')):\n if e1: el1.append(string.replace(e1,'@_@',' '))\n for e in el1:\n m=namepattern.match(e)\n if not m:\n outmess('updatevars: no name pattern found for entity=%s. Skipping.\\n'%(`e`))\n continue\n ename=rmbadname1(m.group('name'))\n edecl={}\n if groupcache[groupcounter]['vars'].has_key(ename):\n edecl=groupcache[groupcounter]['vars'][ename].copy()\n has_typespec = edecl.has_key('typespec')\n if not has_typespec:\n edecl['typespec']=typespec\n elif typespec and (not typespec==edecl['typespec']):\n outmess('updatevars: attempt to change the type of \"%s\" (\"%s\") to \"%s\". Ignoring.\\n' % (ename,edecl['typespec'],typespec))\n if not edecl.has_key('kindselector'):\n edecl['kindselector']=copy.copy(kindselect)\n elif kindselect:\n for k in kindselect.keys():\n if edecl['kindselector'].has_key(k) and (not kindselect[k]==edecl['kindselector'][k]):\n outmess('updatevars: attempt to change the kindselector \"%s\" of \"%s\" (\"%s\") to \"%s\". Ignoring.\\n' % (k,ename,edecl['kindselector'][k],kindselect[k]))\n else: edecl['kindselector'][k]=copy.copy(kindselect[k])\n if not edecl.has_key('charselector') and charselect:\n if not has_typespec:\n edecl['charselector']=charselect\n else:\n errmess('updatevars:%s: attempt to change empty charselector to %r. Ignoring.\\n' \\\n %(ename,charselect))\n elif charselect:\n for k in charselect.keys():\n if edecl['charselector'].has_key(k) and (not charselect[k]==edecl['charselector'][k]):\n outmess('updatevars: attempt to change the charselector \"%s\" of \"%s\" (\"%s\") to \"%s\". Ignoring.\\n' % (k,ename,edecl['charselector'][k],charselect[k]))\n else: edecl['charselector'][k]=copy.copy(charselect[k])\n if not edecl.has_key('typename'):\n edecl['typename']=typename\n elif typename and (not edecl['typename']==typename):\n outmess('updatevars: attempt to change the typename of \"%s\" (\"%s\") to \"%s\". Ignoring.\\n' % (ename,edecl['typename'],typename))\n if not edecl.has_key('attrspec'):\n edecl['attrspec']=copy.copy(attrspec)\n elif attrspec:\n for a in attrspec:\n if a not in edecl['attrspec']:\n edecl['attrspec'].append(a)\n else:\n edecl['typespec']=copy.copy(typespec)\n edecl['kindselector']=copy.copy(kindselect)\n edecl['charselector']=copy.copy(charselect)\n edecl['typename']=typename\n edecl['attrspec']=copy.copy(attrspec)\n if m.group('after'):\n m1=lenarraypattern.match(markouterparen(m.group('after')))\n if m1:\n d1=m1.groupdict()\n for lk in ['len','array','init']:\n if d1[lk+'2'] is not None: d1[lk]=d1[lk+'2']; del d1[lk+'2']\n for k in d1.keys():\n if d1[k] is not None: d1[k]=unmarkouterparen(d1[k])\n else: del d1[k]\n if d1.has_key('len') and d1.has_key('array'):\n if d1['len']=='':\n d1['len']=d1['array']\n del d1['array']\n else:\n d1['array']=d1['array']+','+d1['len']\n del d1['len']\n errmess('updatevars: \"%s %s\" is mapped to \"%s %s(%s)\"\\n'%(typespec,e,typespec,ename,d1['array']))\n if d1.has_key('array'):\n dm = 'dimension(%s)'%d1['array']\n if not edecl.has_key('attrspec') or (not edecl['attrspec']):\n edecl['attrspec']=[dm]\n else:\n edecl['attrspec'].append(dm)\n for dm1 in edecl['attrspec']:\n if dm1[:9]=='dimension' and dm1!=dm:\n del edecl['attrspec'][-1]\n errmess('updatevars:%s: attempt to change %r to %r. Ignoring.\\n' \\\n % (ename,dm1,dm))\n break\n\n if d1.has_key('len'):\n if typespec in ['complex','integer','logical','real']:\n if (not edecl.has_key('kindselector')) or (not edecl['kindselector']):\n edecl['kindselector']={}\n edecl['kindselector']['*']=d1['len']\n elif typespec == 'character':\n if (not edecl.has_key('charselector')) or (not edecl['charselector']): edecl['charselector']={}\n if edecl['charselector'].has_key('len'): del edecl['charselector']['len']\n edecl['charselector']['*']=d1['len']\n if d1.has_key('init'):\n if edecl.has_key('=') and (not edecl['=']==d1['init']):\n outmess('updatevars: attempt to change the init expression of \"%s\" (\"%s\") to \"%s\". Ignoring.\\n' % (ename,edecl['='],d1['init']))\n else:\n edecl['=']=d1['init']\n else:\n outmess('updatevars: could not crack entity declaration \"%s\". Ignoring.\\n'%(ename+m.group('after')))\n for k in edecl.keys():\n if not edecl[k]: del edecl[k]\n groupcache[groupcounter]['vars'][ename]=edecl\n if groupcache[groupcounter].has_key('varnames'):\n groupcache[groupcounter]['varnames'].append(ename)\n last_name = ename\n return last_name\n\ndef cracktypespec(typespec,selector):\n kindselect=None\n charselect=None\n typename=None\n if selector:\n if typespec in ['complex','integer','logical','real']:\n kindselect=kindselector.match(selector)\n if not kindselect:\n outmess('cracktypespec: no kindselector pattern found for %s\\n'%(`selector`))\n return\n kindselect=kindselect.groupdict()\n kindselect['*']=kindselect['kind2']\n del kindselect['kind2']\n for k in kindselect.keys():\n if not kindselect[k]: del kindselect[k]\n for k,i in kindselect.items():\n kindselect[k] = rmbadname1(i)\n elif typespec=='character':\n charselect=charselector.match(selector)\n if not charselect:\n outmess('cracktypespec: no charselector pattern found for %s\\n'%(`selector`))\n return\n charselect=charselect.groupdict()\n charselect['*']=charselect['charlen']\n del charselect['charlen']\n if charselect['lenkind']:\n lenkind=lenkindpattern.match(markoutercomma(charselect['lenkind']))\n lenkind=lenkind.groupdict()\n for lk in ['len','kind']:\n if lenkind[lk+'2']:\n lenkind[lk]=lenkind[lk+'2']\n charselect[lk]=lenkind[lk]\n del lenkind[lk+'2']\n del charselect['lenkind']\n for k in charselect.keys():\n if not charselect[k]: del charselect[k]\n for k,i in charselect.items():\n charselect[k] = rmbadname1(i)\n elif typespec=='type':\n typename=re.match(r'\\s*\\(\\s*(?P\\w+)\\s*\\)',selector,re.I)\n if typename: typename=typename.group('name')\n else: outmess('cracktypespec: no typename found in %s\\n'%(`typespec+selector`))\n else:\n outmess('cracktypespec: no selector used for %s\\n'%(`selector`))\n return kindselect,charselect,typename\n######\ndef setattrspec(decl,attr,force=0):\n if not decl: decl={}\n if not attr: return decl\n if not decl.has_key('attrspec'):\n decl['attrspec']=[attr]\n return decl\n if force: decl['attrspec'].append(attr)\n if attr in decl['attrspec']: return decl\n if attr=='static' and 'automatic' not in decl['attrspec']:\n decl['attrspec'].append(attr)\n elif attr=='automatic' and 'static' not in decl['attrspec']:\n decl['attrspec'].append(attr)\n elif attr=='public' and 'private' not in decl['attrspec']:\n decl['attrspec'].append(attr)\n elif attr=='private' and 'public' not in decl['attrspec']:\n decl['attrspec'].append(attr)\n else:\n decl['attrspec'].append(attr)\n return decl\ndef setkindselector(decl,sel,force=0):\n if not decl: decl={}\n if not sel: return decl\n if not decl.has_key('kindselector'):\n decl['kindselector']=sel\n return decl\n for k in sel.keys():\n if force or not decl['kindselector'].has_key(k):\n decl['kindselector'][k]=sel[k]\n return decl\ndef setcharselector(decl,sel,force=0):\n if not decl: decl={}\n if not sel: return decl\n if not decl.has_key('charselector'):\n decl['charselector']=sel\n return decl\n for k in sel.keys():\n if force or not decl['charselector'].has_key(k):\n decl['charselector'][k]=sel[k]\n return decl\ndef getblockname(block,unknown='unknown'):\n if block.has_key('name'): return block['name']\n return unknown\n###### post processing\ndef setmesstext(block):\n global filepositiontext\n try: filepositiontext='In: %s:%s\\n'%(block['from'],block['name'])\n except: pass\n\ndef get_usedict(block):\n usedict = {}\n if block.has_key('parent_block'):\n usedict = get_usedict(block['parent_block'])\n if block.has_key('use'):\n usedict.update(block['use'])\n return usedict\n\ndef get_useparameters(block, param_map=None):\n global f90modulevars\n if param_map is None:\n param_map = {}\n usedict = get_usedict(block)\n if not usedict:\n return param_map\n for usename,mapping in usedict.items():\n usename = string.lower(usename)\n if not f90modulevars.has_key(usename):\n continue\n mvars = f90modulevars[usename]\n params = get_parameters(mvars)\n if not params:\n continue\n # XXX: apply mapping\n if mapping:\n errmess('get_useparameters: mapping for %s not impl.' % (mapping))\n for k,v in params.items():\n if param_map.has_key(k):\n outmess('get_useparameters: overriding parameter %s with'\\\n ' value from module %s' % (`k`,`usename`))\n param_map[k] = v\n return param_map\n\ndef postcrack2(block,tab='',param_map=None):\n global f90modulevars\n if not f90modulevars:\n return block\n if type(block)==types.ListType:\n ret = []\n for g in block:\n g = postcrack2(g,tab=tab+'\\t',param_map=param_map)\n ret.append(g)\n return ret\n setmesstext(block)\n outmess('%sBlock: %s\\n'%(tab,block['name']),0)\n\n if param_map is None:\n param_map = get_useparameters(block)\n\n if param_map is not None and block.has_key('vars'):\n vars = block['vars']\n for n in vars.keys():\n var = vars[n]\n if var.has_key('kindselector'):\n kind = var['kindselector']\n if kind.has_key('kind'):\n val = kind['kind']\n if param_map.has_key(val):\n kind['kind'] = param_map[val]\n new_body = []\n for b in block['body']:\n b = postcrack2(b,tab=tab+'\\t',param_map=param_map)\n new_body.append(b)\n block['body'] = new_body\n\n return block\n\ndef postcrack(block,args=None,tab=''):\n \"\"\"\n TODO:\n function return values\n determine expression types if in argument list\n \"\"\"\n global usermodules,onlyfunctions\n if type(block)==types.ListType:\n gret=[]\n uret=[]\n for g in block:\n setmesstext(g)\n g=postcrack(g,tab=tab+'\\t')\n if g.has_key('name') and string.find(g['name'],'__user__')>=0: # sort user routines to appear first\n uret.append(g)\n else:\n gret.append(g)\n return uret+gret\n setmesstext(block)\n if (not type(block)==types.DictType) and not block.has_key('block'):\n raise 'postcrack: Expected block dictionary instead of ',block\n if block.has_key('name') and not block['name']=='unknown_interface':\n outmess('%sBlock: %s\\n'%(tab,block['name']),0)\n blocktype=block['block']\n block=analyzeargs(block)\n block=analyzecommon(block)\n block['vars']=analyzevars(block)\n block['sortvars']=sortvarnames(block['vars'])\n if block.has_key('args') and block['args']:\n args=block['args']\n block['body']=analyzebody(block,args,tab=tab)\n\n userisdefined=[]\n## fromuser = []\n if block.has_key('use'):\n useblock=block['use']\n for k in useblock.keys():\n if string.find(k,'__user__')>=0:\n userisdefined.append(k)\n## if useblock[k].has_key('map'):\n## for n in useblock[k]['map'].values():\n## if n not in fromuser: fromuser.append(n)\n else: useblock={}\n name=''\n if block.has_key('name'):name=block['name']\n if block.has_key('externals') and block['externals']:# and not userisdefined: # Build a __user__ module\n interfaced=[]\n if block.has_key('interfaced'): interfaced=block['interfaced']\n mvars=copy.copy(block['vars'])\n if name: mname=name+'__user__routines'\n else: mname='unknown__user__routines'\n if mname in userisdefined:\n i=1\n while '%s_%i'%(mname,i) in userisdefined: i=i+1\n mname='%s_%i'%(mname,i)\n interface={'block':'interface','body':[],'vars':{},'name':name+'_user_interface'}\n for e in block['externals']:\n## if e in fromuser:\n## outmess(' Skipping %s that is defined explicitly in another use statement\\n'%(`e`))\n## continue\n if e in interfaced:\n edef=[]\n j=-1\n for b in block['body']:\n j=j+1\n if b['block']=='interface':\n i=-1\n for bb in b['body']:\n i=i+1\n if bb.has_key('name') and bb['name']==e:\n edef=copy.copy(bb)\n del b['body'][i]\n break\n if edef:\n if not b['body']: del block['body'][j]\n del interfaced[interfaced.index(e)]\n break\n interface['body'].append(edef)\n else:\n if mvars.has_key(e) and not isexternal(mvars[e]):\n interface['vars'][e]=mvars[e]\n if interface['vars'] or interface['body']:\n block['interfaced']=interfaced\n mblock={'block':'python module','body':[interface],'vars':{},'name':mname,'interfaced':block['externals']}\n useblock[mname]={}\n usermodules.append(mblock)\n if useblock:\n block['use']=useblock\n return block\n\ndef sortvarnames(vars):\n indep = []\n dep = []\n for v in vars.keys():\n if vars[v].has_key('depend') and vars[v]['depend']:\n dep.append(v)\n #print '%s depends on %s'%(v,vars[v]['depend'])\n else: indep.append(v)\n n = len(dep)\n i = 0\n while dep: #XXX: How to catch dependence cycles correctly?\n v = dep[0]\n fl = 0\n for w in dep[1:]:\n if w in vars[v]['depend']:\n fl = 1\n break\n if fl:\n dep = dep[1:]+[v]\n i = i + 1\n if i>n:\n errmess('sortvarnames: failed to compute dependencies because'\n ' of cyclic dependencies between '\n +string.join(dep,', ')+'\\n')\n indep = indep + dep\n break\n else:\n indep.append(v)\n dep = dep[1:]\n n = len(dep)\n i = 0\n #print indep\n return indep\n\ndef analyzecommon(block):\n if not hascommon(block): return block\n commonvars=[]\n for k in block['common'].keys():\n comvars=[]\n for e in block['common'][k]:\n m=re.match(r'\\A\\s*\\b(?P.*?)\\b\\s*(\\((?P.*?)\\)|)\\s*\\Z',e,re.I)\n if m:\n dims=[]\n if m.group('dims'):\n dims=map(string.strip,string.split(markoutercomma(m.group('dims')),'@,@'))\n n=string.strip(m.group('name'))\n if block['vars'].has_key(n):\n if block['vars'][n].has_key('attrspec'):\n block['vars'][n]['attrspec'].append('dimension(%s)'%(string.join(dims,',')))\n else:\n block['vars'][n]['attrspec']=['dimension(%s)'%(string.join(dims,','))]\n else:\n if dims:\n block['vars'][n]={'attrspec':['dimension(%s)'%(string.join(dims,','))]}\n else: block['vars'][n]={}\n if n not in commonvars: commonvars.append(n)\n else:\n n=e\n errmess('analyzecommon: failed to extract \"[()]\" from \"%s\" in common /%s/.\\n'%(e,k))\n comvars.append(n)\n block['common'][k]=comvars\n if not block.has_key('commonvars'):\n block['commonvars']=commonvars\n else:\n block['commonvars']=block['commonvars']+commonvars\n return block\ndef analyzebody(block,args,tab=''):\n global usermodules,skipfuncs,onlyfuncs,f90modulevars\n setmesstext(block)\n body=[]\n for b in block['body']:\n b['parent_block'] = block\n if b['block'] in ['function','subroutine']:\n if args is not None and b['name'] not in args:\n continue\n else:\n as=b['args']\n if b['name'] in skipfuncs:\n continue\n if onlyfuncs and b['name'] not in onlyfuncs:\n continue\n else: as=args\n b=postcrack(b,as,tab=tab+'\\t')\n if b['block']=='interface' and not b['body']:\n if not b.has_key('f2pyenhancements'):\n continue\n if string.replace(b['block'],' ','')=='pythonmodule':\n usermodules.append(b)\n else:\n if b['block']=='module':\n f90modulevars[b['name']] = b['vars']\n body.append(b)\n return body\ndef buildimplicitrules(block):\n setmesstext(block)\n implicitrules=defaultimplicitrules\n attrrules={}\n if block.has_key('implicit'):\n if block['implicit'] is None:\n implicitrules=None\n if verbose>1:\n outmess('buildimplicitrules: no implicit rules for routine %s.\\n'%`block['name']`)\n else:\n for k in block['implicit'].keys():\n if block['implicit'][k].get('typespec') not in ['static','automatic']:\n implicitrules[k]=block['implicit'][k]\n else:\n attrrules[k]=block['implicit'][k]['typespec']\n return implicitrules,attrrules\n\ndef myeval(e,g=None,l=None):\n r = eval(e,g,l)\n if type(r) in [type(0),type(0.0)]:\n return r\n raise ValueError,'r=%r' % (r)\n\ngetlincoef_re_1 = re.compile(r'\\A\\b\\w+\\b\\Z',re.I)\ndef getlincoef(e,xset): # e = a*x+b ; x in xset\n try:\n c = int(myeval(e,{},{}))\n return 0,c,None\n except: pass\n if getlincoef_re_1.match(e):\n return 1,0,e\n len_e = len(e)\n for x in xset:\n if len(x)>len_e: continue\n re_1 = re.compile(r'(?P.*?)\\b'+x+r'\\b(?P.*)',re.I)\n m = re_1.match(e)\n if m:\n try:\n m1 = re_1.match(e)\n while m1:\n ee = '%s(%s)%s'%(m1.group('before'),0,m1.group('after'))\n m1 = re_1.match(ee)\n b = myeval(ee,{},{})\n m1 = re_1.match(e)\n while m1:\n ee = '%s(%s)%s'%(m1.group('before'),1,m1.group('after'))\n m1 = re_1.match(ee)\n a = myeval(ee,{},{}) - b\n m1 = re_1.match(e)\n while m1:\n ee = '%s(%s)%s'%(m1.group('before'),0.5,m1.group('after'))\n m1 = re_1.match(ee)\n c = myeval(ee,{},{})\n if (a*0.5+b==c):\n return a,b,x\n except: pass\n break\n return None,None,None\n\n_varname_match = re.compile(r'\\A[a-z]\\w*\\Z').match\ndef getarrlen(dl,args,star='*'):\n edl = []\n try: edl.append(myeval(dl[0],{},{}))\n except: edl.append(dl[0])\n try: edl.append(myeval(dl[1],{},{}))\n except: edl.append(dl[1])\n if type(edl[0]) is type(0):\n p1 = 1-edl[0]\n if p1==0: d = str(dl[1])\n elif p1<0: d = '%s-%s'%(dl[1],-p1)\n else: d = '%s+%s'%(dl[1],p1)\n elif type(edl[1]) is type(0):\n p1 = 1+edl[1]\n if p1==0: d='-(%s)' % (dl[0])\n else: d='%s-(%s)' % (p1,dl[0])\n else: d = '%s-(%s)+1'%(dl[1],dl[0])\n try: return `myeval(d,{},{})`,None,None\n except: pass\n d1,d2=getlincoef(dl[0],args),getlincoef(dl[1],args)\n if None not in [d1[0],d2[0]]:\n if (d1[0],d2[0])==(0,0):\n return `d2[1]-d1[1]+1`,None,None\n b = d2[1] - d1[1] + 1\n d1 = (d1[0],0,d1[2])\n d2 = (d2[0],b,d2[2])\n if d1[0]==0 and d2[2] in args:\n if b<0: return '%s * %s - %s'%(d2[0],d2[2],-b),d2[2],'+%s)/(%s)'%(-b,d2[0])\n elif b: return '%s * %s + %s'%(d2[0],d2[2],b),d2[2],'-%s)/(%s)'%(b,d2[0])\n else: return '%s * %s'%(d2[0],d2[2]),d2[2],')/(%s)'%(d2[0])\n if d2[0]==0 and d1[2] in args:\n\n if b<0: return '%s * %s - %s'%(-d1[0],d1[2],-b),d1[2],'+%s)/(%s)'%(-b,-d1[0])\n elif b: return '%s * %s + %s'%(-d1[0],d1[2],b),d1[2],'-%s)/(%s)'%(b,-d1[0])\n else: return '%s * %s'%(-d1[0],d1[2]),d1[2],')/(%s)'%(-d1[0])\n if d1[2]==d2[2] and d1[2] in args:\n a = d2[0] - d1[0]\n if not a: return `b`,None,None\n if b<0: return '%s * %s - %s'%(a,d1[2],-b),d2[2],'+%s)/(%s)'%(-b,a)\n elif b: return '%s * %s + %s'%(a,d1[2],b),d2[2],'-%s)/(%s)'%(b,a)\n else: return '%s * %s'%(a,d1[2]),d2[2],')/(%s)'%(a)\n if d1[0]==d2[0]==1:\n c = str(d1[2])\n if c not in args:\n if _varname_match(c):\n outmess('\\tgetarrlen:variable \"%s\" undefined\\n' % (c))\n c = '(%s)'%c\n if b==0: d='%s-%s' % (d2[2],c)\n elif b<0: d='%s-%s-%s' % (d2[2],c,-b)\n else: d='%s-%s+%s' % (d2[2],c,b)\n elif d1[0]==0:\n c2 = str(d2[2])\n if c2 not in args:\n if _varname_match(c2):\n outmess('\\tgetarrlen:variable \"%s\" undefined\\n' % (c2))\n c2 = '(%s)'%c2\n if d2[0]==1: pass\n elif d2[0]==-1: c2='-%s' %c2\n else: c2='%s*%s'%(d2[0],c2)\n\n if b==0: d=c2\n elif b<0: d='%s-%s' % (c2,-b)\n else: d='%s+%s' % (c2,b)\n elif d2[0]==0:\n c1 = str(d1[2])\n if c1 not in args:\n if _varname_match(c1):\n outmess('\\tgetarrlen:variable \"%s\" undefined\\n' % (c1))\n c1 = '(%s)'%c1\n if d1[0]==1: c1='-%s'%c1\n elif d1[0]==-1: c1='+%s'%c1\n elif d1[0]<0: c1='+%s*%s'%(-d1[0],c1)\n else: c1 = '-%s*%s' % (d1[0],c1)\n\n if b==0: d=c1\n elif b<0: d='%s-%s' % (c1,-b)\n else: d='%s+%s' % (c1,b)\n else:\n c1 = str(d1[2])\n if c1 not in args:\n if _varname_match(c1):\n outmess('\\tgetarrlen:variable \"%s\" undefined\\n' % (c1))\n c1 = '(%s)'%c1\n if d1[0]==1: c1='-%s'%c1\n elif d1[0]==-1: c1='+%s'%c1\n elif d1[0]<0: c1='+%s*%s'%(-d1[0],c1)\n else: c1 = '-%s*%s' % (d1[0],c1)\n\n c2 = str(d2[2])\n if c2 not in args:\n if _varname_match(c2):\n outmess('\\tgetarrlen:variable \"%s\" undefined\\n' % (c2))\n c2 = '(%s)'%c2\n if d2[0]==1: pass\n elif d2[0]==-1: c2='-%s' %c2\n else: c2='%s*%s'%(d2[0],c2)\n\n if b==0: d='%s%s' % (c2,c1)\n elif b<0: d='%s%s-%s' % (c2,c1,-b)\n else: d='%s%s+%s' % (c2,c1,b)\n return d,None,None\n\nword_pattern = re.compile(r'\\b[a-z][\\w$]*\\b',re.I)\n\ndef _get_depend_dict(name, vars, deps):\n if vars.has_key(name):\n words = vars[name].get('depend',[])\n\n if vars[name].has_key('=') and not isstring(vars[name]):\n for word in word_pattern.findall(vars[name]['=']):\n if word not in words and vars.has_key(word):\n words.append(word)\n for word in words[:]:\n for w in deps.get(word,[]) \\\n or _get_depend_dict(word, vars, deps):\n if w not in words:\n words.append(w)\n else:\n outmess('_get_depend_dict: no dependence info for %s\\n' % (`name`))\n words = []\n deps[name] = words\n return words\n\ndef _calc_depend_dict(vars):\n names = vars.keys()\n depend_dict = {}\n for n in names:\n _get_depend_dict(n, vars, depend_dict)\n return depend_dict\n\ndef get_sorted_names(vars):\n \"\"\"\n \"\"\"\n depend_dict = _calc_depend_dict(vars)\n names = []\n for name in depend_dict.keys():\n if not depend_dict[name]:\n names.append(name)\n del depend_dict[name]\n while depend_dict:\n for name, lst in depend_dict.items():\n new_lst = [n for n in lst if depend_dict.has_key(n)]\n if not new_lst:\n names.append(name)\n del depend_dict[name]\n else:\n depend_dict[name] = new_lst\n return [name for name in names if vars.has_key(name)]\n\ndef _kind_func(string):\n #XXX: return something sensible.\n if string[0] in \"'\\\"\":\n string = string[1:-1]\n if real16pattern.match(string):\n return 16\n elif real8pattern.match(string):\n return 8\n return 'kind('+string+')'\n\ndef _selected_int_kind_func(r):\n #XXX: This should be processor dependent\n m = 10**r\n if m<=2**8: return 1\n if m<=2**16: return 2\n if m<=2**32: return 4\n if m<=2**64: return 8\n if m<=2**128: return 16\n return -1\n\ndef get_parameters(vars, global_params={}):\n params = copy.copy(global_params)\n g_params = copy.copy(global_params)\n for name,func in [('kind',_kind_func),\n ('selected_int_kind',_selected_int_kind_func),\n ]:\n if not g_params.has_key(name):\n g_params[name] = func\n param_names = []\n for n in get_sorted_names(vars):\n if vars[n].has_key('attrspec') and 'parameter' in vars[n]['attrspec']:\n param_names.append(n)\n kind_re = re.compile(r'\\bkind\\s*\\(\\s*(?P.*)\\s*\\)',re.I)\n selected_int_kind_re = re.compile(r'\\bselected_int_kind\\s*\\(\\s*(?P.*)\\s*\\)',re.I)\n for n in param_names:\n if vars[n].has_key('='):\n v = vars[n]['=']\n if islogical(vars[n]):\n v = v.lower()\n for repl in [\n ('.false.','False'),\n ('.true.','True'),\n #TODO: test .eq., .neq., etc replacements.\n ]:\n v = v.replace(*repl)\n v = kind_re.sub(r'kind(\"\\1\")',v)\n v = selected_int_kind_re.sub(r'selected_int_kind(\\1)',v)\n if isinteger(vars[n]) and not selected_int_kind_re.match(v):\n v = v.split('_')[0]\n if isdouble(vars[n]):\n tt = list(v)\n for m in real16pattern.finditer(v):\n tt[m.start():m.end()] = list(\\\n v[m.start():m.end()].lower().replace('d', 'e'))\n v = string.join(tt,'')\n if iscomplex(vars[n]):\n if v[0]=='(' and v[-1]==')':\n l = markoutercomma(v[1:-1]).split('@,@')\n print n,params\n try:\n params[n] = eval(v,g_params,params)\n except Exception,msg:\n params[n] = v\n #print params\n outmess('get_parameters: got \"%s\" on %s\\n' % (msg,`v`))\n if isstring(vars[n]) and type(params[n]) is type(0):\n params[n] = chr(params[n])\n nl = string.lower(n)\n if nl!=n:\n params[nl] = params[n]\n else:\n print vars[n]\n outmess('get_parameters:parameter %s does not have value?!\\n'%(`n`))\n return params\n\ndef _eval_length(length,params):\n if length in ['(:)','(*)','*']:\n return '(*)'\n return _eval_scalar(length,params)\n\n_is_kind_number = re.compile('\\d+_').match\n\ndef _eval_scalar(value,params):\n if _is_kind_number(value):\n value = value.split('_')[0]\n try:\n value = str(eval(value,{},params))\n except (NameError, SyntaxError):\n return value\n except Exception,msg:\n errmess('\"%s\" in evaluating %r '\\\n '(available names: %s)\\n' \\\n % (msg,value,params.keys()))\n return value\n\ndef analyzevars(block):\n global f90modulevars\n setmesstext(block)\n implicitrules,attrrules=buildimplicitrules(block)\n vars=copy.copy(block['vars'])\n if block['block']=='function' and not vars.has_key(block['name']):\n vars[block['name']]={}\n if block['vars'].has_key(''):\n del vars['']\n if block['vars'][''].has_key('attrspec'):\n gen=block['vars']['']['attrspec']\n for n in vars.keys():\n for k in ['public','private']:\n if k in gen:\n vars[n]=setattrspec(vars[n],k)\n svars=[]\n args = block['args']\n for a in args:\n try:\n vars[a]\n svars.append(a)\n except KeyError:\n pass\n for n in vars.keys():\n if n not in args: svars.append(n)\n\n params = get_parameters(vars, get_useparameters(block))\n\n dep_matches = {}\n name_match = re.compile(r'\\w[\\w\\d_$]*').match\n for v in vars.keys():\n m = name_match(v)\n if m:\n n = v[m.start():m.end()]\n try:\n dep_matches[n]\n except KeyError:\n dep_matches[n] = re.compile(r'.*\\b%s\\b'%(v),re.I).match\n for n in svars:\n if n[0] in attrrules.keys():\n vars[n]=setattrspec(vars[n],attrrules[n[0]])\n if not vars[n].has_key('typespec'):\n if not(vars[n].has_key('attrspec') and 'external' in vars[n]['attrspec']):\n if implicitrules:\n ln0 = string.lower(n[0])\n for k in implicitrules[ln0].keys():\n if k=='typespec' and implicitrules[ln0][k]=='undefined':\n continue\n if not vars[n].has_key(k):\n vars[n][k]=implicitrules[ln0][k]\n elif k=='attrspec':\n for l in implicitrules[ln0][k]:\n vars[n]=setattrspec(vars[n],l)\n elif n in block['args']:\n outmess('analyzevars: typespec of variable %s is not defined in routine %s.\\n'%(`n`,block['name']))\n\n if vars[n].has_key('charselector'):\n if vars[n]['charselector'].has_key('len'):\n l = vars[n]['charselector']['len']\n try:\n l = str(eval(l,{},params))\n except:\n pass\n vars[n]['charselector']['len'] = l\n\n if vars[n].has_key('kindselector'):\n if vars[n]['kindselector'].has_key('kind'):\n l = vars[n]['kindselector']['kind']\n try:\n l = str(eval(l,{},params))\n except:\n pass\n vars[n]['kindselector']['kind'] = l\n\n savelindims = {}\n if vars[n].has_key('attrspec'):\n attr=vars[n]['attrspec']\n attr.reverse()\n vars[n]['attrspec']=[]\n dim,intent,depend,check,note=None,None,None,None,None\n for a in attr:\n if a[:9]=='dimension': dim=(string.strip(a[9:]))[1:-1]\n elif a[:6]=='intent': intent=(string.strip(a[6:]))[1:-1]\n elif a[:6]=='depend': depend=(string.strip(a[6:]))[1:-1]\n elif a[:5]=='check': check=(string.strip(a[5:]))[1:-1]\n elif a[:4]=='note': note=(string.strip(a[4:]))[1:-1]\n else: vars[n]=setattrspec(vars[n],a)\n if intent:\n if not vars[n].has_key('intent'): vars[n]['intent']=[]\n for c in map(string.strip,string.split(markoutercomma(intent),'@,@')):\n if not c in vars[n]['intent']:\n vars[n]['intent'].append(c)\n intent=None\n if note:\n note=string.replace(note,'\\\\n\\\\n','\\n\\n')\n note=string.replace(note,'\\\\n ','\\n')\n if not vars[n].has_key('note'): vars[n]['note']=[note]\n else: vars[n]['note'].append(note)\n note=None\n if depend is not None:\n if not vars[n].has_key('depend'): vars[n]['depend']=[]\n for c in rmbadname(map(string.strip,string.split(markoutercomma(depend),'@,@'))):\n if c not in vars[n]['depend']:\n vars[n]['depend'].append(c)\n depend=None\n if check is not None:\n if not vars[n].has_key('check'): vars[n]['check']=[]\n for c in map(string.strip,string.split(markoutercomma(check),'@,@')):\n if not c in vars[n]['check']:\n vars[n]['check'].append(c)\n check=None\n if dim and not vars[n].has_key('dimension'):\n vars[n]['dimension']=[]\n for d in rmbadname(map(string.strip,string.split(markoutercomma(dim),'@,@'))):\n star = '*'\n if d==':': star=':'\n if params.has_key(d):\n d = str(params[d])\n for p in params.keys():\n m = re.match(r'(?P.*?)\\b'+p+r'\\b(?P.*)',d,re.I)\n if m:\n #outmess('analyzevars:replacing parameter %s in %s (dimension of %s) with %s\\n'%(`p`,`d`,`n`,`params[p]`))\n d = m.group('before')+str(params[p])+m.group('after')\n if d==star:\n dl = [star]\n else:\n dl=string.split(markoutercomma(d,':'),'@:@')\n if len(dl)==2 and '*' in dl: # e.g. dimension(5:*)\n dl = ['*']\n d = '*'\n if len(dl)==1 and not dl[0]==star: dl = ['1',dl[0]]\n if len(dl)==2:\n d,v,di = getarrlen(dl,block['vars'].keys())\n if d[:4] == '1 * ': d = d[4:]\n if di and di[-4:] == '/(1)': di = di[:-4]\n if v: savelindims[d] = v,di\n vars[n]['dimension'].append(d)\n if vars[n].has_key('dimension'):\n if isintent_c(vars[n]):\n shape_macro = 'shape'\n else:\n shape_macro = 'shape'#'fshape'\n if isstringarray(vars[n]):\n if vars[n].has_key('charselector'):\n d = vars[n]['charselector']\n if d.has_key('*'):\n d = d['*']\n errmess('analyzevars: character array \"character*%s %s(%s)\" is considered as \"character %s(%s)\"; \"intent(c)\" is forced.\\n'\\\n %(d,n,\n ','.join(vars[n]['dimension']),\n n,','.join(vars[n]['dimension']+[d])))\n vars[n]['dimension'].append(d)\n del vars[n]['charselector']\n if not vars[n].has_key('intent'):\n vars[n]['intent'] = []\n if 'c' not in vars[n]['intent']:\n vars[n]['intent'].append('c')\n else:\n errmess(\"analyzevars: charselector=%r unhandled.\" % (d))\n if not vars[n].has_key('check') and block.has_key('args') and n in block['args']:\n flag=not vars[n].has_key('depend')\n if flag: vars[n]['depend']=[]\n vars[n]['check']=[]\n if vars[n].has_key('dimension'):\n #/----< no check\n #vars[n]['check'].append('rank(%s)==%s'%(n,len(vars[n]['dimension'])))\n i=-1; ni=len(vars[n]['dimension'])\n for d in vars[n]['dimension']:\n ddeps=[] # dependecies of 'd'\n ad=''\n pd=''\n #origd = d\n if not vars.has_key(d):\n if savelindims.has_key(d):\n pd,ad='(',savelindims[d][1]\n d = savelindims[d][0]\n else:\n for r in block['args']:\n #for r in block['vars'].keys():\n if not vars.has_key(r): continue\n if re.match(r'.*?\\b'+r+r'\\b',d,re.I):\n ddeps.append(r)\n if vars.has_key(d):\n if vars[d].has_key('attrspec'):\n for aa in vars[d]['attrspec']:\n if aa[:6]=='depend':\n ddeps=ddeps+string.split((string.strip(aa[6:]))[1:-1],',')\n if vars[d].has_key('depend'):\n ddeps=ddeps+vars[d]['depend']\n i=i+1\n if vars.has_key(d) and (not vars[d].has_key('depend')) \\\n and (not vars[d].has_key('=')) and (d not in vars[n]['depend']) \\\n and l_or(isintent_in,isintent_inout,isintent_inplace)(vars[n]):\n vars[d]['depend']=[n]\n if ni>1:\n vars[d]['=']='%s%s(%s,%s)%s'% (pd,shape_macro,n,i,ad)\n else:\n vars[d]['=']='%slen(%s)%s'% (pd,n,ad)\n # /---< no check\n if 1 and not vars[d].has_key('check'):\n if ni>1:\n vars[d]['check']=['%s%s(%s,%i)%s==%s'\\\n %(pd,shape_macro,n,i,ad,d)]\n else:\n vars[d]['check']=['%slen(%s)%s>=%s'%(pd,n,ad,d)]\n if not vars[d].has_key('attrspec'): vars[d]['attrspec']=['optional']\n if ('optional' not in vars[d]['attrspec']) and\\\n ('required' not in vars[d]['attrspec']):\n vars[d]['attrspec'].append('optional')\n elif d not in ['*',':']:\n #/----< no check\n #if ni>1: vars[n]['check'].append('shape(%s,%i)==%s'%(n,i,d))\n #else: vars[n]['check'].append('len(%s)>=%s'%(n,d))\n if flag:\n if vars.has_key(d):\n if n not in ddeps:\n vars[n]['depend'].append(d)\n else:\n vars[n]['depend'] = vars[n]['depend'] + ddeps\n elif isstring(vars[n]):\n length='1'\n if vars[n].has_key('charselector'):\n if vars[n]['charselector'].has_key('*'):\n length = _eval_length(vars[n]['charselector']['*'],\n params)\n vars[n]['charselector']['*']=length\n elif vars[n]['charselector'].has_key('len'):\n length = _eval_length(vars[n]['charselector']['len'],\n params)\n del vars[n]['charselector']['len']\n vars[n]['charselector']['*']=length\n\n if not vars[n]['check']: del vars[n]['check']\n if flag and not vars[n]['depend']: del vars[n]['depend']\n if vars[n].has_key('='):\n if not vars[n].has_key('attrspec'): vars[n]['attrspec']=[]\n if ('optional' not in vars[n]['attrspec']) and \\\n ('required' not in vars[n]['attrspec']):\n vars[n]['attrspec'].append('optional')\n if not vars[n].has_key('depend'):\n vars[n]['depend']=[]\n for v,m in dep_matches.items():\n if m(vars[n]['=']): vars[n]['depend'].append(v)\n if not vars[n]['depend']: del vars[n]['depend']\n if isscalar(vars[n]):\n vars[n]['='] = _eval_scalar(vars[n]['='],params)\n\n for n in vars.keys():\n if n==block['name']: # n is block name\n if vars[n].has_key('note'):\n block['note']=vars[n]['note']\n if block['block']=='function':\n if block.has_key('result') and vars.has_key(block['result']):\n vars[n]=appenddecl(vars[n],vars[block['result']])\n if block.has_key('prefix'):\n pr=block['prefix']; ispure=0; isrec=1\n pr1=string.replace(pr,'pure','')\n ispure=(not pr==pr1)\n pr=string.replace(pr1,'recursive','')\n isrec=(not pr==pr1)\n m=typespattern[0].match(pr)\n if m:\n typespec,selector,attr,edecl=cracktypespec0(m.group('this'),m.group('after'))\n kindselect,charselect,typename=cracktypespec(typespec,selector)\n vars[n]['typespec']=typespec\n if kindselect:\n if kindselect.has_key('kind'):\n try:\n kindselect['kind'] = eval(kindselect['kind'],{},params)\n except:\n pass\n vars[n]['kindselector']=kindselect\n if charselect: vars[n]['charselector']=charselect\n if typename: vars[n]['typename']=typename\n if ispure: vars[n]=setattrspec(vars[n],'pure')\n if isrec: vars[n]=setattrspec(vars[n],'recursive')\n else:\n outmess('analyzevars: prefix (%s) were not used\\n'%`block['prefix']`)\n if not block['block'] in ['module','pythonmodule','python module','block data']:\n if block.has_key('commonvars'):\n neededvars=copy.copy(block['args']+block['commonvars'])\n else:\n neededvars=copy.copy(block['args'])\n for n in vars.keys():\n if l_or(isintent_callback,isintent_aux)(vars[n]):\n neededvars.append(n)\n if block.has_key('entry'):\n neededvars.extend(block['entry'].keys())\n for k in block['entry'].keys():\n for n in block['entry'][k]:\n if n not in neededvars:\n neededvars.append(n)\n if block['block']=='function':\n if block.has_key('result'):\n neededvars.append(block['result'])\n else:\n neededvars.append(block['name'])\n if block['block'] in ['subroutine','function']:\n name = block['name']\n if vars.has_key(name) and vars[name].has_key('intent'):\n block['intent'] = vars[name]['intent']\n if block['block'] == 'type':\n neededvars.extend(vars.keys())\n for n in vars.keys():\n if n not in neededvars:\n del vars[n]\n return vars\nanalyzeargs_re_1 = re.compile(r'\\A[a-z]+[\\w$]*\\Z',re.I)\ndef analyzeargs(block):\n setmesstext(block)\n implicitrules,attrrules=buildimplicitrules(block)\n if not block.has_key('args'): block['args']=[]\n args=[]\n re_1 = analyzeargs_re_1\n for a in block['args']:\n if not re_1.match(a): # `a` is an expression\n at=determineexprtype(a,block['vars'],implicitrules)\n na='e_'\n for c in a:\n if c not in string.lowercase+string.digits: c='_'\n na=na+c\n if na[-1]=='_': na=na+'e'\n else: na=na+'_e'\n a=na\n while block['vars'].has_key(a) or a in block['args']: a=a+'r'\n block['vars'][a]=at\n args.append(a)\n if not block['vars'].has_key(a):\n block['vars'][a]={}\n if block.has_key('externals') and a in block['externals']+block['interfaced']:\n block['vars'][a]=setattrspec(block['vars'][a],'external')\n block['args']=args\n\n if block.has_key('entry'):\n for k,args1 in block['entry'].items():\n for a in args1:\n if not block['vars'].has_key(a):\n block['vars'][a]={}\n\n for b in block['body']:\n if b['name'] in args:\n if not block.has_key('externals'): block['externals']=[]\n if b['name'] not in block['externals']:\n block['externals'].append(b['name'])\n if block.has_key('result') and not block['vars'].has_key(block['result']):\n block['vars'][block['result']]={}\n return block\ndetermineexprtype_re_1 = re.compile(r'\\A\\(.+?[,].+?\\)\\Z',re.I)\ndetermineexprtype_re_2 = re.compile(r'\\A[+-]?\\d+(_(P[\\w]+)|)\\Z',re.I)\ndetermineexprtype_re_3 = re.compile(r'\\A[+-]?[\\d.]+[\\d+-de.]*(_(P[\\w]+)|)\\Z',re.I)\ndetermineexprtype_re_4 = re.compile(r'\\A\\(.*\\)\\Z',re.I)\ndetermineexprtype_re_5 = re.compile(r'\\A(?P\\w+)\\s*\\(.*?\\)\\s*\\Z',re.I)\ndef _ensure_exprdict(r):\n if type(r) is type(0):\n return {'typespec':'integer'}\n if type(r) is type(0.0):\n return {'typespec':'real'}\n if type(r) is type(0j):\n return {'typespec':'complex'}\n assert type(r) is type({}),`r`\n return r\n\ndef determineexprtype(expr,vars,rules={}):\n if vars.has_key(expr):\n return _ensure_exprdict(vars[expr])\n expr=string.strip(expr)\n if determineexprtype_re_1.match(expr):\n return {'typespec':'complex'}\n m=determineexprtype_re_2.match(expr)\n if m:\n if m.groupdict().has_key('name') and m.group('name'):\n outmess('determineexprtype: selected kind types not supported (%s)\\n'%`expr`)\n return {'typespec':'integer'}\n m = determineexprtype_re_3.match(expr)\n if m:\n if m.groupdict().has_key('name') and m.group('name'):\n outmess('determineexprtype: selected kind types not supported (%s)\\n'%`expr`)\n return {'typespec':'real'}\n for op in ['+','-','*','/']:\n for e in map(string.strip,string.split(markoutercomma(expr,comma=op),'@'+op+'@')):\n if vars.has_key(e):\n return _ensure_exprdict(vars[e])\n t={}\n if determineexprtype_re_4.match(expr): # in parenthesis\n t=determineexprtype(expr[1:-1],vars,rules)\n else:\n m = determineexprtype_re_5.match(expr)\n if m:\n rn=m.group('name')\n t=determineexprtype(m.group('name'),vars,rules)\n if t and t.has_key('attrspec'): del t['attrspec']\n if not t:\n if rules.has_key(rn[0]):\n return _ensure_exprdict(rules[rn[0]])\n if expr[0] in '\\'\"':\n return {'typespec':'character','charselector':{'*':'*'}}\n if not t:\n outmess('determineexprtype: could not determine expressions (%s) type.\\n'%(`expr`))\n return t\n######\ndef crack2fortrangen(block,tab='\\n'):\n global skipfuncs, onlyfuncs\n setmesstext(block)\n ret=''\n if type(block) is type([]):\n for g in block:\n if g['block'] in ['function','subroutine']:\n if g['name'] in skipfuncs:\n continue\n if onlyfuncs and g['name'] not in onlyfuncs:\n continue\n ret=ret+crack2fortrangen(g,tab)\n return ret\n prefix=''\n name=''\n args=''\n blocktype=block['block']\n if blocktype=='program': return ''\n al=[]\n if block.has_key('name'): name=block['name']\n if block.has_key('args'):\n vars = block['vars']\n al = [a for a in block['args'] if not isintent_callback(vars[a])]\n if block['block']=='function' or al:\n args='(%s)'%string.join(al,',')\n f2pyenhancements = ''\n if block.has_key('f2pyenhancements'):\n for k in block['f2pyenhancements'].keys():\n f2pyenhancements = '%s%s%s %s'%(f2pyenhancements,tab+tabchar,k,block['f2pyenhancements'][k])\n intent_lst = block.get('intent',[])[:]\n if blocktype=='function' and 'callback' in intent_lst:\n intent_lst.remove('callback')\n if intent_lst:\n f2pyenhancements = '%s%sintent(%s) %s'%\\\n (f2pyenhancements,tab+tabchar,\n string.join(intent_lst,','),name)\n use=''\n if block.has_key('use'):\n use=use2fortran(block['use'],tab+tabchar)\n common=''\n if block.has_key('common'):\n common=common2fortran(block['common'],tab+tabchar)\n if name=='unknown_interface': name=''\n result=''\n if block.has_key('result'):\n result=' result (%s)'%block['result']\n if block['result'] not in al:\n al.append(block['result'])\n #if block.has_key('prefix'): prefix=block['prefix']+' '\n body=crack2fortrangen(block['body'],tab+tabchar)\n vars=vars2fortran(block,block['vars'],al,tab+tabchar)\n mess=''\n if block.has_key('from'):\n mess='! in %s'%block['from']\n if block.has_key('entry'):\n entry_stmts = ''\n for k,i in block['entry'].items():\n entry_stmts = '%s%sentry %s(%s)' \\\n % (entry_stmts,tab+tabchar,k,string.join(i,','))\n body = body + entry_stmts\n if blocktype=='block data' and name=='_BLOCK_DATA_':\n name = ''\n ret='%s%s%s %s%s%s %s%s%s%s%s%s%send %s %s'%(tab,prefix,blocktype,name,args,result,mess,f2pyenhancements,use,vars,common,body,tab,blocktype,name)\n return ret\ndef common2fortran(common,tab=''):\n ret=''\n for k in common.keys():\n if k=='_BLNK_':\n ret='%s%scommon %s'%(ret,tab,string.join(common[k],','))\n else:\n ret='%s%scommon /%s/ %s'%(ret,tab,k,string.join(common[k],','))\n return ret\ndef use2fortran(use,tab=''):\n ret=''\n for m in use.keys():\n ret='%s%suse %s,'%(ret,tab,m)\n if use[m]=={}:\n if ret and ret[-1]==',': ret=ret[:-1]\n continue\n if use[m].has_key('only') and use[m]['only']:\n ret='%s,only:'%(ret)\n if use[m].has_key('map') and use[m]['map']:\n c=' '\n for k in use[m]['map'].keys():\n if k==use[m]['map'][k]:\n ret='%s%s%s'%(ret,c,k); c=','\n else:\n ret='%s%s%s=>%s'%(ret,c,k,use[m]['map'][k]); c=','\n if ret and ret[-1]==',': ret=ret[:-1]\n return ret\ndef true_intent_list(var):\n lst = var['intent']\n ret = []\n for intent in lst:\n try:\n exec('c = isintent_%s(var)' % intent)\n except NameError:\n c = 0\n if c:\n ret.append(intent)\n return ret\ndef vars2fortran(block,vars,args,tab=''):\n \"\"\"\n TODO:\n public sub\n ...\n \"\"\"\n setmesstext(block)\n ret=''\n nout=[]\n for a in args:\n if block['vars'].has_key(a): nout.append(a)\n if block.has_key('commonvars'):\n for a in block['commonvars']:\n if vars.has_key(a):\n if a not in nout: nout.append(a)\n else: errmess('vars2fortran: Confused?!: \"%s\" is not defined in vars.\\n'%a)\n if block.has_key('varnames'):\n nout.extend(block['varnames'])\n for a in vars.keys():\n if a not in nout: nout.append(a)\n for a in nout:\n if vars[a].has_key('depend'):\n for d in vars[a]['depend']:\n if vars.has_key(d) and vars[d].has_key('depend') and a in vars[d]['depend']:\n errmess('vars2fortran: Warning: cross-dependence between variables \"%s\" and \"%s\"\\n'%(a,d))\n if block.has_key('externals') and a in block['externals']:\n if isintent_callback(vars[a]):\n ret='%s%sintent(callback) %s'%(ret,tab,a)\n ret='%s%sexternal %s'%(ret,tab,a)\n if isoptional(vars[a]):\n ret='%s%soptional %s'%(ret,tab,a)\n if vars.has_key(a) and not vars[a].has_key('typespec'):\n continue\n cont=1\n for b in block['body']:\n if a==b['name'] and b['block']=='function': cont=0;break\n if cont: continue\n if not vars.has_key(a):\n show(vars)\n outmess('vars2fortran: No definition for argument \"%s\".\\n'%a)\n continue\n if a==block['name'] and not block['block']=='function':\n continue\n if not vars[a].has_key('typespec'):\n if vars[a].has_key('attrspec') and 'external' in vars[a]['attrspec']:\n if a in args:\n ret='%s%sexternal %s'%(ret,tab,a)\n continue\n show(vars[a])\n outmess('vars2fortran: No typespec for argument \"%s\".\\n'%a)\n continue\n vardef=vars[a]['typespec']\n if vardef=='type' and vars[a].has_key('typename'):\n vardef='%s(%s)'%(vardef,vars[a]['typename'])\n selector={}\n if vars[a].has_key('kindselector'): selector=vars[a]['kindselector']\n elif vars[a].has_key('charselector'): selector=vars[a]['charselector']\n if selector.has_key('*'):\n if selector['*'] in ['*',':']:\n vardef='%s*(%s)'%(vardef,selector['*'])\n else:\n vardef='%s*%s'%(vardef,selector['*'])\n else:\n if selector.has_key('len'):\n vardef='%s(len=%s'%(vardef,selector['len'])\n if selector.has_key('kind'):\n vardef='%s,kind=%s)'%(vardef,selector['kind'])\n else:\n vardef='%s)'%(vardef)\n elif selector.has_key('kind'):\n vardef='%s(kind=%s)'%(vardef,selector['kind'])\n c=' '\n if vars[a].has_key('attrspec'):\n attr=[]\n for l in vars[a]['attrspec']:\n if l not in ['external']:\n attr.append(l)\n if attr:\n vardef='%s %s'%(vardef,string.join(attr,','))\n c=','\n if vars[a].has_key('dimension'):\n# if not isintent_c(vars[a]):\n# vars[a]['dimension'].reverse()\n vardef='%s%sdimension(%s)'%(vardef,c,string.join(vars[a]['dimension'],','))\n c=','\n if vars[a].has_key('intent'):\n lst = true_intent_list(vars[a])\n if lst:\n vardef='%s%sintent(%s)'%(vardef,c,string.join(lst,','))\n c=','\n if vars[a].has_key('check'):\n vardef='%s%scheck(%s)'%(vardef,c,string.join(vars[a]['check'],','))\n c=','\n if vars[a].has_key('depend'):\n vardef='%s%sdepend(%s)'%(vardef,c,string.join(vars[a]['depend'],','))\n c=','\n if vars[a].has_key('='):\n v = vars[a]['=']\n if vars[a]['typespec'] in ['complex','double complex']:\n try:\n v = eval(v)\n v = '(%s,%s)' % (v.real,v.imag)\n except:\n pass\n vardef='%s :: %s=%s'%(vardef,a,v)\n else:\n vardef='%s :: %s'%(vardef,a)\n ret='%s%s%s'%(ret,tab,vardef)\n return ret\n######\n\ndef crackfortran(files):\n global usermodules\n outmess('Reading fortran codes...\\n',0)\n readfortrancode(files,crackline)\n outmess('Post-processing...\\n',0)\n usermodules=[]\n postlist=postcrack(grouplist[0])\n outmess('Post-processing (stage 2)...\\n',0)\n postlist=postcrack2(postlist)\n return usermodules+postlist\ndef crack2fortran(block):\n global f2py_version\n pyf=crack2fortrangen(block)+'\\n'\n header=\"\"\"! -*- f90 -*-\n! Note: the context of this file is case sensitive.\n\"\"\"\n footer=\"\"\"\n! This file was auto-generated with f2py (version:%s).\n! See http://cens.ioc.ee/projects/f2py2e/\n\"\"\"%(f2py_version)\n return header+pyf+footer\n\nif __name__ == \"__main__\":\n files=[]\n funcs=[]\n f=1;f2=0;f3=0\n showblocklist=0\n for l in sys.argv[1:]:\n if l=='': pass\n elif l[0]==':':\n f=0\n elif l=='-quiet':\n quiet=1\n verbose=0\n elif l=='-verbose':\n verbose=2\n quiet=0\n elif l=='-fix':\n if strictf77:\n outmess('Use option -f90 before -fix if Fortran 90 code is in fix form.\\n',0)\n skipemptyends=1\n sourcecodeform='fix'\n elif l=='-skipemptyends':\n skipemptyends=1\n elif l=='--ignore-contains':\n ignorecontains=1\n elif l=='-f77':\n strictf77=1\n sourcecodeform='fix'\n elif l=='-f90':\n strictf77=0\n sourcecodeform='free'\n skipemptyends=1\n elif l=='-h':\n f2=1\n elif l=='-show':\n showblocklist=1\n elif l=='-m':\n f3=1\n elif l[0]=='-':\n errmess('Unknown option %s\\n'%`l`)\n elif f2:\n f2=0\n pyffilename=l\n elif f3:\n f3=0\n f77modulename=l\n elif f:\n try:\n open(l).close()\n files.append(l)\n except IOError,detail:\n errmess('IOError: %s\\n'%str(detail))\n else:\n funcs.append(l)\n if not strictf77 and f77modulename and not skipemptyends:\n outmess(\"\"\"\\\n Warning: You have specifyied module name for non Fortran 77 code\n that should not need one (expect if you are scanning F90 code\n for non module blocks but then you should use flag -skipemptyends\n and also be sure that the files do not contain programs without program statement).\n\"\"\",0)\n\n postlist=crackfortran(files,funcs)\n if pyffilename:\n outmess('Writing fortran code to file %s\\n'%`pyffilename`,0)\n pyf=crack2fortran(postlist)\n f=open(pyffilename,'w')\n f.write(pyf)\n f.close()\n if showblocklist:\n show(postlist)\n", + "source_code_before": "#!/usr/bin/env python\n\"\"\"\ncrackfortran --- read fortran (77,90) code and extract declaration information.\n Usage is explained in the comment block below.\n\nCopyright 1999-2004 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the\nterms of the NumPy License.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n$Date: 2005/09/27 07:13:49 $\nPearu Peterson\n\"\"\"\n__version__ = \"$Revision: 1.177 $\"[10:-1]\n\nimport __version__\nf2py_version = __version__.version\n\n\"\"\"\n Usage of crackfortran:\n ======================\n Command line keys: -quiet,-verbose,-fix,-f77,-f90,-show,-h \n -m ,--ignore-contains\n Functions: crackfortran, crack2fortran\n The following Fortran statements/constructions are supported\n (or will be if needed):\n block data,byte,call,character,common,complex,contains,data,\n dimension,double complex,double precision,end,external,function,\n implicit,integer,intent,interface,intrinsic,\n logical,module,optional,parameter,private,public,\n program,real,(sequence?),subroutine,type,use,virtual,\n include,pythonmodule\n Note: 'virtual' is mapped to 'dimension'.\n Note: 'implicit integer (z) static (z)' is 'implicit static (z)' (this is minor bug).\n Note: code after 'contains' will be ignored until its scope ends.\n Note: 'common' statement is extended: dimensions are moved to variable definitions\n Note: f2py directive: f2py is read as \n Note: pythonmodule is introduced to represent Python module\n\n Usage:\n `postlist=crackfortran(files,funcs)`\n `postlist` contains declaration information read from the list of files `files`.\n `crack2fortran(postlist)` returns a fortran code to be saved to pyf-file\n\n `postlist` has the following structure:\n *** it is a list of dictionaries containing `blocks':\n B = {'block','body','vars','parent_block'[,'name','prefix','args','result',\n 'implicit','externals','interfaced','common','sortvars',\n 'commonvars','note']}\n B['block'] = 'interface' | 'function' | 'subroutine' | 'module' |\n 'program' | 'block data' | 'type' | 'pythonmodule'\n B['body'] --- list containing `subblocks' with the same structure as `blocks'\n B['parent_block'] --- dictionary of a parent block:\n C['body'][]['parent_block'] is C\n B['vars'] --- dictionary of variable definitions\n B['sortvars'] --- dictionary of variable definitions sorted by dependence (independent first)\n B['name'] --- name of the block (not if B['block']=='interface')\n B['prefix'] --- prefix string (only if B['block']=='function')\n B['args'] --- list of argument names if B['block']== 'function' | 'subroutine'\n B['result'] --- name of the return value (only if B['block']=='function')\n B['implicit'] --- dictionary {'a':,'b':...} | None\n B['externals'] --- list of variables being external\n B['interfaced'] --- list of variables being external and defined\n B['common'] --- dictionary of common blocks (list of objects)\n B['commonvars'] --- list of variables used in common blocks (dimensions are moved to variable definitions)\n B['from'] --- string showing the 'parents' of the current block\n B['use'] --- dictionary of modules used in current block:\n {:{['only':<0|1>],['map':{:,...}]}}\n B['note'] --- list of LaTeX comments on the block\n B['f2pyenhancements'] --- optional dictionary\n {'threadsafe':'','fortranname':,\n 'callstatement':|,\n 'callprotoargument':,\n 'usercode':|,\n 'pymethoddef:'\n }\n B['entry'] --- dictionary {entryname:argslist,..}\n B['varnames'] --- list of variable names given in the order of reading the\n Fortran code, useful for derived types.\n *** Variable definition is a dictionary\n D = B['vars'][] =\n {'typespec'[,'attrspec','kindselector','charselector','=','typename']}\n D['typespec'] = 'byte' | 'character' | 'complex' | 'double complex' |\n 'double precision' | 'integer' | 'logical' | 'real' | 'type'\n D['attrspec'] --- list of attributes (e.g. 'dimension()',\n 'external','intent(in|out|inout|hide|c|callback|cache)',\n 'optional','required', etc)\n K = D['kindselector'] = {['*','kind']} (only if D['typespec'] =\n 'complex' | 'integer' | 'logical' | 'real' )\n C = D['charselector'] = {['*','len','kind']}\n (only if D['typespec']=='character')\n D['='] --- initialization expression string\n D['typename'] --- name of the type if D['typespec']=='type'\n D['dimension'] --- list of dimension bounds\n D['intent'] --- list of intent specifications\n D['depend'] --- list of variable names on which current variable depends on\n D['check'] --- list of C-expressions; if C-expr returns zero, exception is raised\n D['note'] --- list of LaTeX comments on the variable\n *** Meaning of kind/char selectors (few examples):\n D['typespec>']*K['*']\n D['typespec'](kind=K['kind'])\n character*C['*']\n character(len=C['len'],kind=C['kind'])\n (see also fortran type declaration statement formats below)\n\n Fortran 90 type declaration statement format (F77 is subset of F90)\n====================================================================\n (Main source: IBM XL Fortran 5.1 Language Reference Manual)\n type declaration = [[]::] \n = byte |\n character[] |\n complex[] |\n double complex |\n double precision |\n integer[] |\n logical[] |\n real[] |\n type()\n = * |\n ([len=][,[kind=]]) |\n (kind=[,len=])\n = * |\n ([kind=])\n = comma separated list of attributes.\n Only the following attributes are used in\n building up the interface:\n external\n (parameter --- affects '=' key)\n optional\n intent\n Other attributes are ignored.\n = in | out | inout\n = comma separated list of dimension bounds.\n = [[*][()] | [()]*]\n [// | =] [,]\n\n In addition, the following attributes are used: check,depend,note\n\n TODO:\n * Apply 'parameter' attribute (e.g. 'integer parameter :: i=2' 'real x(i)'\n -> 'real x(2)')\n The above may be solved by creating appropriate preprocessor program, for example.\n\"\"\"\n#\nimport sys,string,fileinput,re,pprint,os,copy\nfrom auxfuncs import *\n\n# Global flags:\nstrictf77=1 # Ignore `!' comments unless line[0]=='!'\nsourcecodeform='fix' # 'fix','free'\nquiet=0 # Be verbose if 0 (Obsolete: not used any more)\nverbose=1 # Be quiet if 0, extra verbose if > 1.\ntabchar=4*' '\npyffilename=''\nf77modulename=''\nskipemptyends=0 # for old F77 programs without 'program' statement\nignorecontains=1\ndolowercase=1\ndebug=[]\n## do_analyze = 1\n\n###### global variables\n\n## use reload(crackfortran) to reset these variables\n\ngroupcounter=0\ngrouplist={groupcounter:[]}\nneededmodule=-1\nexpectbegin=1\nskipblocksuntil=-1\nusermodules=[]\nf90modulevars={}\ngotnextfile=1\nfilepositiontext=''\ncurrentfilename=''\nskipfunctions=[]\nskipfuncs=[]\nonlyfuncs=[]\ninclude_paths=[]\nprevious_context = None\n\n###### Some helper functions\ndef show(o,f=0):pprint.pprint(o)\nerrmess=sys.stderr.write\ndef outmess(line,flag=1):\n global filepositiontext\n if not verbose: return\n if not quiet:\n if flag:sys.stdout.write(filepositiontext)\n sys.stdout.write(line)\nre._MAXCACHE=50\ndefaultimplicitrules={}\nfor c in \"abcdefghopqrstuvwxyz$_\": defaultimplicitrules[c]={'typespec':'real'}\nfor c in \"ijklmn\": defaultimplicitrules[c]={'typespec':'integer'}\ndel c\nbadnames={}\ninvbadnames={}\nfor n in ['int','double','float','char','short','long','void','case','while',\n 'return','signed','unsigned','if','for','typedef','sizeof','union',\n 'struct','static','register','new','break','do','goto','switch',\n 'continue','else','inline','extern','delete','const','auto',\n 'len','rank','shape','index','slen','size','_i',\n 'flen','fshape',\n 'string','complex_double','float_double','stdin','stderr','stdout',\n 'type','default']:\n badnames[n]=n+'_bn'\n invbadnames[n+'_bn']=n\ndef rmbadname1(name):\n if badnames.has_key(name):\n errmess('rmbadname1: Replacing \"%s\" with \"%s\".\\n'%(name,badnames[name]))\n return badnames[name]\n return name\ndef rmbadname(names): return map(rmbadname1,names)\n\ndef undo_rmbadname1(name):\n if invbadnames.has_key(name):\n errmess('undo_rmbadname1: Replacing \"%s\" with \"%s\".\\n'\\\n %(name,invbadnames[name]))\n return invbadnames[name]\n return name\ndef undo_rmbadname(names): return map(undo_rmbadname1,names)\n\ndef getextension(name):\n i=string.rfind(name,'.')\n if i==-1: return ''\n if '\\\\' in name[i:]: return ''\n if '/' in name[i:]: return ''\n return name[i+1:]\n\nis_f_file = re.compile(r'.*[.](for|ftn|f77|f)\\Z',re.I).match\n_has_f_header = re.compile(r'-[*]-\\s*fortran\\s*-[*]-',re.I).search\n_has_f90_header = re.compile(r'-[*]-\\s*f90\\s*-[*]-',re.I).search\n_has_fix_header = re.compile(r'-[*]-\\s*fix\\s*-[*]-',re.I).search\n_free_f90_start = re.compile(r'[^c*]\\s*[^\\s\\d\\t]',re.I).match\ndef is_free_format(file):\n \"\"\"Check if file is in free format Fortran.\"\"\"\n # f90 allows both fixed and free format, assuming fixed unless\n # signs of free format are detected.\n result = 0\n f = open(file,'r')\n line = f.readline()\n n = 15 # the number of non-comment lines to scan for hints\n if _has_f_header(line):\n n = 0\n elif _has_f90_header(line):\n n = 0\n result = 1\n while n>0 and line:\n if line[0]!='!':\n n -= 1\n if (line[0]!='\\t' and _free_f90_start(line[:5])) or line[-2:-1]=='&':\n result = 1\n break\n line = f.readline()\n f.close()\n return result\n\n\n####### Read fortran (77,90) code\ndef readfortrancode(ffile,dowithline=show,istop=1):\n \"\"\"\n Read fortran codes from files and\n 1) Get rid of comments, line continuations, and empty lines; lower cases.\n 2) Call dowithline(line) on every line.\n 3) Recursively call itself when statement \\\"include ''\\\" is met.\n \"\"\"\n global gotnextfile,filepositiontext,currentfilename,sourcecodeform,strictf77,\\\n beginpattern,quiet,verbose,dolowercase,include_paths\n if not istop:\n saveglobals=gotnextfile,filepositiontext,currentfilename,sourcecodeform,strictf77,\\\n beginpattern,quiet,verbose,dolowercase\n if ffile==[]: return\n localdolowercase = dolowercase\n cont=0\n finalline=''\n ll=''\n commentline=re.compile(r'(?P([^\"]*\"[^\"]*\"[^\"!]*|[^\\']*\\'[^\\']*\\'[^\\'!]*|[^!]*))!{1}(?P.*)')\n includeline=re.compile(r'\\s*include\\s*(\\'|\")(?P[^\\'\"]*)(\\'|\")',re.I)\n cont1=re.compile(r'(?P.*)&\\s*\\Z')\n cont2=re.compile(r'(\\s*&|)(?P.*)')\n mline_mark = re.compile(r\".*?'''\")\n if istop: dowithline('',-1)\n ll,l1='',''\n spacedigits=[' ']+map(str,range(10))\n filepositiontext=''\n fin=fileinput.FileInput(ffile)\n while 1:\n l=fin.readline()\n if not l: break\n if fin.isfirstline():\n filepositiontext=''\n currentfilename=fin.filename()\n gotnextfile=1\n l1=l\n strictf77=0\n sourcecodeform='fix'\n ext = os.path.splitext(currentfilename)[1]\n if is_f_file(currentfilename) and \\\n not (_has_f90_header(l) or _has_fix_header(l)):\n strictf77=1\n elif is_free_format(currentfilename) and not _has_fix_header(l):\n sourcecodeform='free'\n if strictf77: beginpattern=beginpattern77\n else: beginpattern=beginpattern90\n outmess('\\tReading file %s (format:%s%s)\\n'\\\n %(`currentfilename`,sourcecodeform,\n strictf77 and ',strict' or ''))\n\n l=string.expandtabs(l).replace('\\xa0',' ')\n while not l=='': # Get rid of newline characters\n if l[-1] not in \"\\n\\r\\f\": break\n l=l[:-1]\n if not strictf77:\n r=commentline.match(l)\n if r:\n l=r.group('line')+' ' # Strip comments starting with `!'\n rl=r.group('rest')\n if string.lower(rl[:4])=='f2py': # f2py directive\n l = l + 4*' '\n r=commentline.match(rl[4:])\n if r: l=l+r('line')\n else: l = l + rl[4:]\n if string.strip(l)=='': # Skip empty line\n cont=0\n continue\n if sourcecodeform=='fix':\n if l[0] in ['*','c','!','C','#']:\n if string.lower(l[1:5])=='f2py': # f2py directive\n l=' '+l[5:]\n else: # Skip comment line\n cont=0\n continue\n elif strictf77:\n if len(l)>72: l=l[:72]\n if not (l[0] in spacedigits):\n raise 'readfortrancode: Found non-(space,digit) char in the first column.\\n\\tAre you sure that this code is in fix form?\\n\\tline=%s'%`l`\n\n if (not cont or strictf77) and (len(l)>5 and not l[5]==' '):\n # Continuation of a previous line\n ll=ll+l[6:]\n finalline=''\n origfinalline=''\n else:\n if not strictf77:\n # F90 continuation\n r=cont1.match(l)\n if r: l=r.group('line') # Continuation follows ..\n if cont:\n ll=ll+cont2.match(l).group('line')\n finalline=''\n origfinalline=''\n else:\n l=' '+l[5:] # clean up line beginning from possible digits.\n if localdolowercase: finalline=string.lower(ll)\n else: finalline=ll\n origfinalline=ll\n ll=l\n cont=(r is not None)\n else:\n l=' '+l[5:] # clean up line beginning from possible digits.\n if localdolowercase: finalline=string.lower(ll)\n else: finalline=ll\n origfinalline =ll\n ll=l\n\n elif sourcecodeform=='free':\n if not cont and ext=='.pyf' and mline_mark.match(l):\n l = l + '\\n'\n while 1:\n lc = fin.readline()\n if not lc:\n errmess('Unexpected end of file when reading multiline\\n')\n break\n l = l + lc\n if mline_mark.match(lc):\n break\n l = l.rstrip()\n r=cont1.match(l)\n if r: l=r.group('line') # Continuation follows ..\n if cont:\n ll=ll+cont2.match(l).group('line')\n finalline=''\n origfinalline=''\n else:\n if localdolowercase: finalline=string.lower(ll)\n else: finalline=ll\n origfinalline =ll\n ll=l\n cont=(r is not None)\n else:\n raise ValueError,\"Flag sourcecodeform must be either 'fix' or 'free': %s\"%`sourcecodeform`\n filepositiontext='Line #%d in %s:\"%s\"\\n\\t' % (fin.filelineno()-1,currentfilename,l1)\n m=includeline.match(origfinalline)\n if m:\n fn=m.group('name')\n if os.path.isfile(fn):\n readfortrancode(fn,dowithline=dowithline,istop=0)\n else:\n include_dirs = [os.path.dirname(currentfilename)] + include_paths\n foundfile = 0\n for inc_dir in include_dirs:\n fn1 = os.path.join(inc_dir,fn)\n if os.path.isfile(fn1):\n foundfile = 1\n readfortrancode(fn1,dowithline=dowithline,istop=0)\n break\n if not foundfile:\n outmess('readfortrancode: could not find include file %s. Ignoring.\\n'%(`fn`))\n else:\n dowithline(finalline)\n l1=ll\n if localdolowercase:\n finalline=string.lower(ll)\n else: finalline=ll\n origfinalline = ll\n filepositiontext='Line #%d in %s:\"%s\"\\n\\t' % (fin.filelineno()-1,currentfilename,l1)\n m=includeline.match(origfinalline)\n if m:\n fn=m.group('name')\n fn1=os.path.join(os.path.dirname(currentfilename),fn)\n if os.path.isfile(fn):\n readfortrancode(fn,dowithline=dowithline,istop=0)\n elif os.path.isfile(fn1):\n readfortrancode(fn1,dowithline=dowithline,istop=0)\n else:\n outmess('readfortrancode: could not find include file %s. Ignoring.\\n'%(`fn`))\n else:\n dowithline(finalline)\n filepositiontext=''\n fin.close()\n if istop: dowithline('',1)\n else:\n gotnextfile,filepositiontext,currentfilename,sourcecodeform,strictf77,\\\n beginpattern,quiet,verbose,dolowercase=saveglobals\n\n########### Crack line\nbeforethisafter=r'\\s*(?P%s(?=\\s*(\\b(%s)\\b)))'+ \\\n r'\\s*(?P(\\b(%s)\\b))'+ \\\n r'\\s*(?P%s)\\s*\\Z'\n##\nfortrantypes='character|logical|integer|real|complex|double\\s*(precision\\s*(complex|)|complex)|type(?=\\s*\\([\\w\\s,=(*)]*\\))|byte'\ntypespattern=re.compile(beforethisafter%('',fortrantypes,fortrantypes,'.*'),re.I),'type'\ntypespattern4implicit=re.compile(beforethisafter%('',fortrantypes+'|static|automatic|undefined',fortrantypes+'|static|automatic|undefined','.*'),re.I)\n#\nfunctionpattern=re.compile(beforethisafter%('([a-z]+[\\w\\s(=*+-/)]*?|)','function','function','.*'),re.I),'begin'\nsubroutinepattern=re.compile(beforethisafter%('[a-z\\s]*?','subroutine','subroutine','.*'),re.I),'begin'\n#modulepattern=re.compile(beforethisafter%('[a-z\\s]*?','module','module','.*'),re.I),'begin'\n#\ngroupbegins77=r'program|block\\s*data'\nbeginpattern77=re.compile(beforethisafter%('',groupbegins77,groupbegins77,'.*'),re.I),'begin'\ngroupbegins90=groupbegins77+r'|module|python\\s*module|interface|type(?!\\s*\\()'\nbeginpattern90=re.compile(beforethisafter%('',groupbegins90,groupbegins90,'.*'),re.I),'begin'\ngroupends=r'end|endprogram|endblockdata|endmodule|endpythonmodule|endinterface'\nendpattern=re.compile(beforethisafter%('',groupends,groupends,'[\\w\\s]*'),re.I),'end'\n#endifs='end\\s*(if|do|where|select|while|forall)'\nendifs='(end\\s*(if|do|where|select|while|forall))|(module\\s*procedure)'\nendifpattern=re.compile(beforethisafter%('[\\w]*?',endifs,endifs,'[\\w\\s]*'),re.I),'endif'\n#\nimplicitpattern=re.compile(beforethisafter%('','implicit','implicit','.*'),re.I),'implicit'\ndimensionpattern=re.compile(beforethisafter%('','dimension|virtual','dimension|virtual','.*'),re.I),'dimension'\nexternalpattern=re.compile(beforethisafter%('','external','external','.*'),re.I),'external'\noptionalpattern=re.compile(beforethisafter%('','optional','optional','.*'),re.I),'optional'\nrequiredpattern=re.compile(beforethisafter%('','required','required','.*'),re.I),'required'\npublicpattern=re.compile(beforethisafter%('','public','public','.*'),re.I),'public'\nprivatepattern=re.compile(beforethisafter%('','private','private','.*'),re.I),'private'\nintrisicpattern=re.compile(beforethisafter%('','intrisic','intrisic','.*'),re.I),'intrisic'\nintentpattern=re.compile(beforethisafter%('','intent|depend|note|check','intent|depend|note|check','\\s*\\(.*?\\).*'),re.I),'intent'\nparameterpattern=re.compile(beforethisafter%('','parameter','parameter','\\s*\\(.*'),re.I),'parameter'\ndatapattern=re.compile(beforethisafter%('','data','data','.*'),re.I),'data'\ncallpattern=re.compile(beforethisafter%('','call','call','.*'),re.I),'call'\nentrypattern=re.compile(beforethisafter%('','entry','entry','.*'),re.I),'entry'\ncallfunpattern=re.compile(beforethisafter%('','callfun','callfun','.*'),re.I),'callfun'\ncommonpattern=re.compile(beforethisafter%('','common','common','.*'),re.I),'common'\nusepattern=re.compile(beforethisafter%('','use','use','.*'),re.I),'use'\ncontainspattern=re.compile(beforethisafter%('','contains','contains',''),re.I),'contains'\nformatpattern=re.compile(beforethisafter%('','format','format','.*'),re.I),'format'\n## Non-fortran and f2py-specific statements\nf2pyenhancementspattern=re.compile(beforethisafter%('','threadsafe|fortranname|callstatement|callprotoargument|usercode|pymethoddef','threadsafe|fortranname|callstatement|callprotoargument|usercode|pymethoddef','.*'),re.I|re.S),'f2pyenhancements'\nmultilinepattern = re.compile(r\"\\s*(?P''')(?P.*?)(?P''')\\s*\\Z\",re.S),'multiline'\n##\n\ndef _simplifyargs(argsline):\n a = []\n for n in string.split(markoutercomma(argsline),'@,@'):\n for r in '(),':\n n = string.replace(n,r,'_')\n a.append(n)\n return string.join(a,',')\n\ncrackline_re_1 = re.compile(r'\\s*(?P\\b[a-z]+[\\w]*\\b)\\s*[=].*',re.I)\ndef crackline(line,reset=0):\n \"\"\"\n reset=-1 --- initialize\n reset=0 --- crack the line\n reset=1 --- final check if mismatch of blocks occured\n\n Cracked data is saved in grouplist[0].\n \"\"\"\n global beginpattern,groupcounter,groupname,groupcache,grouplist,gotnextfile,\\\n filepositiontext,currentfilename,neededmodule,expectbegin,skipblocksuntil,\\\n skipemptyends,previous_context\n if ';' in line and not (f2pyenhancementspattern[0].match(line) or\n multilinepattern[0].match(line)):\n for l in line.split(';'):\n assert reset==0,`reset` # XXX: non-zero reset values need testing\n crackline(l,reset)\n return\n if reset<0:\n groupcounter=0\n groupname={groupcounter:''}\n groupcache={groupcounter:{}}\n grouplist={groupcounter:[]}\n groupcache[groupcounter]['body']=[]\n groupcache[groupcounter]['vars']={}\n groupcache[groupcounter]['block']=''\n groupcache[groupcounter]['name']=''\n neededmodule=-1\n skipblocksuntil=-1\n return\n if reset>0:\n fl=0\n if f77modulename and neededmodule==groupcounter: fl=2\n while groupcounter>fl:\n outmess('crackline: groupcounter=%s groupname=%s\\n'%(`groupcounter`,`groupname`))\n outmess('crackline: Mismatch of blocks encountered. Trying to fix it by assuming \"end\" statement.\\n')\n grouplist[groupcounter-1].append(groupcache[groupcounter])\n grouplist[groupcounter-1][-1]['body']=grouplist[groupcounter]\n del grouplist[groupcounter]\n groupcounter=groupcounter-1\n if f77modulename and neededmodule==groupcounter:\n grouplist[groupcounter-1].append(groupcache[groupcounter])\n grouplist[groupcounter-1][-1]['body']=grouplist[groupcounter]\n del grouplist[groupcounter]\n groupcounter=groupcounter-1 # end interface\n grouplist[groupcounter-1].append(groupcache[groupcounter])\n grouplist[groupcounter-1][-1]['body']=grouplist[groupcounter]\n del grouplist[groupcounter]\n groupcounter=groupcounter-1 # end module\n neededmodule=-1\n return\n if line=='': return\n flag=0\n for pat in [dimensionpattern,externalpattern,intentpattern,optionalpattern,\n requiredpattern,\n parameterpattern,datapattern,publicpattern,privatepattern,\n intrisicpattern,\n endifpattern,endpattern,\n formatpattern,\n beginpattern,functionpattern,subroutinepattern,\n implicitpattern,typespattern,commonpattern,\n callpattern,usepattern,containspattern,\n entrypattern,\n f2pyenhancementspattern,\n multilinepattern\n ]:\n m = pat[0].match(line)\n if m:\n break\n flag=flag+1\n if not m:\n re_1 = crackline_re_1\n if 0<=skipblocksuntil<=groupcounter:return\n if groupcache[groupcounter].has_key('externals'):\n for name in groupcache[groupcounter]['externals']:\n if invbadnames.has_key(name):\n name=invbadnames[name]\n if groupcache[groupcounter].has_key('interfaced') and name in groupcache[groupcounter]['interfaced']: continue\n m1=re.match(r'(?P[^\"]*)\\b%s\\b\\s*@\\(@(?P[^@]*)@\\)@.*\\Z'%name,markouterparen(line),re.I)\n if m1:\n m2 = re_1.match(m1.group('before'))\n a = _simplifyargs(m1.group('args'))\n if m2:\n line='callfun %s(%s) result (%s)'%(name,a,m2.group('result'))\n else: line='callfun %s(%s)'%(name,a)\n m = callfunpattern[0].match(line)\n if not m:\n outmess('crackline: could not resolve function call for line=%s.\\n'%`line`)\n return\n analyzeline(m,'callfun',line)\n return\n if verbose>1:\n previous_context = None\n outmess('crackline:%d: No pattern for line\\n'%(groupcounter))\n return\n elif pat[1]=='end':\n if 0<=skipblocksuntil(@\\(@.*?@\\)@|[*][\\d*]+|[*]\\s*@\\(@.*?@\\)@|))(?P.*)\\Z',re.I)\nnameargspattern=re.compile(r'\\s*(?P\\b[\\w$]+\\b)\\s*(@\\(@\\s*(?P[\\w\\s,]*)\\s*@\\)@|)\\s*(result(\\s*@\\(@\\s*(?P\\b[\\w$]+\\b)\\s*@\\)@|))*\\s*\\Z',re.I)\ncallnameargspattern=re.compile(r'\\s*(?P\\b[\\w$]+\\b)\\s*@\\(@\\s*(?P.*)\\s*@\\)@\\s*\\Z',re.I)\nreal16pattern = re.compile(r'([-+]?(?:\\d+(?:\\.\\d*)?|\\d*\\.\\d+))[dD]((?:[-+]?\\d+)?)')\nreal8pattern = re.compile(r'([-+]?((?:\\d+(?:\\.\\d*)?|\\d*\\.\\d+))[eE]((?:[-+]?\\d+)?)|(\\d+\\.\\d*))')\n\n_intentcallbackpattern = re.compile(r'intent\\s*\\(.*?\\bcallback\\b',re.I)\ndef _is_intent_callback(vdecl):\n for a in vdecl.get('attrspec',[]):\n if _intentcallbackpattern.match(a):\n return 1\n return 0\n\ndef _resolvenameargspattern(line):\n line = markouterparen(line)\n m1=nameargspattern.match(line)\n if m1: return m1.group('name'),m1.group('args'),m1.group('result')\n m1=callnameargspattern.match(line)\n if m1: return m1.group('name'),m1.group('args'),None\n return None,[],None\n\ndef analyzeline(m,case,line):\n global groupcounter,groupname,groupcache,grouplist,filepositiontext,\\\n currentfilename,f77modulename,neededinterface,neededmodule,expectbegin,\\\n gotnextfile,previous_context\n block=m.group('this')\n if case != 'multiline':\n previous_context = None\n if expectbegin and case not in ['begin','call','callfun','type'] \\\n and not skipemptyends and groupcounter<1:\n newname=string.split(os.path.basename(currentfilename),'.')[0]\n outmess('analyzeline: no group yet. Creating program group with name \"%s\".\\n'%newname)\n gotnextfile=0\n groupcounter=groupcounter+1\n groupname[groupcounter]='program'\n groupcache[groupcounter]={}\n grouplist[groupcounter]=[]\n groupcache[groupcounter]['body']=[]\n groupcache[groupcounter]['vars']={}\n groupcache[groupcounter]['block']='program'\n groupcache[groupcounter]['name']=newname\n groupcache[groupcounter]['from']='fromsky'\n expectbegin=0\n if case in ['begin','call','callfun']:\n # Crack line => block,name,args,result\n block = block.lower()\n if re.match(r'block\\s*data',block,re.I): block='block data'\n if re.match(r'python\\s*module',block,re.I): block='python module'\n name,args,result = _resolvenameargspattern(m.group('after'))\n if name is None:\n if block=='block data':\n name = '_BLOCK_DATA_'\n else:\n name = ''\n if block not in ['interface','block data']:\n outmess('analyzeline: No name/args pattern found for line.\\n')\n\n previous_context = (block,name,groupcounter)\n if args: args=rmbadname(map(string.strip,string.split(markoutercomma(args),'@,@')))\n else: args=[]\n if '' in args:\n while '' in args:\n args.remove('')\n outmess('analyzeline: argument list is malformed (missing argument).\\n')\n\n # end of crack line => block,name,args,result\n needmodule=0\n needinterface=0\n\n if case in ['call','callfun']:\n needinterface=1\n if not groupcache[groupcounter].has_key('args'): return\n if name not in groupcache[groupcounter]['args']:\n return\n for it in grouplist[groupcounter]:\n if it['name']==name: return\n if name in groupcache[groupcounter]['interfaced']: return\n block={'call':'subroutine','callfun':'function'}[case]\n if f77modulename and neededmodule==-1 and groupcounter<=1:\n neededmodule=groupcounter+2\n needmodule=1\n needinterface=1\n # Create new block(s)\n groupcounter=groupcounter+1\n groupcache[groupcounter]={}\n grouplist[groupcounter]=[]\n if needmodule:\n if verbose>1:\n outmess('analyzeline: Creating module block %s\\n'%`f77modulename`,0)\n groupname[groupcounter]='module'\n groupcache[groupcounter]['block']='python module'\n groupcache[groupcounter]['name']=f77modulename\n groupcache[groupcounter]['from']=''\n groupcache[groupcounter]['body']=[]\n groupcache[groupcounter]['externals']=[]\n groupcache[groupcounter]['interfaced']=[]\n groupcache[groupcounter]['vars']={}\n groupcounter=groupcounter+1\n groupcache[groupcounter]={}\n grouplist[groupcounter]=[]\n if needinterface:\n if verbose>1:\n outmess('analyzeline: Creating additional interface block.\\n',0)\n groupname[groupcounter]='interface'\n groupcache[groupcounter]['block']='interface'\n groupcache[groupcounter]['name']='unknown_interface'\n groupcache[groupcounter]['from']='%s:%s'%(groupcache[groupcounter-1]['from'],groupcache[groupcounter-1]['name'])\n groupcache[groupcounter]['body']=[]\n groupcache[groupcounter]['externals']=[]\n groupcache[groupcounter]['interfaced']=[]\n groupcache[groupcounter]['vars']={}\n groupcounter=groupcounter+1\n groupcache[groupcounter]={}\n grouplist[groupcounter]=[]\n groupname[groupcounter]=block\n groupcache[groupcounter]['block']=block\n if not name: name='unknown_'+block\n groupcache[groupcounter]['prefix']=m.group('before')\n groupcache[groupcounter]['name']=rmbadname1(name)\n groupcache[groupcounter]['result']=result\n if groupcounter==1:\n groupcache[groupcounter]['from']=currentfilename\n else:\n if f77modulename and groupcounter==3:\n groupcache[groupcounter]['from']='%s:%s'%(groupcache[groupcounter-1]['from'],currentfilename)\n else:\n groupcache[groupcounter]['from']='%s:%s'%(groupcache[groupcounter-1]['from'],groupcache[groupcounter-1]['name'])\n for k in groupcache[groupcounter].keys():\n if not groupcache[groupcounter][k]: del groupcache[groupcounter][k]\n groupcache[groupcounter]['args']=args\n groupcache[groupcounter]['body']=[]\n groupcache[groupcounter]['externals']=[]\n groupcache[groupcounter]['interfaced']=[]\n groupcache[groupcounter]['vars']={}\n groupcache[groupcounter]['entry']={}\n # end of creation\n if block=='type':\n groupcache[groupcounter]['varnames'] = []\n\n if case in ['call','callfun']: # set parents variables\n if name not in groupcache[groupcounter-2]['externals']:\n groupcache[groupcounter-2]['externals'].append(name)\n groupcache[groupcounter]['vars']=copy.deepcopy(groupcache[groupcounter-2]['vars'])\n #try: del groupcache[groupcounter]['vars'][groupcache[groupcounter-2]['name']]\n #except: pass\n try: del groupcache[groupcounter]['vars'][name][groupcache[groupcounter]['vars'][name]['attrspec'].index('external')]\n except: pass\n if block in ['function','subroutine']: # set global attributes\n try: groupcache[groupcounter]['vars'][name]=appenddecl(groupcache[groupcounter]['vars'][name],groupcache[groupcounter-2]['vars'][''])\n except: pass\n if case=='callfun': # return type\n if result and groupcache[groupcounter]['vars'].has_key(result):\n if not name==result:\n groupcache[groupcounter]['vars'][name]=appenddecl(groupcache[groupcounter]['vars'][name],groupcache[groupcounter]['vars'][result])\n #if groupcounter>1: # name is interfaced\n try: groupcache[groupcounter-2]['interfaced'].append(name)\n except: pass\n if block=='function':\n t=typespattern[0].match(m.group('before')+' '+name)\n if t:\n typespec,selector,attr,edecl=cracktypespec0(t.group('this'),t.group('after'))\n updatevars(typespec,selector,attr,edecl)\n if case in ['call','callfun']:\n grouplist[groupcounter-1].append(groupcache[groupcounter])\n grouplist[groupcounter-1][-1]['body']=grouplist[groupcounter]\n del grouplist[groupcounter]\n groupcounter=groupcounter-1 # end routine\n grouplist[groupcounter-1].append(groupcache[groupcounter])\n grouplist[groupcounter-1][-1]['body']=grouplist[groupcounter]\n del grouplist[groupcounter]\n groupcounter=groupcounter-1 # end interface\n elif case=='entry':\n name,args,result=_resolvenameargspattern(m.group('after'))\n if name is not None:\n if args:\n args=rmbadname(map(string.strip,string.split(markoutercomma(args),'@,@')))\n else: args=[]\n assert result is None,`result`\n groupcache[groupcounter]['entry'][name] = args\n previous_context = ('entry',name,groupcounter)\n elif case=='type':\n typespec,selector,attr,edecl=cracktypespec0(block,m.group('after'))\n last_name = updatevars(typespec,selector,attr,edecl)\n if last_name is not None:\n previous_context = ('variable',last_name,groupcounter)\n elif case in ['dimension','intent','optional','required','external','public','private','intrisic']:\n edecl=groupcache[groupcounter]['vars']\n ll=m.group('after').strip()\n i=string.find(ll,'::')\n if i<0 and case=='intent':\n i=string.find(markouterparen(ll),'@)@')-2\n ll=ll[:i+1]+'::'+ll[i+1:]\n i=string.find(ll,'::')\n if ll[i:]=='::' and groupcache[groupcounter].has_key('args'):\n outmess('All arguments will have attribute %s%s\\n'%(m.group('this'),ll[:i]))\n ll = ll + string.join(groupcache[groupcounter]['args'],',')\n if i<0:i=0;pl=''\n else: pl=string.strip(ll[:i]);ll=ll[i+2:]\n ch = string.split(markoutercomma(pl),'@,@')\n if len(ch)>1:\n pl = ch[0]\n outmess('analyzeline: cannot handle multiple attributes without type specification. Ignoring %r.\\n' % (','.join(ch[1:])))\n last_name = None\n for e in map(string.strip,string.split(markoutercomma(ll),'@,@')):\n m1=namepattern.match(e)\n if not m1:\n if case in ['public','private']: k=''\n else:\n print m.groupdict()\n outmess('analyzeline: no name pattern found in %s statement for %s. Skipping.\\n'%(case,`e`))\n continue\n else:\n k=rmbadname1(m1.group('name'))\n if not edecl.has_key(k): edecl[k]={}\n if case=='dimension': ap=case+m1.group('after')\n if case=='intent':\n ap=m.group('this')+pl\n if _intentcallbackpattern.match(ap):\n if k not in groupcache[groupcounter]['args']:\n if groupcounter>1 and \\\n string.find(groupcache[groupcounter-2]['name'],\n '__user__')==-1:\n outmess('analyzeline: appending intent(callback) %s'\\\n ' to %s arguments\\n' % (k,groupcache[groupcounter]['name']))\n groupcache[groupcounter]['args'].append(k)\n else:\n errmess('analyzeline: intent(callback) %s is already'\\\n ' in argument list' % (k))\n if case in ['optional','required','public','external','private','intrisic']: ap=case\n if edecl[k].has_key('attrspec'): edecl[k]['attrspec'].append(ap)\n else: edecl[k]['attrspec']=[ap]\n if case=='external':\n if groupcache[groupcounter]['block']=='program':\n outmess('analyzeline: ignoring program arguments\\n')\n continue\n if k not in groupcache[groupcounter]['args']:\n #outmess('analyzeline: ignoring external %s (not in arguments list)\\n'%(`k`))\n continue\n if not groupcache[groupcounter].has_key('externals'):\n groupcache[groupcounter]['externals']=[]\n groupcache[groupcounter]['externals'].append(k)\n last_name = k\n groupcache[groupcounter]['vars']=edecl\n if last_name is not None:\n previous_context = ('variable',last_name,groupcounter)\n elif case=='parameter':\n edecl=groupcache[groupcounter]['vars']\n ll=string.strip(m.group('after'))[1:-1]\n last_name = None\n for e in string.split(markoutercomma(ll),'@,@'):\n try:\n k,initexpr=map(string.strip,string.split(e,'='))\n except:\n outmess('analyzeline: could not extract name,expr in parameter statement \"%s\" of \"%s\"\\n'%(e,ll));continue\n params = get_parameters(edecl)\n k=rmbadname1(k)\n if not edecl.has_key(k): edecl[k]={}\n if edecl[k].has_key('=') and (not edecl[k]['=']==initexpr):\n outmess('analyzeline: Overwriting the value of parameter \"%s\" (\"%s\") with \"%s\".\\n'%(k,edecl[k]['='],initexpr))\n t = determineexprtype(initexpr,params)\n if t:\n if t.get('typespec')=='real':\n tt = list(initexpr)\n for m in real16pattern.finditer(initexpr):\n tt[m.start():m.end()] = list(\\\n initexpr[m.start():m.end()].lower().replace('d', 'e'))\n initexpr = \"\".join(tt)\n elif t.get('typespec')=='complex':\n initexpr = initexpr[1:].lower().replace('d','e').\\\n replace(',','+1j*(')\n try:\n v = eval(initexpr,{},params)\n except (SyntaxError,NameError),msg:\n errmess('analyzeline: Failed to evaluate %r. Ignoring: %s\\n'\\\n % (initexpr, msg))\n continue\n edecl[k]['='] = repr(v)\n if edecl[k].has_key('attrspec'):\n edecl[k]['attrspec'].append('parameter')\n else: edecl[k]['attrspec']=['parameter']\n last_name = k\n groupcache[groupcounter]['vars']=edecl\n if last_name is not None:\n previous_context = ('variable',last_name,groupcounter)\n elif case=='implicit':\n if string.lower(string.strip(m.group('after')))=='none':\n groupcache[groupcounter]['implicit']=None\n elif m.group('after'):\n if groupcache[groupcounter].has_key('implicit'):\n impl=groupcache[groupcounter]['implicit']\n else: impl={}\n if impl is None:\n outmess('analyzeline: Overwriting earlier \"implicit none\" statement.\\n')\n impl={}\n for e in string.split(markoutercomma(m.group('after')),'@,@'):\n decl={}\n m1=re.match(r'\\s*(?P.*?)\\s*(\\(\\s*(?P[a-z-, ]+)\\s*\\)\\s*|)\\Z',e,re.I)\n if not m1:\n outmess('analyzeline: could not extract info of implicit statement part \"%s\"\\n'%(e));continue\n m2=typespattern4implicit.match(m1.group('this'))\n if not m2:\n outmess('analyzeline: could not extract types pattern of implicit statement part \"%s\"\\n'%(e));continue\n typespec,selector,attr,edecl=cracktypespec0(m2.group('this'),m2.group('after'))\n kindselect,charselect,typename=cracktypespec(typespec,selector)\n decl['typespec']=typespec\n decl['kindselector']=kindselect\n decl['charselector']=charselect\n decl['typename']=typename\n for k in decl.keys():\n if not decl[k]: del decl[k]\n for r in string.split(markoutercomma(m1.group('after')),'@,@'):\n if '-' in r:\n try: begc,endc=map(string.strip,string.split(r,'-'))\n except:\n outmess('analyzeline: expected \"-\" instead of \"%s\" in range list of implicit statement\\n'%r);continue\n else: begc=endc=string.strip(r)\n if not len(begc)==len(endc)==1:\n outmess('analyzeline: expected \"-\" instead of \"%s\" in range list of implicit statement (2)\\n'%r);continue\n for o in range(ord(begc),ord(endc)+1):\n impl[chr(o)]=decl\n groupcache[groupcounter]['implicit']=impl\n elif case=='data':\n ll=[]\n dl='';il='';f=0;fc=1\n for c in m.group('after'):\n if c==\"'\": fc=not fc\n if c=='/' and fc: f=f+1;continue\n if f==0: dl=dl+c\n elif f==1: il=il+c\n elif f==2:\n dl = dl.strip()\n if dl.startswith(','):\n dl = dl[1:].strip()\n ll.append([dl,il])\n dl=c;il='';f=0\n if f==2:\n dl = dl.strip()\n if dl.startswith(','):\n dl = dl[1:].strip()\n ll.append([dl,il])\n vars={}\n if groupcache[groupcounter].has_key('vars'):\n vars=groupcache[groupcounter]['vars']\n last_name = None\n for l in ll:\n l=map(string.strip,l)\n if l[0][0]==',':l[0]=l[0][1:]\n if l[0][0]=='(':\n outmess('analyzeline: implied-DO list \"%s\" is not supported. Skipping.\\n'%l[0])\n continue\n #if '(' in l[0]:\n # #outmess('analyzeline: ignoring this data statement.\\n')\n # continue\n i=0;j=0;llen=len(l[1])\n for v in rmbadname(map(string.strip,string.split(markoutercomma(l[0]),'@,@'))):\n if v[0]=='(':\n outmess('analyzeline: implied-DO list \"%s\" is not supported. Skipping.\\n'%v)\n # XXX: subsequent init expressions may get wrong values.\n # Ignoring since data statements are irrelevant for wrapping.\n continue\n fc=0\n while (i=3:\n bn = string.strip(bn)\n if not bn: bn='_BLNK_'\n cl.append([bn,ol])\n f=f-2;bn='';ol=''\n if f%2: bn=bn+c\n else: ol=ol+c\n bn = string.strip(bn)\n if not bn: bn='_BLNK_'\n cl.append([bn,ol])\n commonkey={}\n if groupcache[groupcounter].has_key('common'):\n commonkey=groupcache[groupcounter]['common']\n for c in cl:\n if commonkey.has_key(c[0]):\n outmess('analyzeline: previously defined common block encountered. Skipping.\\n')\n continue\n commonkey[c[0]]=[]\n for i in map(string.strip,string.split(markoutercomma(c[1]),'@,@')):\n if i: commonkey[c[0]].append(i)\n groupcache[groupcounter]['common']=commonkey\n previous_context = ('common',bn,groupcounter)\n elif case=='use':\n m1=re.match(r'\\A\\s*(?P\\b[\\w]+\\b)\\s*((,(\\s*\\bonly\\b\\s*:|(?P))\\s*(?P.*))|)\\s*\\Z',m.group('after'),re.I)\n if m1:\n mm=m1.groupdict()\n if not groupcache[groupcounter].has_key('use'): groupcache[groupcounter]['use']={}\n name=m1.group('name')\n groupcache[groupcounter]['use'][name]={}\n isonly=0\n if mm.has_key('list') and mm['list'] is not None:\n if mm.has_key('notonly') and mm['notonly'] is None:isonly=1\n groupcache[groupcounter]['use'][name]['only']=isonly\n ll=map(string.strip,string.split(mm['list'],','))\n rl={}\n for l in ll:\n if '=' in l:\n m2=re.match(r'\\A\\s*(?P\\b[\\w]+\\b)\\s*=\\s*>\\s*(?P\\b[\\w]+\\b)\\s*\\Z',l,re.I)\n if m2: rl[string.strip(m2.group('local'))]=string.strip(m2.group('use'))\n else:\n outmess('analyzeline: Not local=>use pattern found in %s\\n'%`l`)\n else:\n rl[l]=l\n groupcache[groupcounter]['use'][name]['map']=rl\n else:\n pass\n\n else:\n print m.groupdict()\n outmess('analyzeline: Could not crack the use statement.\\n')\n elif case in ['f2pyenhancements']:\n if not groupcache[groupcounter].has_key ('f2pyenhancements'):\n groupcache[groupcounter]['f2pyenhancements'] = {}\n d = groupcache[groupcounter]['f2pyenhancements']\n if m.group('this')=='usercode' and d.has_key('usercode'):\n if type(d['usercode']) is type(''):\n d['usercode'] = [d['usercode']]\n d['usercode'].append(m.group('after'))\n else:\n d[m.group('this')] = m.group('after')\n elif case=='multiline':\n if previous_context is None:\n if verbose:\n outmess('analyzeline: No context for multiline block.\\n')\n return\n gc = groupcounter\n #gc = previous_context[2]\n appendmultiline(groupcache[gc],\n previous_context[:2],\n m.group('this'))\n else:\n if verbose>1:\n print m.groupdict()\n outmess('analyzeline: No code implemented for line.\\n')\n\ndef appendmultiline(group, context_name,ml):\n if not group.has_key('f2pymultilines'):\n group['f2pymultilines'] = {}\n d = group['f2pymultilines']\n if not d.has_key(context_name):\n d[context_name] = []\n d[context_name].append(ml)\n return\n\ndef cracktypespec0(typespec,ll):\n selector=None\n attr=None\n if re.match(r'double\\s*complex',typespec,re.I): typespec='double complex'\n elif re.match(r'double\\s*precision',typespec,re.I): typespec='double precision'\n else: typespec=string.lower(string.strip(typespec))\n m1=selectpattern.match(markouterparen(ll))\n if not m1:\n outmess('cracktypespec0: no kind/char_selector pattern found for line.\\n')\n return\n d=m1.groupdict()\n for k in d.keys(): d[k]=unmarkouterparen(d[k])\n if typespec in ['complex','integer','logical','real','character','type']:\n selector=d['this']\n ll=d['after']\n i=string.find(ll,'::')\n if i>=0:\n attr=string.strip(ll[:i])\n ll=ll[i+2:]\n return typespec,selector,attr,ll\n#####\nnamepattern=re.compile(r'\\s*(?P\\b[\\w]+\\b)\\s*(?P.*)\\s*\\Z',re.I)\nkindselector=re.compile(r'\\s*(\\(\\s*(kind\\s*=)?\\s*(?P.*)\\s*\\)|[*]\\s*(?P.*?))\\s*\\Z',re.I)\ncharselector=re.compile(r'\\s*(\\((?P.*)\\)|[*]\\s*(?P.*))\\s*\\Z',re.I)\nlenkindpattern=re.compile(r'\\s*(kind\\s*=\\s*(?P.*?)\\s*(@,@\\s*len\\s*=\\s*(?P.*)|)|(len\\s*=\\s*|)(?P.*?)\\s*(@,@\\s*(kind\\s*=\\s*|)(?P.*)|))\\s*\\Z',re.I)\nlenarraypattern=re.compile(r'\\s*(@\\(@\\s*(?!/)\\s*(?P.*?)\\s*@\\)@\\s*[*]\\s*(?P.*?)|([*]\\s*(?P.*?)|)\\s*(@\\(@\\s*(?!/)\\s*(?P.*?)\\s*@\\)@|))\\s*(=\\s*(?P.*?)|(@\\(@|)/\\s*(?P.*?)\\s*/(@\\)@|)|)\\s*\\Z',re.I)\ndef removespaces(expr):\n expr=string.strip(expr)\n if len(expr)<=1: return expr\n expr2=expr[0]\n for i in range(1,len(expr)-1):\n if expr[i]==' ' and \\\n ((expr[i+1] in \"()[]{}= \") or (expr[i-1] in \"()[]{}= \")): continue\n expr2=expr2+expr[i]\n expr2=expr2+expr[-1]\n return expr2\ndef markinnerspaces(line):\n l='';f=0\n cc='\\''\n cc1='\"'\n cb=''\n for c in line:\n if cb=='\\\\' and c in ['\\\\','\\'','\"']:\n l=l+c;\n cb=c\n continue\n if f==0 and c in ['\\'','\"']: cc=c; cc1={'\\'':'\"','\"':'\\''}[c]\n if c==cc:f=f+1\n elif c==cc:f=f-1\n elif c==' ' and f==1: l=l+'@_@'; continue\n l=l+c;cb=c\n return l\ndef updatevars(typespec,selector,attrspec,entitydecl):\n global groupcache,groupcounter\n last_name = None\n kindselect,charselect,typename=cracktypespec(typespec,selector)\n if attrspec:\n attrspec=map(string.strip,string.split(markoutercomma(attrspec),'@,@'))\n l = []\n c = re.compile(r'(?P[a-zA-Z]+)')\n for a in attrspec:\n m = c.match(a)\n if m:\n s = string.lower(m.group('start'))\n a = s + a[len(s):]\n l.append(a)\n attrspec = l\n el=map(string.strip,string.split(markoutercomma(entitydecl),'@,@'))\n el1=[]\n for e in el:\n for e1 in map(string.strip,string.split(markoutercomma(removespaces(markinnerspaces(e)),comma=' '),'@ @')):\n if e1: el1.append(string.replace(e1,'@_@',' '))\n for e in el1:\n m=namepattern.match(e)\n if not m:\n outmess('updatevars: no name pattern found for entity=%s. Skipping.\\n'%(`e`))\n continue\n ename=rmbadname1(m.group('name'))\n edecl={}\n if groupcache[groupcounter]['vars'].has_key(ename):\n edecl=groupcache[groupcounter]['vars'][ename].copy()\n has_typespec = edecl.has_key('typespec')\n if not has_typespec:\n edecl['typespec']=typespec\n elif typespec and (not typespec==edecl['typespec']):\n outmess('updatevars: attempt to change the type of \"%s\" (\"%s\") to \"%s\". Ignoring.\\n' % (ename,edecl['typespec'],typespec))\n if not edecl.has_key('kindselector'):\n edecl['kindselector']=copy.copy(kindselect)\n elif kindselect:\n for k in kindselect.keys():\n if edecl['kindselector'].has_key(k) and (not kindselect[k]==edecl['kindselector'][k]):\n outmess('updatevars: attempt to change the kindselector \"%s\" of \"%s\" (\"%s\") to \"%s\". Ignoring.\\n' % (k,ename,edecl['kindselector'][k],kindselect[k]))\n else: edecl['kindselector'][k]=copy.copy(kindselect[k])\n if not edecl.has_key('charselector') and charselect:\n if not has_typespec:\n edecl['charselector']=charselect\n else:\n errmess('updatevars:%s: attempt to change empty charselector to %r. Ignoring.\\n' \\\n %(ename,charselect))\n elif charselect:\n for k in charselect.keys():\n if edecl['charselector'].has_key(k) and (not charselect[k]==edecl['charselector'][k]):\n outmess('updatevars: attempt to change the charselector \"%s\" of \"%s\" (\"%s\") to \"%s\". Ignoring.\\n' % (k,ename,edecl['charselector'][k],charselect[k]))\n else: edecl['charselector'][k]=copy.copy(charselect[k])\n if not edecl.has_key('typename'):\n edecl['typename']=typename\n elif typename and (not edecl['typename']==typename):\n outmess('updatevars: attempt to change the typename of \"%s\" (\"%s\") to \"%s\". Ignoring.\\n' % (ename,edecl['typename'],typename))\n if not edecl.has_key('attrspec'):\n edecl['attrspec']=copy.copy(attrspec)\n elif attrspec:\n for a in attrspec:\n if a not in edecl['attrspec']:\n edecl['attrspec'].append(a)\n else:\n edecl['typespec']=copy.copy(typespec)\n edecl['kindselector']=copy.copy(kindselect)\n edecl['charselector']=copy.copy(charselect)\n edecl['typename']=typename\n edecl['attrspec']=copy.copy(attrspec)\n if m.group('after'):\n m1=lenarraypattern.match(markouterparen(m.group('after')))\n if m1:\n d1=m1.groupdict()\n for lk in ['len','array','init']:\n if d1[lk+'2'] is not None: d1[lk]=d1[lk+'2']; del d1[lk+'2']\n for k in d1.keys():\n if d1[k] is not None: d1[k]=unmarkouterparen(d1[k])\n else: del d1[k]\n if d1.has_key('len') and d1.has_key('array'):\n if d1['len']=='':\n d1['len']=d1['array']\n del d1['array']\n else:\n d1['array']=d1['array']+','+d1['len']\n del d1['len']\n errmess('updatevars: \"%s %s\" is mapped to \"%s %s(%s)\"\\n'%(typespec,e,typespec,ename,d1['array']))\n if d1.has_key('array'):\n dm = 'dimension(%s)'%d1['array']\n if not edecl.has_key('attrspec') or (not edecl['attrspec']):\n edecl['attrspec']=[dm]\n else:\n edecl['attrspec'].append(dm)\n for dm1 in edecl['attrspec']:\n if dm1[:9]=='dimension' and dm1!=dm:\n del edecl['attrspec'][-1]\n errmess('updatevars:%s: attempt to change %r to %r. Ignoring.\\n' \\\n % (ename,dm1,dm))\n break\n\n if d1.has_key('len'):\n if typespec in ['complex','integer','logical','real']:\n if (not edecl.has_key('kindselector')) or (not edecl['kindselector']):\n edecl['kindselector']={}\n edecl['kindselector']['*']=d1['len']\n elif typespec == 'character':\n if (not edecl.has_key('charselector')) or (not edecl['charselector']): edecl['charselector']={}\n if edecl['charselector'].has_key('len'): del edecl['charselector']['len']\n edecl['charselector']['*']=d1['len']\n if d1.has_key('init'):\n if edecl.has_key('=') and (not edecl['=']==d1['init']):\n outmess('updatevars: attempt to change the init expression of \"%s\" (\"%s\") to \"%s\". Ignoring.\\n' % (ename,edecl['='],d1['init']))\n else:\n edecl['=']=d1['init']\n else:\n outmess('updatevars: could not crack entity declaration \"%s\". Ignoring.\\n'%(ename+m.group('after')))\n for k in edecl.keys():\n if not edecl[k]: del edecl[k]\n groupcache[groupcounter]['vars'][ename]=edecl\n if groupcache[groupcounter].has_key('varnames'):\n groupcache[groupcounter]['varnames'].append(ename)\n last_name = ename\n return last_name\n\ndef cracktypespec(typespec,selector):\n kindselect=None\n charselect=None\n typename=None\n if selector:\n if typespec in ['complex','integer','logical','real']:\n kindselect=kindselector.match(selector)\n if not kindselect:\n outmess('cracktypespec: no kindselector pattern found for %s\\n'%(`selector`))\n return\n kindselect=kindselect.groupdict()\n kindselect['*']=kindselect['kind2']\n del kindselect['kind2']\n for k in kindselect.keys():\n if not kindselect[k]: del kindselect[k]\n for k,i in kindselect.items():\n kindselect[k] = rmbadname1(i)\n elif typespec=='character':\n charselect=charselector.match(selector)\n if not charselect:\n outmess('cracktypespec: no charselector pattern found for %s\\n'%(`selector`))\n return\n charselect=charselect.groupdict()\n charselect['*']=charselect['charlen']\n del charselect['charlen']\n if charselect['lenkind']:\n lenkind=lenkindpattern.match(markoutercomma(charselect['lenkind']))\n lenkind=lenkind.groupdict()\n for lk in ['len','kind']:\n if lenkind[lk+'2']:\n lenkind[lk]=lenkind[lk+'2']\n charselect[lk]=lenkind[lk]\n del lenkind[lk+'2']\n del charselect['lenkind']\n for k in charselect.keys():\n if not charselect[k]: del charselect[k]\n for k,i in charselect.items():\n charselect[k] = rmbadname1(i)\n elif typespec=='type':\n typename=re.match(r'\\s*\\(\\s*(?P\\w+)\\s*\\)',selector,re.I)\n if typename: typename=typename.group('name')\n else: outmess('cracktypespec: no typename found in %s\\n'%(`typespec+selector`))\n else:\n outmess('cracktypespec: no selector used for %s\\n'%(`selector`))\n return kindselect,charselect,typename\n######\ndef setattrspec(decl,attr,force=0):\n if not decl: decl={}\n if not attr: return decl\n if not decl.has_key('attrspec'):\n decl['attrspec']=[attr]\n return decl\n if force: decl['attrspec'].append(attr)\n if attr in decl['attrspec']: return decl\n if attr=='static' and 'automatic' not in decl['attrspec']:\n decl['attrspec'].append(attr)\n elif attr=='automatic' and 'static' not in decl['attrspec']:\n decl['attrspec'].append(attr)\n elif attr=='public' and 'private' not in decl['attrspec']:\n decl['attrspec'].append(attr)\n elif attr=='private' and 'public' not in decl['attrspec']:\n decl['attrspec'].append(attr)\n else:\n decl['attrspec'].append(attr)\n return decl\ndef setkindselector(decl,sel,force=0):\n if not decl: decl={}\n if not sel: return decl\n if not decl.has_key('kindselector'):\n decl['kindselector']=sel\n return decl\n for k in sel.keys():\n if force or not decl['kindselector'].has_key(k):\n decl['kindselector'][k]=sel[k]\n return decl\ndef setcharselector(decl,sel,force=0):\n if not decl: decl={}\n if not sel: return decl\n if not decl.has_key('charselector'):\n decl['charselector']=sel\n return decl\n for k in sel.keys():\n if force or not decl['charselector'].has_key(k):\n decl['charselector'][k]=sel[k]\n return decl\ndef getblockname(block,unknown='unknown'):\n if block.has_key('name'): return block['name']\n return unknown\n###### post processing\ndef setmesstext(block):\n global filepositiontext\n try: filepositiontext='In: %s:%s\\n'%(block['from'],block['name'])\n except: pass\n\ndef get_usedict(block):\n usedict = {}\n if block.has_key('parent_block'):\n usedict = get_usedict(block['parent_block'])\n if block.has_key('use'):\n usedict.update(block['use'])\n return usedict\n\ndef get_useparameters(block, param_map=None):\n global f90modulevars\n if param_map is None:\n param_map = {}\n usedict = get_usedict(block)\n if not usedict:\n return param_map\n for usename,mapping in usedict.items():\n usename = string.lower(usename)\n if not f90modulevars.has_key(usename):\n continue\n mvars = f90modulevars[usename]\n params = get_parameters(mvars)\n if not params:\n continue\n # XXX: apply mapping\n if mapping:\n errmess('get_useparameters: mapping for %s not impl.' % (mapping))\n for k,v in params.items():\n if param_map.has_key(k):\n outmess('get_useparameters: overriding parameter %s with'\\\n ' value from module %s' % (`k`,`usename`))\n param_map[k] = v\n return param_map\n\ndef postcrack2(block,tab='',param_map=None):\n global f90modulevars\n if not f90modulevars:\n return block\n if type(block)==types.ListType:\n ret = []\n for g in block:\n g = postcrack2(g,tab=tab+'\\t',param_map=param_map)\n ret.append(g)\n return ret\n setmesstext(block)\n outmess('%sBlock: %s\\n'%(tab,block['name']),0)\n\n if param_map is None:\n param_map = get_useparameters(block)\n\n if param_map is not None and block.has_key('vars'):\n vars = block['vars']\n for n in vars.keys():\n var = vars[n]\n if var.has_key('kindselector'):\n kind = var['kindselector']\n if kind.has_key('kind'):\n val = kind['kind']\n if param_map.has_key(val):\n kind['kind'] = param_map[val]\n new_body = []\n for b in block['body']:\n b = postcrack2(b,tab=tab+'\\t',param_map=param_map)\n new_body.append(b)\n block['body'] = new_body\n\n return block\n\ndef postcrack(block,args=None,tab=''):\n \"\"\"\n TODO:\n function return values\n determine expression types if in argument list\n \"\"\"\n global usermodules,onlyfunctions\n if type(block)==types.ListType:\n gret=[]\n uret=[]\n for g in block:\n setmesstext(g)\n g=postcrack(g,tab=tab+'\\t')\n if g.has_key('name') and string.find(g['name'],'__user__')>=0: # sort user routines to appear first\n uret.append(g)\n else:\n gret.append(g)\n return uret+gret\n setmesstext(block)\n if (not type(block)==types.DictType) and not block.has_key('block'):\n raise 'postcrack: Expected block dictionary instead of ',block\n if block.has_key('name') and not block['name']=='unknown_interface':\n outmess('%sBlock: %s\\n'%(tab,block['name']),0)\n blocktype=block['block']\n block=analyzeargs(block)\n block=analyzecommon(block)\n block['vars']=analyzevars(block)\n block['sortvars']=sortvarnames(block['vars'])\n if block.has_key('args') and block['args']:\n args=block['args']\n block['body']=analyzebody(block,args,tab=tab)\n\n userisdefined=[]\n## fromuser = []\n if block.has_key('use'):\n useblock=block['use']\n for k in useblock.keys():\n if string.find(k,'__user__')>=0:\n userisdefined.append(k)\n## if useblock[k].has_key('map'):\n## for n in useblock[k]['map'].values():\n## if n not in fromuser: fromuser.append(n)\n else: useblock={}\n name=''\n if block.has_key('name'):name=block['name']\n if block.has_key('externals') and block['externals']:# and not userisdefined: # Build a __user__ module\n interfaced=[]\n if block.has_key('interfaced'): interfaced=block['interfaced']\n mvars=copy.copy(block['vars'])\n if name: mname=name+'__user__routines'\n else: mname='unknown__user__routines'\n if mname in userisdefined:\n i=1\n while '%s_%i'%(mname,i) in userisdefined: i=i+1\n mname='%s_%i'%(mname,i)\n interface={'block':'interface','body':[],'vars':{},'name':name+'_user_interface'}\n for e in block['externals']:\n## if e in fromuser:\n## outmess(' Skipping %s that is defined explicitly in another use statement\\n'%(`e`))\n## continue\n if e in interfaced:\n edef=[]\n j=-1\n for b in block['body']:\n j=j+1\n if b['block']=='interface':\n i=-1\n for bb in b['body']:\n i=i+1\n if bb.has_key('name') and bb['name']==e:\n edef=copy.copy(bb)\n del b['body'][i]\n break\n if edef:\n if not b['body']: del block['body'][j]\n del interfaced[interfaced.index(e)]\n break\n interface['body'].append(edef)\n else:\n if mvars.has_key(e) and not isexternal(mvars[e]):\n interface['vars'][e]=mvars[e]\n if interface['vars'] or interface['body']:\n block['interfaced']=interfaced\n mblock={'block':'python module','body':[interface],'vars':{},'name':mname,'interfaced':block['externals']}\n useblock[mname]={}\n usermodules.append(mblock)\n if useblock:\n block['use']=useblock\n return block\n\ndef sortvarnames(vars):\n indep = []\n dep = []\n for v in vars.keys():\n if vars[v].has_key('depend') and vars[v]['depend']:\n dep.append(v)\n #print '%s depends on %s'%(v,vars[v]['depend'])\n else: indep.append(v)\n n = len(dep)\n i = 0\n while dep: #XXX: How to catch dependence cycles correctly?\n v = dep[0]\n fl = 0\n for w in dep[1:]:\n if w in vars[v]['depend']:\n fl = 1\n break\n if fl:\n dep = dep[1:]+[v]\n i = i + 1\n if i>n:\n errmess('sortvarnames: failed to compute dependencies because'\n ' of cyclic dependencies between '\n +string.join(dep,', ')+'\\n')\n indep = indep + dep\n break\n else:\n indep.append(v)\n dep = dep[1:]\n n = len(dep)\n i = 0\n #print indep\n return indep\n\ndef analyzecommon(block):\n if not hascommon(block): return block\n commonvars=[]\n for k in block['common'].keys():\n comvars=[]\n for e in block['common'][k]:\n m=re.match(r'\\A\\s*\\b(?P.*?)\\b\\s*(\\((?P.*?)\\)|)\\s*\\Z',e,re.I)\n if m:\n dims=[]\n if m.group('dims'):\n dims=map(string.strip,string.split(markoutercomma(m.group('dims')),'@,@'))\n n=string.strip(m.group('name'))\n if block['vars'].has_key(n):\n if block['vars'][n].has_key('attrspec'):\n block['vars'][n]['attrspec'].append('dimension(%s)'%(string.join(dims,',')))\n else:\n block['vars'][n]['attrspec']=['dimension(%s)'%(string.join(dims,','))]\n else:\n if dims:\n block['vars'][n]={'attrspec':['dimension(%s)'%(string.join(dims,','))]}\n else: block['vars'][n]={}\n if n not in commonvars: commonvars.append(n)\n else:\n n=e\n errmess('analyzecommon: failed to extract \"[()]\" from \"%s\" in common /%s/.\\n'%(e,k))\n comvars.append(n)\n block['common'][k]=comvars\n if not block.has_key('commonvars'):\n block['commonvars']=commonvars\n else:\n block['commonvars']=block['commonvars']+commonvars\n return block\ndef analyzebody(block,args,tab=''):\n global usermodules,skipfuncs,onlyfuncs,f90modulevars\n setmesstext(block)\n body=[]\n for b in block['body']:\n b['parent_block'] = block\n if b['block'] in ['function','subroutine']:\n if args is not None and b['name'] not in args:\n continue\n else:\n as=b['args']\n if b['name'] in skipfuncs:\n continue\n if onlyfuncs and b['name'] not in onlyfuncs:\n continue\n else: as=args\n b=postcrack(b,as,tab=tab+'\\t')\n if b['block']=='interface' and not b['body']:\n if not b.has_key('f2pyenhancements'):\n continue\n if string.replace(b['block'],' ','')=='pythonmodule':\n usermodules.append(b)\n else:\n if b['block']=='module':\n f90modulevars[b['name']] = b['vars']\n body.append(b)\n return body\ndef buildimplicitrules(block):\n setmesstext(block)\n implicitrules=defaultimplicitrules\n attrrules={}\n if block.has_key('implicit'):\n if block['implicit'] is None:\n implicitrules=None\n if verbose>1:\n outmess('buildimplicitrules: no implicit rules for routine %s.\\n'%`block['name']`)\n else:\n for k in block['implicit'].keys():\n if block['implicit'][k].get('typespec') not in ['static','automatic']:\n implicitrules[k]=block['implicit'][k]\n else:\n attrrules[k]=block['implicit'][k]['typespec']\n return implicitrules,attrrules\n\ndef myeval(e,g=None,l=None):\n r = eval(e,g,l)\n if type(r) in [type(0),type(0.0)]:\n return r\n raise ValueError,'r=%r' % (r)\n\ngetlincoef_re_1 = re.compile(r'\\A\\b\\w+\\b\\Z',re.I)\ndef getlincoef(e,xset): # e = a*x+b ; x in xset\n try:\n c = int(myeval(e,{},{}))\n return 0,c,None\n except: pass\n if getlincoef_re_1.match(e):\n return 1,0,e\n len_e = len(e)\n for x in xset:\n if len(x)>len_e: continue\n re_1 = re.compile(r'(?P.*?)\\b'+x+r'\\b(?P.*)',re.I)\n m = re_1.match(e)\n if m:\n try:\n m1 = re_1.match(e)\n while m1:\n ee = '%s(%s)%s'%(m1.group('before'),0,m1.group('after'))\n m1 = re_1.match(ee)\n b = myeval(ee,{},{})\n m1 = re_1.match(e)\n while m1:\n ee = '%s(%s)%s'%(m1.group('before'),1,m1.group('after'))\n m1 = re_1.match(ee)\n a = myeval(ee,{},{}) - b\n m1 = re_1.match(e)\n while m1:\n ee = '%s(%s)%s'%(m1.group('before'),0.5,m1.group('after'))\n m1 = re_1.match(ee)\n c = myeval(ee,{},{})\n if (a*0.5+b==c):\n return a,b,x\n except: pass\n break\n return None,None,None\n\n_varname_match = re.compile(r'\\A[a-z]\\w*\\Z').match\ndef getarrlen(dl,args,star='*'):\n edl = []\n try: edl.append(myeval(dl[0],{},{}))\n except: edl.append(dl[0])\n try: edl.append(myeval(dl[1],{},{}))\n except: edl.append(dl[1])\n if type(edl[0]) is type(0):\n p1 = 1-edl[0]\n if p1==0: d = str(dl[1])\n elif p1<0: d = '%s-%s'%(dl[1],-p1)\n else: d = '%s+%s'%(dl[1],p1)\n elif type(edl[1]) is type(0):\n p1 = 1+edl[1]\n if p1==0: d='-(%s)' % (dl[0])\n else: d='%s-(%s)' % (p1,dl[0])\n else: d = '%s-(%s)+1'%(dl[1],dl[0])\n try: return `myeval(d,{},{})`,None,None\n except: pass\n d1,d2=getlincoef(dl[0],args),getlincoef(dl[1],args)\n if None not in [d1[0],d2[0]]:\n if (d1[0],d2[0])==(0,0):\n return `d2[1]-d1[1]+1`,None,None\n b = d2[1] - d1[1] + 1\n d1 = (d1[0],0,d1[2])\n d2 = (d2[0],b,d2[2])\n if d1[0]==0 and d2[2] in args:\n if b<0: return '%s * %s - %s'%(d2[0],d2[2],-b),d2[2],'+%s)/(%s)'%(-b,d2[0])\n elif b: return '%s * %s + %s'%(d2[0],d2[2],b),d2[2],'-%s)/(%s)'%(b,d2[0])\n else: return '%s * %s'%(d2[0],d2[2]),d2[2],')/(%s)'%(d2[0])\n if d2[0]==0 and d1[2] in args:\n\n if b<0: return '%s * %s - %s'%(-d1[0],d1[2],-b),d1[2],'+%s)/(%s)'%(-b,-d1[0])\n elif b: return '%s * %s + %s'%(-d1[0],d1[2],b),d1[2],'-%s)/(%s)'%(b,-d1[0])\n else: return '%s * %s'%(-d1[0],d1[2]),d1[2],')/(%s)'%(-d1[0])\n if d1[2]==d2[2] and d1[2] in args:\n a = d2[0] - d1[0]\n if not a: return `b`,None,None\n if b<0: return '%s * %s - %s'%(a,d1[2],-b),d2[2],'+%s)/(%s)'%(-b,a)\n elif b: return '%s * %s + %s'%(a,d1[2],b),d2[2],'-%s)/(%s)'%(b,a)\n else: return '%s * %s'%(a,d1[2]),d2[2],')/(%s)'%(a)\n if d1[0]==d2[0]==1:\n c = str(d1[2])\n if c not in args:\n if _varname_match(c):\n outmess('\\tgetarrlen:variable \"%s\" undefined\\n' % (c))\n c = '(%s)'%c\n if b==0: d='%s-%s' % (d2[2],c)\n elif b<0: d='%s-%s-%s' % (d2[2],c,-b)\n else: d='%s-%s+%s' % (d2[2],c,b)\n elif d1[0]==0:\n c2 = str(d2[2])\n if c2 not in args:\n if _varname_match(c2):\n outmess('\\tgetarrlen:variable \"%s\" undefined\\n' % (c2))\n c2 = '(%s)'%c2\n if d2[0]==1: pass\n elif d2[0]==-1: c2='-%s' %c2\n else: c2='%s*%s'%(d2[0],c2)\n\n if b==0: d=c2\n elif b<0: d='%s-%s' % (c2,-b)\n else: d='%s+%s' % (c2,b)\n elif d2[0]==0:\n c1 = str(d1[2])\n if c1 not in args:\n if _varname_match(c1):\n outmess('\\tgetarrlen:variable \"%s\" undefined\\n' % (c1))\n c1 = '(%s)'%c1\n if d1[0]==1: c1='-%s'%c1\n elif d1[0]==-1: c1='+%s'%c1\n elif d1[0]<0: c1='+%s*%s'%(-d1[0],c1)\n else: c1 = '-%s*%s' % (d1[0],c1)\n\n if b==0: d=c1\n elif b<0: d='%s-%s' % (c1,-b)\n else: d='%s+%s' % (c1,b)\n else:\n c1 = str(d1[2])\n if c1 not in args:\n if _varname_match(c1):\n outmess('\\tgetarrlen:variable \"%s\" undefined\\n' % (c1))\n c1 = '(%s)'%c1\n if d1[0]==1: c1='-%s'%c1\n elif d1[0]==-1: c1='+%s'%c1\n elif d1[0]<0: c1='+%s*%s'%(-d1[0],c1)\n else: c1 = '-%s*%s' % (d1[0],c1)\n\n c2 = str(d2[2])\n if c2 not in args:\n if _varname_match(c2):\n outmess('\\tgetarrlen:variable \"%s\" undefined\\n' % (c2))\n c2 = '(%s)'%c2\n if d2[0]==1: pass\n elif d2[0]==-1: c2='-%s' %c2\n else: c2='%s*%s'%(d2[0],c2)\n\n if b==0: d='%s%s' % (c2,c1)\n elif b<0: d='%s%s-%s' % (c2,c1,-b)\n else: d='%s%s+%s' % (c2,c1,b)\n return d,None,None\n\nword_pattern = re.compile(r'\\b[a-z][\\w$]*\\b',re.I)\n\ndef _get_depend_dict(name, vars, deps):\n if vars.has_key(name):\n words = vars[name].get('depend',[])\n\n if vars[name].has_key('=') and not isstring(vars[name]):\n for word in word_pattern.findall(vars[name]['=']):\n if word not in words and vars.has_key(word):\n words.append(word)\n for word in words[:]:\n for w in deps.get(word,[]) \\\n or _get_depend_dict(word, vars, deps):\n if w not in words:\n words.append(w)\n else:\n outmess('_get_depend_dict: no dependence info for %s\\n' % (`name`))\n words = []\n deps[name] = words\n return words\n\ndef _calc_depend_dict(vars):\n names = vars.keys()\n depend_dict = {}\n for n in names:\n _get_depend_dict(n, vars, depend_dict)\n return depend_dict\n\ndef get_sorted_names(vars):\n \"\"\"\n \"\"\"\n depend_dict = _calc_depend_dict(vars)\n names = []\n for name in depend_dict.keys():\n if not depend_dict[name]:\n names.append(name)\n del depend_dict[name]\n while depend_dict:\n for name, lst in depend_dict.items():\n new_lst = [n for n in lst if depend_dict.has_key(n)]\n if not new_lst:\n names.append(name)\n del depend_dict[name]\n else:\n depend_dict[name] = new_lst\n return [name for name in names if vars.has_key(name)]\n\ndef _kind_func(string):\n #XXX: return something sensible.\n if string[0] in \"'\\\"\":\n string = string[1:-1]\n if real16pattern.match(string):\n return 16\n elif real8pattern.match(string):\n return 8\n return 'kind('+string+')'\n\ndef _selected_int_kind_func(r):\n #XXX: This should be processor dependent\n m = 10**r\n if m<=2**8: return 1\n if m<=2**16: return 2\n if m<=2**32: return 4\n if m<=2**64: return 8\n if m<=2**128: return 16\n return -1\n\ndef get_parameters(vars, global_params={}):\n params = copy.copy(global_params)\n g_params = copy.copy(global_params)\n for name,func in [('kind',_kind_func),\n ('selected_int_kind',_selected_int_kind_func),\n ]:\n if not g_params.has_key(name):\n g_params[name] = func\n param_names = []\n for n in get_sorted_names(vars):\n if vars[n].has_key('attrspec') and 'parameter' in vars[n]['attrspec']:\n param_names.append(n)\n kind_re = re.compile(r'\\bkind\\s*\\(\\s*(?P.*)\\s*\\)',re.I)\n selected_int_kind_re = re.compile(r'\\bselected_int_kind\\s*\\(\\s*(?P.*)\\s*\\)',re.I)\n for n in param_names:\n if vars[n].has_key('='):\n v = vars[n]['=']\n if islogical(vars[n]):\n v = v.lower()\n for repl in [\n ('.false.','False'),\n ('.true.','True'),\n #TODO: test .eq., .neq., etc replacements.\n ]:\n v = v.replace(*repl)\n v = kind_re.sub(r'kind(\"\\1\")',v)\n v = selected_int_kind_re.sub(r'selected_int_kind(\\1)',v)\n if isinteger(vars[n]) and not selected_int_kind_re.match(v):\n v = v.split('_')[0]\n if isdouble(vars[n]):\n tt = list(v)\n for m in real16pattern.finditer(v):\n tt[m.start():m.end()] = list(\\\n v[m.start():m.end()].lower().replace('d', 'e'))\n v = string.join(tt,'')\n if iscomplex(vars[n]):\n if v[0]=='(' and v[-1]==')':\n l = markoutercomma(v[1:-1]).split('@,@')\n print n,params\n try:\n params[n] = eval(v,g_params,params)\n except Exception,msg:\n params[n] = v\n #print params\n outmess('get_parameters: got \"%s\" on %s\\n' % (msg,`v`))\n if isstring(vars[n]) and type(params[n]) is type(0):\n params[n] = chr(params[n])\n nl = string.lower(n)\n if nl!=n:\n params[nl] = params[n]\n else:\n print vars[n]\n outmess('get_parameters:parameter %s does not have value?!\\n'%(`n`))\n return params\n\ndef _eval_length(length,params):\n if length in ['(:)','(*)','*']:\n return '(*)'\n return _eval_scalar(length,params)\n\n_is_kind_number = re.compile('\\d+_').match\n\ndef _eval_scalar(value,params):\n if _is_kind_number(value):\n value = value.split('_')[0]\n try:\n value = str(eval(value,{},params))\n except (NameError, SyntaxError):\n return value\n except Exception,msg:\n errmess('\"%s\" in evaluating %r '\\\n '(available names: %s)\\n' \\\n % (msg,value,params.keys()))\n return value\n\ndef analyzevars(block):\n global f90modulevars\n setmesstext(block)\n implicitrules,attrrules=buildimplicitrules(block)\n vars=copy.copy(block['vars'])\n if block['block']=='function' and not vars.has_key(block['name']):\n vars[block['name']]={}\n if block['vars'].has_key(''):\n del vars['']\n if block['vars'][''].has_key('attrspec'):\n gen=block['vars']['']['attrspec']\n for n in vars.keys():\n for k in ['public','private']:\n if k in gen:\n vars[n]=setattrspec(vars[n],k)\n svars=[]\n args = block['args']\n for a in args:\n try:\n vars[a]\n svars.append(a)\n except KeyError:\n pass\n for n in vars.keys():\n if n not in args: svars.append(n)\n\n params = get_parameters(vars, get_useparameters(block))\n\n dep_matches = {}\n name_match = re.compile(r'\\w[\\w\\d_$]*').match\n for v in vars.keys():\n m = name_match(v)\n if m:\n n = v[m.start():m.end()]\n try:\n dep_matches[n]\n except KeyError:\n dep_matches[n] = re.compile(r'.*\\b%s\\b'%(v),re.I).match\n for n in svars:\n if n[0] in attrrules.keys():\n vars[n]=setattrspec(vars[n],attrrules[n[0]])\n if not vars[n].has_key('typespec'):\n if not(vars[n].has_key('attrspec') and 'external' in vars[n]['attrspec']):\n if implicitrules:\n ln0 = string.lower(n[0])\n for k in implicitrules[ln0].keys():\n if k=='typespec' and implicitrules[ln0][k]=='undefined':\n continue\n if not vars[n].has_key(k):\n vars[n][k]=implicitrules[ln0][k]\n elif k=='attrspec':\n for l in implicitrules[ln0][k]:\n vars[n]=setattrspec(vars[n],l)\n elif n in block['args']:\n outmess('analyzevars: typespec of variable %s is not defined in routine %s.\\n'%(`n`,block['name']))\n\n if vars[n].has_key('charselector'):\n if vars[n]['charselector'].has_key('len'):\n l = vars[n]['charselector']['len']\n try:\n l = str(eval(l,{},params))\n except:\n pass\n vars[n]['charselector']['len'] = l\n\n if vars[n].has_key('kindselector'):\n if vars[n]['kindselector'].has_key('kind'):\n l = vars[n]['kindselector']['kind']\n try:\n l = str(eval(l,{},params))\n except:\n pass\n vars[n]['kindselector']['kind'] = l\n\n savelindims = {}\n if vars[n].has_key('attrspec'):\n attr=vars[n]['attrspec']\n attr.reverse()\n vars[n]['attrspec']=[]\n dim,intent,depend,check,note=None,None,None,None,None\n for a in attr:\n if a[:9]=='dimension': dim=(string.strip(a[9:]))[1:-1]\n elif a[:6]=='intent': intent=(string.strip(a[6:]))[1:-1]\n elif a[:6]=='depend': depend=(string.strip(a[6:]))[1:-1]\n elif a[:5]=='check': check=(string.strip(a[5:]))[1:-1]\n elif a[:4]=='note': note=(string.strip(a[4:]))[1:-1]\n else: vars[n]=setattrspec(vars[n],a)\n if intent:\n if not vars[n].has_key('intent'): vars[n]['intent']=[]\n for c in map(string.strip,string.split(markoutercomma(intent),'@,@')):\n if not c in vars[n]['intent']:\n vars[n]['intent'].append(c)\n intent=None\n if note:\n note=string.replace(note,'\\\\n\\\\n','\\n\\n')\n note=string.replace(note,'\\\\n ','\\n')\n if not vars[n].has_key('note'): vars[n]['note']=[note]\n else: vars[n]['note'].append(note)\n note=None\n if depend is not None:\n if not vars[n].has_key('depend'): vars[n]['depend']=[]\n for c in rmbadname(map(string.strip,string.split(markoutercomma(depend),'@,@'))):\n if c not in vars[n]['depend']:\n vars[n]['depend'].append(c)\n depend=None\n if check is not None:\n if not vars[n].has_key('check'): vars[n]['check']=[]\n for c in map(string.strip,string.split(markoutercomma(check),'@,@')):\n if not c in vars[n]['check']:\n vars[n]['check'].append(c)\n check=None\n if dim and not vars[n].has_key('dimension'):\n vars[n]['dimension']=[]\n for d in rmbadname(map(string.strip,string.split(markoutercomma(dim),'@,@'))):\n star = '*'\n if d==':': star=':'\n if params.has_key(d):\n d = str(params[d])\n for p in params.keys():\n m = re.match(r'(?P.*?)\\b'+p+r'\\b(?P.*)',d,re.I)\n if m:\n #outmess('analyzevars:replacing parameter %s in %s (dimension of %s) with %s\\n'%(`p`,`d`,`n`,`params[p]`))\n d = m.group('before')+str(params[p])+m.group('after')\n if d==star:\n dl = [star]\n else:\n dl=string.split(markoutercomma(d,':'),'@:@')\n if len(dl)==2 and '*' in dl: # e.g. dimension(5:*)\n dl = ['*']\n d = '*'\n if len(dl)==1 and not dl[0]==star: dl = ['1',dl[0]]\n if len(dl)==2:\n d,v,di = getarrlen(dl,block['vars'].keys())\n if d[:4] == '1 * ': d = d[4:]\n if di and di[-4:] == '/(1)': di = di[:-4]\n if v: savelindims[d] = v,di\n vars[n]['dimension'].append(d)\n if vars[n].has_key('dimension'):\n if isintent_c(vars[n]):\n shape_macro = 'shape'\n else:\n shape_macro = 'shape'#'fshape'\n if isstringarray(vars[n]):\n if vars[n].has_key('charselector'):\n d = vars[n]['charselector']\n if d.has_key('*'):\n d = d['*']\n errmess('analyzevars: character array \"character*%s %s(%s)\" is considered as \"character %s(%s)\"; \"intent(c)\" is forced.\\n'\\\n %(d,n,\n ','.join(vars[n]['dimension']),\n n,','.join(vars[n]['dimension']+[d])))\n vars[n]['dimension'].append(d)\n del vars[n]['charselector']\n if not vars[n].has_key('intent'):\n vars[n]['intent'] = []\n if 'c' not in vars[n]['intent']:\n vars[n]['intent'].append('c')\n else:\n errmess(\"analyzevars: charselector=%r unhandled.\" % (d))\n if not vars[n].has_key('check') and block.has_key('args') and n in block['args']:\n flag=not vars[n].has_key('depend')\n if flag: vars[n]['depend']=[]\n vars[n]['check']=[]\n if vars[n].has_key('dimension'):\n #/----< no check\n #vars[n]['check'].append('rank(%s)==%s'%(n,len(vars[n]['dimension'])))\n i=-1; ni=len(vars[n]['dimension'])\n for d in vars[n]['dimension']:\n ddeps=[] # dependecies of 'd'\n ad=''\n pd=''\n #origd = d\n if not vars.has_key(d):\n if savelindims.has_key(d):\n pd,ad='(',savelindims[d][1]\n d = savelindims[d][0]\n else:\n for r in block['args']:\n #for r in block['vars'].keys():\n if not vars.has_key(r): continue\n if re.match(r'.*?\\b'+r+r'\\b',d,re.I):\n ddeps.append(r)\n if vars.has_key(d):\n if vars[d].has_key('attrspec'):\n for aa in vars[d]['attrspec']:\n if aa[:6]=='depend':\n ddeps=ddeps+string.split((string.strip(aa[6:]))[1:-1],',')\n if vars[d].has_key('depend'):\n ddeps=ddeps+vars[d]['depend']\n i=i+1\n if vars.has_key(d) and (not vars[d].has_key('depend')) \\\n and (not vars[d].has_key('=')) and (d not in vars[n]['depend']) \\\n and l_or(isintent_in,isintent_inout,isintent_inplace)(vars[n]):\n vars[d]['depend']=[n]\n if ni>1:\n vars[d]['=']='%s%s(%s,%s)%s'% (pd,shape_macro,n,i,ad)\n else:\n vars[d]['=']='%slen(%s)%s'% (pd,n,ad)\n # /---< no check\n if 1 and not vars[d].has_key('check'):\n if ni>1:\n vars[d]['check']=['%s%s(%s,%i)%s==%s'\\\n %(pd,shape_macro,n,i,ad,d)]\n else:\n vars[d]['check']=['%slen(%s)%s>=%s'%(pd,n,ad,d)]\n if not vars[d].has_key('attrspec'): vars[d]['attrspec']=['optional']\n if ('optional' not in vars[d]['attrspec']) and\\\n ('required' not in vars[d]['attrspec']):\n vars[d]['attrspec'].append('optional')\n elif d not in ['*',':']:\n #/----< no check\n #if ni>1: vars[n]['check'].append('shape(%s,%i)==%s'%(n,i,d))\n #else: vars[n]['check'].append('len(%s)>=%s'%(n,d))\n if flag:\n if vars.has_key(d):\n if n not in ddeps:\n vars[n]['depend'].append(d)\n else:\n vars[n]['depend'] = vars[n]['depend'] + ddeps\n elif isstring(vars[n]):\n length='1'\n if vars[n].has_key('charselector'):\n if vars[n]['charselector'].has_key('*'):\n length = _eval_length(vars[n]['charselector']['*'],\n params)\n vars[n]['charselector']['*']=length\n elif vars[n]['charselector'].has_key('len'):\n length = _eval_length(vars[n]['charselector']['len'],\n params)\n del vars[n]['charselector']['len']\n vars[n]['charselector']['*']=length\n\n if not vars[n]['check']: del vars[n]['check']\n if flag and not vars[n]['depend']: del vars[n]['depend']\n if vars[n].has_key('='):\n if not vars[n].has_key('attrspec'): vars[n]['attrspec']=[]\n if ('optional' not in vars[n]['attrspec']) and \\\n ('required' not in vars[n]['attrspec']):\n vars[n]['attrspec'].append('optional')\n if not vars[n].has_key('depend'):\n vars[n]['depend']=[]\n for v,m in dep_matches.items():\n if m(vars[n]['=']): vars[n]['depend'].append(v)\n if not vars[n]['depend']: del vars[n]['depend']\n if isscalar(vars[n]):\n vars[n]['='] = _eval_scalar(vars[n]['='],params)\n\n for n in vars.keys():\n if n==block['name']: # n is block name\n if vars[n].has_key('note'):\n block['note']=vars[n]['note']\n if block['block']=='function':\n if block.has_key('result') and vars.has_key(block['result']):\n vars[n]=appenddecl(vars[n],vars[block['result']])\n if block.has_key('prefix'):\n pr=block['prefix']; ispure=0; isrec=1\n pr1=string.replace(pr,'pure','')\n ispure=(not pr==pr1)\n pr=string.replace(pr1,'recursive','')\n isrec=(not pr==pr1)\n m=typespattern[0].match(pr)\n if m:\n typespec,selector,attr,edecl=cracktypespec0(m.group('this'),m.group('after'))\n kindselect,charselect,typename=cracktypespec(typespec,selector)\n vars[n]['typespec']=typespec\n if kindselect:\n if kindselect.has_key('kind'):\n try:\n kindselect['kind'] = eval(kindselect['kind'],{},params)\n except:\n pass\n vars[n]['kindselector']=kindselect\n if charselect: vars[n]['charselector']=charselect\n if typename: vars[n]['typename']=typename\n if ispure: vars[n]=setattrspec(vars[n],'pure')\n if isrec: vars[n]=setattrspec(vars[n],'recursive')\n else:\n outmess('analyzevars: prefix (%s) were not used\\n'%`block['prefix']`)\n if not block['block'] in ['module','pythonmodule','python module','block data']:\n if block.has_key('commonvars'):\n neededvars=copy.copy(block['args']+block['commonvars'])\n else:\n neededvars=copy.copy(block['args'])\n for n in vars.keys():\n if l_or(isintent_callback,isintent_aux)(vars[n]):\n neededvars.append(n)\n if block.has_key('entry'):\n neededvars.extend(block['entry'].keys())\n for k in block['entry'].keys():\n for n in block['entry'][k]:\n if n not in neededvars:\n neededvars.append(n)\n if block['block']=='function':\n if block.has_key('result'):\n neededvars.append(block['result'])\n else:\n neededvars.append(block['name'])\n if block['block'] in ['subroutine','function']:\n name = block['name']\n if vars.has_key(name) and vars[name].has_key('intent'):\n block['intent'] = vars[name]['intent']\n if block['block'] == 'type':\n neededvars.extend(vars.keys())\n for n in vars.keys():\n if n not in neededvars:\n del vars[n]\n return vars\nanalyzeargs_re_1 = re.compile(r'\\A[a-z]+[\\w$]*\\Z',re.I)\ndef analyzeargs(block):\n setmesstext(block)\n implicitrules,attrrules=buildimplicitrules(block)\n if not block.has_key('args'): block['args']=[]\n args=[]\n re_1 = analyzeargs_re_1\n for a in block['args']:\n if not re_1.match(a): # `a` is an expression\n at=determineexprtype(a,block['vars'],implicitrules)\n na='e_'\n for c in a:\n if c not in string.lowercase+string.digits: c='_'\n na=na+c\n if na[-1]=='_': na=na+'e'\n else: na=na+'_e'\n a=na\n while block['vars'].has_key(a) or a in block['args']: a=a+'r'\n block['vars'][a]=at\n args.append(a)\n if not block['vars'].has_key(a):\n block['vars'][a]={}\n if block.has_key('externals') and a in block['externals']+block['interfaced']:\n block['vars'][a]=setattrspec(block['vars'][a],'external')\n block['args']=args\n\n if block.has_key('entry'):\n for k,args1 in block['entry'].items():\n for a in args1:\n if not block['vars'].has_key(a):\n block['vars'][a]={}\n\n for b in block['body']:\n if b['name'] in args:\n if not block.has_key('externals'): block['externals']=[]\n if b['name'] not in block['externals']:\n block['externals'].append(b['name'])\n if block.has_key('result') and not block['vars'].has_key(block['result']):\n block['vars'][block['result']]={}\n return block\ndetermineexprtype_re_1 = re.compile(r'\\A\\(.+?[,].+?\\)\\Z',re.I)\ndetermineexprtype_re_2 = re.compile(r'\\A[+-]?\\d+(_(P[\\w]+)|)\\Z',re.I)\ndetermineexprtype_re_3 = re.compile(r'\\A[+-]?[\\d.]+[\\d+-de.]*(_(P[\\w]+)|)\\Z',re.I)\ndetermineexprtype_re_4 = re.compile(r'\\A\\(.*\\)\\Z',re.I)\ndetermineexprtype_re_5 = re.compile(r'\\A(?P\\w+)\\s*\\(.*?\\)\\s*\\Z',re.I)\ndef _ensure_exprdict(r):\n if type(r) is type(0):\n return {'typespec':'integer'}\n if type(r) is type(0.0):\n return {'typespec':'real'}\n if type(r) is type(0j):\n return {'typespec':'complex'}\n assert type(r) is type({}),`r`\n return r\n\ndef determineexprtype(expr,vars,rules={}):\n if vars.has_key(expr):\n return _ensure_exprdict(vars[expr])\n expr=string.strip(expr)\n if determineexprtype_re_1.match(expr):\n return {'typespec':'complex'}\n m=determineexprtype_re_2.match(expr)\n if m:\n if m.groupdict().has_key('name') and m.group('name'):\n outmess('determineexprtype: selected kind types not supported (%s)\\n'%`expr`)\n return {'typespec':'integer'}\n m = determineexprtype_re_3.match(expr)\n if m:\n if m.groupdict().has_key('name') and m.group('name'):\n outmess('determineexprtype: selected kind types not supported (%s)\\n'%`expr`)\n return {'typespec':'real'}\n for op in ['+','-','*','/']:\n for e in map(string.strip,string.split(markoutercomma(expr,comma=op),'@'+op+'@')):\n if vars.has_key(e):\n return _ensure_exprdict(vars[e])\n t={}\n if determineexprtype_re_4.match(expr): # in parenthesis\n t=determineexprtype(expr[1:-1],vars,rules)\n else:\n m = determineexprtype_re_5.match(expr)\n if m:\n rn=m.group('name')\n t=determineexprtype(m.group('name'),vars,rules)\n if t and t.has_key('attrspec'): del t['attrspec']\n if not t:\n if rules.has_key(rn[0]):\n return _ensure_exprdict(rules[rn[0]])\n if expr[0] in '\\'\"':\n return {'typespec':'character','charselector':{'*':'*'}}\n if not t:\n outmess('determineexprtype: could not determine expressions (%s) type.\\n'%(`expr`))\n return t\n######\ndef crack2fortrangen(block,tab='\\n'):\n setmesstext(block)\n ret=''\n if type(block) is type([]):\n for g in block:\n ret=ret+crack2fortrangen(g,tab)\n return ret\n prefix=''\n name=''\n args=''\n blocktype=block['block']\n if blocktype=='program': return ''\n al=[]\n if block.has_key('name'): name=block['name']\n if block.has_key('args'):\n vars = block['vars']\n al = [a for a in block['args'] if not isintent_callback(vars[a])]\n if block['block']=='function' or al:\n args='(%s)'%string.join(al,',')\n f2pyenhancements = ''\n if block.has_key('f2pyenhancements'):\n for k in block['f2pyenhancements'].keys():\n f2pyenhancements = '%s%s%s %s'%(f2pyenhancements,tab+tabchar,k,block['f2pyenhancements'][k])\n intent_lst = block.get('intent',[])[:]\n if blocktype=='function' and 'callback' in intent_lst:\n intent_lst.remove('callback')\n if intent_lst:\n f2pyenhancements = '%s%sintent(%s) %s'%\\\n (f2pyenhancements,tab+tabchar,\n string.join(intent_lst,','),name)\n use=''\n if block.has_key('use'):\n use=use2fortran(block['use'],tab+tabchar)\n common=''\n if block.has_key('common'):\n common=common2fortran(block['common'],tab+tabchar)\n if name=='unknown_interface': name=''\n result=''\n if block.has_key('result'):\n result=' result (%s)'%block['result']\n if block['result'] not in al:\n al.append(block['result'])\n #if block.has_key('prefix'): prefix=block['prefix']+' '\n body=crack2fortrangen(block['body'],tab+tabchar)\n vars=vars2fortran(block,block['vars'],al,tab+tabchar)\n mess=''\n if block.has_key('from'):\n mess='! in %s'%block['from']\n if block.has_key('entry'):\n entry_stmts = ''\n for k,i in block['entry'].items():\n entry_stmts = '%s%sentry %s(%s)' \\\n % (entry_stmts,tab+tabchar,k,string.join(i,','))\n body = body + entry_stmts\n if blocktype=='block data' and name=='_BLOCK_DATA_':\n name = ''\n ret='%s%s%s %s%s%s %s%s%s%s%s%s%send %s %s'%(tab,prefix,blocktype,name,args,result,mess,f2pyenhancements,use,vars,common,body,tab,blocktype,name)\n return ret\ndef common2fortran(common,tab=''):\n ret=''\n for k in common.keys():\n if k=='_BLNK_':\n ret='%s%scommon %s'%(ret,tab,string.join(common[k],','))\n else:\n ret='%s%scommon /%s/ %s'%(ret,tab,k,string.join(common[k],','))\n return ret\ndef use2fortran(use,tab=''):\n ret=''\n for m in use.keys():\n ret='%s%suse %s,'%(ret,tab,m)\n if use[m]=={}:\n if ret and ret[-1]==',': ret=ret[:-1]\n continue\n if use[m].has_key('only') and use[m]['only']:\n ret='%s,only:'%(ret)\n if use[m].has_key('map') and use[m]['map']:\n c=' '\n for k in use[m]['map'].keys():\n if k==use[m]['map'][k]:\n ret='%s%s%s'%(ret,c,k); c=','\n else:\n ret='%s%s%s=>%s'%(ret,c,k,use[m]['map'][k]); c=','\n if ret and ret[-1]==',': ret=ret[:-1]\n return ret\ndef true_intent_list(var):\n lst = var['intent']\n ret = []\n for intent in lst:\n try:\n exec('c = isintent_%s(var)' % intent)\n except NameError:\n c = 0\n if c:\n ret.append(intent)\n return ret\ndef vars2fortran(block,vars,args,tab=''):\n \"\"\"\n TODO:\n public sub\n ...\n \"\"\"\n setmesstext(block)\n ret=''\n nout=[]\n for a in args:\n if block['vars'].has_key(a): nout.append(a)\n if block.has_key('commonvars'):\n for a in block['commonvars']:\n if vars.has_key(a):\n if a not in nout: nout.append(a)\n else: errmess('vars2fortran: Confused?!: \"%s\" is not defined in vars.\\n'%a)\n if block.has_key('varnames'):\n nout.extend(block['varnames'])\n for a in vars.keys():\n if a not in nout: nout.append(a)\n for a in nout:\n if vars[a].has_key('depend'):\n for d in vars[a]['depend']:\n if vars.has_key(d) and vars[d].has_key('depend') and a in vars[d]['depend']:\n errmess('vars2fortran: Warning: cross-dependence between variables \"%s\" and \"%s\"\\n'%(a,d))\n if block.has_key('externals') and a in block['externals']:\n if isintent_callback(vars[a]):\n ret='%s%sintent(callback) %s'%(ret,tab,a)\n ret='%s%sexternal %s'%(ret,tab,a)\n if isoptional(vars[a]):\n ret='%s%soptional %s'%(ret,tab,a)\n if vars.has_key(a) and not vars[a].has_key('typespec'):\n continue\n cont=1\n for b in block['body']:\n if a==b['name'] and b['block']=='function': cont=0;break\n if cont: continue\n if not vars.has_key(a):\n show(vars)\n outmess('vars2fortran: No definition for argument \"%s\".\\n'%a)\n continue\n if a==block['name'] and not block['block']=='function':\n continue\n if not vars[a].has_key('typespec'):\n if vars[a].has_key('attrspec') and 'external' in vars[a]['attrspec']:\n if a in args:\n ret='%s%sexternal %s'%(ret,tab,a)\n continue\n show(vars[a])\n outmess('vars2fortran: No typespec for argument \"%s\".\\n'%a)\n continue\n vardef=vars[a]['typespec']\n if vardef=='type' and vars[a].has_key('typename'):\n vardef='%s(%s)'%(vardef,vars[a]['typename'])\n selector={}\n if vars[a].has_key('kindselector'): selector=vars[a]['kindselector']\n elif vars[a].has_key('charselector'): selector=vars[a]['charselector']\n if selector.has_key('*'):\n if selector['*'] in ['*',':']:\n vardef='%s*(%s)'%(vardef,selector['*'])\n else:\n vardef='%s*%s'%(vardef,selector['*'])\n else:\n if selector.has_key('len'):\n vardef='%s(len=%s'%(vardef,selector['len'])\n if selector.has_key('kind'):\n vardef='%s,kind=%s)'%(vardef,selector['kind'])\n else:\n vardef='%s)'%(vardef)\n elif selector.has_key('kind'):\n vardef='%s(kind=%s)'%(vardef,selector['kind'])\n c=' '\n if vars[a].has_key('attrspec'):\n attr=[]\n for l in vars[a]['attrspec']:\n if l not in ['external']:\n attr.append(l)\n if attr:\n vardef='%s %s'%(vardef,string.join(attr,','))\n c=','\n if vars[a].has_key('dimension'):\n# if not isintent_c(vars[a]):\n# vars[a]['dimension'].reverse()\n vardef='%s%sdimension(%s)'%(vardef,c,string.join(vars[a]['dimension'],','))\n c=','\n if vars[a].has_key('intent'):\n lst = true_intent_list(vars[a])\n if lst:\n vardef='%s%sintent(%s)'%(vardef,c,string.join(lst,','))\n c=','\n if vars[a].has_key('check'):\n vardef='%s%scheck(%s)'%(vardef,c,string.join(vars[a]['check'],','))\n c=','\n if vars[a].has_key('depend'):\n vardef='%s%sdepend(%s)'%(vardef,c,string.join(vars[a]['depend'],','))\n c=','\n if vars[a].has_key('='):\n v = vars[a]['=']\n if vars[a]['typespec'] in ['complex','double complex']:\n try:\n v = eval(v)\n v = '(%s,%s)' % (v.real,v.imag)\n except:\n pass\n vardef='%s :: %s=%s'%(vardef,a,v)\n else:\n vardef='%s :: %s'%(vardef,a)\n ret='%s%s%s'%(ret,tab,vardef)\n return ret\n######\n\ndef crackfortran(files):\n global usermodules\n outmess('Reading fortran codes...\\n',0)\n readfortrancode(files,crackline)\n outmess('Post-processing...\\n',0)\n usermodules=[]\n postlist=postcrack(grouplist[0])\n outmess('Post-processing (stage 2)...\\n',0)\n postlist=postcrack2(postlist)\n return usermodules+postlist\ndef crack2fortran(block):\n global f2py_version\n pyf=crack2fortrangen(block)+'\\n'\n header=\"\"\"! -*- f90 -*-\n! Note: the context of this file is case sensitive.\n\"\"\"\n footer=\"\"\"\n! This file was auto-generated with f2py (version:%s).\n! See http://cens.ioc.ee/projects/f2py2e/\n\"\"\"%(f2py_version)\n return header+pyf+footer\n\nif __name__ == \"__main__\":\n files=[]\n funcs=[]\n f=1;f2=0;f3=0\n showblocklist=0\n for l in sys.argv[1:]:\n if l=='': pass\n elif l[0]==':':\n f=0\n elif l=='-quiet':\n quiet=1\n verbose=0\n elif l=='-verbose':\n verbose=2\n quiet=0\n elif l=='-fix':\n if strictf77:\n outmess('Use option -f90 before -fix if Fortran 90 code is in fix form.\\n',0)\n skipemptyends=1\n sourcecodeform='fix'\n elif l=='-skipemptyends':\n skipemptyends=1\n elif l=='--ignore-contains':\n ignorecontains=1\n elif l=='-f77':\n strictf77=1\n sourcecodeform='fix'\n elif l=='-f90':\n strictf77=0\n sourcecodeform='free'\n skipemptyends=1\n elif l=='-h':\n f2=1\n elif l=='-show':\n showblocklist=1\n elif l=='-m':\n f3=1\n elif l[0]=='-':\n errmess('Unknown option %s\\n'%`l`)\n elif f2:\n f2=0\n pyffilename=l\n elif f3:\n f3=0\n f77modulename=l\n elif f:\n try:\n open(l).close()\n files.append(l)\n except IOError,detail:\n errmess('IOError: %s\\n'%str(detail))\n else:\n funcs.append(l)\n if not strictf77 and f77modulename and not skipemptyends:\n outmess(\"\"\"\\\n Warning: You have specifyied module name for non Fortran 77 code\n that should not need one (expect if you are scanning F90 code\n for non module blocks but then you should use flag -skipemptyends\n and also be sure that the files do not contain programs without program statement).\n\"\"\",0)\n\n postlist=crackfortran(files,funcs)\n if pyffilename:\n outmess('Writing fortran code to file %s\\n'%`pyffilename`,0)\n pyf=crack2fortran(postlist)\n f=open(pyffilename,'w')\n f.write(pyf)\n f.close()\n if showblocklist:\n show(postlist)\n", + "methods": [ + { + "name": "outmess", + "long_name": "outmess( line , flag = 1 )", + "filename": "crackfortran.py", + "nloc": 6, + "complexity": 4, + "token_count": 39, + "parameters": [ + "line", + "flag" + ], + "start_line": 186, + "end_line": 191, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "rmbadname1", + "long_name": "rmbadname1( name )", + "filename": "crackfortran.py", + "nloc": 5, + "complexity": 2, + "token_count": 33, + "parameters": [ + "name" + ], + "start_line": 209, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "undo_rmbadname1", + "long_name": "undo_rmbadname1( name )", + "filename": "crackfortran.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "name" + ], + "start_line": 216, + "end_line": 221, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "getextension", + "long_name": "getextension( name )", + "filename": "crackfortran.py", + "nloc": 6, + "complexity": 4, + "token_count": 53, + "parameters": [ + "name" + ], + "start_line": 224, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_free_format", + "long_name": "is_free_format( file )", + "filename": "crackfortran.py", + "nloc": 19, + "complexity": 9, + "token_count": 114, + "parameters": [ + "file" + ], + "start_line": 236, + "end_line": 257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "readfortrancode", + "long_name": "readfortrancode( ffile , dowithline = show , istop = 1 )", + "filename": "crackfortran.py", + "nloc": 164, + "complexity": 57, + "token_count": 1156, + "parameters": [ + "ffile", + "dowithline", + "istop" + ], + "start_line": 261, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 175, + "top_nesting_level": 0 + }, + { + "name": "_simplifyargs", + "long_name": "_simplifyargs( argsline )", + "filename": "crackfortran.py", + "nloc": 7, + "complexity": 3, + "token_count": 56, + "parameters": [ + "argsline" + ], + "start_line": 483, + "end_line": 489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "crackline", + "long_name": "crackline( line , reset = 0 )", + "filename": "crackfortran.py", + "nloc": 121, + "complexity": 41, + "token_count": 874, + "parameters": [ + "line", + "reset" + ], + "start_line": 492, + "end_line": 619, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 128, + "top_nesting_level": 0 + }, + { + "name": "markouterparen", + "long_name": "markouterparen( line )", + "filename": "crackfortran.py", + "nloc": 11, + "complexity": 6, + "token_count": 68, + "parameters": [ + "line" + ], + "start_line": 621, + "end_line": 631, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "markoutercomma", + "long_name": "markoutercomma( line , comma = ',' )", + "filename": "crackfortran.py", + "nloc": 20, + "complexity": 13, + "token_count": 132, + "parameters": [ + "line", + "comma" + ], + "start_line": 632, + "end_line": 651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "unmarkouterparen", + "long_name": "unmarkouterparen( line )", + "filename": "crackfortran.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "line" + ], + "start_line": 652, + "end_line": 654, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "appenddecl", + "long_name": "appenddecl( decl , decl2 , force = 1 )", + "filename": "crackfortran.py", + "nloc": 23, + "complexity": 17, + "token_count": 189, + "parameters": [ + "decl", + "decl2", + "force" + ], + "start_line": 655, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_is_intent_callback", + "long_name": "_is_intent_callback( vdecl )", + "filename": "crackfortran.py", + "nloc": 5, + "complexity": 3, + "token_count": 30, + "parameters": [ + "vdecl" + ], + "start_line": 686, + "end_line": 690, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_resolvenameargspattern", + "long_name": "_resolvenameargspattern( line )", + "filename": "crackfortran.py", + "nloc": 7, + "complexity": 3, + "token_count": 77, + "parameters": [ + "line" + ], + "start_line": 692, + "end_line": 698, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "analyzeline", + "long_name": "analyzeline( m , case , line )", + "filename": "crackfortran.py", + "nloc": 416, + "complexity": 162, + "token_count": 4017, + "parameters": [ + "m", + "case", + "line" + ], + "start_line": 700, + "end_line": 1135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 436, + "top_nesting_level": 0 + }, + { + "name": "appendmultiline", + "long_name": "appendmultiline( group , context_name , ml )", + "filename": "crackfortran.py", + "nloc": 8, + "complexity": 3, + "token_count": 57, + "parameters": [ + "group", + "context_name", + "ml" + ], + "start_line": 1137, + "end_line": 1144, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "cracktypespec0", + "long_name": "cracktypespec0( typespec , ll )", + "filename": "crackfortran.py", + "nloc": 20, + "complexity": 7, + "token_count": 185, + "parameters": [ + "typespec", + "ll" + ], + "start_line": 1146, + "end_line": 1165, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "removespaces", + "long_name": "removespaces( expr )", + "filename": "crackfortran.py", + "nloc": 10, + "complexity": 6, + "token_count": 97, + "parameters": [ + "expr" + ], + "start_line": 1172, + "end_line": 1181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "markinnerspaces", + "long_name": "markinnerspaces( line )", + "filename": "crackfortran.py", + "nloc": 16, + "complexity": 10, + "token_count": 129, + "parameters": [ + "line" + ], + "start_line": 1182, + "end_line": 1197, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "updatevars", + "long_name": "updatevars( typespec , selector , attrspec , entitydecl )", + "filename": "crackfortran.py", + "nloc": 120, + "complexity": 61, + "token_count": 1215, + "parameters": [ + "typespec", + "selector", + "attrspec", + "entitydecl" + ], + "start_line": 1198, + "end_line": 1318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 121, + "top_nesting_level": 0 + }, + { + "name": "cracktypespec", + "long_name": "cracktypespec( typespec , selector )", + "filename": "crackfortran.py", + "nloc": 45, + "complexity": 17, + "token_count": 346, + "parameters": [ + "typespec", + "selector" + ], + "start_line": 1320, + "end_line": 1364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "setattrspec", + "long_name": "setattrspec( decl , attr , force = 0 )", + "filename": "crackfortran.py", + "nloc": 19, + "complexity": 14, + "token_count": 167, + "parameters": [ + "decl", + "attr", + "force" + ], + "start_line": 1366, + "end_line": 1384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "setkindselector", + "long_name": "setkindselector( decl , sel , force = 0 )", + "filename": "crackfortran.py", + "nloc": 10, + "complexity": 7, + "token_count": 79, + "parameters": [ + "decl", + "sel", + "force" + ], + "start_line": 1385, + "end_line": 1394, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "setcharselector", + "long_name": "setcharselector( decl , sel , force = 0 )", + "filename": "crackfortran.py", + "nloc": 10, + "complexity": 7, + "token_count": 79, + "parameters": [ + "decl", + "sel", + "force" + ], + "start_line": 1395, + "end_line": 1404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "getblockname", + "long_name": "getblockname( block , unknown = 'unknown' )", + "filename": "crackfortran.py", + "nloc": 3, + "complexity": 2, + "token_count": 24, + "parameters": [ + "block", + "unknown" + ], + "start_line": 1405, + "end_line": 1407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "setmesstext", + "long_name": "setmesstext( block )", + "filename": "crackfortran.py", + "nloc": 4, + "complexity": 2, + "token_count": 27, + "parameters": [ + "block" + ], + "start_line": 1409, + "end_line": 1412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_usedict", + "long_name": "get_usedict( block )", + "filename": "crackfortran.py", + "nloc": 7, + "complexity": 3, + "token_count": 45, + "parameters": [ + "block" + ], + "start_line": 1414, + "end_line": 1420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "get_useparameters", + "long_name": "get_useparameters( block , param_map = None )", + "filename": "crackfortran.py", + "nloc": 23, + "complexity": 9, + "token_count": 132, + "parameters": [ + "block", + "param_map" + ], + "start_line": 1422, + "end_line": 1445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "postcrack2", + "long_name": "postcrack2( block , tab = '' , param_map = None )", + "filename": "crackfortran.py", + "nloc": 30, + "complexity": 12, + "token_count": 215, + "parameters": [ + "block", + "tab", + "param_map" + ], + "start_line": 1447, + "end_line": 1479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "postcrack", + "long_name": "postcrack( block , args = None , tab = '' )", + "filename": "crackfortran.py", + "nloc": 76, + "complexity": 35, + "token_count": 639, + "parameters": [ + "block", + "args", + "tab" + ], + "start_line": 1481, + "end_line": 1569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "sortvarnames", + "long_name": "sortvarnames( vars )", + "filename": "crackfortran.py", + "nloc": 31, + "complexity": 9, + "token_count": 172, + "parameters": [ + "vars" + ], + "start_line": 1571, + "end_line": 1603, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "analyzecommon", + "long_name": "analyzecommon( block )", + "filename": "crackfortran.py", + "nloc": 32, + "complexity": 11, + "token_count": 306, + "parameters": [ + "block" + ], + "start_line": 1605, + "end_line": 1636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "analyzebody", + "long_name": "analyzebody( block , args , tab = '' )", + "filename": "crackfortran.py", + "nloc": 27, + "complexity": 13, + "token_count": 193, + "parameters": [ + "block", + "args", + "tab" + ], + "start_line": 1637, + "end_line": 1663, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "buildimplicitrules", + "long_name": "buildimplicitrules( block )", + "filename": "crackfortran.py", + "nloc": 16, + "complexity": 6, + "token_count": 119, + "parameters": [ + "block" + ], + "start_line": 1664, + "end_line": 1679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "myeval", + "long_name": "myeval( e , g = None , l = None )", + "filename": "crackfortran.py", + "nloc": 5, + "complexity": 2, + "token_count": 53, + "parameters": [ + "e", + "g", + "l" + ], + "start_line": 1681, + "end_line": 1685, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "getlincoef", + "long_name": "getlincoef( e , xset )", + "filename": "crackfortran.py", + "nloc": 34, + "complexity": 11, + "token_count": 287, + "parameters": [ + "e", + "xset" + ], + "start_line": 1688, + "end_line": 1721, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "getarrlen", + "long_name": "getarrlen( dl , args , star = '*' )", + "filename": "crackfortran.py", + "nloc": 95, + "complexity": 55, + "token_count": 1295, + "parameters": [ + "dl", + "args", + "star" + ], + "start_line": 1724, + "end_line": 1823, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 100, + "top_nesting_level": 0 + }, + { + "name": "_get_depend_dict", + "long_name": "_get_depend_dict( name , vars , deps )", + "filename": "crackfortran.py", + "nloc": 17, + "complexity": 11, + "token_count": 153, + "parameters": [ + "name", + "vars", + "deps" + ], + "start_line": 1827, + "end_line": 1844, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_calc_depend_dict", + "long_name": "_calc_depend_dict( vars )", + "filename": "crackfortran.py", + "nloc": 6, + "complexity": 2, + "token_count": 31, + "parameters": [ + "vars" + ], + "start_line": 1846, + "end_line": 1851, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "get_sorted_names", + "long_name": "get_sorted_names( vars )", + "filename": "crackfortran.py", + "nloc": 16, + "complexity": 10, + "token_count": 111, + "parameters": [ + "vars" + ], + "start_line": 1853, + "end_line": 1870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_kind_func", + "long_name": "_kind_func( string )", + "filename": "crackfortran.py", + "nloc": 8, + "complexity": 4, + "token_count": 48, + "parameters": [ + "string" + ], + "start_line": 1872, + "end_line": 1880, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "_selected_int_kind_func", + "long_name": "_selected_int_kind_func( r )", + "filename": "crackfortran.py", + "nloc": 8, + "complexity": 6, + "token_count": 58, + "parameters": [ + "r" + ], + "start_line": 1882, + "end_line": 1890, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "get_parameters", + "long_name": "get_parameters( vars , global_params = { } )", + "filename": "crackfortran.py", + "nloc": 52, + "complexity": 21, + "token_count": 482, + "parameters": [ + "vars", + "global_params" + ], + "start_line": 1892, + "end_line": 1945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "_eval_length", + "long_name": "_eval_length( length , params )", + "filename": "crackfortran.py", + "nloc": 4, + "complexity": 2, + "token_count": 27, + "parameters": [ + "length", + "params" + ], + "start_line": 1947, + "end_line": 1950, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_eval_scalar", + "long_name": "_eval_scalar( value , params )", + "filename": "crackfortran.py", + "nloc": 12, + "complexity": 4, + "token_count": 75, + "parameters": [ + "value", + "params" + ], + "start_line": 1954, + "end_line": 1965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "analyzevars", + "long_name": "analyzevars( block )", + "filename": "crackfortran.py", + "nloc": 291, + "complexity": 158, + "token_count": 3132, + "parameters": [ + "block" + ], + "start_line": 1967, + "end_line": 2273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 307, + "top_nesting_level": 0 + }, + { + "name": "analyzeargs", + "long_name": "analyzeargs( block )", + "filename": "crackfortran.py", + "nloc": 37, + "complexity": 22, + "token_count": 370, + "parameters": [ + "block" + ], + "start_line": 2275, + "end_line": 2313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "_ensure_exprdict", + "long_name": "_ensure_exprdict( r )", + "filename": "crackfortran.py", + "nloc": 9, + "complexity": 4, + "token_count": 75, + "parameters": [ + "r" + ], + "start_line": 2319, + "end_line": 2327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "determineexprtype", + "long_name": "determineexprtype( expr , vars , rules = { } )", + "filename": "crackfortran.py", + "nloc": 37, + "complexity": 20, + "token_count": 340, + "parameters": [ + "expr", + "vars", + "rules" + ], + "start_line": 2329, + "end_line": 2365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "crack2fortrangen", + "long_name": "crack2fortrangen( block , tab = '\\n' )", + "filename": "crackfortran.py", + "nloc": 63, + "complexity": 29, + "token_count": 522, + "parameters": [ + "block", + "tab" + ], + "start_line": 2367, + "end_line": 2430, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "common2fortran", + "long_name": "common2fortran( common , tab = '' )", + "filename": "crackfortran.py", + "nloc": 8, + "complexity": 3, + "token_count": 74, + "parameters": [ + "common", + "tab" + ], + "start_line": 2431, + "end_line": 2438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "use2fortran", + "long_name": "use2fortran( use , tab = '' )", + "filename": "crackfortran.py", + "nloc": 18, + "complexity": 13, + "token_count": 202, + "parameters": [ + "use", + "tab" + ], + "start_line": 2439, + "end_line": 2456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "true_intent_list", + "long_name": "true_intent_list( var )", + "filename": "crackfortran.py", + "nloc": 11, + "complexity": 4, + "token_count": 45, + "parameters": [ + "var" + ], + "start_line": 2457, + "end_line": 2467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "vars2fortran", + "long_name": "vars2fortran( block , vars , args , tab = '' )", + "filename": "crackfortran.py", + "nloc": 102, + "complexity": 54, + "token_count": 933, + "parameters": [ + "block", + "vars", + "args", + "tab" + ], + "start_line": 2468, + "end_line": 2576, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "crackfortran", + "long_name": "crackfortran( files )", + "filename": "crackfortran.py", + "nloc": 10, + "complexity": 1, + "token_count": 54, + "parameters": [ + "files" + ], + "start_line": 2579, + "end_line": 2588, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "crack2fortran", + "long_name": "crack2fortran( block )", + "filename": "crackfortran.py", + "nloc": 11, + "complexity": 1, + "token_count": 31, + "parameters": [ + "block" + ], + "start_line": 2589, + "end_line": 2599, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "outmess", + "long_name": "outmess( line , flag = 1 )", + "filename": "crackfortran.py", + "nloc": 6, + "complexity": 4, + "token_count": 39, + "parameters": [ + "line", + "flag" + ], + "start_line": 186, + "end_line": 191, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "rmbadname1", + "long_name": "rmbadname1( name )", + "filename": "crackfortran.py", + "nloc": 5, + "complexity": 2, + "token_count": 33, + "parameters": [ + "name" + ], + "start_line": 209, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "undo_rmbadname1", + "long_name": "undo_rmbadname1( name )", + "filename": "crackfortran.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "name" + ], + "start_line": 216, + "end_line": 221, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "getextension", + "long_name": "getextension( name )", + "filename": "crackfortran.py", + "nloc": 6, + "complexity": 4, + "token_count": 53, + "parameters": [ + "name" + ], + "start_line": 224, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "is_free_format", + "long_name": "is_free_format( file )", + "filename": "crackfortran.py", + "nloc": 19, + "complexity": 9, + "token_count": 114, + "parameters": [ + "file" + ], + "start_line": 236, + "end_line": 257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "readfortrancode", + "long_name": "readfortrancode( ffile , dowithline = show , istop = 1 )", + "filename": "crackfortran.py", + "nloc": 164, + "complexity": 57, + "token_count": 1156, + "parameters": [ + "ffile", + "dowithline", + "istop" + ], + "start_line": 261, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 175, + "top_nesting_level": 0 + }, + { + "name": "_simplifyargs", + "long_name": "_simplifyargs( argsline )", + "filename": "crackfortran.py", + "nloc": 7, + "complexity": 3, + "token_count": 56, + "parameters": [ + "argsline" + ], + "start_line": 483, + "end_line": 489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "crackline", + "long_name": "crackline( line , reset = 0 )", + "filename": "crackfortran.py", + "nloc": 121, + "complexity": 41, + "token_count": 874, + "parameters": [ + "line", + "reset" + ], + "start_line": 492, + "end_line": 619, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 128, + "top_nesting_level": 0 + }, + { + "name": "markouterparen", + "long_name": "markouterparen( line )", + "filename": "crackfortran.py", + "nloc": 11, + "complexity": 6, + "token_count": 68, + "parameters": [ + "line" + ], + "start_line": 621, + "end_line": 631, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "markoutercomma", + "long_name": "markoutercomma( line , comma = ',' )", + "filename": "crackfortran.py", + "nloc": 20, + "complexity": 13, + "token_count": 132, + "parameters": [ + "line", + "comma" + ], + "start_line": 632, + "end_line": 651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "unmarkouterparen", + "long_name": "unmarkouterparen( line )", + "filename": "crackfortran.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "line" + ], + "start_line": 652, + "end_line": 654, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "appenddecl", + "long_name": "appenddecl( decl , decl2 , force = 1 )", + "filename": "crackfortran.py", + "nloc": 23, + "complexity": 17, + "token_count": 189, + "parameters": [ + "decl", + "decl2", + "force" + ], + "start_line": 655, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_is_intent_callback", + "long_name": "_is_intent_callback( vdecl )", + "filename": "crackfortran.py", + "nloc": 5, + "complexity": 3, + "token_count": 30, + "parameters": [ + "vdecl" + ], + "start_line": 686, + "end_line": 690, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_resolvenameargspattern", + "long_name": "_resolvenameargspattern( line )", + "filename": "crackfortran.py", + "nloc": 7, + "complexity": 3, + "token_count": 77, + "parameters": [ + "line" + ], + "start_line": 692, + "end_line": 698, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "analyzeline", + "long_name": "analyzeline( m , case , line )", + "filename": "crackfortran.py", + "nloc": 416, + "complexity": 162, + "token_count": 4017, + "parameters": [ + "m", + "case", + "line" + ], + "start_line": 700, + "end_line": 1135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 436, + "top_nesting_level": 0 + }, + { + "name": "appendmultiline", + "long_name": "appendmultiline( group , context_name , ml )", + "filename": "crackfortran.py", + "nloc": 8, + "complexity": 3, + "token_count": 57, + "parameters": [ + "group", + "context_name", + "ml" + ], + "start_line": 1137, + "end_line": 1144, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "cracktypespec0", + "long_name": "cracktypespec0( typespec , ll )", + "filename": "crackfortran.py", + "nloc": 20, + "complexity": 7, + "token_count": 185, + "parameters": [ + "typespec", + "ll" + ], + "start_line": 1146, + "end_line": 1165, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "removespaces", + "long_name": "removespaces( expr )", + "filename": "crackfortran.py", + "nloc": 10, + "complexity": 6, + "token_count": 97, + "parameters": [ + "expr" + ], + "start_line": 1172, + "end_line": 1181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "markinnerspaces", + "long_name": "markinnerspaces( line )", + "filename": "crackfortran.py", + "nloc": 16, + "complexity": 10, + "token_count": 129, + "parameters": [ + "line" + ], + "start_line": 1182, + "end_line": 1197, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "updatevars", + "long_name": "updatevars( typespec , selector , attrspec , entitydecl )", + "filename": "crackfortran.py", + "nloc": 120, + "complexity": 61, + "token_count": 1215, + "parameters": [ + "typespec", + "selector", + "attrspec", + "entitydecl" + ], + "start_line": 1198, + "end_line": 1318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 121, + "top_nesting_level": 0 + }, + { + "name": "cracktypespec", + "long_name": "cracktypespec( typespec , selector )", + "filename": "crackfortran.py", + "nloc": 45, + "complexity": 17, + "token_count": 346, + "parameters": [ + "typespec", + "selector" + ], + "start_line": 1320, + "end_line": 1364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "setattrspec", + "long_name": "setattrspec( decl , attr , force = 0 )", + "filename": "crackfortran.py", + "nloc": 19, + "complexity": 14, + "token_count": 167, + "parameters": [ + "decl", + "attr", + "force" + ], + "start_line": 1366, + "end_line": 1384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "setkindselector", + "long_name": "setkindselector( decl , sel , force = 0 )", + "filename": "crackfortran.py", + "nloc": 10, + "complexity": 7, + "token_count": 79, + "parameters": [ + "decl", + "sel", + "force" + ], + "start_line": 1385, + "end_line": 1394, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "setcharselector", + "long_name": "setcharselector( decl , sel , force = 0 )", + "filename": "crackfortran.py", + "nloc": 10, + "complexity": 7, + "token_count": 79, + "parameters": [ + "decl", + "sel", + "force" + ], + "start_line": 1395, + "end_line": 1404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "getblockname", + "long_name": "getblockname( block , unknown = 'unknown' )", + "filename": "crackfortran.py", + "nloc": 3, + "complexity": 2, + "token_count": 24, + "parameters": [ + "block", + "unknown" + ], + "start_line": 1405, + "end_line": 1407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "setmesstext", + "long_name": "setmesstext( block )", + "filename": "crackfortran.py", + "nloc": 4, + "complexity": 2, + "token_count": 27, + "parameters": [ + "block" + ], + "start_line": 1409, + "end_line": 1412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "get_usedict", + "long_name": "get_usedict( block )", + "filename": "crackfortran.py", + "nloc": 7, + "complexity": 3, + "token_count": 45, + "parameters": [ + "block" + ], + "start_line": 1414, + "end_line": 1420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "get_useparameters", + "long_name": "get_useparameters( block , param_map = None )", + "filename": "crackfortran.py", + "nloc": 23, + "complexity": 9, + "token_count": 132, + "parameters": [ + "block", + "param_map" + ], + "start_line": 1422, + "end_line": 1445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "postcrack2", + "long_name": "postcrack2( block , tab = '' , param_map = None )", + "filename": "crackfortran.py", + "nloc": 30, + "complexity": 12, + "token_count": 215, + "parameters": [ + "block", + "tab", + "param_map" + ], + "start_line": 1447, + "end_line": 1479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "postcrack", + "long_name": "postcrack( block , args = None , tab = '' )", + "filename": "crackfortran.py", + "nloc": 76, + "complexity": 35, + "token_count": 639, + "parameters": [ + "block", + "args", + "tab" + ], + "start_line": 1481, + "end_line": 1569, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 0 + }, + { + "name": "sortvarnames", + "long_name": "sortvarnames( vars )", + "filename": "crackfortran.py", + "nloc": 31, + "complexity": 9, + "token_count": 172, + "parameters": [ + "vars" + ], + "start_line": 1571, + "end_line": 1603, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "analyzecommon", + "long_name": "analyzecommon( block )", + "filename": "crackfortran.py", + "nloc": 32, + "complexity": 11, + "token_count": 306, + "parameters": [ + "block" + ], + "start_line": 1605, + "end_line": 1636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "analyzebody", + "long_name": "analyzebody( block , args , tab = '' )", + "filename": "crackfortran.py", + "nloc": 27, + "complexity": 13, + "token_count": 193, + "parameters": [ + "block", + "args", + "tab" + ], + "start_line": 1637, + "end_line": 1663, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "buildimplicitrules", + "long_name": "buildimplicitrules( block )", + "filename": "crackfortran.py", + "nloc": 16, + "complexity": 6, + "token_count": 119, + "parameters": [ + "block" + ], + "start_line": 1664, + "end_line": 1679, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "myeval", + "long_name": "myeval( e , g = None , l = None )", + "filename": "crackfortran.py", + "nloc": 5, + "complexity": 2, + "token_count": 53, + "parameters": [ + "e", + "g", + "l" + ], + "start_line": 1681, + "end_line": 1685, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "getlincoef", + "long_name": "getlincoef( e , xset )", + "filename": "crackfortran.py", + "nloc": 34, + "complexity": 11, + "token_count": 287, + "parameters": [ + "e", + "xset" + ], + "start_line": 1688, + "end_line": 1721, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "getarrlen", + "long_name": "getarrlen( dl , args , star = '*' )", + "filename": "crackfortran.py", + "nloc": 95, + "complexity": 55, + "token_count": 1295, + "parameters": [ + "dl", + "args", + "star" + ], + "start_line": 1724, + "end_line": 1823, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 100, + "top_nesting_level": 0 + }, + { + "name": "_get_depend_dict", + "long_name": "_get_depend_dict( name , vars , deps )", + "filename": "crackfortran.py", + "nloc": 17, + "complexity": 11, + "token_count": 153, + "parameters": [ + "name", + "vars", + "deps" + ], + "start_line": 1827, + "end_line": 1844, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_calc_depend_dict", + "long_name": "_calc_depend_dict( vars )", + "filename": "crackfortran.py", + "nloc": 6, + "complexity": 2, + "token_count": 31, + "parameters": [ + "vars" + ], + "start_line": 1846, + "end_line": 1851, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "get_sorted_names", + "long_name": "get_sorted_names( vars )", + "filename": "crackfortran.py", + "nloc": 16, + "complexity": 10, + "token_count": 111, + "parameters": [ + "vars" + ], + "start_line": 1853, + "end_line": 1870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "_kind_func", + "long_name": "_kind_func( string )", + "filename": "crackfortran.py", + "nloc": 8, + "complexity": 4, + "token_count": 48, + "parameters": [ + "string" + ], + "start_line": 1872, + "end_line": 1880, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "_selected_int_kind_func", + "long_name": "_selected_int_kind_func( r )", + "filename": "crackfortran.py", + "nloc": 8, + "complexity": 6, + "token_count": 58, + "parameters": [ + "r" + ], + "start_line": 1882, + "end_line": 1890, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "get_parameters", + "long_name": "get_parameters( vars , global_params = { } )", + "filename": "crackfortran.py", + "nloc": 52, + "complexity": 21, + "token_count": 482, + "parameters": [ + "vars", + "global_params" + ], + "start_line": 1892, + "end_line": 1945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "_eval_length", + "long_name": "_eval_length( length , params )", + "filename": "crackfortran.py", + "nloc": 4, + "complexity": 2, + "token_count": 27, + "parameters": [ + "length", + "params" + ], + "start_line": 1947, + "end_line": 1950, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_eval_scalar", + "long_name": "_eval_scalar( value , params )", + "filename": "crackfortran.py", + "nloc": 12, + "complexity": 4, + "token_count": 75, + "parameters": [ + "value", + "params" + ], + "start_line": 1954, + "end_line": 1965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "analyzevars", + "long_name": "analyzevars( block )", + "filename": "crackfortran.py", + "nloc": 291, + "complexity": 158, + "token_count": 3132, + "parameters": [ + "block" + ], + "start_line": 1967, + "end_line": 2273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 307, + "top_nesting_level": 0 + }, + { + "name": "analyzeargs", + "long_name": "analyzeargs( block )", + "filename": "crackfortran.py", + "nloc": 37, + "complexity": 22, + "token_count": 370, + "parameters": [ + "block" + ], + "start_line": 2275, + "end_line": 2313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "_ensure_exprdict", + "long_name": "_ensure_exprdict( r )", + "filename": "crackfortran.py", + "nloc": 9, + "complexity": 4, + "token_count": 75, + "parameters": [ + "r" + ], + "start_line": 2319, + "end_line": 2327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "determineexprtype", + "long_name": "determineexprtype( expr , vars , rules = { } )", + "filename": "crackfortran.py", + "nloc": 37, + "complexity": 20, + "token_count": 340, + "parameters": [ + "expr", + "vars", + "rules" + ], + "start_line": 2329, + "end_line": 2365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "crack2fortrangen", + "long_name": "crack2fortrangen( block , tab = '\\n' )", + "filename": "crackfortran.py", + "nloc": 57, + "complexity": 25, + "token_count": 485, + "parameters": [ + "block", + "tab" + ], + "start_line": 2367, + "end_line": 2424, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "common2fortran", + "long_name": "common2fortran( common , tab = '' )", + "filename": "crackfortran.py", + "nloc": 8, + "complexity": 3, + "token_count": 74, + "parameters": [ + "common", + "tab" + ], + "start_line": 2425, + "end_line": 2432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "use2fortran", + "long_name": "use2fortran( use , tab = '' )", + "filename": "crackfortran.py", + "nloc": 18, + "complexity": 13, + "token_count": 202, + "parameters": [ + "use", + "tab" + ], + "start_line": 2433, + "end_line": 2450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "true_intent_list", + "long_name": "true_intent_list( var )", + "filename": "crackfortran.py", + "nloc": 11, + "complexity": 4, + "token_count": 45, + "parameters": [ + "var" + ], + "start_line": 2451, + "end_line": 2461, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "vars2fortran", + "long_name": "vars2fortran( block , vars , args , tab = '' )", + "filename": "crackfortran.py", + "nloc": 102, + "complexity": 54, + "token_count": 933, + "parameters": [ + "block", + "vars", + "args", + "tab" + ], + "start_line": 2462, + "end_line": 2570, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "crackfortran", + "long_name": "crackfortran( files )", + "filename": "crackfortran.py", + "nloc": 10, + "complexity": 1, + "token_count": 54, + "parameters": [ + "files" + ], + "start_line": 2573, + "end_line": 2582, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "crack2fortran", + "long_name": "crack2fortran( block )", + "filename": "crackfortran.py", + "nloc": 11, + "complexity": 1, + "token_count": 31, + "parameters": [ + "block" + ], + "start_line": 2583, + "end_line": 2593, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "crack2fortrangen", + "long_name": "crack2fortrangen( block , tab = '\\n' )", + "filename": "crackfortran.py", + "nloc": 63, + "complexity": 29, + "token_count": 522, + "parameters": [ + "block", + "tab" + ], + "start_line": 2367, + "end_line": 2430, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + } + ], + "nloc": 2502, + "complexity": 998, + "token_count": 21281, + "diff_parsed": { + "added": [ + " global skipfuncs, onlyfuncs", + " if g['block'] in ['function','subroutine']:", + " if g['name'] in skipfuncs:", + " continue", + " if onlyfuncs and g['name'] not in onlyfuncs:", + " continue" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "fe2076907f6245231857df946e08d656b7303236", + "msg": "Fix #90.", + "author": { + "name": "Robert Kern", + "email": "robert.kern@gmail.com" + }, + "committer": { + "name": "Robert Kern", + "email": "robert.kern@gmail.com" + }, + "author_date": "2006-05-01T18:14:12+00:00", + "author_timezone": 0, + "committer_date": "2006-05-01T18:14:12+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "7a10bcdf14827bef1ba4b79fd4bd4f92bc9e84be" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmpi8pwe29d/repo_copy", + "deletions": 1, + "insertions": 1, + "lines": 2, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/random/mtrand/distributions.c", + "new_path": "numpy/random/mtrand/distributions.c", + "filename": "distributions.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -197,7 +197,7 @@ double rk_beta(rk_state *state, double a, double b)\n \n if ((X + Y) <= 1.0)\n {\n- return X;\n+ return X / (X + Y);\n }\n }\n }\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "/* Copyright 2005 Robert Kern (robert.kern@gmail.com)\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the\n * \"Software\"), to deal in the Software without restriction, including\n * without limitation the rights to use, copy, modify, merge, publish,\n * distribute, sublicense, and/or sell copies of the Software, and to\n * permit persons to whom the Software is furnished to do so, subject to\n * the following conditions:\n * \n * The above copyright notice and this permission notice shall be included\n * in all copies or substantial portions of the Software.\n * \n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\n/* The implementations of rk_hypergeometric_hyp(), rk_hypergeometric_hrua(),\n * and rk_triangular() were adapted from Ivan Frohne's rv.py which has this \n * license:\n * \n * Copyright 1998 by Ivan Frohne; Wasilla, Alaska, U.S.A.\n * All Rights Reserved\n *\n * Permission to use, copy, modify and distribute this software and its\n * documentation for any purpose, free of charge, is granted subject to the\n * following conditions:\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the software.\n *\n * THE SOFTWARE AND DOCUMENTATION IS PROVIDED WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR\n * OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM OR DAMAGES IN A CONTRACT\n * ACTION, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n * SOFTWARE OR ITS DOCUMENTATION.\n */\n\n#include \n#include \"distributions.h\"\n#include \n\n#ifndef min\n#define min(x,y) ((xy)?x:y)\n#endif\n\n#ifndef M_PI\n#define M_PI 3.14159265358979323846264338328\n#endif \n/* log-gamma function to support some of these distributions. The \n * algorithm comes from SPECFUN by Shanjie Zhang and Jianming Jin and their\n * book \"Computation of Special Functions\", 1996, John Wiley & Sons, Inc.\n */\nextern double loggam(double x);\ndouble loggam(double x)\n{\n double x0, x2, xp, gl, gl0;\n long k, n;\n \n static double a[10] = {8.333333333333333e-02,-2.777777777777778e-03,\n 7.936507936507937e-04,-5.952380952380952e-04,\n 8.417508417508418e-04,-1.917526917526918e-03,\n 6.410256410256410e-03,-2.955065359477124e-02,\n 1.796443723688307e-01,-1.39243221690590e+00};\n x0 = x;\n n = 0;\n if ((x == 1.0) || (x == 2.0))\n {\n return 0.0;\n }\n else if (x <= 7.0)\n {\n n = (long)(7 - x);\n x0 = x + n;\n }\n x2 = 1.0/(x0*x0);\n xp = 2*M_PI;\n gl0 = a[9];\n for (k=8; k>=0; k--)\n {\n gl0 *= x2;\n gl0 += a[k];\n }\n gl = gl0/x0 + 0.5*log(xp) + (x0-0.5)*log(x0) - x0;\n if (x <= 7.0)\n {\n for (k=1; k<=n; k++)\n {\n gl -= log(x0-1.0);\n x0 -= 1.0;\n }\n }\n return gl;\n}\n\ndouble rk_normal(rk_state *state, double loc, double scale)\n{\n return loc + scale*rk_gauss(state);\n}\n\ndouble rk_standard_exponential(rk_state *state)\n{\n /* We use -log(1-U) since U is [0, 1) */\n return -log(1.0 - rk_double(state));\n}\n\ndouble rk_exponential(rk_state *state, double scale)\n{\n return scale * rk_standard_exponential(state);\n}\n\ndouble rk_uniform(rk_state *state, double loc, double scale)\n{\n return loc + scale*rk_double(state);\n}\n\ndouble rk_standard_gamma(rk_state *state, double shape)\n{\n double b, c;\n double U, V, X, Y;\n\n if (shape == 1.0)\n {\n return rk_standard_exponential(state);\n }\n else if (shape < 1.0)\n {\n for (;;)\n {\n U = rk_double(state);\n V = rk_standard_exponential(state);\n if (U <= 1.0 - shape)\n {\n X = pow(U, 1./shape);\n if (X <= V)\n {\n return X;\n }\n }\n else\n {\n Y = -log((1-U)/shape);\n X = pow(1.0 - shape + shape*Y, 1./shape);\n if (X <= (V + Y))\n {\n return X;\n }\n }\n }\n }\n else\n {\n b = shape - 1./3.;\n c = 1./sqrt(9*b);\n for (;;)\n {\n do\n {\n X = rk_gauss(state); \n V = 1.0 + c*X;\n } while (V <= 0.0);\n\n V = V*V*V;\n U = rk_double(state);\n if (U < 1.0 - 0.0331*(X*X)*(X*X)) return (b*V);\n if (log(U) < 0.5*X*X + b*(1. - V + log(V))) return (b*V);\n }\n }\n}\n\ndouble rk_gamma(rk_state *state, double shape, double scale)\n{\n return scale * rk_standard_gamma(state, shape);\n}\n\ndouble rk_beta(rk_state *state, double a, double b)\n{\n double Ga, Gb;\n\n if ((a <= 1.0) && (b <= 1.0))\n {\n double U, V, X, Y;\n /* Use Jonk's algorithm */\n\n while (1)\n {\n U = rk_double(state);\n V = rk_double(state);\n X = pow(U, 1.0/a);\n Y = pow(V, 1.0/b);\n\n if ((X + Y) <= 1.0)\n {\n return X / (X + Y);\n }\n }\n }\n else\n {\n Ga = rk_standard_gamma(state, a);\n Gb = rk_standard_gamma(state, b);\n return Ga/(Ga + Gb);\n }\n}\n\ndouble rk_chisquare(rk_state *state, double df)\n{\n return 2.0*rk_standard_gamma(state, df/2.0);\n}\n\ndouble rk_noncentral_chisquare(rk_state *state, double df, double nonc)\n{\n double Chi2, N;\n\n Chi2 = rk_chisquare(state, df-1);\n N = rk_gauss(state) + sqrt(nonc);\n return Chi2 + N*N;\n}\n\ndouble rk_f(rk_state *state, double dfnum, double dfden)\n{\n return rk_chisquare(state, dfnum) / rk_chisquare(state, dfden);\n}\n\ndouble rk_noncentral_f(rk_state *state, double dfnum, double dfden, double nonc)\n{\n return ((rk_noncentral_chisquare(state, dfnum, nonc)*dfden) /\n (rk_chisquare(state, dfden)*dfnum));\n}\n\nlong rk_binomial_btpe(rk_state *state, long n, double p)\n{\n double r,q,fm,p1,xm,xl,xr,c,laml,lamr,p2,p3,p4;\n double a,u,v,s,F,rho,t,A,nrq,x1,x2,f1,f2,z,z2,w,w2,x;\n long m,y,k,i;\n\n if (!(state->has_binomial) || \n (state->nsave != n) ||\n (state->psave != p))\n {\n /* initialize */\n state->nsave = n;\n state->psave = p;\n state->has_binomial = 1;\n state->r = r = min(p, 1.0-p);\n state->q = q = 1.0 - r;\n state->fm = fm = n*r+r;\n state->m = m = (long)floor(state->fm);\n state->p1 = p1 = floor(2.195*sqrt(n*r*q)-4.6*q) + 0.5;\n state->xm = xm = m + 0.5;\n state->xl = xl = xm - p1;\n state->xr = xr = xm + p1;\n state->c = c = 0.134 + 20.5/(15.3 + m);\n a = (fm - xl)/(fm-xl*r);\n state->laml = laml = a*(1.0 + a/2.0);\n a = (xr - fm)/(xr*q);\n state->lamr = lamr = a*(1.0 + a/2.0);\n state->p2 = p2 = p1*(1.0 + 2.0*c);\n state->p3 = p3 = p2 + c/laml;\n state->p4 = p4 = p3 + c/lamr;\n }\n else\n {\n r = state->r;\n q = state->q;\n fm = state->fm;\n m = state->m;\n p1 = state->p1;\n xm = state->xm;\n xl = state->xl;\n xr = state->xr;\n c = state->c;\n laml = state->laml;\n lamr = state->lamr;\n p2 = state->p2;\n p3 = state->p3;\n p4 = state->p4;\n }\n\n /* sigh ... */\n Step10:\n nrq = n*r*q;\n u = rk_double(state)*p4;\n v = rk_double(state);\n if (u > p1) goto Step20;\n y = (long)floor(xm - p1*v + u);\n goto Step60;\n\n Step20:\n if (u > p2) goto Step30;\n x = xl + (u - p1)/c;\n v = v*c + 1.0 - fabs(m - x + 0.5)/p1;\n if (v > 1.0) goto Step10;\n y = (long)floor(x);\n goto Step50;\n\n Step30:\n if (u > p3) goto Step40;\n y = (long)floor(xl + log(v)/laml);\n if (y < 0) goto Step10;\n v = v*(u-p2)*laml;\n goto Step50;\n\n Step40:\n y = (int)floor(xr - log(v)/lamr);\n if (y > n) goto Step10;\n v = v*(u-p3)*lamr;\n\n Step50:\n k = fabs(y - m);\n if ((k > 20) && (k < ((nrq)/2.0 - 1))) goto Step52;\n\n s = r/q;\n a = s*(n+1);\n F = 1.0;\n if (m < y)\n {\n for (i=m; i<=y; i++)\n {\n F *= (a/i - s);\n }\n }\n else if (m > y)\n {\n for (i=y; i<=m; i++)\n {\n F /= (a/i - s);\n }\n }\n else\n {\n if (v > F) goto Step10;\n goto Step60;\n }\n\n Step52:\n rho = (k/(nrq))*((k*(k/3.0 + 0.625) + 0.16666666666666666)/nrq + 0.5);\n t = -k*k/(2*nrq);\n A = log(v);\n if (A < (t - rho)) goto Step60;\n if (A > (t + rho)) goto Step10;\n\n x1 = y+1;\n f1 = m+1;\n z = n+1-m;\n w = n-y+1;\n x2 = x1*x1;\n f2 = f1*f1;\n z2 = z*z;\n w2 = w*w;\n if (A > (xm*log(f1/x1)\n + (n-m+0.5)*log(z/w)\n + (y-m)*log(w*r/(x1*q))\n + (13680.-(462.-(132.-(99.-140./f2)/f2)/f2)/f2)/f1/166320.\n + (13680.-(462.-(132.-(99.-140./z2)/z2)/z2)/z2)/z/166320.\n + (13680.-(462.-(132.-(99.-140./x2)/x2)/x2)/x2)/x1/166320.\n + (13680.-(462.-(132.-(99.-140./w2)/w2)/w2)/w2)/w/166320.))\n {\n goto Step10;\n }\n\n Step60:\n if (p > 0.5)\n {\n y = n - y;\n }\n\n return y;\n}\n\nlong rk_binomial_inversion(rk_state *state, long n, double p)\n{\n double q, qn, np, px, U;\n long X, bound;\n\n if (!(state->has_binomial) || \n (state->nsave != n) ||\n (state->psave != p))\n {\n state->nsave = n;\n state->psave = p;\n state->has_binomial = 1;\n state->q = q = 1.0 - p;\n state->r = qn = exp(n * log(q));\n state->c = np = n*p;\n state->m = bound = min(n, np + 10.0*sqrt(np));\n } else\n {\n q = state->q;\n qn = state->r;\n np = state->c;\n bound = state->m;\n }\n X = 0;\n px = qn;\n U = rk_double(state);\n while (U > px)\n {\n X++;\n if (X > bound) \n {\n X = 0;\n px = qn;\n U = rk_double(state);\n } else \n {\n U -= px;\n px = ((n-X+1) * p * px)/(X*q);\n }\n }\n return X;\n}\n\nlong rk_binomial(rk_state *state, long n, double p)\n{\n double q;\n\n if (p <= 0.5)\n {\n if (p*n <= 30.0)\n {\n return rk_binomial_inversion(state, n, p);\n }\n else\n {\n return rk_binomial_btpe(state, n, p);\n }\n }\n else\n {\n q = 1.0-p;\n if (q*n <= 30.0)\n {\n return n - rk_binomial_inversion(state, n, q);\n }\n else\n {\n return n - rk_binomial_btpe(state, n, q);\n }\n }\n\n}\n\nlong rk_negative_binomial(rk_state *state, long n, double p)\n{\n double Y;\n\n Y = rk_gamma(state, n, (1-p)/p);\n return rk_poisson(state, Y);\n}\n\nlong rk_poisson_mult(rk_state *state, double lam)\n{\n long X;\n double prod, U, enlam;\n\n enlam = exp(-lam);\n X = 0;\n prod = 1.0;\n while (1)\n {\n U = rk_double(state);\n prod *= U;\n if (prod > enlam)\n {\n X += 1;\n }\n else\n {\n return X;\n }\n }\n}\n\n#define LS2PI 0.91893853320467267\n#define TWELFTH 0.083333333333333333333333\nlong rk_poisson_ptrs(rk_state *state, double lam)\n{\n long k;\n double U, V, slam, loglam, a, b, invalpha, vr, us;\n\n slam = sqrt(lam);\n loglam = log(lam);\n b = 0.931 + 2.53*slam;\n a = -0.059 + 0.02483*b;\n invalpha = 1.1239 + 1.1328/(b-3.4);\n vr = 0.9277 - 3.6224/(b-2);\n\n while (1)\n {\n U = rk_double(state) - 0.5;\n V = rk_double(state);\n us = 0.5 - fabs(U);\n k = (long)floor((2*a/us + b)*U + lam + 0.43);\n if ((us >= 0.07) && (V <= vr))\n {\n return k;\n }\n if ((k < 0) ||\n ((us < 0.013) && (V > us)))\n {\n continue;\n }\n if ((log(V) + log(invalpha) - log(a/(us*us)+b)) <=\n (-lam + k*loglam - loggam(k+1)))\n {\n return k;\n }\n\n \n }\n\n}\n\nlong rk_poisson(rk_state *state, double lam)\n{\n if (lam >= 10)\n {\n return rk_poisson_ptrs(state, lam);\n }\n else\n {\n return rk_poisson_mult(state, lam);\n }\n}\n\ndouble rk_standard_cauchy(rk_state *state)\n{\n return rk_gauss(state) / rk_gauss(state);\n}\n\ndouble rk_standard_t(rk_state *state, double df)\n{\n double N, G, X;\n\n N = rk_gauss(state);\n G = rk_standard_gamma(state, df/2);\n X = sqrt(df/2)*N/sqrt(G);\n return X;\n}\n\ndouble rk_vonmises(rk_state *state, double mu, double kappa)\n{\n double r, rho, s;\n double U, V, W, Y, Z;\n double result, mod;\n\n if (kappa < 1e-8)\n {\n return M_PI * (2*rk_double(state)-1);\n }\n else\n {\n r = 1 + sqrt(1 + 4*kappa*kappa);\n rho = (r - sqrt(2*r))/(2*kappa);\n s = (1 + rho*rho)/(2*rho);\n\n while (1)\n {\n U = 2*rk_double(state) - 1;\n V = 2*rk_double(state) - 1;\n Z = cos(M_PI*U);\n W = (1 + s*Z)/(s + Z);\n Y = kappa * (s - W);\n if ((Y*(2-Y) - V >= 0) || (log(Y/V)+1 - Y >= 0))\n {\n break;\n }\n }\n\n if (U < 0)\n {\n result = acos(W);\n }\n else\n {\n result = -acos(W);\n }\n result += mu + M_PI;\n mod = fmod(result, 2*M_PI);\n if (mod && (mod < 0))\n {\n mod += 2*M_PI;\n }\n return mod - M_PI;\n }\n}\n\ndouble rk_pareto(rk_state *state, double a)\n{\n return exp(rk_standard_exponential(state)/a) - 1;\n}\n\ndouble rk_weibull(rk_state *state, double a)\n{\n return pow(rk_standard_exponential(state), 1./a);\n}\n\ndouble rk_power(rk_state *state, double a)\n{\n return pow(1 - exp(-rk_standard_exponential(state)), 1./a);\n}\n\ndouble rk_laplace(rk_state *state, double loc, double scale)\n{\n double U;\n \n U = rk_double(state);\n if (U < 0.5)\n {\n U = loc + scale * log(U + U);\n } else \n {\n U = loc - scale * log(2.0 - U - U);\n }\n return U;\n}\n\ndouble rk_gumbel(rk_state *state, double loc, double scale)\n{\n double U;\n \n U = 1.0 - rk_double(state);\n return loc - scale * log(-log(U));\n}\n\ndouble rk_logistic(rk_state *state, double loc, double scale)\n{\n double U;\n \n U = rk_double(state);\n return loc + scale * log(U/(1.0 - U));\n}\n\ndouble rk_lognormal(rk_state *state, double mean, double sigma)\n{\n return exp(rk_normal(state, mean, sigma));\n}\n\ndouble rk_rayleigh(rk_state *state, double mode)\n{\n return mode*sqrt(-2.0 * log(1.0 - rk_double(state)));\n}\n\ndouble rk_wald(rk_state *state, double mean, double scale)\n{\n double U, X, Y;\n double mu_2l;\n \n mu_2l = mean / (2*scale);\n Y = rk_gauss(state);\n Y = mean*Y*Y;\n X = mean + mu_2l*(Y - sqrt(4*scale*Y + Y*Y));\n U = rk_double(state);\n if (U <= mean/(mean+X))\n {\n return X;\n } else\n {\n return mean*mean/X;\n }\n}\n\nlong rk_zipf(rk_state *state, double a)\n{\n double T, U, V;\n long X;\n double b;\n \n b = pow(2.0, a-1.0);\n do\n {\n U = rk_double(state);\n V = rk_double(state);\n X = (long)floor(pow(U, -1.0/(a-1.0)));\n T = pow(1.0 + 1.0/X, a-1.0); \n } while ((V *X*(T-1.0)/(b-1.0)) > (T/b));\n return X;\n}\n\nlong rk_geometric_search(rk_state *state, double p)\n{\n double U;\n long X;\n double sum, prod, q;\n \n X = 1;\n sum = prod = p;\n q = 1.0 - p;\n U = rk_double(state);\n while (U > sum)\n {\n prod *= q;\n sum += prod;\n X++;\n }\n return X;\n}\n\nlong rk_geometric_inversion(rk_state *state, double p)\n{\n return (long)ceil(log(1.0-rk_double(state))/log(1.0-p));\n}\n\nlong rk_geometric(rk_state *state, double p)\n{\n if (p >= 0.333333333333333333333333)\n {\n return rk_geometric_search(state, p);\n } else\n {\n return rk_geometric_inversion(state, p);\n }\n}\n\nlong rk_hypergeometric_hyp(rk_state *state, long good, long bad, long sample)\n{\n long d1, K, Z;\n double d2, U, Y;\n \n d1 = bad + good - sample;\n d2 = (double)min(bad, good);\n \n Y = d2;\n K = sample;\n while (Y > 0.0)\n {\n U = rk_double(state);\n Y -= (long)floor(U + Y/(d1 + K));\n K--;\n if (K == 0) break;\n }\n Z = (long)(d2 - Y);\n if (bad > good) Z = sample - Z;\n return Z;\n}\n\n/* D1 = 2*sqrt(2/e) */\n/* D2 = 3 - 2*sqrt(3/e) */\n#define D1 1.7155277699214135\n#define D2 0.8989161620588988\nlong rk_hypergeometric_hrua(rk_state *state, long good, long bad, long sample)\n{\n long mingoodbad, maxgoodbad, popsize, m, d9;\n double d4, d5, d6, d7, d8, d10, d11;\n long Z;\n double T, W, X, Y;\n \n mingoodbad = min(good, bad);\n popsize = good + bad;\n maxgoodbad = max(good, bad);\n m = min(sample, popsize - sample);\n d4 = ((double)mingoodbad) / popsize;\n d5 = 1.0 - d4;\n d6 = m*d4 + 0.5;\n d7 = sqrt((popsize - m) * sample * d4 *d5 / (popsize-1) + 0.5);\n d8 = D1*d7 + D2;\n d9 = (long)floor((double)((m+1)*(mingoodbad+1))/(popsize+2));\n d10 = (loggam(d9+1) + loggam(mingoodbad-d9+1) + loggam(m-d9+1) + \n loggam(maxgoodbad-m+d9+1));\n d11 = min(min(m, mingoodbad)+1.0, floor(d6+16*d7));\n /* 16 for 16-decimal-digit precision in D1 and D2 */\n \n while (1)\n {\n X = rk_double(state);\n Y = rk_double(state);\n W = d6 + d8*(Y- 0.5)/X;\n \n /* fast rejection: */\n if ((W < 0.0) || (W >= d11)) continue;\n \n Z = (long)floor(W);\n T = d10 - (loggam(Z+1) + loggam(mingoodbad-Z+1) + loggam(m-Z+1) +\n loggam(maxgoodbad-m+Z+1));\n \n /* fast acceptance: */\n if ((X*(4.0-X)-3.0) <= T) break;\n \n /* fast rejection: */\n if (X*(X-T) >= 1) continue;\n\n if (2.0*log(X) <= T) break; /* acceptance */\n }\n \n /* this is a correction to HRUA* by Ivan Frohne in rv.py */\n if (bad > good) Z = m - Z;\n \n /* another fix from rv.py to allow sample to exceed popsize/2 */\n if (m < sample) Z = bad - Z;\n \n return Z;\n}\n#undef D1\n#undef D2\n\nlong rk_hypergeometric(rk_state *state, long good, long bad, long sample)\n{\n if (sample > 10)\n {\n return rk_hypergeometric_hrua(state, good, bad, sample);\n } else\n {\n return rk_hypergeometric_hyp(state, good, bad, sample);\n }\n}\n\ndouble rk_triangular(rk_state *state, double left, double mode, double right)\n{\n double base, leftbase, ratio, leftprod, rightprod;\n double U;\n \n base = right - left;\n leftbase = mode - left;\n ratio = leftbase / base;\n leftprod = leftbase*base;\n rightprod = (right - mode)*base;\n \n U = rk_double(state);\n if (U <= ratio)\n {\n return left + sqrt(U*leftprod);\n } else \n {\n return right - sqrt((1.0 - U) * rightprod); \n }\n}\n\nlong rk_logseries(rk_state *state, double p)\n{\n double q, r, U, V;\n \n r = log(1.0 - p);\n \n V = rk_double(state);\n if (V >= p) return 1;\n U = rk_double(state);\n q = 1.0 - exp(r*U);\n if (V <= q*q) return (long)floor(1 + log(V)/log(q));\n if (V <= q) return 1;\n return 2;\n}\n", + "source_code_before": "/* Copyright 2005 Robert Kern (robert.kern@gmail.com)\n *\n * Permission is hereby granted, free of charge, to any person obtaining a\n * copy of this software and associated documentation files (the\n * \"Software\"), to deal in the Software without restriction, including\n * without limitation the rights to use, copy, modify, merge, publish,\n * distribute, sublicense, and/or sell copies of the Software, and to\n * permit persons to whom the Software is furnished to do so, subject to\n * the following conditions:\n * \n * The above copyright notice and this permission notice shall be included\n * in all copies or substantial portions of the Software.\n * \n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS\n * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\n * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\n * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\n * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\n/* The implementations of rk_hypergeometric_hyp(), rk_hypergeometric_hrua(),\n * and rk_triangular() were adapted from Ivan Frohne's rv.py which has this \n * license:\n * \n * Copyright 1998 by Ivan Frohne; Wasilla, Alaska, U.S.A.\n * All Rights Reserved\n *\n * Permission to use, copy, modify and distribute this software and its\n * documentation for any purpose, free of charge, is granted subject to the\n * following conditions:\n * The above copyright notice and this permission notice shall be included in\n * all copies or substantial portions of the software.\n *\n * THE SOFTWARE AND DOCUMENTATION IS PROVIDED WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO MERCHANTABILITY, FITNESS\n * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHOR\n * OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM OR DAMAGES IN A CONTRACT\n * ACTION, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\n * SOFTWARE OR ITS DOCUMENTATION.\n */\n\n#include \n#include \"distributions.h\"\n#include \n\n#ifndef min\n#define min(x,y) ((xy)?x:y)\n#endif\n\n#ifndef M_PI\n#define M_PI 3.14159265358979323846264338328\n#endif \n/* log-gamma function to support some of these distributions. The \n * algorithm comes from SPECFUN by Shanjie Zhang and Jianming Jin and their\n * book \"Computation of Special Functions\", 1996, John Wiley & Sons, Inc.\n */\nextern double loggam(double x);\ndouble loggam(double x)\n{\n double x0, x2, xp, gl, gl0;\n long k, n;\n \n static double a[10] = {8.333333333333333e-02,-2.777777777777778e-03,\n 7.936507936507937e-04,-5.952380952380952e-04,\n 8.417508417508418e-04,-1.917526917526918e-03,\n 6.410256410256410e-03,-2.955065359477124e-02,\n 1.796443723688307e-01,-1.39243221690590e+00};\n x0 = x;\n n = 0;\n if ((x == 1.0) || (x == 2.0))\n {\n return 0.0;\n }\n else if (x <= 7.0)\n {\n n = (long)(7 - x);\n x0 = x + n;\n }\n x2 = 1.0/(x0*x0);\n xp = 2*M_PI;\n gl0 = a[9];\n for (k=8; k>=0; k--)\n {\n gl0 *= x2;\n gl0 += a[k];\n }\n gl = gl0/x0 + 0.5*log(xp) + (x0-0.5)*log(x0) - x0;\n if (x <= 7.0)\n {\n for (k=1; k<=n; k++)\n {\n gl -= log(x0-1.0);\n x0 -= 1.0;\n }\n }\n return gl;\n}\n\ndouble rk_normal(rk_state *state, double loc, double scale)\n{\n return loc + scale*rk_gauss(state);\n}\n\ndouble rk_standard_exponential(rk_state *state)\n{\n /* We use -log(1-U) since U is [0, 1) */\n return -log(1.0 - rk_double(state));\n}\n\ndouble rk_exponential(rk_state *state, double scale)\n{\n return scale * rk_standard_exponential(state);\n}\n\ndouble rk_uniform(rk_state *state, double loc, double scale)\n{\n return loc + scale*rk_double(state);\n}\n\ndouble rk_standard_gamma(rk_state *state, double shape)\n{\n double b, c;\n double U, V, X, Y;\n\n if (shape == 1.0)\n {\n return rk_standard_exponential(state);\n }\n else if (shape < 1.0)\n {\n for (;;)\n {\n U = rk_double(state);\n V = rk_standard_exponential(state);\n if (U <= 1.0 - shape)\n {\n X = pow(U, 1./shape);\n if (X <= V)\n {\n return X;\n }\n }\n else\n {\n Y = -log((1-U)/shape);\n X = pow(1.0 - shape + shape*Y, 1./shape);\n if (X <= (V + Y))\n {\n return X;\n }\n }\n }\n }\n else\n {\n b = shape - 1./3.;\n c = 1./sqrt(9*b);\n for (;;)\n {\n do\n {\n X = rk_gauss(state); \n V = 1.0 + c*X;\n } while (V <= 0.0);\n\n V = V*V*V;\n U = rk_double(state);\n if (U < 1.0 - 0.0331*(X*X)*(X*X)) return (b*V);\n if (log(U) < 0.5*X*X + b*(1. - V + log(V))) return (b*V);\n }\n }\n}\n\ndouble rk_gamma(rk_state *state, double shape, double scale)\n{\n return scale * rk_standard_gamma(state, shape);\n}\n\ndouble rk_beta(rk_state *state, double a, double b)\n{\n double Ga, Gb;\n\n if ((a <= 1.0) && (b <= 1.0))\n {\n double U, V, X, Y;\n /* Use Jonk's algorithm */\n\n while (1)\n {\n U = rk_double(state);\n V = rk_double(state);\n X = pow(U, 1.0/a);\n Y = pow(V, 1.0/b);\n\n if ((X + Y) <= 1.0)\n {\n return X;\n }\n }\n }\n else\n {\n Ga = rk_standard_gamma(state, a);\n Gb = rk_standard_gamma(state, b);\n return Ga/(Ga + Gb);\n }\n}\n\ndouble rk_chisquare(rk_state *state, double df)\n{\n return 2.0*rk_standard_gamma(state, df/2.0);\n}\n\ndouble rk_noncentral_chisquare(rk_state *state, double df, double nonc)\n{\n double Chi2, N;\n\n Chi2 = rk_chisquare(state, df-1);\n N = rk_gauss(state) + sqrt(nonc);\n return Chi2 + N*N;\n}\n\ndouble rk_f(rk_state *state, double dfnum, double dfden)\n{\n return rk_chisquare(state, dfnum) / rk_chisquare(state, dfden);\n}\n\ndouble rk_noncentral_f(rk_state *state, double dfnum, double dfden, double nonc)\n{\n return ((rk_noncentral_chisquare(state, dfnum, nonc)*dfden) /\n (rk_chisquare(state, dfden)*dfnum));\n}\n\nlong rk_binomial_btpe(rk_state *state, long n, double p)\n{\n double r,q,fm,p1,xm,xl,xr,c,laml,lamr,p2,p3,p4;\n double a,u,v,s,F,rho,t,A,nrq,x1,x2,f1,f2,z,z2,w,w2,x;\n long m,y,k,i;\n\n if (!(state->has_binomial) || \n (state->nsave != n) ||\n (state->psave != p))\n {\n /* initialize */\n state->nsave = n;\n state->psave = p;\n state->has_binomial = 1;\n state->r = r = min(p, 1.0-p);\n state->q = q = 1.0 - r;\n state->fm = fm = n*r+r;\n state->m = m = (long)floor(state->fm);\n state->p1 = p1 = floor(2.195*sqrt(n*r*q)-4.6*q) + 0.5;\n state->xm = xm = m + 0.5;\n state->xl = xl = xm - p1;\n state->xr = xr = xm + p1;\n state->c = c = 0.134 + 20.5/(15.3 + m);\n a = (fm - xl)/(fm-xl*r);\n state->laml = laml = a*(1.0 + a/2.0);\n a = (xr - fm)/(xr*q);\n state->lamr = lamr = a*(1.0 + a/2.0);\n state->p2 = p2 = p1*(1.0 + 2.0*c);\n state->p3 = p3 = p2 + c/laml;\n state->p4 = p4 = p3 + c/lamr;\n }\n else\n {\n r = state->r;\n q = state->q;\n fm = state->fm;\n m = state->m;\n p1 = state->p1;\n xm = state->xm;\n xl = state->xl;\n xr = state->xr;\n c = state->c;\n laml = state->laml;\n lamr = state->lamr;\n p2 = state->p2;\n p3 = state->p3;\n p4 = state->p4;\n }\n\n /* sigh ... */\n Step10:\n nrq = n*r*q;\n u = rk_double(state)*p4;\n v = rk_double(state);\n if (u > p1) goto Step20;\n y = (long)floor(xm - p1*v + u);\n goto Step60;\n\n Step20:\n if (u > p2) goto Step30;\n x = xl + (u - p1)/c;\n v = v*c + 1.0 - fabs(m - x + 0.5)/p1;\n if (v > 1.0) goto Step10;\n y = (long)floor(x);\n goto Step50;\n\n Step30:\n if (u > p3) goto Step40;\n y = (long)floor(xl + log(v)/laml);\n if (y < 0) goto Step10;\n v = v*(u-p2)*laml;\n goto Step50;\n\n Step40:\n y = (int)floor(xr - log(v)/lamr);\n if (y > n) goto Step10;\n v = v*(u-p3)*lamr;\n\n Step50:\n k = fabs(y - m);\n if ((k > 20) && (k < ((nrq)/2.0 - 1))) goto Step52;\n\n s = r/q;\n a = s*(n+1);\n F = 1.0;\n if (m < y)\n {\n for (i=m; i<=y; i++)\n {\n F *= (a/i - s);\n }\n }\n else if (m > y)\n {\n for (i=y; i<=m; i++)\n {\n F /= (a/i - s);\n }\n }\n else\n {\n if (v > F) goto Step10;\n goto Step60;\n }\n\n Step52:\n rho = (k/(nrq))*((k*(k/3.0 + 0.625) + 0.16666666666666666)/nrq + 0.5);\n t = -k*k/(2*nrq);\n A = log(v);\n if (A < (t - rho)) goto Step60;\n if (A > (t + rho)) goto Step10;\n\n x1 = y+1;\n f1 = m+1;\n z = n+1-m;\n w = n-y+1;\n x2 = x1*x1;\n f2 = f1*f1;\n z2 = z*z;\n w2 = w*w;\n if (A > (xm*log(f1/x1)\n + (n-m+0.5)*log(z/w)\n + (y-m)*log(w*r/(x1*q))\n + (13680.-(462.-(132.-(99.-140./f2)/f2)/f2)/f2)/f1/166320.\n + (13680.-(462.-(132.-(99.-140./z2)/z2)/z2)/z2)/z/166320.\n + (13680.-(462.-(132.-(99.-140./x2)/x2)/x2)/x2)/x1/166320.\n + (13680.-(462.-(132.-(99.-140./w2)/w2)/w2)/w2)/w/166320.))\n {\n goto Step10;\n }\n\n Step60:\n if (p > 0.5)\n {\n y = n - y;\n }\n\n return y;\n}\n\nlong rk_binomial_inversion(rk_state *state, long n, double p)\n{\n double q, qn, np, px, U;\n long X, bound;\n\n if (!(state->has_binomial) || \n (state->nsave != n) ||\n (state->psave != p))\n {\n state->nsave = n;\n state->psave = p;\n state->has_binomial = 1;\n state->q = q = 1.0 - p;\n state->r = qn = exp(n * log(q));\n state->c = np = n*p;\n state->m = bound = min(n, np + 10.0*sqrt(np));\n } else\n {\n q = state->q;\n qn = state->r;\n np = state->c;\n bound = state->m;\n }\n X = 0;\n px = qn;\n U = rk_double(state);\n while (U > px)\n {\n X++;\n if (X > bound) \n {\n X = 0;\n px = qn;\n U = rk_double(state);\n } else \n {\n U -= px;\n px = ((n-X+1) * p * px)/(X*q);\n }\n }\n return X;\n}\n\nlong rk_binomial(rk_state *state, long n, double p)\n{\n double q;\n\n if (p <= 0.5)\n {\n if (p*n <= 30.0)\n {\n return rk_binomial_inversion(state, n, p);\n }\n else\n {\n return rk_binomial_btpe(state, n, p);\n }\n }\n else\n {\n q = 1.0-p;\n if (q*n <= 30.0)\n {\n return n - rk_binomial_inversion(state, n, q);\n }\n else\n {\n return n - rk_binomial_btpe(state, n, q);\n }\n }\n\n}\n\nlong rk_negative_binomial(rk_state *state, long n, double p)\n{\n double Y;\n\n Y = rk_gamma(state, n, (1-p)/p);\n return rk_poisson(state, Y);\n}\n\nlong rk_poisson_mult(rk_state *state, double lam)\n{\n long X;\n double prod, U, enlam;\n\n enlam = exp(-lam);\n X = 0;\n prod = 1.0;\n while (1)\n {\n U = rk_double(state);\n prod *= U;\n if (prod > enlam)\n {\n X += 1;\n }\n else\n {\n return X;\n }\n }\n}\n\n#define LS2PI 0.91893853320467267\n#define TWELFTH 0.083333333333333333333333\nlong rk_poisson_ptrs(rk_state *state, double lam)\n{\n long k;\n double U, V, slam, loglam, a, b, invalpha, vr, us;\n\n slam = sqrt(lam);\n loglam = log(lam);\n b = 0.931 + 2.53*slam;\n a = -0.059 + 0.02483*b;\n invalpha = 1.1239 + 1.1328/(b-3.4);\n vr = 0.9277 - 3.6224/(b-2);\n\n while (1)\n {\n U = rk_double(state) - 0.5;\n V = rk_double(state);\n us = 0.5 - fabs(U);\n k = (long)floor((2*a/us + b)*U + lam + 0.43);\n if ((us >= 0.07) && (V <= vr))\n {\n return k;\n }\n if ((k < 0) ||\n ((us < 0.013) && (V > us)))\n {\n continue;\n }\n if ((log(V) + log(invalpha) - log(a/(us*us)+b)) <=\n (-lam + k*loglam - loggam(k+1)))\n {\n return k;\n }\n\n \n }\n\n}\n\nlong rk_poisson(rk_state *state, double lam)\n{\n if (lam >= 10)\n {\n return rk_poisson_ptrs(state, lam);\n }\n else\n {\n return rk_poisson_mult(state, lam);\n }\n}\n\ndouble rk_standard_cauchy(rk_state *state)\n{\n return rk_gauss(state) / rk_gauss(state);\n}\n\ndouble rk_standard_t(rk_state *state, double df)\n{\n double N, G, X;\n\n N = rk_gauss(state);\n G = rk_standard_gamma(state, df/2);\n X = sqrt(df/2)*N/sqrt(G);\n return X;\n}\n\ndouble rk_vonmises(rk_state *state, double mu, double kappa)\n{\n double r, rho, s;\n double U, V, W, Y, Z;\n double result, mod;\n\n if (kappa < 1e-8)\n {\n return M_PI * (2*rk_double(state)-1);\n }\n else\n {\n r = 1 + sqrt(1 + 4*kappa*kappa);\n rho = (r - sqrt(2*r))/(2*kappa);\n s = (1 + rho*rho)/(2*rho);\n\n while (1)\n {\n U = 2*rk_double(state) - 1;\n V = 2*rk_double(state) - 1;\n Z = cos(M_PI*U);\n W = (1 + s*Z)/(s + Z);\n Y = kappa * (s - W);\n if ((Y*(2-Y) - V >= 0) || (log(Y/V)+1 - Y >= 0))\n {\n break;\n }\n }\n\n if (U < 0)\n {\n result = acos(W);\n }\n else\n {\n result = -acos(W);\n }\n result += mu + M_PI;\n mod = fmod(result, 2*M_PI);\n if (mod && (mod < 0))\n {\n mod += 2*M_PI;\n }\n return mod - M_PI;\n }\n}\n\ndouble rk_pareto(rk_state *state, double a)\n{\n return exp(rk_standard_exponential(state)/a) - 1;\n}\n\ndouble rk_weibull(rk_state *state, double a)\n{\n return pow(rk_standard_exponential(state), 1./a);\n}\n\ndouble rk_power(rk_state *state, double a)\n{\n return pow(1 - exp(-rk_standard_exponential(state)), 1./a);\n}\n\ndouble rk_laplace(rk_state *state, double loc, double scale)\n{\n double U;\n \n U = rk_double(state);\n if (U < 0.5)\n {\n U = loc + scale * log(U + U);\n } else \n {\n U = loc - scale * log(2.0 - U - U);\n }\n return U;\n}\n\ndouble rk_gumbel(rk_state *state, double loc, double scale)\n{\n double U;\n \n U = 1.0 - rk_double(state);\n return loc - scale * log(-log(U));\n}\n\ndouble rk_logistic(rk_state *state, double loc, double scale)\n{\n double U;\n \n U = rk_double(state);\n return loc + scale * log(U/(1.0 - U));\n}\n\ndouble rk_lognormal(rk_state *state, double mean, double sigma)\n{\n return exp(rk_normal(state, mean, sigma));\n}\n\ndouble rk_rayleigh(rk_state *state, double mode)\n{\n return mode*sqrt(-2.0 * log(1.0 - rk_double(state)));\n}\n\ndouble rk_wald(rk_state *state, double mean, double scale)\n{\n double U, X, Y;\n double mu_2l;\n \n mu_2l = mean / (2*scale);\n Y = rk_gauss(state);\n Y = mean*Y*Y;\n X = mean + mu_2l*(Y - sqrt(4*scale*Y + Y*Y));\n U = rk_double(state);\n if (U <= mean/(mean+X))\n {\n return X;\n } else\n {\n return mean*mean/X;\n }\n}\n\nlong rk_zipf(rk_state *state, double a)\n{\n double T, U, V;\n long X;\n double b;\n \n b = pow(2.0, a-1.0);\n do\n {\n U = rk_double(state);\n V = rk_double(state);\n X = (long)floor(pow(U, -1.0/(a-1.0)));\n T = pow(1.0 + 1.0/X, a-1.0); \n } while ((V *X*(T-1.0)/(b-1.0)) > (T/b));\n return X;\n}\n\nlong rk_geometric_search(rk_state *state, double p)\n{\n double U;\n long X;\n double sum, prod, q;\n \n X = 1;\n sum = prod = p;\n q = 1.0 - p;\n U = rk_double(state);\n while (U > sum)\n {\n prod *= q;\n sum += prod;\n X++;\n }\n return X;\n}\n\nlong rk_geometric_inversion(rk_state *state, double p)\n{\n return (long)ceil(log(1.0-rk_double(state))/log(1.0-p));\n}\n\nlong rk_geometric(rk_state *state, double p)\n{\n if (p >= 0.333333333333333333333333)\n {\n return rk_geometric_search(state, p);\n } else\n {\n return rk_geometric_inversion(state, p);\n }\n}\n\nlong rk_hypergeometric_hyp(rk_state *state, long good, long bad, long sample)\n{\n long d1, K, Z;\n double d2, U, Y;\n \n d1 = bad + good - sample;\n d2 = (double)min(bad, good);\n \n Y = d2;\n K = sample;\n while (Y > 0.0)\n {\n U = rk_double(state);\n Y -= (long)floor(U + Y/(d1 + K));\n K--;\n if (K == 0) break;\n }\n Z = (long)(d2 - Y);\n if (bad > good) Z = sample - Z;\n return Z;\n}\n\n/* D1 = 2*sqrt(2/e) */\n/* D2 = 3 - 2*sqrt(3/e) */\n#define D1 1.7155277699214135\n#define D2 0.8989161620588988\nlong rk_hypergeometric_hrua(rk_state *state, long good, long bad, long sample)\n{\n long mingoodbad, maxgoodbad, popsize, m, d9;\n double d4, d5, d6, d7, d8, d10, d11;\n long Z;\n double T, W, X, Y;\n \n mingoodbad = min(good, bad);\n popsize = good + bad;\n maxgoodbad = max(good, bad);\n m = min(sample, popsize - sample);\n d4 = ((double)mingoodbad) / popsize;\n d5 = 1.0 - d4;\n d6 = m*d4 + 0.5;\n d7 = sqrt((popsize - m) * sample * d4 *d5 / (popsize-1) + 0.5);\n d8 = D1*d7 + D2;\n d9 = (long)floor((double)((m+1)*(mingoodbad+1))/(popsize+2));\n d10 = (loggam(d9+1) + loggam(mingoodbad-d9+1) + loggam(m-d9+1) + \n loggam(maxgoodbad-m+d9+1));\n d11 = min(min(m, mingoodbad)+1.0, floor(d6+16*d7));\n /* 16 for 16-decimal-digit precision in D1 and D2 */\n \n while (1)\n {\n X = rk_double(state);\n Y = rk_double(state);\n W = d6 + d8*(Y- 0.5)/X;\n \n /* fast rejection: */\n if ((W < 0.0) || (W >= d11)) continue;\n \n Z = (long)floor(W);\n T = d10 - (loggam(Z+1) + loggam(mingoodbad-Z+1) + loggam(m-Z+1) +\n loggam(maxgoodbad-m+Z+1));\n \n /* fast acceptance: */\n if ((X*(4.0-X)-3.0) <= T) break;\n \n /* fast rejection: */\n if (X*(X-T) >= 1) continue;\n\n if (2.0*log(X) <= T) break; /* acceptance */\n }\n \n /* this is a correction to HRUA* by Ivan Frohne in rv.py */\n if (bad > good) Z = m - Z;\n \n /* another fix from rv.py to allow sample to exceed popsize/2 */\n if (m < sample) Z = bad - Z;\n \n return Z;\n}\n#undef D1\n#undef D2\n\nlong rk_hypergeometric(rk_state *state, long good, long bad, long sample)\n{\n if (sample > 10)\n {\n return rk_hypergeometric_hrua(state, good, bad, sample);\n } else\n {\n return rk_hypergeometric_hyp(state, good, bad, sample);\n }\n}\n\ndouble rk_triangular(rk_state *state, double left, double mode, double right)\n{\n double base, leftbase, ratio, leftprod, rightprod;\n double U;\n \n base = right - left;\n leftbase = mode - left;\n ratio = leftbase / base;\n leftprod = leftbase*base;\n rightprod = (right - mode)*base;\n \n U = rk_double(state);\n if (U <= ratio)\n {\n return left + sqrt(U*leftprod);\n } else \n {\n return right - sqrt((1.0 - U) * rightprod); \n }\n}\n\nlong rk_logseries(rk_state *state, double p)\n{\n double q, r, U, V;\n \n r = log(1.0 - p);\n \n V = rk_double(state);\n if (V >= p) return 1;\n U = rk_double(state);\n q = 1.0 - exp(r*U);\n if (V <= q*q) return (long)floor(1 + log(V)/log(q));\n if (V <= q) return 1;\n return 2;\n}\n", + "methods": [ + { + "name": "loggam", + "long_name": "loggam( double x)", + "filename": "distributions.c", + "nloc": 39, + "complexity": 7, + "token_count": 225, + "parameters": [ + "x" + ], + "start_line": 61, + "end_line": 100, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "rk_normal", + "long_name": "rk_normal( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 102, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_standard_exponential", + "long_name": "rk_standard_exponential( rk_state * state)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "state" + ], + "start_line": 107, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rk_exponential", + "long_name": "rk_exponential( rk_state * state , double scale)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "state", + "scale" + ], + "start_line": 113, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_uniform", + "long_name": "rk_uniform( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 118, + "end_line": 121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_standard_gamma", + "long_name": "rk_standard_gamma( rk_state * state , double shape)", + "filename": "distributions.c", + "nloc": 51, + "complexity": 11, + "token_count": 279, + "parameters": [ + "state", + "shape" + ], + "start_line": 123, + "end_line": 175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "rk_gamma", + "long_name": "rk_gamma( rk_state * state , double shape , double scale)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "shape", + "scale" + ], + "start_line": 177, + "end_line": 180, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_beta", + "long_name": "rk_beta( rk_state * state , double a , double b)", + "filename": "distributions.c", + "nloc": 25, + "complexity": 5, + "token_count": 137, + "parameters": [ + "state", + "a", + "b" + ], + "start_line": 182, + "end_line": 210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "rk_chisquare", + "long_name": "rk_chisquare( rk_state * state , double df)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "state", + "df" + ], + "start_line": 212, + "end_line": 215, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_noncentral_chisquare", + "long_name": "rk_noncentral_chisquare( rk_state * state , double df , double nonc)", + "filename": "distributions.c", + "nloc": 7, + "complexity": 1, + "token_count": 49, + "parameters": [ + "state", + "df", + "nonc" + ], + "start_line": 217, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "rk_f", + "long_name": "rk_f( rk_state * state , double dfnum , double dfden)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "state", + "dfnum", + "dfden" + ], + "start_line": 226, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_noncentral_f", + "long_name": "rk_noncentral_f( rk_state * state , double dfnum , double dfden , double nonc)", + "filename": "distributions.c", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "state", + "dfnum", + "dfden", + "nonc" + ], + "start_line": 231, + "end_line": 235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rk_binomial_btpe", + "long_name": "rk_binomial_btpe( rk_state * state , long n , double p)", + "filename": "distributions.c", + "nloc": 126, + "complexity": 21, + "token_count": 1119, + "parameters": [ + "state", + "n", + "p" + ], + "start_line": 237, + "end_line": 375, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "rk_binomial_inversion", + "long_name": "rk_binomial_inversion( rk_state * state , long n , double p)", + "filename": "distributions.c", + "nloc": 41, + "complexity": 6, + "token_count": 239, + "parameters": [ + "state", + "n", + "p" + ], + "start_line": 377, + "end_line": 418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "rk_binomial", + "long_name": "rk_binomial( rk_state * state , long n , double p)", + "filename": "distributions.c", + "nloc": 27, + "complexity": 4, + "token_count": 104, + "parameters": [ + "state", + "n", + "p" + ], + "start_line": 420, + "end_line": 448, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "rk_negative_binomial", + "long_name": "rk_negative_binomial( rk_state * state , long n , double p)", + "filename": "distributions.c", + "nloc": 6, + "complexity": 1, + "token_count": 42, + "parameters": [ + "state", + "n", + "p" + ], + "start_line": 450, + "end_line": 456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "rk_poisson_mult", + "long_name": "rk_poisson_mult( rk_state * state , double lam)", + "filename": "distributions.c", + "nloc": 21, + "complexity": 3, + "token_count": 73, + "parameters": [ + "state", + "lam" + ], + "start_line": 458, + "end_line": 479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "rk_poisson_ptrs", + "long_name": "rk_poisson_ptrs( rk_state * state , double lam)", + "filename": "distributions.c", + "nloc": 32, + "complexity": 8, + "token_count": 236, + "parameters": [ + "state", + "lam" + ], + "start_line": 483, + "end_line": 519, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "rk_poisson", + "long_name": "rk_poisson( rk_state * state , double lam)", + "filename": "distributions.c", + "nloc": 11, + "complexity": 2, + "token_count": 38, + "parameters": [ + "state", + "lam" + ], + "start_line": 521, + "end_line": 531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "rk_standard_cauchy", + "long_name": "rk_standard_cauchy( rk_state * state)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "state" + ], + "start_line": 533, + "end_line": 536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_standard_t", + "long_name": "rk_standard_t( rk_state * state , double df)", + "filename": "distributions.c", + "nloc": 8, + "complexity": 1, + "token_count": 55, + "parameters": [ + "state", + "df" + ], + "start_line": 538, + "end_line": 546, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "rk_vonmises", + "long_name": "rk_vonmises( rk_state * state , double mu , double kappa)", + "filename": "distributions.c", + "nloc": 43, + "complexity": 8, + "token_count": 278, + "parameters": [ + "state", + "mu", + "kappa" + ], + "start_line": 548, + "end_line": 593, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "rk_pareto", + "long_name": "rk_pareto( rk_state * state , double a)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "a" + ], + "start_line": 595, + "end_line": 598, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_weibull", + "long_name": "rk_weibull( rk_state * state , double a)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "a" + ], + "start_line": 600, + "end_line": 603, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_power", + "long_name": "rk_power( rk_state * state , double a)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "state", + "a" + ], + "start_line": 605, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_laplace", + "long_name": "rk_laplace( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 13, + "complexity": 2, + "token_count": 66, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 610, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "rk_gumbel", + "long_name": "rk_gumbel( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 6, + "complexity": 1, + "token_count": 40, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 625, + "end_line": 631, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "rk_logistic", + "long_name": "rk_logistic( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 6, + "complexity": 1, + "token_count": 40, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 633, + "end_line": 639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "rk_lognormal", + "long_name": "rk_lognormal( rk_state * state , double mean , double sigma)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "state", + "mean", + "sigma" + ], + "start_line": 641, + "end_line": 644, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_rayleigh", + "long_name": "rk_rayleigh( rk_state * state , double mode)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "state", + "mode" + ], + "start_line": 646, + "end_line": 649, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_wald", + "long_name": "rk_wald( rk_state * state , double mean , double scale)", + "filename": "distributions.c", + "nloc": 17, + "complexity": 2, + "token_count": 106, + "parameters": [ + "state", + "mean", + "scale" + ], + "start_line": 651, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "rk_zipf", + "long_name": "rk_zipf( rk_state * state , double a)", + "filename": "distributions.c", + "nloc": 15, + "complexity": 2, + "token_count": 119, + "parameters": [ + "state", + "a" + ], + "start_line": 670, + "end_line": 685, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "rk_geometric_search", + "long_name": "rk_geometric_search( rk_state * state , double p)", + "filename": "distributions.c", + "nloc": 17, + "complexity": 2, + "token_count": 70, + "parameters": [ + "state", + "p" + ], + "start_line": 687, + "end_line": 704, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "rk_geometric_inversion", + "long_name": "rk_geometric_inversion( rk_state * state , double p)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 35, + "parameters": [ + "state", + "p" + ], + "start_line": 706, + "end_line": 709, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_geometric", + "long_name": "rk_geometric( rk_state * state , double p)", + "filename": "distributions.c", + "nloc": 10, + "complexity": 2, + "token_count": 38, + "parameters": [ + "state", + "p" + ], + "start_line": 711, + "end_line": 720, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "rk_hypergeometric_hyp", + "long_name": "rk_hypergeometric_hyp( rk_state * state , long good , long bad , long sample)", + "filename": "distributions.c", + "nloc": 19, + "complexity": 4, + "token_count": 129, + "parameters": [ + "state", + "good", + "bad", + "sample" + ], + "start_line": 722, + "end_line": 742, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "rk_hypergeometric_hrua", + "long_name": "rk_hypergeometric_hrua( rk_state * state , long good , long bad , long sample)", + "filename": "distributions.c", + "nloc": 36, + "complexity": 9, + "token_count": 416, + "parameters": [ + "state", + "good", + "bad", + "sample" + ], + "start_line": 748, + "end_line": 799, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "rk_hypergeometric", + "long_name": "rk_hypergeometric( rk_state * state , long good , long bad , long sample)", + "filename": "distributions.c", + "nloc": 10, + "complexity": 2, + "token_count": 52, + "parameters": [ + "state", + "good", + "bad", + "sample" + ], + "start_line": 803, + "end_line": 812, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "rk_triangular", + "long_name": "rk_triangular( rk_state * state , double left , double mode , double right)", + "filename": "distributions.c", + "nloc": 18, + "complexity": 2, + "token_count": 107, + "parameters": [ + "state", + "left", + "mode", + "right" + ], + "start_line": 814, + "end_line": 833, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "rk_logseries", + "long_name": "rk_logseries( rk_state * state , double p)", + "filename": "distributions.c", + "nloc": 12, + "complexity": 4, + "token_count": 102, + "parameters": [ + "state", + "p" + ], + "start_line": 835, + "end_line": 848, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "loggam", + "long_name": "loggam( double x)", + "filename": "distributions.c", + "nloc": 39, + "complexity": 7, + "token_count": 225, + "parameters": [ + "x" + ], + "start_line": 61, + "end_line": 100, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "rk_normal", + "long_name": "rk_normal( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 102, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_standard_exponential", + "long_name": "rk_standard_exponential( rk_state * state)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "state" + ], + "start_line": 107, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rk_exponential", + "long_name": "rk_exponential( rk_state * state , double scale)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "state", + "scale" + ], + "start_line": 113, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_uniform", + "long_name": "rk_uniform( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 118, + "end_line": 121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_standard_gamma", + "long_name": "rk_standard_gamma( rk_state * state , double shape)", + "filename": "distributions.c", + "nloc": 51, + "complexity": 11, + "token_count": 279, + "parameters": [ + "state", + "shape" + ], + "start_line": 123, + "end_line": 175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + }, + { + "name": "rk_gamma", + "long_name": "rk_gamma( rk_state * state , double shape , double scale)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "shape", + "scale" + ], + "start_line": 177, + "end_line": 180, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_beta", + "long_name": "rk_beta( rk_state * state , double a , double b)", + "filename": "distributions.c", + "nloc": 25, + "complexity": 5, + "token_count": 131, + "parameters": [ + "state", + "a", + "b" + ], + "start_line": 182, + "end_line": 210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "rk_chisquare", + "long_name": "rk_chisquare( rk_state * state , double df)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "state", + "df" + ], + "start_line": 212, + "end_line": 215, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_noncentral_chisquare", + "long_name": "rk_noncentral_chisquare( rk_state * state , double df , double nonc)", + "filename": "distributions.c", + "nloc": 7, + "complexity": 1, + "token_count": 49, + "parameters": [ + "state", + "df", + "nonc" + ], + "start_line": 217, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "rk_f", + "long_name": "rk_f( rk_state * state , double dfnum , double dfden)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "state", + "dfnum", + "dfden" + ], + "start_line": 226, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_noncentral_f", + "long_name": "rk_noncentral_f( rk_state * state , double dfnum , double dfden , double nonc)", + "filename": "distributions.c", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "state", + "dfnum", + "dfden", + "nonc" + ], + "start_line": 231, + "end_line": 235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rk_binomial_btpe", + "long_name": "rk_binomial_btpe( rk_state * state , long n , double p)", + "filename": "distributions.c", + "nloc": 126, + "complexity": 21, + "token_count": 1119, + "parameters": [ + "state", + "n", + "p" + ], + "start_line": 237, + "end_line": 375, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "rk_binomial_inversion", + "long_name": "rk_binomial_inversion( rk_state * state , long n , double p)", + "filename": "distributions.c", + "nloc": 41, + "complexity": 6, + "token_count": 239, + "parameters": [ + "state", + "n", + "p" + ], + "start_line": 377, + "end_line": 418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "rk_binomial", + "long_name": "rk_binomial( rk_state * state , long n , double p)", + "filename": "distributions.c", + "nloc": 27, + "complexity": 4, + "token_count": 104, + "parameters": [ + "state", + "n", + "p" + ], + "start_line": 420, + "end_line": 448, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "rk_negative_binomial", + "long_name": "rk_negative_binomial( rk_state * state , long n , double p)", + "filename": "distributions.c", + "nloc": 6, + "complexity": 1, + "token_count": 42, + "parameters": [ + "state", + "n", + "p" + ], + "start_line": 450, + "end_line": 456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "rk_poisson_mult", + "long_name": "rk_poisson_mult( rk_state * state , double lam)", + "filename": "distributions.c", + "nloc": 21, + "complexity": 3, + "token_count": 73, + "parameters": [ + "state", + "lam" + ], + "start_line": 458, + "end_line": 479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "rk_poisson_ptrs", + "long_name": "rk_poisson_ptrs( rk_state * state , double lam)", + "filename": "distributions.c", + "nloc": 32, + "complexity": 8, + "token_count": 236, + "parameters": [ + "state", + "lam" + ], + "start_line": 483, + "end_line": 519, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "rk_poisson", + "long_name": "rk_poisson( rk_state * state , double lam)", + "filename": "distributions.c", + "nloc": 11, + "complexity": 2, + "token_count": 38, + "parameters": [ + "state", + "lam" + ], + "start_line": 521, + "end_line": 531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "rk_standard_cauchy", + "long_name": "rk_standard_cauchy( rk_state * state)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "state" + ], + "start_line": 533, + "end_line": 536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_standard_t", + "long_name": "rk_standard_t( rk_state * state , double df)", + "filename": "distributions.c", + "nloc": 8, + "complexity": 1, + "token_count": 55, + "parameters": [ + "state", + "df" + ], + "start_line": 538, + "end_line": 546, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "rk_vonmises", + "long_name": "rk_vonmises( rk_state * state , double mu , double kappa)", + "filename": "distributions.c", + "nloc": 43, + "complexity": 8, + "token_count": 278, + "parameters": [ + "state", + "mu", + "kappa" + ], + "start_line": 548, + "end_line": 593, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "rk_pareto", + "long_name": "rk_pareto( rk_state * state , double a)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "a" + ], + "start_line": 595, + "end_line": 598, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_weibull", + "long_name": "rk_weibull( rk_state * state , double a)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "state", + "a" + ], + "start_line": 600, + "end_line": 603, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_power", + "long_name": "rk_power( rk_state * state , double a)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "state", + "a" + ], + "start_line": 605, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_laplace", + "long_name": "rk_laplace( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 13, + "complexity": 2, + "token_count": 66, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 610, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "rk_gumbel", + "long_name": "rk_gumbel( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 6, + "complexity": 1, + "token_count": 40, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 625, + "end_line": 631, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "rk_logistic", + "long_name": "rk_logistic( rk_state * state , double loc , double scale)", + "filename": "distributions.c", + "nloc": 6, + "complexity": 1, + "token_count": 40, + "parameters": [ + "state", + "loc", + "scale" + ], + "start_line": 633, + "end_line": 639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "rk_lognormal", + "long_name": "rk_lognormal( rk_state * state , double mean , double sigma)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "state", + "mean", + "sigma" + ], + "start_line": 641, + "end_line": 644, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_rayleigh", + "long_name": "rk_rayleigh( rk_state * state , double mode)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "state", + "mode" + ], + "start_line": 646, + "end_line": 649, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_wald", + "long_name": "rk_wald( rk_state * state , double mean , double scale)", + "filename": "distributions.c", + "nloc": 17, + "complexity": 2, + "token_count": 106, + "parameters": [ + "state", + "mean", + "scale" + ], + "start_line": 651, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "rk_zipf", + "long_name": "rk_zipf( rk_state * state , double a)", + "filename": "distributions.c", + "nloc": 15, + "complexity": 2, + "token_count": 119, + "parameters": [ + "state", + "a" + ], + "start_line": 670, + "end_line": 685, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "rk_geometric_search", + "long_name": "rk_geometric_search( rk_state * state , double p)", + "filename": "distributions.c", + "nloc": 17, + "complexity": 2, + "token_count": 70, + "parameters": [ + "state", + "p" + ], + "start_line": 687, + "end_line": 704, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "rk_geometric_inversion", + "long_name": "rk_geometric_inversion( rk_state * state , double p)", + "filename": "distributions.c", + "nloc": 4, + "complexity": 1, + "token_count": 35, + "parameters": [ + "state", + "p" + ], + "start_line": 706, + "end_line": 709, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "rk_geometric", + "long_name": "rk_geometric( rk_state * state , double p)", + "filename": "distributions.c", + "nloc": 10, + "complexity": 2, + "token_count": 38, + "parameters": [ + "state", + "p" + ], + "start_line": 711, + "end_line": 720, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "rk_hypergeometric_hyp", + "long_name": "rk_hypergeometric_hyp( rk_state * state , long good , long bad , long sample)", + "filename": "distributions.c", + "nloc": 19, + "complexity": 4, + "token_count": 129, + "parameters": [ + "state", + "good", + "bad", + "sample" + ], + "start_line": 722, + "end_line": 742, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "rk_hypergeometric_hrua", + "long_name": "rk_hypergeometric_hrua( rk_state * state , long good , long bad , long sample)", + "filename": "distributions.c", + "nloc": 36, + "complexity": 9, + "token_count": 416, + "parameters": [ + "state", + "good", + "bad", + "sample" + ], + "start_line": 748, + "end_line": 799, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "rk_hypergeometric", + "long_name": "rk_hypergeometric( rk_state * state , long good , long bad , long sample)", + "filename": "distributions.c", + "nloc": 10, + "complexity": 2, + "token_count": 52, + "parameters": [ + "state", + "good", + "bad", + "sample" + ], + "start_line": 803, + "end_line": 812, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "rk_triangular", + "long_name": "rk_triangular( rk_state * state , double left , double mode , double right)", + "filename": "distributions.c", + "nloc": 18, + "complexity": 2, + "token_count": 107, + "parameters": [ + "state", + "left", + "mode", + "right" + ], + "start_line": 814, + "end_line": 833, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "rk_logseries", + "long_name": "rk_logseries( rk_state * state , double p)", + "filename": "distributions.c", + "nloc": 12, + "complexity": 4, + "token_count": 102, + "parameters": [ + "state", + "p" + ], + "start_line": 835, + "end_line": 848, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "rk_beta", + "long_name": "rk_beta( rk_state * state , double a , double b)", + "filename": "distributions.c", + "nloc": 25, + "complexity": 5, + "token_count": 137, + "parameters": [ + "state", + "a", + "b" + ], + "start_line": 182, + "end_line": 210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + } + ], + "nloc": 681, + "complexity": 126, + "token_count": 4609, + "diff_parsed": { + "added": [ + " return X / (X + Y);" + ], + "deleted": [ + " return X;" + ] + } + } + ] + } +] \ No newline at end of file