diff --git "a/partition_72.json" "b/partition_72.json" new file mode 100644--- /dev/null +++ "b/partition_72.json" @@ -0,0 +1,106704 @@ +[ + { + "hash": "2ea2a8751198880820adaebd55f4e0f1979aeaea", + "msg": "Change the order of attribute lookup for object array types.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-11T07:18:26+00:00", + "author_timezone": 0, + "committer_date": "2006-01-11T07:18:26+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "45c7e2bb8135146245b5a980560e4d0a2b3a7868" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 6, + "insertions": 7, + "lines": 13, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/src/scalartypes.inc.src", + "new_path": "numpy/core/src/scalartypes.inc.src", + "filename": "scalartypes.inc.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -1849,23 +1849,24 @@ void_arrtype_hash(PyObject *obj)\n static PyObject *\n object_arrtype_getattro(PyObjectScalarObject *obj, PyObject *attr) {\n \tPyObject *res;\n-\t/* first look in generic type and then hand off to actual object */\n \n-\tres = PyObject_GenericGetAttr((PyObject *)obj, attr);\n+\t/* first look in object and then hand off to generic type */\n+\n+\tres = PyObject_GenericGetAttr(obj->obval, attr);\t\n \tif (res) return res;\n \tPyErr_Clear();\n-\treturn PyObject_GenericGetAttr(obj->obval, attr);\n+\treturn \tPyObject_GenericGetAttr((PyObject *)obj, attr);\n }\n \n static int\n object_arrtype_setattro(PyObjectScalarObject *obj, PyObject *attr, PyObject *val) {\n \tint res;\n-\t/* first look in generic type and then hand off to actual object */\n+\t/* first look in object and then hand off to generic type */\n \n-\tres = PyObject_GenericSetAttr((PyObject *)obj, attr, val);\n+\tres = PyObject_GenericSetAttr(obj->obval, attr, val);\n \tif (res >= 0) return res;\n \tPyErr_Clear();\n-\treturn PyObject_GenericSetAttr(obj->obval, attr, val);\n+\treturn PyObject_GenericSetAttr((PyObject *)obj, attr, val);\n }\n \n static int \n", + "added_lines": 7, + "deleted_lines": 6, + "source_code": "/* -*- c -*- */\n\nstatic int PyArrayScalar_Offset[PyArray_NTYPES+1];\n\n#define _SOFFSET_(obj, type_num) ((char *)(obj) + PyArrayScalar_Offset[(type_num)])\n\n/**begin repeat\n#name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,#\n#type=Bool, signed char, short, int, long, longlong, unsigned char, unsigned short, unsigned int, unsigned long, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, PyObject *,char#\n*/\ntypedef struct {\n\tPyObject_HEAD\n\t@type@ obval;\n} Py@name@ScalarObject;\n/**end repeat**/\n\n/* Inheritance established later when tp_bases is set (or tp_base for \n single inheritance) */\n\n/**begin repeat\n\n#name=number, integer, signedinteger, unsignedinteger, inexact, floating, complexfloating, flexible, \ncharacter#\n#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating, ComplexFloating, Flexible, Character#\n*/\n\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@_arrtype\",\t\t /*tp_name*/\n sizeof(PyObject),\t\t /*tp_basicsize*/\n};\n/**end repeat**/\n\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/* no error checking is performed -- ctypeptr must be same type as scalar */\n/* in case of flexible type, the data is not copied \n into ctypeptr which is expected to be a pointer to pointer */\n/*OBJECT_API\n Convert to c-type\n*/\nstatic void\nPyArray_ScalarAsCtype(PyObject *scalar, void *ctypeptr)\n{\n\tPyArray_Descr *typecode;\n\ttypecode = PyArray_DescrFromScalar(scalar);\n\t\n\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\tvoid **newptr = (void **)ctypeptr;\n\t\tswitch(typecode->type_num) {\n\t\tcase PyArray_STRING:\n\t\t\t*newptr = (void *)PyString_AS_STRING(scalar);\n\t\tcase PyArray_UNICODE:\n\t\t\t*newptr = (void *)PyUnicode_AS_DATA(scalar);\n\t\tdefault:\n\t\t\t*newptr = ((PyVoidScalarObject *)scalar)->obval;\n\t\t}\n\t\treturn;\n\t}\n\tmemcpy(ctypeptr, _SOFFSET_(scalar, typecode->type_num),\n\t typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn;\n}\n\n/* The output buffer must be large-enough to receive the value */\n/* Even for flexible types which is different from ScalarAsCtype\n where only a reference for flexible types is returned \n*/\n\n/*OBJECT_API\n Cast Scalar to c-type\n*/\nstatic int\nPyArray_CastScalarToCtype(PyObject *scalar, void *ctypeptr, \n\t\t\t PyArray_Descr *outcode)\n{\n\tPyArray_Descr* descr;\n\t\n\tdescr = PyArray_DescrFromScalar(scalar);\n\tif (PyTypeNum_ISEXTENDED(descr->type_num) ||\n\t PyTypeNum_ISEXTENDED(outcode->type_num)) {\n\t\tPyArrayObject *ain, *aout;\n\n\t\tain = (PyArrayObject *)PyArray_FromScalar(scalar, NULL);\n\t\tif (ain == NULL) {Py_DECREF(descr); return -1;}\n\t\taout = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t outcode,\n\t\t\t\t\t 0, NULL, \n\t\t\t\t\t NULL, ctypeptr, \n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\t\tif (aout == NULL) {Py_DECREF(ain); return -1;}\n\t\tdescr->f->cast[outcode->type_num](ain->data, \n\t\t\t\t\t aout->data, 1, ain, aout);\n\t\tPy_DECREF(ain);\n\t\tPy_DECREF(aout);\n\t}\n\telse {\n\t\tdescr->f->cast[outcode->type_num](_SOFFSET_(scalar, \n\t\t\t\t\t\t\t descr->type_num), \n\t\t\t\t\t ctypeptr, 1, NULL, NULL);\n\t}\n\tPy_DECREF(descr);\n\treturn 0;\n}\n\n/* 0-dim array from array-scalar object */\n/* always contains a copy of the data \n unless outcode is NULL, it is of void type and the referrer does\n not own it either.\n*/\n\n/* steals reference to outcode */\n/*OBJECT_API\n Get 0-dim array from scalar\n*/\nstatic PyObject *\nPyArray_FromScalar(PyObject *scalar, PyArray_Descr *outcode)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *r;\n\tchar *memptr;\n\tPyObject *ret;\n\n\t/* convert to 0-dim array of scalar typecode */\n\ttypecode = PyArray_DescrFromScalar(scalar);\n\tif ((typecode->type_num == PyArray_VOID) &&\t\t\t\\\n\t !(((PyVoidScalarObject *)scalar)->flags & OWNDATA) &&\t\\\n\t outcode == NULL) {\n\t\tr = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t typecode,\n\t\t\t\t\t 0, NULL, NULL,\n\t\t\t\t\t ((PyVoidScalarObject *)scalar)->obval,\n\t\t\t\t\t ((PyVoidScalarObject *)scalar)->flags,\n\t\t\t\t\t NULL);\n\t\tPyArray_BASE(r) = (PyObject *)scalar;\n\t\tPy_INCREF(scalar);\n\t\treturn r;\n\t}\n\tr = PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t typecode,\n\t\t\t\t 0, NULL, \n\t\t\t\t NULL, NULL, 0, NULL);\n\tif (r==NULL) {Py_XDECREF(outcode); return NULL;}\n\n\tswitch(typecode->type_num) {\n\tcase PyArray_STRING:\n\t\tmemptr = PyString_AS_STRING(scalar);\n\t\tbreak;\n\tcase PyArray_UNICODE:\n\t\tmemptr = (char *)PyUnicode_AS_DATA(scalar);\n\t\tbreak;\n\tdefault:\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tmemptr = (((PyVoidScalarObject *)scalar)->obval);\n\t\t}\n\t\telse {\n\t\t\tmemptr = _SOFFSET_(scalar, typecode->type_num);\n\t\t}\n\t\tbreak;\n\t}\n\n\tmemcpy(PyArray_DATA(r), memptr, PyArray_ITEMSIZE(r));\n\tif (PyArray_ISOBJECT(r)) {\n\t\tPy_INCREF(*((PyObject **)memptr));\n\t}\n\t\n\tif (outcode == NULL) return r;\n\t\n\tif (outcode->type_num == typecode->type_num) {\n\t\tif (!PyTypeNum_ISEXTENDED(typecode->type_num))\n\t\t\treturn r;\n\t\tif (outcode->elsize == typecode->elsize);\n\t\treturn r;\t\t\t\n\t}\n\t\n\t/* cast if necessary to desired output typecode */\n\tret = PyArray_CastToType((PyArrayObject *)r, outcode, 0);\n\tPy_DECREF(r);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n const size_t size = _PyObject_VAR_SIZE(type, nitems+1);\n\n obj = (PyObject *)_pya_malloc(size);\n\tmemset(obj, 0, size);\n\tif (type->tp_itemsize == 0)\n PyObject_INIT(obj, type);\n else\n (void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems);\n return obj;\n}\n\nstatic void\ngentype_dealloc(PyObject *v) \n{\n\tv->ob_type->tp_free(v);\n}\n\n\nstatic PyObject *\ngentype_power(PyObject *m1, PyObject *m2, PyObject *m3)\n{\n\tPyObject *arr, *ret, *arg2;\n\tchar *msg=\"unsupported operand type(s) for ** or pow()\";\n\t\n\tif (!PyArray_IsScalar(m1,Generic)) {\n\t\tif (PyArray_Check(m1)) {\n\t\t\tret = m1->ob_type->tp_as_number->nb_power(m1,m2, \n\t\t\t\t\t\t\t\t Py_None);\n\t\t}\n\t\telse {\n\t\t\tif (!PyArray_IsScalar(m2,Generic)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tarr = PyArray_FromScalar(m2, NULL);\n\t\t\tif (arr == NULL) return NULL;\n\t\t\tret = arr->ob_type->tp_as_number->nb_power(m1, arr,\n\t\t\t\t\t\t\t\t Py_None);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t\treturn ret;\n\t}\n\tif (!PyArray_IsScalar(m2, Generic)) {\n\t\tif (PyArray_Check(m2)) {\n\t\t\tret = m2->ob_type->tp_as_number->nb_power(m1,m2, \n\t\t\t\t\t\t\t\t Py_None);\n\t\t}\n\t\telse {\n\t\t\tif (!PyArray_IsScalar(m1, Generic)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tarr = PyArray_FromScalar(m1, NULL);\n\t\t\tif (arr == NULL) return NULL;\n\t\t\tret = arr->ob_type->tp_as_number->nb_power(arr, m2,\n\t\t\t\t\t\t\t\t Py_None);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t\treturn ret;\n\t}\n\tarr=arg2=NULL;\n\tarr = PyArray_FromScalar(m1, NULL);\n\targ2 = PyArray_FromScalar(m2, NULL);\t\n\tif (arr == NULL || arg2 == NULL) {\n\t\tPy_XDECREF(arr); Py_XDECREF(arg2); return NULL;\n\t}\n\tret = arr->ob_type->tp_as_number->nb_power(arr, arg2, Py_None);\n\tPy_DECREF(arr);\n\tPy_DECREF(arg2);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_generic_method(PyObject *self, PyObject *args, PyObject *kwds, \n\t\t char *str)\n{\n\tPyObject *arr, *meth, *ret;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tmeth = PyObject_GetAttrString(arr, str);\n\tif (meth == NULL) {Py_DECREF(arr); return NULL;}\n\tif (kwds == NULL) \n\t\tret = PyObject_CallObject(meth, args);\n\telse\n\t\tret = PyObject_Call(meth, args, kwds);\n\tPy_DECREF(meth);\n\tPy_DECREF(arr);\n if (ret && PyArray_Check(ret))\n return PyArray_Return((PyArrayObject *)ret);\n else\n return ret;\n}\n\n/**begin repeat\n\n#name=add, subtract, divide, remainder, divmod, lshift, rshift, and, xor, or, floor_divide, true_divide#\n#PYNAME=Add, Subtract, Divide, Remainder, Divmod, Lshift, Rshift, And, Xor, Or, FloorDivide, TrueDivide#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *m1, PyObject *m2)\n{\n\tPyObject *arr, *ret=NULL, *tup;\n\t\n\tif (!PyArray_IsScalar(m1, Generic)) {\n\t\tif (PyArray_Check(m1)) {\n\t\t\tret = m1->ob_type->tp_as_number->nb_@name@(m1,m2);\n\t\t}\n else {\n\t\t\tPyObject *newarr;\n\t\t\t/* Convert object to Array scalar and try again */\n\t\t\tnewarr = PyArray_FromAny(m1, NULL, 0, 0, 0);\n\t\t\tif (newarr!=NULL) {\n\t\t\t\tret = newarr->ob_type->tp_as_number->nb_@name@(newarr, m2);\n\t\t\t\tPy_DECREF(newarr);\n\t\t\t}\n\t\t\telse ret=NULL;\n\t\t}\n\t\treturn ret;\n\t}\n\tif (!PyArray_IsScalar(m2, Generic)) {\n\t\tif (PyArray_Check(m2)) {\n\t\t\tret = m2->ob_type->tp_as_number->nb_@name@(m1,m2);\n\t\t}\n\t\telse {\n\t\t\tPyObject *newarr;\n\t\t\t/* Convert object to Array and try again */\n\t\t\tnewarr = PyArray_FromAny(m2, NULL, 0, 0, 0);\n\t\t\tif (newarr!=NULL) {\n\t\t\t\tret = newarr->ob_type->tp_as_number->nb_@name@(m1, newarr);\n\t\t\t\tPy_DECREF(newarr);\n\t\t\t}\n\t\t\telse ret=NULL;\n\t\t}\n\t\treturn ret;\n\t}\n\tarr=tup=NULL;\n\tarr = PyArray_FromScalar(m1, NULL);\n\ttup = PyArray_FromScalar(m2, NULL);\n\tif (arr == NULL || tup == NULL) {\n\t\tPy_XDECREF(tup); Py_XDECREF(arr); return NULL;\n\t}\n\tret = arr->ob_type->tp_as_number->nb_@name@(arr, tup);\n\tPy_DECREF(arr);\n\tPy_DECREF(tup);\n\treturn ret;\n}\n/**end repeat**/\n\n\nstatic PyObject *\ngentype_multiply(PyObject *m1, PyObject *m2)\n{\n\tPyObject *arr, *ret=NULL, *tup;\n\tlong repeat;\n\n\tif (!PyArray_IsScalar(m1, Generic)) {\n\t\tif (PyArray_Check(m1)) {\n\t\t\tret = m1->ob_type->tp_as_number->nb_multiply(m1,m2);\n\t\t}\n\t\telse if ((m1->ob_type->tp_as_number == NULL) ||\n\t\t\t (m1->ob_type->tp_as_number->nb_multiply == NULL)) {\n\t\t\t/* Convert m2 to an int and assume sequence\n\t\t\t repeat */\n\t\t\trepeat = PyInt_AsLong(m2);\n\t\t\tif (repeat == -1 && PyErr_Occurred()) return NULL;\n\t\t\tret = PySequence_Repeat(m1, (int) repeat);\n\t\t\tif (ret == NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tarr = PyArray_FromScalar(m2, NULL);\n\t\t\t\tif (arr == NULL) return NULL;\n\t\t\t\tret = arr->ob_type->tp_as_number->\\\n\t\t\t\t\tnb_multiply(m1, arr);\n\t\t\t\tPy_DECREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyObject *newarr;\n\t\t\t/* Convert object to Array scalar and try again */\n\t\t\tnewarr = PyArray_FromAny(m1, NULL, 0, 0, 0);\n\t\t\tif (newarr!=NULL) {\n\t\t\t\tret = newarr->ob_type->tp_as_number->nb_multiply(newarr, m2);\n\t\t\t\tPy_DECREF(newarr);\n\t\t\t}\n\t\t\telse ret=NULL;\n\t\t}\n\t\treturn ret;\n\t}\n\tif (!PyArray_IsScalar(m2, Generic)) {\n\t\tif (PyArray_Check(m2)) {\n\t\t\tret = m2->ob_type->tp_as_number->nb_multiply(m1,m2);\n\t\t}\n\t\telse if ((m2->ob_type->tp_as_number == NULL) ||\n\t\t\t (m2->ob_type->tp_as_number->nb_multiply == NULL)) {\n\t\t\t/* Convert m1 to an int and assume sequence\n\t\t\t repeat */\n\t\t\trepeat = PyInt_AsLong(m1);\n\t\t\tif (repeat == -1 && PyErr_Occurred()) return NULL;\n\t\t\tret = PySequence_Repeat(m2, (int) repeat);\n\t\t\tif (ret == NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tarr = PyArray_FromScalar(m1, NULL);\n\t\t\t\tif (arr == NULL) return NULL;\n\t\t\t\tret = arr->ob_type->tp_as_number->\t\\\n\t\t\t\t\tnb_multiply(arr, m2);\n\t\t\t\tPy_DECREF(arr);\n\t\t\t}\t\t\t\n\t\t}\n\t\telse {\n\t\t\tPyObject *newarr;\n\t\t\t/* Convert object to Array scalar and try again */\n\t\t\tnewarr = PyArray_FromAny(m2, NULL, 0, 0, 0);\n\t\t\tif (newarr!=NULL) {\n\t\t\t\tret = newarr->ob_type->tp_as_number->nb_multiply(m1, newarr);\n\t\t\t\tPy_DECREF(newarr);\n\t\t\t}\n\t\t\telse ret =NULL;\n\t\t}\n\t\treturn ret;\n\t}\n\t/* Both are array scalar objects */\n\tarr=tup=NULL;\n\tarr = PyArray_FromScalar(m1, NULL);\n\ttup = PyArray_FromScalar(m2, NULL);\n\tif (arr == NULL || tup == NULL) {\n\t\tPy_XDECREF(tup); Py_XDECREF(arr); return NULL;\n\t}\n\tret = arr->ob_type->tp_as_number->nb_multiply(arr, tup);\n\tPy_DECREF(arr);\n\tPy_DECREF(tup);\n\treturn ret;\n\n}\n\n\n\n/**begin repeat\n\n#name=negative, absolute, invert, int, long, float, oct, hex#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *m1)\n{\n\tPyObject *arr, *ret;\n\n\tarr = PyArray_FromScalar(m1, NULL);\n\tif (arr == NULL) return NULL;\n\tret = arr->ob_type->tp_as_number->nb_@name@(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n/**end repeat**/\n\nstatic int\ngentype_nonzero_number(PyObject *m1)\n{\n\tPyObject *arr;\n\tint ret;\n\n\tarr = PyArray_FromScalar(m1, NULL);\n\tif (arr == NULL) return -1;\n\tret = arr->ob_type->tp_as_number->nb_nonzero(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_str(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret, *tmp;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tif (arr==NULL) return NULL;\n\tret = PyObject_Str((tmp=arr->descr->f->getitem(arr->data, arr)));\n\tPy_DECREF(arr);\n\tPy_XDECREF(tmp);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_repr(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret, *tmp ;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tif (arr==NULL) return NULL;\n\tret = PyObject_Repr((tmp=arr->descr->f->getitem(arr->data, arr)));\n\tPy_DECREF(arr);\n\tPy_XDECREF(tmp);\n\treturn ret;\n}\n\nstatic void\nformat_longdouble(char *buf, size_t buflen, longdouble val, int precision)\n{\n register char *cp;\n\n PyOS_snprintf(buf, buflen, \"%.*\" LONGDOUBLE_FMT, precision, val);\n cp = buf;\n if (*cp == '-')\n cp++;\n for (; *cp != '\\0'; cp++) {\n if (!isdigit(Py_CHARMASK(*cp)))\n break;\n }\n if (*cp == '\\0') {\n *cp++ = '.';\n *cp++ = '0';\n *cp++ = '\\0';\n }\n}\n\n#if SIZEOF_LONGDOUBLE == SIZEOF_DOUBLE\n#define PREC_REPR 15\n#define PREC_STR 15\n#else\n#define PREC_REPR 21\n#define PREC_STR 21\n#endif\n\nstatic PyObject *\nlongdoubletype_repr(PyObject *self)\n{\n static char buf[100];\n format_longdouble(buf, sizeof(buf), ((PyLongDoubleScalarObject *)self)->obval, PREC_REPR);\n return PyString_FromString(buf);\n}\n\nstatic PyObject *\nclongdoubletype_repr(PyObject *self)\n{\n static char buf1[100];\n static char buf2[100];\n\tstatic char buf3[202];\n clongdouble x;\n x = ((PyCLongDoubleScalarObject *)self)->obval;\n format_longdouble(buf1, sizeof(buf1), x.real, PREC_REPR);\n format_longdouble(buf2, sizeof(buf2), x.imag, PREC_REPR);\n\n\tsnprintf(buf3, sizeof(buf3), \"(%s+%sj)\", buf1, buf2);\n\treturn PyString_FromString(buf3);\n}\n\n#define longdoubletype_str longdoubletype_repr\n#define clongdoubletype_str clongdoubletype_repr\n\n/** Could improve this with a PyLong_FromLongDouble(longdouble ldval)\n but this would need some more work...\n**/\n\n/**begin repeat\n\n#name=(int, long, hex, oct, float)*2#\n#KIND=(Long*4, Float)*2#\n#char=,,,,,c*5#\n#CHAR=,,,,,C*5#\n#POST=,,,,,.real*5#\n*/\nstatic PyObject *\n@char@longdoubletype_@name@(PyObject *self)\n{\n\tdouble dval;\n\tPyObject *obj, *ret;\n\t\n\tdval = (double)(((Py@CHAR@LongDoubleScalarObject *)self)->obval)@POST@;\n\tobj = Py@KIND@_FromDouble(dval);\n\tret = obj->ob_type->tp_as_number->nb_@name@(obj);\n\tPy_DECREF(obj);\n\treturn ret;\n}\n/**end repeat**/\n\n\nstatic PyObject *gentype_copy(PyObject *, PyObject *);\n\nstatic PyNumberMethods gentype_as_number = {\n (binaryfunc)gentype_add,\t\t /*nb_add*/\n (binaryfunc)gentype_subtract,\t\t /*nb_subtract*/\n (binaryfunc)gentype_multiply,\t\t /*nb_multiply*/\n (binaryfunc)gentype_divide,\t\t /*nb_divide*/\n (binaryfunc)gentype_remainder,\t /*nb_remainder*/\n (binaryfunc)gentype_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)gentype_power,\t\t /*nb_power*/\n (unaryfunc)gentype_negative,\t \n (unaryfunc)gentype_copy,\t\t /*nb_pos*/ \n (unaryfunc)gentype_absolute,\t\t /*(unaryfunc)gentype_abs,*/\n (inquiry)gentype_nonzero_number,\t\t /*nb_nonzero*/\n (unaryfunc)gentype_invert,\t\t /*nb_invert*/\n (binaryfunc)gentype_lshift,\t /*nb_lshift*/\n (binaryfunc)gentype_rshift,\t /*nb_rshift*/\n (binaryfunc)gentype_and,\t /*nb_and*/\n (binaryfunc)gentype_xor,\t /*nb_xor*/\n (binaryfunc)gentype_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)gentype_int,\t\t /*nb_int*/\n (unaryfunc)gentype_long,\t\t /*nb_long*/\n (unaryfunc)gentype_float,\t\t /*nb_float*/\n (unaryfunc)gentype_oct,\t\t /*nb_oct*/\n (unaryfunc)gentype_hex,\t\t /*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)gentype_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)gentype_true_divide,\t /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n\n};\n\nstatic PyObject *\ngentype_richcompare(PyObject *self, PyObject *other, int cmp_op) \n{\n\n\tPyObject *arr, *ret;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tret = arr->ob_type->tp_richcompare(arr, other, cmp_op);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_ndim_get(PyObject *self)\n{\n\treturn PyInt_FromLong(0);\n}\n\nstatic PyObject *\ngentype_flags_get(PyObject *self)\n{\n\tstatic int flags=CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n\n return PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, flags, 1);\n}\n\nstatic PyObject *\nvoidtype_flags_get(PyVoidScalarObject *self)\n{\n\treturn PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 1);\n}\n\nstatic PyObject *\nvoidtype_dtypedescr_get(PyVoidScalarObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n\nstatic PyObject *\ngentype_shape_get(PyObject *self)\n{\n\treturn PyTuple_New(0);\n}\n\n/*\nstatic int\ngentype_shape_set(PyObject *self, PyObject *val)\n{\n\tif (!PyTuple_Check(val) || PyTuple_GET_SIZE(val) > 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \\\n\t\t\t\t\"invalid shape for scalar\");\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n*/\n\nstatic PyObject *\ngentype_dataptr_get(PyObject *self)\n{\n\treturn Py_BuildValue(\"NO\",PyString_FromString(\"\"),Py_True);\n}\n\n\nstatic PyObject *\ngentype_data_get(PyObject *self)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\n\ttypecode = PyArray_DescrFromScalar(self);\n\tret = PyBuffer_FromObject(self, 0, typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\n\nstatic PyObject *\ngentype_itemsize_get(PyObject *self)\n{\t\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\n\ttypecode = PyArray_DescrFromScalar(self);\n\tret = PyInt_FromLong((long) typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_size_get(PyObject *self)\n{\n\treturn PyInt_FromLong(1);\n}\n\n\nstatic PyObject *\ngentype_typechar_get(PyObject *self)\n{\n\tPyArray_Descr *descr;\n\tchar type;\n\tint elsize;\n\n\tdescr = PyArray_DescrFromScalar(self);\n\ttype = descr->type;\n\telsize = descr->elsize;\n\tPy_DECREF(descr);\n\tif (PyArray_IsScalar(self, Flexible)) \n\t\treturn PyString_FromFormat(\"%c%d\", (int)type, elsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&type, 1);\n}\n\nstatic void\ngentype_struct_free(void *ptr, void *arr)\n{\n Py_DECREF((PyObject *)arr);\n _pya_free(ptr);\n}\n\nstatic PyObject *\ngentype_struct_get(PyObject *self)\n{\n PyArrayObject *arr;\n PyArrayInterface *inter;\n \n arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = 0;\n inter->flags = arr->flags;\n inter->typekind = arr->descr->kind;\n inter->itemsize = arr->descr->elsize;\n inter->strides = NULL;\n inter->shape = NULL;\n inter->data = arr->data;\n return PyCObject_FromVoidPtrAndDesc(inter, arr, gentype_struct_free);\n}\n\nstatic PyObject *\ngentype_typestr_get(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tret = PyObject_GetAttrString((PyObject *)arr, \"dtypestr\");\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_descr_get(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tret = PyObject_GetAttrString((PyObject *)arr, \"__array_descr__\");\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\n\nstatic PyObject *\ngentype_type_get(PyObject *self)\n{\n Py_INCREF(self->ob_type);\n\treturn (PyObject *)self->ob_type;\n}\n\nstatic PyObject *\ngentype_typedescr_get(PyObject *self)\n{\n\treturn (PyObject *)PyArray_DescrFromScalar(self);\n}\n\n\nstatic PyObject *\ngentype_base_get(PyObject *self)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic PyArray_Descr *\n_realdescr_fromcomplexscalar(PyObject *self, int *typenum)\n{\n\tif PyArray_IsScalar(self, CDouble) {\n\t\t*typenum = PyArray_CDOUBLE;\n\t\treturn PyArray_DescrFromType(PyArray_DOUBLE);\n\t}\n\tif PyArray_IsScalar(self, CFloat) {\n\t\t*typenum = PyArray_CFLOAT;\n\t\treturn PyArray_DescrFromType(PyArray_FLOAT);\n\t}\n\tif PyArray_IsScalar(self, CLongDouble) {\n\t\t*typenum = PyArray_CLONGDOUBLE;\n\t\treturn PyArray_DescrFromType(PyArray_LONGDOUBLE);\n\t}\n\treturn NULL;\n}\n\nstatic PyObject *\ngentype_real_get(PyObject *self)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\tint typenum;\n\n\tif (PyArray_IsScalar(self, ComplexFloating)) {\n\t\ttypecode = _realdescr_fromcomplexscalar(self, &typenum);\n\t\tret = PyArray_Scalar(_SOFFSET_(self, typenum), typecode,\n\t\t\t\t NULL);\n\t\tPy_DECREF(typecode);\n\t\treturn ret;\n\t}\n\telse if PyArray_IsScalar(self, Object) {\n\t\tPyObject *obj = ((PyObjectScalarObject *)self)->obval;\n\t\tret = PyObject_GetAttrString(obj, \"real\");\n\t\tif (ret != NULL) return ret;\n\t\tPyErr_Clear();\n\t}\n\tPy_INCREF(self);\n\treturn (PyObject *)self;\n}\n\nstatic PyObject *\ngentype_imag_get(PyObject *self)\n{\t\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\t\n\tint typenum;\n\t\n\ttypecode = _realdescr_fromcomplexscalar(self, &typenum);\n\tif (PyArray_IsScalar(self, ComplexFloating)) {\n\t\tret = PyArray_Scalar(_SOFFSET_(self, typenum)\t\t\\\n\t\t\t\t + typecode->elsize, typecode, NULL);\n\t}\n\telse if PyArray_IsScalar(self, Object) {\n\t\tPyObject *obj = ((PyObjectScalarObject *)self)->obval;\n\t\tPyArray_Descr *newtype;\n\t\tret = PyObject_GetAttrString(obj, \"imag\");\n\t\tif (ret == NULL) {\n\t\t\tPyErr_Clear();\n\t\t\tobj = PyInt_FromLong(0);\n\t\t\tnewtype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\t\tret = PyArray_Scalar((char *)&obj, newtype, NULL);\n\t\t\tPy_DECREF(newtype);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tchar *temp;\n\t\ttemp = PyDataMem_NEW(typecode->elsize);\n\t\tmemset(temp, '\\0', typecode->elsize);\n\t\tret = PyArray_Scalar(temp, typecode, NULL);\n\t\tPyDataMem_FREE(temp);\n\t}\n\t\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_flat_get(PyObject *self)\n{\n\tPyObject *ret, *arr;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tret = PyArray_IterNew(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyGetSetDef gentype_getsets[] = {\n {\"ndim\", \n\t (getter)gentype_ndim_get, \n\t (setter) 0, \n\t \"number of array dimensions\"},\n {\"flags\", \n\t (getter)gentype_flags_get, \n\t (setter)0, \n\t \"integer value of flags\"},\n {\"shape\", \n\t (getter)gentype_shape_get, \n\t (setter)0, \n\t \"tuple of array dimensions\"},\n {\"strides\", \n\t (getter)gentype_shape_get, \n\t (setter) 0, \n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)gentype_data_get, \n\t (setter) 0, \n\t \"pointer to start of data\"},\n {\"itemsize\", \n\t (getter)gentype_itemsize_get, \n\t (setter)0, \n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)gentype_size_get,\n (setter)0,\n \"number of elements in the gentype\"},\n {\"nbytes\",\n (getter)gentype_itemsize_get,\n (setter)0,\n \"length of item in bytes\"},\n\t{\"base\",\n\t (getter)gentype_base_get,\n\t (setter)0,\n\t \"base object\"},\n {\"dtype\", \n\t (getter)gentype_type_get, \n\t (setter)0, \n\t \"get gentype type class\"},\n\t{\"dtypechar\",\n\t (getter)gentype_typechar_get,\n\t (setter)0,\n\t \"get gentype type character code\"},\n\t{\"dtypestr\",\n\t (getter)gentype_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n\t{\"dtypedescr\",\n\t (getter)gentype_typedescr_get,\n\t NULL,\n\t \"get array data-descriptor\"},\n {\"real\", \n\t (getter)gentype_real_get, \n\t (setter)0,\n\t \"real part of scalar\"},\n {\"imag\", \n\t (getter)gentype_imag_get, \n\t (setter)0, \n\t \"imaginary part of scalar\"},\n\t{\"flat\", \n\t (getter)gentype_flat_get, \n\t (setter)0, \n\t \"a 1-d view of scalar\"}, \n\t{\"__array_data__\", \n\t (getter)gentype_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)gentype_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)gentype_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)gentype_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)gentype_shape_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)gentype_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t/* Does not have __array_priority__ because it is not a subtype.\n\t */\n \t{NULL, NULL, NULL, NULL} /* Sentinel */\n};\n\n\n/* 0-dim array from scalar object */\n\nstatic char doc_getarray[] = \"sc.__array__(|type) return 0-dim array\";\n\nstatic PyObject *\ngentype_getarray(PyObject *scalar, PyObject *args) \n{\n\tPyArray_Descr *outcode=NULL;\n\tPyObject *ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", &PyArray_DescrConverter,\n\t\t\t &outcode)) return NULL;\n\tret = PyArray_FromScalar(scalar, outcode);\n\treturn ret;\n}\n\nstatic char doc_sc_wraparray[] = \"sc.__array_wrap__(obj) return scalar from array\";\n\nstatic PyObject *\ngentype_wraparray(PyObject *scalar, PyObject *args)\n{\n\tPyObject *arr;\n\n\tif (PyTuple_Size(args) < 1) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"only accepts 1 argument.\");\n\t\treturn NULL;\n\t}\n\tarr = PyTuple_GET_ITEM(args, 0);\n\tif (!PyArray_Check(arr)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"can only be called with ndarray object\");\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_Scalar(PyArray_DATA(arr), PyArray_DESCR(arr), arr);\n}\n\n\n/**begin repeat\n\n#name=tolist, item, tostring, astype, copy, resize, __deepcopy__, choose, searchsorted, argmax, argmin, reshape, view, swapaxes, max, min, ptp, conj, conjugate, nonzero, all, any, flatten, ravel, fill, transpose, newbyteorder#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *self, PyObject *args)\n{\n\treturn gentype_generic_method(self, args, NULL, \"@name@\");\n}\n/**end repeat**/\n\nstatic PyObject *\ngentype_squeeze(PyObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\tPy_INCREF(self);\n\treturn self;\n}\n\nstatic int\ngentype_getreadbuf(PyObject *, int, void **);\n\nstatic PyObject *\ngentype_byteswap(PyObject *self, PyObject *args)\n{\n\tBool inplace=FALSE;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter, &inplace))\n\t\treturn NULL;\n\t\n\tif (inplace) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot byteswap a scalar in-place\");\n\t\treturn NULL;\n\t}\n\telse {\n\t\t/* get the data, copyswap it and pass it to a new Array scalar\n\t\t */\n\t\tchar *data;\n\t\tint numbytes;\n\t\tPyArray_Descr *descr;\n\t\tPyObject *new;\n\t\tchar *newmem;\n\n\t\tnumbytes = gentype_getreadbuf(self, 0, (void **)&data);\n\t\tdescr = PyArray_DescrFromScalar(self);\n\t\tnewmem = _pya_malloc(descr->elsize);\n\t\tif (newmem == NULL) {Py_DECREF(descr); return PyErr_NoMemory();}\n\t\telse memcpy(newmem, data, descr->elsize);\n\t\tdescr->f->copyswap(newmem, NULL, 1, descr->elsize);\n\t\tnew = PyArray_Scalar(newmem, descr, NULL);\n\t\t_pya_free(newmem);\n\t\tPy_DECREF(descr);\n\t\treturn new;\n\t}\n}\n\n\n/**begin repeat\n\n#name=take, getfield, put, putmask, repeat, tofile, mean, trace, diagonal, clip, std, var, sum, cumsum, prod, cumprod, compress, sort, argsort#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\treturn gentype_generic_method(self, args, kwds, \"@name@\");\n}\n/**end repeat**/\n\nstatic PyObject *\nvoidtype_getfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyObject *ret;\n\n\tret = gentype_generic_method((PyObject *)self, args, kwds, \"getfield\");\n\tif (!ret) return ret;\n\tif (PyArray_IsScalar(ret, Generic) &&\t\\\n\t (!PyArray_IsScalar(ret, Void))) {\n\t\tPyArray_Descr *new;\n\t\tif (!PyArray_ISNBO(self->descr->byteorder)) {\n\t\t\tnew = PyArray_DescrFromScalar(ret);\n\t\t\tnew->f->copyswap(_SOFFSET_(ret, \n\t\t\t\t\t\t new->type_num),\n\t\t\t\t\t NULL, 1, new->elsize);\n\t\t\tPy_DECREF(new);\n\t\t}\n\t}\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_setfield(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\t\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"Can't set fields in a non-void array scalar.\");\n\treturn NULL;\n}\t\n\nstatic PyObject *\nvoidtype_setfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *typecode;\n\tint offset = 0;\n\tPyObject *value, *src;\n\tint mysize;\n\tchar *dptr;\n\tstatic char *kwlist[] = {\"value\", \"dtype\", \"offset\", 0};\n\t\n\tif ((self->flags & WRITEABLE) != WRITEABLE) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"Can't write to memory\");\n\t\treturn NULL;\n\t}\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO&|i\", kwlist,\n\t\t\t\t\t &value,\n\t\t\t\t\t PyArray_DescrConverter, \n\t\t\t\t\t &typecode, &offset)) return NULL;\n\n\tmysize = self->ob_size;\n\t\n\tif (offset < 0 || (offset + typecode->elsize) > mysize) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need 0 <= offset <= %d for requested type \" \\\n\t\t\t \"but received offset = %d\",\n\t\t\t mysize-typecode->elsize, offset);\n\t\tPy_DECREF(typecode);\n\t\treturn NULL;\n\t}\t\n\n\tdptr = self->obval + offset;\n\n\t/* Copy data from value to correct place in dptr */\n src = PyArray_FromAny(value, typecode, 0, 0, CARRAY_FLAGS);\n if (src == NULL) return NULL;\n\ttypecode->f->copyswap(dptr, PyArray_DATA(src), \n\t\t\t !PyArray_ISNBO(self->descr->byteorder),\n\t\t\t PyArray_ITEMSIZE(src));\n\tPy_DECREF(src);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic PyObject *\ngentype_reduce(PyObject *self, PyObject *args)\n{\n\tPyObject *ret=NULL, *obj=NULL, *mod=NULL;\n\tconst char *buffer; \n\tint buflen;\n\n\t/* Return a tuple of (callable object, arguments) */\n\n\tret = PyTuple_New(2);\n\tif (ret == NULL) return NULL;\t\n\tif (PyObject_AsReadBuffer(self, (const void **)&buffer, &buflen)<0) {\n\t\tPy_DECREF(ret); return NULL;\n\t}\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) return NULL;\n\tobj = PyObject_GetAttrString(mod, \"scalar\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) return NULL;\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tobj = PyObject_GetAttrString((PyObject *)self, \"dtypedescr\");\n\tif PyArray_IsScalar(self, Object) {\n\t\tmod = ((PyObjectScalarObject *)self)->obval;\n\t\tPyTuple_SET_ITEM(ret, 1,\n\t\t\t\t Py_BuildValue(\"NO\", obj, mod));\n\t}\n\telse {\n\t\tmod = PyString_FromStringAndSize(buffer, buflen);\n\t\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t\t Py_BuildValue(\"NN\", obj, mod));\n\t}\n\treturn ret;\n}\n\n/* ignores everything */\nstatic PyObject *\ngentype_setstate(PyObject *self, PyObject *args)\n{\n\tPy_INCREF(Py_None);\n\treturn (Py_None);\n}\n\nstatic PyObject *\ngentype_dump(PyObject *self, PyObject *args)\n{\n\tPyObject *file=NULL;\n\tint ret;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &file))\n\t\treturn NULL;\n\tret = PyArray_Dump(self, file, 2);\n\tif (ret < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyObject *\ngentype_dumps(PyObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\"))\n\t\treturn NULL;\n\treturn PyArray_Dumps(self, 2);\n}\n\n\n/* setting flags cannot be done for scalars */\nstatic PyObject *\ngentype_setflags(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* need to fill in doc-strings for these methods on import -- copy from \n array docstrings \n*/\nstatic PyMethodDef gentype_methods[] = {\n {\"tolist\",\t (PyCFunction)gentype_tolist,\t1, NULL},\n {\"item\", (PyCFunction)gentype_item, METH_VARARGS, NULL},\n\t{\"tofile\", (PyCFunction)gentype_tofile, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"tostring\", (PyCFunction)gentype_tostring, METH_VARARGS, NULL},\n {\"byteswap\", (PyCFunction)gentype_byteswap,1, NULL},\n {\"astype\", (PyCFunction)gentype_astype, 1, NULL},\n\t{\"getfield\", (PyCFunction)gentype_getfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{\"setfield\", (PyCFunction)gentype_setfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n {\"copy\", (PyCFunction)gentype_copy, 1, NULL}, \n {\"resize\", (PyCFunction)gentype_resize, 1, NULL}, \n\n\t{\"__array__\", (PyCFunction)gentype_getarray, 1, doc_getarray},\n\t{\"__array_wrap__\", (PyCFunction)gentype_wraparray, 1, doc_sc_wraparray},\n\n /* for the copy module */\n {\"__copy__\", (PyCFunction)gentype_copy, 1, NULL},\n {\"__deepcopy__\", (PyCFunction)gentype___deepcopy__, 1, NULL},\n\n\n {\"__reduce__\", (PyCFunction) gentype_reduce, 1, NULL},\t\n\t/* For consistency does nothing */\n\t{\"__setstate__\", (PyCFunction) gentype_setstate, 1, NULL},\n\n\t{\"dumps\", (PyCFunction) gentype_dumps, 1, NULL},\n\t{\"dump\", (PyCFunction) gentype_dump, 1, NULL},\n\n\t/* Methods for array */\n\t{\"fill\", (PyCFunction)gentype_fill,\n\t METH_VARARGS, NULL},\n\t{\"transpose\",\t(PyCFunction)gentype_transpose, \n\t METH_VARARGS, NULL},\n\t{\"take\",\t(PyCFunction)gentype_take, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"put\",\t(PyCFunction)gentype_put, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"putmask\",\t(PyCFunction)gentype_putmask, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"repeat\",\t(PyCFunction)gentype_repeat, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"choose\",\t(PyCFunction)gentype_choose, \n\t METH_VARARGS, NULL},\t\n\t{\"sort\",\t(PyCFunction)gentype_sort, \n\t METH_VARARGS, NULL},\n\t{\"argsort\",\t(PyCFunction)gentype_argsort, \n\t METH_VARARGS, NULL},\n\t{\"searchsorted\", (PyCFunction)gentype_searchsorted, \n\t METH_VARARGS, NULL},\t\n\t{\"argmax\",\t(PyCFunction)gentype_argmax, \n\t METH_VARARGS, NULL},\n\t{\"argmin\", (PyCFunction)gentype_argmin,\n\t METH_VARARGS, NULL},\n\t{\"reshape\",\t(PyCFunction)gentype_reshape, \n\t METH_VARARGS, NULL},\n\t{\"squeeze\",\t(PyCFunction)gentype_squeeze, \n\t METH_VARARGS, NULL},\n\t{\"view\", (PyCFunction)gentype_view, \n\t METH_VARARGS, NULL},\n\t{\"swapaxes\", (PyCFunction)gentype_swapaxes,\n\t METH_VARARGS, NULL},\n\t{\"max\", (PyCFunction)gentype_max,\n\t METH_VARARGS, NULL},\n\t{\"min\", (PyCFunction)gentype_min,\n\t METH_VARARGS, NULL},\n\t{\"ptp\", (PyCFunction)gentype_ptp,\n\t METH_VARARGS, NULL},\n\t{\"mean\", (PyCFunction)gentype_mean,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"trace\", (PyCFunction)gentype_trace,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"diagonal\", (PyCFunction)gentype_diagonal,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"clip\", (PyCFunction)gentype_clip,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"conj\", (PyCFunction)gentype_conj,\n\t METH_VARARGS, NULL},\n\t{\"conjugate\", (PyCFunction)gentype_conjugate,\n\t METH_VARARGS, NULL},\n\t{\"nonzero\", (PyCFunction)gentype_nonzero,\n\t METH_VARARGS, NULL},\n\t{\"std\", (PyCFunction)gentype_std,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"var\", (PyCFunction)gentype_var,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"sum\", (PyCFunction)gentype_sum,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"cumsum\", (PyCFunction)gentype_cumsum,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"prod\", (PyCFunction)gentype_prod,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"cumprod\", (PyCFunction)gentype_cumprod,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"all\", (PyCFunction)gentype_all,\n\t METH_VARARGS, NULL},\n\t{\"any\", (PyCFunction)gentype_any,\n\t METH_VARARGS, NULL},\n\t{\"compress\", (PyCFunction)gentype_compress,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"flatten\", (PyCFunction)gentype_flatten,\n\t METH_VARARGS, NULL},\n\t{\"ravel\", (PyCFunction)gentype_ravel,\n\t METH_VARARGS, NULL},\n\t{\"setflags\", (PyCFunction)gentype_setflags,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"newbyteorder\", (PyCFunction)gentype_newbyteorder,\n\t METH_VARARGS, NULL},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\nstatic PyGetSetDef voidtype_getsets[] = {\n {\"flags\", \n\t (getter)voidtype_flags_get, \n\t (setter)0, \n\t \"integer value of flags\"},\n\t{\"dtypedescr\",\n\t (getter)voidtype_dtypedescr_get,\n\t (setter)0,\n\t \"dtypedescr object\"},\n\t{NULL, NULL}\n};\n\nstatic PyMethodDef voidtype_methods[] = {\n\t{\"getfield\", (PyCFunction)voidtype_getfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{\"setfield\", (PyCFunction)voidtype_setfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{NULL, NULL}\n};\n\n/************* As_mapping functions for void array scalar ************/\n\n\nstatic int\nvoidtype_length(PyVoidScalarObject *self) \n{\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\treturn 0;\n\t}\n\telse { /* return the number of fields */\n\t\tPyObject *key;\n\t\tPyObject *flist;\n\t\tkey = PyInt_FromLong(-1);\n\t\tflist = PyDict_GetItem(self->descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!flist) return 0;\n\t\treturn PyList_GET_SIZE(flist);\n\t}\n}\n\n/* get field by name or number */\nstatic PyObject *\nvoidtype_subscript(PyVoidScalarObject *self, PyObject *ind)\n{\n\tint n, m;\n\tchar *msg = \"invalid index\";\n\tPyObject *flist=NULL, *key, *fieldinfo;\n\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"can't index void scalar without fields\");\n\t\treturn NULL;\n\t}\n\n\tif (PyString_Check(ind) || PyUnicode_Check(ind)) {\n\t\t/* look up in fields */\n\t\tfieldinfo = PyDict_GetItem(self->descr->fields, ind);\n\t\tif (!fieldinfo) {\n\t\t\tPyErr_SetString(PyExc_IndexError, msg);\n\t\t\treturn NULL;\n\t\t}\n\t\treturn voidtype_getfield(self, fieldinfo, NULL);\n\t}\n\t\n\t/* try to convert it to a number */\n\tn = PyArray_PyIntAsIntp(ind);\n\tif (error_converting(n)) {\n\t\tPyErr_Clear();\n\t\tgoto fail;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tflist = PyDict_GetItem(self->descr->fields, key);\n\tPy_DECREF(key);\n\tif (!flist) m = 0; \n\tm = PyList_GET_SIZE(flist);\n\tif (n < 0) n += m;\n\tif (n < 0 || n >= m) goto fail;\n\tfieldinfo = PyDict_GetItem(self->descr->fields, \n\t\t\t\t PyList_GET_ITEM(flist, n));\n\treturn voidtype_getfield(self, fieldinfo, NULL);\n\n fail:\n\tPyErr_SetString(PyExc_IndexError, msg);\n\treturn NULL;\n}\n\nstatic int\nvoidtype_ass_subscript(PyVoidScalarObject *self, PyObject *ind, PyObject *val) \n{\n\tint n, m;\n\tchar *msg = \"invalid index\";\n\tPyObject *flist=NULL, *key, *fieldinfo, *newtup;\n\tPyObject *res;\n\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"can't index void scalar without fields\");\n\t\treturn -1;\n\t}\n\n\tif (PyString_Check(ind) || PyUnicode_Check(ind)) {\n\t\t/* look up in fields */\n\t\tfieldinfo = PyDict_GetItem(self->descr->fields, ind);\n\t\tif (!fieldinfo) {\n\t\t\tPyErr_SetString(PyExc_IndexError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tnewtup = Py_BuildValue(\"(OOO)\", val, \n\t\t\t\t PyTuple_GET_ITEM(fieldinfo, 0),\n\t\t\t\t PyTuple_GET_ITEM(fieldinfo, 1));\n\t\tres = voidtype_setfield(self, newtup, NULL);\n\t\tPy_DECREF(newtup);\n\t\tif (!res) return -1;\n\t\tPy_DECREF(res);\n\t\treturn 0;\n\t}\n\t\n\t/* try to convert it to a number */\n\tn = PyArray_PyIntAsIntp(ind);\n\tif (error_converting(n)) {\n\t\tPyErr_Clear();\n\t\tgoto fail;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tflist = PyDict_GetItem(self->descr->fields, key);\n\tPy_DECREF(key);\n\tif (!flist) m = 0; \n\tm = PyList_GET_SIZE(flist);\n\tif (n < 0) n += m;\n\tif (n < 0 || n >= m) goto fail;\n\tfieldinfo = PyDict_GetItem(self->descr->fields, \n\t\t\t\t PyList_GET_ITEM(flist, n));\n\tnewtup = Py_BuildValue(\"(OOO)\", val, \n\t\t\t PyTuple_GET_ITEM(fieldinfo, 0),\n\t\t\t PyTuple_GET_ITEM(fieldinfo, 1));\n\tres = voidtype_setfield(self, fieldinfo, NULL);\n\tPy_DECREF(newtup);\n\tif (!res) return -1;\n\tPy_DECREF(res);\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_IndexError, msg);\n\treturn -1;\n}\n\nstatic PyMappingMethods voidtype_as_mapping = {\n (inquiry)voidtype_length,\t\t /*mp_length*/\n (binaryfunc)voidtype_subscript,\t /*mp_subscript*/\n (objobjargproc)voidtype_ass_subscript,\t /*mp_ass_subscript*/\n};\n\n\nstatic int\ngentype_getreadbuf(PyObject *self, int segment, void **ptrptr)\n{\n\tint numbytes;\n\tPyArray_Descr *outcode;\n\t\n\tif (segment != 0) {\n\t\tPyErr_SetString(PyExc_SystemError, \n\t\t\t\t\"Accessing non-existent array segment\");\n\t\treturn -1;\n\t}\n\n\toutcode = PyArray_DescrFromScalar(self);\n\tnumbytes = outcode->elsize;\n\tif PyArray_IsScalar(self, Flexible) {\n\t\tif PyArray_IsScalar(self, String)\n\t\t\t*ptrptr = PyString_AS_STRING(self);\n\t\telse if PyArray_IsScalar(self, Unicode)\n\t\t\t*ptrptr = (char *)PyUnicode_AS_DATA(self);\n\t\telse if PyArray_IsScalar(self, Void)\n\t\t\t*ptrptr = ((PyVoidScalarObject *)self)->obval;\n\t}\n\telse \n\t\t*ptrptr = (void *)_SOFFSET_(self, outcode->type_num);\n\n\tPy_DECREF(outcode);\n\treturn numbytes;\n}\n\nstatic int\ngentype_getsegcount(PyObject *self, int *lenp)\n{\n\tPyArray_Descr *outcode;\n\n\toutcode = PyArray_DescrFromScalar(self);\n\tif (lenp)\n\t\t*lenp = outcode->elsize;\n\tPy_DECREF(outcode);\n\treturn 1;\n}\n\nstatic int\ngentype_getcharbuf(PyObject *self, int segment, const char **ptrptr)\n{\n\tif (PyArray_IsScalar(self, String) ||\t\\\n\t PyArray_IsScalar(self, Unicode))\n\t\treturn gentype_getreadbuf(self, segment, (void **)ptrptr);\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"Non-character array cannot be interpreted \"\\\n\t\t\t\t\"as character buffer.\");\n\t\treturn -1;\n\t}\n}\n\n\nstatic PyBufferProcs gentype_as_buffer = {\n (getreadbufferproc)gentype_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)0, /*bf_getwritebuffer*/\n (getsegcountproc)gentype_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)gentype_getcharbuf, /*bf_getcharbuffer*/\n};\n\n\n#define BASEFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES\n#define LEAFFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES\n\nstatic PyTypeObject PyGenericArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"generic_arrtype\",\t /*tp_name*/\n sizeof(PyObject),\t\t /*tp_basicsize*/\n};\n\nstatic void\nunicode_dealloc(PyObject *v) \n{\n\tPyDataMem_FREE(((PyVoidScalarObject *)v)->obval);\n\tv->ob_type->tp_free(v);\n}\n\nstatic void\nvoid_dealloc(PyVoidScalarObject *v) \n{\n\tif (v->flags & OWNDATA)\n\t\tPyDataMem_FREE(v->obval);\n\tPy_XDECREF(v->descr);\n\tPy_XDECREF(v->base);\n\tv->ob_type->tp_free(v);\n}\n\nstatic void\nobject_arrtype_dealloc(PyObject *v)\n{\n\tPy_XDECREF(((PyObjectScalarObject *)v)->obval);\n\tv->ob_type->tp_free(v);\n}\n\n/* string and unicode inherit from Python Type first and so GET_ITEM is different to\n get to the Python Type.\n */\n\n/**begin repeat \n#name=byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, object#\n#TYPE=BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, STRING, UNICODE, OBJECT#\n#num=1*16,0,0,1#\n*/\nstatic PyObject *\n@name@_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj=NULL;\n\tPyObject *arr;\n\tPyArray_Descr *typecode;\n\n\tif (type->tp_bases && (PyTuple_GET_SIZE(type->tp_bases)==2)) {\n\t\tPyTypeObject *sup;\n\t\tPyObject *ret;\n\t\t/* We are inheriting from a Python type as well so\n\t\t give it first dibs on conversion */\n\t\tsup = (PyTypeObject *)PyTuple_GET_ITEM(type->tp_bases, @num@);\n\t\tret = sup->tp_new(type, args, kwds);\n\t\tif (ret) return ret;\n\t\tPyErr_Clear();\n\t\t/* now do default conversion */\n\t}\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\n\ttypecode = PyArray_DescrFromType(PyArray_@TYPE@);\n\tarr = PyArray_FromAny(obj, typecode, 0, 0, FORCECAST);\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n/**end repeat**/\n\n/* bool->tp_new only returns Py_True or Py_False */\nstatic PyObject *\nbool_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj=NULL;\n\tPyObject *arr;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\t\n\tarr = PyArray_FROM_OTF(obj, PyArray_BOOL, FORCECAST);\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n\nstatic PyObject *\nvoid_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj, *arr;\n\tulonglong memu=1;\n\tPyObject *new=NULL;\n\tchar *destptr;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\t/* For a VOID scalar first see if obj is an integer or long \n\t and create new memory of that size (filled with 0) for the scalar\n\t*/\n\n\tif (PyLong_Check(obj) || PyInt_Check(obj) || \\\n\t PyArray_IsScalar(obj, Integer) ||\n\t (PyArray_Check(obj) && PyArray_NDIM(obj)==0 &&\t\\\n\t PyArray_ISINTEGER(obj))) {\n\t\tnew = obj->ob_type->tp_as_number->nb_long(obj);\n\t}\n\tif (new && PyLong_Check(new)) {\n\t\tPyObject *ret;\n\t\tmemu = PyLong_AsUnsignedLongLong(new);\n\t\tPy_DECREF(new);\n\t\tif (PyErr_Occurred() || (memu > MAX_INT)) {\n\t\t\tPyErr_Clear();\n\t\t\tPyErr_Format(PyExc_OverflowError, \n\t\t\t\t \"size must be smaller than %d\",\n\t\t\t\t (int) MAX_INT);\n\t\t\treturn NULL;\n\t\t}\n\t\tdestptr = PyDataMem_NEW((int) memu);\n\t\tif (destptr == NULL) return PyErr_NoMemory();\n\t\tret = type->tp_alloc(type, 0);\n\t\tif (ret == NULL) {\n\t\t\tPyDataMem_FREE(destptr);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\t((PyVoidScalarObject *)ret)->obval = destptr;\n\t\t((PyVoidScalarObject *)ret)->ob_size = (int) memu;\n\t\t((PyVoidScalarObject *)ret)->descr = \\\n\t\t\tPyArray_DescrNewFromType(PyArray_VOID);\n\t\t((PyVoidScalarObject *)ret)->descr->elsize = (int) memu;\n\t\t((PyVoidScalarObject *)ret)->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t((PyVoidScalarObject *)ret)->base = NULL;\n\t\tmemset(destptr, '\\0', (size_t) memu);\n\t\treturn ret;\n\t}\n\n\tarr = PyArray_FROM_OTF(obj, PyArray_VOID, FORCECAST);\n return PyArray_Return((PyArrayObject *)arr);\n}\n\n\n/**************** Define Hash functions ********************/\n\n/**begin repeat\n#lname=bool,ubyte,ushort#\n#name=Bool,UByte, UShort#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n return (long)(((Py@name@ScalarObject *)obj)->obval);\n}\n/**end repeat**/\n\n/**begin repeat\n#lname=byte,short,uint,ulong#\n#name=Byte,Short,UInt,ULong#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((Py@name@ScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n/**end repeat**/\n\n#if SIZEOF_INT != SIZEOF_LONG\nstatic long\nint_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((PyIntScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n#endif\n\n/**begin repeat\n#char=,u#\n#Char=,U#\n#ext=&& (x >= LONG_MIN),#\n*/\n#if SIZEOF_LONG != SIZEOF_LONGLONG\n/* we assume SIZEOF_LONGLONG=2*SIZEOF_LONG */\nstatic long\n@char@longlong_arrtype_hash(PyObject *obj)\n{\n long y;\n @char@longlong x = (((Py@Char@LongLongScalarObject *)obj)->obval);\n\n if ((x <= LONG_MAX)@ext@) {\n y = (long) x;\n }\n else {\n union Mask {\n long hashvals[2];\n @char@longlong v;\n } both;\n\n both.v = x;\n y = both.hashvals[0] + (1000003)*both.hashvals[1];\n }\n if (y == -1) y = -2;\n return y;\n}\n#endif\n/**end repeat**/\n\n#if SIZEOF_LONG==SIZEOF_LONGLONG\nstatic long\nulonglong_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((PyULongLongScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n#endif\n\n\n\n/* Wrong thing to do for longdouble, but....*/\n/**begin repeat\n#lname=float, longdouble#\n#name=Float, LongDouble#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n return _Py_HashDouble((double) ((Py@name@ScalarObject *)obj)->obval);\n}\n\n/* borrowed from complex_hash */\nstatic long\nc@lname@_arrtype_hash(PyObject *obj)\n{\n long hashreal, hashimag, combined;\n hashreal = _Py_HashDouble((double) \\\n (((PyC@name@ScalarObject *)obj)->obval).real);\n\n if (hashreal == -1) return -1;\n hashimag = _Py_HashDouble((double) \\\n (((PyC@name@ScalarObject *)obj)->obval).imag);\n if (hashimag == -1) return -1;\n\n combined = hashreal + 1000003 * hashimag;\n if (combined == -1) combined = -2;\n return combined;\n}\n/**end repeat**/\n\nstatic long\nobject_arrtype_hash(PyObject *obj)\n{\n return PyObject_Hash(((PyObjectScalarObject *)obj)->obval);\n}\n\n/* just hash the pointer */\nstatic long\nvoid_arrtype_hash(PyObject *obj)\n{\n return _Py_HashPointer((void *)(((PyVoidScalarObject *)obj)->obval));\n}\n\n/*object arrtype getattro and setattro */\nstatic PyObject *\nobject_arrtype_getattro(PyObjectScalarObject *obj, PyObject *attr) {\n\tPyObject *res;\n\n\t/* first look in object and then hand off to generic type */\n\n\tres = PyObject_GenericGetAttr(obj->obval, attr);\t\n\tif (res) return res;\n\tPyErr_Clear();\n\treturn \tPyObject_GenericGetAttr((PyObject *)obj, attr);\n}\n\nstatic int\nobject_arrtype_setattro(PyObjectScalarObject *obj, PyObject *attr, PyObject *val) {\n\tint res;\n\t/* first look in object and then hand off to generic type */\n\n\tres = PyObject_GenericSetAttr(obj->obval, attr, val);\n\tif (res >= 0) return res;\n\tPyErr_Clear();\n\treturn PyObject_GenericSetAttr((PyObject *)obj, attr, val);\n}\n\nstatic int \nobject_arrtype_length(PyObjectScalarObject *self) \n{\n\treturn PyObject_Length(self->obval);\n}\n\nstatic PyObject *\nobject_arrtype_concat(PyObjectScalarObject *self, PyObject *other)\n{\n\treturn PySequence_Concat(self->obval, other);\n}\n\nstatic PyObject *\nobject_arrtype_repeat(PyObjectScalarObject *self, int count)\n{\n\treturn PySequence_Repeat(self->obval, count);\n}\n\nstatic PyObject *\nobject_arrtype_subscript(PyObjectScalarObject *self, PyObject *key)\n{\n\treturn PyObject_GetItem(self->obval, key);\n}\n\nstatic int\nobject_arrtype_ass_subscript(PyObjectScalarObject *self, PyObject *key, \n\t\t\t PyObject *value)\n{\n\treturn PyObject_SetItem(self->obval, key, value);\n}\n\nstatic int\nobject_arrtype_contains(PyObjectScalarObject *self, PyObject *ob)\n{\n\treturn PySequence_Contains(self->obval, ob);\n}\n\nstatic PyObject *\nobject_arrtype_inplace_concat(PyObjectScalarObject *self, PyObject *o)\n{\n\treturn PySequence_InPlaceConcat(self->obval, o);\n}\n\nstatic PyObject *\nobject_arrtype_inplace_repeat(PyObjectScalarObject *self, int count)\n{\n\treturn PySequence_InPlaceRepeat(self->obval, count);\n}\n\nstatic PySequenceMethods object_arrtype_as_sequence = {\n (inquiry)object_arrtype_length, /*sq_length*/\n (binaryfunc)object_arrtype_concat, /*sq_concat*/\n (intargfunc)object_arrtype_repeat, /*sq_repeat*/\n 0, /*sq_item*/\n 0, /*sq_slice*/\n 0, /* sq_ass_item */\n 0, /* sq_ass_slice */\n (objobjproc)object_arrtype_contains, /* sq_contains */\n (binaryfunc)object_arrtype_inplace_concat, /* sq_inplace_concat */\n (intargfunc)object_arrtype_inplace_repeat, /* sq_inplace_repeat */\n};\n\nstatic PyMappingMethods object_arrtype_as_mapping = {\n (inquiry)object_arrtype_length,\n (binaryfunc)object_arrtype_subscript,\n (objobjargproc)object_arrtype_ass_subscript,\n};\n\nstatic int \nobject_arrtype_getsegcount(PyObjectScalarObject *self, int *lenp) \n{\n\tint newlen;\n\tint cnt;\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\t\n\tif (pb == NULL || \\\n\t pb->bf_getsegcount == NULL || \\\n\t (cnt = (*pb->bf_getsegcount)(self->obval, &newlen)) != 1) \n\t\treturn 0;\n\t\n\tif (lenp) \n\t\t*lenp = newlen;\n\t\n\treturn cnt;\n}\n\nstatic int \nobject_arrtype_getreadbuf(PyObjectScalarObject *self, int segment, void **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getreadbuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a readable buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getreadbuffer)(self->obval, segment, ptrptr);\n}\n\nstatic int \nobject_arrtype_getwritebuf(PyObjectScalarObject *self, int segment, void **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getwritebuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a writeable buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getwritebuffer)(self->obval, segment, ptrptr);\n}\n\nstatic int \nobject_arrtype_getcharbuf(PyObjectScalarObject *self, int segment, \n\t\t\t const char **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getcharbuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a character buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getcharbuffer)(self->obval, segment, ptrptr);\n}\n\nstatic PyBufferProcs object_arrtype_as_buffer = {\n (getreadbufferproc)object_arrtype_getreadbuf,\n (getwritebufferproc)object_arrtype_getwritebuf,\n (getsegcountproc)object_arrtype_getsegcount,\n (getcharbufferproc)object_arrtype_getcharbuf,\n};\n\nstatic PyObject *\nobject_arrtype_call(PyObjectScalarObject *obj, PyObject *args, PyObject *kwds)\n{\n\treturn PyObject_Call(obj->obval, args, kwds);\n}\n\nstatic PyTypeObject PyObjectArrType_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"object_arrtype\",\t /*tp_name*/\n sizeof(PyObjectScalarObject),\t /*tp_basicsize*/\n 0, /* tp_itemsize */\n (destructor)object_arrtype_dealloc, /* tp_dealloc */\n 0, /* tp_print */\n 0, /* tp_getattr */\n 0, /* tp_setattr */\n 0, /* tp_compare */\n 0, /* tp_repr */\n 0, /* tp_as_number */\n &object_arrtype_as_sequence, /* tp_as_sequence */\n &object_arrtype_as_mapping, /* tp_as_mapping */\n 0, /* tp_hash */\n (ternaryfunc)object_arrtype_call, /* tp_call */\n 0, /* tp_str */\n (getattrofunc)object_arrtype_getattro, /* tp_getattro */\n (setattrofunc)object_arrtype_setattro, /* tp_setattro */\n &object_arrtype_as_buffer, /* tp_as_buffer */\n 0, /* tp_flags */\n};\n\n/**begin repeat\n#name=bool, string, unicode, void#\n#NAME=Bool, String, Unicode, Void#\n*/\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@_arrtype\",\t /*tp_name*/\n sizeof(Py@NAME@ScalarObject),\t /*tp_basicsize*/\n};\n/**end repeat**/\n\n/**begin repeat\n#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n#name=int*5, uint*5, float*3, complex*3#\n#CNAME=(CHAR, SHORT, INT, LONG, LONGLONG)*2, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n*/\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@\" STRBITSOF_@CNAME@ \"_arrtype\",\t /*tp_name*/\n sizeof(Py@NAME@ScalarObject),\t /*tp_basicsize*/\n};\n\n/**end repeat**/\n\n\nstatic PyNumberMethods longdoubletype_as_number;\nstatic PyNumberMethods clongdoubletype_as_number;\n\n\nstatic void \ninitialize_numeric_types(void)\n{\n\tPyGenericArrType_Type.tp_dealloc = (destructor)gentype_dealloc;\n\tPyGenericArrType_Type.tp_as_number = &gentype_as_number;\n\tPyGenericArrType_Type.tp_as_buffer = &gentype_as_buffer;\n\tPyGenericArrType_Type.tp_flags = BASEFLAGS;\n\tPyGenericArrType_Type.tp_methods = gentype_methods;\n\tPyGenericArrType_Type.tp_getset = gentype_getsets;\n\tPyGenericArrType_Type.tp_new = NULL;\n PyGenericArrType_Type.tp_alloc = gentype_alloc;\n\tPyGenericArrType_Type.tp_free = _pya_free;\n\tPyGenericArrType_Type.tp_repr = gentype_repr;\n\tPyGenericArrType_Type.tp_str = gentype_str;\n\tPyGenericArrType_Type.tp_richcompare = gentype_richcompare;\n\n\tPyStringArrType_Type.tp_alloc = NULL;\n\tPyStringArrType_Type.tp_free = NULL;\n\n\tPyVoidArrType_Type.tp_methods = voidtype_methods;\n\tPyVoidArrType_Type.tp_getset = voidtype_getsets;\n\tPyVoidArrType_Type.tp_as_mapping = &voidtype_as_mapping;\n\t\n\t/**begin repeat\n#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating, \nComplexFloating, Flexible, Character#\n\t*/\n Py@NAME@ArrType_Type.tp_flags = BASEFLAGS;\n\t/**end repeat**/\n\n\t/**begin repeat\n#name=bool, byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, void, object#\n#NAME=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, String, Unicode, Void, Object#\n\t*/\n\tPy@NAME@ArrType_Type.tp_flags = LEAFFLAGS;\n\tPy@NAME@ArrType_Type.tp_new = @name@_arrtype_new;\n\tPy@NAME@ArrType_Type.tp_richcompare = gentype_richcompare;\n\t/**end repeat**/\n\t/* Allow the Void type to be subclassed -- for adding new types */\n\tPyVoidArrType_Type.tp_flags = BASEFLAGS;\n\n /**begin repeat\n#name=bool, byte, short, ubyte, ushort, uint, ulong, ulonglong, float, longdouble, cfloat, clongdouble, void, object#\n#NAME=Bool, Byte, Short, UByte, UShort, UInt, ULong, ULongLong, Float, LongDouble, CFloat, CLongDouble, Void, Object#\n */\n Py@NAME@ArrType_Type.tp_hash = @name@_arrtype_hash;\n /**end repeat**/\n\n#if SIZEOF_INT != SIZEOF_LONG\n /* We won't be inheriting from Python Int type. */\n PyIntArrType_Type.tp_hash = int_arrtype_hash;\n#endif\n\n#if SIZEOF_LONG != SIZEOF_LONGLONG\n /* We won't be inheriting from Python Int type. */\n PyLongLongArrType_Type.tp_hash = longlong_arrtype_hash;\n#endif\n\n\t/* These need to be coded specially because getitem does not\n\t return a normal Python type\n\t*/\n\tPyLongDoubleArrType_Type.tp_as_number = &longdoubletype_as_number;\n\tPyCLongDoubleArrType_Type.tp_as_number = &clongdoubletype_as_number;\n\n\t/**begin repeat\n#name=int, long, hex, oct, float, repr, str#\n#kind=tp_as_number->nb*5, tp*2#\n\t*/\n\tPyLongDoubleArrType_Type.@kind@_@name@ = longdoubletype_@name@;\n\tPyCLongDoubleArrType_Type.@kind@_@name@ = clongdoubletype_@name@;\n\t/**end repeat**/\n\n\tPyStringArrType_Type.tp_itemsize = sizeof(char);\n\tPyVoidArrType_Type.tp_dealloc = (destructor) void_dealloc;\n\tPyUnicodeArrType_Type.tp_dealloc = unicode_dealloc;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMapIter_Type.tp_iter = PyObject_SelfIter;\n\n/**begin repeat\n#name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,#\n#num=BOOL, BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, OBJECT, NTYPES#\n**/\n PyArrayScalar_Offset[PyArray_@num@] = (int) offsetof(Py@name@ScalarObject, obval);\n/**end repeat**/\n}\n\n\n/* the order of this table is important */\nstatic PyTypeObject *typeobjects[] = {\n &PyBoolArrType_Type,\n &PyByteArrType_Type,\n\t&PyUByteArrType_Type,\n &PyShortArrType_Type,\n &PyUShortArrType_Type,\n\t&PyIntArrType_Type,\n\t&PyUIntArrType_Type,\n\t&PyLongArrType_Type,\n\t&PyULongArrType_Type,\n\t&PyLongLongArrType_Type,\n\t&PyULongLongArrType_Type,\n\t&PyFloatArrType_Type,\n\t&PyDoubleArrType_Type,\n\t&PyLongDoubleArrType_Type,\n\t&PyCFloatArrType_Type,\n\t&PyCDoubleArrType_Type,\n\t&PyCLongDoubleArrType_Type,\n\t&PyObjectArrType_Type,\n\t&PyStringArrType_Type,\n\t&PyUnicodeArrType_Type,\n\t&PyVoidArrType_Type\n};\n\nstatic int\n_typenum_fromtypeobj(PyObject *type, int user)\n{\n\tint typenum, i;\n\n\ttypenum = PyArray_NOTYPE;\n i = 0;\n\twhile(i < PyArray_NTYPES) {\n\t\tif (type == (PyObject *)typeobjects[i]) {\n\t\t\ttypenum = i;\n\t\t\tbreak;\n\t\t}\n i++;\n\t}\n\t\n\tif (!user) return typenum;\n\n\t/* Search any registered types */\n\ti = 0;\n\twhile (i < PyArray_NUMUSERTYPES) {\n\t\tif (type == (PyObject *)(userdescrs[i]->typeobj)) {\n\t\t\ttypenum = i + PyArray_USERDEF;\n\t\t\tbreak;\n\t\t}\n\t\ti++;\n\t}\n\treturn typenum;\n}\n\n/* new reference */\nstatic PyArray_Descr *\nPyArray_DescrFromTypeObject(PyObject *type)\n{\t\n\tint typenum;\n\tPyArray_Descr *new, *conv=NULL;\n\n\t/* if it's a builtin type, then use the typenumber */\n\ttypenum = _typenum_fromtypeobj(type,1);\t\n\tif (typenum != PyArray_NOTYPE) {\n\t\tnew = PyArray_DescrFromType(typenum);\n\t\tif (PyTypeNum_ISUSERDEF(typenum)) goto finish;\n\t\treturn new;\n\t}\n\n\t/* Check the generic types */\n\tif ((type == (PyObject *) &PyNumberArrType_Type) ||\t\t\\\n\t (type == (PyObject *) &PyInexactArrType_Type) ||\t\t\\\n\t (type == (PyObject *) &PyFloatingArrType_Type))\n\t\ttypenum = PyArray_DOUBLE;\n\telse if (type == (PyObject *)&PyComplexFloatingArrType_Type)\n\t\ttypenum = PyArray_CDOUBLE;\n\telse if ((type == (PyObject *)&PyIntegerArrType_Type) ||\t\\\n\t\t (type == (PyObject *)&PySignedIntegerArrType_Type))\n\t\ttypenum = PyArray_LONG;\n\telse if (type == (PyObject *) &PyUnsignedIntegerArrType_Type)\n\t\ttypenum = PyArray_ULONG;\n\telse if (type == (PyObject *) &PyCharacterArrType_Type)\n\t\ttypenum = PyArray_STRING;\n\telse if ((type == (PyObject *) &PyGenericArrType_Type) || \\\n\t\t (type == (PyObject *) &PyFlexibleArrType_Type))\n\t\ttypenum = PyArray_VOID;\n\n\tif (typenum != PyArray_NOTYPE) {\n\t\treturn PyArray_DescrFromType(typenum);\n\t}\n\t\n\t/* Otherwise --- type is a sub-type of an array scalar\n\t currently only VOID allows it -- use it as the type-object.\n\t*/\n\t/* look for a dtypedescr attribute */\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\n finish:\n\tconv = _arraydescr_fromobj(type);\n\tif (conv) {\n\t\tnew->fields = conv->fields;\n\t\tPy_INCREF(new->fields);\n\t\tnew->elsize = conv->elsize;\n\t\tnew->subarray = conv->subarray;\n\t\tconv->subarray = NULL;\n\t\tPy_DECREF(conv);\n\t}\n Py_DECREF(new->typeobj);\n new->typeobj = (PyTypeObject *)type;\n Py_INCREF(type);\n\treturn new;\n}\n\n/* New reference */\n/*OBJECT_API\n Return descr object from array scalar.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromScalar(PyObject *sc)\n{\n\tint type_num;\n\tPyArray_Descr *descr;\n\n\tif PyArray_IsScalar(sc, Void) {\n\t\tdescr = ((PyVoidScalarObject *)sc)->descr;\n\t\tPy_INCREF(descr);\n\t\treturn descr;\n\t}\n descr = PyArray_DescrFromTypeObject((PyObject *)sc->ob_type);\n if (descr->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(descr);\n type_num = descr->type_num;\n\t\tif (type_num == PyArray_STRING) \n\t\t\tdescr->elsize = PyString_GET_SIZE(sc);\n\t\telse if (type_num == PyArray_UNICODE)\n\t\t\tdescr->elsize = PyUnicode_GET_DATA_SIZE(sc);\n\t\telse {\n\t\t\tdescr->elsize =\t\t\t\t\t\\\n\t\t\t\t((PyVoidScalarObject *)sc)->ob_size;\n\t\t\tdescr->fields = PyObject_GetAttrString(sc, \"fields\");\n\t\t\tif (!descr->fields || !PyDict_Check(descr->fields) || \\\n\t\t\t (descr->fields == Py_None)) {\n\t\t\t\tPy_XDECREF(descr->fields);\n\t\t\t\tdescr->fields = NULL;\n\t\t\t}\n\t\t\tPyErr_Clear();\n\t\t}\n }\n\treturn descr;\n}\n\n/* New reference */\n/*OBJECT_API\n Get a typeobject from a type-number\n*/\nstatic PyObject *\nPyArray_TypeObjectFromType(int type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr == NULL) return NULL;\n\tPy_INCREF((PyObject *)descr->typeobj);\n\tobj = (PyObject *)descr->typeobj;\n\tPy_DECREF(descr);\n\treturn obj;\n}\n\n", + "source_code_before": "/* -*- c -*- */\n\nstatic int PyArrayScalar_Offset[PyArray_NTYPES+1];\n\n#define _SOFFSET_(obj, type_num) ((char *)(obj) + PyArrayScalar_Offset[(type_num)])\n\n/**begin repeat\n#name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,#\n#type=Bool, signed char, short, int, long, longlong, unsigned char, unsigned short, unsigned int, unsigned long, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, PyObject *,char#\n*/\ntypedef struct {\n\tPyObject_HEAD\n\t@type@ obval;\n} Py@name@ScalarObject;\n/**end repeat**/\n\n/* Inheritance established later when tp_bases is set (or tp_base for \n single inheritance) */\n\n/**begin repeat\n\n#name=number, integer, signedinteger, unsignedinteger, inexact, floating, complexfloating, flexible, \ncharacter#\n#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating, ComplexFloating, Flexible, Character#\n*/\n\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@_arrtype\",\t\t /*tp_name*/\n sizeof(PyObject),\t\t /*tp_basicsize*/\n};\n/**end repeat**/\n\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/* no error checking is performed -- ctypeptr must be same type as scalar */\n/* in case of flexible type, the data is not copied \n into ctypeptr which is expected to be a pointer to pointer */\n/*OBJECT_API\n Convert to c-type\n*/\nstatic void\nPyArray_ScalarAsCtype(PyObject *scalar, void *ctypeptr)\n{\n\tPyArray_Descr *typecode;\n\ttypecode = PyArray_DescrFromScalar(scalar);\n\t\n\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\tvoid **newptr = (void **)ctypeptr;\n\t\tswitch(typecode->type_num) {\n\t\tcase PyArray_STRING:\n\t\t\t*newptr = (void *)PyString_AS_STRING(scalar);\n\t\tcase PyArray_UNICODE:\n\t\t\t*newptr = (void *)PyUnicode_AS_DATA(scalar);\n\t\tdefault:\n\t\t\t*newptr = ((PyVoidScalarObject *)scalar)->obval;\n\t\t}\n\t\treturn;\n\t}\n\tmemcpy(ctypeptr, _SOFFSET_(scalar, typecode->type_num),\n\t typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn;\n}\n\n/* The output buffer must be large-enough to receive the value */\n/* Even for flexible types which is different from ScalarAsCtype\n where only a reference for flexible types is returned \n*/\n\n/*OBJECT_API\n Cast Scalar to c-type\n*/\nstatic int\nPyArray_CastScalarToCtype(PyObject *scalar, void *ctypeptr, \n\t\t\t PyArray_Descr *outcode)\n{\n\tPyArray_Descr* descr;\n\t\n\tdescr = PyArray_DescrFromScalar(scalar);\n\tif (PyTypeNum_ISEXTENDED(descr->type_num) ||\n\t PyTypeNum_ISEXTENDED(outcode->type_num)) {\n\t\tPyArrayObject *ain, *aout;\n\n\t\tain = (PyArrayObject *)PyArray_FromScalar(scalar, NULL);\n\t\tif (ain == NULL) {Py_DECREF(descr); return -1;}\n\t\taout = (PyArrayObject *)\\\n\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t outcode,\n\t\t\t\t\t 0, NULL, \n\t\t\t\t\t NULL, ctypeptr, \n\t\t\t\t\t CARRAY_FLAGS, NULL);\n\t\tif (aout == NULL) {Py_DECREF(ain); return -1;}\n\t\tdescr->f->cast[outcode->type_num](ain->data, \n\t\t\t\t\t aout->data, 1, ain, aout);\n\t\tPy_DECREF(ain);\n\t\tPy_DECREF(aout);\n\t}\n\telse {\n\t\tdescr->f->cast[outcode->type_num](_SOFFSET_(scalar, \n\t\t\t\t\t\t\t descr->type_num), \n\t\t\t\t\t ctypeptr, 1, NULL, NULL);\n\t}\n\tPy_DECREF(descr);\n\treturn 0;\n}\n\n/* 0-dim array from array-scalar object */\n/* always contains a copy of the data \n unless outcode is NULL, it is of void type and the referrer does\n not own it either.\n*/\n\n/* steals reference to outcode */\n/*OBJECT_API\n Get 0-dim array from scalar\n*/\nstatic PyObject *\nPyArray_FromScalar(PyObject *scalar, PyArray_Descr *outcode)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *r;\n\tchar *memptr;\n\tPyObject *ret;\n\n\t/* convert to 0-dim array of scalar typecode */\n\ttypecode = PyArray_DescrFromScalar(scalar);\n\tif ((typecode->type_num == PyArray_VOID) &&\t\t\t\\\n\t !(((PyVoidScalarObject *)scalar)->flags & OWNDATA) &&\t\\\n\t outcode == NULL) {\n\t\tr = PyArray_NewFromDescr(&PyArray_Type,\n\t\t\t\t\t typecode,\n\t\t\t\t\t 0, NULL, NULL,\n\t\t\t\t\t ((PyVoidScalarObject *)scalar)->obval,\n\t\t\t\t\t ((PyVoidScalarObject *)scalar)->flags,\n\t\t\t\t\t NULL);\n\t\tPyArray_BASE(r) = (PyObject *)scalar;\n\t\tPy_INCREF(scalar);\n\t\treturn r;\n\t}\n\tr = PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t typecode,\n\t\t\t\t 0, NULL, \n\t\t\t\t NULL, NULL, 0, NULL);\n\tif (r==NULL) {Py_XDECREF(outcode); return NULL;}\n\n\tswitch(typecode->type_num) {\n\tcase PyArray_STRING:\n\t\tmemptr = PyString_AS_STRING(scalar);\n\t\tbreak;\n\tcase PyArray_UNICODE:\n\t\tmemptr = (char *)PyUnicode_AS_DATA(scalar);\n\t\tbreak;\n\tdefault:\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tmemptr = (((PyVoidScalarObject *)scalar)->obval);\n\t\t}\n\t\telse {\n\t\t\tmemptr = _SOFFSET_(scalar, typecode->type_num);\n\t\t}\n\t\tbreak;\n\t}\n\n\tmemcpy(PyArray_DATA(r), memptr, PyArray_ITEMSIZE(r));\n\tif (PyArray_ISOBJECT(r)) {\n\t\tPy_INCREF(*((PyObject **)memptr));\n\t}\n\t\n\tif (outcode == NULL) return r;\n\t\n\tif (outcode->type_num == typecode->type_num) {\n\t\tif (!PyTypeNum_ISEXTENDED(typecode->type_num))\n\t\t\treturn r;\n\t\tif (outcode->elsize == typecode->elsize);\n\t\treturn r;\t\t\t\n\t}\n\t\n\t/* cast if necessary to desired output typecode */\n\tret = PyArray_CastToType((PyArrayObject *)r, outcode, 0);\n\tPy_DECREF(r);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_alloc(PyTypeObject *type, int nitems)\n{\n PyObject *obj;\n const size_t size = _PyObject_VAR_SIZE(type, nitems+1);\n\n obj = (PyObject *)_pya_malloc(size);\n\tmemset(obj, 0, size);\n\tif (type->tp_itemsize == 0)\n PyObject_INIT(obj, type);\n else\n (void) PyObject_INIT_VAR((PyVarObject *)obj, type, nitems);\n return obj;\n}\n\nstatic void\ngentype_dealloc(PyObject *v) \n{\n\tv->ob_type->tp_free(v);\n}\n\n\nstatic PyObject *\ngentype_power(PyObject *m1, PyObject *m2, PyObject *m3)\n{\n\tPyObject *arr, *ret, *arg2;\n\tchar *msg=\"unsupported operand type(s) for ** or pow()\";\n\t\n\tif (!PyArray_IsScalar(m1,Generic)) {\n\t\tif (PyArray_Check(m1)) {\n\t\t\tret = m1->ob_type->tp_as_number->nb_power(m1,m2, \n\t\t\t\t\t\t\t\t Py_None);\n\t\t}\n\t\telse {\n\t\t\tif (!PyArray_IsScalar(m2,Generic)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tarr = PyArray_FromScalar(m2, NULL);\n\t\t\tif (arr == NULL) return NULL;\n\t\t\tret = arr->ob_type->tp_as_number->nb_power(m1, arr,\n\t\t\t\t\t\t\t\t Py_None);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t\treturn ret;\n\t}\n\tif (!PyArray_IsScalar(m2, Generic)) {\n\t\tif (PyArray_Check(m2)) {\n\t\t\tret = m2->ob_type->tp_as_number->nb_power(m1,m2, \n\t\t\t\t\t\t\t\t Py_None);\n\t\t}\n\t\telse {\n\t\t\tif (!PyArray_IsScalar(m1, Generic)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tarr = PyArray_FromScalar(m1, NULL);\n\t\t\tif (arr == NULL) return NULL;\n\t\t\tret = arr->ob_type->tp_as_number->nb_power(arr, m2,\n\t\t\t\t\t\t\t\t Py_None);\n\t\t\tPy_DECREF(arr);\n\t\t}\n\t\treturn ret;\n\t}\n\tarr=arg2=NULL;\n\tarr = PyArray_FromScalar(m1, NULL);\n\targ2 = PyArray_FromScalar(m2, NULL);\t\n\tif (arr == NULL || arg2 == NULL) {\n\t\tPy_XDECREF(arr); Py_XDECREF(arg2); return NULL;\n\t}\n\tret = arr->ob_type->tp_as_number->nb_power(arr, arg2, Py_None);\n\tPy_DECREF(arr);\n\tPy_DECREF(arg2);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_generic_method(PyObject *self, PyObject *args, PyObject *kwds, \n\t\t char *str)\n{\n\tPyObject *arr, *meth, *ret;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tmeth = PyObject_GetAttrString(arr, str);\n\tif (meth == NULL) {Py_DECREF(arr); return NULL;}\n\tif (kwds == NULL) \n\t\tret = PyObject_CallObject(meth, args);\n\telse\n\t\tret = PyObject_Call(meth, args, kwds);\n\tPy_DECREF(meth);\n\tPy_DECREF(arr);\n if (ret && PyArray_Check(ret))\n return PyArray_Return((PyArrayObject *)ret);\n else\n return ret;\n}\n\n/**begin repeat\n\n#name=add, subtract, divide, remainder, divmod, lshift, rshift, and, xor, or, floor_divide, true_divide#\n#PYNAME=Add, Subtract, Divide, Remainder, Divmod, Lshift, Rshift, And, Xor, Or, FloorDivide, TrueDivide#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *m1, PyObject *m2)\n{\n\tPyObject *arr, *ret=NULL, *tup;\n\t\n\tif (!PyArray_IsScalar(m1, Generic)) {\n\t\tif (PyArray_Check(m1)) {\n\t\t\tret = m1->ob_type->tp_as_number->nb_@name@(m1,m2);\n\t\t}\n else {\n\t\t\tPyObject *newarr;\n\t\t\t/* Convert object to Array scalar and try again */\n\t\t\tnewarr = PyArray_FromAny(m1, NULL, 0, 0, 0);\n\t\t\tif (newarr!=NULL) {\n\t\t\t\tret = newarr->ob_type->tp_as_number->nb_@name@(newarr, m2);\n\t\t\t\tPy_DECREF(newarr);\n\t\t\t}\n\t\t\telse ret=NULL;\n\t\t}\n\t\treturn ret;\n\t}\n\tif (!PyArray_IsScalar(m2, Generic)) {\n\t\tif (PyArray_Check(m2)) {\n\t\t\tret = m2->ob_type->tp_as_number->nb_@name@(m1,m2);\n\t\t}\n\t\telse {\n\t\t\tPyObject *newarr;\n\t\t\t/* Convert object to Array and try again */\n\t\t\tnewarr = PyArray_FromAny(m2, NULL, 0, 0, 0);\n\t\t\tif (newarr!=NULL) {\n\t\t\t\tret = newarr->ob_type->tp_as_number->nb_@name@(m1, newarr);\n\t\t\t\tPy_DECREF(newarr);\n\t\t\t}\n\t\t\telse ret=NULL;\n\t\t}\n\t\treturn ret;\n\t}\n\tarr=tup=NULL;\n\tarr = PyArray_FromScalar(m1, NULL);\n\ttup = PyArray_FromScalar(m2, NULL);\n\tif (arr == NULL || tup == NULL) {\n\t\tPy_XDECREF(tup); Py_XDECREF(arr); return NULL;\n\t}\n\tret = arr->ob_type->tp_as_number->nb_@name@(arr, tup);\n\tPy_DECREF(arr);\n\tPy_DECREF(tup);\n\treturn ret;\n}\n/**end repeat**/\n\n\nstatic PyObject *\ngentype_multiply(PyObject *m1, PyObject *m2)\n{\n\tPyObject *arr, *ret=NULL, *tup;\n\tlong repeat;\n\n\tif (!PyArray_IsScalar(m1, Generic)) {\n\t\tif (PyArray_Check(m1)) {\n\t\t\tret = m1->ob_type->tp_as_number->nb_multiply(m1,m2);\n\t\t}\n\t\telse if ((m1->ob_type->tp_as_number == NULL) ||\n\t\t\t (m1->ob_type->tp_as_number->nb_multiply == NULL)) {\n\t\t\t/* Convert m2 to an int and assume sequence\n\t\t\t repeat */\n\t\t\trepeat = PyInt_AsLong(m2);\n\t\t\tif (repeat == -1 && PyErr_Occurred()) return NULL;\n\t\t\tret = PySequence_Repeat(m1, (int) repeat);\n\t\t\tif (ret == NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tarr = PyArray_FromScalar(m2, NULL);\n\t\t\t\tif (arr == NULL) return NULL;\n\t\t\t\tret = arr->ob_type->tp_as_number->\\\n\t\t\t\t\tnb_multiply(m1, arr);\n\t\t\t\tPy_DECREF(arr);\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tPyObject *newarr;\n\t\t\t/* Convert object to Array scalar and try again */\n\t\t\tnewarr = PyArray_FromAny(m1, NULL, 0, 0, 0);\n\t\t\tif (newarr!=NULL) {\n\t\t\t\tret = newarr->ob_type->tp_as_number->nb_multiply(newarr, m2);\n\t\t\t\tPy_DECREF(newarr);\n\t\t\t}\n\t\t\telse ret=NULL;\n\t\t}\n\t\treturn ret;\n\t}\n\tif (!PyArray_IsScalar(m2, Generic)) {\n\t\tif (PyArray_Check(m2)) {\n\t\t\tret = m2->ob_type->tp_as_number->nb_multiply(m1,m2);\n\t\t}\n\t\telse if ((m2->ob_type->tp_as_number == NULL) ||\n\t\t\t (m2->ob_type->tp_as_number->nb_multiply == NULL)) {\n\t\t\t/* Convert m1 to an int and assume sequence\n\t\t\t repeat */\n\t\t\trepeat = PyInt_AsLong(m1);\n\t\t\tif (repeat == -1 && PyErr_Occurred()) return NULL;\n\t\t\tret = PySequence_Repeat(m2, (int) repeat);\n\t\t\tif (ret == NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tarr = PyArray_FromScalar(m1, NULL);\n\t\t\t\tif (arr == NULL) return NULL;\n\t\t\t\tret = arr->ob_type->tp_as_number->\t\\\n\t\t\t\t\tnb_multiply(arr, m2);\n\t\t\t\tPy_DECREF(arr);\n\t\t\t}\t\t\t\n\t\t}\n\t\telse {\n\t\t\tPyObject *newarr;\n\t\t\t/* Convert object to Array scalar and try again */\n\t\t\tnewarr = PyArray_FromAny(m2, NULL, 0, 0, 0);\n\t\t\tif (newarr!=NULL) {\n\t\t\t\tret = newarr->ob_type->tp_as_number->nb_multiply(m1, newarr);\n\t\t\t\tPy_DECREF(newarr);\n\t\t\t}\n\t\t\telse ret =NULL;\n\t\t}\n\t\treturn ret;\n\t}\n\t/* Both are array scalar objects */\n\tarr=tup=NULL;\n\tarr = PyArray_FromScalar(m1, NULL);\n\ttup = PyArray_FromScalar(m2, NULL);\n\tif (arr == NULL || tup == NULL) {\n\t\tPy_XDECREF(tup); Py_XDECREF(arr); return NULL;\n\t}\n\tret = arr->ob_type->tp_as_number->nb_multiply(arr, tup);\n\tPy_DECREF(arr);\n\tPy_DECREF(tup);\n\treturn ret;\n\n}\n\n\n\n/**begin repeat\n\n#name=negative, absolute, invert, int, long, float, oct, hex#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *m1)\n{\n\tPyObject *arr, *ret;\n\n\tarr = PyArray_FromScalar(m1, NULL);\n\tif (arr == NULL) return NULL;\n\tret = arr->ob_type->tp_as_number->nb_@name@(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n/**end repeat**/\n\nstatic int\ngentype_nonzero_number(PyObject *m1)\n{\n\tPyObject *arr;\n\tint ret;\n\n\tarr = PyArray_FromScalar(m1, NULL);\n\tif (arr == NULL) return -1;\n\tret = arr->ob_type->tp_as_number->nb_nonzero(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_str(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret, *tmp;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tif (arr==NULL) return NULL;\n\tret = PyObject_Str((tmp=arr->descr->f->getitem(arr->data, arr)));\n\tPy_DECREF(arr);\n\tPy_XDECREF(tmp);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_repr(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret, *tmp ;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tif (arr==NULL) return NULL;\n\tret = PyObject_Repr((tmp=arr->descr->f->getitem(arr->data, arr)));\n\tPy_DECREF(arr);\n\tPy_XDECREF(tmp);\n\treturn ret;\n}\n\nstatic void\nformat_longdouble(char *buf, size_t buflen, longdouble val, int precision)\n{\n register char *cp;\n\n PyOS_snprintf(buf, buflen, \"%.*\" LONGDOUBLE_FMT, precision, val);\n cp = buf;\n if (*cp == '-')\n cp++;\n for (; *cp != '\\0'; cp++) {\n if (!isdigit(Py_CHARMASK(*cp)))\n break;\n }\n if (*cp == '\\0') {\n *cp++ = '.';\n *cp++ = '0';\n *cp++ = '\\0';\n }\n}\n\n#if SIZEOF_LONGDOUBLE == SIZEOF_DOUBLE\n#define PREC_REPR 15\n#define PREC_STR 15\n#else\n#define PREC_REPR 21\n#define PREC_STR 21\n#endif\n\nstatic PyObject *\nlongdoubletype_repr(PyObject *self)\n{\n static char buf[100];\n format_longdouble(buf, sizeof(buf), ((PyLongDoubleScalarObject *)self)->obval, PREC_REPR);\n return PyString_FromString(buf);\n}\n\nstatic PyObject *\nclongdoubletype_repr(PyObject *self)\n{\n static char buf1[100];\n static char buf2[100];\n\tstatic char buf3[202];\n clongdouble x;\n x = ((PyCLongDoubleScalarObject *)self)->obval;\n format_longdouble(buf1, sizeof(buf1), x.real, PREC_REPR);\n format_longdouble(buf2, sizeof(buf2), x.imag, PREC_REPR);\n\n\tsnprintf(buf3, sizeof(buf3), \"(%s+%sj)\", buf1, buf2);\n\treturn PyString_FromString(buf3);\n}\n\n#define longdoubletype_str longdoubletype_repr\n#define clongdoubletype_str clongdoubletype_repr\n\n/** Could improve this with a PyLong_FromLongDouble(longdouble ldval)\n but this would need some more work...\n**/\n\n/**begin repeat\n\n#name=(int, long, hex, oct, float)*2#\n#KIND=(Long*4, Float)*2#\n#char=,,,,,c*5#\n#CHAR=,,,,,C*5#\n#POST=,,,,,.real*5#\n*/\nstatic PyObject *\n@char@longdoubletype_@name@(PyObject *self)\n{\n\tdouble dval;\n\tPyObject *obj, *ret;\n\t\n\tdval = (double)(((Py@CHAR@LongDoubleScalarObject *)self)->obval)@POST@;\n\tobj = Py@KIND@_FromDouble(dval);\n\tret = obj->ob_type->tp_as_number->nb_@name@(obj);\n\tPy_DECREF(obj);\n\treturn ret;\n}\n/**end repeat**/\n\n\nstatic PyObject *gentype_copy(PyObject *, PyObject *);\n\nstatic PyNumberMethods gentype_as_number = {\n (binaryfunc)gentype_add,\t\t /*nb_add*/\n (binaryfunc)gentype_subtract,\t\t /*nb_subtract*/\n (binaryfunc)gentype_multiply,\t\t /*nb_multiply*/\n (binaryfunc)gentype_divide,\t\t /*nb_divide*/\n (binaryfunc)gentype_remainder,\t /*nb_remainder*/\n (binaryfunc)gentype_divmod,\t\t /*nb_divmod*/\n (ternaryfunc)gentype_power,\t\t /*nb_power*/\n (unaryfunc)gentype_negative,\t \n (unaryfunc)gentype_copy,\t\t /*nb_pos*/ \n (unaryfunc)gentype_absolute,\t\t /*(unaryfunc)gentype_abs,*/\n (inquiry)gentype_nonzero_number,\t\t /*nb_nonzero*/\n (unaryfunc)gentype_invert,\t\t /*nb_invert*/\n (binaryfunc)gentype_lshift,\t /*nb_lshift*/\n (binaryfunc)gentype_rshift,\t /*nb_rshift*/\n (binaryfunc)gentype_and,\t /*nb_and*/\n (binaryfunc)gentype_xor,\t /*nb_xor*/\n (binaryfunc)gentype_or,\t /*nb_or*/\n 0,\t\t /*nb_coerce*/\n (unaryfunc)gentype_int,\t\t /*nb_int*/\n (unaryfunc)gentype_long,\t\t /*nb_long*/\n (unaryfunc)gentype_float,\t\t /*nb_float*/\n (unaryfunc)gentype_oct,\t\t /*nb_oct*/\n (unaryfunc)gentype_hex,\t\t /*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)gentype_floor_divide,\t /*nb_floor_divide*/\n (binaryfunc)gentype_true_divide,\t /*nb_true_divide*/\n 0, /*nb_inplace_floor_divide*/\n 0, /*nb_inplace_true_divide*/\n\n};\n\nstatic PyObject *\ngentype_richcompare(PyObject *self, PyObject *other, int cmp_op) \n{\n\n\tPyObject *arr, *ret;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tret = arr->ob_type->tp_richcompare(arr, other, cmp_op);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_ndim_get(PyObject *self)\n{\n\treturn PyInt_FromLong(0);\n}\n\nstatic PyObject *\ngentype_flags_get(PyObject *self)\n{\n\tstatic int flags=CONTIGUOUS | OWNDATA | FORTRAN | ALIGNED;\n\n return PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, flags, 1);\n}\n\nstatic PyObject *\nvoidtype_flags_get(PyVoidScalarObject *self)\n{\n\treturn PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 1);\n}\n\nstatic PyObject *\nvoidtype_dtypedescr_get(PyVoidScalarObject *self)\n{\n\tPy_INCREF(self->descr);\n\treturn (PyObject *)self->descr;\n}\n\n\n\nstatic PyObject *\ngentype_shape_get(PyObject *self)\n{\n\treturn PyTuple_New(0);\n}\n\n/*\nstatic int\ngentype_shape_set(PyObject *self, PyObject *val)\n{\n\tif (!PyTuple_Check(val) || PyTuple_GET_SIZE(val) > 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \\\n\t\t\t\t\"invalid shape for scalar\");\n\t\treturn -1;\n\t}\n\treturn 0;\n}\n*/\n\nstatic PyObject *\ngentype_dataptr_get(PyObject *self)\n{\n\treturn Py_BuildValue(\"NO\",PyString_FromString(\"\"),Py_True);\n}\n\n\nstatic PyObject *\ngentype_data_get(PyObject *self)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\n\ttypecode = PyArray_DescrFromScalar(self);\n\tret = PyBuffer_FromObject(self, 0, typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\n\nstatic PyObject *\ngentype_itemsize_get(PyObject *self)\n{\t\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\n\ttypecode = PyArray_DescrFromScalar(self);\n\tret = PyInt_FromLong((long) typecode->elsize);\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_size_get(PyObject *self)\n{\n\treturn PyInt_FromLong(1);\n}\n\n\nstatic PyObject *\ngentype_typechar_get(PyObject *self)\n{\n\tPyArray_Descr *descr;\n\tchar type;\n\tint elsize;\n\n\tdescr = PyArray_DescrFromScalar(self);\n\ttype = descr->type;\n\telsize = descr->elsize;\n\tPy_DECREF(descr);\n\tif (PyArray_IsScalar(self, Flexible)) \n\t\treturn PyString_FromFormat(\"%c%d\", (int)type, elsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&type, 1);\n}\n\nstatic void\ngentype_struct_free(void *ptr, void *arr)\n{\n Py_DECREF((PyObject *)arr);\n _pya_free(ptr);\n}\n\nstatic PyObject *\ngentype_struct_get(PyObject *self)\n{\n PyArrayObject *arr;\n PyArrayInterface *inter;\n \n arr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n inter = (PyArrayInterface *)_pya_malloc(sizeof(PyArrayInterface));\n inter->version = 2;\n inter->nd = 0;\n inter->flags = arr->flags;\n inter->typekind = arr->descr->kind;\n inter->itemsize = arr->descr->elsize;\n inter->strides = NULL;\n inter->shape = NULL;\n inter->data = arr->data;\n return PyCObject_FromVoidPtrAndDesc(inter, arr, gentype_struct_free);\n}\n\nstatic PyObject *\ngentype_typestr_get(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tret = PyObject_GetAttrString((PyObject *)arr, \"dtypestr\");\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_descr_get(PyObject *self)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tarr = (PyArrayObject *)PyArray_FromScalar(self, NULL);\n\tret = PyObject_GetAttrString((PyObject *)arr, \"__array_descr__\");\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\n\nstatic PyObject *\ngentype_type_get(PyObject *self)\n{\n Py_INCREF(self->ob_type);\n\treturn (PyObject *)self->ob_type;\n}\n\nstatic PyObject *\ngentype_typedescr_get(PyObject *self)\n{\n\treturn (PyObject *)PyArray_DescrFromScalar(self);\n}\n\n\nstatic PyObject *\ngentype_base_get(PyObject *self)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic PyArray_Descr *\n_realdescr_fromcomplexscalar(PyObject *self, int *typenum)\n{\n\tif PyArray_IsScalar(self, CDouble) {\n\t\t*typenum = PyArray_CDOUBLE;\n\t\treturn PyArray_DescrFromType(PyArray_DOUBLE);\n\t}\n\tif PyArray_IsScalar(self, CFloat) {\n\t\t*typenum = PyArray_CFLOAT;\n\t\treturn PyArray_DescrFromType(PyArray_FLOAT);\n\t}\n\tif PyArray_IsScalar(self, CLongDouble) {\n\t\t*typenum = PyArray_CLONGDOUBLE;\n\t\treturn PyArray_DescrFromType(PyArray_LONGDOUBLE);\n\t}\n\treturn NULL;\n}\n\nstatic PyObject *\ngentype_real_get(PyObject *self)\n{\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\n\tint typenum;\n\n\tif (PyArray_IsScalar(self, ComplexFloating)) {\n\t\ttypecode = _realdescr_fromcomplexscalar(self, &typenum);\n\t\tret = PyArray_Scalar(_SOFFSET_(self, typenum), typecode,\n\t\t\t\t NULL);\n\t\tPy_DECREF(typecode);\n\t\treturn ret;\n\t}\n\telse if PyArray_IsScalar(self, Object) {\n\t\tPyObject *obj = ((PyObjectScalarObject *)self)->obval;\n\t\tret = PyObject_GetAttrString(obj, \"real\");\n\t\tif (ret != NULL) return ret;\n\t\tPyErr_Clear();\n\t}\n\tPy_INCREF(self);\n\treturn (PyObject *)self;\n}\n\nstatic PyObject *\ngentype_imag_get(PyObject *self)\n{\t\n\tPyArray_Descr *typecode;\n\tPyObject *ret;\t\n\tint typenum;\n\t\n\ttypecode = _realdescr_fromcomplexscalar(self, &typenum);\n\tif (PyArray_IsScalar(self, ComplexFloating)) {\n\t\tret = PyArray_Scalar(_SOFFSET_(self, typenum)\t\t\\\n\t\t\t\t + typecode->elsize, typecode, NULL);\n\t}\n\telse if PyArray_IsScalar(self, Object) {\n\t\tPyObject *obj = ((PyObjectScalarObject *)self)->obval;\n\t\tPyArray_Descr *newtype;\n\t\tret = PyObject_GetAttrString(obj, \"imag\");\n\t\tif (ret == NULL) {\n\t\t\tPyErr_Clear();\n\t\t\tobj = PyInt_FromLong(0);\n\t\t\tnewtype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\t\tret = PyArray_Scalar((char *)&obj, newtype, NULL);\n\t\t\tPy_DECREF(newtype);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t}\n\telse {\n\t\tchar *temp;\n\t\ttemp = PyDataMem_NEW(typecode->elsize);\n\t\tmemset(temp, '\\0', typecode->elsize);\n\t\tret = PyArray_Scalar(temp, typecode, NULL);\n\t\tPyDataMem_FREE(temp);\n\t}\n\t\n\tPy_DECREF(typecode);\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_flat_get(PyObject *self)\n{\n\tPyObject *ret, *arr;\n\n\tarr = PyArray_FromScalar(self, NULL);\n\tif (arr == NULL) return NULL;\n\tret = PyArray_IterNew(arr);\n\tPy_DECREF(arr);\n\treturn ret;\n}\n\nstatic PyGetSetDef gentype_getsets[] = {\n {\"ndim\", \n\t (getter)gentype_ndim_get, \n\t (setter) 0, \n\t \"number of array dimensions\"},\n {\"flags\", \n\t (getter)gentype_flags_get, \n\t (setter)0, \n\t \"integer value of flags\"},\n {\"shape\", \n\t (getter)gentype_shape_get, \n\t (setter)0, \n\t \"tuple of array dimensions\"},\n {\"strides\", \n\t (getter)gentype_shape_get, \n\t (setter) 0, \n\t \"tuple of bytes steps in each dimension\"},\n {\"data\",\n\t (getter)gentype_data_get, \n\t (setter) 0, \n\t \"pointer to start of data\"},\n {\"itemsize\", \n\t (getter)gentype_itemsize_get, \n\t (setter)0, \n\t \"length of one element in bytes\"},\n {\"size\",\n (getter)gentype_size_get,\n (setter)0,\n \"number of elements in the gentype\"},\n {\"nbytes\",\n (getter)gentype_itemsize_get,\n (setter)0,\n \"length of item in bytes\"},\n\t{\"base\",\n\t (getter)gentype_base_get,\n\t (setter)0,\n\t \"base object\"},\n {\"dtype\", \n\t (getter)gentype_type_get, \n\t (setter)0, \n\t \"get gentype type class\"},\n\t{\"dtypechar\",\n\t (getter)gentype_typechar_get,\n\t (setter)0,\n\t \"get gentype type character code\"},\n\t{\"dtypestr\",\n\t (getter)gentype_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n\t{\"dtypedescr\",\n\t (getter)gentype_typedescr_get,\n\t NULL,\n\t \"get array data-descriptor\"},\n {\"real\", \n\t (getter)gentype_real_get, \n\t (setter)0,\n\t \"real part of scalar\"},\n {\"imag\", \n\t (getter)gentype_imag_get, \n\t (setter)0, \n\t \"imaginary part of scalar\"},\n\t{\"flat\", \n\t (getter)gentype_flat_get, \n\t (setter)0, \n\t \"a 1-d view of scalar\"}, \n\t{\"__array_data__\", \n\t (getter)gentype_dataptr_get,\n\t NULL,\n\t \"Array protocol: data\"},\n\t{\"__array_typestr__\",\n\t (getter)gentype_typestr_get,\n\t NULL,\n\t \"Array protocol: typestr\"},\n\t{\"__array_descr__\",\n\t (getter)gentype_descr_get,\n\t NULL,\n\t \"Array protocol: descr\"},\n\t{\"__array_shape__\", \n\t (getter)gentype_shape_get,\n\t NULL,\n\t \"Array protocol: shape\"},\n\t{\"__array_strides__\",\n\t (getter)gentype_shape_get,\n\t NULL,\n\t \"Array protocol: strides\"},\n {\"__array_struct__\",\n (getter)gentype_struct_get,\n NULL,\n \"Array protocol: struct\"},\n\t/* Does not have __array_priority__ because it is not a subtype.\n\t */\n \t{NULL, NULL, NULL, NULL} /* Sentinel */\n};\n\n\n/* 0-dim array from scalar object */\n\nstatic char doc_getarray[] = \"sc.__array__(|type) return 0-dim array\";\n\nstatic PyObject *\ngentype_getarray(PyObject *scalar, PyObject *args) \n{\n\tPyArray_Descr *outcode=NULL;\n\tPyObject *ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", &PyArray_DescrConverter,\n\t\t\t &outcode)) return NULL;\n\tret = PyArray_FromScalar(scalar, outcode);\n\treturn ret;\n}\n\nstatic char doc_sc_wraparray[] = \"sc.__array_wrap__(obj) return scalar from array\";\n\nstatic PyObject *\ngentype_wraparray(PyObject *scalar, PyObject *args)\n{\n\tPyObject *arr;\n\n\tif (PyTuple_Size(args) < 1) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"only accepts 1 argument.\");\n\t\treturn NULL;\n\t}\n\tarr = PyTuple_GET_ITEM(args, 0);\n\tif (!PyArray_Check(arr)) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"can only be called with ndarray object\");\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_Scalar(PyArray_DATA(arr), PyArray_DESCR(arr), arr);\n}\n\n\n/**begin repeat\n\n#name=tolist, item, tostring, astype, copy, resize, __deepcopy__, choose, searchsorted, argmax, argmin, reshape, view, swapaxes, max, min, ptp, conj, conjugate, nonzero, all, any, flatten, ravel, fill, transpose, newbyteorder#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *self, PyObject *args)\n{\n\treturn gentype_generic_method(self, args, NULL, \"@name@\");\n}\n/**end repeat**/\n\nstatic PyObject *\ngentype_squeeze(PyObject *self, PyObject *args)\n{\n if (!PyArg_ParseTuple(args, \"\")) return NULL;\n\tPy_INCREF(self);\n\treturn self;\n}\n\nstatic int\ngentype_getreadbuf(PyObject *, int, void **);\n\nstatic PyObject *\ngentype_byteswap(PyObject *self, PyObject *args)\n{\n\tBool inplace=FALSE;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_BoolConverter, &inplace))\n\t\treturn NULL;\n\t\n\tif (inplace) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot byteswap a scalar in-place\");\n\t\treturn NULL;\n\t}\n\telse {\n\t\t/* get the data, copyswap it and pass it to a new Array scalar\n\t\t */\n\t\tchar *data;\n\t\tint numbytes;\n\t\tPyArray_Descr *descr;\n\t\tPyObject *new;\n\t\tchar *newmem;\n\n\t\tnumbytes = gentype_getreadbuf(self, 0, (void **)&data);\n\t\tdescr = PyArray_DescrFromScalar(self);\n\t\tnewmem = _pya_malloc(descr->elsize);\n\t\tif (newmem == NULL) {Py_DECREF(descr); return PyErr_NoMemory();}\n\t\telse memcpy(newmem, data, descr->elsize);\n\t\tdescr->f->copyswap(newmem, NULL, 1, descr->elsize);\n\t\tnew = PyArray_Scalar(newmem, descr, NULL);\n\t\t_pya_free(newmem);\n\t\tPy_DECREF(descr);\n\t\treturn new;\n\t}\n}\n\n\n/**begin repeat\n\n#name=take, getfield, put, putmask, repeat, tofile, mean, trace, diagonal, clip, std, var, sum, cumsum, prod, cumprod, compress, sort, argsort#\n*/\n\nstatic PyObject *\ngentype_@name@(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\treturn gentype_generic_method(self, args, kwds, \"@name@\");\n}\n/**end repeat**/\n\nstatic PyObject *\nvoidtype_getfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyObject *ret;\n\n\tret = gentype_generic_method((PyObject *)self, args, kwds, \"getfield\");\n\tif (!ret) return ret;\n\tif (PyArray_IsScalar(ret, Generic) &&\t\\\n\t (!PyArray_IsScalar(ret, Void))) {\n\t\tPyArray_Descr *new;\n\t\tif (!PyArray_ISNBO(self->descr->byteorder)) {\n\t\t\tnew = PyArray_DescrFromScalar(ret);\n\t\t\tnew->f->copyswap(_SOFFSET_(ret, \n\t\t\t\t\t\t new->type_num),\n\t\t\t\t\t NULL, 1, new->elsize);\n\t\t\tPy_DECREF(new);\n\t\t}\n\t}\n\treturn ret;\n}\n\nstatic PyObject *\ngentype_setfield(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\t\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"Can't set fields in a non-void array scalar.\");\n\treturn NULL;\n}\t\n\nstatic PyObject *\nvoidtype_setfield(PyVoidScalarObject *self, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *typecode;\n\tint offset = 0;\n\tPyObject *value, *src;\n\tint mysize;\n\tchar *dptr;\n\tstatic char *kwlist[] = {\"value\", \"dtype\", \"offset\", 0};\n\t\n\tif ((self->flags & WRITEABLE) != WRITEABLE) {\n\t\tPyErr_SetString(PyExc_RuntimeError,\n\t\t\t\t\"Can't write to memory\");\n\t\treturn NULL;\n\t}\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO&|i\", kwlist,\n\t\t\t\t\t &value,\n\t\t\t\t\t PyArray_DescrConverter, \n\t\t\t\t\t &typecode, &offset)) return NULL;\n\n\tmysize = self->ob_size;\n\t\n\tif (offset < 0 || (offset + typecode->elsize) > mysize) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"Need 0 <= offset <= %d for requested type \" \\\n\t\t\t \"but received offset = %d\",\n\t\t\t mysize-typecode->elsize, offset);\n\t\tPy_DECREF(typecode);\n\t\treturn NULL;\n\t}\t\n\n\tdptr = self->obval + offset;\n\n\t/* Copy data from value to correct place in dptr */\n src = PyArray_FromAny(value, typecode, 0, 0, CARRAY_FLAGS);\n if (src == NULL) return NULL;\n\ttypecode->f->copyswap(dptr, PyArray_DATA(src), \n\t\t\t !PyArray_ISNBO(self->descr->byteorder),\n\t\t\t PyArray_ITEMSIZE(src));\n\tPy_DECREF(src);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\nstatic PyObject *\ngentype_reduce(PyObject *self, PyObject *args)\n{\n\tPyObject *ret=NULL, *obj=NULL, *mod=NULL;\n\tconst char *buffer; \n\tint buflen;\n\n\t/* Return a tuple of (callable object, arguments) */\n\n\tret = PyTuple_New(2);\n\tif (ret == NULL) return NULL;\t\n\tif (PyObject_AsReadBuffer(self, (const void **)&buffer, &buflen)<0) {\n\t\tPy_DECREF(ret); return NULL;\n\t}\n\tmod = PyImport_ImportModule(\"numpy.core.multiarray\");\n\tif (mod == NULL) return NULL;\n\tobj = PyObject_GetAttrString(mod, \"scalar\");\n\tPy_DECREF(mod);\n\tif (obj == NULL) return NULL;\n\tPyTuple_SET_ITEM(ret, 0, obj);\n\tobj = PyObject_GetAttrString((PyObject *)self, \"dtypedescr\");\n\tif PyArray_IsScalar(self, Object) {\n\t\tmod = ((PyObjectScalarObject *)self)->obval;\n\t\tPyTuple_SET_ITEM(ret, 1,\n\t\t\t\t Py_BuildValue(\"NO\", obj, mod));\n\t}\n\telse {\n\t\tmod = PyString_FromStringAndSize(buffer, buflen);\n\t\tPyTuple_SET_ITEM(ret, 1, \n\t\t\t\t Py_BuildValue(\"NN\", obj, mod));\n\t}\n\treturn ret;\n}\n\n/* ignores everything */\nstatic PyObject *\ngentype_setstate(PyObject *self, PyObject *args)\n{\n\tPy_INCREF(Py_None);\n\treturn (Py_None);\n}\n\nstatic PyObject *\ngentype_dump(PyObject *self, PyObject *args)\n{\n\tPyObject *file=NULL;\n\tint ret;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &file))\n\t\treturn NULL;\n\tret = PyArray_Dump(self, file, 2);\n\tif (ret < 0) return NULL;\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyObject *\ngentype_dumps(PyObject *self, PyObject *args)\n{\n\tif (!PyArg_ParseTuple(args, \"\"))\n\t\treturn NULL;\n\treturn PyArray_Dumps(self, 2);\n}\n\n\n/* setting flags cannot be done for scalars */\nstatic PyObject *\ngentype_setflags(PyObject *self, PyObject *args, PyObject *kwds)\n{\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n\n/* need to fill in doc-strings for these methods on import -- copy from \n array docstrings \n*/\nstatic PyMethodDef gentype_methods[] = {\n {\"tolist\",\t (PyCFunction)gentype_tolist,\t1, NULL},\n {\"item\", (PyCFunction)gentype_item, METH_VARARGS, NULL},\n\t{\"tofile\", (PyCFunction)gentype_tofile, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"tostring\", (PyCFunction)gentype_tostring, METH_VARARGS, NULL},\n {\"byteswap\", (PyCFunction)gentype_byteswap,1, NULL},\n {\"astype\", (PyCFunction)gentype_astype, 1, NULL},\n\t{\"getfield\", (PyCFunction)gentype_getfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{\"setfield\", (PyCFunction)gentype_setfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n {\"copy\", (PyCFunction)gentype_copy, 1, NULL}, \n {\"resize\", (PyCFunction)gentype_resize, 1, NULL}, \n\n\t{\"__array__\", (PyCFunction)gentype_getarray, 1, doc_getarray},\n\t{\"__array_wrap__\", (PyCFunction)gentype_wraparray, 1, doc_sc_wraparray},\n\n /* for the copy module */\n {\"__copy__\", (PyCFunction)gentype_copy, 1, NULL},\n {\"__deepcopy__\", (PyCFunction)gentype___deepcopy__, 1, NULL},\n\n\n {\"__reduce__\", (PyCFunction) gentype_reduce, 1, NULL},\t\n\t/* For consistency does nothing */\n\t{\"__setstate__\", (PyCFunction) gentype_setstate, 1, NULL},\n\n\t{\"dumps\", (PyCFunction) gentype_dumps, 1, NULL},\n\t{\"dump\", (PyCFunction) gentype_dump, 1, NULL},\n\n\t/* Methods for array */\n\t{\"fill\", (PyCFunction)gentype_fill,\n\t METH_VARARGS, NULL},\n\t{\"transpose\",\t(PyCFunction)gentype_transpose, \n\t METH_VARARGS, NULL},\n\t{\"take\",\t(PyCFunction)gentype_take, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"put\",\t(PyCFunction)gentype_put, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"putmask\",\t(PyCFunction)gentype_putmask, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"repeat\",\t(PyCFunction)gentype_repeat, \n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"choose\",\t(PyCFunction)gentype_choose, \n\t METH_VARARGS, NULL},\t\n\t{\"sort\",\t(PyCFunction)gentype_sort, \n\t METH_VARARGS, NULL},\n\t{\"argsort\",\t(PyCFunction)gentype_argsort, \n\t METH_VARARGS, NULL},\n\t{\"searchsorted\", (PyCFunction)gentype_searchsorted, \n\t METH_VARARGS, NULL},\t\n\t{\"argmax\",\t(PyCFunction)gentype_argmax, \n\t METH_VARARGS, NULL},\n\t{\"argmin\", (PyCFunction)gentype_argmin,\n\t METH_VARARGS, NULL},\n\t{\"reshape\",\t(PyCFunction)gentype_reshape, \n\t METH_VARARGS, NULL},\n\t{\"squeeze\",\t(PyCFunction)gentype_squeeze, \n\t METH_VARARGS, NULL},\n\t{\"view\", (PyCFunction)gentype_view, \n\t METH_VARARGS, NULL},\n\t{\"swapaxes\", (PyCFunction)gentype_swapaxes,\n\t METH_VARARGS, NULL},\n\t{\"max\", (PyCFunction)gentype_max,\n\t METH_VARARGS, NULL},\n\t{\"min\", (PyCFunction)gentype_min,\n\t METH_VARARGS, NULL},\n\t{\"ptp\", (PyCFunction)gentype_ptp,\n\t METH_VARARGS, NULL},\n\t{\"mean\", (PyCFunction)gentype_mean,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"trace\", (PyCFunction)gentype_trace,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"diagonal\", (PyCFunction)gentype_diagonal,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"clip\", (PyCFunction)gentype_clip,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"conj\", (PyCFunction)gentype_conj,\n\t METH_VARARGS, NULL},\n\t{\"conjugate\", (PyCFunction)gentype_conjugate,\n\t METH_VARARGS, NULL},\n\t{\"nonzero\", (PyCFunction)gentype_nonzero,\n\t METH_VARARGS, NULL},\n\t{\"std\", (PyCFunction)gentype_std,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"var\", (PyCFunction)gentype_var,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"sum\", (PyCFunction)gentype_sum,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"cumsum\", (PyCFunction)gentype_cumsum,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"prod\", (PyCFunction)gentype_prod,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"cumprod\", (PyCFunction)gentype_cumprod,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"all\", (PyCFunction)gentype_all,\n\t METH_VARARGS, NULL},\n\t{\"any\", (PyCFunction)gentype_any,\n\t METH_VARARGS, NULL},\n\t{\"compress\", (PyCFunction)gentype_compress,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"flatten\", (PyCFunction)gentype_flatten,\n\t METH_VARARGS, NULL},\n\t{\"ravel\", (PyCFunction)gentype_ravel,\n\t METH_VARARGS, NULL},\n\t{\"setflags\", (PyCFunction)gentype_setflags,\n\t METH_VARARGS|METH_KEYWORDS, NULL},\n\t{\"newbyteorder\", (PyCFunction)gentype_newbyteorder,\n\t METH_VARARGS, NULL},\n {NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\nstatic PyGetSetDef voidtype_getsets[] = {\n {\"flags\", \n\t (getter)voidtype_flags_get, \n\t (setter)0, \n\t \"integer value of flags\"},\n\t{\"dtypedescr\",\n\t (getter)voidtype_dtypedescr_get,\n\t (setter)0,\n\t \"dtypedescr object\"},\n\t{NULL, NULL}\n};\n\nstatic PyMethodDef voidtype_methods[] = {\n\t{\"getfield\", (PyCFunction)voidtype_getfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{\"setfield\", (PyCFunction)voidtype_setfield, \n\t METH_VARARGS | METH_KEYWORDS, NULL},\n\t{NULL, NULL}\n};\n\n/************* As_mapping functions for void array scalar ************/\n\n\nstatic int\nvoidtype_length(PyVoidScalarObject *self) \n{\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\treturn 0;\n\t}\n\telse { /* return the number of fields */\n\t\tPyObject *key;\n\t\tPyObject *flist;\n\t\tkey = PyInt_FromLong(-1);\n\t\tflist = PyDict_GetItem(self->descr->fields, key);\n\t\tPy_DECREF(key);\n\t\tif (!flist) return 0;\n\t\treturn PyList_GET_SIZE(flist);\n\t}\n}\n\n/* get field by name or number */\nstatic PyObject *\nvoidtype_subscript(PyVoidScalarObject *self, PyObject *ind)\n{\n\tint n, m;\n\tchar *msg = \"invalid index\";\n\tPyObject *flist=NULL, *key, *fieldinfo;\n\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"can't index void scalar without fields\");\n\t\treturn NULL;\n\t}\n\n\tif (PyString_Check(ind) || PyUnicode_Check(ind)) {\n\t\t/* look up in fields */\n\t\tfieldinfo = PyDict_GetItem(self->descr->fields, ind);\n\t\tif (!fieldinfo) {\n\t\t\tPyErr_SetString(PyExc_IndexError, msg);\n\t\t\treturn NULL;\n\t\t}\n\t\treturn voidtype_getfield(self, fieldinfo, NULL);\n\t}\n\t\n\t/* try to convert it to a number */\n\tn = PyArray_PyIntAsIntp(ind);\n\tif (error_converting(n)) {\n\t\tPyErr_Clear();\n\t\tgoto fail;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tflist = PyDict_GetItem(self->descr->fields, key);\n\tPy_DECREF(key);\n\tif (!flist) m = 0; \n\tm = PyList_GET_SIZE(flist);\n\tif (n < 0) n += m;\n\tif (n < 0 || n >= m) goto fail;\n\tfieldinfo = PyDict_GetItem(self->descr->fields, \n\t\t\t\t PyList_GET_ITEM(flist, n));\n\treturn voidtype_getfield(self, fieldinfo, NULL);\n\n fail:\n\tPyErr_SetString(PyExc_IndexError, msg);\n\treturn NULL;\n}\n\nstatic int\nvoidtype_ass_subscript(PyVoidScalarObject *self, PyObject *ind, PyObject *val) \n{\n\tint n, m;\n\tchar *msg = \"invalid index\";\n\tPyObject *flist=NULL, *key, *fieldinfo, *newtup;\n\tPyObject *res;\n\n\tif (!self->descr->fields || self->descr->fields == Py_None) {\n\t\tPyErr_SetString(PyExc_IndexError, \n\t\t\t\t\"can't index void scalar without fields\");\n\t\treturn -1;\n\t}\n\n\tif (PyString_Check(ind) || PyUnicode_Check(ind)) {\n\t\t/* look up in fields */\n\t\tfieldinfo = PyDict_GetItem(self->descr->fields, ind);\n\t\tif (!fieldinfo) {\n\t\t\tPyErr_SetString(PyExc_IndexError, msg);\n\t\t\treturn -1;\n\t\t}\n\t\tnewtup = Py_BuildValue(\"(OOO)\", val, \n\t\t\t\t PyTuple_GET_ITEM(fieldinfo, 0),\n\t\t\t\t PyTuple_GET_ITEM(fieldinfo, 1));\n\t\tres = voidtype_setfield(self, newtup, NULL);\n\t\tPy_DECREF(newtup);\n\t\tif (!res) return -1;\n\t\tPy_DECREF(res);\n\t\treturn 0;\n\t}\n\t\n\t/* try to convert it to a number */\n\tn = PyArray_PyIntAsIntp(ind);\n\tif (error_converting(n)) {\n\t\tPyErr_Clear();\n\t\tgoto fail;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tflist = PyDict_GetItem(self->descr->fields, key);\n\tPy_DECREF(key);\n\tif (!flist) m = 0; \n\tm = PyList_GET_SIZE(flist);\n\tif (n < 0) n += m;\n\tif (n < 0 || n >= m) goto fail;\n\tfieldinfo = PyDict_GetItem(self->descr->fields, \n\t\t\t\t PyList_GET_ITEM(flist, n));\n\tnewtup = Py_BuildValue(\"(OOO)\", val, \n\t\t\t PyTuple_GET_ITEM(fieldinfo, 0),\n\t\t\t PyTuple_GET_ITEM(fieldinfo, 1));\n\tres = voidtype_setfield(self, fieldinfo, NULL);\n\tPy_DECREF(newtup);\n\tif (!res) return -1;\n\tPy_DECREF(res);\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_IndexError, msg);\n\treturn -1;\n}\n\nstatic PyMappingMethods voidtype_as_mapping = {\n (inquiry)voidtype_length,\t\t /*mp_length*/\n (binaryfunc)voidtype_subscript,\t /*mp_subscript*/\n (objobjargproc)voidtype_ass_subscript,\t /*mp_ass_subscript*/\n};\n\n\nstatic int\ngentype_getreadbuf(PyObject *self, int segment, void **ptrptr)\n{\n\tint numbytes;\n\tPyArray_Descr *outcode;\n\t\n\tif (segment != 0) {\n\t\tPyErr_SetString(PyExc_SystemError, \n\t\t\t\t\"Accessing non-existent array segment\");\n\t\treturn -1;\n\t}\n\n\toutcode = PyArray_DescrFromScalar(self);\n\tnumbytes = outcode->elsize;\n\tif PyArray_IsScalar(self, Flexible) {\n\t\tif PyArray_IsScalar(self, String)\n\t\t\t*ptrptr = PyString_AS_STRING(self);\n\t\telse if PyArray_IsScalar(self, Unicode)\n\t\t\t*ptrptr = (char *)PyUnicode_AS_DATA(self);\n\t\telse if PyArray_IsScalar(self, Void)\n\t\t\t*ptrptr = ((PyVoidScalarObject *)self)->obval;\n\t}\n\telse \n\t\t*ptrptr = (void *)_SOFFSET_(self, outcode->type_num);\n\n\tPy_DECREF(outcode);\n\treturn numbytes;\n}\n\nstatic int\ngentype_getsegcount(PyObject *self, int *lenp)\n{\n\tPyArray_Descr *outcode;\n\n\toutcode = PyArray_DescrFromScalar(self);\n\tif (lenp)\n\t\t*lenp = outcode->elsize;\n\tPy_DECREF(outcode);\n\treturn 1;\n}\n\nstatic int\ngentype_getcharbuf(PyObject *self, int segment, const char **ptrptr)\n{\n\tif (PyArray_IsScalar(self, String) ||\t\\\n\t PyArray_IsScalar(self, Unicode))\n\t\treturn gentype_getreadbuf(self, segment, (void **)ptrptr);\n\telse {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"Non-character array cannot be interpreted \"\\\n\t\t\t\t\"as character buffer.\");\n\t\treturn -1;\n\t}\n}\n\n\nstatic PyBufferProcs gentype_as_buffer = {\n (getreadbufferproc)gentype_getreadbuf, /*bf_getreadbuffer*/\n (getwritebufferproc)0, /*bf_getwritebuffer*/\n (getsegcountproc)gentype_getsegcount,\t /*bf_getsegcount*/\n (getcharbufferproc)gentype_getcharbuf, /*bf_getcharbuffer*/\n};\n\n\n#define BASEFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_CHECKTYPES\n#define LEAFFLAGS Py_TPFLAGS_DEFAULT | Py_TPFLAGS_CHECKTYPES\n\nstatic PyTypeObject PyGenericArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"generic_arrtype\",\t /*tp_name*/\n sizeof(PyObject),\t\t /*tp_basicsize*/\n};\n\nstatic void\nunicode_dealloc(PyObject *v) \n{\n\tPyDataMem_FREE(((PyVoidScalarObject *)v)->obval);\n\tv->ob_type->tp_free(v);\n}\n\nstatic void\nvoid_dealloc(PyVoidScalarObject *v) \n{\n\tif (v->flags & OWNDATA)\n\t\tPyDataMem_FREE(v->obval);\n\tPy_XDECREF(v->descr);\n\tPy_XDECREF(v->base);\n\tv->ob_type->tp_free(v);\n}\n\nstatic void\nobject_arrtype_dealloc(PyObject *v)\n{\n\tPy_XDECREF(((PyObjectScalarObject *)v)->obval);\n\tv->ob_type->tp_free(v);\n}\n\n/* string and unicode inherit from Python Type first and so GET_ITEM is different to\n get to the Python Type.\n */\n\n/**begin repeat \n#name=byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, object#\n#TYPE=BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, STRING, UNICODE, OBJECT#\n#num=1*16,0,0,1#\n*/\nstatic PyObject *\n@name@_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj=NULL;\n\tPyObject *arr;\n\tPyArray_Descr *typecode;\n\n\tif (type->tp_bases && (PyTuple_GET_SIZE(type->tp_bases)==2)) {\n\t\tPyTypeObject *sup;\n\t\tPyObject *ret;\n\t\t/* We are inheriting from a Python type as well so\n\t\t give it first dibs on conversion */\n\t\tsup = (PyTypeObject *)PyTuple_GET_ITEM(type->tp_bases, @num@);\n\t\tret = sup->tp_new(type, args, kwds);\n\t\tif (ret) return ret;\n\t\tPyErr_Clear();\n\t\t/* now do default conversion */\n\t}\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\n\ttypecode = PyArray_DescrFromType(PyArray_@TYPE@);\n\tarr = PyArray_FromAny(obj, typecode, 0, 0, FORCECAST);\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n/**end repeat**/\n\n/* bool->tp_new only returns Py_True or Py_False */\nstatic PyObject *\nbool_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj=NULL;\n\tPyObject *arr;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\t\n\tarr = PyArray_FROM_OTF(obj, PyArray_BOOL, FORCECAST);\n\treturn PyArray_Return((PyArrayObject *)arr);\n}\n\nstatic PyObject *\nvoid_arrtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj, *arr;\n\tulonglong memu=1;\n\tPyObject *new=NULL;\n\tchar *destptr;\n\n\tif (!PyArg_ParseTuple(args, \"O\", &obj)) return NULL;\n\t/* For a VOID scalar first see if obj is an integer or long \n\t and create new memory of that size (filled with 0) for the scalar\n\t*/\n\n\tif (PyLong_Check(obj) || PyInt_Check(obj) || \\\n\t PyArray_IsScalar(obj, Integer) ||\n\t (PyArray_Check(obj) && PyArray_NDIM(obj)==0 &&\t\\\n\t PyArray_ISINTEGER(obj))) {\n\t\tnew = obj->ob_type->tp_as_number->nb_long(obj);\n\t}\n\tif (new && PyLong_Check(new)) {\n\t\tPyObject *ret;\n\t\tmemu = PyLong_AsUnsignedLongLong(new);\n\t\tPy_DECREF(new);\n\t\tif (PyErr_Occurred() || (memu > MAX_INT)) {\n\t\t\tPyErr_Clear();\n\t\t\tPyErr_Format(PyExc_OverflowError, \n\t\t\t\t \"size must be smaller than %d\",\n\t\t\t\t (int) MAX_INT);\n\t\t\treturn NULL;\n\t\t}\n\t\tdestptr = PyDataMem_NEW((int) memu);\n\t\tif (destptr == NULL) return PyErr_NoMemory();\n\t\tret = type->tp_alloc(type, 0);\n\t\tif (ret == NULL) {\n\t\t\tPyDataMem_FREE(destptr);\n\t\t\treturn PyErr_NoMemory();\n\t\t}\n\t\t((PyVoidScalarObject *)ret)->obval = destptr;\n\t\t((PyVoidScalarObject *)ret)->ob_size = (int) memu;\n\t\t((PyVoidScalarObject *)ret)->descr = \\\n\t\t\tPyArray_DescrNewFromType(PyArray_VOID);\n\t\t((PyVoidScalarObject *)ret)->descr->elsize = (int) memu;\n\t\t((PyVoidScalarObject *)ret)->flags = BEHAVED_FLAGS | OWNDATA;\n\t\t((PyVoidScalarObject *)ret)->base = NULL;\n\t\tmemset(destptr, '\\0', (size_t) memu);\n\t\treturn ret;\n\t}\n\n\tarr = PyArray_FROM_OTF(obj, PyArray_VOID, FORCECAST);\n return PyArray_Return((PyArrayObject *)arr);\n}\n\n\n/**************** Define Hash functions ********************/\n\n/**begin repeat\n#lname=bool,ubyte,ushort#\n#name=Bool,UByte, UShort#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n return (long)(((Py@name@ScalarObject *)obj)->obval);\n}\n/**end repeat**/\n\n/**begin repeat\n#lname=byte,short,uint,ulong#\n#name=Byte,Short,UInt,ULong#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((Py@name@ScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n/**end repeat**/\n\n#if SIZEOF_INT != SIZEOF_LONG\nstatic long\nint_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((PyIntScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n#endif\n\n/**begin repeat\n#char=,u#\n#Char=,U#\n#ext=&& (x >= LONG_MIN),#\n*/\n#if SIZEOF_LONG != SIZEOF_LONGLONG\n/* we assume SIZEOF_LONGLONG=2*SIZEOF_LONG */\nstatic long\n@char@longlong_arrtype_hash(PyObject *obj)\n{\n long y;\n @char@longlong x = (((Py@Char@LongLongScalarObject *)obj)->obval);\n\n if ((x <= LONG_MAX)@ext@) {\n y = (long) x;\n }\n else {\n union Mask {\n long hashvals[2];\n @char@longlong v;\n } both;\n\n both.v = x;\n y = both.hashvals[0] + (1000003)*both.hashvals[1];\n }\n if (y == -1) y = -2;\n return y;\n}\n#endif\n/**end repeat**/\n\n#if SIZEOF_LONG==SIZEOF_LONGLONG\nstatic long\nulonglong_arrtype_hash(PyObject *obj)\n{\n long x = (long)(((PyULongLongScalarObject *)obj)->obval);\n if (x == -1) x=-2;\n return x;\n}\n#endif\n\n\n\n/* Wrong thing to do for longdouble, but....*/\n/**begin repeat\n#lname=float, longdouble#\n#name=Float, LongDouble#\n */\nstatic long\n@lname@_arrtype_hash(PyObject *obj)\n{\n return _Py_HashDouble((double) ((Py@name@ScalarObject *)obj)->obval);\n}\n\n/* borrowed from complex_hash */\nstatic long\nc@lname@_arrtype_hash(PyObject *obj)\n{\n long hashreal, hashimag, combined;\n hashreal = _Py_HashDouble((double) \\\n (((PyC@name@ScalarObject *)obj)->obval).real);\n\n if (hashreal == -1) return -1;\n hashimag = _Py_HashDouble((double) \\\n (((PyC@name@ScalarObject *)obj)->obval).imag);\n if (hashimag == -1) return -1;\n\n combined = hashreal + 1000003 * hashimag;\n if (combined == -1) combined = -2;\n return combined;\n}\n/**end repeat**/\n\nstatic long\nobject_arrtype_hash(PyObject *obj)\n{\n return PyObject_Hash(((PyObjectScalarObject *)obj)->obval);\n}\n\n/* just hash the pointer */\nstatic long\nvoid_arrtype_hash(PyObject *obj)\n{\n return _Py_HashPointer((void *)(((PyVoidScalarObject *)obj)->obval));\n}\n\n/*object arrtype getattro and setattro */\nstatic PyObject *\nobject_arrtype_getattro(PyObjectScalarObject *obj, PyObject *attr) {\n\tPyObject *res;\n\t/* first look in generic type and then hand off to actual object */\n\n\tres = PyObject_GenericGetAttr((PyObject *)obj, attr);\n\tif (res) return res;\n\tPyErr_Clear();\n\treturn PyObject_GenericGetAttr(obj->obval, attr);\n}\n\nstatic int\nobject_arrtype_setattro(PyObjectScalarObject *obj, PyObject *attr, PyObject *val) {\n\tint res;\n\t/* first look in generic type and then hand off to actual object */\n\n\tres = PyObject_GenericSetAttr((PyObject *)obj, attr, val);\n\tif (res >= 0) return res;\n\tPyErr_Clear();\n\treturn PyObject_GenericSetAttr(obj->obval, attr, val);\n}\n\nstatic int \nobject_arrtype_length(PyObjectScalarObject *self) \n{\n\treturn PyObject_Length(self->obval);\n}\n\nstatic PyObject *\nobject_arrtype_concat(PyObjectScalarObject *self, PyObject *other)\n{\n\treturn PySequence_Concat(self->obval, other);\n}\n\nstatic PyObject *\nobject_arrtype_repeat(PyObjectScalarObject *self, int count)\n{\n\treturn PySequence_Repeat(self->obval, count);\n}\n\nstatic PyObject *\nobject_arrtype_subscript(PyObjectScalarObject *self, PyObject *key)\n{\n\treturn PyObject_GetItem(self->obval, key);\n}\n\nstatic int\nobject_arrtype_ass_subscript(PyObjectScalarObject *self, PyObject *key, \n\t\t\t PyObject *value)\n{\n\treturn PyObject_SetItem(self->obval, key, value);\n}\n\nstatic int\nobject_arrtype_contains(PyObjectScalarObject *self, PyObject *ob)\n{\n\treturn PySequence_Contains(self->obval, ob);\n}\n\nstatic PyObject *\nobject_arrtype_inplace_concat(PyObjectScalarObject *self, PyObject *o)\n{\n\treturn PySequence_InPlaceConcat(self->obval, o);\n}\n\nstatic PyObject *\nobject_arrtype_inplace_repeat(PyObjectScalarObject *self, int count)\n{\n\treturn PySequence_InPlaceRepeat(self->obval, count);\n}\n\nstatic PySequenceMethods object_arrtype_as_sequence = {\n (inquiry)object_arrtype_length, /*sq_length*/\n (binaryfunc)object_arrtype_concat, /*sq_concat*/\n (intargfunc)object_arrtype_repeat, /*sq_repeat*/\n 0, /*sq_item*/\n 0, /*sq_slice*/\n 0, /* sq_ass_item */\n 0, /* sq_ass_slice */\n (objobjproc)object_arrtype_contains, /* sq_contains */\n (binaryfunc)object_arrtype_inplace_concat, /* sq_inplace_concat */\n (intargfunc)object_arrtype_inplace_repeat, /* sq_inplace_repeat */\n};\n\nstatic PyMappingMethods object_arrtype_as_mapping = {\n (inquiry)object_arrtype_length,\n (binaryfunc)object_arrtype_subscript,\n (objobjargproc)object_arrtype_ass_subscript,\n};\n\nstatic int \nobject_arrtype_getsegcount(PyObjectScalarObject *self, int *lenp) \n{\n\tint newlen;\n\tint cnt;\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\t\n\tif (pb == NULL || \\\n\t pb->bf_getsegcount == NULL || \\\n\t (cnt = (*pb->bf_getsegcount)(self->obval, &newlen)) != 1) \n\t\treturn 0;\n\t\n\tif (lenp) \n\t\t*lenp = newlen;\n\t\n\treturn cnt;\n}\n\nstatic int \nobject_arrtype_getreadbuf(PyObjectScalarObject *self, int segment, void **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getreadbuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a readable buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getreadbuffer)(self->obval, segment, ptrptr);\n}\n\nstatic int \nobject_arrtype_getwritebuf(PyObjectScalarObject *self, int segment, void **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getwritebuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a writeable buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getwritebuffer)(self->obval, segment, ptrptr);\n}\n\nstatic int \nobject_arrtype_getcharbuf(PyObjectScalarObject *self, int segment, \n\t\t\t const char **ptrptr) \n{\n\tPyBufferProcs *pb = self->obval->ob_type->tp_as_buffer;\n\n\tif (pb == NULL || \\\n\t pb->bf_getcharbuffer == NULL ||\n\t pb->bf_getsegcount == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"expected a character buffer object\");\n\t\treturn -1;\n\t}\n\t\n\treturn (*pb->bf_getcharbuffer)(self->obval, segment, ptrptr);\n}\n\nstatic PyBufferProcs object_arrtype_as_buffer = {\n (getreadbufferproc)object_arrtype_getreadbuf,\n (getwritebufferproc)object_arrtype_getwritebuf,\n (getsegcountproc)object_arrtype_getsegcount,\n (getcharbufferproc)object_arrtype_getcharbuf,\n};\n\nstatic PyObject *\nobject_arrtype_call(PyObjectScalarObject *obj, PyObject *args, PyObject *kwds)\n{\n\treturn PyObject_Call(obj->obval, args, kwds);\n}\n\nstatic PyTypeObject PyObjectArrType_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"object_arrtype\",\t /*tp_name*/\n sizeof(PyObjectScalarObject),\t /*tp_basicsize*/\n 0, /* tp_itemsize */\n (destructor)object_arrtype_dealloc, /* tp_dealloc */\n 0, /* tp_print */\n 0, /* tp_getattr */\n 0, /* tp_setattr */\n 0, /* tp_compare */\n 0, /* tp_repr */\n 0, /* tp_as_number */\n &object_arrtype_as_sequence, /* tp_as_sequence */\n &object_arrtype_as_mapping, /* tp_as_mapping */\n 0, /* tp_hash */\n (ternaryfunc)object_arrtype_call, /* tp_call */\n 0, /* tp_str */\n (getattrofunc)object_arrtype_getattro, /* tp_getattro */\n (setattrofunc)object_arrtype_setattro, /* tp_setattro */\n &object_arrtype_as_buffer, /* tp_as_buffer */\n 0, /* tp_flags */\n};\n\n/**begin repeat\n#name=bool, string, unicode, void#\n#NAME=Bool, String, Unicode, Void#\n*/\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@_arrtype\",\t /*tp_name*/\n sizeof(Py@NAME@ScalarObject),\t /*tp_basicsize*/\n};\n/**end repeat**/\n\n/**begin repeat\n#NAME=Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble#\n#name=int*5, uint*5, float*3, complex*3#\n#CNAME=(CHAR, SHORT, INT, LONG, LONGLONG)*2, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE#\n*/\nstatic PyTypeObject Py@NAME@ArrType_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"@name@\" STRBITSOF_@CNAME@ \"_arrtype\",\t /*tp_name*/\n sizeof(Py@NAME@ScalarObject),\t /*tp_basicsize*/\n};\n\n/**end repeat**/\n\n\nstatic PyNumberMethods longdoubletype_as_number;\nstatic PyNumberMethods clongdoubletype_as_number;\n\n\nstatic void \ninitialize_numeric_types(void)\n{\n\tPyGenericArrType_Type.tp_dealloc = (destructor)gentype_dealloc;\n\tPyGenericArrType_Type.tp_as_number = &gentype_as_number;\n\tPyGenericArrType_Type.tp_as_buffer = &gentype_as_buffer;\n\tPyGenericArrType_Type.tp_flags = BASEFLAGS;\n\tPyGenericArrType_Type.tp_methods = gentype_methods;\n\tPyGenericArrType_Type.tp_getset = gentype_getsets;\n\tPyGenericArrType_Type.tp_new = NULL;\n PyGenericArrType_Type.tp_alloc = gentype_alloc;\n\tPyGenericArrType_Type.tp_free = _pya_free;\n\tPyGenericArrType_Type.tp_repr = gentype_repr;\n\tPyGenericArrType_Type.tp_str = gentype_str;\n\tPyGenericArrType_Type.tp_richcompare = gentype_richcompare;\n\n\tPyStringArrType_Type.tp_alloc = NULL;\n\tPyStringArrType_Type.tp_free = NULL;\n\n\tPyVoidArrType_Type.tp_methods = voidtype_methods;\n\tPyVoidArrType_Type.tp_getset = voidtype_getsets;\n\tPyVoidArrType_Type.tp_as_mapping = &voidtype_as_mapping;\n\t\n\t/**begin repeat\n#NAME=Number, Integer, SignedInteger, UnsignedInteger, Inexact, Floating, \nComplexFloating, Flexible, Character#\n\t*/\n Py@NAME@ArrType_Type.tp_flags = BASEFLAGS;\n\t/**end repeat**/\n\n\t/**begin repeat\n#name=bool, byte, short, int, long, longlong, ubyte, ushort, uint, ulong, ulonglong, float, double, longdouble, cfloat, cdouble, clongdouble, string, unicode, void, object#\n#NAME=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, String, Unicode, Void, Object#\n\t*/\n\tPy@NAME@ArrType_Type.tp_flags = LEAFFLAGS;\n\tPy@NAME@ArrType_Type.tp_new = @name@_arrtype_new;\n\tPy@NAME@ArrType_Type.tp_richcompare = gentype_richcompare;\n\t/**end repeat**/\n\t/* Allow the Void type to be subclassed -- for adding new types */\n\tPyVoidArrType_Type.tp_flags = BASEFLAGS;\n\n /**begin repeat\n#name=bool, byte, short, ubyte, ushort, uint, ulong, ulonglong, float, longdouble, cfloat, clongdouble, void, object#\n#NAME=Bool, Byte, Short, UByte, UShort, UInt, ULong, ULongLong, Float, LongDouble, CFloat, CLongDouble, Void, Object#\n */\n Py@NAME@ArrType_Type.tp_hash = @name@_arrtype_hash;\n /**end repeat**/\n\n#if SIZEOF_INT != SIZEOF_LONG\n /* We won't be inheriting from Python Int type. */\n PyIntArrType_Type.tp_hash = int_arrtype_hash;\n#endif\n\n#if SIZEOF_LONG != SIZEOF_LONGLONG\n /* We won't be inheriting from Python Int type. */\n PyLongLongArrType_Type.tp_hash = longlong_arrtype_hash;\n#endif\n\n\t/* These need to be coded specially because getitem does not\n\t return a normal Python type\n\t*/\n\tPyLongDoubleArrType_Type.tp_as_number = &longdoubletype_as_number;\n\tPyCLongDoubleArrType_Type.tp_as_number = &clongdoubletype_as_number;\n\n\t/**begin repeat\n#name=int, long, hex, oct, float, repr, str#\n#kind=tp_as_number->nb*5, tp*2#\n\t*/\n\tPyLongDoubleArrType_Type.@kind@_@name@ = longdoubletype_@name@;\n\tPyCLongDoubleArrType_Type.@kind@_@name@ = clongdoubletype_@name@;\n\t/**end repeat**/\n\n\tPyStringArrType_Type.tp_itemsize = sizeof(char);\n\tPyVoidArrType_Type.tp_dealloc = (destructor) void_dealloc;\n\tPyUnicodeArrType_Type.tp_dealloc = unicode_dealloc;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMapIter_Type.tp_iter = PyObject_SelfIter;\n\n/**begin repeat\n#name=Bool, Byte, Short, Int, Long, LongLong, UByte, UShort, UInt, ULong, ULongLong, Float, Double, LongDouble, CFloat, CDouble, CLongDouble, Object,#\n#num=BOOL, BYTE, SHORT, INT, LONG, LONGLONG, UBYTE, USHORT, UINT, ULONG, ULONGLONG, FLOAT, DOUBLE, LONGDOUBLE, CFLOAT, CDOUBLE, CLONGDOUBLE, OBJECT, NTYPES#\n**/\n PyArrayScalar_Offset[PyArray_@num@] = (int) offsetof(Py@name@ScalarObject, obval);\n/**end repeat**/\n}\n\n\n/* the order of this table is important */\nstatic PyTypeObject *typeobjects[] = {\n &PyBoolArrType_Type,\n &PyByteArrType_Type,\n\t&PyUByteArrType_Type,\n &PyShortArrType_Type,\n &PyUShortArrType_Type,\n\t&PyIntArrType_Type,\n\t&PyUIntArrType_Type,\n\t&PyLongArrType_Type,\n\t&PyULongArrType_Type,\n\t&PyLongLongArrType_Type,\n\t&PyULongLongArrType_Type,\n\t&PyFloatArrType_Type,\n\t&PyDoubleArrType_Type,\n\t&PyLongDoubleArrType_Type,\n\t&PyCFloatArrType_Type,\n\t&PyCDoubleArrType_Type,\n\t&PyCLongDoubleArrType_Type,\n\t&PyObjectArrType_Type,\n\t&PyStringArrType_Type,\n\t&PyUnicodeArrType_Type,\n\t&PyVoidArrType_Type\n};\n\nstatic int\n_typenum_fromtypeobj(PyObject *type, int user)\n{\n\tint typenum, i;\n\n\ttypenum = PyArray_NOTYPE;\n i = 0;\n\twhile(i < PyArray_NTYPES) {\n\t\tif (type == (PyObject *)typeobjects[i]) {\n\t\t\ttypenum = i;\n\t\t\tbreak;\n\t\t}\n i++;\n\t}\n\t\n\tif (!user) return typenum;\n\n\t/* Search any registered types */\n\ti = 0;\n\twhile (i < PyArray_NUMUSERTYPES) {\n\t\tif (type == (PyObject *)(userdescrs[i]->typeobj)) {\n\t\t\ttypenum = i + PyArray_USERDEF;\n\t\t\tbreak;\n\t\t}\n\t\ti++;\n\t}\n\treturn typenum;\n}\n\n/* new reference */\nstatic PyArray_Descr *\nPyArray_DescrFromTypeObject(PyObject *type)\n{\t\n\tint typenum;\n\tPyArray_Descr *new, *conv=NULL;\n\n\t/* if it's a builtin type, then use the typenumber */\n\ttypenum = _typenum_fromtypeobj(type,1);\t\n\tif (typenum != PyArray_NOTYPE) {\n\t\tnew = PyArray_DescrFromType(typenum);\n\t\tif (PyTypeNum_ISUSERDEF(typenum)) goto finish;\n\t\treturn new;\n\t}\n\n\t/* Check the generic types */\n\tif ((type == (PyObject *) &PyNumberArrType_Type) ||\t\t\\\n\t (type == (PyObject *) &PyInexactArrType_Type) ||\t\t\\\n\t (type == (PyObject *) &PyFloatingArrType_Type))\n\t\ttypenum = PyArray_DOUBLE;\n\telse if (type == (PyObject *)&PyComplexFloatingArrType_Type)\n\t\ttypenum = PyArray_CDOUBLE;\n\telse if ((type == (PyObject *)&PyIntegerArrType_Type) ||\t\\\n\t\t (type == (PyObject *)&PySignedIntegerArrType_Type))\n\t\ttypenum = PyArray_LONG;\n\telse if (type == (PyObject *) &PyUnsignedIntegerArrType_Type)\n\t\ttypenum = PyArray_ULONG;\n\telse if (type == (PyObject *) &PyCharacterArrType_Type)\n\t\ttypenum = PyArray_STRING;\n\telse if ((type == (PyObject *) &PyGenericArrType_Type) || \\\n\t\t (type == (PyObject *) &PyFlexibleArrType_Type))\n\t\ttypenum = PyArray_VOID;\n\n\tif (typenum != PyArray_NOTYPE) {\n\t\treturn PyArray_DescrFromType(typenum);\n\t}\n\t\n\t/* Otherwise --- type is a sub-type of an array scalar\n\t currently only VOID allows it -- use it as the type-object.\n\t*/\n\t/* look for a dtypedescr attribute */\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\n finish:\n\tconv = _arraydescr_fromobj(type);\n\tif (conv) {\n\t\tnew->fields = conv->fields;\n\t\tPy_INCREF(new->fields);\n\t\tnew->elsize = conv->elsize;\n\t\tnew->subarray = conv->subarray;\n\t\tconv->subarray = NULL;\n\t\tPy_DECREF(conv);\n\t}\n Py_DECREF(new->typeobj);\n new->typeobj = (PyTypeObject *)type;\n Py_INCREF(type);\n\treturn new;\n}\n\n/* New reference */\n/*OBJECT_API\n Return descr object from array scalar.\n*/\nstatic PyArray_Descr *\nPyArray_DescrFromScalar(PyObject *sc)\n{\n\tint type_num;\n\tPyArray_Descr *descr;\n\n\tif PyArray_IsScalar(sc, Void) {\n\t\tdescr = ((PyVoidScalarObject *)sc)->descr;\n\t\tPy_INCREF(descr);\n\t\treturn descr;\n\t}\n descr = PyArray_DescrFromTypeObject((PyObject *)sc->ob_type);\n if (descr->elsize == 0) {\n\t\tPyArray_DESCR_REPLACE(descr);\n type_num = descr->type_num;\n\t\tif (type_num == PyArray_STRING) \n\t\t\tdescr->elsize = PyString_GET_SIZE(sc);\n\t\telse if (type_num == PyArray_UNICODE)\n\t\t\tdescr->elsize = PyUnicode_GET_DATA_SIZE(sc);\n\t\telse {\n\t\t\tdescr->elsize =\t\t\t\t\t\\\n\t\t\t\t((PyVoidScalarObject *)sc)->ob_size;\n\t\t\tdescr->fields = PyObject_GetAttrString(sc, \"fields\");\n\t\t\tif (!descr->fields || !PyDict_Check(descr->fields) || \\\n\t\t\t (descr->fields == Py_None)) {\n\t\t\t\tPy_XDECREF(descr->fields);\n\t\t\t\tdescr->fields = NULL;\n\t\t\t}\n\t\t\tPyErr_Clear();\n\t\t}\n }\n\treturn descr;\n}\n\n/* New reference */\n/*OBJECT_API\n Get a typeobject from a type-number\n*/\nstatic PyObject *\nPyArray_TypeObjectFromType(int type)\n{\n\tPyArray_Descr *descr;\n\tPyObject *obj;\n\n\tdescr = PyArray_DescrFromType(type);\n\tif (descr == NULL) return NULL;\n\tPy_INCREF((PyObject *)descr->typeobj);\n\tobj = (PyObject *)descr->typeobj;\n\tPy_DECREF(descr);\n\treturn obj;\n}\n\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + "\t/* first look in object and then hand off to generic type */", + "", + "\tres = PyObject_GenericGetAttr(obj->obval, attr);", + "\treturn \tPyObject_GenericGetAttr((PyObject *)obj, attr);", + "\t/* first look in object and then hand off to generic type */", + "\tres = PyObject_GenericSetAttr(obj->obval, attr, val);", + "\treturn PyObject_GenericSetAttr((PyObject *)obj, attr, val);" + ], + "deleted": [ + "\t/* first look in generic type and then hand off to actual object */", + "\tres = PyObject_GenericGetAttr((PyObject *)obj, attr);", + "\treturn PyObject_GenericGetAttr(obj->obval, attr);", + "\t/* first look in generic type and then hand off to actual object */", + "\tres = PyObject_GenericSetAttr((PyObject *)obj, attr, val);", + "\treturn PyObject_GenericSetAttr(obj->obval, attr, val);" + ] + } + } + ] + }, + { + "hash": "efa20eba4c84c282c1932cbd3a0f4154a3e7a026", + "msg": "Don't wrap ndarray's in object array wrappers.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-11T07:27:46+00:00", + "author_timezone": 0, + "committer_date": "2006-01-11T07:27:46+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "2ea2a8751198880820adaebd55f4e0f1979aeaea" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 0, + "insertions": 5, + "lines": 5, + "files": 1, + "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": "@@ -809,6 +809,11 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n \tint swap;\n \n \ttype_num = descr->type_num;\n+\tif ((type_num == PyArray_OBJECT) &&\t\t\\\n+\t (PyArray_Check((*((PyObject **)data))))) {\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", + "added_lines": 5, + "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\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\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=NULL;\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\tdescr = PyArray_DescrFromType(PyArray_INTP);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else 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} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\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=NULL;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\tdescr = PyArray_DescrFromType(PyArray_INT);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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} else 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) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\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\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 if (PyBigArray_CheckExact(obj)) \n return PyArray_BIG_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\t\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\t\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\t\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\t\n dest_strides_ptr = dest_strides;\n\t\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\t\n new_data = (char *)_pya_malloc(stride);\n\t\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\t\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\t\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\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\nstatic PyArray_Descr **userdescrs=NULL;\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\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\t\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\n/* If destination is not the right type, then src \n will be cast to destination. \n*/\n\n/* Does a flat iterator-based copy. \n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however. \n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n \n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError, \n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->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, elsize);\n PyArray_INCREF(dest);\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 memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\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\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t dest->descr, 0,\n\t\t\t\t\t dest->nd, FORTRAN_IF(dest));\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\t\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/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\t\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\t\n return (PyObject *)ret;\t\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_OBJECT) &&\t\t\\\n\t (PyArray_Check((*((PyObject **)data))))) {\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 (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}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize / sizeof(Py_UNICODE);\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\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, itemsize);\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/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\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\t\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\t\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 fwrite(sep, 1, n3, fp);\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\t\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\t\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\t\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\t\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\t\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\t\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \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\t\t\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\t\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\nstatic PyObject *\narray_item_nice(PyArrayObject *self, int i) \n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\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\t\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 SIZEOF_INT == SIZEOF_INTP\n#define array_ass_item array_ass_big_item\n#else\nstatic int\narray_ass_item(PyArrayObject *self, int 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\t\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\t\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\t\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\t\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\t\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\t\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\t\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);\t\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\t\n nd_old = nd_new = 0;\n\t\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\t\t\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 }\t \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\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\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);\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->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\t\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);\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}\n\t}\n\t\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, PyArray_ITEMSIZE(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}\t\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\t\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/* 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;\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\t\t\t\t\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\t\t\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\treturn PyArray_ToScalar(self->data, self);\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\treturn PyArray_ToScalar(self->data, self);\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n\t/* wrap arguments into a mapiter object */\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(op, oned);\n if (mit == NULL) return NULL;\n if (!mit->view) { /* fancy indexing */\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 Py_DECREF(mit);\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\t\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\t\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;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\t\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\t\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\t\t\t\t\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\t\t\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(index, oned);\n if (mit == NULL) return -1;\n if (!mit->view) {\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 Py_DECREF(mit);\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\t\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\treturn PyArray_Return((PyArrayObject *)array_subscript(self, op));\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n (inquiry)array_length,\t\t /*mp_length*/\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 \narray_getsegcount(PyArrayObject *self, int *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 \narray_getreadbuf(PyArrayObject *self, int 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 \narray_getwritebuf(PyArrayObject *self, int 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 \narray_getcharbuf(PyArrayObject *self, int 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 (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};\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\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;\t\n\t\n} NumericOps;\n\nstatic NumericOps n_ops = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL};\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\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);\t \n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\t\n SET(true_divide);\t\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\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;\t\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\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);\t \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\treturn dict;\t\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\t\t\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}\t\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}\t\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 *\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 PyObject *\narray_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.power);\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 *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.power);\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\t\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;\t \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 an \"\\\n\t\t\t\t\"int; 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;\t \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;\t \n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v) \n{\t \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;\t \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;\t \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*/\t\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 ilow, int ihigh) \n{\n PyArrayObject *r;\n int l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n \t\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\n self->dimensions[0] = l;\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 ilow, int ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\t\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\t\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\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, 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\n\nstatic PySequenceMethods array_as_sequence = {\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};\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\t\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\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\t\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\t\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\t\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\t\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\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\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 return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\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.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\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\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\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; ind == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tintp sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\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\t\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;\t\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by a single segment array of the provided \n dimensions and element size. If numbytes is 0 it will be calculated from \n the provided shape and element size.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\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;\t\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 */\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, \n\t\t\t intp *newstrides, int oldnd)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\t\n\told = *des;\n\t*des = old->subarray->base;\n\n\tmydim = newdims + oldnd;\n\tif (PyTuple_Check(old->subarray->shape)) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t\t\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tnumnew = 1;\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\t\n\tnewnd = oldnd + numnew;\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\t/* Make new strides */\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\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{\t\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\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);\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\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\t\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { /* strides is NULL too */\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\t\t\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\t\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 {\n\t\t\tif (data == NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"if 'strides' is given in \" \\\n\t\t\t\t\t\t\"array creation, data must \" \\\n\t\t\t\t\t\t\"be given too\");\n\t\t\t\tgoto fail;\n\t\t\t} \n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t} \t\n\t\t\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\t\tif (descr == &OBJECT_Descr) {\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 and some object passed in */\n\tif ((obj != NULL) && (subtype != &PyArray_Type) && \n\t (subtype != &PyBigArray_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 (!(self->flags & OWNDATA)) { /* did not allocate own data */\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\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\t\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*/\nstatic PyObject * \nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape)\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\t\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n \"resize only works on contiguous arrays\");\n return NULL;\n }\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\t\t\n\t\trefcnt = REFCOUNT(self);\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\t\t\t\t\n\t\tif (newsize == 0) sd = self->descr->elsize;\t\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 0, &(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);\t\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);\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\twhile (size--) {\n\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\ttoptr += itemsize;\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\t\t\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, itemsize);\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\", \n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", 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\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*/\t\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\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 &fortran)) \n\t\tgoto fail;\n\t\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\t\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\\\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 NULL, 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\t\tbuffer.len -= offset;\n\t\tbuffer.ptr += offset;\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\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 (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\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 (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 PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\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\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\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;\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 != NULL) {\n\t\tif (PyArray_Check(new->base)) \n\t\t\tnew = (PyArrayObject *)new->base;\n\t}\n\tnumbytes = PyArray_MultiplyList(new->dimensions, \n\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes, \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 if (PyBigArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_BIG_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}\t\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 *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISEXTENDED(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->descr->elsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\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 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\t\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\t\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\t\n\telse if (newtype->elsize > self->descr->elsize) {\n\t\t\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\t\t\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\t\t\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\ttemp = (PyArrayObject *)\\\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\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tPy_DECREF(newtype);\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator */\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\ttemp->descr = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype; \n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\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\t\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"arrdescr\");\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_type_get(PyArrayObject *self)\n{\n Py_INCREF(self->descr->typeobj);\n return (PyObject *)self->descr->typeobj;\n}\n\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);\n\tif (new == NULL) return -1;\n\t\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) {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}\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{\t\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{\t\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); \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);\t\t\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));\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->descr->elsize);\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 {\"dtype\", \n\t (getter)array_type_get, \n\t NULL,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n\t{\"dtypedescr\", \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.dtypedescr object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\t\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.bigndarray\",\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 NULL, \t\t\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\t\t\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n NULL, \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/* A standard array will subclass from the Big Array and \n add the array_as_sequence table\n and the array_as_buffer table\n */\n\nstatic PyTypeObject PyArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n};\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\t\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;\t\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\t\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, sizeof(Py_UNICODE)*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\t\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, 2*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\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\t\n\tif (minitype == NULL) \n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\t\n if (max < 0) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\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 \t\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\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\t\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\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_BOOL);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_LONG);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_DOUBLE);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_CDOUBLE);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\n finish:\n\t\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\t\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\t\n l=PyObject_Length(v);\n if(l < 0) return -1; \n\t\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\t\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 *= sizeof(Py_UNICODE);\n\t}\n\n\tret = (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\n\tif (ret == NULL) return NULL;\n\n ret->descr->f->setitem(op, ret->data, ret);\n\t\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 unless return value is NULL*/\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\tPyArray_Descr *savetype=typecode;\n\t\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\t\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 return NULL;\n }\n\t\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 return NULL;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\treturn NULL;\n\t\t}\n\t\tif (type == PyArray_UNICODE) itemsize*=sizeof(Py_UNICODE);\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\t\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\t\n if(!r) {Py_XINCREF(savetype); return NULL;}\n if(Assign_Array(r,s) == -1) {\n\t\tPy_XINCREF(savetype);\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\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\t\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\t\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\t\t\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\t\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\t\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, elsize);\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\t\t\t\t\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\t\t\t\t\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 oelsize);\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);\t\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\t\t\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*sizeof(Py_UNICODE);\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize/sizeof(Py_UNICODE);\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\t\n\tPy_DECREF(out);\n\treturn NULL;\n\t\n}\n\t \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\t\t\t\t\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * outsize;\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\t\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 */\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) \n{\n\t\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\t\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 (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\t\t\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 != &PyBigArray_Type)) {\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 (subtype != &PyBigArray_Type)) {\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\t\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 != &PyBigArray_Type)) {\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\t\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}\t\t\n\t\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;\t \n\t\telse _MY_FAIL \n\t\t\tbreak;\t\t \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;\t\t \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;\t\t \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\t\tbreak;\n\tcase 'S':\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase 'U':\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize *= sizeof(Py_UNICODE);\n\t\tbreak;\t \n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\t\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/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_fromstructinterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r, *ret;\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_XDECREF(intype);\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_XDECREF(intype);\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 ret = array_fromarray((PyArrayObject*)r, intype, flags);\n Py_DECREF(r);\n return ret;\n}\n\n/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n PyObject *tstr=NULL, *shape=NULL; \n\tPyArrayObject *ret=NULL;\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\t\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\tPy_XDECREF(intype);\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\tPy_XDECREF(intype);\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\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n\n fail:\n\tPy_XDECREF(intype);\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* steals a reference to typecode */\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Descr *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode == NULL) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyObject *obj;\n\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", typecode->type,\n\t\t\t\t\t\t typecode->elsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(typecode->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\n if (new == NULL) {Py_XDECREF(typecode); 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\t\tPy_DECREF(typecode);\n return NULL;\n }\n r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n/* Steals a reference to newtype --- which can be NULL */\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Descr *newtype, int min_depth, \n\t\t int max_depth, int flags) \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 = array_fromarray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if ((r = array_fromstructinterface(op, newtype, flags)) != \\\n\t\t Py_NotImplemented) {\n }\n else if ((r = array_frominterface(op, newtype, flags)) !=\t\\\n\t\t Py_NotImplemented) {\n\t}\n else if (PyObject_HasAttrString(op, \"__array__\")) {\n /* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, newtype, flags);\n }\n\telse {\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\t\t\t\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 PyErr_Clear();\n else\n seq = TRUE;\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\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\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\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_FromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n\t\tint max_depth, int requires) \n{\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\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 array_fromobject(op, descr, min_depth, max_depth,\n \t\t\t\trequires);\t\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 or PyBigArray_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) || PyBigArray_CheckExact(op)) return op;\n \n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FROM_OF(op, ENSUREARRAY);\n Py_DECREF(op);\n return new;\n}\n\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 * sizeof(Py_UNICODE)\\\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.\t\t \n\t\t*/\n\t}\n\treturn ret;\n}\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\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\t\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\t\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\t\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/* 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\niter_length(PyArrayIterObject *self) \n{\n return (int) 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, itemsize);\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\t\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, itemsize);\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;\t\t\t\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */ \t\n\t\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, size);\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);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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\t\t\t\t\t FORCECAST | ALIGNED);\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,\n\t\t\t\t itemsize);\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, itemsize);\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, itemsize);\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\t\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\t\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0);\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, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\t\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, itemsize);\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, itemsize);\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);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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_FromAny(obj, indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\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\t\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n (inquiry)iter_length,\t\t /*mp_length*/\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;\t\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\t{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 0, /* 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/* 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/* 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);\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\t\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\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\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 sizeof(intp));\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\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\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 sizeof(intp));\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 sizeof(intp));\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\t\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\t \n\tif (mit->view) return;\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\n\tsub = PyObject_GetItem((PyObject *)arr, mit->indexobj);\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\t\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\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\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= 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) *indptr, (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);\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\t\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->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_IndexError,\t\t\t\\\n\t\t\t\t\"arrays used as indices must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_IndexError, \"too many indices\");\n\t\tgoto fail;\n\t}\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\t\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);\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 ret:\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\t\n\tint i, err=0;\n\t\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\t\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\t\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);\t\n\t\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\t\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\t\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\t\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\t\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\t\n return (PyObject *)multi;\n\t\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\t_pya_free(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);\t\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 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/*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;\t\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(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 dtypedescr objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"dtype\", 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\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\tchar basic_=self->kind;\n\tchar endian = self->byteorder;\n\t\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\t\n\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t self->elsize);\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{\"subdescr\", \n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"arrdescr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"dtypestr\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\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\t\n\tif (!PyArg_ParseTuple(args, \"O|iO&\", &odescr, &align,\n\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\t\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, \n\t\t\t\t\t\t\t\t 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, \"dtypedescr\");\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\tobj = PyString_FromFormat(\"%c%d\",self->kind, self->elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\t\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\t\n\tif (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\t\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\t\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\t\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*/\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\t\t\t\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 dtypedescr 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 dtypedescr object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\t\t\t\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);\t\t\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(\"dtypedescr(\");\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 dtypedescr 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\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtypedescr\",\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 0, \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", + "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\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\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=NULL;\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\tdescr = PyArray_DescrFromType(PyArray_INTP);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else 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} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\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=NULL;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\tdescr = PyArray_DescrFromType(PyArray_INT);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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} else 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) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\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\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 if (PyBigArray_CheckExact(obj)) \n return PyArray_BIG_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\t\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\t\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\t\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\t\n dest_strides_ptr = dest_strides;\n\t\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\t\n new_data = (char *)_pya_malloc(stride);\n\t\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\t\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\t\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\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\nstatic PyArray_Descr **userdescrs=NULL;\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\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\t\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\n/* If destination is not the right type, then src \n will be cast to destination. \n*/\n\n/* Does a flat iterator-based copy. \n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however. \n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n \n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError, \n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->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, elsize);\n PyArray_INCREF(dest);\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 memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\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\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t dest->descr, 0,\n\t\t\t\t\t dest->nd, FORTRAN_IF(dest));\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\t\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/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\t\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\t\n return (PyObject *)ret;\t\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\titemsize = descr->elsize;\n type = descr->typeobj;\n copyswap = descr->f->copyswap;\n\tswap = !PyArray_ISNBO(descr->byteorder);\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}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize / sizeof(Py_UNICODE);\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\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, itemsize);\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/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\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\t\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\t\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 fwrite(sep, 1, n3, fp);\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\t\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\t\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\t\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\t\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\t\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\t\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \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\t\t\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\t\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\nstatic PyObject *\narray_item_nice(PyArrayObject *self, int i) \n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\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\t\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 SIZEOF_INT == SIZEOF_INTP\n#define array_ass_item array_ass_big_item\n#else\nstatic int\narray_ass_item(PyArrayObject *self, int 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\t\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\t\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\t\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\t\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\t\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\t\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\t\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);\t\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\t\n nd_old = nd_new = 0;\n\t\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\t\t\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 }\t \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\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\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);\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->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\t\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);\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}\n\t}\n\t\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, PyArray_ITEMSIZE(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}\t\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\t\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/* 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;\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\t\t\t\t\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\t\t\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\treturn PyArray_ToScalar(self->data, self);\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\treturn PyArray_ToScalar(self->data, self);\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n\t/* wrap arguments into a mapiter object */\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(op, oned);\n if (mit == NULL) return NULL;\n if (!mit->view) { /* fancy indexing */\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 Py_DECREF(mit);\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\t\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\t\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;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\t\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\t\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\t\t\t\t\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\t\t\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(index, oned);\n if (mit == NULL) return -1;\n if (!mit->view) {\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 Py_DECREF(mit);\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\t\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\treturn PyArray_Return((PyArrayObject *)array_subscript(self, op));\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n (inquiry)array_length,\t\t /*mp_length*/\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 \narray_getsegcount(PyArrayObject *self, int *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 \narray_getreadbuf(PyArrayObject *self, int 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 \narray_getwritebuf(PyArrayObject *self, int 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 \narray_getcharbuf(PyArrayObject *self, int 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 (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};\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\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;\t\n\t\n} NumericOps;\n\nstatic NumericOps n_ops = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL};\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\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);\t \n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\t\n SET(true_divide);\t\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\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;\t\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\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);\t \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\treturn dict;\t\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\t\t\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}\t\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}\t\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 *\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 PyObject *\narray_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.power);\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 *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.power);\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\t\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;\t \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 an \"\\\n\t\t\t\t\"int; 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;\t \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;\t \n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v) \n{\t \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;\t \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;\t \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*/\t\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 ilow, int ihigh) \n{\n PyArrayObject *r;\n int l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n \t\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\n self->dimensions[0] = l;\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 ilow, int ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\t\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\t\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\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, 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\n\nstatic PySequenceMethods array_as_sequence = {\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};\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\t\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\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\t\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\t\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\t\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\t\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\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\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 return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\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.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\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\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\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; ind == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tintp sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\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\t\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;\t\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by a single segment array of the provided \n dimensions and element size. If numbytes is 0 it will be calculated from \n the provided shape and element size.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\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;\t\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 */\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, \n\t\t\t intp *newstrides, int oldnd)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\t\n\told = *des;\n\t*des = old->subarray->base;\n\n\tmydim = newdims + oldnd;\n\tif (PyTuple_Check(old->subarray->shape)) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t\t\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tnumnew = 1;\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\t\n\tnewnd = oldnd + numnew;\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\t/* Make new strides */\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\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{\t\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\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);\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\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\t\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { /* strides is NULL too */\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\t\t\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\t\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 {\n\t\t\tif (data == NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"if 'strides' is given in \" \\\n\t\t\t\t\t\t\"array creation, data must \" \\\n\t\t\t\t\t\t\"be given too\");\n\t\t\t\tgoto fail;\n\t\t\t} \n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t} \t\n\t\t\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\t\tif (descr == &OBJECT_Descr) {\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 and some object passed in */\n\tif ((obj != NULL) && (subtype != &PyArray_Type) && \n\t (subtype != &PyBigArray_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 (!(self->flags & OWNDATA)) { /* did not allocate own data */\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\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\t\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*/\nstatic PyObject * \nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape)\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\t\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n \"resize only works on contiguous arrays\");\n return NULL;\n }\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\t\t\n\t\trefcnt = REFCOUNT(self);\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\t\t\t\t\n\t\tif (newsize == 0) sd = self->descr->elsize;\t\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 0, &(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);\t\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);\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\twhile (size--) {\n\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\ttoptr += itemsize;\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\t\t\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, itemsize);\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\", \n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", 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\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*/\t\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\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 &fortran)) \n\t\tgoto fail;\n\t\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\t\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\\\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 NULL, 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\t\tbuffer.len -= offset;\n\t\tbuffer.ptr += offset;\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\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 (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\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 (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 PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\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\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\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;\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 != NULL) {\n\t\tif (PyArray_Check(new->base)) \n\t\t\tnew = (PyArrayObject *)new->base;\n\t}\n\tnumbytes = PyArray_MultiplyList(new->dimensions, \n\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes, \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 if (PyBigArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_BIG_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}\t\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 *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISEXTENDED(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->descr->elsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\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 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\t\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\t\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\t\n\telse if (newtype->elsize > self->descr->elsize) {\n\t\t\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\t\t\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\t\t\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\ttemp = (PyArrayObject *)\\\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\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tPy_DECREF(newtype);\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator */\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\ttemp->descr = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype; \n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\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\t\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"arrdescr\");\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_type_get(PyArrayObject *self)\n{\n Py_INCREF(self->descr->typeobj);\n return (PyObject *)self->descr->typeobj;\n}\n\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);\n\tif (new == NULL) return -1;\n\t\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) {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}\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{\t\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{\t\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); \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);\t\t\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));\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->descr->elsize);\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 {\"dtype\", \n\t (getter)array_type_get, \n\t NULL,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n\t{\"dtypedescr\", \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.dtypedescr object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\t\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.bigndarray\",\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 NULL, \t\t\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\t\t\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n NULL, \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/* A standard array will subclass from the Big Array and \n add the array_as_sequence table\n and the array_as_buffer table\n */\n\nstatic PyTypeObject PyArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n};\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\t\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;\t\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\t\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, sizeof(Py_UNICODE)*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\t\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, 2*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\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\t\n\tif (minitype == NULL) \n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\t\n if (max < 0) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\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 \t\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\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\t\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\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_BOOL);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_LONG);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_DOUBLE);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_CDOUBLE);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\n finish:\n\t\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\t\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\t\n l=PyObject_Length(v);\n if(l < 0) return -1; \n\t\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\t\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 *= sizeof(Py_UNICODE);\n\t}\n\n\tret = (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\n\tif (ret == NULL) return NULL;\n\n ret->descr->f->setitem(op, ret->data, ret);\n\t\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 unless return value is NULL*/\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\tPyArray_Descr *savetype=typecode;\n\t\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\t\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 return NULL;\n }\n\t\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 return NULL;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\treturn NULL;\n\t\t}\n\t\tif (type == PyArray_UNICODE) itemsize*=sizeof(Py_UNICODE);\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\t\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\t\n if(!r) {Py_XINCREF(savetype); return NULL;}\n if(Assign_Array(r,s) == -1) {\n\t\tPy_XINCREF(savetype);\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\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\t\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\t\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\t\t\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\t\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\t\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, elsize);\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\t\t\t\t\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\t\t\t\t\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 oelsize);\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);\t\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\t\t\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*sizeof(Py_UNICODE);\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize/sizeof(Py_UNICODE);\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\t\n\tPy_DECREF(out);\n\treturn NULL;\n\t\n}\n\t \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\t\t\t\t\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * outsize;\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\t\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 */\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) \n{\n\t\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\t\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 (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\t\t\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 != &PyBigArray_Type)) {\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 (subtype != &PyBigArray_Type)) {\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\t\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 != &PyBigArray_Type)) {\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\t\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}\t\t\n\t\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;\t \n\t\telse _MY_FAIL \n\t\t\tbreak;\t\t \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;\t\t \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;\t\t \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\t\tbreak;\n\tcase 'S':\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase 'U':\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize *= sizeof(Py_UNICODE);\n\t\tbreak;\t \n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\t\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/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_fromstructinterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r, *ret;\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_XDECREF(intype);\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_XDECREF(intype);\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 ret = array_fromarray((PyArrayObject*)r, intype, flags);\n Py_DECREF(r);\n return ret;\n}\n\n/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n PyObject *tstr=NULL, *shape=NULL; \n\tPyArrayObject *ret=NULL;\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\t\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\tPy_XDECREF(intype);\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\tPy_XDECREF(intype);\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\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n\n fail:\n\tPy_XDECREF(intype);\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* steals a reference to typecode */\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Descr *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode == NULL) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyObject *obj;\n\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", typecode->type,\n\t\t\t\t\t\t typecode->elsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(typecode->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\n if (new == NULL) {Py_XDECREF(typecode); 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\t\tPy_DECREF(typecode);\n return NULL;\n }\n r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n/* Steals a reference to newtype --- which can be NULL */\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Descr *newtype, int min_depth, \n\t\t int max_depth, int flags) \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 = array_fromarray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if ((r = array_fromstructinterface(op, newtype, flags)) != \\\n\t\t Py_NotImplemented) {\n }\n else if ((r = array_frominterface(op, newtype, flags)) !=\t\\\n\t\t Py_NotImplemented) {\n\t}\n else if (PyObject_HasAttrString(op, \"__array__\")) {\n /* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, newtype, flags);\n }\n\telse {\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\t\t\t\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 PyErr_Clear();\n else\n seq = TRUE;\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\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\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\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_FromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n\t\tint max_depth, int requires) \n{\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\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 array_fromobject(op, descr, min_depth, max_depth,\n \t\t\t\trequires);\t\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 or PyBigArray_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) || PyBigArray_CheckExact(op)) return op;\n \n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FROM_OF(op, ENSUREARRAY);\n Py_DECREF(op);\n return new;\n}\n\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 * sizeof(Py_UNICODE)\\\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.\t\t \n\t\t*/\n\t}\n\treturn ret;\n}\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\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\t\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\t\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\t\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/* 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\niter_length(PyArrayIterObject *self) \n{\n return (int) 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, itemsize);\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\t\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, itemsize);\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;\t\t\t\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */ \t\n\t\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, size);\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);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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\t\t\t\t\t FORCECAST | ALIGNED);\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,\n\t\t\t\t itemsize);\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, itemsize);\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, itemsize);\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\t\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\t\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0);\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, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\t\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, itemsize);\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, itemsize);\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);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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_FromAny(obj, indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\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\t\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n (inquiry)iter_length,\t\t /*mp_length*/\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;\t\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\t{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 0, /* 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/* 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/* 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);\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\t\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\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\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 sizeof(intp));\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\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\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 sizeof(intp));\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 sizeof(intp));\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\t\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\t \n\tif (mit->view) return;\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\n\tsub = PyObject_GetItem((PyObject *)arr, mit->indexobj);\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\t\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\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\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= 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) *indptr, (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);\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\t\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->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_IndexError,\t\t\t\\\n\t\t\t\t\"arrays used as indices must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_IndexError, \"too many indices\");\n\t\tgoto fail;\n\t}\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\t\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);\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 ret:\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\t\n\tint i, err=0;\n\t\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\t\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\t\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);\t\n\t\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\t\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\t\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\t\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\t\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\t\n return (PyObject *)multi;\n\t\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\t_pya_free(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);\t\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 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/*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;\t\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(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 dtypedescr objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"dtype\", 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\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\tchar basic_=self->kind;\n\tchar endian = self->byteorder;\n\t\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\t\n\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t self->elsize);\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{\"subdescr\", \n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"arrdescr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"dtypestr\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\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\t\n\tif (!PyArg_ParseTuple(args, \"O|iO&\", &odescr, &align,\n\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\t\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, \n\t\t\t\t\t\t\t\t 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, \"dtypedescr\");\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\tobj = PyString_FromFormat(\"%c%d\",self->kind, self->elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\t\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\t\n\tif (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\t\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\t\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\t\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*/\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\t\t\t\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 dtypedescr 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 dtypedescr object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\t\t\t\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);\t\t\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(\"dtypedescr(\");\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 dtypedescr 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\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtypedescr\",\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 0, \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", + "methods": [ + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 19, + "token_count": 391, + "parameters": [ + "o" + ], + "start_line": 31, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 59, + "complexity": 19, + "token_count": 394, + "parameters": [ + "o" + ], + "start_line": 103, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 86, + "parameters": [ + "obj", + "default_" + ], + "start_line": 173, + "end_line": 191, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "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": 212, + "end_line": 240, + "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": 246, + "end_line": 275, + "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": 281, + "end_line": 331, + "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": 354, + "end_line": 385, + "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": 388, + "end_line": 422, + "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": 438, + "end_line": 460, + "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": 466, + "end_line": 487, + "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": 491, + "end_line": 529, + "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": 534, + "end_line": 554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "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": 562, + "end_line": 577, + "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": 583, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 607, + "end_line": 687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "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": 79, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 691, + "end_line": 705, + "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": 718, + "end_line": 744, + "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": 750, + "end_line": 764, + "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 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 772, + "end_line": 792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 80, + "complexity": 12, + "token_count": 485, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 801, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 84, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 900, + "end_line": 903, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 913, + "end_line": 935, + "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": 949, + "end_line": 989, + "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": 1004, + "end_line": 1045, + "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": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1052, + "end_line": 1143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "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": 1149, + "end_line": 1178, + "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": 1181, + "end_line": 1217, + "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": 1226, + "end_line": 1263, + "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": 1270, + "end_line": 1278, + "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": 1281, + "end_line": 1306, + "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 i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1309, + "end_line": 1312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 1316, + "end_line": 1351, + "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 i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1357, + "end_line": 1360, + "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": 1366, + "end_line": 1374, + "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": 1380, + "end_line": 1430, + "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": 1437, + "end_line": 1482, + "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": 1486, + "end_line": 1580, + "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": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1583, + "end_line": 1620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1632, + "end_line": 1685, + "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": 53, + "complexity": 12, + "token_count": 380, + "parameters": [ + "mit", + "op" + ], + "start_line": 1688, + "end_line": 1748, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "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": 1751, + "end_line": 1778, + "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": 1781, + "end_line": 1800, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 28, + "token_count": 659, + "parameters": [ + "self", + "op" + ], + "start_line": 1824, + "end_line": 1939, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 91, + "complexity": 28, + "token_count": 581, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 1954, + "end_line": 2056, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2065, + "end_line": 2068, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , int * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2087, + "end_line": 2099, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2102, + "end_line": 2117, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2121, + "end_line": 2130, + "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 segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2133, + "end_line": 2144, + "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": 34, + "complexity": 1, + "token_count": 162, + "parameters": [ + "dict" + ], + "start_line": 2215, + "end_line": 2248, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 2, + "token_count": 183, + "parameters": [], + "start_line": 2258, + "end_line": 2297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "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": 2300, + "end_line": 2323, + "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": 2327, + "end_line": 2350, + "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": 2354, + "end_line": 2361, + "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": 2364, + "end_line": 2371, + "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": 2374, + "end_line": 2382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 2385, + "end_line": 2388, + "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": 2391, + "end_line": 2394, + "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": 2397, + "end_line": 2400, + "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": 2403, + "end_line": 2406, + "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": 2409, + "end_line": 2412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2415, + "end_line": 2418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2421, + "end_line": 2424, + "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": 2427, + "end_line": 2430, + "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": 2433, + "end_line": 2436, + "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": 2439, + "end_line": 2442, + "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": 2445, + "end_line": 2448, + "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": 2451, + "end_line": 2454, + "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": 2457, + "end_line": 2460, + "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": 2463, + "end_line": 2466, + "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": 2469, + "end_line": 2472, + "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": 2475, + "end_line": 2478, + "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": 2481, + "end_line": 2484, + "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": 2487, + "end_line": 2490, + "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": 2493, + "end_line": 2496, + "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 * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2499, + "end_line": 2502, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2505, + "end_line": 2508, + "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": 2511, + "end_line": 2514, + "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": 2517, + "end_line": 2520, + "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": 2523, + "end_line": 2526, + "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": 2529, + "end_line": 2532, + "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": 2535, + "end_line": 2538, + "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": 2541, + "end_line": 2544, + "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": 2547, + "end_line": 2551, + "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": 2554, + "end_line": 2558, + "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": 2562, + "end_line": 2580, + "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": 2583, + "end_line": 2600, + "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": 2605, + "end_line": 2620, + "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": 2624, + "end_line": 2650, + "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": 2653, + "end_line": 2678, + "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": 2681, + "end_line": 2703, + "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": 2706, + "end_line": 2728, + "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": 2731, + "end_line": 2753, + "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": 2756, + "end_line": 2760, + "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 ilow , int ihigh)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 11, + "token_count": 259, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 2821, + "end_line": 2861, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , int ilow , int ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 2865, + "end_line": 2886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 2889, + "end_line": 2901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 2922, + "end_line": 2969, + "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": 2972, + "end_line": 3008, + "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": 3017, + "end_line": 3034, + "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": 3037, + "end_line": 3049, + "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": 3052, + "end_line": 3064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_richcompare", + "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 13, + "token_count": 273, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3067, + "end_line": 3144, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 164, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3147, + "end_line": 3176, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 3182, + "end_line": 3202, + "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": 21, + "complexity": 7, + "token_count": 161, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3210, + "end_line": 3233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 111, + "parameters": [ + "ap" + ], + "start_line": 3239, + "end_line": 3255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 109, + "parameters": [ + "ap" + ], + "start_line": 3259, + "end_line": 3275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 3278, + "end_line": 3295, + "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": 3298, + "end_line": 3331, + "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": 3338, + "end_line": 3365, + "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 * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 84, + "parameters": [ + "elsize", + "nd", + "numbytes", + "dims", + "newstrides" + ], + "start_line": 3374, + "end_line": 3389, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 3409, + "end_line": 3433, + "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": 3439, + "end_line": 3461, + "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)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 6, + "token_count": 229, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd" + ], + "start_line": 3465, + "end_line": 3507, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 130, + "complexity": 26, + "token_count": 761, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3515, + "end_line": 3673, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 159, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", + "filename": "arrayobject.c", + "nloc": 82, + "complexity": 15, + "token_count": 497, + "parameters": [ + "self", + "newshape" + ], + "start_line": 3682, + "end_line": 3780, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "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": 3786, + "end_line": 3803, + "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": 41, + "complexity": 6, + "token_count": 229, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3807, + "end_line": 3849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 18, + "token_count": 570, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 3852, + "end_line": 3966, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 115, + "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": 3970, + "end_line": 3978, + "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": 3984, + "end_line": 3987, + "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": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 3990, + "end_line": 3994, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 3997, + "end_line": 4000, + "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": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4004, + "end_line": 4033, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 4037, + "end_line": 4040, + "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": 36, + "complexity": 7, + "token_count": 231, + "parameters": [ + "self", + "obj" + ], + "start_line": 4043, + "end_line": 4081, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "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": 4085, + "end_line": 4092, + "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": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 4095, + "end_line": 4103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 4107, + "end_line": 4113, + "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": 4116, + "end_line": 4130, + "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": 4133, + "end_line": 4177, + "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": 4181, + "end_line": 4184, + "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": 4187, + "end_line": 4198, + "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": 4201, + "end_line": 4212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typechar_get", + "long_name": "array_typechar_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 4216, + "end_line": 4223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 4228, + "end_line": 4231, + "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": 4234, + "end_line": 4238, + "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": 15, + "token_count": 443, + "parameters": [ + "self", + "arg" + ], + "start_line": 4252, + "end_line": 4337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "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": 4340, + "end_line": 4358, + "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": 4361, + "end_line": 4379, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_type_get", + "long_name": "array_type_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4382, + "end_line": 4386, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 4391, + "end_line": 4401, + "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": 4405, + "end_line": 4430, + "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": 32, + "complexity": 4, + "token_count": 189, + "parameters": [ + "self", + "val" + ], + "start_line": 4434, + "end_line": 4467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "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": 4470, + "end_line": 4503, + "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": 205, + "parameters": [ + "self", + "val" + ], + "start_line": 4506, + "end_line": 4543, + "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": 4546, + "end_line": 4549, + "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": 346, + "parameters": [ + "self", + "val" + ], + "start_line": 4552, + "end_line": 4602, + "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": 4704, + "end_line": 4711, + "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": 4813, + "end_line": 4846, + "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": 161, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 4849, + "end_line": 4871, + "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": 4878, + "end_line": 4904, + "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": 4910, + "end_line": 4942, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 120, + "complexity": 31, + "token_count": 691, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 4954, + "end_line": 5090, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 137, + "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": 5093, + "end_line": 5116, + "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": 23, + "complexity": 6, + "token_count": 146, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5121, + "end_line": 5149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 21, + "token_count": 367, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5154, + "end_line": 5218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "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": 5225, + "end_line": 5234, + "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": 5240, + "end_line": 5333, + "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": 280, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5343, + "end_line": 5389, + "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": 5399, + "end_line": 5452, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_fromarray", + "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 32, + "token_count": 673, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5456, + "end_line": 5585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 505, + "parameters": [ + "str" + ], + "start_line": 5589, + "end_line": 5697, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "array_fromstructinterface", + "long_name": "array_fromstructinterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 6, + "token_count": 274, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5701, + "end_line": 5745, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_frominterface", + "long_name": "array_frominterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 134, + "complexity": 28, + "token_count": 839, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5749, + "end_line": 5892, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 144, + "top_nesting_level": 0 + }, + { + "name": "array_fromattr", + "long_name": "array_fromattr( PyObject * op , PyArray_Descr * typecode , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 178, + "parameters": [ + "op", + "typecode", + "flags" + ], + "start_line": 5896, + "end_line": 5926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "array_fromobject", + "long_name": "array_fromobject( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 17, + "token_count": 330, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags" + ], + "start_line": 5930, + "end_line": 6006, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 77, + "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": 6011, + "end_line": 6014, + "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": 6021, + "end_line": 6034, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 8, + "token_count": 117, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires" + ], + "start_line": 6080, + "end_line": 6099, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 81, + "parameters": [ + "op" + ], + "start_line": 6112, + "end_line": 6128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 6136, + "end_line": 6224, + "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": 134, + "parameters": [ + "from", + "to" + ], + "start_line": 6229, + "end_line": 6257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 6270, + "end_line": 6308, + "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": 6316, + "end_line": 6333, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "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": 6338, + "end_line": 6348, + "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": 6351, + "end_line": 6355, + "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": 16, + "parameters": [ + "self" + ], + "start_line": 6358, + "end_line": 6361, + "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": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6365, + "end_line": 6415, + "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": 6418, + "end_line": 6472, + "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": 664, + "parameters": [ + "self", + "ind" + ], + "start_line": 6476, + "end_line": 6609, + "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": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6613, + "end_line": 6645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "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": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6648, + "end_line": 6690, + "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": 692, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 6693, + "end_line": 6827, + "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": 6840, + "end_line": 6885, + "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": 6890, + "end_line": 6894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 6966, + "end_line": 7028, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 104, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7036, + "end_line": 7052, + "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": 7059, + "end_line": 7128, + "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": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7132, + "end_line": 7169, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7175, + "end_line": 7219, + "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": 99, + "complexity": 22, + "token_count": 670, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7237, + "end_line": 7367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 460, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7373, + "end_line": 7446, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned)", + "filename": "arrayobject.c", + "nloc": 112, + "complexity": 25, + "token_count": 758, + "parameters": [ + "indexobj", + "oned" + ], + "start_line": 7449, + "end_line": 7584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "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": 7588, + "end_line": 7597, + "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": 231, + "parameters": [ + "n" + ], + "start_line": 7668, + "end_line": 7717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "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": 265, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 7720, + "end_line": 7765, + "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": 7768, + "end_line": 7787, + "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": 41, + "parameters": [ + "multi" + ], + "start_line": 7790, + "end_line": 7797, + "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": 7800, + "end_line": 7810, + "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": 7813, + "end_line": 7823, + "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": 7826, + "end_line": 7829, + "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": 7832, + "end_line": 7844, + "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": 7874, + "end_line": 7881, + "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": 7940, + "end_line": 7949, + "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": 7967, + "end_line": 7989, + "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": 64, + "parameters": [ + "self" + ], + "start_line": 7995, + "end_line": 8005, + "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": 8023, + "end_line": 8031, + "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": 11, + "complexity": 3, + "token_count": 60, + "parameters": [ + "self" + ], + "start_line": 8034, + "end_line": 8046, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 8049, + "end_line": 8068, + "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": 8075, + "end_line": 8082, + "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": 8085, + "end_line": 8092, + "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": 8095, + "end_line": 8102, + "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": 47, + "complexity": 13, + "token_count": 251, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8138, + "end_line": 8189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 50, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "args" + ], + "start_line": 8195, + "end_line": 8252, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8260, + "end_line": 8302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 8322, + "end_line": 8388, + "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": 8399, + "end_line": 8407, + "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": 8422, + "end_line": 8467, + "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": 8470, + "end_line": 8479, + "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": 8482, + "end_line": 8492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 19, + "token_count": 391, + "parameters": [ + "o" + ], + "start_line": 31, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 59, + "complexity": 19, + "token_count": 394, + "parameters": [ + "o" + ], + "start_line": 103, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 86, + "parameters": [ + "obj", + "default_" + ], + "start_line": 173, + "end_line": 191, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "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": 212, + "end_line": 240, + "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": 246, + "end_line": 275, + "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": 281, + "end_line": 331, + "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": 354, + "end_line": 385, + "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": 388, + "end_line": 422, + "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": 438, + "end_line": 460, + "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": 466, + "end_line": 487, + "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": 491, + "end_line": 529, + "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": 534, + "end_line": 554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "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": 562, + "end_line": 577, + "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": 583, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 607, + "end_line": 687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "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": 79, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 691, + "end_line": 705, + "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": 718, + "end_line": 744, + "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": 750, + "end_line": 764, + "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 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 772, + "end_line": 792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 75, + "complexity": 10, + "token_count": 436, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 801, + "end_line": 879, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 895, + "end_line": 898, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 908, + "end_line": 930, + "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": 944, + "end_line": 984, + "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": 999, + "end_line": 1040, + "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": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1047, + "end_line": 1138, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "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": 1144, + "end_line": 1173, + "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": 1176, + "end_line": 1212, + "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": 1221, + "end_line": 1258, + "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": 1265, + "end_line": 1273, + "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": 1276, + "end_line": 1301, + "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 i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1304, + "end_line": 1307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 1311, + "end_line": 1346, + "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 i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1352, + "end_line": 1355, + "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": 1361, + "end_line": 1369, + "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": 1375, + "end_line": 1425, + "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": 1432, + "end_line": 1477, + "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": 1481, + "end_line": 1575, + "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": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1578, + "end_line": 1615, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1627, + "end_line": 1680, + "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": 53, + "complexity": 12, + "token_count": 380, + "parameters": [ + "mit", + "op" + ], + "start_line": 1683, + "end_line": 1743, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "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": 1746, + "end_line": 1773, + "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": 1776, + "end_line": 1795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 28, + "token_count": 659, + "parameters": [ + "self", + "op" + ], + "start_line": 1819, + "end_line": 1934, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 91, + "complexity": 28, + "token_count": 581, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 1949, + "end_line": 2051, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2060, + "end_line": 2063, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , int * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2082, + "end_line": 2094, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2097, + "end_line": 2112, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2116, + "end_line": 2125, + "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 segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2128, + "end_line": 2139, + "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": 34, + "complexity": 1, + "token_count": 162, + "parameters": [ + "dict" + ], + "start_line": 2210, + "end_line": 2243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 2, + "token_count": 183, + "parameters": [], + "start_line": 2253, + "end_line": 2292, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "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": 2295, + "end_line": 2318, + "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": 2322, + "end_line": 2345, + "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": 2349, + "end_line": 2356, + "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": 2359, + "end_line": 2366, + "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": 2369, + "end_line": 2377, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 2380, + "end_line": 2383, + "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": 2386, + "end_line": 2389, + "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": 2392, + "end_line": 2395, + "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": 2398, + "end_line": 2401, + "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": 2404, + "end_line": 2407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2410, + "end_line": 2413, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2416, + "end_line": 2419, + "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": 2422, + "end_line": 2425, + "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": 2428, + "end_line": 2431, + "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": 2434, + "end_line": 2437, + "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": 2440, + "end_line": 2443, + "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": 2446, + "end_line": 2449, + "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": 2452, + "end_line": 2455, + "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": 2458, + "end_line": 2461, + "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": 2464, + "end_line": 2467, + "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": 2470, + "end_line": 2473, + "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": 2476, + "end_line": 2479, + "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": 2482, + "end_line": 2485, + "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": 2488, + "end_line": 2491, + "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 * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2494, + "end_line": 2497, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2500, + "end_line": 2503, + "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": 2506, + "end_line": 2509, + "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": 2512, + "end_line": 2515, + "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": 2518, + "end_line": 2521, + "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": 2524, + "end_line": 2527, + "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": 2530, + "end_line": 2533, + "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": 2536, + "end_line": 2539, + "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": 2542, + "end_line": 2546, + "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": 2549, + "end_line": 2553, + "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": 2557, + "end_line": 2575, + "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": 2578, + "end_line": 2595, + "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": 2600, + "end_line": 2615, + "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": 2619, + "end_line": 2645, + "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": 2648, + "end_line": 2673, + "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": 2676, + "end_line": 2698, + "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": 2701, + "end_line": 2723, + "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": 2726, + "end_line": 2748, + "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": 2751, + "end_line": 2755, + "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 ilow , int ihigh)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 11, + "token_count": 259, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 2816, + "end_line": 2856, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , int ilow , int ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 2860, + "end_line": 2881, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 2884, + "end_line": 2896, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 2917, + "end_line": 2964, + "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": 2967, + "end_line": 3003, + "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": 3012, + "end_line": 3029, + "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": 3032, + "end_line": 3044, + "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": 3047, + "end_line": 3059, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_richcompare", + "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 13, + "token_count": 273, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3062, + "end_line": 3139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 164, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3142, + "end_line": 3171, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 3177, + "end_line": 3197, + "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": 21, + "complexity": 7, + "token_count": 161, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3205, + "end_line": 3228, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 111, + "parameters": [ + "ap" + ], + "start_line": 3234, + "end_line": 3250, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 109, + "parameters": [ + "ap" + ], + "start_line": 3254, + "end_line": 3270, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 3273, + "end_line": 3290, + "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": 3293, + "end_line": 3326, + "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": 3333, + "end_line": 3360, + "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 * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 84, + "parameters": [ + "elsize", + "nd", + "numbytes", + "dims", + "newstrides" + ], + "start_line": 3369, + "end_line": 3384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 3404, + "end_line": 3428, + "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": 3434, + "end_line": 3456, + "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)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 6, + "token_count": 229, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd" + ], + "start_line": 3460, + "end_line": 3502, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 130, + "complexity": 26, + "token_count": 761, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3510, + "end_line": 3668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 159, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", + "filename": "arrayobject.c", + "nloc": 82, + "complexity": 15, + "token_count": 497, + "parameters": [ + "self", + "newshape" + ], + "start_line": 3677, + "end_line": 3775, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "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": 3781, + "end_line": 3798, + "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": 41, + "complexity": 6, + "token_count": 229, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3802, + "end_line": 3844, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 18, + "token_count": 570, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 3847, + "end_line": 3961, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 115, + "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": 3965, + "end_line": 3973, + "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": 3979, + "end_line": 3982, + "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": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 3985, + "end_line": 3989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 3992, + "end_line": 3995, + "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": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 3999, + "end_line": 4028, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 4032, + "end_line": 4035, + "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": 36, + "complexity": 7, + "token_count": 231, + "parameters": [ + "self", + "obj" + ], + "start_line": 4038, + "end_line": 4076, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "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": 4080, + "end_line": 4087, + "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": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 4090, + "end_line": 4098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 4102, + "end_line": 4108, + "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": 4111, + "end_line": 4125, + "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": 4128, + "end_line": 4172, + "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": 4176, + "end_line": 4179, + "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": 4182, + "end_line": 4193, + "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": 4196, + "end_line": 4207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typechar_get", + "long_name": "array_typechar_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 4211, + "end_line": 4218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 4223, + "end_line": 4226, + "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": 4229, + "end_line": 4233, + "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": 15, + "token_count": 443, + "parameters": [ + "self", + "arg" + ], + "start_line": 4247, + "end_line": 4332, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "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": 4335, + "end_line": 4353, + "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": 4356, + "end_line": 4374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_type_get", + "long_name": "array_type_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4377, + "end_line": 4381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 4386, + "end_line": 4396, + "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": 4400, + "end_line": 4425, + "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": 32, + "complexity": 4, + "token_count": 189, + "parameters": [ + "self", + "val" + ], + "start_line": 4429, + "end_line": 4462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "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": 4465, + "end_line": 4498, + "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": 205, + "parameters": [ + "self", + "val" + ], + "start_line": 4501, + "end_line": 4538, + "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": 4541, + "end_line": 4544, + "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": 346, + "parameters": [ + "self", + "val" + ], + "start_line": 4547, + "end_line": 4597, + "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": 4699, + "end_line": 4706, + "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": 4808, + "end_line": 4841, + "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": 161, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 4844, + "end_line": 4866, + "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": 4873, + "end_line": 4899, + "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": 4905, + "end_line": 4937, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 120, + "complexity": 31, + "token_count": 691, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 4949, + "end_line": 5085, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 137, + "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": 5088, + "end_line": 5111, + "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": 23, + "complexity": 6, + "token_count": 146, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5116, + "end_line": 5144, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 21, + "token_count": 367, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5149, + "end_line": 5213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "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": 5220, + "end_line": 5229, + "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": 5235, + "end_line": 5328, + "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": 280, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5338, + "end_line": 5384, + "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": 5394, + "end_line": 5447, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_fromarray", + "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 32, + "token_count": 673, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5451, + "end_line": 5580, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 505, + "parameters": [ + "str" + ], + "start_line": 5584, + "end_line": 5692, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "array_fromstructinterface", + "long_name": "array_fromstructinterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 6, + "token_count": 274, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5696, + "end_line": 5740, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_frominterface", + "long_name": "array_frominterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 134, + "complexity": 28, + "token_count": 839, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5744, + "end_line": 5887, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 144, + "top_nesting_level": 0 + }, + { + "name": "array_fromattr", + "long_name": "array_fromattr( PyObject * op , PyArray_Descr * typecode , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 178, + "parameters": [ + "op", + "typecode", + "flags" + ], + "start_line": 5891, + "end_line": 5921, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "array_fromobject", + "long_name": "array_fromobject( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 17, + "token_count": 330, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags" + ], + "start_line": 5925, + "end_line": 6001, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 77, + "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": 6006, + "end_line": 6009, + "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": 6016, + "end_line": 6029, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 8, + "token_count": 117, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires" + ], + "start_line": 6075, + "end_line": 6094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 81, + "parameters": [ + "op" + ], + "start_line": 6107, + "end_line": 6123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 6131, + "end_line": 6219, + "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": 134, + "parameters": [ + "from", + "to" + ], + "start_line": 6224, + "end_line": 6252, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 6265, + "end_line": 6303, + "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": 6311, + "end_line": 6328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "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": 6333, + "end_line": 6343, + "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": 6346, + "end_line": 6350, + "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": 16, + "parameters": [ + "self" + ], + "start_line": 6353, + "end_line": 6356, + "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": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6360, + "end_line": 6410, + "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": 6413, + "end_line": 6467, + "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": 664, + "parameters": [ + "self", + "ind" + ], + "start_line": 6471, + "end_line": 6604, + "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": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6608, + "end_line": 6640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "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": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6643, + "end_line": 6685, + "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": 692, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 6688, + "end_line": 6822, + "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": 6835, + "end_line": 6880, + "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": 6885, + "end_line": 6889, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 6961, + "end_line": 7023, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 104, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7031, + "end_line": 7047, + "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": 7054, + "end_line": 7123, + "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": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7127, + "end_line": 7164, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7170, + "end_line": 7214, + "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": 99, + "complexity": 22, + "token_count": 670, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7232, + "end_line": 7362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 460, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7368, + "end_line": 7441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned)", + "filename": "arrayobject.c", + "nloc": 112, + "complexity": 25, + "token_count": 758, + "parameters": [ + "indexobj", + "oned" + ], + "start_line": 7444, + "end_line": 7579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "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": 7583, + "end_line": 7592, + "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": 231, + "parameters": [ + "n" + ], + "start_line": 7663, + "end_line": 7712, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "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": 265, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 7715, + "end_line": 7760, + "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": 7763, + "end_line": 7782, + "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": 41, + "parameters": [ + "multi" + ], + "start_line": 7785, + "end_line": 7792, + "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": 7795, + "end_line": 7805, + "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": 7808, + "end_line": 7818, + "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": 7821, + "end_line": 7824, + "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": 7827, + "end_line": 7839, + "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": 7869, + "end_line": 7876, + "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": 7935, + "end_line": 7944, + "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": 7962, + "end_line": 7984, + "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": 64, + "parameters": [ + "self" + ], + "start_line": 7990, + "end_line": 8000, + "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": 8018, + "end_line": 8026, + "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": 11, + "complexity": 3, + "token_count": 60, + "parameters": [ + "self" + ], + "start_line": 8029, + "end_line": 8041, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 8044, + "end_line": 8063, + "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": 8070, + "end_line": 8077, + "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": 8080, + "end_line": 8087, + "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": 8090, + "end_line": 8097, + "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": 47, + "complexity": 13, + "token_count": 251, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8133, + "end_line": 8184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 50, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "args" + ], + "start_line": 8190, + "end_line": 8247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8255, + "end_line": 8297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 8317, + "end_line": 8383, + "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": 8394, + "end_line": 8402, + "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": 8417, + "end_line": 8462, + "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": 8465, + "end_line": 8474, + "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": 8477, + "end_line": 8487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 80, + "complexity": 12, + "token_count": 485, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 801, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 84, + "top_nesting_level": 0 + } + ], + "nloc": 6781, + "complexity": 1443, + "token_count": 39865, + "diff_parsed": { + "added": [ + "\tif ((type_num == PyArray_OBJECT) &&\t\t\\", + "\t (PyArray_Check((*((PyObject **)data))))) {", + "\t\tPy_INCREF(*((PyObject **)data));", + "\t\treturn *((PyObject **)data);", + "\t}" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "9a1d729679a1470530014a0ed79bbd7b42fecfa6", + "msg": "Rename arguments in arraysetops to follow convention. Add bsum for builtin sum.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-11T08:27:34+00:00", + "author_timezone": 0, + "committer_date": "2006-01-11T08:27:34+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "efa20eba4c84c282c1932cbd3a0f4154a3e7a026" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 16, + "insertions": 19, + "lines": 35, + "files": 2, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/oldnumeric.py", + "new_path": "numpy/core/oldnumeric.py", + "filename": "oldnumeric.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -24,7 +24,7 @@\n 'compress', 'clip', 'sum', 'product', 'prod', 'sometrue', 'alltrue',\n 'any', 'all', 'cumsum', 'cumproduct', 'cumprod', 'ptp', 'ndim',\n 'rank', 'size', 'around', 'round_', 'mean', 'std', 'var', 'squeeze',\n- 'amax', 'amin'\n+ 'amax', 'amin','bsum'\n ]\n \n import multiarray as mu\n@@ -48,6 +48,9 @@\n \n LittleEndian = (sys.byteorder == 'little')\n \n+# save away Python sum\n+bsum = sum\n+\n # backward compatible names from old Precision.py\n \n Character = 'S1'\n", + "added_lines": 4, + "deleted_lines": 1, + "source_code": "# Compatibility module containing deprecated names\n\n__all__ = ['asarray', 'array', 'concatenate',\n 'NewAxis',\n 'UFuncType', 'UfuncType', 'ArrayType', 'arraytype',\n 'LittleEndian', 'Bool', \n 'Character', 'UnsignedInt8', 'UnsignedInt16', 'UnsignedInt',\n 'UInt8','UInt16','UInt32',\n # UnsignedInt64 and Unsigned128 added below if possible\n # same for Int64 and Int128, Float128, and Complex128\n 'Int8', 'Int16', 'Int32',\n 'Int0', 'Int', 'Float0', 'Float', 'Complex0', 'Complex',\n 'PyObject', 'Float32', 'Float64',\n 'Complex32', 'Complex64',\n 'typecodes', 'sarray', 'arrayrange', 'cross_correlate',\n 'matrixmultiply', 'outerproduct', 'innerproduct',\n # from cPickle\n 'dump', 'dumps',\n # functions that are now methods\n 'take', 'reshape', 'choose', 'repeat', 'put', 'putmask',\n 'swapaxes', 'transpose', 'sort', 'argsort', 'argmax', 'argmin',\n 'searchsorted', 'alen', \n 'resize', 'diagonal', 'trace', 'ravel', 'nonzero', 'shape',\n 'compress', 'clip', 'sum', 'product', 'prod', 'sometrue', 'alltrue',\n 'any', 'all', 'cumsum', 'cumproduct', 'cumprod', 'ptp', 'ndim',\n 'rank', 'size', 'around', 'round_', 'mean', 'std', 'var', 'squeeze',\n 'amax', 'amin','bsum'\n ]\n\nimport multiarray as mu\nimport umath as um\nimport numerictypes as nt\nfrom numeric import asarray, array, correlate, outer, concatenate\nfrom umath import sign, absolute, multiply\nimport numeric as _nx\nimport sys\n_dt_ = nt.dtype2char\n\n#Use this to add a new axis to an array\n#compatibility only\nNewAxis = None\n\n#deprecated\nUFuncType = type(um.sin)\nUfuncType = type(um.sin)\nArrayType = mu.ndarray\narraytype = mu.ndarray\n\nLittleEndian = (sys.byteorder == 'little')\n\n# save away Python sum\nbsum = sum\n\n# backward compatible names from old Precision.py\n\nCharacter = 'S1'\nUnsignedInt8 = _dt_(nt.uint8)\nUInt8 = UnsignedInt8\nUnsignedInt16 = _dt_(nt.uint16)\nUInt16 = UnsignedInt16\nUnsignedInt32 = _dt_(nt.uint32)\nUInt32 = UnsignedInt32\nUnsignedInt = _dt_(nt.uint)\n\ntry:\n UnsignedInt64 = _dt_(nt.uint64)\nexcept AttributeError:\n pass\nelse:\n UInt64 = UnsignedInt64\n __all__ += ['UnsignedInt64', 'UInt64']\ntry:\n UnsignedInt128 = _dt_(nt.uint128)\nexcept AttributeError:\n pass\nelse:\n UInt128 = UnsignedInt128\n __all__ += ['UnsignedInt128','UInt128']\n\nInt8 = _dt_(nt.int8)\nInt16 = _dt_(nt.int16)\nInt32 = _dt_(nt.int32)\n\ntry:\n Int64 = _dt_(nt.int64)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int64']\n\ntry:\n Int128 = _dt_(nt.int128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int128']\n\nBool = _dt_(bool)\nInt0 = _dt_(int)\nInt = _dt_(int)\nFloat0 = _dt_(float)\nFloat = _dt_(float)\nComplex0 = _dt_(complex)\nComplex = _dt_(complex)\nPyObject = _dt_(nt.object_)\nFloat32 = _dt_(nt.float32)\nFloat64 = _dt_(nt.float64)\n\ntry:\n Float128 = _dt_(nt.float128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Float128']\n\nComplex32 = _dt_(nt.complex64)\nComplex64 = _dt_(nt.complex128)\n\ntry:\n Complex128 = _dt_(nt.complex256)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Complex128']\n\ntypecodes = {'Character':'S1',\n 'Integer':'bhilqp',\n 'UnsignedInteger':'BHILQP',\n 'Float':'fdg',\n 'Complex':'FDG',\n 'AllInteger':'bBhHiIlLqQpP',\n 'AllFloat':'fdgFDG',\n 'All':'?bhilqpBHILQPfdgFDGSUVO'}\n\ndef sarray(a, dtype=None, copy=False):\n return array(a, dtype, copy)\n\n# backward compatibility\narrayrange = mu.arange\ncross_correlate = correlate\n\n# deprecated names\nmatrixmultiply = mu.dot\nouterproduct = outer\ninnerproduct = mu.inner\n\nfrom cPickle import dump, dumps\n\n# functions that are now methods\n\ndef take(a, indices, axis=0):\n a = asarray(a)\n return a.take(indices, axis)\n\ndef reshape(a, newshape):\n \"\"\"Change the shape of a to newshape. Return a new view object.\n \"\"\"\n return asarray(a).reshape(newshape)\n\ndef choose(a, choices):\n a = asarray(a)\n return a.choose(choices)\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n If repeats is an integer, it is interpreted as\n a tuple of length a.shape[axis] containing repeats.\n The argument a can be anything array(a) will accept.\n \"\"\"\n a = array(a, copy=False)\n return a.repeat(repeats, axis)\n\ndef put (a, ind, v):\n \"\"\"put(a, ind, v) results in a[n] = v[n] for all n in ind\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n The routine put is the equivalent of the following (although the loop\n is in C for speed):\n\n ind = array(indices, copy=False)\n v = array(values, copy=False).astype(a, a.dtype)\n for i in ind: a.flat[i] = v[i]\n a must be a contiguous Numeric array.\n \"\"\"\n return a.put(v,ind)\n\ndef putmask (a, mask, v):\n \"\"\"putmask(a, mask, v) results in a = v for all places mask is true.\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n \"\"\"\n return a.putmask(v, mask)\n\ndef swapaxes(a, axis1, axis2):\n \"\"\"swapaxes(a, axis1, axis2) returns array a with axis1 and axis2\n interchanged.\n \"\"\"\n a = array(a, copy=False)\n return a.swapaxes(axis1, axis2)\n\ndef transpose(a, axes=None):\n \"\"\"transpose(a, axes=None) returns array with dimensions permuted\n according to axes. If axes is None (default) returns array with\n dimensions reversed.\n \"\"\"\n a = array(a,copy=False)\n return a.transpose(axes)\n\ndef sort(a, axis=-1):\n \"\"\"sort(a,axis=-1) returns array with elements sorted along given axis.\n \"\"\"\n a = array(a, copy=True)\n a.sort(axis)\n return a\n\ndef argsort(a, axis=-1):\n \"\"\"argsort(a,axis=-1) return the indices into a of the sorted array\n along the given axis, so that take(a,result,axis) is the sorted array.\n \"\"\"\n a = array(a, copy=False)\n return a.argsort(axis)\n\ndef argmax(a, axis=-1):\n \"\"\"argmax(a,axis=-1) returns the indices to the maximum value of the\n 1-D arrays along the given axis.\n \"\"\"\n a = array(a, copy=False)\n return a.argmax(axis)\n\ndef argmin(a, axis=-1):\n \"\"\"argmin(a,axis=-1) returns the indices to the minimum value of the\n 1-D arrays along the given axis.\n \"\"\"\n a = array(a,copy=False)\n return a.argmin(axis)\n\ndef searchsorted(a, v):\n \"\"\"searchsorted(a, v)\n \"\"\"\n a = array(a,copy=False)\n return a.searchsorted(v)\n\ndef resize(a, new_shape):\n \"\"\"resize(a,new_shape) returns a new array with the specified shape.\n The original array's total size can be any size. It\n fills the new array with repeated copies of a.\n\n Note that a.resize(new_shape) will fill array with 0's\n beyond current definition of a.\n \"\"\"\n\n if isinstance(new_shape, (int, nt.integer)):\n new_shape = (new_shape,)\n a = ravel(a)\n Na = len(a)\n if not Na: return mu.zeros(new_shape, a.dtypechar)\n total_size = um.multiply.reduce(new_shape)\n n_copies = int(total_size / Na)\n extra = total_size % Na\n\n if total_size == 0:\n return a[:0]\n\n if extra != 0:\n n_copies = n_copies+1\n extra = Na-extra\n\n a = concatenate( (a,)*n_copies)\n if extra > 0:\n a = a[:-extra]\n\n return reshape(a, new_shape)\n\ndef squeeze(a):\n \"Returns a with any ones from the shape of a removed\"\n return asarray(a).squeeze()\n\ndef diagonal(a, offset=0, axis1=0, axis2=1):\n \"\"\"diagonal(a, offset=0, axis1=0, axis2=1) returns the given diagonals\n defined by the last two dimensions of the array.\n \"\"\"\n return asarray(a).diagonal(offset, axis1, axis2)\n\ndef trace(a, offset=0, axis1=0, axis2=1, dtype=None):\n \"\"\"trace(a,offset=0, axis1=0, axis2=1) returns the sum along diagonals\n (defined by the last two dimenions) of the array.\n \"\"\"\n return asarray(a).trace(offset, axis1, axis2, dtype)\n\ndef ravel(m):\n \"\"\"ravel(m) returns a 1d array corresponding to all the elements of it's\n argument.\n \"\"\"\n return asarray(m).ravel()\n\ndef nonzero(a):\n \"\"\"nonzero(a) returns the indices of the elements of a which are not zero,\n a must be 1d\n \"\"\"\n return asarray(a).nonzero()\n\ndef shape(a):\n \"\"\"shape(a) returns the shape of a (as a function call which\n also works on nested sequences).\n \"\"\"\n return asarray(a).shape\n\ndef compress(condition, m, axis=-1):\n \"\"\"compress(condition, x, axis=-1) = those elements of x corresponding \n to those elements of condition that are \"true\". condition must be the\n same size as the given dimension of x.\"\"\"\n return asarray(m).compress(condition, axis)\n\ndef clip(m, m_min, m_max):\n \"\"\"clip(m, m_min, m_max) = every entry in m that is less than m_min is\n replaced by m_min, and every entry greater than m_max is replaced by\n m_max.\n \"\"\"\n return asarray(m).clip(m_min, m_max)\n\ndef sum(x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis. The optional dtype argument\n is the data type for intermediate calculations.\n\n The default is to upcast (promote) smaller integer types to the\n platform-dependent Int. For example, on 32-bit platforms:\n\n x.dtype default sum() dtype\n ---------------------------------------------------\n bool, Int8, Int16, Int32 Int32\n\n Examples:\n >>> sum([0.5, 1.5])\n 2.0\n >>> sum([0.5, 1.5], dtype=Int32)\n 1\n >>> sum([[0, 1], [0, 5]])\n array([0, 6])\n >>> sum([[0, 1], [0, 5]], axis=1)\n array([1, 5])\n \"\"\"\n return asarray(x).sum(axis, dtype)\n\ndef product (x, axis=0, dtype=None):\n \"\"\"Product of the array elements over the given axis.\"\"\"\n return asarray(x).prod(axis, dtype)\n\ndef sometrue (x, axis=0):\n \"\"\"Perform a logical_or over the given axis.\"\"\"\n return asarray(x).any(axis)\n\ndef alltrue (x, axis=0):\n \"\"\"Perform a logical_and over the given axis.\"\"\"\n return asarray(x).all(axis)\n\ndef any(x,axis=None):\n \"\"\"Return true if any elements of x are true: sometrue(ravel(x))\n \"\"\"\n return ravel(x).any(axis)\n\ndef all(x,axis=None):\n \"\"\"Return true if all elements of x are true: alltrue(ravel(x))\n \"\"\"\n return ravel(x).all(axis)\n\ndef cumsum (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumsum(axis, dtype)\n\ndef cumproduct (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumprod(axis, dtype)\n\ndef ptp(a, axis=0):\n \"\"\"Return maximum - minimum along the the given dimension\n \"\"\"\n return asarray(a).ptp(axis)\n\ndef amax(a, axis=0):\n \"\"\"Return the maximum of 'a' along dimension axis.\n \"\"\"\n return asarray(a).max(axis)\n\ndef amin(a, axis=0):\n \"\"\"Return the minimum of a along dimension axis.\n \"\"\"\n return asarray(a).min(axis)\n\ndef alen(a):\n \"\"\"Return the length of a Python object interpreted as an array\n \"\"\"\n return len(asarray(a))\n\ndef prod(a, axis=0):\n \"\"\"Return the product of the elements along the given axis\n \"\"\"\n return asarray(a).prod(axis)\n\ndef cumprod(a, axis=0):\n \"\"\"Return the cumulative product of the elments along the given axis\n \"\"\"\n return asarray(a).cumprod(axis)\n\ndef ndim(a):\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef rank (a):\n \"\"\"Get the rank of sequence a (the number of dimensions, not a matrix rank)\n The rank of a scalar is zero.\n \"\"\"\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef size (a, axis=None):\n \"Get the number of elements in sequence a, or along a certain axis.\"\n if axis is None:\n try:\n return a.size\n except AttributeError:\n return asarray(a).size\n else:\n try:\n return a.shape[axis]\n except AttributeError:\n return asarray(a).shape[axis]\n\ndef round_(a, decimals=0):\n \"\"\"Round 'a' to the given number of decimal places. Rounding\n behaviour is equivalent to Python.\n\n Return 'a' if the array is not floating point. Round both the real\n and imaginary parts separately if the array is complex.\n \"\"\"\n a = asarray(a)\n if not issubclass(a.dtype, _nx.inexact):\n return a\n if issubclass(a.dtype, _nx.complexfloating):\n return round_(a.real, decimals) + 1j*round_(a.imag, decimals)\n if decimals is not 0:\n decimals = asarray(decimals)\n s = sign(a)\n if decimals is not 0:\n a = absolute(multiply(a, 10.**decimals))\n else:\n a = absolute(a)\n rem = a-asarray(a).astype(_nx.intp)\n a = _nx.where(_nx.less(rem, 0.5), _nx.floor(a), _nx.ceil(a))\n # convert back\n if decimals is not 0:\n return multiply(a, s/(10.**decimals))\n else:\n return multiply(a, s)\n\naround = round_\n\ndef mean(a, axis=0, dtype=None):\n return asarray(a).mean(axis, dtype)\n\ndef std(a, axis=0, dtype=None):\n return asarray(a).std(axis, dtype)\n\ndef var(a, axis=0, dtype=None):\n return asarray(a).var(axis, dtype)\n", + "source_code_before": "# Compatibility module containing deprecated names\n\n__all__ = ['asarray', 'array', 'concatenate',\n 'NewAxis',\n 'UFuncType', 'UfuncType', 'ArrayType', 'arraytype',\n 'LittleEndian', 'Bool', \n 'Character', 'UnsignedInt8', 'UnsignedInt16', 'UnsignedInt',\n 'UInt8','UInt16','UInt32',\n # UnsignedInt64 and Unsigned128 added below if possible\n # same for Int64 and Int128, Float128, and Complex128\n 'Int8', 'Int16', 'Int32',\n 'Int0', 'Int', 'Float0', 'Float', 'Complex0', 'Complex',\n 'PyObject', 'Float32', 'Float64',\n 'Complex32', 'Complex64',\n 'typecodes', 'sarray', 'arrayrange', 'cross_correlate',\n 'matrixmultiply', 'outerproduct', 'innerproduct',\n # from cPickle\n 'dump', 'dumps',\n # functions that are now methods\n 'take', 'reshape', 'choose', 'repeat', 'put', 'putmask',\n 'swapaxes', 'transpose', 'sort', 'argsort', 'argmax', 'argmin',\n 'searchsorted', 'alen', \n 'resize', 'diagonal', 'trace', 'ravel', 'nonzero', 'shape',\n 'compress', 'clip', 'sum', 'product', 'prod', 'sometrue', 'alltrue',\n 'any', 'all', 'cumsum', 'cumproduct', 'cumprod', 'ptp', 'ndim',\n 'rank', 'size', 'around', 'round_', 'mean', 'std', 'var', 'squeeze',\n 'amax', 'amin'\n ]\n\nimport multiarray as mu\nimport umath as um\nimport numerictypes as nt\nfrom numeric import asarray, array, correlate, outer, concatenate\nfrom umath import sign, absolute, multiply\nimport numeric as _nx\nimport sys\n_dt_ = nt.dtype2char\n\n#Use this to add a new axis to an array\n#compatibility only\nNewAxis = None\n\n#deprecated\nUFuncType = type(um.sin)\nUfuncType = type(um.sin)\nArrayType = mu.ndarray\narraytype = mu.ndarray\n\nLittleEndian = (sys.byteorder == 'little')\n\n# backward compatible names from old Precision.py\n\nCharacter = 'S1'\nUnsignedInt8 = _dt_(nt.uint8)\nUInt8 = UnsignedInt8\nUnsignedInt16 = _dt_(nt.uint16)\nUInt16 = UnsignedInt16\nUnsignedInt32 = _dt_(nt.uint32)\nUInt32 = UnsignedInt32\nUnsignedInt = _dt_(nt.uint)\n\ntry:\n UnsignedInt64 = _dt_(nt.uint64)\nexcept AttributeError:\n pass\nelse:\n UInt64 = UnsignedInt64\n __all__ += ['UnsignedInt64', 'UInt64']\ntry:\n UnsignedInt128 = _dt_(nt.uint128)\nexcept AttributeError:\n pass\nelse:\n UInt128 = UnsignedInt128\n __all__ += ['UnsignedInt128','UInt128']\n\nInt8 = _dt_(nt.int8)\nInt16 = _dt_(nt.int16)\nInt32 = _dt_(nt.int32)\n\ntry:\n Int64 = _dt_(nt.int64)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int64']\n\ntry:\n Int128 = _dt_(nt.int128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int128']\n\nBool = _dt_(bool)\nInt0 = _dt_(int)\nInt = _dt_(int)\nFloat0 = _dt_(float)\nFloat = _dt_(float)\nComplex0 = _dt_(complex)\nComplex = _dt_(complex)\nPyObject = _dt_(nt.object_)\nFloat32 = _dt_(nt.float32)\nFloat64 = _dt_(nt.float64)\n\ntry:\n Float128 = _dt_(nt.float128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Float128']\n\nComplex32 = _dt_(nt.complex64)\nComplex64 = _dt_(nt.complex128)\n\ntry:\n Complex128 = _dt_(nt.complex256)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Complex128']\n\ntypecodes = {'Character':'S1',\n 'Integer':'bhilqp',\n 'UnsignedInteger':'BHILQP',\n 'Float':'fdg',\n 'Complex':'FDG',\n 'AllInteger':'bBhHiIlLqQpP',\n 'AllFloat':'fdgFDG',\n 'All':'?bhilqpBHILQPfdgFDGSUVO'}\n\ndef sarray(a, dtype=None, copy=False):\n return array(a, dtype, copy)\n\n# backward compatibility\narrayrange = mu.arange\ncross_correlate = correlate\n\n# deprecated names\nmatrixmultiply = mu.dot\nouterproduct = outer\ninnerproduct = mu.inner\n\nfrom cPickle import dump, dumps\n\n# functions that are now methods\n\ndef take(a, indices, axis=0):\n a = asarray(a)\n return a.take(indices, axis)\n\ndef reshape(a, newshape):\n \"\"\"Change the shape of a to newshape. Return a new view object.\n \"\"\"\n return asarray(a).reshape(newshape)\n\ndef choose(a, choices):\n a = asarray(a)\n return a.choose(choices)\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n If repeats is an integer, it is interpreted as\n a tuple of length a.shape[axis] containing repeats.\n The argument a can be anything array(a) will accept.\n \"\"\"\n a = array(a, copy=False)\n return a.repeat(repeats, axis)\n\ndef put (a, ind, v):\n \"\"\"put(a, ind, v) results in a[n] = v[n] for all n in ind\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n The routine put is the equivalent of the following (although the loop\n is in C for speed):\n\n ind = array(indices, copy=False)\n v = array(values, copy=False).astype(a, a.dtype)\n for i in ind: a.flat[i] = v[i]\n a must be a contiguous Numeric array.\n \"\"\"\n return a.put(v,ind)\n\ndef putmask (a, mask, v):\n \"\"\"putmask(a, mask, v) results in a = v for all places mask is true.\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n \"\"\"\n return a.putmask(v, mask)\n\ndef swapaxes(a, axis1, axis2):\n \"\"\"swapaxes(a, axis1, axis2) returns array a with axis1 and axis2\n interchanged.\n \"\"\"\n a = array(a, copy=False)\n return a.swapaxes(axis1, axis2)\n\ndef transpose(a, axes=None):\n \"\"\"transpose(a, axes=None) returns array with dimensions permuted\n according to axes. If axes is None (default) returns array with\n dimensions reversed.\n \"\"\"\n a = array(a,copy=False)\n return a.transpose(axes)\n\ndef sort(a, axis=-1):\n \"\"\"sort(a,axis=-1) returns array with elements sorted along given axis.\n \"\"\"\n a = array(a, copy=True)\n a.sort(axis)\n return a\n\ndef argsort(a, axis=-1):\n \"\"\"argsort(a,axis=-1) return the indices into a of the sorted array\n along the given axis, so that take(a,result,axis) is the sorted array.\n \"\"\"\n a = array(a, copy=False)\n return a.argsort(axis)\n\ndef argmax(a, axis=-1):\n \"\"\"argmax(a,axis=-1) returns the indices to the maximum value of the\n 1-D arrays along the given axis.\n \"\"\"\n a = array(a, copy=False)\n return a.argmax(axis)\n\ndef argmin(a, axis=-1):\n \"\"\"argmin(a,axis=-1) returns the indices to the minimum value of the\n 1-D arrays along the given axis.\n \"\"\"\n a = array(a,copy=False)\n return a.argmin(axis)\n\ndef searchsorted(a, v):\n \"\"\"searchsorted(a, v)\n \"\"\"\n a = array(a,copy=False)\n return a.searchsorted(v)\n\ndef resize(a, new_shape):\n \"\"\"resize(a,new_shape) returns a new array with the specified shape.\n The original array's total size can be any size. It\n fills the new array with repeated copies of a.\n\n Note that a.resize(new_shape) will fill array with 0's\n beyond current definition of a.\n \"\"\"\n\n if isinstance(new_shape, (int, nt.integer)):\n new_shape = (new_shape,)\n a = ravel(a)\n Na = len(a)\n if not Na: return mu.zeros(new_shape, a.dtypechar)\n total_size = um.multiply.reduce(new_shape)\n n_copies = int(total_size / Na)\n extra = total_size % Na\n\n if total_size == 0:\n return a[:0]\n\n if extra != 0:\n n_copies = n_copies+1\n extra = Na-extra\n\n a = concatenate( (a,)*n_copies)\n if extra > 0:\n a = a[:-extra]\n\n return reshape(a, new_shape)\n\ndef squeeze(a):\n \"Returns a with any ones from the shape of a removed\"\n return asarray(a).squeeze()\n\ndef diagonal(a, offset=0, axis1=0, axis2=1):\n \"\"\"diagonal(a, offset=0, axis1=0, axis2=1) returns the given diagonals\n defined by the last two dimensions of the array.\n \"\"\"\n return asarray(a).diagonal(offset, axis1, axis2)\n\ndef trace(a, offset=0, axis1=0, axis2=1, dtype=None):\n \"\"\"trace(a,offset=0, axis1=0, axis2=1) returns the sum along diagonals\n (defined by the last two dimenions) of the array.\n \"\"\"\n return asarray(a).trace(offset, axis1, axis2, dtype)\n\ndef ravel(m):\n \"\"\"ravel(m) returns a 1d array corresponding to all the elements of it's\n argument.\n \"\"\"\n return asarray(m).ravel()\n\ndef nonzero(a):\n \"\"\"nonzero(a) returns the indices of the elements of a which are not zero,\n a must be 1d\n \"\"\"\n return asarray(a).nonzero()\n\ndef shape(a):\n \"\"\"shape(a) returns the shape of a (as a function call which\n also works on nested sequences).\n \"\"\"\n return asarray(a).shape\n\ndef compress(condition, m, axis=-1):\n \"\"\"compress(condition, x, axis=-1) = those elements of x corresponding \n to those elements of condition that are \"true\". condition must be the\n same size as the given dimension of x.\"\"\"\n return asarray(m).compress(condition, axis)\n\ndef clip(m, m_min, m_max):\n \"\"\"clip(m, m_min, m_max) = every entry in m that is less than m_min is\n replaced by m_min, and every entry greater than m_max is replaced by\n m_max.\n \"\"\"\n return asarray(m).clip(m_min, m_max)\n\ndef sum(x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis. The optional dtype argument\n is the data type for intermediate calculations.\n\n The default is to upcast (promote) smaller integer types to the\n platform-dependent Int. For example, on 32-bit platforms:\n\n x.dtype default sum() dtype\n ---------------------------------------------------\n bool, Int8, Int16, Int32 Int32\n\n Examples:\n >>> sum([0.5, 1.5])\n 2.0\n >>> sum([0.5, 1.5], dtype=Int32)\n 1\n >>> sum([[0, 1], [0, 5]])\n array([0, 6])\n >>> sum([[0, 1], [0, 5]], axis=1)\n array([1, 5])\n \"\"\"\n return asarray(x).sum(axis, dtype)\n\ndef product (x, axis=0, dtype=None):\n \"\"\"Product of the array elements over the given axis.\"\"\"\n return asarray(x).prod(axis, dtype)\n\ndef sometrue (x, axis=0):\n \"\"\"Perform a logical_or over the given axis.\"\"\"\n return asarray(x).any(axis)\n\ndef alltrue (x, axis=0):\n \"\"\"Perform a logical_and over the given axis.\"\"\"\n return asarray(x).all(axis)\n\ndef any(x,axis=None):\n \"\"\"Return true if any elements of x are true: sometrue(ravel(x))\n \"\"\"\n return ravel(x).any(axis)\n\ndef all(x,axis=None):\n \"\"\"Return true if all elements of x are true: alltrue(ravel(x))\n \"\"\"\n return ravel(x).all(axis)\n\ndef cumsum (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumsum(axis, dtype)\n\ndef cumproduct (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumprod(axis, dtype)\n\ndef ptp(a, axis=0):\n \"\"\"Return maximum - minimum along the the given dimension\n \"\"\"\n return asarray(a).ptp(axis)\n\ndef amax(a, axis=0):\n \"\"\"Return the maximum of 'a' along dimension axis.\n \"\"\"\n return asarray(a).max(axis)\n\ndef amin(a, axis=0):\n \"\"\"Return the minimum of a along dimension axis.\n \"\"\"\n return asarray(a).min(axis)\n\ndef alen(a):\n \"\"\"Return the length of a Python object interpreted as an array\n \"\"\"\n return len(asarray(a))\n\ndef prod(a, axis=0):\n \"\"\"Return the product of the elements along the given axis\n \"\"\"\n return asarray(a).prod(axis)\n\ndef cumprod(a, axis=0):\n \"\"\"Return the cumulative product of the elments along the given axis\n \"\"\"\n return asarray(a).cumprod(axis)\n\ndef ndim(a):\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef rank (a):\n \"\"\"Get the rank of sequence a (the number of dimensions, not a matrix rank)\n The rank of a scalar is zero.\n \"\"\"\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef size (a, axis=None):\n \"Get the number of elements in sequence a, or along a certain axis.\"\n if axis is None:\n try:\n return a.size\n except AttributeError:\n return asarray(a).size\n else:\n try:\n return a.shape[axis]\n except AttributeError:\n return asarray(a).shape[axis]\n\ndef round_(a, decimals=0):\n \"\"\"Round 'a' to the given number of decimal places. Rounding\n behaviour is equivalent to Python.\n\n Return 'a' if the array is not floating point. Round both the real\n and imaginary parts separately if the array is complex.\n \"\"\"\n a = asarray(a)\n if not issubclass(a.dtype, _nx.inexact):\n return a\n if issubclass(a.dtype, _nx.complexfloating):\n return round_(a.real, decimals) + 1j*round_(a.imag, decimals)\n if decimals is not 0:\n decimals = asarray(decimals)\n s = sign(a)\n if decimals is not 0:\n a = absolute(multiply(a, 10.**decimals))\n else:\n a = absolute(a)\n rem = a-asarray(a).astype(_nx.intp)\n a = _nx.where(_nx.less(rem, 0.5), _nx.floor(a), _nx.ceil(a))\n # convert back\n if decimals is not 0:\n return multiply(a, s/(10.**decimals))\n else:\n return multiply(a, s)\n\naround = round_\n\ndef mean(a, axis=0, dtype=None):\n return asarray(a).mean(axis, dtype)\n\ndef std(a, axis=0, dtype=None):\n return asarray(a).std(axis, dtype)\n\ndef var(a, axis=0, dtype=None):\n return asarray(a).var(axis, dtype)\n", + "methods": [ + { + "name": "sarray", + "long_name": "sarray( a , dtype = None , copy = False )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "dtype", + "copy" + ], + "start_line": 135, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 151, + "end_line": 153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , newshape )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "a", + "newshape" + ], + "start_line": 155, + "end_line": 158, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "choose", + "long_name": "choose( a , choices )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "choices" + ], + "start_line": 160, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 164, + "end_line": 173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , ind , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "ind", + "v" + ], + "start_line": 175, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "mask", + "v" + ], + "start_line": 189, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "swapaxes", + "long_name": "swapaxes( a , axis1 , axis2 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis1", + "axis2" + ], + "start_line": 196, + "end_line": 201, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a", + "axes" + ], + "start_line": 203, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "sort", + "long_name": "sort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis" + ], + "start_line": 211, + "end_line": 216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 218, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 225, + "end_line": 230, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 232, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "searchsorted", + "long_name": "searchsorted( a , v )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "v" + ], + "start_line": 239, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "oldnumeric.py", + "nloc": 18, + "complexity": 6, + "token_count": 135, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 245, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "squeeze", + "long_name": "squeeze( a )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "a" + ], + "start_line": 276, + "end_line": 278, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , offset = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 32, + "parameters": [ + "a", + "offset", + "axis1", + "axis2" + ], + "start_line": 280, + "end_line": 284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "trace", + "long_name": "trace( a , offset = 0 , axis1 = 0 , axis2 = 1 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 38, + "parameters": [ + "a", + "offset", + "axis1", + "axis2", + "dtype" + ], + "start_line": 286, + "end_line": 290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( m )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "m" + ], + "start_line": 292, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "nonzero", + "long_name": "nonzero( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "a" + ], + "start_line": 298, + "end_line": 302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "a" + ], + "start_line": 304, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , m , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "condition", + "m", + "axis" + ], + "start_line": 310, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "clip", + "long_name": "clip( m , m_min , m_max )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "m", + "m_min", + "m_max" + ], + "start_line": 316, + "end_line": 321, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "sum", + "long_name": "sum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 323, + "end_line": 344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "product", + "long_name": "product( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 346, + "end_line": 348, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "sometrue", + "long_name": "sometrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 350, + "end_line": 352, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "alltrue", + "long_name": "alltrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 354, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "any", + "long_name": "any( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 358, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "all", + "long_name": "all( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 363, + "end_line": 366, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "cumsum", + "long_name": "cumsum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 368, + "end_line": 370, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cumproduct", + "long_name": "cumproduct( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 372, + "end_line": 374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "ptp", + "long_name": "ptp( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 376, + "end_line": 379, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "amax", + "long_name": "amax( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 381, + "end_line": 384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "amin", + "long_name": "amin( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 386, + "end_line": 389, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "alen", + "long_name": "alen( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "a" + ], + "start_line": 391, + "end_line": 394, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "prod", + "long_name": "prod( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 396, + "end_line": 399, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "cumprod", + "long_name": "cumprod( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 401, + "end_line": 404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ndim", + "long_name": "ndim( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 21, + "parameters": [ + "a" + ], + "start_line": 406, + "end_line": 410, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rank", + "long_name": "rank( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "a" + ], + "start_line": 412, + "end_line": 419, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( a , axis = None )", + "filename": "oldnumeric.py", + "nloc": 12, + "complexity": 4, + "token_count": 55, + "parameters": [ + "a", + "axis" + ], + "start_line": 421, + "end_line": 432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "round_", + "long_name": "round_( a , decimals = 0 )", + "filename": "oldnumeric.py", + "nloc": 19, + "complexity": 6, + "token_count": 184, + "parameters": [ + "a", + "decimals" + ], + "start_line": 434, + "end_line": 459, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "mean", + "long_name": "mean( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 463, + "end_line": 464, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "std", + "long_name": "std( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 466, + "end_line": 467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "var", + "long_name": "var( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 469, + "end_line": 470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "sarray", + "long_name": "sarray( a , dtype = None , copy = False )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "dtype", + "copy" + ], + "start_line": 132, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 148, + "end_line": 150, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , newshape )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "a", + "newshape" + ], + "start_line": 152, + "end_line": 155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "choose", + "long_name": "choose( a , choices )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "choices" + ], + "start_line": 157, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 161, + "end_line": 170, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , ind , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "ind", + "v" + ], + "start_line": 172, + "end_line": 184, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "mask", + "v" + ], + "start_line": 186, + "end_line": 191, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "swapaxes", + "long_name": "swapaxes( a , axis1 , axis2 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis1", + "axis2" + ], + "start_line": 193, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a", + "axes" + ], + "start_line": 200, + "end_line": 206, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "sort", + "long_name": "sort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis" + ], + "start_line": 208, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 215, + "end_line": 220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 222, + "end_line": 227, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 229, + "end_line": 234, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "searchsorted", + "long_name": "searchsorted( a , v )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "v" + ], + "start_line": 236, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "oldnumeric.py", + "nloc": 18, + "complexity": 6, + "token_count": 135, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 242, + "end_line": 271, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "squeeze", + "long_name": "squeeze( a )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "a" + ], + "start_line": 273, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , offset = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 32, + "parameters": [ + "a", + "offset", + "axis1", + "axis2" + ], + "start_line": 277, + "end_line": 281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "trace", + "long_name": "trace( a , offset = 0 , axis1 = 0 , axis2 = 1 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 38, + "parameters": [ + "a", + "offset", + "axis1", + "axis2", + "dtype" + ], + "start_line": 283, + "end_line": 287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( m )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "m" + ], + "start_line": 289, + "end_line": 293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "nonzero", + "long_name": "nonzero( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "a" + ], + "start_line": 295, + "end_line": 299, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "a" + ], + "start_line": 301, + "end_line": 305, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , m , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "condition", + "m", + "axis" + ], + "start_line": 307, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "clip", + "long_name": "clip( m , m_min , m_max )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "m", + "m_min", + "m_max" + ], + "start_line": 313, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "sum", + "long_name": "sum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 320, + "end_line": 341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "product", + "long_name": "product( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 343, + "end_line": 345, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "sometrue", + "long_name": "sometrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 347, + "end_line": 349, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "alltrue", + "long_name": "alltrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 351, + "end_line": 353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "any", + "long_name": "any( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 355, + "end_line": 358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "all", + "long_name": "all( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 360, + "end_line": 363, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "cumsum", + "long_name": "cumsum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 365, + "end_line": 367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cumproduct", + "long_name": "cumproduct( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 369, + "end_line": 371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "ptp", + "long_name": "ptp( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 373, + "end_line": 376, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "amax", + "long_name": "amax( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 378, + "end_line": 381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "amin", + "long_name": "amin( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 383, + "end_line": 386, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "alen", + "long_name": "alen( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "a" + ], + "start_line": 388, + "end_line": 391, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "prod", + "long_name": "prod( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 393, + "end_line": 396, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "cumprod", + "long_name": "cumprod( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 398, + "end_line": 401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ndim", + "long_name": "ndim( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 21, + "parameters": [ + "a" + ], + "start_line": 403, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rank", + "long_name": "rank( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "a" + ], + "start_line": 409, + "end_line": 416, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( a , axis = None )", + "filename": "oldnumeric.py", + "nloc": 12, + "complexity": 4, + "token_count": 55, + "parameters": [ + "a", + "axis" + ], + "start_line": 418, + "end_line": 429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "round_", + "long_name": "round_( a , decimals = 0 )", + "filename": "oldnumeric.py", + "nloc": 19, + "complexity": 6, + "token_count": 184, + "parameters": [ + "a", + "decimals" + ], + "start_line": 431, + "end_line": 456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "mean", + "long_name": "mean( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 460, + "end_line": 461, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "std", + "long_name": "std( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 463, + "end_line": 464, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "var", + "long_name": "var( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 466, + "end_line": 467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 262, + "complexity": 59, + "token_count": 1966, + "diff_parsed": { + "added": [ + " 'amax', 'amin','bsum'", + "# save away Python sum", + "bsum = sum", + "" + ], + "deleted": [ + " 'amax', 'amin'" + ] + } + }, + { + "old_path": "numpy/lib/arraysetops.py", + "new_path": "numpy/lib/arraysetops.py", + "filename": "arraysetops.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -34,21 +34,21 @@\n \n ##\n # 03.11.2005, c\n-def ediff1d( ar1, toEnd = None, toBegin = None ):\n+def ediff1d( ar1, to_end = None, to_begin = None ):\n \"\"\"Array difference with prefixed and/or appended value.\"\"\"\n dar1 = ar1[1:] - ar1[:-1]\n- if toEnd and toBegin:\n+ if to_end and to_begin:\n shape = (ar1.shape[0] + 1,) + ar1.shape[1:]\n ed = numpy.empty( shape, dtype = ar1.dtype )\n- ed[0], ed[-1] = toBegin, toEnd\n+ ed[0], ed[-1] = to_begin, to_end\n ed[1:-1] = dar1\n- elif toEnd:\n+ elif to_end:\n ed = numpy.empty( ar1.shape, dtype = ar1.dtype )\n- ed[-1] = toEnd\n+ ed[-1] = to_end\n ed[:-1] = dar1\n- elif toBegin:\n+ elif to_begin:\n ed = numpy.empty( ar1.shape, dtype = ar1.dtype )\n- ed[0] = toBegin\n+ ed[0] = to_begin\n ed[1:] = dar1\n else:\n ed = dar1\n@@ -59,12 +59,12 @@ def ediff1d( ar1, toEnd = None, toBegin = None ):\n ##\n # 01.11.2005, c\n # 02.11.2005\n-def unique1d( ar1, retIndx = False ):\n- \"\"\"Unique elements of 1D array. When retIndx is True, return also the\n- indices indx such that ar1[indx] is the resulting array of unique\n+def unique1d( ar1, retindx = False ):\n+ \"\"\"Unique elements of 1D array. When ret_indx is True, return also the\n+ indices indx such that ar1.flat[indx] is the resulting array of unique\n elements.\"\"\"\n ar = numpy.array( ar1 ).ravel()\n- if retIndx:\n+ if retindx:\n perm = numpy.argsort( ar )\n aux = numpy.take( ar, perm )\n flag = ediff1d( aux, 1 ) != 0\n@@ -94,7 +94,7 @@ def intersect1d_nu( ar1, ar2 ):\n def setxor1d( ar1, ar2 ):\n \"\"\"Set exclusive-or of 1D arrays with unique elements.\"\"\"\n aux = numpy.sort( numpy.concatenate( (ar1, ar2 ) ) )\n- flag = ediff1d( aux, toEnd = 1, toBegin = 1 ) == 0\n+ flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0\n flag2 = ediff1d( flag, 0 ) == 0\n return numpy.compress( flag2, aux )\n \n@@ -136,7 +136,7 @@ def setdiff1d( ar1, ar2 ):\n \n ##\n # 02.11.2005, c\n-def test_unique1d_speed( plotResults = False ):\n+def test_unique1d_speed( plot_results = False ):\n # exponents = numpy.linspace( 2, 7, 9 )\n exponents = numpy.linspace( 2, 6, 9 )\n ratios = []\n@@ -182,7 +182,7 @@ def test_unique1d_speed( plotResults = False ):\n print dt2s\n print ratios\n \n- if plotResults:\n+ if plot_results:\n import pylab\n \n def plotMe( fig, fun, nItems, dt1s, dt2s ):\n@@ -198,4 +198,4 @@ def plotMe( fig, fun, nItems, dt1s, dt2s ):\n pylab.show()\n \n if (__name__ == '__main__'):\n- test_unique1d_speed( plotResults = True )\n+ test_unique1d_speed( plot_results = True )\n", + "added_lines": 15, + "deleted_lines": 15, + "source_code": "\"\"\"\nSet operations for 1D numeric arrays based on sort() function.\n\nContains:\n ediff1d,\n unique1d,\n intersect1d,\n intersect1d_nu,\n setxor1d,\n setmember1d,\n union1d,\n setdiff1d\n\nConcerning the speed, test_unique1d_speed() reveals that up to 10000000\nelements unique1d() is about 10 times faster than the standard dictionary-based\nnumpy.unique().\n\nLimitations: Except unique1d, union1d and intersect1d_nu, all functions expect\ninputs with unique elements. Speed could be gained in some operations by an\nimplementaion of sort(), that can provide directly the permutation vectors,\navoiding thus calls to argsort().\n\nTo do: Optionally return indices analogously to unique1d for all functions.\n\nAuthor: Robert Cimrman\n\"\"\"\n__all__ = ['unique1d', 'intersect1d', 'intersect1d_nu', 'setxor1d',\n 'setmember1d', 'union1d', 'setdiff1d']\n\n\n# 02.11.2005, c\nimport time\nimport numpy\n\n##\n# 03.11.2005, c\ndef ediff1d( ar1, to_end = None, to_begin = None ):\n \"\"\"Array difference with prefixed and/or appended value.\"\"\"\n dar1 = ar1[1:] - ar1[:-1]\n if to_end and to_begin:\n shape = (ar1.shape[0] + 1,) + ar1.shape[1:]\n ed = numpy.empty( shape, dtype = ar1.dtype )\n ed[0], ed[-1] = to_begin, to_end\n ed[1:-1] = dar1\n elif to_end:\n ed = numpy.empty( ar1.shape, dtype = ar1.dtype )\n ed[-1] = to_end\n ed[:-1] = dar1\n elif to_begin:\n ed = numpy.empty( ar1.shape, dtype = ar1.dtype )\n ed[0] = to_begin\n ed[1:] = dar1\n else:\n ed = dar1\n\n return ed\n\n\n##\n# 01.11.2005, c\n# 02.11.2005\ndef unique1d( ar1, retindx = False ):\n \"\"\"Unique elements of 1D array. When ret_indx is True, return also the\n indices indx such that ar1.flat[indx] is the resulting array of unique\n elements.\"\"\"\n ar = numpy.array( ar1 ).ravel()\n if retindx:\n perm = numpy.argsort( ar )\n aux = numpy.take( ar, perm )\n flag = ediff1d( aux, 1 ) != 0\n return numpy.compress( flag, perm ), numpy.compress( flag, aux )\n else:\n aux = numpy.sort( ar )\n return numpy.compress( ediff1d( aux, 1 ) != 0, aux ) \n\n##\n# 01.11.2005, c\ndef intersect1d( ar1, ar2 ):\n \"\"\"Intersection of 1D arrays with unique elements.\"\"\"\n aux = numpy.sort( numpy.concatenate( (ar1, ar2 ) ) )\n return numpy.compress( (aux[1:] - aux[:-1]) == 0, aux )\n\n##\n# 01.11.2005, c\ndef intersect1d_nu( ar1, ar2 ):\n \"\"\"Intersection of 1D arrays with any elements.\"\"\"\n # Might be faster then unique1d( intersect1d( ar1, ar2 ) )?\n aux = numpy.sort( numpy.concatenate( (unique1d( ar1 ),\n unique1d( ar2 )) ) )\n return numpy.compress( (aux[1:] - aux[:-1]) == 0, aux )\n\n##\n# 01.11.2005, c\ndef setxor1d( ar1, ar2 ):\n \"\"\"Set exclusive-or of 1D arrays with unique elements.\"\"\"\n aux = numpy.sort( numpy.concatenate( (ar1, ar2 ) ) )\n flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0\n flag2 = ediff1d( flag, 0 ) == 0\n return numpy.compress( flag2, aux )\n\n##\n# 03.11.2005, c\n# 05.01.2006\ndef setmember1d( ar1, ar2 ):\n \"\"\"Return an array of shape of ar1 containing 1 where the elements of\n ar1 are in ar2 and 0 otherwise.\"\"\"\n ar = numpy.concatenate( (ar1, ar2 ) )\n tt = numpy.concatenate( (numpy.zeros_like( ar1 ),\n numpy.zeros_like( ar2 ) + 1) )\n perm = numpy.argsort( ar )\n aux = numpy.take( ar, perm )\n aux2 = numpy.take( tt, perm )\n flag = ediff1d( aux, 1 ) == 0\n\n ii = numpy.where( flag * aux2 )\n aux = perm[ii+1]\n perm[ii+1] = perm[ii]\n perm[ii] = aux\n\n indx = numpy.argsort( perm )[:len( ar1 )]\n\n return numpy.take( flag, indx )\n\n##\n# 03.11.2005, c\ndef union1d( ar1, ar2 ):\n \"\"\"Union of 1D arrays with unique elements.\"\"\"\n return unique1d( numpy.concatenate( (ar1, ar2) ) )\n\n##\n# 03.11.2005, c\ndef setdiff1d( ar1, ar2 ):\n \"\"\"Set difference of 1D arrays with unique elements.\"\"\"\n aux = setmember1d( ar1, ar2 )\n return numpy.compress( aux == 0, ar1 )\n\n##\n# 02.11.2005, c\ndef test_unique1d_speed( plot_results = False ):\n# exponents = numpy.linspace( 2, 7, 9 )\n exponents = numpy.linspace( 2, 6, 9 )\n ratios = []\n nItems = []\n dt1s = []\n dt2s = []\n for ii in exponents:\n\n nItem = 10 ** ii\n print 'using %d items:' % nItem\n a = numpy.fix( nItem / 10 * numpy.random.random( nItem ) )\n\n print 'dictionary:'\n tt = time.clock() \n b = numpy.unique( a )\n dt1 = time.clock() - tt\n print dt1\n\n print 'array:'\n tt = time.clock() \n c = unique1d( a )\n dt2 = time.clock() - tt\n print dt2\n\n\n if dt1 < 1e-8:\n ratio = 'ND'\n else:\n ratio = dt2 / dt1\n print 'ratio:', ratio\n print 'nUnique: %d == %d\\n' % (len( b ), len( c ))\n\n nItems.append( nItem )\n ratios.append( ratio )\n dt1s.append( dt1 )\n dt2s.append( dt2 )\n\n assert numpy.alltrue( b == c )\n\n\n print nItems\n print dt1s\n print dt2s\n print ratios\n\n if plot_results:\n import pylab\n\n def plotMe( fig, fun, nItems, dt1s, dt2s ):\n pylab.figure( fig )\n fun( nItems, dt1s, 'g-o', linewidth = 2, markersize = 8 )\n fun( nItems, dt2s, 'b-x', linewidth = 2, markersize = 8 )\n pylab.legend( ('dictionary', 'array' ) )\n pylab.xlabel( 'nItem' )\n pylab.ylabel( 'time [s]' )\n\n plotMe( 1, pylab.loglog, nItems, dt1s, dt2s )\n plotMe( 2, pylab.plot, nItems, dt1s, dt2s )\n pylab.show()\n\nif (__name__ == '__main__'):\n test_unique1d_speed( plot_results = True )\n", + "source_code_before": "\"\"\"\nSet operations for 1D numeric arrays based on sort() function.\n\nContains:\n ediff1d,\n unique1d,\n intersect1d,\n intersect1d_nu,\n setxor1d,\n setmember1d,\n union1d,\n setdiff1d\n\nConcerning the speed, test_unique1d_speed() reveals that up to 10000000\nelements unique1d() is about 10 times faster than the standard dictionary-based\nnumpy.unique().\n\nLimitations: Except unique1d, union1d and intersect1d_nu, all functions expect\ninputs with unique elements. Speed could be gained in some operations by an\nimplementaion of sort(), that can provide directly the permutation vectors,\navoiding thus calls to argsort().\n\nTo do: Optionally return indices analogously to unique1d for all functions.\n\nAuthor: Robert Cimrman\n\"\"\"\n__all__ = ['unique1d', 'intersect1d', 'intersect1d_nu', 'setxor1d',\n 'setmember1d', 'union1d', 'setdiff1d']\n\n\n# 02.11.2005, c\nimport time\nimport numpy\n\n##\n# 03.11.2005, c\ndef ediff1d( ar1, toEnd = None, toBegin = None ):\n \"\"\"Array difference with prefixed and/or appended value.\"\"\"\n dar1 = ar1[1:] - ar1[:-1]\n if toEnd and toBegin:\n shape = (ar1.shape[0] + 1,) + ar1.shape[1:]\n ed = numpy.empty( shape, dtype = ar1.dtype )\n ed[0], ed[-1] = toBegin, toEnd\n ed[1:-1] = dar1\n elif toEnd:\n ed = numpy.empty( ar1.shape, dtype = ar1.dtype )\n ed[-1] = toEnd\n ed[:-1] = dar1\n elif toBegin:\n ed = numpy.empty( ar1.shape, dtype = ar1.dtype )\n ed[0] = toBegin\n ed[1:] = dar1\n else:\n ed = dar1\n\n return ed\n\n\n##\n# 01.11.2005, c\n# 02.11.2005\ndef unique1d( ar1, retIndx = False ):\n \"\"\"Unique elements of 1D array. When retIndx is True, return also the\n indices indx such that ar1[indx] is the resulting array of unique\n elements.\"\"\"\n ar = numpy.array( ar1 ).ravel()\n if retIndx:\n perm = numpy.argsort( ar )\n aux = numpy.take( ar, perm )\n flag = ediff1d( aux, 1 ) != 0\n return numpy.compress( flag, perm ), numpy.compress( flag, aux )\n else:\n aux = numpy.sort( ar )\n return numpy.compress( ediff1d( aux, 1 ) != 0, aux ) \n\n##\n# 01.11.2005, c\ndef intersect1d( ar1, ar2 ):\n \"\"\"Intersection of 1D arrays with unique elements.\"\"\"\n aux = numpy.sort( numpy.concatenate( (ar1, ar2 ) ) )\n return numpy.compress( (aux[1:] - aux[:-1]) == 0, aux )\n\n##\n# 01.11.2005, c\ndef intersect1d_nu( ar1, ar2 ):\n \"\"\"Intersection of 1D arrays with any elements.\"\"\"\n # Might be faster then unique1d( intersect1d( ar1, ar2 ) )?\n aux = numpy.sort( numpy.concatenate( (unique1d( ar1 ),\n unique1d( ar2 )) ) )\n return numpy.compress( (aux[1:] - aux[:-1]) == 0, aux )\n\n##\n# 01.11.2005, c\ndef setxor1d( ar1, ar2 ):\n \"\"\"Set exclusive-or of 1D arrays with unique elements.\"\"\"\n aux = numpy.sort( numpy.concatenate( (ar1, ar2 ) ) )\n flag = ediff1d( aux, toEnd = 1, toBegin = 1 ) == 0\n flag2 = ediff1d( flag, 0 ) == 0\n return numpy.compress( flag2, aux )\n\n##\n# 03.11.2005, c\n# 05.01.2006\ndef setmember1d( ar1, ar2 ):\n \"\"\"Return an array of shape of ar1 containing 1 where the elements of\n ar1 are in ar2 and 0 otherwise.\"\"\"\n ar = numpy.concatenate( (ar1, ar2 ) )\n tt = numpy.concatenate( (numpy.zeros_like( ar1 ),\n numpy.zeros_like( ar2 ) + 1) )\n perm = numpy.argsort( ar )\n aux = numpy.take( ar, perm )\n aux2 = numpy.take( tt, perm )\n flag = ediff1d( aux, 1 ) == 0\n\n ii = numpy.where( flag * aux2 )\n aux = perm[ii+1]\n perm[ii+1] = perm[ii]\n perm[ii] = aux\n\n indx = numpy.argsort( perm )[:len( ar1 )]\n\n return numpy.take( flag, indx )\n\n##\n# 03.11.2005, c\ndef union1d( ar1, ar2 ):\n \"\"\"Union of 1D arrays with unique elements.\"\"\"\n return unique1d( numpy.concatenate( (ar1, ar2) ) )\n\n##\n# 03.11.2005, c\ndef setdiff1d( ar1, ar2 ):\n \"\"\"Set difference of 1D arrays with unique elements.\"\"\"\n aux = setmember1d( ar1, ar2 )\n return numpy.compress( aux == 0, ar1 )\n\n##\n# 02.11.2005, c\ndef test_unique1d_speed( plotResults = False ):\n# exponents = numpy.linspace( 2, 7, 9 )\n exponents = numpy.linspace( 2, 6, 9 )\n ratios = []\n nItems = []\n dt1s = []\n dt2s = []\n for ii in exponents:\n\n nItem = 10 ** ii\n print 'using %d items:' % nItem\n a = numpy.fix( nItem / 10 * numpy.random.random( nItem ) )\n\n print 'dictionary:'\n tt = time.clock() \n b = numpy.unique( a )\n dt1 = time.clock() - tt\n print dt1\n\n print 'array:'\n tt = time.clock() \n c = unique1d( a )\n dt2 = time.clock() - tt\n print dt2\n\n\n if dt1 < 1e-8:\n ratio = 'ND'\n else:\n ratio = dt2 / dt1\n print 'ratio:', ratio\n print 'nUnique: %d == %d\\n' % (len( b ), len( c ))\n\n nItems.append( nItem )\n ratios.append( ratio )\n dt1s.append( dt1 )\n dt2s.append( dt2 )\n\n assert numpy.alltrue( b == c )\n\n\n print nItems\n print dt1s\n print dt2s\n print ratios\n\n if plotResults:\n import pylab\n\n def plotMe( fig, fun, nItems, dt1s, dt2s ):\n pylab.figure( fig )\n fun( nItems, dt1s, 'g-o', linewidth = 2, markersize = 8 )\n fun( nItems, dt2s, 'b-x', linewidth = 2, markersize = 8 )\n pylab.legend( ('dictionary', 'array' ) )\n pylab.xlabel( 'nItem' )\n pylab.ylabel( 'time [s]' )\n\n plotMe( 1, pylab.loglog, nItems, dt1s, dt2s )\n plotMe( 2, pylab.plot, nItems, dt1s, dt2s )\n pylab.show()\n\nif (__name__ == '__main__'):\n test_unique1d_speed( plotResults = True )\n", + "methods": [ + { + "name": "ediff1d", + "long_name": "ediff1d( ar1 , to_end = None , to_begin = None )", + "filename": "arraysetops.py", + "nloc": 18, + "complexity": 5, + "token_count": 164, + "parameters": [ + "ar1", + "to_end", + "to_begin" + ], + "start_line": 37, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "unique1d", + "long_name": "unique1d( ar1 , retindx = False )", + "filename": "arraysetops.py", + "nloc": 10, + "complexity": 2, + "token_count": 97, + "parameters": [ + "ar1", + "retindx" + ], + "start_line": 62, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "intersect1d", + "long_name": "intersect1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 3, + "complexity": 1, + "token_count": 49, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 78, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "intersect1d_nu", + "long_name": "intersect1d_nu( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 4, + "complexity": 1, + "token_count": 55, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 85, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "setxor1d", + "long_name": "setxor1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 5, + "complexity": 1, + "token_count": 60, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 94, + "end_line": 99, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "setmember1d", + "long_name": "setmember1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 14, + "complexity": 1, + "token_count": 141, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 104, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "union1d", + "long_name": "union1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 126, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "setdiff1d", + "long_name": "setdiff1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 132, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "test_unique1d_speed.plotMe", + "long_name": "test_unique1d_speed.plotMe( fig , fun , nItems , dt1s , dt2s )", + "filename": "arraysetops.py", + "nloc": 7, + "complexity": 1, + "token_count": 73, + "parameters": [ + "fig", + "fun", + "nItems", + "dt1s", + "dt2s" + ], + "start_line": 188, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 2 + }, + { + "name": "test_unique1d_speed", + "long_name": "test_unique1d_speed( plot_results = False )", + "filename": "arraysetops.py", + "nloc": 41, + "complexity": 4, + "token_count": 238, + "parameters": [ + "plot_results" + ], + "start_line": 139, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "ediff1d", + "long_name": "ediff1d( ar1 , toEnd = None , toBegin = None )", + "filename": "arraysetops.py", + "nloc": 18, + "complexity": 5, + "token_count": 164, + "parameters": [ + "ar1", + "toEnd", + "toBegin" + ], + "start_line": 37, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "unique1d", + "long_name": "unique1d( ar1 , retIndx = False )", + "filename": "arraysetops.py", + "nloc": 10, + "complexity": 2, + "token_count": 97, + "parameters": [ + "ar1", + "retIndx" + ], + "start_line": 62, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "intersect1d", + "long_name": "intersect1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 3, + "complexity": 1, + "token_count": 49, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 78, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "intersect1d_nu", + "long_name": "intersect1d_nu( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 4, + "complexity": 1, + "token_count": 55, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 85, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "setxor1d", + "long_name": "setxor1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 5, + "complexity": 1, + "token_count": 60, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 94, + "end_line": 99, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "setmember1d", + "long_name": "setmember1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 14, + "complexity": 1, + "token_count": 141, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 104, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "union1d", + "long_name": "union1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 126, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "setdiff1d", + "long_name": "setdiff1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 132, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "test_unique1d_speed.plotMe", + "long_name": "test_unique1d_speed.plotMe( fig , fun , nItems , dt1s , dt2s )", + "filename": "arraysetops.py", + "nloc": 7, + "complexity": 1, + "token_count": 73, + "parameters": [ + "fig", + "fun", + "nItems", + "dt1s", + "dt2s" + ], + "start_line": 188, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 2 + }, + { + "name": "test_unique1d_speed", + "long_name": "test_unique1d_speed( plotResults = False )", + "filename": "arraysetops.py", + "nloc": 41, + "complexity": 4, + "token_count": 238, + "parameters": [ + "plotResults" + ], + "start_line": 139, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "test_unique1d_speed", + "long_name": "test_unique1d_speed( plotResults = False )", + "filename": "arraysetops.py", + "nloc": 41, + "complexity": 4, + "token_count": 238, + "parameters": [ + "plotResults" + ], + "start_line": 139, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "ediff1d", + "long_name": "ediff1d( ar1 , toEnd = None , toBegin = None )", + "filename": "arraysetops.py", + "nloc": 18, + "complexity": 5, + "token_count": 164, + "parameters": [ + "ar1", + "toEnd", + "toBegin" + ], + "start_line": 37, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "test_unique1d_speed", + "long_name": "test_unique1d_speed( plot_results = False )", + "filename": "arraysetops.py", + "nloc": 41, + "complexity": 4, + "token_count": 238, + "parameters": [ + "plot_results" + ], + "start_line": 139, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "ediff1d", + "long_name": "ediff1d( ar1 , to_end = None , to_begin = None )", + "filename": "arraysetops.py", + "nloc": 18, + "complexity": 5, + "token_count": 164, + "parameters": [ + "ar1", + "to_end", + "to_begin" + ], + "start_line": 37, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "setxor1d", + "long_name": "setxor1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 5, + "complexity": 1, + "token_count": 60, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 94, + "end_line": 99, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "unique1d", + "long_name": "unique1d( ar1 , retindx = False )", + "filename": "arraysetops.py", + "nloc": 10, + "complexity": 2, + "token_count": 97, + "parameters": [ + "ar1", + "retindx" + ], + "start_line": 62, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "unique1d", + "long_name": "unique1d( ar1 , retIndx = False )", + "filename": "arraysetops.py", + "nloc": 10, + "complexity": 2, + "token_count": 97, + "parameters": [ + "ar1", + "retIndx" + ], + "start_line": 62, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + } + ], + "nloc": 138, + "complexity": 18, + "token_count": 969, + "diff_parsed": { + "added": [ + "def ediff1d( ar1, to_end = None, to_begin = None ):", + " if to_end and to_begin:", + " ed[0], ed[-1] = to_begin, to_end", + " elif to_end:", + " ed[-1] = to_end", + " elif to_begin:", + " ed[0] = to_begin", + "def unique1d( ar1, retindx = False ):", + " \"\"\"Unique elements of 1D array. When ret_indx is True, return also the", + " indices indx such that ar1.flat[indx] is the resulting array of unique", + " if retindx:", + " flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0", + "def test_unique1d_speed( plot_results = False ):", + " if plot_results:", + " test_unique1d_speed( plot_results = True )" + ], + "deleted": [ + "def ediff1d( ar1, toEnd = None, toBegin = None ):", + " if toEnd and toBegin:", + " ed[0], ed[-1] = toBegin, toEnd", + " elif toEnd:", + " ed[-1] = toEnd", + " elif toBegin:", + " ed[0] = toBegin", + "def unique1d( ar1, retIndx = False ):", + " \"\"\"Unique elements of 1D array. When retIndx is True, return also the", + " indices indx such that ar1[indx] is the resulting array of unique", + " if retIndx:", + " flag = ediff1d( aux, toEnd = 1, toBegin = 1 ) == 0", + "def test_unique1d_speed( plotResults = False ):", + " if plotResults:", + " test_unique1d_speed( plotResults = True )" + ] + } + } + ] + }, + { + "hash": "a13aad3ac33b629f3e696b4d4d5dbf4b5605d567", + "msg": "Add support for generators in NumPy sum", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-11T08:38:19+00:00", + "author_timezone": 0, + "committer_date": "2006-01-11T08:38:19+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "9a1d729679a1470530014a0ed79bbd7b42fecfa6" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 2, + "insertions": 10, + "lines": 12, + "files": 1, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "numpy/core/oldnumeric.py", + "new_path": "numpy/core/oldnumeric.py", + "filename": "oldnumeric.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -24,7 +24,7 @@\n 'compress', 'clip', 'sum', 'product', 'prod', 'sometrue', 'alltrue',\n 'any', 'all', 'cumsum', 'cumproduct', 'cumprod', 'ptp', 'ndim',\n 'rank', 'size', 'around', 'round_', 'mean', 'std', 'var', 'squeeze',\n- 'amax', 'amin','bsum'\n+ 'amax', 'amin',\n ]\n \n import multiarray as mu\n@@ -36,6 +36,12 @@\n import sys\n _dt_ = nt.dtype2char\n \n+import types\n+\n+try:\n+ _gentype = types.GeneratorType\n+except AttributeError:\n+ _gentype = types.NoneType\n #Use this to add a new axis to an array\n #compatibility only\n NewAxis = None\n@@ -49,7 +55,7 @@\n LittleEndian = (sys.byteorder == 'little')\n \n # save away Python sum\n-bsum = sum\n+_sum_ = sum\n \n # backward compatible names from old Precision.py\n \n@@ -341,6 +347,8 @@ def sum(x, axis=0, dtype=None):\n >>> sum([[0, 1], [0, 5]], axis=1)\n array([1, 5])\n \"\"\"\n+ if isinstance(x, _gentype):\n+ return _sum_(x)\n return asarray(x).sum(axis, dtype)\n \n def product (x, axis=0, dtype=None):\n", + "added_lines": 10, + "deleted_lines": 2, + "source_code": "# Compatibility module containing deprecated names\n\n__all__ = ['asarray', 'array', 'concatenate',\n 'NewAxis',\n 'UFuncType', 'UfuncType', 'ArrayType', 'arraytype',\n 'LittleEndian', 'Bool', \n 'Character', 'UnsignedInt8', 'UnsignedInt16', 'UnsignedInt',\n 'UInt8','UInt16','UInt32',\n # UnsignedInt64 and Unsigned128 added below if possible\n # same for Int64 and Int128, Float128, and Complex128\n 'Int8', 'Int16', 'Int32',\n 'Int0', 'Int', 'Float0', 'Float', 'Complex0', 'Complex',\n 'PyObject', 'Float32', 'Float64',\n 'Complex32', 'Complex64',\n 'typecodes', 'sarray', 'arrayrange', 'cross_correlate',\n 'matrixmultiply', 'outerproduct', 'innerproduct',\n # from cPickle\n 'dump', 'dumps',\n # functions that are now methods\n 'take', 'reshape', 'choose', 'repeat', 'put', 'putmask',\n 'swapaxes', 'transpose', 'sort', 'argsort', 'argmax', 'argmin',\n 'searchsorted', 'alen', \n 'resize', 'diagonal', 'trace', 'ravel', 'nonzero', 'shape',\n 'compress', 'clip', 'sum', 'product', 'prod', 'sometrue', 'alltrue',\n 'any', 'all', 'cumsum', 'cumproduct', 'cumprod', 'ptp', 'ndim',\n 'rank', 'size', 'around', 'round_', 'mean', 'std', 'var', 'squeeze',\n 'amax', 'amin',\n ]\n\nimport multiarray as mu\nimport umath as um\nimport numerictypes as nt\nfrom numeric import asarray, array, correlate, outer, concatenate\nfrom umath import sign, absolute, multiply\nimport numeric as _nx\nimport sys\n_dt_ = nt.dtype2char\n\nimport types\n\ntry:\n _gentype = types.GeneratorType\nexcept AttributeError:\n _gentype = types.NoneType\n#Use this to add a new axis to an array\n#compatibility only\nNewAxis = None\n\n#deprecated\nUFuncType = type(um.sin)\nUfuncType = type(um.sin)\nArrayType = mu.ndarray\narraytype = mu.ndarray\n\nLittleEndian = (sys.byteorder == 'little')\n\n# save away Python sum\n_sum_ = sum\n\n# backward compatible names from old Precision.py\n\nCharacter = 'S1'\nUnsignedInt8 = _dt_(nt.uint8)\nUInt8 = UnsignedInt8\nUnsignedInt16 = _dt_(nt.uint16)\nUInt16 = UnsignedInt16\nUnsignedInt32 = _dt_(nt.uint32)\nUInt32 = UnsignedInt32\nUnsignedInt = _dt_(nt.uint)\n\ntry:\n UnsignedInt64 = _dt_(nt.uint64)\nexcept AttributeError:\n pass\nelse:\n UInt64 = UnsignedInt64\n __all__ += ['UnsignedInt64', 'UInt64']\ntry:\n UnsignedInt128 = _dt_(nt.uint128)\nexcept AttributeError:\n pass\nelse:\n UInt128 = UnsignedInt128\n __all__ += ['UnsignedInt128','UInt128']\n\nInt8 = _dt_(nt.int8)\nInt16 = _dt_(nt.int16)\nInt32 = _dt_(nt.int32)\n\ntry:\n Int64 = _dt_(nt.int64)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int64']\n\ntry:\n Int128 = _dt_(nt.int128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int128']\n\nBool = _dt_(bool)\nInt0 = _dt_(int)\nInt = _dt_(int)\nFloat0 = _dt_(float)\nFloat = _dt_(float)\nComplex0 = _dt_(complex)\nComplex = _dt_(complex)\nPyObject = _dt_(nt.object_)\nFloat32 = _dt_(nt.float32)\nFloat64 = _dt_(nt.float64)\n\ntry:\n Float128 = _dt_(nt.float128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Float128']\n\nComplex32 = _dt_(nt.complex64)\nComplex64 = _dt_(nt.complex128)\n\ntry:\n Complex128 = _dt_(nt.complex256)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Complex128']\n\ntypecodes = {'Character':'S1',\n 'Integer':'bhilqp',\n 'UnsignedInteger':'BHILQP',\n 'Float':'fdg',\n 'Complex':'FDG',\n 'AllInteger':'bBhHiIlLqQpP',\n 'AllFloat':'fdgFDG',\n 'All':'?bhilqpBHILQPfdgFDGSUVO'}\n\ndef sarray(a, dtype=None, copy=False):\n return array(a, dtype, copy)\n\n# backward compatibility\narrayrange = mu.arange\ncross_correlate = correlate\n\n# deprecated names\nmatrixmultiply = mu.dot\nouterproduct = outer\ninnerproduct = mu.inner\n\nfrom cPickle import dump, dumps\n\n# functions that are now methods\n\ndef take(a, indices, axis=0):\n a = asarray(a)\n return a.take(indices, axis)\n\ndef reshape(a, newshape):\n \"\"\"Change the shape of a to newshape. Return a new view object.\n \"\"\"\n return asarray(a).reshape(newshape)\n\ndef choose(a, choices):\n a = asarray(a)\n return a.choose(choices)\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n If repeats is an integer, it is interpreted as\n a tuple of length a.shape[axis] containing repeats.\n The argument a can be anything array(a) will accept.\n \"\"\"\n a = array(a, copy=False)\n return a.repeat(repeats, axis)\n\ndef put (a, ind, v):\n \"\"\"put(a, ind, v) results in a[n] = v[n] for all n in ind\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n The routine put is the equivalent of the following (although the loop\n is in C for speed):\n\n ind = array(indices, copy=False)\n v = array(values, copy=False).astype(a, a.dtype)\n for i in ind: a.flat[i] = v[i]\n a must be a contiguous Numeric array.\n \"\"\"\n return a.put(v,ind)\n\ndef putmask (a, mask, v):\n \"\"\"putmask(a, mask, v) results in a = v for all places mask is true.\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n \"\"\"\n return a.putmask(v, mask)\n\ndef swapaxes(a, axis1, axis2):\n \"\"\"swapaxes(a, axis1, axis2) returns array a with axis1 and axis2\n interchanged.\n \"\"\"\n a = array(a, copy=False)\n return a.swapaxes(axis1, axis2)\n\ndef transpose(a, axes=None):\n \"\"\"transpose(a, axes=None) returns array with dimensions permuted\n according to axes. If axes is None (default) returns array with\n dimensions reversed.\n \"\"\"\n a = array(a,copy=False)\n return a.transpose(axes)\n\ndef sort(a, axis=-1):\n \"\"\"sort(a,axis=-1) returns array with elements sorted along given axis.\n \"\"\"\n a = array(a, copy=True)\n a.sort(axis)\n return a\n\ndef argsort(a, axis=-1):\n \"\"\"argsort(a,axis=-1) return the indices into a of the sorted array\n along the given axis, so that take(a,result,axis) is the sorted array.\n \"\"\"\n a = array(a, copy=False)\n return a.argsort(axis)\n\ndef argmax(a, axis=-1):\n \"\"\"argmax(a,axis=-1) returns the indices to the maximum value of the\n 1-D arrays along the given axis.\n \"\"\"\n a = array(a, copy=False)\n return a.argmax(axis)\n\ndef argmin(a, axis=-1):\n \"\"\"argmin(a,axis=-1) returns the indices to the minimum value of the\n 1-D arrays along the given axis.\n \"\"\"\n a = array(a,copy=False)\n return a.argmin(axis)\n\ndef searchsorted(a, v):\n \"\"\"searchsorted(a, v)\n \"\"\"\n a = array(a,copy=False)\n return a.searchsorted(v)\n\ndef resize(a, new_shape):\n \"\"\"resize(a,new_shape) returns a new array with the specified shape.\n The original array's total size can be any size. It\n fills the new array with repeated copies of a.\n\n Note that a.resize(new_shape) will fill array with 0's\n beyond current definition of a.\n \"\"\"\n\n if isinstance(new_shape, (int, nt.integer)):\n new_shape = (new_shape,)\n a = ravel(a)\n Na = len(a)\n if not Na: return mu.zeros(new_shape, a.dtypechar)\n total_size = um.multiply.reduce(new_shape)\n n_copies = int(total_size / Na)\n extra = total_size % Na\n\n if total_size == 0:\n return a[:0]\n\n if extra != 0:\n n_copies = n_copies+1\n extra = Na-extra\n\n a = concatenate( (a,)*n_copies)\n if extra > 0:\n a = a[:-extra]\n\n return reshape(a, new_shape)\n\ndef squeeze(a):\n \"Returns a with any ones from the shape of a removed\"\n return asarray(a).squeeze()\n\ndef diagonal(a, offset=0, axis1=0, axis2=1):\n \"\"\"diagonal(a, offset=0, axis1=0, axis2=1) returns the given diagonals\n defined by the last two dimensions of the array.\n \"\"\"\n return asarray(a).diagonal(offset, axis1, axis2)\n\ndef trace(a, offset=0, axis1=0, axis2=1, dtype=None):\n \"\"\"trace(a,offset=0, axis1=0, axis2=1) returns the sum along diagonals\n (defined by the last two dimenions) of the array.\n \"\"\"\n return asarray(a).trace(offset, axis1, axis2, dtype)\n\ndef ravel(m):\n \"\"\"ravel(m) returns a 1d array corresponding to all the elements of it's\n argument.\n \"\"\"\n return asarray(m).ravel()\n\ndef nonzero(a):\n \"\"\"nonzero(a) returns the indices of the elements of a which are not zero,\n a must be 1d\n \"\"\"\n return asarray(a).nonzero()\n\ndef shape(a):\n \"\"\"shape(a) returns the shape of a (as a function call which\n also works on nested sequences).\n \"\"\"\n return asarray(a).shape\n\ndef compress(condition, m, axis=-1):\n \"\"\"compress(condition, x, axis=-1) = those elements of x corresponding \n to those elements of condition that are \"true\". condition must be the\n same size as the given dimension of x.\"\"\"\n return asarray(m).compress(condition, axis)\n\ndef clip(m, m_min, m_max):\n \"\"\"clip(m, m_min, m_max) = every entry in m that is less than m_min is\n replaced by m_min, and every entry greater than m_max is replaced by\n m_max.\n \"\"\"\n return asarray(m).clip(m_min, m_max)\n\ndef sum(x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis. The optional dtype argument\n is the data type for intermediate calculations.\n\n The default is to upcast (promote) smaller integer types to the\n platform-dependent Int. For example, on 32-bit platforms:\n\n x.dtype default sum() dtype\n ---------------------------------------------------\n bool, Int8, Int16, Int32 Int32\n\n Examples:\n >>> sum([0.5, 1.5])\n 2.0\n >>> sum([0.5, 1.5], dtype=Int32)\n 1\n >>> sum([[0, 1], [0, 5]])\n array([0, 6])\n >>> sum([[0, 1], [0, 5]], axis=1)\n array([1, 5])\n \"\"\"\n if isinstance(x, _gentype):\n return _sum_(x)\n return asarray(x).sum(axis, dtype)\n\ndef product (x, axis=0, dtype=None):\n \"\"\"Product of the array elements over the given axis.\"\"\"\n return asarray(x).prod(axis, dtype)\n\ndef sometrue (x, axis=0):\n \"\"\"Perform a logical_or over the given axis.\"\"\"\n return asarray(x).any(axis)\n\ndef alltrue (x, axis=0):\n \"\"\"Perform a logical_and over the given axis.\"\"\"\n return asarray(x).all(axis)\n\ndef any(x,axis=None):\n \"\"\"Return true if any elements of x are true: sometrue(ravel(x))\n \"\"\"\n return ravel(x).any(axis)\n\ndef all(x,axis=None):\n \"\"\"Return true if all elements of x are true: alltrue(ravel(x))\n \"\"\"\n return ravel(x).all(axis)\n\ndef cumsum (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumsum(axis, dtype)\n\ndef cumproduct (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumprod(axis, dtype)\n\ndef ptp(a, axis=0):\n \"\"\"Return maximum - minimum along the the given dimension\n \"\"\"\n return asarray(a).ptp(axis)\n\ndef amax(a, axis=0):\n \"\"\"Return the maximum of 'a' along dimension axis.\n \"\"\"\n return asarray(a).max(axis)\n\ndef amin(a, axis=0):\n \"\"\"Return the minimum of a along dimension axis.\n \"\"\"\n return asarray(a).min(axis)\n\ndef alen(a):\n \"\"\"Return the length of a Python object interpreted as an array\n \"\"\"\n return len(asarray(a))\n\ndef prod(a, axis=0):\n \"\"\"Return the product of the elements along the given axis\n \"\"\"\n return asarray(a).prod(axis)\n\ndef cumprod(a, axis=0):\n \"\"\"Return the cumulative product of the elments along the given axis\n \"\"\"\n return asarray(a).cumprod(axis)\n\ndef ndim(a):\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef rank (a):\n \"\"\"Get the rank of sequence a (the number of dimensions, not a matrix rank)\n The rank of a scalar is zero.\n \"\"\"\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef size (a, axis=None):\n \"Get the number of elements in sequence a, or along a certain axis.\"\n if axis is None:\n try:\n return a.size\n except AttributeError:\n return asarray(a).size\n else:\n try:\n return a.shape[axis]\n except AttributeError:\n return asarray(a).shape[axis]\n\ndef round_(a, decimals=0):\n \"\"\"Round 'a' to the given number of decimal places. Rounding\n behaviour is equivalent to Python.\n\n Return 'a' if the array is not floating point. Round both the real\n and imaginary parts separately if the array is complex.\n \"\"\"\n a = asarray(a)\n if not issubclass(a.dtype, _nx.inexact):\n return a\n if issubclass(a.dtype, _nx.complexfloating):\n return round_(a.real, decimals) + 1j*round_(a.imag, decimals)\n if decimals is not 0:\n decimals = asarray(decimals)\n s = sign(a)\n if decimals is not 0:\n a = absolute(multiply(a, 10.**decimals))\n else:\n a = absolute(a)\n rem = a-asarray(a).astype(_nx.intp)\n a = _nx.where(_nx.less(rem, 0.5), _nx.floor(a), _nx.ceil(a))\n # convert back\n if decimals is not 0:\n return multiply(a, s/(10.**decimals))\n else:\n return multiply(a, s)\n\naround = round_\n\ndef mean(a, axis=0, dtype=None):\n return asarray(a).mean(axis, dtype)\n\ndef std(a, axis=0, dtype=None):\n return asarray(a).std(axis, dtype)\n\ndef var(a, axis=0, dtype=None):\n return asarray(a).var(axis, dtype)\n", + "source_code_before": "# Compatibility module containing deprecated names\n\n__all__ = ['asarray', 'array', 'concatenate',\n 'NewAxis',\n 'UFuncType', 'UfuncType', 'ArrayType', 'arraytype',\n 'LittleEndian', 'Bool', \n 'Character', 'UnsignedInt8', 'UnsignedInt16', 'UnsignedInt',\n 'UInt8','UInt16','UInt32',\n # UnsignedInt64 and Unsigned128 added below if possible\n # same for Int64 and Int128, Float128, and Complex128\n 'Int8', 'Int16', 'Int32',\n 'Int0', 'Int', 'Float0', 'Float', 'Complex0', 'Complex',\n 'PyObject', 'Float32', 'Float64',\n 'Complex32', 'Complex64',\n 'typecodes', 'sarray', 'arrayrange', 'cross_correlate',\n 'matrixmultiply', 'outerproduct', 'innerproduct',\n # from cPickle\n 'dump', 'dumps',\n # functions that are now methods\n 'take', 'reshape', 'choose', 'repeat', 'put', 'putmask',\n 'swapaxes', 'transpose', 'sort', 'argsort', 'argmax', 'argmin',\n 'searchsorted', 'alen', \n 'resize', 'diagonal', 'trace', 'ravel', 'nonzero', 'shape',\n 'compress', 'clip', 'sum', 'product', 'prod', 'sometrue', 'alltrue',\n 'any', 'all', 'cumsum', 'cumproduct', 'cumprod', 'ptp', 'ndim',\n 'rank', 'size', 'around', 'round_', 'mean', 'std', 'var', 'squeeze',\n 'amax', 'amin','bsum'\n ]\n\nimport multiarray as mu\nimport umath as um\nimport numerictypes as nt\nfrom numeric import asarray, array, correlate, outer, concatenate\nfrom umath import sign, absolute, multiply\nimport numeric as _nx\nimport sys\n_dt_ = nt.dtype2char\n\n#Use this to add a new axis to an array\n#compatibility only\nNewAxis = None\n\n#deprecated\nUFuncType = type(um.sin)\nUfuncType = type(um.sin)\nArrayType = mu.ndarray\narraytype = mu.ndarray\n\nLittleEndian = (sys.byteorder == 'little')\n\n# save away Python sum\nbsum = sum\n\n# backward compatible names from old Precision.py\n\nCharacter = 'S1'\nUnsignedInt8 = _dt_(nt.uint8)\nUInt8 = UnsignedInt8\nUnsignedInt16 = _dt_(nt.uint16)\nUInt16 = UnsignedInt16\nUnsignedInt32 = _dt_(nt.uint32)\nUInt32 = UnsignedInt32\nUnsignedInt = _dt_(nt.uint)\n\ntry:\n UnsignedInt64 = _dt_(nt.uint64)\nexcept AttributeError:\n pass\nelse:\n UInt64 = UnsignedInt64\n __all__ += ['UnsignedInt64', 'UInt64']\ntry:\n UnsignedInt128 = _dt_(nt.uint128)\nexcept AttributeError:\n pass\nelse:\n UInt128 = UnsignedInt128\n __all__ += ['UnsignedInt128','UInt128']\n\nInt8 = _dt_(nt.int8)\nInt16 = _dt_(nt.int16)\nInt32 = _dt_(nt.int32)\n\ntry:\n Int64 = _dt_(nt.int64)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int64']\n\ntry:\n Int128 = _dt_(nt.int128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Int128']\n\nBool = _dt_(bool)\nInt0 = _dt_(int)\nInt = _dt_(int)\nFloat0 = _dt_(float)\nFloat = _dt_(float)\nComplex0 = _dt_(complex)\nComplex = _dt_(complex)\nPyObject = _dt_(nt.object_)\nFloat32 = _dt_(nt.float32)\nFloat64 = _dt_(nt.float64)\n\ntry:\n Float128 = _dt_(nt.float128)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Float128']\n\nComplex32 = _dt_(nt.complex64)\nComplex64 = _dt_(nt.complex128)\n\ntry:\n Complex128 = _dt_(nt.complex256)\nexcept AttributeError:\n pass\nelse:\n __all__ += ['Complex128']\n\ntypecodes = {'Character':'S1',\n 'Integer':'bhilqp',\n 'UnsignedInteger':'BHILQP',\n 'Float':'fdg',\n 'Complex':'FDG',\n 'AllInteger':'bBhHiIlLqQpP',\n 'AllFloat':'fdgFDG',\n 'All':'?bhilqpBHILQPfdgFDGSUVO'}\n\ndef sarray(a, dtype=None, copy=False):\n return array(a, dtype, copy)\n\n# backward compatibility\narrayrange = mu.arange\ncross_correlate = correlate\n\n# deprecated names\nmatrixmultiply = mu.dot\nouterproduct = outer\ninnerproduct = mu.inner\n\nfrom cPickle import dump, dumps\n\n# functions that are now methods\n\ndef take(a, indices, axis=0):\n a = asarray(a)\n return a.take(indices, axis)\n\ndef reshape(a, newshape):\n \"\"\"Change the shape of a to newshape. Return a new view object.\n \"\"\"\n return asarray(a).reshape(newshape)\n\ndef choose(a, choices):\n a = asarray(a)\n return a.choose(choices)\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n If repeats is an integer, it is interpreted as\n a tuple of length a.shape[axis] containing repeats.\n The argument a can be anything array(a) will accept.\n \"\"\"\n a = array(a, copy=False)\n return a.repeat(repeats, axis)\n\ndef put (a, ind, v):\n \"\"\"put(a, ind, v) results in a[n] = v[n] for all n in ind\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n The routine put is the equivalent of the following (although the loop\n is in C for speed):\n\n ind = array(indices, copy=False)\n v = array(values, copy=False).astype(a, a.dtype)\n for i in ind: a.flat[i] = v[i]\n a must be a contiguous Numeric array.\n \"\"\"\n return a.put(v,ind)\n\ndef putmask (a, mask, v):\n \"\"\"putmask(a, mask, v) results in a = v for all places mask is true.\n If v is shorter than mask it will be repeated as necessary.\n In particular v can be a scalar or length 1 array.\n \"\"\"\n return a.putmask(v, mask)\n\ndef swapaxes(a, axis1, axis2):\n \"\"\"swapaxes(a, axis1, axis2) returns array a with axis1 and axis2\n interchanged.\n \"\"\"\n a = array(a, copy=False)\n return a.swapaxes(axis1, axis2)\n\ndef transpose(a, axes=None):\n \"\"\"transpose(a, axes=None) returns array with dimensions permuted\n according to axes. If axes is None (default) returns array with\n dimensions reversed.\n \"\"\"\n a = array(a,copy=False)\n return a.transpose(axes)\n\ndef sort(a, axis=-1):\n \"\"\"sort(a,axis=-1) returns array with elements sorted along given axis.\n \"\"\"\n a = array(a, copy=True)\n a.sort(axis)\n return a\n\ndef argsort(a, axis=-1):\n \"\"\"argsort(a,axis=-1) return the indices into a of the sorted array\n along the given axis, so that take(a,result,axis) is the sorted array.\n \"\"\"\n a = array(a, copy=False)\n return a.argsort(axis)\n\ndef argmax(a, axis=-1):\n \"\"\"argmax(a,axis=-1) returns the indices to the maximum value of the\n 1-D arrays along the given axis.\n \"\"\"\n a = array(a, copy=False)\n return a.argmax(axis)\n\ndef argmin(a, axis=-1):\n \"\"\"argmin(a,axis=-1) returns the indices to the minimum value of the\n 1-D arrays along the given axis.\n \"\"\"\n a = array(a,copy=False)\n return a.argmin(axis)\n\ndef searchsorted(a, v):\n \"\"\"searchsorted(a, v)\n \"\"\"\n a = array(a,copy=False)\n return a.searchsorted(v)\n\ndef resize(a, new_shape):\n \"\"\"resize(a,new_shape) returns a new array with the specified shape.\n The original array's total size can be any size. It\n fills the new array with repeated copies of a.\n\n Note that a.resize(new_shape) will fill array with 0's\n beyond current definition of a.\n \"\"\"\n\n if isinstance(new_shape, (int, nt.integer)):\n new_shape = (new_shape,)\n a = ravel(a)\n Na = len(a)\n if not Na: return mu.zeros(new_shape, a.dtypechar)\n total_size = um.multiply.reduce(new_shape)\n n_copies = int(total_size / Na)\n extra = total_size % Na\n\n if total_size == 0:\n return a[:0]\n\n if extra != 0:\n n_copies = n_copies+1\n extra = Na-extra\n\n a = concatenate( (a,)*n_copies)\n if extra > 0:\n a = a[:-extra]\n\n return reshape(a, new_shape)\n\ndef squeeze(a):\n \"Returns a with any ones from the shape of a removed\"\n return asarray(a).squeeze()\n\ndef diagonal(a, offset=0, axis1=0, axis2=1):\n \"\"\"diagonal(a, offset=0, axis1=0, axis2=1) returns the given diagonals\n defined by the last two dimensions of the array.\n \"\"\"\n return asarray(a).diagonal(offset, axis1, axis2)\n\ndef trace(a, offset=0, axis1=0, axis2=1, dtype=None):\n \"\"\"trace(a,offset=0, axis1=0, axis2=1) returns the sum along diagonals\n (defined by the last two dimenions) of the array.\n \"\"\"\n return asarray(a).trace(offset, axis1, axis2, dtype)\n\ndef ravel(m):\n \"\"\"ravel(m) returns a 1d array corresponding to all the elements of it's\n argument.\n \"\"\"\n return asarray(m).ravel()\n\ndef nonzero(a):\n \"\"\"nonzero(a) returns the indices of the elements of a which are not zero,\n a must be 1d\n \"\"\"\n return asarray(a).nonzero()\n\ndef shape(a):\n \"\"\"shape(a) returns the shape of a (as a function call which\n also works on nested sequences).\n \"\"\"\n return asarray(a).shape\n\ndef compress(condition, m, axis=-1):\n \"\"\"compress(condition, x, axis=-1) = those elements of x corresponding \n to those elements of condition that are \"true\". condition must be the\n same size as the given dimension of x.\"\"\"\n return asarray(m).compress(condition, axis)\n\ndef clip(m, m_min, m_max):\n \"\"\"clip(m, m_min, m_max) = every entry in m that is less than m_min is\n replaced by m_min, and every entry greater than m_max is replaced by\n m_max.\n \"\"\"\n return asarray(m).clip(m_min, m_max)\n\ndef sum(x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis. The optional dtype argument\n is the data type for intermediate calculations.\n\n The default is to upcast (promote) smaller integer types to the\n platform-dependent Int. For example, on 32-bit platforms:\n\n x.dtype default sum() dtype\n ---------------------------------------------------\n bool, Int8, Int16, Int32 Int32\n\n Examples:\n >>> sum([0.5, 1.5])\n 2.0\n >>> sum([0.5, 1.5], dtype=Int32)\n 1\n >>> sum([[0, 1], [0, 5]])\n array([0, 6])\n >>> sum([[0, 1], [0, 5]], axis=1)\n array([1, 5])\n \"\"\"\n return asarray(x).sum(axis, dtype)\n\ndef product (x, axis=0, dtype=None):\n \"\"\"Product of the array elements over the given axis.\"\"\"\n return asarray(x).prod(axis, dtype)\n\ndef sometrue (x, axis=0):\n \"\"\"Perform a logical_or over the given axis.\"\"\"\n return asarray(x).any(axis)\n\ndef alltrue (x, axis=0):\n \"\"\"Perform a logical_and over the given axis.\"\"\"\n return asarray(x).all(axis)\n\ndef any(x,axis=None):\n \"\"\"Return true if any elements of x are true: sometrue(ravel(x))\n \"\"\"\n return ravel(x).any(axis)\n\ndef all(x,axis=None):\n \"\"\"Return true if all elements of x are true: alltrue(ravel(x))\n \"\"\"\n return ravel(x).all(axis)\n\ndef cumsum (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumsum(axis, dtype)\n\ndef cumproduct (x, axis=0, dtype=None):\n \"\"\"Sum the array over the given axis.\"\"\"\n return asarray(x).cumprod(axis, dtype)\n\ndef ptp(a, axis=0):\n \"\"\"Return maximum - minimum along the the given dimension\n \"\"\"\n return asarray(a).ptp(axis)\n\ndef amax(a, axis=0):\n \"\"\"Return the maximum of 'a' along dimension axis.\n \"\"\"\n return asarray(a).max(axis)\n\ndef amin(a, axis=0):\n \"\"\"Return the minimum of a along dimension axis.\n \"\"\"\n return asarray(a).min(axis)\n\ndef alen(a):\n \"\"\"Return the length of a Python object interpreted as an array\n \"\"\"\n return len(asarray(a))\n\ndef prod(a, axis=0):\n \"\"\"Return the product of the elements along the given axis\n \"\"\"\n return asarray(a).prod(axis)\n\ndef cumprod(a, axis=0):\n \"\"\"Return the cumulative product of the elments along the given axis\n \"\"\"\n return asarray(a).cumprod(axis)\n\ndef ndim(a):\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef rank (a):\n \"\"\"Get the rank of sequence a (the number of dimensions, not a matrix rank)\n The rank of a scalar is zero.\n \"\"\"\n try:\n return a.ndim\n except AttributeError:\n return asarray(a).ndim\n\ndef size (a, axis=None):\n \"Get the number of elements in sequence a, or along a certain axis.\"\n if axis is None:\n try:\n return a.size\n except AttributeError:\n return asarray(a).size\n else:\n try:\n return a.shape[axis]\n except AttributeError:\n return asarray(a).shape[axis]\n\ndef round_(a, decimals=0):\n \"\"\"Round 'a' to the given number of decimal places. Rounding\n behaviour is equivalent to Python.\n\n Return 'a' if the array is not floating point. Round both the real\n and imaginary parts separately if the array is complex.\n \"\"\"\n a = asarray(a)\n if not issubclass(a.dtype, _nx.inexact):\n return a\n if issubclass(a.dtype, _nx.complexfloating):\n return round_(a.real, decimals) + 1j*round_(a.imag, decimals)\n if decimals is not 0:\n decimals = asarray(decimals)\n s = sign(a)\n if decimals is not 0:\n a = absolute(multiply(a, 10.**decimals))\n else:\n a = absolute(a)\n rem = a-asarray(a).astype(_nx.intp)\n a = _nx.where(_nx.less(rem, 0.5), _nx.floor(a), _nx.ceil(a))\n # convert back\n if decimals is not 0:\n return multiply(a, s/(10.**decimals))\n else:\n return multiply(a, s)\n\naround = round_\n\ndef mean(a, axis=0, dtype=None):\n return asarray(a).mean(axis, dtype)\n\ndef std(a, axis=0, dtype=None):\n return asarray(a).std(axis, dtype)\n\ndef var(a, axis=0, dtype=None):\n return asarray(a).var(axis, dtype)\n", + "methods": [ + { + "name": "sarray", + "long_name": "sarray( a , dtype = None , copy = False )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "dtype", + "copy" + ], + "start_line": 141, + "end_line": 142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 157, + "end_line": 159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , newshape )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "a", + "newshape" + ], + "start_line": 161, + "end_line": 164, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "choose", + "long_name": "choose( a , choices )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "choices" + ], + "start_line": 166, + "end_line": 168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 170, + "end_line": 179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , ind , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "ind", + "v" + ], + "start_line": 181, + "end_line": 193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "mask", + "v" + ], + "start_line": 195, + "end_line": 200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "swapaxes", + "long_name": "swapaxes( a , axis1 , axis2 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis1", + "axis2" + ], + "start_line": 202, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a", + "axes" + ], + "start_line": 209, + "end_line": 215, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "sort", + "long_name": "sort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis" + ], + "start_line": 217, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 224, + "end_line": 229, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 231, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 238, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "searchsorted", + "long_name": "searchsorted( a , v )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "v" + ], + "start_line": 245, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "oldnumeric.py", + "nloc": 18, + "complexity": 6, + "token_count": 135, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 251, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "squeeze", + "long_name": "squeeze( a )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "a" + ], + "start_line": 282, + "end_line": 284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , offset = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 32, + "parameters": [ + "a", + "offset", + "axis1", + "axis2" + ], + "start_line": 286, + "end_line": 290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "trace", + "long_name": "trace( a , offset = 0 , axis1 = 0 , axis2 = 1 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 38, + "parameters": [ + "a", + "offset", + "axis1", + "axis2", + "dtype" + ], + "start_line": 292, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( m )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "m" + ], + "start_line": 298, + "end_line": 302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "nonzero", + "long_name": "nonzero( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "a" + ], + "start_line": 304, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "a" + ], + "start_line": 310, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , m , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "condition", + "m", + "axis" + ], + "start_line": 316, + "end_line": 320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "clip", + "long_name": "clip( m , m_min , m_max )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "m", + "m_min", + "m_max" + ], + "start_line": 322, + "end_line": 327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "sum", + "long_name": "sum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 2, + "token_count": 39, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 329, + "end_line": 352, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "product", + "long_name": "product( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 354, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "sometrue", + "long_name": "sometrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 358, + "end_line": 360, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "alltrue", + "long_name": "alltrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 362, + "end_line": 364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "any", + "long_name": "any( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 366, + "end_line": 369, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "all", + "long_name": "all( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 371, + "end_line": 374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "cumsum", + "long_name": "cumsum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 376, + "end_line": 378, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cumproduct", + "long_name": "cumproduct( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 380, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "ptp", + "long_name": "ptp( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 384, + "end_line": 387, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "amax", + "long_name": "amax( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 389, + "end_line": 392, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "amin", + "long_name": "amin( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 394, + "end_line": 397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "alen", + "long_name": "alen( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "a" + ], + "start_line": 399, + "end_line": 402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "prod", + "long_name": "prod( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 404, + "end_line": 407, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "cumprod", + "long_name": "cumprod( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 409, + "end_line": 412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ndim", + "long_name": "ndim( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 21, + "parameters": [ + "a" + ], + "start_line": 414, + "end_line": 418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rank", + "long_name": "rank( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "a" + ], + "start_line": 420, + "end_line": 427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( a , axis = None )", + "filename": "oldnumeric.py", + "nloc": 12, + "complexity": 4, + "token_count": 55, + "parameters": [ + "a", + "axis" + ], + "start_line": 429, + "end_line": 440, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "round_", + "long_name": "round_( a , decimals = 0 )", + "filename": "oldnumeric.py", + "nloc": 19, + "complexity": 6, + "token_count": 184, + "parameters": [ + "a", + "decimals" + ], + "start_line": 442, + "end_line": 467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "mean", + "long_name": "mean( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 471, + "end_line": 472, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "std", + "long_name": "std( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 474, + "end_line": 475, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "var", + "long_name": "var( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 477, + "end_line": 478, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "sarray", + "long_name": "sarray( a , dtype = None , copy = False )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "a", + "dtype", + "copy" + ], + "start_line": 135, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 151, + "end_line": 153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , newshape )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "a", + "newshape" + ], + "start_line": 155, + "end_line": 158, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "choose", + "long_name": "choose( a , choices )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "choices" + ], + "start_line": 160, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 164, + "end_line": 173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , ind , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "ind", + "v" + ], + "start_line": 175, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , v )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "a", + "mask", + "v" + ], + "start_line": 189, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "swapaxes", + "long_name": "swapaxes( a , axis1 , axis2 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis1", + "axis2" + ], + "start_line": 196, + "end_line": 201, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "a", + "axes" + ], + "start_line": 203, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "sort", + "long_name": "sort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "a", + "axis" + ], + "start_line": 211, + "end_line": 216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 218, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 225, + "end_line": 230, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( a , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "a", + "axis" + ], + "start_line": 232, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "searchsorted", + "long_name": "searchsorted( a , v )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "v" + ], + "start_line": 239, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "oldnumeric.py", + "nloc": 18, + "complexity": 6, + "token_count": 135, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 245, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "squeeze", + "long_name": "squeeze( a )", + "filename": "oldnumeric.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "a" + ], + "start_line": 276, + "end_line": 278, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , offset = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 32, + "parameters": [ + "a", + "offset", + "axis1", + "axis2" + ], + "start_line": 280, + "end_line": 284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "trace", + "long_name": "trace( a , offset = 0 , axis1 = 0 , axis2 = 1 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 38, + "parameters": [ + "a", + "offset", + "axis1", + "axis2", + "dtype" + ], + "start_line": 286, + "end_line": 290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( m )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "m" + ], + "start_line": 292, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "nonzero", + "long_name": "nonzero( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "a" + ], + "start_line": 298, + "end_line": 302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "a" + ], + "start_line": 304, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , m , axis = - 1 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "condition", + "m", + "axis" + ], + "start_line": 310, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "clip", + "long_name": "clip( m , m_min , m_max )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "m", + "m_min", + "m_max" + ], + "start_line": 316, + "end_line": 321, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "sum", + "long_name": "sum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 323, + "end_line": 344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "product", + "long_name": "product( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 346, + "end_line": 348, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "sometrue", + "long_name": "sometrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 350, + "end_line": 352, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "alltrue", + "long_name": "alltrue( x , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 354, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "any", + "long_name": "any( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 358, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "all", + "long_name": "all( x , axis = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "x", + "axis" + ], + "start_line": 363, + "end_line": 366, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "cumsum", + "long_name": "cumsum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 368, + "end_line": 370, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "cumproduct", + "long_name": "cumproduct( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 372, + "end_line": 374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "ptp", + "long_name": "ptp( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 376, + "end_line": 379, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "amax", + "long_name": "amax( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 381, + "end_line": 384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "amin", + "long_name": "amin( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 386, + "end_line": 389, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "alen", + "long_name": "alen( a )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "a" + ], + "start_line": 391, + "end_line": 394, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "prod", + "long_name": "prod( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 396, + "end_line": 399, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "cumprod", + "long_name": "cumprod( a , axis = 0 )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "a", + "axis" + ], + "start_line": 401, + "end_line": 404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ndim", + "long_name": "ndim( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 21, + "parameters": [ + "a" + ], + "start_line": 406, + "end_line": 410, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "rank", + "long_name": "rank( a )", + "filename": "oldnumeric.py", + "nloc": 5, + "complexity": 2, + "token_count": 22, + "parameters": [ + "a" + ], + "start_line": 412, + "end_line": 419, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( a , axis = None )", + "filename": "oldnumeric.py", + "nloc": 12, + "complexity": 4, + "token_count": 55, + "parameters": [ + "a", + "axis" + ], + "start_line": 421, + "end_line": 432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "round_", + "long_name": "round_( a , decimals = 0 )", + "filename": "oldnumeric.py", + "nloc": 19, + "complexity": 6, + "token_count": 184, + "parameters": [ + "a", + "decimals" + ], + "start_line": 434, + "end_line": 459, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "mean", + "long_name": "mean( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 463, + "end_line": 464, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "std", + "long_name": "std( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 466, + "end_line": 467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "var", + "long_name": "var( a , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 2, + "complexity": 1, + "token_count": 25, + "parameters": [ + "a", + "axis", + "dtype" + ], + "start_line": 469, + "end_line": 470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "sum", + "long_name": "sum( x , axis = 0 , dtype = None )", + "filename": "oldnumeric.py", + "nloc": 4, + "complexity": 2, + "token_count": 39, + "parameters": [ + "x", + "axis", + "dtype" + ], + "start_line": 329, + "end_line": 352, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "nloc": 269, + "complexity": 60, + "token_count": 1995, + "diff_parsed": { + "added": [ + " 'amax', 'amin',", + "import types", + "", + "try:", + " _gentype = types.GeneratorType", + "except AttributeError:", + " _gentype = types.NoneType", + "_sum_ = sum", + " if isinstance(x, _gentype):", + " return _sum_(x)" + ], + "deleted": [ + " 'amax', 'amin','bsum'", + "bsum = sum" + ] + } + } + ] + }, + { + "hash": "7433c36a44abc08281b9a4c69c6a00b3d885545e", + "msg": "Fix arraysetops.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-11T09:34:13+00:00", + "author_timezone": 0, + "committer_date": "2006-01-11T09:34:13+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "a13aad3ac33b629f3e696b4d4d5dbf4b5605d567" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 22, + "insertions": 27, + "lines": 49, + "files": 1, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/lib/arraysetops.py", + "new_path": "numpy/lib/arraysetops.py", + "filename": "arraysetops.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -63,40 +63,43 @@ def unique1d( ar1, retindx = False ):\n \"\"\"Unique elements of 1D array. When ret_indx is True, return also the\n indices indx such that ar1.flat[indx] is the resulting array of unique\n elements.\"\"\"\n- ar = numpy.array( ar1 ).ravel()\n if retindx:\n- perm = numpy.argsort( ar )\n- aux = numpy.take( ar, perm )\n+ ar = numpy.array(ar1).ravel()\n+ perm = ar.argsort()\n+ aux = ar.take(perm)\n flag = ediff1d( aux, 1 ) != 0\n- return numpy.compress( flag, perm ), numpy.compress( flag, aux )\n+ return perm.compress(flag), aux.compress(flag)\n else:\n- aux = numpy.sort( ar )\n- return numpy.compress( ediff1d( aux, 1 ) != 0, aux ) \n+ ar = numpy.array( ar1 ).flatten()\n+ ar.sort()\n+ return ar.compress( ediff1d( ar, 1 ) != 0)\n \n ##\n # 01.11.2005, c\n def intersect1d( ar1, ar2 ):\n \"\"\"Intersection of 1D arrays with unique elements.\"\"\"\n- aux = numpy.sort( numpy.concatenate( (ar1, ar2 ) ) )\n- return numpy.compress( (aux[1:] - aux[:-1]) == 0, aux )\n+ aux = numpy.concatenate((ar1,ar2))\n+ aux.sort()\n+ return aux.compress( (aux[1:] - aux[:-1]) == 0)\n \n ##\n # 01.11.2005, c\n def intersect1d_nu( ar1, ar2 ):\n \"\"\"Intersection of 1D arrays with any elements.\"\"\"\n # Might be faster then unique1d( intersect1d( ar1, ar2 ) )?\n- aux = numpy.sort( numpy.concatenate( (unique1d( ar1 ),\n- unique1d( ar2 )) ) )\n- return numpy.compress( (aux[1:] - aux[:-1]) == 0, aux )\n+ aux = numpy.concatenate((unique1d(ar1), unique1d(ar2)))\n+ aux.sort()\n+ return aux.compress( (aux[1:] - aux[:-1]) == 0)\n \n ##\n # 01.11.2005, c\n def setxor1d( ar1, ar2 ):\n \"\"\"Set exclusive-or of 1D arrays with unique elements.\"\"\"\n- aux = numpy.sort( numpy.concatenate( (ar1, ar2 ) ) )\n+ aux = numpy.concatenate( (ar1, ar2 ) )\n+ aux.sort()\n flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0\n flag2 = ediff1d( flag, 0 ) == 0\n- return numpy.compress( flag2, aux )\n+ return aux.compress( flag2 )\n \n ##\n # 03.11.2005, c\n@@ -104,12 +107,14 @@ def setxor1d( ar1, ar2 ):\n def setmember1d( ar1, ar2 ):\n \"\"\"Return an array of shape of ar1 containing 1 where the elements of\n ar1 are in ar2 and 0 otherwise.\"\"\"\n- ar = numpy.concatenate( (ar1, ar2 ) )\n- tt = numpy.concatenate( (numpy.zeros_like( ar1 ),\n- numpy.zeros_like( ar2 ) + 1) )\n- perm = numpy.argsort( ar )\n- aux = numpy.take( ar, perm )\n- aux2 = numpy.take( tt, perm )\n+ concat = numpy.concatenate\n+ zlike = numpy.zeros_like\n+ ar = concat( (ar1, ar2 ) )\n+ tt = concat( (zlike( ar1 ),\n+ zlike( ar2 ) + 1) )\n+ perm = ar.argsort()\n+ aux = ar.take(perm)\n+ aux2 = tt.take(perm)\n flag = ediff1d( aux, 1 ) == 0\n \n ii = numpy.where( flag * aux2 )\n@@ -117,9 +122,9 @@ def setmember1d( ar1, ar2 ):\n perm[ii+1] = perm[ii]\n perm[ii] = aux\n \n- indx = numpy.argsort( perm )[:len( ar1 )]\n+ indx = perm.argsort()[:len( ar1 )]\n \n- return numpy.take( flag, indx )\n+ return flag.take( indx )\n \n ##\n # 03.11.2005, c\n@@ -132,7 +137,7 @@ def union1d( ar1, ar2 ):\n def setdiff1d( ar1, ar2 ):\n \"\"\"Set difference of 1D arrays with unique elements.\"\"\"\n aux = setmember1d( ar1, ar2 )\n- return numpy.compress( aux == 0, ar1 )\n+ return ar1.compress(aux == 0)\n \n ##\n # 02.11.2005, c\n", + "added_lines": 27, + "deleted_lines": 22, + "source_code": "\"\"\"\nSet operations for 1D numeric arrays based on sort() function.\n\nContains:\n ediff1d,\n unique1d,\n intersect1d,\n intersect1d_nu,\n setxor1d,\n setmember1d,\n union1d,\n setdiff1d\n\nConcerning the speed, test_unique1d_speed() reveals that up to 10000000\nelements unique1d() is about 10 times faster than the standard dictionary-based\nnumpy.unique().\n\nLimitations: Except unique1d, union1d and intersect1d_nu, all functions expect\ninputs with unique elements. Speed could be gained in some operations by an\nimplementaion of sort(), that can provide directly the permutation vectors,\navoiding thus calls to argsort().\n\nTo do: Optionally return indices analogously to unique1d for all functions.\n\nAuthor: Robert Cimrman\n\"\"\"\n__all__ = ['unique1d', 'intersect1d', 'intersect1d_nu', 'setxor1d',\n 'setmember1d', 'union1d', 'setdiff1d']\n\n\n# 02.11.2005, c\nimport time\nimport numpy\n\n##\n# 03.11.2005, c\ndef ediff1d( ar1, to_end = None, to_begin = None ):\n \"\"\"Array difference with prefixed and/or appended value.\"\"\"\n dar1 = ar1[1:] - ar1[:-1]\n if to_end and to_begin:\n shape = (ar1.shape[0] + 1,) + ar1.shape[1:]\n ed = numpy.empty( shape, dtype = ar1.dtype )\n ed[0], ed[-1] = to_begin, to_end\n ed[1:-1] = dar1\n elif to_end:\n ed = numpy.empty( ar1.shape, dtype = ar1.dtype )\n ed[-1] = to_end\n ed[:-1] = dar1\n elif to_begin:\n ed = numpy.empty( ar1.shape, dtype = ar1.dtype )\n ed[0] = to_begin\n ed[1:] = dar1\n else:\n ed = dar1\n\n return ed\n\n\n##\n# 01.11.2005, c\n# 02.11.2005\ndef unique1d( ar1, retindx = False ):\n \"\"\"Unique elements of 1D array. When ret_indx is True, return also the\n indices indx such that ar1.flat[indx] is the resulting array of unique\n elements.\"\"\"\n if retindx:\n ar = numpy.array(ar1).ravel()\n perm = ar.argsort()\n aux = ar.take(perm)\n flag = ediff1d( aux, 1 ) != 0\n return perm.compress(flag), aux.compress(flag)\n else:\n ar = numpy.array( ar1 ).flatten()\n ar.sort()\n return ar.compress( ediff1d( ar, 1 ) != 0)\n\n##\n# 01.11.2005, c\ndef intersect1d( ar1, ar2 ):\n \"\"\"Intersection of 1D arrays with unique elements.\"\"\"\n aux = numpy.concatenate((ar1,ar2))\n aux.sort()\n return aux.compress( (aux[1:] - aux[:-1]) == 0)\n\n##\n# 01.11.2005, c\ndef intersect1d_nu( ar1, ar2 ):\n \"\"\"Intersection of 1D arrays with any elements.\"\"\"\n # Might be faster then unique1d( intersect1d( ar1, ar2 ) )?\n aux = numpy.concatenate((unique1d(ar1), unique1d(ar2)))\n aux.sort()\n return aux.compress( (aux[1:] - aux[:-1]) == 0)\n\n##\n# 01.11.2005, c\ndef setxor1d( ar1, ar2 ):\n \"\"\"Set exclusive-or of 1D arrays with unique elements.\"\"\"\n aux = numpy.concatenate( (ar1, ar2 ) )\n aux.sort()\n flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0\n flag2 = ediff1d( flag, 0 ) == 0\n return aux.compress( flag2 )\n\n##\n# 03.11.2005, c\n# 05.01.2006\ndef setmember1d( ar1, ar2 ):\n \"\"\"Return an array of shape of ar1 containing 1 where the elements of\n ar1 are in ar2 and 0 otherwise.\"\"\"\n concat = numpy.concatenate\n zlike = numpy.zeros_like\n ar = concat( (ar1, ar2 ) )\n tt = concat( (zlike( ar1 ),\n zlike( ar2 ) + 1) )\n perm = ar.argsort()\n aux = ar.take(perm)\n aux2 = tt.take(perm)\n flag = ediff1d( aux, 1 ) == 0\n\n ii = numpy.where( flag * aux2 )\n aux = perm[ii+1]\n perm[ii+1] = perm[ii]\n perm[ii] = aux\n\n indx = perm.argsort()[:len( ar1 )]\n\n return flag.take( indx )\n\n##\n# 03.11.2005, c\ndef union1d( ar1, ar2 ):\n \"\"\"Union of 1D arrays with unique elements.\"\"\"\n return unique1d( numpy.concatenate( (ar1, ar2) ) )\n\n##\n# 03.11.2005, c\ndef setdiff1d( ar1, ar2 ):\n \"\"\"Set difference of 1D arrays with unique elements.\"\"\"\n aux = setmember1d( ar1, ar2 )\n return ar1.compress(aux == 0)\n\n##\n# 02.11.2005, c\ndef test_unique1d_speed( plot_results = False ):\n# exponents = numpy.linspace( 2, 7, 9 )\n exponents = numpy.linspace( 2, 6, 9 )\n ratios = []\n nItems = []\n dt1s = []\n dt2s = []\n for ii in exponents:\n\n nItem = 10 ** ii\n print 'using %d items:' % nItem\n a = numpy.fix( nItem / 10 * numpy.random.random( nItem ) )\n\n print 'dictionary:'\n tt = time.clock() \n b = numpy.unique( a )\n dt1 = time.clock() - tt\n print dt1\n\n print 'array:'\n tt = time.clock() \n c = unique1d( a )\n dt2 = time.clock() - tt\n print dt2\n\n\n if dt1 < 1e-8:\n ratio = 'ND'\n else:\n ratio = dt2 / dt1\n print 'ratio:', ratio\n print 'nUnique: %d == %d\\n' % (len( b ), len( c ))\n\n nItems.append( nItem )\n ratios.append( ratio )\n dt1s.append( dt1 )\n dt2s.append( dt2 )\n\n assert numpy.alltrue( b == c )\n\n\n print nItems\n print dt1s\n print dt2s\n print ratios\n\n if plot_results:\n import pylab\n\n def plotMe( fig, fun, nItems, dt1s, dt2s ):\n pylab.figure( fig )\n fun( nItems, dt1s, 'g-o', linewidth = 2, markersize = 8 )\n fun( nItems, dt2s, 'b-x', linewidth = 2, markersize = 8 )\n pylab.legend( ('dictionary', 'array' ) )\n pylab.xlabel( 'nItem' )\n pylab.ylabel( 'time [s]' )\n\n plotMe( 1, pylab.loglog, nItems, dt1s, dt2s )\n plotMe( 2, pylab.plot, nItems, dt1s, dt2s )\n pylab.show()\n\nif (__name__ == '__main__'):\n test_unique1d_speed( plot_results = True )\n", + "source_code_before": "\"\"\"\nSet operations for 1D numeric arrays based on sort() function.\n\nContains:\n ediff1d,\n unique1d,\n intersect1d,\n intersect1d_nu,\n setxor1d,\n setmember1d,\n union1d,\n setdiff1d\n\nConcerning the speed, test_unique1d_speed() reveals that up to 10000000\nelements unique1d() is about 10 times faster than the standard dictionary-based\nnumpy.unique().\n\nLimitations: Except unique1d, union1d and intersect1d_nu, all functions expect\ninputs with unique elements. Speed could be gained in some operations by an\nimplementaion of sort(), that can provide directly the permutation vectors,\navoiding thus calls to argsort().\n\nTo do: Optionally return indices analogously to unique1d for all functions.\n\nAuthor: Robert Cimrman\n\"\"\"\n__all__ = ['unique1d', 'intersect1d', 'intersect1d_nu', 'setxor1d',\n 'setmember1d', 'union1d', 'setdiff1d']\n\n\n# 02.11.2005, c\nimport time\nimport numpy\n\n##\n# 03.11.2005, c\ndef ediff1d( ar1, to_end = None, to_begin = None ):\n \"\"\"Array difference with prefixed and/or appended value.\"\"\"\n dar1 = ar1[1:] - ar1[:-1]\n if to_end and to_begin:\n shape = (ar1.shape[0] + 1,) + ar1.shape[1:]\n ed = numpy.empty( shape, dtype = ar1.dtype )\n ed[0], ed[-1] = to_begin, to_end\n ed[1:-1] = dar1\n elif to_end:\n ed = numpy.empty( ar1.shape, dtype = ar1.dtype )\n ed[-1] = to_end\n ed[:-1] = dar1\n elif to_begin:\n ed = numpy.empty( ar1.shape, dtype = ar1.dtype )\n ed[0] = to_begin\n ed[1:] = dar1\n else:\n ed = dar1\n\n return ed\n\n\n##\n# 01.11.2005, c\n# 02.11.2005\ndef unique1d( ar1, retindx = False ):\n \"\"\"Unique elements of 1D array. When ret_indx is True, return also the\n indices indx such that ar1.flat[indx] is the resulting array of unique\n elements.\"\"\"\n ar = numpy.array( ar1 ).ravel()\n if retindx:\n perm = numpy.argsort( ar )\n aux = numpy.take( ar, perm )\n flag = ediff1d( aux, 1 ) != 0\n return numpy.compress( flag, perm ), numpy.compress( flag, aux )\n else:\n aux = numpy.sort( ar )\n return numpy.compress( ediff1d( aux, 1 ) != 0, aux ) \n\n##\n# 01.11.2005, c\ndef intersect1d( ar1, ar2 ):\n \"\"\"Intersection of 1D arrays with unique elements.\"\"\"\n aux = numpy.sort( numpy.concatenate( (ar1, ar2 ) ) )\n return numpy.compress( (aux[1:] - aux[:-1]) == 0, aux )\n\n##\n# 01.11.2005, c\ndef intersect1d_nu( ar1, ar2 ):\n \"\"\"Intersection of 1D arrays with any elements.\"\"\"\n # Might be faster then unique1d( intersect1d( ar1, ar2 ) )?\n aux = numpy.sort( numpy.concatenate( (unique1d( ar1 ),\n unique1d( ar2 )) ) )\n return numpy.compress( (aux[1:] - aux[:-1]) == 0, aux )\n\n##\n# 01.11.2005, c\ndef setxor1d( ar1, ar2 ):\n \"\"\"Set exclusive-or of 1D arrays with unique elements.\"\"\"\n aux = numpy.sort( numpy.concatenate( (ar1, ar2 ) ) )\n flag = ediff1d( aux, to_end = 1, to_begin = 1 ) == 0\n flag2 = ediff1d( flag, 0 ) == 0\n return numpy.compress( flag2, aux )\n\n##\n# 03.11.2005, c\n# 05.01.2006\ndef setmember1d( ar1, ar2 ):\n \"\"\"Return an array of shape of ar1 containing 1 where the elements of\n ar1 are in ar2 and 0 otherwise.\"\"\"\n ar = numpy.concatenate( (ar1, ar2 ) )\n tt = numpy.concatenate( (numpy.zeros_like( ar1 ),\n numpy.zeros_like( ar2 ) + 1) )\n perm = numpy.argsort( ar )\n aux = numpy.take( ar, perm )\n aux2 = numpy.take( tt, perm )\n flag = ediff1d( aux, 1 ) == 0\n\n ii = numpy.where( flag * aux2 )\n aux = perm[ii+1]\n perm[ii+1] = perm[ii]\n perm[ii] = aux\n\n indx = numpy.argsort( perm )[:len( ar1 )]\n\n return numpy.take( flag, indx )\n\n##\n# 03.11.2005, c\ndef union1d( ar1, ar2 ):\n \"\"\"Union of 1D arrays with unique elements.\"\"\"\n return unique1d( numpy.concatenate( (ar1, ar2) ) )\n\n##\n# 03.11.2005, c\ndef setdiff1d( ar1, ar2 ):\n \"\"\"Set difference of 1D arrays with unique elements.\"\"\"\n aux = setmember1d( ar1, ar2 )\n return numpy.compress( aux == 0, ar1 )\n\n##\n# 02.11.2005, c\ndef test_unique1d_speed( plot_results = False ):\n# exponents = numpy.linspace( 2, 7, 9 )\n exponents = numpy.linspace( 2, 6, 9 )\n ratios = []\n nItems = []\n dt1s = []\n dt2s = []\n for ii in exponents:\n\n nItem = 10 ** ii\n print 'using %d items:' % nItem\n a = numpy.fix( nItem / 10 * numpy.random.random( nItem ) )\n\n print 'dictionary:'\n tt = time.clock() \n b = numpy.unique( a )\n dt1 = time.clock() - tt\n print dt1\n\n print 'array:'\n tt = time.clock() \n c = unique1d( a )\n dt2 = time.clock() - tt\n print dt2\n\n\n if dt1 < 1e-8:\n ratio = 'ND'\n else:\n ratio = dt2 / dt1\n print 'ratio:', ratio\n print 'nUnique: %d == %d\\n' % (len( b ), len( c ))\n\n nItems.append( nItem )\n ratios.append( ratio )\n dt1s.append( dt1 )\n dt2s.append( dt2 )\n\n assert numpy.alltrue( b == c )\n\n\n print nItems\n print dt1s\n print dt2s\n print ratios\n\n if plot_results:\n import pylab\n\n def plotMe( fig, fun, nItems, dt1s, dt2s ):\n pylab.figure( fig )\n fun( nItems, dt1s, 'g-o', linewidth = 2, markersize = 8 )\n fun( nItems, dt2s, 'b-x', linewidth = 2, markersize = 8 )\n pylab.legend( ('dictionary', 'array' ) )\n pylab.xlabel( 'nItem' )\n pylab.ylabel( 'time [s]' )\n\n plotMe( 1, pylab.loglog, nItems, dt1s, dt2s )\n plotMe( 2, pylab.plot, nItems, dt1s, dt2s )\n pylab.show()\n\nif (__name__ == '__main__'):\n test_unique1d_speed( plot_results = True )\n", + "methods": [ + { + "name": "ediff1d", + "long_name": "ediff1d( ar1 , to_end = None , to_begin = None )", + "filename": "arraysetops.py", + "nloc": 18, + "complexity": 5, + "token_count": 164, + "parameters": [ + "ar1", + "to_end", + "to_begin" + ], + "start_line": 37, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "unique1d", + "long_name": "unique1d( ar1 , retindx = False )", + "filename": "arraysetops.py", + "nloc": 11, + "complexity": 2, + "token_count": 97, + "parameters": [ + "ar1", + "retindx" + ], + "start_line": 62, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "intersect1d", + "long_name": "intersect1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 4, + "complexity": 1, + "token_count": 47, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 79, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "intersect1d_nu", + "long_name": "intersect1d_nu( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 4, + "complexity": 1, + "token_count": 53, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 87, + "end_line": 92, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "setxor1d", + "long_name": "setxor1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 6, + "complexity": 1, + "token_count": 58, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 96, + "end_line": 102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "setmember1d", + "long_name": "setmember1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 16, + "complexity": 1, + "token_count": 135, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 107, + "end_line": 127, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "union1d", + "long_name": "union1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 131, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "setdiff1d", + "long_name": "setdiff1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 137, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "test_unique1d_speed.plotMe", + "long_name": "test_unique1d_speed.plotMe( fig , fun , nItems , dt1s , dt2s )", + "filename": "arraysetops.py", + "nloc": 7, + "complexity": 1, + "token_count": 73, + "parameters": [ + "fig", + "fun", + "nItems", + "dt1s", + "dt2s" + ], + "start_line": 193, + "end_line": 199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 2 + }, + { + "name": "test_unique1d_speed", + "long_name": "test_unique1d_speed( plot_results = False )", + "filename": "arraysetops.py", + "nloc": 41, + "complexity": 4, + "token_count": 238, + "parameters": [ + "plot_results" + ], + "start_line": 144, + "end_line": 203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "ediff1d", + "long_name": "ediff1d( ar1 , to_end = None , to_begin = None )", + "filename": "arraysetops.py", + "nloc": 18, + "complexity": 5, + "token_count": 164, + "parameters": [ + "ar1", + "to_end", + "to_begin" + ], + "start_line": 37, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "unique1d", + "long_name": "unique1d( ar1 , retindx = False )", + "filename": "arraysetops.py", + "nloc": 10, + "complexity": 2, + "token_count": 97, + "parameters": [ + "ar1", + "retindx" + ], + "start_line": 62, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "intersect1d", + "long_name": "intersect1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 3, + "complexity": 1, + "token_count": 49, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 78, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "intersect1d_nu", + "long_name": "intersect1d_nu( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 4, + "complexity": 1, + "token_count": 55, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 85, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "setxor1d", + "long_name": "setxor1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 5, + "complexity": 1, + "token_count": 60, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 94, + "end_line": 99, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "setmember1d", + "long_name": "setmember1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 14, + "complexity": 1, + "token_count": 141, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 104, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "union1d", + "long_name": "union1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 126, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "setdiff1d", + "long_name": "setdiff1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 132, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "test_unique1d_speed.plotMe", + "long_name": "test_unique1d_speed.plotMe( fig , fun , nItems , dt1s , dt2s )", + "filename": "arraysetops.py", + "nloc": 7, + "complexity": 1, + "token_count": 73, + "parameters": [ + "fig", + "fun", + "nItems", + "dt1s", + "dt2s" + ], + "start_line": 188, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 2 + }, + { + "name": "test_unique1d_speed", + "long_name": "test_unique1d_speed( plot_results = False )", + "filename": "arraysetops.py", + "nloc": 41, + "complexity": 4, + "token_count": 238, + "parameters": [ + "plot_results" + ], + "start_line": 139, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "setmember1d", + "long_name": "setmember1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 16, + "complexity": 1, + "token_count": 135, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 107, + "end_line": 127, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "intersect1d", + "long_name": "intersect1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 4, + "complexity": 1, + "token_count": 47, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 79, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "setdiff1d", + "long_name": "setdiff1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 137, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "intersect1d_nu", + "long_name": "intersect1d_nu( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 4, + "complexity": 1, + "token_count": 53, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 87, + "end_line": 92, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "setxor1d", + "long_name": "setxor1d( ar1 , ar2 )", + "filename": "arraysetops.py", + "nloc": 6, + "complexity": 1, + "token_count": 58, + "parameters": [ + "ar1", + "ar2" + ], + "start_line": 96, + "end_line": 102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "unique1d", + "long_name": "unique1d( ar1 , retindx = False )", + "filename": "arraysetops.py", + "nloc": 11, + "complexity": 2, + "token_count": 97, + "parameters": [ + "ar1", + "retindx" + ], + "start_line": 62, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + } + ], + "nloc": 143, + "complexity": 18, + "token_count": 955, + "diff_parsed": { + "added": [ + " ar = numpy.array(ar1).ravel()", + " perm = ar.argsort()", + " aux = ar.take(perm)", + " return perm.compress(flag), aux.compress(flag)", + " ar = numpy.array( ar1 ).flatten()", + " ar.sort()", + " return ar.compress( ediff1d( ar, 1 ) != 0)", + " aux = numpy.concatenate((ar1,ar2))", + " aux.sort()", + " return aux.compress( (aux[1:] - aux[:-1]) == 0)", + " aux = numpy.concatenate((unique1d(ar1), unique1d(ar2)))", + " aux.sort()", + " return aux.compress( (aux[1:] - aux[:-1]) == 0)", + " aux = numpy.concatenate( (ar1, ar2 ) )", + " aux.sort()", + " return aux.compress( flag2 )", + " concat = numpy.concatenate", + " zlike = numpy.zeros_like", + " ar = concat( (ar1, ar2 ) )", + " tt = concat( (zlike( ar1 ),", + " zlike( ar2 ) + 1) )", + " perm = ar.argsort()", + " aux = ar.take(perm)", + " aux2 = tt.take(perm)", + " indx = perm.argsort()[:len( ar1 )]", + " return flag.take( indx )", + " return ar1.compress(aux == 0)" + ], + "deleted": [ + " ar = numpy.array( ar1 ).ravel()", + " perm = numpy.argsort( ar )", + " aux = numpy.take( ar, perm )", + " return numpy.compress( flag, perm ), numpy.compress( flag, aux )", + " aux = numpy.sort( ar )", + " return numpy.compress( ediff1d( aux, 1 ) != 0, aux )", + " aux = numpy.sort( numpy.concatenate( (ar1, ar2 ) ) )", + " return numpy.compress( (aux[1:] - aux[:-1]) == 0, aux )", + " aux = numpy.sort( numpy.concatenate( (unique1d( ar1 ),", + " unique1d( ar2 )) ) )", + " return numpy.compress( (aux[1:] - aux[:-1]) == 0, aux )", + " aux = numpy.sort( numpy.concatenate( (ar1, ar2 ) ) )", + " return numpy.compress( flag2, aux )", + " ar = numpy.concatenate( (ar1, ar2 ) )", + " tt = numpy.concatenate( (numpy.zeros_like( ar1 ),", + " numpy.zeros_like( ar2 ) + 1) )", + " perm = numpy.argsort( ar )", + " aux = numpy.take( ar, perm )", + " aux2 = numpy.take( tt, perm )", + " indx = numpy.argsort( perm )[:len( ar1 )]", + " return numpy.take( flag, indx )", + " return numpy.compress( aux == 0, ar1 )" + ] + } + } + ] + }, + { + "hash": "fec83ff625de7f0481fb82717b3e599093507b4f", + "msg": "Don't return Object Array Scalars.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-11T09:35:51+00:00", + "author_timezone": 0, + "committer_date": "2006-01-11T09:35:51+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "7433c36a44abc08281b9a4c69c6a00b3d885545e" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 2, + "insertions": 1, + "lines": 3, + "files": 1, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 1.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": "@@ -809,8 +809,7 @@ PyArray_Scalar(void *data, PyArray_Descr *descr, PyObject *base)\n \tint swap;\n \n \ttype_num = descr->type_num;\n-\tif ((type_num == PyArray_OBJECT) &&\t\t\\\n-\t (PyArray_Check((*((PyObject **)data))))) {\n+\tif ((type_num == PyArray_OBJECT)) {\n \t\tPy_INCREF(*((PyObject **)data));\n \t\treturn *((PyObject **)data);\n \t}\n", + "added_lines": 1, + "deleted_lines": 2, + "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\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\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=NULL;\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\tdescr = PyArray_DescrFromType(PyArray_INTP);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else 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} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\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=NULL;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\tdescr = PyArray_DescrFromType(PyArray_INT);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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} else 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) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\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\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 if (PyBigArray_CheckExact(obj)) \n return PyArray_BIG_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\t\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\t\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\t\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\t\n dest_strides_ptr = dest_strides;\n\t\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\t\n new_data = (char *)_pya_malloc(stride);\n\t\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\t\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\t\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\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\nstatic PyArray_Descr **userdescrs=NULL;\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\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\t\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\n/* If destination is not the right type, then src \n will be cast to destination. \n*/\n\n/* Does a flat iterator-based copy. \n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however. \n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n \n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError, \n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->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, elsize);\n PyArray_INCREF(dest);\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 memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\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\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t dest->descr, 0,\n\t\t\t\t\t dest->nd, FORTRAN_IF(dest));\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\t\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/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\t\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\t\n return (PyObject *)ret;\t\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_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 (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}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize / sizeof(Py_UNICODE);\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\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, itemsize);\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/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\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\t\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\t\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 fwrite(sep, 1, n3, fp);\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\t\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\t\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\t\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\t\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\t\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\t\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \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\t\t\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\t\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\nstatic PyObject *\narray_item_nice(PyArrayObject *self, int i) \n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\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\t\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 SIZEOF_INT == SIZEOF_INTP\n#define array_ass_item array_ass_big_item\n#else\nstatic int\narray_ass_item(PyArrayObject *self, int 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\t\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\t\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\t\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\t\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\t\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\t\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\t\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);\t\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\t\n nd_old = nd_new = 0;\n\t\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\t\t\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 }\t \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\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\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);\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->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\t\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);\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}\n\t}\n\t\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, PyArray_ITEMSIZE(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}\t\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\t\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/* 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;\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\t\t\t\t\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\t\t\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\treturn PyArray_ToScalar(self->data, self);\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\treturn PyArray_ToScalar(self->data, self);\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n\t/* wrap arguments into a mapiter object */\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(op, oned);\n if (mit == NULL) return NULL;\n if (!mit->view) { /* fancy indexing */\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 Py_DECREF(mit);\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\t\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\t\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;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\t\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\t\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\t\t\t\t\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\t\t\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(index, oned);\n if (mit == NULL) return -1;\n if (!mit->view) {\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 Py_DECREF(mit);\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\t\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\treturn PyArray_Return((PyArrayObject *)array_subscript(self, op));\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n (inquiry)array_length,\t\t /*mp_length*/\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 \narray_getsegcount(PyArrayObject *self, int *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 \narray_getreadbuf(PyArrayObject *self, int 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 \narray_getwritebuf(PyArrayObject *self, int 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 \narray_getcharbuf(PyArrayObject *self, int 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 (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};\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\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;\t\n\t\n} NumericOps;\n\nstatic NumericOps n_ops = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL};\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\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);\t \n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\t\n SET(true_divide);\t\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\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;\t\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\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);\t \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\treturn dict;\t\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\t\t\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}\t\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}\t\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 *\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 PyObject *\narray_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.power);\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 *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.power);\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\t\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;\t \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 an \"\\\n\t\t\t\t\"int; 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;\t \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;\t \n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v) \n{\t \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;\t \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;\t \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*/\t\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 ilow, int ihigh) \n{\n PyArrayObject *r;\n int l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n \t\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\n self->dimensions[0] = l;\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 ilow, int ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\t\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\t\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\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, 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\n\nstatic PySequenceMethods array_as_sequence = {\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};\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\t\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\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\t\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\t\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\t\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\t\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\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\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 return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\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.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\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\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\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; ind == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tintp sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\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\t\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;\t\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by a single segment array of the provided \n dimensions and element size. If numbytes is 0 it will be calculated from \n the provided shape and element size.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\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;\t\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 */\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, \n\t\t\t intp *newstrides, int oldnd)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\t\n\told = *des;\n\t*des = old->subarray->base;\n\n\tmydim = newdims + oldnd;\n\tif (PyTuple_Check(old->subarray->shape)) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t\t\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tnumnew = 1;\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\t\n\tnewnd = oldnd + numnew;\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\t/* Make new strides */\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\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{\t\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\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);\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\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\t\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { /* strides is NULL too */\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\t\t\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\t\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 {\n\t\t\tif (data == NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"if 'strides' is given in \" \\\n\t\t\t\t\t\t\"array creation, data must \" \\\n\t\t\t\t\t\t\"be given too\");\n\t\t\t\tgoto fail;\n\t\t\t} \n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t} \t\n\t\t\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\t\tif (descr == &OBJECT_Descr) {\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 and some object passed in */\n\tif ((obj != NULL) && (subtype != &PyArray_Type) && \n\t (subtype != &PyBigArray_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 (!(self->flags & OWNDATA)) { /* did not allocate own data */\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\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\t\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*/\nstatic PyObject * \nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape)\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\t\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n \"resize only works on contiguous arrays\");\n return NULL;\n }\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\t\t\n\t\trefcnt = REFCOUNT(self);\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\t\t\t\t\n\t\tif (newsize == 0) sd = self->descr->elsize;\t\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 0, &(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);\t\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);\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\twhile (size--) {\n\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\ttoptr += itemsize;\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\t\t\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, itemsize);\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\", \n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", 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\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*/\t\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\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 &fortran)) \n\t\tgoto fail;\n\t\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\t\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\\\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 NULL, 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\t\tbuffer.len -= offset;\n\t\tbuffer.ptr += offset;\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\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 (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\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 (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 PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\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\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\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;\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 != NULL) {\n\t\tif (PyArray_Check(new->base)) \n\t\t\tnew = (PyArrayObject *)new->base;\n\t}\n\tnumbytes = PyArray_MultiplyList(new->dimensions, \n\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes, \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 if (PyBigArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_BIG_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}\t\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 *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISEXTENDED(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->descr->elsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\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 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\t\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\t\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\t\n\telse if (newtype->elsize > self->descr->elsize) {\n\t\t\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\t\t\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\t\t\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\ttemp = (PyArrayObject *)\\\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\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tPy_DECREF(newtype);\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator */\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\ttemp->descr = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype; \n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\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\t\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"arrdescr\");\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_type_get(PyArrayObject *self)\n{\n Py_INCREF(self->descr->typeobj);\n return (PyObject *)self->descr->typeobj;\n}\n\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);\n\tif (new == NULL) return -1;\n\t\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) {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}\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{\t\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{\t\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); \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);\t\t\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));\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->descr->elsize);\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 {\"dtype\", \n\t (getter)array_type_get, \n\t NULL,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n\t{\"dtypedescr\", \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.dtypedescr object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\t\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.bigndarray\",\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 NULL, \t\t\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\t\t\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n NULL, \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/* A standard array will subclass from the Big Array and \n add the array_as_sequence table\n and the array_as_buffer table\n */\n\nstatic PyTypeObject PyArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n};\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\t\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;\t\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\t\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, sizeof(Py_UNICODE)*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\t\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, 2*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\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\t\n\tif (minitype == NULL) \n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\t\n if (max < 0) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\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 \t\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\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\t\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\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_BOOL);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_LONG);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_DOUBLE);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_CDOUBLE);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\n finish:\n\t\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\t\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\t\n l=PyObject_Length(v);\n if(l < 0) return -1; \n\t\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\t\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 *= sizeof(Py_UNICODE);\n\t}\n\n\tret = (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\n\tif (ret == NULL) return NULL;\n\n ret->descr->f->setitem(op, ret->data, ret);\n\t\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 unless return value is NULL*/\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\tPyArray_Descr *savetype=typecode;\n\t\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\t\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 return NULL;\n }\n\t\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 return NULL;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\treturn NULL;\n\t\t}\n\t\tif (type == PyArray_UNICODE) itemsize*=sizeof(Py_UNICODE);\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\t\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\t\n if(!r) {Py_XINCREF(savetype); return NULL;}\n if(Assign_Array(r,s) == -1) {\n\t\tPy_XINCREF(savetype);\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\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\t\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\t\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\t\t\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\t\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\t\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, elsize);\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\t\t\t\t\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\t\t\t\t\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 oelsize);\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);\t\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\t\t\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*sizeof(Py_UNICODE);\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize/sizeof(Py_UNICODE);\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\t\n\tPy_DECREF(out);\n\treturn NULL;\n\t\n}\n\t \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\t\t\t\t\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * outsize;\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\t\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 */\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) \n{\n\t\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\t\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 (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\t\t\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 != &PyBigArray_Type)) {\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 (subtype != &PyBigArray_Type)) {\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\t\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 != &PyBigArray_Type)) {\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\t\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}\t\t\n\t\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;\t \n\t\telse _MY_FAIL \n\t\t\tbreak;\t\t \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;\t\t \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;\t\t \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\t\tbreak;\n\tcase 'S':\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase 'U':\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize *= sizeof(Py_UNICODE);\n\t\tbreak;\t \n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\t\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/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_fromstructinterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r, *ret;\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_XDECREF(intype);\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_XDECREF(intype);\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 ret = array_fromarray((PyArrayObject*)r, intype, flags);\n Py_DECREF(r);\n return ret;\n}\n\n/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n PyObject *tstr=NULL, *shape=NULL; \n\tPyArrayObject *ret=NULL;\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\t\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\tPy_XDECREF(intype);\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\tPy_XDECREF(intype);\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\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n\n fail:\n\tPy_XDECREF(intype);\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* steals a reference to typecode */\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Descr *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode == NULL) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyObject *obj;\n\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", typecode->type,\n\t\t\t\t\t\t typecode->elsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(typecode->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\n if (new == NULL) {Py_XDECREF(typecode); 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\t\tPy_DECREF(typecode);\n return NULL;\n }\n r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n/* Steals a reference to newtype --- which can be NULL */\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Descr *newtype, int min_depth, \n\t\t int max_depth, int flags) \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 = array_fromarray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if ((r = array_fromstructinterface(op, newtype, flags)) != \\\n\t\t Py_NotImplemented) {\n }\n else if ((r = array_frominterface(op, newtype, flags)) !=\t\\\n\t\t Py_NotImplemented) {\n\t}\n else if (PyObject_HasAttrString(op, \"__array__\")) {\n /* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, newtype, flags);\n }\n\telse {\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\t\t\t\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 PyErr_Clear();\n else\n seq = TRUE;\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\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\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\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_FromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n\t\tint max_depth, int requires) \n{\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\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 array_fromobject(op, descr, min_depth, max_depth,\n \t\t\t\trequires);\t\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 or PyBigArray_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) || PyBigArray_CheckExact(op)) return op;\n \n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FROM_OF(op, ENSUREARRAY);\n Py_DECREF(op);\n return new;\n}\n\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 * sizeof(Py_UNICODE)\\\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.\t\t \n\t\t*/\n\t}\n\treturn ret;\n}\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\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\t\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\t\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\t\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/* 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\niter_length(PyArrayIterObject *self) \n{\n return (int) 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, itemsize);\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\t\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, itemsize);\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;\t\t\t\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */ \t\n\t\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, size);\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);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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\t\t\t\t\t FORCECAST | ALIGNED);\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,\n\t\t\t\t itemsize);\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, itemsize);\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, itemsize);\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\t\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\t\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0);\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, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\t\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, itemsize);\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, itemsize);\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);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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_FromAny(obj, indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\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\t\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n (inquiry)iter_length,\t\t /*mp_length*/\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;\t\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\t{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 0, /* 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/* 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/* 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);\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\t\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\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\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 sizeof(intp));\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\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\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 sizeof(intp));\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 sizeof(intp));\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\t\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\t \n\tif (mit->view) return;\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\n\tsub = PyObject_GetItem((PyObject *)arr, mit->indexobj);\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\t\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\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\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= 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) *indptr, (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);\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\t\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->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_IndexError,\t\t\t\\\n\t\t\t\t\"arrays used as indices must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_IndexError, \"too many indices\");\n\t\tgoto fail;\n\t}\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\t\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);\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 ret:\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\t\n\tint i, err=0;\n\t\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\t\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\t\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);\t\n\t\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\t\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\t\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\t\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\t\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\t\n return (PyObject *)multi;\n\t\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\t_pya_free(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);\t\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 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/*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;\t\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(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 dtypedescr objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"dtype\", 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\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\tchar basic_=self->kind;\n\tchar endian = self->byteorder;\n\t\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\t\n\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t self->elsize);\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{\"subdescr\", \n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"arrdescr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"dtypestr\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\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\t\n\tif (!PyArg_ParseTuple(args, \"O|iO&\", &odescr, &align,\n\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\t\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, \n\t\t\t\t\t\t\t\t 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, \"dtypedescr\");\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\tobj = PyString_FromFormat(\"%c%d\",self->kind, self->elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\t\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\t\n\tif (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\t\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\t\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\t\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*/\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\t\t\t\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 dtypedescr 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 dtypedescr object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\t\t\t\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);\t\t\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(\"dtypedescr(\");\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 dtypedescr 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\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtypedescr\",\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 0, \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", + "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\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\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=NULL;\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\tdescr = PyArray_DescrFromType(PyArray_INTP);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else 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} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\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=NULL;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\tdescr = PyArray_DescrFromType(PyArray_INT);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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} else 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) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\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\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 if (PyBigArray_CheckExact(obj)) \n return PyArray_BIG_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\t\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\t\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\t\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\t\n dest_strides_ptr = dest_strides;\n\t\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\t\n new_data = (char *)_pya_malloc(stride);\n\t\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\t\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\t\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\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\nstatic PyArray_Descr **userdescrs=NULL;\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\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\t\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\n/* If destination is not the right type, then src \n will be cast to destination. \n*/\n\n/* Does a flat iterator-based copy. \n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however. \n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n \n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError, \n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->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, elsize);\n PyArray_INCREF(dest);\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 memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\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\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t dest->descr, 0,\n\t\t\t\t\t dest->nd, FORTRAN_IF(dest));\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\t\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/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\t\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\t\n return (PyObject *)ret;\t\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_OBJECT) &&\t\t\\\n\t (PyArray_Check((*((PyObject **)data))))) {\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 (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}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize / sizeof(Py_UNICODE);\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\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, itemsize);\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/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\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\t\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\t\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 fwrite(sep, 1, n3, fp);\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\t\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\t\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\t\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\t\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\t\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\t\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \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\t\t\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\t\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\nstatic PyObject *\narray_item_nice(PyArrayObject *self, int i) \n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\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\t\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 SIZEOF_INT == SIZEOF_INTP\n#define array_ass_item array_ass_big_item\n#else\nstatic int\narray_ass_item(PyArrayObject *self, int 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\t\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\t\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\t\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\t\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\t\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\t\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\t\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);\t\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\t\n nd_old = nd_new = 0;\n\t\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\t\t\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 }\t \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\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\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);\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->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\t\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);\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}\n\t}\n\t\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, PyArray_ITEMSIZE(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}\t\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\t\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/* 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;\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\t\t\t\t\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\t\t\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\treturn PyArray_ToScalar(self->data, self);\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\treturn PyArray_ToScalar(self->data, self);\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n\t/* wrap arguments into a mapiter object */\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(op, oned);\n if (mit == NULL) return NULL;\n if (!mit->view) { /* fancy indexing */\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 Py_DECREF(mit);\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\t\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\t\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;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\t\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\t\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\t\t\t\t\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\t\t\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(index, oned);\n if (mit == NULL) return -1;\n if (!mit->view) {\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 Py_DECREF(mit);\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\t\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\treturn PyArray_Return((PyArrayObject *)array_subscript(self, op));\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n (inquiry)array_length,\t\t /*mp_length*/\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 \narray_getsegcount(PyArrayObject *self, int *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 \narray_getreadbuf(PyArrayObject *self, int 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 \narray_getwritebuf(PyArrayObject *self, int 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 \narray_getcharbuf(PyArrayObject *self, int 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 (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};\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\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;\t\n\t\n} NumericOps;\n\nstatic NumericOps n_ops = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL};\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\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);\t \n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\t\n SET(true_divide);\t\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\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;\t\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\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);\t \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\treturn dict;\t\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\t\t\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}\t\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}\t\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 *\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 PyObject *\narray_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.power);\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 *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.power);\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\t\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;\t \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 an \"\\\n\t\t\t\t\"int; 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;\t \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;\t \n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v) \n{\t \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;\t \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;\t \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*/\t\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 ilow, int ihigh) \n{\n PyArrayObject *r;\n int l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n \t\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\n self->dimensions[0] = l;\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 ilow, int ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\t\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\t\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\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, 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\n\nstatic PySequenceMethods array_as_sequence = {\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};\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\t\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\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\t\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\t\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\t\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\t\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\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\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 return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\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.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\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\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\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; ind == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tintp sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\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\t\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;\t\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by a single segment array of the provided \n dimensions and element size. If numbytes is 0 it will be calculated from \n the provided shape and element size.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\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;\t\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 */\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, \n\t\t\t intp *newstrides, int oldnd)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\t\n\told = *des;\n\t*des = old->subarray->base;\n\n\tmydim = newdims + oldnd;\n\tif (PyTuple_Check(old->subarray->shape)) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t\t\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tnumnew = 1;\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\t\n\tnewnd = oldnd + numnew;\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\t/* Make new strides */\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\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{\t\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\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);\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\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\t\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { /* strides is NULL too */\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\t\t\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\t\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 {\n\t\t\tif (data == NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"if 'strides' is given in \" \\\n\t\t\t\t\t\t\"array creation, data must \" \\\n\t\t\t\t\t\t\"be given too\");\n\t\t\t\tgoto fail;\n\t\t\t} \n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t} \t\n\t\t\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\t\tif (descr == &OBJECT_Descr) {\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 and some object passed in */\n\tif ((obj != NULL) && (subtype != &PyArray_Type) && \n\t (subtype != &PyBigArray_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 (!(self->flags & OWNDATA)) { /* did not allocate own data */\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\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\t\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*/\nstatic PyObject * \nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape)\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\t\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n \"resize only works on contiguous arrays\");\n return NULL;\n }\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\t\t\n\t\trefcnt = REFCOUNT(self);\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\t\t\t\t\n\t\tif (newsize == 0) sd = self->descr->elsize;\t\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 0, &(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);\t\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);\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\twhile (size--) {\n\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\ttoptr += itemsize;\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\t\t\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, itemsize);\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\", \n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", 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\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*/\t\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\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 &fortran)) \n\t\tgoto fail;\n\t\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\t\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\\\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 NULL, 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\t\tbuffer.len -= offset;\n\t\tbuffer.ptr += offset;\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\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 (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\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 (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 PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\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\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\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;\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 != NULL) {\n\t\tif (PyArray_Check(new->base)) \n\t\t\tnew = (PyArrayObject *)new->base;\n\t}\n\tnumbytes = PyArray_MultiplyList(new->dimensions, \n\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes, \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 if (PyBigArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_BIG_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}\t\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 *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISEXTENDED(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->descr->elsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\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 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\t\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\t\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\t\n\telse if (newtype->elsize > self->descr->elsize) {\n\t\t\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\t\t\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\t\t\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\ttemp = (PyArrayObject *)\\\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\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tPy_DECREF(newtype);\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator */\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\ttemp->descr = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype; \n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\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\t\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"arrdescr\");\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_type_get(PyArrayObject *self)\n{\n Py_INCREF(self->descr->typeobj);\n return (PyObject *)self->descr->typeobj;\n}\n\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);\n\tif (new == NULL) return -1;\n\t\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) {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}\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{\t\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{\t\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); \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);\t\t\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));\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->descr->elsize);\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 {\"dtype\", \n\t (getter)array_type_get, \n\t NULL,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n\t{\"dtypedescr\", \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.dtypedescr object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\t\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.bigndarray\",\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 NULL, \t\t\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\t\t\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n NULL, \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/* A standard array will subclass from the Big Array and \n add the array_as_sequence table\n and the array_as_buffer table\n */\n\nstatic PyTypeObject PyArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n};\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\t\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;\t\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\t\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, sizeof(Py_UNICODE)*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\t\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, 2*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\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\t\n\tif (minitype == NULL) \n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\t\n if (max < 0) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\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 \t\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\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\t\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\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_BOOL);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_LONG);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_DOUBLE);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_CDOUBLE);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\n finish:\n\t\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\t\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\t\n l=PyObject_Length(v);\n if(l < 0) return -1; \n\t\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\t\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 *= sizeof(Py_UNICODE);\n\t}\n\n\tret = (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\n\tif (ret == NULL) return NULL;\n\n ret->descr->f->setitem(op, ret->data, ret);\n\t\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 unless return value is NULL*/\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\tPyArray_Descr *savetype=typecode;\n\t\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\t\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 return NULL;\n }\n\t\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 return NULL;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\treturn NULL;\n\t\t}\n\t\tif (type == PyArray_UNICODE) itemsize*=sizeof(Py_UNICODE);\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\t\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\t\n if(!r) {Py_XINCREF(savetype); return NULL;}\n if(Assign_Array(r,s) == -1) {\n\t\tPy_XINCREF(savetype);\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\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\t\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\t\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\t\t\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\t\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\t\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, elsize);\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\t\t\t\t\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\t\t\t\t\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 oelsize);\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);\t\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\t\t\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*sizeof(Py_UNICODE);\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize/sizeof(Py_UNICODE);\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\t\n\tPy_DECREF(out);\n\treturn NULL;\n\t\n}\n\t \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\t\t\t\t\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * outsize;\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\t\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 */\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) \n{\n\t\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\t\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 (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\t\t\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 != &PyBigArray_Type)) {\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 (subtype != &PyBigArray_Type)) {\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\t\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 != &PyBigArray_Type)) {\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\t\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}\t\t\n\t\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;\t \n\t\telse _MY_FAIL \n\t\t\tbreak;\t\t \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;\t\t \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;\t\t \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\t\tbreak;\n\tcase 'S':\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase 'U':\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize *= sizeof(Py_UNICODE);\n\t\tbreak;\t \n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\t\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/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_fromstructinterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r, *ret;\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_XDECREF(intype);\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_XDECREF(intype);\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 ret = array_fromarray((PyArrayObject*)r, intype, flags);\n Py_DECREF(r);\n return ret;\n}\n\n/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n PyObject *tstr=NULL, *shape=NULL; \n\tPyArrayObject *ret=NULL;\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\t\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\tPy_XDECREF(intype);\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\tPy_XDECREF(intype);\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\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n\n fail:\n\tPy_XDECREF(intype);\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* steals a reference to typecode */\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Descr *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode == NULL) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyObject *obj;\n\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", typecode->type,\n\t\t\t\t\t\t typecode->elsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(typecode->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\n if (new == NULL) {Py_XDECREF(typecode); 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\t\tPy_DECREF(typecode);\n return NULL;\n }\n r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n/* Steals a reference to newtype --- which can be NULL */\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Descr *newtype, int min_depth, \n\t\t int max_depth, int flags) \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 = array_fromarray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if ((r = array_fromstructinterface(op, newtype, flags)) != \\\n\t\t Py_NotImplemented) {\n }\n else if ((r = array_frominterface(op, newtype, flags)) !=\t\\\n\t\t Py_NotImplemented) {\n\t}\n else if (PyObject_HasAttrString(op, \"__array__\")) {\n /* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, newtype, flags);\n }\n\telse {\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\t\t\t\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 PyErr_Clear();\n else\n seq = TRUE;\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\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\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\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_FromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n\t\tint max_depth, int requires) \n{\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\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 array_fromobject(op, descr, min_depth, max_depth,\n \t\t\t\trequires);\t\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 or PyBigArray_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) || PyBigArray_CheckExact(op)) return op;\n \n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FROM_OF(op, ENSUREARRAY);\n Py_DECREF(op);\n return new;\n}\n\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 * sizeof(Py_UNICODE)\\\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.\t\t \n\t\t*/\n\t}\n\treturn ret;\n}\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\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\t\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\t\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\t\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/* 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\niter_length(PyArrayIterObject *self) \n{\n return (int) 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, itemsize);\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\t\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, itemsize);\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;\t\t\t\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */ \t\n\t\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, size);\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);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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\t\t\t\t\t FORCECAST | ALIGNED);\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,\n\t\t\t\t itemsize);\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, itemsize);\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, itemsize);\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\t\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\t\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0);\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, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\t\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, itemsize);\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, itemsize);\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);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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_FromAny(obj, indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\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\t\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n (inquiry)iter_length,\t\t /*mp_length*/\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;\t\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\t{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 0, /* 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/* 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/* 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);\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\t\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\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\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 sizeof(intp));\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\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\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 sizeof(intp));\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 sizeof(intp));\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\t\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\t \n\tif (mit->view) return;\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\n\tsub = PyObject_GetItem((PyObject *)arr, mit->indexobj);\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\t\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\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\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= 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) *indptr, (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);\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\t\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->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_IndexError,\t\t\t\\\n\t\t\t\t\"arrays used as indices must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_IndexError, \"too many indices\");\n\t\tgoto fail;\n\t}\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\t\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);\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 ret:\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\t\n\tint i, err=0;\n\t\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\t\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\t\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);\t\n\t\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\t\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\t\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\t\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\t\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\t\n return (PyObject *)multi;\n\t\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\t_pya_free(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);\t\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 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/*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;\t\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(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 dtypedescr objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"dtype\", 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\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\tchar basic_=self->kind;\n\tchar endian = self->byteorder;\n\t\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\t\n\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t self->elsize);\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{\"subdescr\", \n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"arrdescr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"dtypestr\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\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\t\n\tif (!PyArg_ParseTuple(args, \"O|iO&\", &odescr, &align,\n\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\t\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, \n\t\t\t\t\t\t\t\t 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, \"dtypedescr\");\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\tobj = PyString_FromFormat(\"%c%d\",self->kind, self->elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\t\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\t\n\tif (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\t\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\t\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\t\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*/\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\t\t\t\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 dtypedescr 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 dtypedescr object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\t\t\t\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);\t\t\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(\"dtypedescr(\");\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 dtypedescr 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\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtypedescr\",\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 0, \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", + "methods": [ + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 19, + "token_count": 391, + "parameters": [ + "o" + ], + "start_line": 31, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 59, + "complexity": 19, + "token_count": 394, + "parameters": [ + "o" + ], + "start_line": 103, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 86, + "parameters": [ + "obj", + "default_" + ], + "start_line": 173, + "end_line": 191, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "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": 212, + "end_line": 240, + "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": 246, + "end_line": 275, + "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": 281, + "end_line": 331, + "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": 354, + "end_line": 385, + "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": 388, + "end_line": 422, + "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": 438, + "end_line": 460, + "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": 466, + "end_line": 487, + "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": 491, + "end_line": 529, + "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": 534, + "end_line": 554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "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": 562, + "end_line": 577, + "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": 583, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 607, + "end_line": 687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "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": 79, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 691, + "end_line": 705, + "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": 718, + "end_line": 744, + "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": 750, + "end_line": 764, + "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 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 772, + "end_line": 792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 11, + "token_count": 468, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 801, + "end_line": 883, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 899, + "end_line": 902, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 912, + "end_line": 934, + "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": 948, + "end_line": 988, + "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": 1003, + "end_line": 1044, + "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": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1051, + "end_line": 1142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "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": 1148, + "end_line": 1177, + "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": 1180, + "end_line": 1216, + "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": 1225, + "end_line": 1262, + "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": 1269, + "end_line": 1277, + "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": 1280, + "end_line": 1305, + "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 i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1308, + "end_line": 1311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 1315, + "end_line": 1350, + "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 i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1356, + "end_line": 1359, + "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": 1365, + "end_line": 1373, + "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": 1379, + "end_line": 1429, + "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": 1436, + "end_line": 1481, + "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": 1485, + "end_line": 1579, + "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": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1582, + "end_line": 1619, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1631, + "end_line": 1684, + "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": 53, + "complexity": 12, + "token_count": 380, + "parameters": [ + "mit", + "op" + ], + "start_line": 1687, + "end_line": 1747, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "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": 1750, + "end_line": 1777, + "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": 1780, + "end_line": 1799, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 28, + "token_count": 659, + "parameters": [ + "self", + "op" + ], + "start_line": 1823, + "end_line": 1938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 91, + "complexity": 28, + "token_count": 581, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 1953, + "end_line": 2055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2064, + "end_line": 2067, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , int * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2086, + "end_line": 2098, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2101, + "end_line": 2116, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2120, + "end_line": 2129, + "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 segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2132, + "end_line": 2143, + "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": 34, + "complexity": 1, + "token_count": 162, + "parameters": [ + "dict" + ], + "start_line": 2214, + "end_line": 2247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 2, + "token_count": 183, + "parameters": [], + "start_line": 2257, + "end_line": 2296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "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": 2299, + "end_line": 2322, + "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": 2326, + "end_line": 2349, + "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": 2353, + "end_line": 2360, + "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": 2363, + "end_line": 2370, + "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": 2373, + "end_line": 2381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 2384, + "end_line": 2387, + "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": 2390, + "end_line": 2393, + "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": 2396, + "end_line": 2399, + "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": 2402, + "end_line": 2405, + "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": 2408, + "end_line": 2411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2414, + "end_line": 2417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2420, + "end_line": 2423, + "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": 2426, + "end_line": 2429, + "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": 2432, + "end_line": 2435, + "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": 2438, + "end_line": 2441, + "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": 2444, + "end_line": 2447, + "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": 2450, + "end_line": 2453, + "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": 2456, + "end_line": 2459, + "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": 2462, + "end_line": 2465, + "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": 2468, + "end_line": 2471, + "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": 2474, + "end_line": 2477, + "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": 2480, + "end_line": 2483, + "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": 2486, + "end_line": 2489, + "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": 2492, + "end_line": 2495, + "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 * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2498, + "end_line": 2501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2504, + "end_line": 2507, + "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": 2510, + "end_line": 2513, + "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": 2516, + "end_line": 2519, + "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": 2522, + "end_line": 2525, + "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": 2528, + "end_line": 2531, + "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": 2534, + "end_line": 2537, + "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": 2540, + "end_line": 2543, + "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": 2546, + "end_line": 2550, + "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": 2553, + "end_line": 2557, + "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": 2561, + "end_line": 2579, + "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": 2582, + "end_line": 2599, + "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": 2604, + "end_line": 2619, + "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": 2623, + "end_line": 2649, + "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": 2652, + "end_line": 2677, + "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": 2680, + "end_line": 2702, + "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": 2705, + "end_line": 2727, + "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": 2730, + "end_line": 2752, + "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": 2755, + "end_line": 2759, + "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 ilow , int ihigh)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 11, + "token_count": 259, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 2820, + "end_line": 2860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , int ilow , int ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 2864, + "end_line": 2885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 2888, + "end_line": 2900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 2921, + "end_line": 2968, + "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": 2971, + "end_line": 3007, + "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": 3016, + "end_line": 3033, + "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": 3036, + "end_line": 3048, + "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": 3051, + "end_line": 3063, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_richcompare", + "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 13, + "token_count": 273, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3066, + "end_line": 3143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 164, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3146, + "end_line": 3175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 3181, + "end_line": 3201, + "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": 21, + "complexity": 7, + "token_count": 161, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3209, + "end_line": 3232, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 111, + "parameters": [ + "ap" + ], + "start_line": 3238, + "end_line": 3254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 109, + "parameters": [ + "ap" + ], + "start_line": 3258, + "end_line": 3274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 3277, + "end_line": 3294, + "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": 3297, + "end_line": 3330, + "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": 3337, + "end_line": 3364, + "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 * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 84, + "parameters": [ + "elsize", + "nd", + "numbytes", + "dims", + "newstrides" + ], + "start_line": 3373, + "end_line": 3388, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 3408, + "end_line": 3432, + "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": 3438, + "end_line": 3460, + "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)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 6, + "token_count": 229, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd" + ], + "start_line": 3464, + "end_line": 3506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 130, + "complexity": 26, + "token_count": 761, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3514, + "end_line": 3672, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 159, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", + "filename": "arrayobject.c", + "nloc": 82, + "complexity": 15, + "token_count": 497, + "parameters": [ + "self", + "newshape" + ], + "start_line": 3681, + "end_line": 3779, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "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": 3785, + "end_line": 3802, + "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": 41, + "complexity": 6, + "token_count": 229, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3806, + "end_line": 3848, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 18, + "token_count": 570, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 3851, + "end_line": 3965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 115, + "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": 3969, + "end_line": 3977, + "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": 3983, + "end_line": 3986, + "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": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 3989, + "end_line": 3993, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 3996, + "end_line": 3999, + "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": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4003, + "end_line": 4032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 4036, + "end_line": 4039, + "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": 36, + "complexity": 7, + "token_count": 231, + "parameters": [ + "self", + "obj" + ], + "start_line": 4042, + "end_line": 4080, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "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": 4084, + "end_line": 4091, + "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": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 4094, + "end_line": 4102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 4106, + "end_line": 4112, + "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": 4115, + "end_line": 4129, + "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": 4132, + "end_line": 4176, + "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": 4180, + "end_line": 4183, + "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": 4186, + "end_line": 4197, + "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": 4200, + "end_line": 4211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typechar_get", + "long_name": "array_typechar_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 4215, + "end_line": 4222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 4227, + "end_line": 4230, + "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": 4233, + "end_line": 4237, + "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": 15, + "token_count": 443, + "parameters": [ + "self", + "arg" + ], + "start_line": 4251, + "end_line": 4336, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "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": 4339, + "end_line": 4357, + "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": 4360, + "end_line": 4378, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_type_get", + "long_name": "array_type_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4381, + "end_line": 4385, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 4390, + "end_line": 4400, + "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": 4404, + "end_line": 4429, + "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": 32, + "complexity": 4, + "token_count": 189, + "parameters": [ + "self", + "val" + ], + "start_line": 4433, + "end_line": 4466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "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": 4469, + "end_line": 4502, + "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": 205, + "parameters": [ + "self", + "val" + ], + "start_line": 4505, + "end_line": 4542, + "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": 4545, + "end_line": 4548, + "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": 346, + "parameters": [ + "self", + "val" + ], + "start_line": 4551, + "end_line": 4601, + "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": 4703, + "end_line": 4710, + "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": 4812, + "end_line": 4845, + "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": 161, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 4848, + "end_line": 4870, + "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": 4877, + "end_line": 4903, + "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": 4909, + "end_line": 4941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 120, + "complexity": 31, + "token_count": 691, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 4953, + "end_line": 5089, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 137, + "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": 5092, + "end_line": 5115, + "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": 23, + "complexity": 6, + "token_count": 146, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5120, + "end_line": 5148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 21, + "token_count": 367, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5153, + "end_line": 5217, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "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": 5224, + "end_line": 5233, + "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": 5239, + "end_line": 5332, + "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": 280, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5342, + "end_line": 5388, + "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": 5398, + "end_line": 5451, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_fromarray", + "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 32, + "token_count": 673, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5455, + "end_line": 5584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 505, + "parameters": [ + "str" + ], + "start_line": 5588, + "end_line": 5696, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "array_fromstructinterface", + "long_name": "array_fromstructinterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 6, + "token_count": 274, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5700, + "end_line": 5744, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_frominterface", + "long_name": "array_frominterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 134, + "complexity": 28, + "token_count": 839, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5748, + "end_line": 5891, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 144, + "top_nesting_level": 0 + }, + { + "name": "array_fromattr", + "long_name": "array_fromattr( PyObject * op , PyArray_Descr * typecode , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 178, + "parameters": [ + "op", + "typecode", + "flags" + ], + "start_line": 5895, + "end_line": 5925, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "array_fromobject", + "long_name": "array_fromobject( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 17, + "token_count": 330, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags" + ], + "start_line": 5929, + "end_line": 6005, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 77, + "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": 6010, + "end_line": 6013, + "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": 6020, + "end_line": 6033, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 8, + "token_count": 117, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires" + ], + "start_line": 6079, + "end_line": 6098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 81, + "parameters": [ + "op" + ], + "start_line": 6111, + "end_line": 6127, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 6135, + "end_line": 6223, + "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": 134, + "parameters": [ + "from", + "to" + ], + "start_line": 6228, + "end_line": 6256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 6269, + "end_line": 6307, + "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": 6315, + "end_line": 6332, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "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": 6337, + "end_line": 6347, + "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": 6350, + "end_line": 6354, + "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": 16, + "parameters": [ + "self" + ], + "start_line": 6357, + "end_line": 6360, + "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": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6364, + "end_line": 6414, + "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": 6417, + "end_line": 6471, + "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": 664, + "parameters": [ + "self", + "ind" + ], + "start_line": 6475, + "end_line": 6608, + "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": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6612, + "end_line": 6644, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "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": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6647, + "end_line": 6689, + "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": 692, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 6692, + "end_line": 6826, + "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": 6839, + "end_line": 6884, + "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": 6889, + "end_line": 6893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 6965, + "end_line": 7027, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 104, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7035, + "end_line": 7051, + "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": 7058, + "end_line": 7127, + "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": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7131, + "end_line": 7168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7174, + "end_line": 7218, + "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": 99, + "complexity": 22, + "token_count": 670, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7236, + "end_line": 7366, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 460, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7372, + "end_line": 7445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned)", + "filename": "arrayobject.c", + "nloc": 112, + "complexity": 25, + "token_count": 758, + "parameters": [ + "indexobj", + "oned" + ], + "start_line": 7448, + "end_line": 7583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "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": 7587, + "end_line": 7596, + "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": 231, + "parameters": [ + "n" + ], + "start_line": 7667, + "end_line": 7716, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "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": 265, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 7719, + "end_line": 7764, + "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": 7767, + "end_line": 7786, + "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": 41, + "parameters": [ + "multi" + ], + "start_line": 7789, + "end_line": 7796, + "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": 7799, + "end_line": 7809, + "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": 7812, + "end_line": 7822, + "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": 7825, + "end_line": 7828, + "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": 7831, + "end_line": 7843, + "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": 7873, + "end_line": 7880, + "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": 7939, + "end_line": 7948, + "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": 7966, + "end_line": 7988, + "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": 64, + "parameters": [ + "self" + ], + "start_line": 7994, + "end_line": 8004, + "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": 8022, + "end_line": 8030, + "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": 11, + "complexity": 3, + "token_count": 60, + "parameters": [ + "self" + ], + "start_line": 8033, + "end_line": 8045, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 8048, + "end_line": 8067, + "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": 8074, + "end_line": 8081, + "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": 8084, + "end_line": 8091, + "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": 8094, + "end_line": 8101, + "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": 47, + "complexity": 13, + "token_count": 251, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8137, + "end_line": 8188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 50, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "args" + ], + "start_line": 8194, + "end_line": 8251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8259, + "end_line": 8301, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 8321, + "end_line": 8387, + "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": 8398, + "end_line": 8406, + "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": 8421, + "end_line": 8466, + "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": 8469, + "end_line": 8478, + "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": 8481, + "end_line": 8491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 19, + "token_count": 391, + "parameters": [ + "o" + ], + "start_line": 31, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 59, + "complexity": 19, + "token_count": 394, + "parameters": [ + "o" + ], + "start_line": 103, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 86, + "parameters": [ + "obj", + "default_" + ], + "start_line": 173, + "end_line": 191, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "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": 212, + "end_line": 240, + "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": 246, + "end_line": 275, + "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": 281, + "end_line": 331, + "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": 354, + "end_line": 385, + "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": 388, + "end_line": 422, + "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": 438, + "end_line": 460, + "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": 466, + "end_line": 487, + "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": 491, + "end_line": 529, + "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": 534, + "end_line": 554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "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": 562, + "end_line": 577, + "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": 583, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 607, + "end_line": 687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "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": 79, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 691, + "end_line": 705, + "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": 718, + "end_line": 744, + "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": 750, + "end_line": 764, + "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 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 772, + "end_line": 792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 80, + "complexity": 12, + "token_count": 485, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 801, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 84, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 900, + "end_line": 903, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 913, + "end_line": 935, + "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": 949, + "end_line": 989, + "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": 1004, + "end_line": 1045, + "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": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1052, + "end_line": 1143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "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": 1149, + "end_line": 1178, + "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": 1181, + "end_line": 1217, + "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": 1226, + "end_line": 1263, + "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": 1270, + "end_line": 1278, + "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": 1281, + "end_line": 1306, + "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 i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1309, + "end_line": 1312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 1316, + "end_line": 1351, + "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 i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1357, + "end_line": 1360, + "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": 1366, + "end_line": 1374, + "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": 1380, + "end_line": 1430, + "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": 1437, + "end_line": 1482, + "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": 1486, + "end_line": 1580, + "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": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1583, + "end_line": 1620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1632, + "end_line": 1685, + "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": 53, + "complexity": 12, + "token_count": 380, + "parameters": [ + "mit", + "op" + ], + "start_line": 1688, + "end_line": 1748, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "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": 1751, + "end_line": 1778, + "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": 1781, + "end_line": 1800, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 28, + "token_count": 659, + "parameters": [ + "self", + "op" + ], + "start_line": 1824, + "end_line": 1939, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 91, + "complexity": 28, + "token_count": 581, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 1954, + "end_line": 2056, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2065, + "end_line": 2068, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , int * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2087, + "end_line": 2099, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2102, + "end_line": 2117, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2121, + "end_line": 2130, + "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 segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2133, + "end_line": 2144, + "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": 34, + "complexity": 1, + "token_count": 162, + "parameters": [ + "dict" + ], + "start_line": 2215, + "end_line": 2248, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 2, + "token_count": 183, + "parameters": [], + "start_line": 2258, + "end_line": 2297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "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": 2300, + "end_line": 2323, + "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": 2327, + "end_line": 2350, + "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": 2354, + "end_line": 2361, + "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": 2364, + "end_line": 2371, + "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": 2374, + "end_line": 2382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 2385, + "end_line": 2388, + "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": 2391, + "end_line": 2394, + "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": 2397, + "end_line": 2400, + "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": 2403, + "end_line": 2406, + "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": 2409, + "end_line": 2412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2415, + "end_line": 2418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2421, + "end_line": 2424, + "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": 2427, + "end_line": 2430, + "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": 2433, + "end_line": 2436, + "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": 2439, + "end_line": 2442, + "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": 2445, + "end_line": 2448, + "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": 2451, + "end_line": 2454, + "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": 2457, + "end_line": 2460, + "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": 2463, + "end_line": 2466, + "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": 2469, + "end_line": 2472, + "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": 2475, + "end_line": 2478, + "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": 2481, + "end_line": 2484, + "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": 2487, + "end_line": 2490, + "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": 2493, + "end_line": 2496, + "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 * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2499, + "end_line": 2502, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2505, + "end_line": 2508, + "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": 2511, + "end_line": 2514, + "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": 2517, + "end_line": 2520, + "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": 2523, + "end_line": 2526, + "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": 2529, + "end_line": 2532, + "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": 2535, + "end_line": 2538, + "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": 2541, + "end_line": 2544, + "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": 2547, + "end_line": 2551, + "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": 2554, + "end_line": 2558, + "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": 2562, + "end_line": 2580, + "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": 2583, + "end_line": 2600, + "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": 2605, + "end_line": 2620, + "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": 2624, + "end_line": 2650, + "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": 2653, + "end_line": 2678, + "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": 2681, + "end_line": 2703, + "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": 2706, + "end_line": 2728, + "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": 2731, + "end_line": 2753, + "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": 2756, + "end_line": 2760, + "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 ilow , int ihigh)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 11, + "token_count": 259, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 2821, + "end_line": 2861, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , int ilow , int ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 2865, + "end_line": 2886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 2889, + "end_line": 2901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 2922, + "end_line": 2969, + "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": 2972, + "end_line": 3008, + "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": 3017, + "end_line": 3034, + "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": 3037, + "end_line": 3049, + "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": 3052, + "end_line": 3064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_richcompare", + "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 13, + "token_count": 273, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3067, + "end_line": 3144, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 164, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3147, + "end_line": 3176, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 3182, + "end_line": 3202, + "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": 21, + "complexity": 7, + "token_count": 161, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3210, + "end_line": 3233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 111, + "parameters": [ + "ap" + ], + "start_line": 3239, + "end_line": 3255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 109, + "parameters": [ + "ap" + ], + "start_line": 3259, + "end_line": 3275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 3278, + "end_line": 3295, + "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": 3298, + "end_line": 3331, + "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": 3338, + "end_line": 3365, + "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 * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 84, + "parameters": [ + "elsize", + "nd", + "numbytes", + "dims", + "newstrides" + ], + "start_line": 3374, + "end_line": 3389, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 3409, + "end_line": 3433, + "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": 3439, + "end_line": 3461, + "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)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 6, + "token_count": 229, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd" + ], + "start_line": 3465, + "end_line": 3507, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 130, + "complexity": 26, + "token_count": 761, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3515, + "end_line": 3673, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 159, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", + "filename": "arrayobject.c", + "nloc": 82, + "complexity": 15, + "token_count": 497, + "parameters": [ + "self", + "newshape" + ], + "start_line": 3682, + "end_line": 3780, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "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": 3786, + "end_line": 3803, + "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": 41, + "complexity": 6, + "token_count": 229, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3807, + "end_line": 3849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 18, + "token_count": 570, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 3852, + "end_line": 3966, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 115, + "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": 3970, + "end_line": 3978, + "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": 3984, + "end_line": 3987, + "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": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 3990, + "end_line": 3994, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 3997, + "end_line": 4000, + "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": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4004, + "end_line": 4033, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 4037, + "end_line": 4040, + "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": 36, + "complexity": 7, + "token_count": 231, + "parameters": [ + "self", + "obj" + ], + "start_line": 4043, + "end_line": 4081, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "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": 4085, + "end_line": 4092, + "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": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 4095, + "end_line": 4103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 4107, + "end_line": 4113, + "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": 4116, + "end_line": 4130, + "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": 4133, + "end_line": 4177, + "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": 4181, + "end_line": 4184, + "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": 4187, + "end_line": 4198, + "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": 4201, + "end_line": 4212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typechar_get", + "long_name": "array_typechar_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 4216, + "end_line": 4223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 4228, + "end_line": 4231, + "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": 4234, + "end_line": 4238, + "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": 15, + "token_count": 443, + "parameters": [ + "self", + "arg" + ], + "start_line": 4252, + "end_line": 4337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "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": 4340, + "end_line": 4358, + "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": 4361, + "end_line": 4379, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_type_get", + "long_name": "array_type_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4382, + "end_line": 4386, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 4391, + "end_line": 4401, + "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": 4405, + "end_line": 4430, + "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": 32, + "complexity": 4, + "token_count": 189, + "parameters": [ + "self", + "val" + ], + "start_line": 4434, + "end_line": 4467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "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": 4470, + "end_line": 4503, + "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": 205, + "parameters": [ + "self", + "val" + ], + "start_line": 4506, + "end_line": 4543, + "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": 4546, + "end_line": 4549, + "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": 346, + "parameters": [ + "self", + "val" + ], + "start_line": 4552, + "end_line": 4602, + "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": 4704, + "end_line": 4711, + "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": 4813, + "end_line": 4846, + "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": 161, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 4849, + "end_line": 4871, + "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": 4878, + "end_line": 4904, + "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": 4910, + "end_line": 4942, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 120, + "complexity": 31, + "token_count": 691, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 4954, + "end_line": 5090, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 137, + "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": 5093, + "end_line": 5116, + "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": 23, + "complexity": 6, + "token_count": 146, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5121, + "end_line": 5149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 21, + "token_count": 367, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5154, + "end_line": 5218, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "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": 5225, + "end_line": 5234, + "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": 5240, + "end_line": 5333, + "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": 280, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5343, + "end_line": 5389, + "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": 5399, + "end_line": 5452, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_fromarray", + "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 32, + "token_count": 673, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5456, + "end_line": 5585, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 505, + "parameters": [ + "str" + ], + "start_line": 5589, + "end_line": 5697, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "array_fromstructinterface", + "long_name": "array_fromstructinterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 6, + "token_count": 274, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5701, + "end_line": 5745, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_frominterface", + "long_name": "array_frominterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 134, + "complexity": 28, + "token_count": 839, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5749, + "end_line": 5892, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 144, + "top_nesting_level": 0 + }, + { + "name": "array_fromattr", + "long_name": "array_fromattr( PyObject * op , PyArray_Descr * typecode , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 178, + "parameters": [ + "op", + "typecode", + "flags" + ], + "start_line": 5896, + "end_line": 5926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "array_fromobject", + "long_name": "array_fromobject( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 17, + "token_count": 330, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags" + ], + "start_line": 5930, + "end_line": 6006, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 77, + "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": 6011, + "end_line": 6014, + "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": 6021, + "end_line": 6034, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 8, + "token_count": 117, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires" + ], + "start_line": 6080, + "end_line": 6099, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 81, + "parameters": [ + "op" + ], + "start_line": 6112, + "end_line": 6128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 6136, + "end_line": 6224, + "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": 134, + "parameters": [ + "from", + "to" + ], + "start_line": 6229, + "end_line": 6257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 6270, + "end_line": 6308, + "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": 6316, + "end_line": 6333, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "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": 6338, + "end_line": 6348, + "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": 6351, + "end_line": 6355, + "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": 16, + "parameters": [ + "self" + ], + "start_line": 6358, + "end_line": 6361, + "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": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6365, + "end_line": 6415, + "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": 6418, + "end_line": 6472, + "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": 664, + "parameters": [ + "self", + "ind" + ], + "start_line": 6476, + "end_line": 6609, + "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": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6613, + "end_line": 6645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "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": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6648, + "end_line": 6690, + "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": 692, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 6693, + "end_line": 6827, + "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": 6840, + "end_line": 6885, + "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": 6890, + "end_line": 6894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 6966, + "end_line": 7028, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 104, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7036, + "end_line": 7052, + "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": 7059, + "end_line": 7128, + "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": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7132, + "end_line": 7169, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7175, + "end_line": 7219, + "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": 99, + "complexity": 22, + "token_count": 670, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7237, + "end_line": 7367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 460, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7373, + "end_line": 7446, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned)", + "filename": "arrayobject.c", + "nloc": 112, + "complexity": 25, + "token_count": 758, + "parameters": [ + "indexobj", + "oned" + ], + "start_line": 7449, + "end_line": 7584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "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": 7588, + "end_line": 7597, + "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": 231, + "parameters": [ + "n" + ], + "start_line": 7668, + "end_line": 7717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "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": 265, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 7720, + "end_line": 7765, + "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": 7768, + "end_line": 7787, + "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": 41, + "parameters": [ + "multi" + ], + "start_line": 7790, + "end_line": 7797, + "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": 7800, + "end_line": 7810, + "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": 7813, + "end_line": 7823, + "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": 7826, + "end_line": 7829, + "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": 7832, + "end_line": 7844, + "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": 7874, + "end_line": 7881, + "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": 7940, + "end_line": 7949, + "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": 7967, + "end_line": 7989, + "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": 64, + "parameters": [ + "self" + ], + "start_line": 7995, + "end_line": 8005, + "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": 8023, + "end_line": 8031, + "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": 11, + "complexity": 3, + "token_count": 60, + "parameters": [ + "self" + ], + "start_line": 8034, + "end_line": 8046, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 8049, + "end_line": 8068, + "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": 8075, + "end_line": 8082, + "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": 8085, + "end_line": 8092, + "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": 8095, + "end_line": 8102, + "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": 47, + "complexity": 13, + "token_count": 251, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8138, + "end_line": 8189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 50, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "args" + ], + "start_line": 8195, + "end_line": 8252, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8260, + "end_line": 8302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 8322, + "end_line": 8388, + "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": 8399, + "end_line": 8407, + "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": 8422, + "end_line": 8467, + "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": 8470, + "end_line": 8479, + "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": 8482, + "end_line": 8492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 11, + "token_count": 468, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 801, + "end_line": 883, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + } + ], + "nloc": 6780, + "complexity": 1442, + "token_count": 39848, + "diff_parsed": { + "added": [ + "\tif ((type_num == PyArray_OBJECT)) {" + ], + "deleted": [ + "\tif ((type_num == PyArray_OBJECT) &&\t\t\\", + "\t (PyArray_Check((*((PyObject **)data))))) {" + ] + } + } + ] + }, + { + "hash": "f547239676d6803e8644bacb3023aa0aed031425", + "msg": "Fixed-up tests we are not returning object array scalars...", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-11T09:53:43+00:00", + "author_timezone": 0, + "committer_date": "2006-01-11T09:53:43+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "fec83ff625de7f0481fb82717b3e599093507b4f" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 9, + "insertions": 9, + "lines": 18, + "files": 2, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/tests/test_ma.py", + "new_path": "numpy/core/tests/test_ma.py", + "filename": "test_ma.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -223,8 +223,8 @@ def check_testCI(self):\n assert eq(3.0, x2.fill_value())\n x1 = array([1,'hello',2,3],object)\n x2 = numpy.array([1,'hello',2,3],object)\n- s1 = x1[1].item()\n- s2 = x2[1].item()\n+ s1 = x1[1]\n+ s2 = x2[1]\n self.assertEqual(type(s2), str)\n self.assertEqual(type(s1), str)\n self.assertEqual(s1, s2)\n@@ -430,9 +430,9 @@ def check_testTakeTransposeInnerOuter(self):\n y = array(['abc', 1, 'def', 2, 3], object)\n y[2] = masked\n t = take(y,[0,3,4])\n- assert t[0].item() == 'abc'\n- assert t[1].item() == 2\n- assert t[2].item() == 3\n+ assert t[0] == 'abc'\n+ assert t[1] == 2\n+ assert t[2] == 3\n \n def check_testInplace(self):\n \"\"\"Test of inplace operations and rich comparisons\"\"\"\n", + "added_lines": 5, + "deleted_lines": 5, + "source_code": "import numpy \nimport types, time\nfrom numpy.core.ma import *\nfrom numpy.testing import ScipyTestCase, ScipyTest\ndef eq(v,w):\n result = allclose(v,w)\n if not result:\n print \"\"\"Not eq:\n%s\n----\n%s\"\"\"% (str(v), str(w))\n return result\n\nclass test_ma(ScipyTestCase):\n def __init__(self, *args, **kwds):\n ScipyTestCase.__init__(self, *args, **kwds)\n self.setUp()\n \n def setUp (self):\n x=numpy.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])\n y=numpy.array([5.,0.,3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])\n a10 = 10.\n m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]\n m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0 ,0, 1]\n xm = array(x, mask=m1)\n ym = array(y, mask=m2)\n z = numpy.array([-.5, 0., .5, .8])\n zm = array(z, mask=[0,1,0,0])\n xf = numpy.where(m1, 1.e+20, x)\n s = x.shape\n xm.set_fill_value(1.e+20)\n self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf, s)\n\n def check_testBasic1d(self):\n \"Test of basic array creation and properties in 1 dimension.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual(xm.dtype, x.dtype)\n self.assertEqual(xm.dtypechar, x.dtypechar)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual(count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n\n def check_testBasic2d(self):\n \"Test of basic array creation and properties in 2 dimensions.\"\n for s in [(4,3), (6,2)]: \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n x.shape = s\n y.shape = s\n xm.shape = s\n ym.shape = s\n xf.shape = s\n \n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual( count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n self.setUp()\n\n def check_testArithmetic (self):\n \"Test of basic arithmetic.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n a2d = array([[1,2],[0,4]])\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n self.failUnless(eq (a2d * a2d, a2d * a2dm))\n self.failUnless(eq (a2d + a2d, a2d + a2dm))\n self.failUnless(eq (a2d - a2d, a2d - a2dm))\n for s in [(12,), (4,3), (2,6)]: \n x = x.reshape(s)\n y = y.reshape(s)\n xm = xm.reshape(s)\n ym = ym.reshape(s)\n xf = xf.reshape(s)\n self.failUnless(eq(-x, -xm))\n self.failUnless(eq(x + y, xm + ym))\n self.failUnless(eq(x - y, xm - ym))\n self.failUnless(eq(x * y, xm * ym))\n self.failUnless(eq(x / y, xm / ym))\n self.failUnless(eq(a10 + y, a10 + ym))\n self.failUnless(eq(a10 - y, a10 - ym))\n self.failUnless(eq(a10 * y, a10 * ym))\n self.failUnless(eq(a10 / y, a10 / ym))\n self.failUnless(eq(x + a10, xm + a10))\n self.failUnless(eq(x - a10, xm - a10))\n self.failUnless(eq(x * a10, xm * a10))\n self.failUnless(eq(x / a10, xm / a10))\n self.failUnless(eq(x**2, xm**2))\n self.failUnless(eq(abs(x)**2.5, abs(xm) **2.5))\n self.failUnless(eq(x**y, xm**ym))\n self.failUnless(eq(numpy.add(x,y), add(xm, ym)))\n self.failUnless(eq(numpy.subtract(x,y), subtract(xm, ym)))\n self.failUnless(eq(numpy.multiply(x,y), multiply(xm, ym)))\n self.failUnless(eq(numpy.divide(x,y), divide(xm, ym)))\n\n\n def check_testMixedArithmetic(self):\n na = numpy.array([1])\n ma = array([1])\n self.failUnless(isinstance(na + ma, MaskedArray))\n self.failUnless(isinstance(ma + na, MaskedArray))\n \n def check_testUfuncs1 (self):\n \"Test various functions such as sin, cos.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.cos(x), cos(xm)))\n self.failUnless (eq(numpy.cosh(x), cosh(xm)))\n self.failUnless (eq(numpy.sin(x), sin(xm)))\n self.failUnless (eq(numpy.sinh(x), sinh(xm)))\n self.failUnless (eq(numpy.tan(x), tan(xm)))\n self.failUnless (eq(numpy.tanh(x), tanh(xm)))\n self.failUnless (eq(numpy.sqrt(abs(x)), sqrt(xm)))\n self.failUnless (eq(numpy.log(abs(x)), log(xm)))\n self.failUnless (eq(numpy.log10(abs(x)), log10(xm)))\n self.failUnless (eq(numpy.exp(x), exp(xm)))\n self.failUnless (eq(numpy.arcsin(z), arcsin(zm)))\n self.failUnless (eq(numpy.arccos(z), arccos(zm)))\n self.failUnless (eq(numpy.arctan(z), arctan(zm)))\n self.failUnless (eq(numpy.arctan2(x, y), arctan2(xm, ym)))\n self.failUnless (eq(numpy.absolute(x), absolute(xm)))\n self.failUnless (eq(numpy.equal(x,y), equal(xm, ym)))\n self.failUnless (eq(numpy.not_equal(x,y), not_equal(xm, ym)))\n self.failUnless (eq(numpy.less(x,y), less(xm, ym)))\n self.failUnless (eq(numpy.greater(x,y), greater(xm, ym)))\n self.failUnless (eq(numpy.less_equal(x,y), less_equal(xm, ym)))\n self.failUnless (eq(numpy.greater_equal(x,y), greater_equal(xm, ym)))\n self.failUnless (eq(numpy.conjugate(x), conjugate(xm)))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,ym))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((x,y))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,y))))\n self.failUnless (eq(numpy.concatenate((x,y,x)), concatenate((x,ym,x))))\n \n def check_xtestCount (self):\n \"Test count\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless( isinstance(count(ott), types.IntType))\n self.assertEqual(3, count(ott))\n self.assertEqual(1, count(1))\n self.failUnless (eq(0, array(1,mask=[1])))\n ott=ott.reshape((2,2))\n assert isMaskedArray(count(ott,0))\n assert isinstance(count(ott), types.IntType)\n self.failUnless (eq(3, count(ott)))\n assert getmask(count(ott,0)) is None\n self.failUnless (eq([1,2],count(ott,0)))\n \n def check_testMinMax (self):\n \"Test minimum and maximum.\" \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n xr = numpy.ravel(x) #max doesn't work if shaped\n xmr = ravel(xm)\n self.failUnless (eq(max(xr), maximum(xmr))) #true because of careful selection of data\n self.failUnless (eq(min(xr), minimum(xmr))) #true because of careful selection of data\n\n def check_testAddSumProd (self):\n \"Test add, sum, product.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.add.reduce(x), add.reduce(x)))\n self.failUnless (eq(numpy.add.accumulate(x), add.accumulate(x)))\n self.failUnless (eq(4, sum(array(4))))\n self.failUnless (eq(4, sum(array(4), axis=0)))\n self.failUnless (eq(numpy.sum(x), sum(x)))\n self.failUnless (eq(numpy.sum(filled(xm,0)), sum(xm)))\n self.failUnless (eq(numpy.sum(x,0), sum(x,0)))\n self.failUnless (eq(numpy.product(x), product(x)))\n self.failUnless (eq(numpy.product(x,0), product(x,0)))\n self.failUnless (eq(numpy.product(filled(xm,1)), product(xm)))\n if len(s) > 1:\n self.failUnless (eq(numpy.concatenate((x,y),1), concatenate((xm,ym),1)))\n self.failUnless (eq(numpy.add.reduce(x,1), add.reduce(x,1)))\n self.failUnless (eq(numpy.sum(x,1), sum(x,1)))\n self.failUnless (eq(numpy.product(x,1), product(x,1)))\n \n \n def check_testCI(self):\n \"Test of conversions and indexing\"\n x1 = numpy.array([1,2,4,3])\n x2 = array(x1, mask = [1,0,0,0])\n x3 = array(x1, mask = [0,1,0,1])\n x4 = array(x1)\n # test conversion to strings\n junk, garbage = str(x2), repr(x2)\n assert eq(numpy.sort(x1),sort(x2, fill_value=0))\n # tests of indexing\n assert type(x2[1]) is type(x1[1])\n assert x1[1] == x2[1]\n assert x2[0] is masked\n assert eq(x1[2],x2[2])\n assert eq(x1[2:5],x2[2:5])\n assert eq(x1[:],x2[:])\n assert eq(x1[1:], x3[1:])\n x1[2]=9\n x2[2]=9\n assert eq(x1,x2)\n x1[1:3] = 99\n x2[1:3] = 99\n assert eq(x1,x2)\n x2[1] = masked\n assert eq(x1,x2)\n x2[1:3]=masked\n assert eq(x1,x2)\n x2[:] = x1\n x2[1] = masked\n assert allequal(getmask(x2),array([0,1,0,0]))\n x3[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x3), array([0,1,1,0]))\n x4[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x4), array([0,1,1,0]))\n assert allequal(x4, array([1,2,3,4]))\n x1 = numpy.arange(5)*1.0\n x2 = masked_values(x1, 3.0)\n assert eq(x1,x2)\n assert allequal(array([0,0,0,1,0],MaskType), x2.mask)\n assert eq(3.0, x2.fill_value())\n x1 = array([1,'hello',2,3],object)\n x2 = numpy.array([1,'hello',2,3],object)\n s1 = x1[1]\n s2 = x2[1]\n self.assertEqual(type(s2), str)\n self.assertEqual(type(s1), str)\n self.assertEqual(s1, s2)\n assert x1[1:1].shape == (0,)\n \n def check_testCopySize(self):\n \"Tests of some subtle points of copying and sizing.\"\n n = [0,0,1,0,0]\n m = make_mask(n)\n m2 = make_mask(m)\n self.failUnless(m is m2)\n m3 = make_mask(m, copy=1)\n self.failUnless(m is not m3)\n \n x1 = numpy.arange(5)\n y1 = array(x1, mask=m)\n self.failUnless( y1.raw_data() is not x1)\n self.failUnless( allequal(x1,y1.raw_data()))\n self.failUnless( y1.mask is m)\n \n y1a = array(y1, copy=0)\n self.failUnless( y1a.raw_data() is y1.raw_data())\n self.failUnless( y1a.mask is y1.mask)\n \n y2 = array(x1, mask=m, copy=0)\n self.failUnless( y2.raw_data() is x1)\n self.failUnless( y2.mask is m)\n self.failUnless( y2[2] is masked)\n y2[2]=9\n self.failUnless( y2[2] is not masked)\n self.failUnless( y2.mask is not m)\n self.failUnless( allequal(y2.mask, 0))\n \n y3 = array(x1*1.0, mask=m)\n self.failUnless(filled(y3).dtype is (x1*1.0).dtype)\n \n x4 = arange(4)\n x4[2] = masked\n y4 = resize(x4, (8,))\n self.failUnless( eq(concatenate([x4,x4]), y4))\n self.failUnless( eq(getmask(y4),[0,0,1,0,0,0,1,0]))\n y5 = repeat(x4, (2,2,2,2))\n self.failUnless( eq(y5, [0,0,1,1,2,2,3,3]))\n y6 = repeat(x4, 2)\n self.failUnless( eq(y5, y6))\n \n def check_testPut(self):\n \"Test of put\"\n d = arange(5)\n n = [0,0,0,1,1]\n m = make_mask(n)\n x = array(d, mask = m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n x[[1,4]] = [10,40]\n self.failUnless( x.mask is not m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is not masked)\n self.failUnless( eq(x, [0,10,2,-1,40]))\n \n x = array(d, mask = m) \n x.put([-1,100,200])\n self.failUnless( eq(x, [-1,100,200,0,0]))\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n \n x = array(d, mask = m) \n x.putmask([30,40])\n self.failUnless( eq(x, [0,1,2,30,40]))\n self.failUnless( x.mask is None)\n \n x = array(d, mask = m) \n y = x.compressed()\n z = array(x, mask = m)\n z.put(y)\n assert eq (x, z)\n \n def check_testMaPut(self):\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]\n i = numpy.nonzero(m)\n putmask(xm, m, z)\n assert take(xm, i) == z\n put(ym, i, zm)\n assert take(ym, i) == zm\n \n def check_testOddFeatures(self):\n \"Test of other odd features\"\n x = arange(20); x=x.reshape(4,5)\n x.flat[5] = 12\n assert x[1,0] == 12\n z = x + 10j * x\n assert eq(z.real, x)\n assert eq(z.imag, 10*x)\n assert eq((z*conjugate(z)).real, 101*x*x)\n z.imag[...] = 0.0\n \n x = arange(10)\n x[3] = masked\n assert str(x[3]) == str(masked)\n c = x >= 8\n assert count(where(c,masked,masked)) == 0\n assert shape(where(c,masked,masked)) == c.shape\n z = where(c , x, masked)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is masked\n assert z[7] is masked\n assert z[8] is not masked\n assert z[9] is not masked\n assert eq(x,z)\n z = where(c , masked, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n z = masked_where(c, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n assert eq(x,z)\n x = array([1.,2.,3.,4.,5.])\n c = array([1,1,1,0,0])\n x[2] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n c[0] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n assert eq(masked_where(greater(x, 2), x), masked_greater(x,2))\n assert eq(masked_where(greater_equal(x, 2), x), masked_greater_equal(x,2))\n assert eq(masked_where(less(x, 2), x), masked_less(x,2))\n assert eq(masked_where(less_equal(x, 2), x), masked_less_equal(x,2))\n assert eq(masked_where(not_equal(x, 2), x), masked_not_equal(x,2))\n assert eq(masked_where(equal(x, 2), x), masked_equal(x,2))\n assert eq(masked_where(not_equal(x,2), x), masked_not_equal(x,2))\n assert eq(masked_inside(range(5), 1, 3), [0, 199, 199, 199, 4])\n assert eq(masked_outside(range(5), 1, 3),[199,1,2,3,199])\n assert eq(masked_inside(array(range(5), mask=[1,0,0,0,0]), 1, 3).mask, [1,1,1,1,0])\n assert eq(masked_outside(array(range(5), mask=[0,1,0,0,0]), 1, 3).mask, [1,1,0,0,1])\n assert eq(masked_equal(array(range(5), mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,0])\n assert eq(masked_not_equal(array([2,2,1,2,1], mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,1])\n assert eq(masked_where([1,1,0,0,0], [1,2,3,4,5]), [99,99,3,4,5])\n atest = ones((10,10,10), dtype=float32)\n btest = zeros(atest.shape, MaskType)\n ctest = masked_where(btest,atest)\n assert eq(atest,ctest)\n z = choose(c, (-x, x))\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n x = arange(6)\n x[5] = masked\n y = arange(6)*10\n y[2]= masked\n c = array([1,1,1,0,0,0], mask=[1,0,0,0,0,0])\n cm = c.filled(1)\n z = where(c,x,y)\n zm = where(cm,x,y)\n assert eq(z, zm)\n assert getmask(zm) is None\n assert eq(zm, [0,1,2,30,40,50])\n z = where(c, masked, 1)\n assert eq(z, [99,99,99,1,1,1])\n z = where(c, 1, masked)\n assert eq(z, [99, 1, 1, 99, 99, 99])\n \n def check_testMinMax(self):\n \"Test of minumum, maximum.\" \n assert eq(minimum([1,2,3],[4,0,9]), [1,0,3])\n assert eq(maximum([1,2,3],[4,0,9]), [4,2,9])\n x = arange(5)\n y = arange(5) - 2\n x[3] = masked\n y[0] = masked\n assert eq(minimum(x,y), where(less(x,y), x, y))\n assert eq(maximum(x,y), where(greater(x,y), x, y))\n assert minimum(x) == 0\n assert maximum(x) == 4\n \n def check_testTakeTransposeInnerOuter(self):\n \"Test of take, transpose, inner, outer products\"\n x = arange(24)\n y = numpy.arange(24)\n x[5:6] = masked\n x=x.reshape(2,3,4)\n y=y.reshape(2,3,4)\n assert eq(numpy.transpose(y,(2,0,1)), transpose(x,(2,0,1)))\n assert eq(numpy.take(y, (2,0,1), 1), take(x, (2,0,1), 1))\n assert eq(numpy.innerproduct(filled(x,0),filled(y,0)),\n innerproduct(x, y))\n assert eq(numpy.outerproduct(filled(x,0),filled(y,0)),\n outerproduct(x, y))\n y = array(['abc', 1, 'def', 2, 3], object)\n y[2] = masked\n t = take(y,[0,3,4])\n assert t[0] == 'abc'\n assert t[1] == 2\n assert t[2] == 3\n \n def check_testInplace(self):\n \"\"\"Test of inplace operations and rich comparisons\"\"\"\n y = arange(10)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x += 1\n assert eq(x, y+1)\n xm += 1\n assert eq(x, y+1)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x -= 1\n assert eq(x, y-1)\n xm -= 1\n assert eq(xm, y-1)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x *= 2.0\n assert eq(x, y*2)\n xm *= 2.0\n assert eq(xm, y*2)\n \n x = arange(10)*2\n xm = arange(10)\n xm[2] = masked\n x /= 2\n assert eq(x, y)\n xm /= 2\n assert eq(x, y)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x /= 2.0\n assert eq(x, y/2.0)\n xm /= arange(10)\n assert eq(xm, ones((10,)))\n \n x = arange(10).astype(float32)\n xm = arange(10)\n xm[2] = masked\n id1 = id(x.raw_data())\n x += 1.\n assert id1 == id(x.raw_data())\n assert eq(x, y+1.)\n \n def check_testPickle(self):\n \"Test of pickling\"\n x = arange(12)\n x[4:10:2] = masked\n x=x.reshape(4,3)\n f = open('test9.pik','wb')\n import pickle\n pickle.dump(x, f)\n f.close()\n f = open('test9.pik', 'rb')\n y = pickle.load(f)\n assert eq(x,y) \n \n def check_testMasked(self):\n \"Test of masked element\"\n xx=arange(6)\n xx[1] = masked\n self.failUnless(str(masked) == '--')\n self.failUnless(xx[1] is masked)\n # don't know why these should raise an exception...\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, masked)\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, 2)\n self.failUnlessRaises(Exception, lambda x,y: x+y, masked, xx)\n self.failUnlessRaises(Exception, lambda x,y: x+y, xx, masked)\n \n def check_testAverage1(self):\n \"Test of average.\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless(eq(2.0, average(ott)))\n self.failUnless(eq(2.0, average(ott, weights=[1., 1., 2., 1.])))\n result, wts = average(ott, weights=[1.,1.,2.,1.], returned=1)\n self.failUnless(eq(2.0, result))\n self.failUnless(wts == 4.0)\n ott[:] = masked\n self.failUnless(average(ott) is masked)\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n ott=ott.reshape(2,2)\n ott[:,1] = masked\n self.failUnless(eq(average(ott), [2.0, 0.0]))\n self.failUnless(average(ott,axis=1)[0] is masked)\n self.failUnless(eq([2.,0.], average(ott)))\n result, wts = average(ott, returned=1)\n self.failUnless(eq(wts, [1., 0.]))\n\n def check_testAverage2(self):\n \"More tests of average.\"\n w1 = [0,1,1,1,1,0]\n w2 = [[0,1,1,1,1,0],[1,0,0,0,0,1]]\n x=arange(6)\n self.failUnless(allclose(average(x), 2.5))\n self.failUnless(allclose(average(x, weights=w1), 2.5))\n y=array([arange(6), 2.0*arange(6)])\n self.failUnless(allclose(average(y, None), numpy.add.reduce(numpy.arange(6))*3./12.))\n self.failUnless(allclose(average(y, axis=0), numpy.arange(6) * 3./2.))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n self.failUnless(allclose(average(y, None, weights=w2), 20./6.))\n self.failUnless(allclose(average(y, axis=0, weights=w2), [0.,1.,2.,3.,4.,10.]))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n m1 = zeros(6)\n m2 = [0,0,1,1,0,0]\n m3 = [[0,0,1,1,0,0],[0,1,1,1,1,0]]\n m4 = ones(6)\n m5 = [0, 1, 1, 1, 1, 1]\n self.failUnless(allclose(average(masked_array(x, m1)), 2.5))\n self.failUnless(allclose(average(masked_array(x, m2)), 2.5))\n self.failUnless(average(masked_array(x, m4)) is masked)\n self.assertEqual(average(masked_array(x, m5)), 0.0)\n self.assertEqual(count(average(masked_array(x, m4))), 0)\n z = masked_array(y, m3)\n self.failUnless(allclose(average(z, None), 20./6.))\n self.failUnless(allclose(average(z, axis=0), [0.,1.,99.,99.,4.0, 7.5]))\n self.failUnless(allclose(average(z, axis=1), [2.5, 5.0]))\n self.failUnless(allclose( average(z,weights=w2), [0.,1., 99., 99., 4.0, 10.0]))\n \n a = arange(6)\n b = arange(6) * 3\n r1, w1 = average([[a,b],[b,a]], axis=1, returned=1)\n self.assertEqual(shape(r1) , shape(w1))\n self.assertEqual(r1.shape , w1.shape)\n r2, w2 = average(ones((2,2,3)), axis=0, weights=[3,1], returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), weights=ones((2,2,3)), returned=1)\n self.failUnless(shape(w2) == shape(r2))\n a2d = array([[1,2],[0,4]], float)\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n a2da = average(a2d)\n self.failUnless(eq (a2da, [0.5, 3.0]))\n a2dma = average(a2dm)\n self.failUnless(eq( a2dma, [1.0, 3.0]))\n a2dma = average(a2dm, axis=None)\n self.failUnless(eq(a2dma, 7./3.))\n a2dma = average(a2dm, axis=1)\n self.failUnless(eq(a2dma, [1.5, 4.0]))\n\n def check_testToPython(self):\n self.assertEqual(1, int(array(1)))\n self.assertEqual(1.0, float(array(1)))\n self.assertEqual(1, int(array([[[1]]])))\n self.assertEqual(1.0, float(array([[1]])))\n self.failUnlessRaises(ValueError, float, array([1,1]))\n self.failUnlessRaises(MAError, float, array([1],mask=[1]))\n self.failUnless(bool(array([0,1])))\n self.failUnless(bool(array([0,0],mask=[0,1])))\n self.failIf(bool(array([0,0])))\n self.failIf(bool(array([0,0],mask=[0,0])))\n\n def check_testScalarArithmetic(self):\n xm = array(0, mask=1)\n self.failUnless((1/array(0)).mask)\n self.failUnless((1 + xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless(maximum(xm, xm).mask)\n self.failUnless(minimum(xm, xm).mask)\n self.failUnless(xm.filled().dtype is xm.data.dtype)\n x = array(0, mask=0)\n self.failUnless(x.filled() is x.data)\n \ndef timingTest():\n for f in [testf, testinplace]:\n for n in [1000,10000,50000]:\n t = testta(n, f)\n t1 = testtb(n, f)\n t2 = testtc(n, f)\n print f.test_name\n print \"\"\"\\\nn = %7d \nnumpy time (ms) %6.1f \nMA maskless ratio %6.1f\nMA masked ratio %6.1f\n\"\"\" % (n, t*1000.0, t1/t, t2/t)\n\ndef testta(n, f):\n x=numpy.arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtb(n, f):\n x=arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtc(n, f):\n x=arange(n) + 1.0\n x[0] = masked\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testf(x):\n for i in range(25):\n y = x **2 + 2.0 * x - 1.0\n w = x **2 + 1.0\n z = (y / w) ** 2\n return z\ntestf.test_name = 'Simple arithmetic'\n\ndef testinplace(x):\n for i in range(25):\n y = x**2\n y += 2.0*x\n y -= 1.0\n y /= x\n return y\ntestinplace.test_name = 'Inplace operations'\n\nif __name__ == \"__main__\":\n ScipyTest('numpy.core.ma').run() \n #timingTest()\n", + "source_code_before": "import numpy \nimport types, time\nfrom numpy.core.ma import *\nfrom numpy.testing import ScipyTestCase, ScipyTest\ndef eq(v,w):\n result = allclose(v,w)\n if not result:\n print \"\"\"Not eq:\n%s\n----\n%s\"\"\"% (str(v), str(w))\n return result\n\nclass test_ma(ScipyTestCase):\n def __init__(self, *args, **kwds):\n ScipyTestCase.__init__(self, *args, **kwds)\n self.setUp()\n \n def setUp (self):\n x=numpy.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])\n y=numpy.array([5.,0.,3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])\n a10 = 10.\n m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]\n m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0 ,0, 1]\n xm = array(x, mask=m1)\n ym = array(y, mask=m2)\n z = numpy.array([-.5, 0., .5, .8])\n zm = array(z, mask=[0,1,0,0])\n xf = numpy.where(m1, 1.e+20, x)\n s = x.shape\n xm.set_fill_value(1.e+20)\n self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf, s)\n\n def check_testBasic1d(self):\n \"Test of basic array creation and properties in 1 dimension.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual(xm.dtype, x.dtype)\n self.assertEqual(xm.dtypechar, x.dtypechar)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual(count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n\n def check_testBasic2d(self):\n \"Test of basic array creation and properties in 2 dimensions.\"\n for s in [(4,3), (6,2)]: \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n x.shape = s\n y.shape = s\n xm.shape = s\n ym.shape = s\n xf.shape = s\n \n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual( count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n self.setUp()\n\n def check_testArithmetic (self):\n \"Test of basic arithmetic.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n a2d = array([[1,2],[0,4]])\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n self.failUnless(eq (a2d * a2d, a2d * a2dm))\n self.failUnless(eq (a2d + a2d, a2d + a2dm))\n self.failUnless(eq (a2d - a2d, a2d - a2dm))\n for s in [(12,), (4,3), (2,6)]: \n x = x.reshape(s)\n y = y.reshape(s)\n xm = xm.reshape(s)\n ym = ym.reshape(s)\n xf = xf.reshape(s)\n self.failUnless(eq(-x, -xm))\n self.failUnless(eq(x + y, xm + ym))\n self.failUnless(eq(x - y, xm - ym))\n self.failUnless(eq(x * y, xm * ym))\n self.failUnless(eq(x / y, xm / ym))\n self.failUnless(eq(a10 + y, a10 + ym))\n self.failUnless(eq(a10 - y, a10 - ym))\n self.failUnless(eq(a10 * y, a10 * ym))\n self.failUnless(eq(a10 / y, a10 / ym))\n self.failUnless(eq(x + a10, xm + a10))\n self.failUnless(eq(x - a10, xm - a10))\n self.failUnless(eq(x * a10, xm * a10))\n self.failUnless(eq(x / a10, xm / a10))\n self.failUnless(eq(x**2, xm**2))\n self.failUnless(eq(abs(x)**2.5, abs(xm) **2.5))\n self.failUnless(eq(x**y, xm**ym))\n self.failUnless(eq(numpy.add(x,y), add(xm, ym)))\n self.failUnless(eq(numpy.subtract(x,y), subtract(xm, ym)))\n self.failUnless(eq(numpy.multiply(x,y), multiply(xm, ym)))\n self.failUnless(eq(numpy.divide(x,y), divide(xm, ym)))\n\n\n def check_testMixedArithmetic(self):\n na = numpy.array([1])\n ma = array([1])\n self.failUnless(isinstance(na + ma, MaskedArray))\n self.failUnless(isinstance(ma + na, MaskedArray))\n \n def check_testUfuncs1 (self):\n \"Test various functions such as sin, cos.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.cos(x), cos(xm)))\n self.failUnless (eq(numpy.cosh(x), cosh(xm)))\n self.failUnless (eq(numpy.sin(x), sin(xm)))\n self.failUnless (eq(numpy.sinh(x), sinh(xm)))\n self.failUnless (eq(numpy.tan(x), tan(xm)))\n self.failUnless (eq(numpy.tanh(x), tanh(xm)))\n self.failUnless (eq(numpy.sqrt(abs(x)), sqrt(xm)))\n self.failUnless (eq(numpy.log(abs(x)), log(xm)))\n self.failUnless (eq(numpy.log10(abs(x)), log10(xm)))\n self.failUnless (eq(numpy.exp(x), exp(xm)))\n self.failUnless (eq(numpy.arcsin(z), arcsin(zm)))\n self.failUnless (eq(numpy.arccos(z), arccos(zm)))\n self.failUnless (eq(numpy.arctan(z), arctan(zm)))\n self.failUnless (eq(numpy.arctan2(x, y), arctan2(xm, ym)))\n self.failUnless (eq(numpy.absolute(x), absolute(xm)))\n self.failUnless (eq(numpy.equal(x,y), equal(xm, ym)))\n self.failUnless (eq(numpy.not_equal(x,y), not_equal(xm, ym)))\n self.failUnless (eq(numpy.less(x,y), less(xm, ym)))\n self.failUnless (eq(numpy.greater(x,y), greater(xm, ym)))\n self.failUnless (eq(numpy.less_equal(x,y), less_equal(xm, ym)))\n self.failUnless (eq(numpy.greater_equal(x,y), greater_equal(xm, ym)))\n self.failUnless (eq(numpy.conjugate(x), conjugate(xm)))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,ym))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((x,y))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,y))))\n self.failUnless (eq(numpy.concatenate((x,y,x)), concatenate((x,ym,x))))\n \n def check_xtestCount (self):\n \"Test count\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless( isinstance(count(ott), types.IntType))\n self.assertEqual(3, count(ott))\n self.assertEqual(1, count(1))\n self.failUnless (eq(0, array(1,mask=[1])))\n ott=ott.reshape((2,2))\n assert isMaskedArray(count(ott,0))\n assert isinstance(count(ott), types.IntType)\n self.failUnless (eq(3, count(ott)))\n assert getmask(count(ott,0)) is None\n self.failUnless (eq([1,2],count(ott,0)))\n \n def check_testMinMax (self):\n \"Test minimum and maximum.\" \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n xr = numpy.ravel(x) #max doesn't work if shaped\n xmr = ravel(xm)\n self.failUnless (eq(max(xr), maximum(xmr))) #true because of careful selection of data\n self.failUnless (eq(min(xr), minimum(xmr))) #true because of careful selection of data\n\n def check_testAddSumProd (self):\n \"Test add, sum, product.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.add.reduce(x), add.reduce(x)))\n self.failUnless (eq(numpy.add.accumulate(x), add.accumulate(x)))\n self.failUnless (eq(4, sum(array(4))))\n self.failUnless (eq(4, sum(array(4), axis=0)))\n self.failUnless (eq(numpy.sum(x), sum(x)))\n self.failUnless (eq(numpy.sum(filled(xm,0)), sum(xm)))\n self.failUnless (eq(numpy.sum(x,0), sum(x,0)))\n self.failUnless (eq(numpy.product(x), product(x)))\n self.failUnless (eq(numpy.product(x,0), product(x,0)))\n self.failUnless (eq(numpy.product(filled(xm,1)), product(xm)))\n if len(s) > 1:\n self.failUnless (eq(numpy.concatenate((x,y),1), concatenate((xm,ym),1)))\n self.failUnless (eq(numpy.add.reduce(x,1), add.reduce(x,1)))\n self.failUnless (eq(numpy.sum(x,1), sum(x,1)))\n self.failUnless (eq(numpy.product(x,1), product(x,1)))\n \n \n def check_testCI(self):\n \"Test of conversions and indexing\"\n x1 = numpy.array([1,2,4,3])\n x2 = array(x1, mask = [1,0,0,0])\n x3 = array(x1, mask = [0,1,0,1])\n x4 = array(x1)\n # test conversion to strings\n junk, garbage = str(x2), repr(x2)\n assert eq(numpy.sort(x1),sort(x2, fill_value=0))\n # tests of indexing\n assert type(x2[1]) is type(x1[1])\n assert x1[1] == x2[1]\n assert x2[0] is masked\n assert eq(x1[2],x2[2])\n assert eq(x1[2:5],x2[2:5])\n assert eq(x1[:],x2[:])\n assert eq(x1[1:], x3[1:])\n x1[2]=9\n x2[2]=9\n assert eq(x1,x2)\n x1[1:3] = 99\n x2[1:3] = 99\n assert eq(x1,x2)\n x2[1] = masked\n assert eq(x1,x2)\n x2[1:3]=masked\n assert eq(x1,x2)\n x2[:] = x1\n x2[1] = masked\n assert allequal(getmask(x2),array([0,1,0,0]))\n x3[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x3), array([0,1,1,0]))\n x4[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x4), array([0,1,1,0]))\n assert allequal(x4, array([1,2,3,4]))\n x1 = numpy.arange(5)*1.0\n x2 = masked_values(x1, 3.0)\n assert eq(x1,x2)\n assert allequal(array([0,0,0,1,0],MaskType), x2.mask)\n assert eq(3.0, x2.fill_value())\n x1 = array([1,'hello',2,3],object)\n x2 = numpy.array([1,'hello',2,3],object)\n s1 = x1[1].item()\n s2 = x2[1].item()\n self.assertEqual(type(s2), str)\n self.assertEqual(type(s1), str)\n self.assertEqual(s1, s2)\n assert x1[1:1].shape == (0,)\n \n def check_testCopySize(self):\n \"Tests of some subtle points of copying and sizing.\"\n n = [0,0,1,0,0]\n m = make_mask(n)\n m2 = make_mask(m)\n self.failUnless(m is m2)\n m3 = make_mask(m, copy=1)\n self.failUnless(m is not m3)\n \n x1 = numpy.arange(5)\n y1 = array(x1, mask=m)\n self.failUnless( y1.raw_data() is not x1)\n self.failUnless( allequal(x1,y1.raw_data()))\n self.failUnless( y1.mask is m)\n \n y1a = array(y1, copy=0)\n self.failUnless( y1a.raw_data() is y1.raw_data())\n self.failUnless( y1a.mask is y1.mask)\n \n y2 = array(x1, mask=m, copy=0)\n self.failUnless( y2.raw_data() is x1)\n self.failUnless( y2.mask is m)\n self.failUnless( y2[2] is masked)\n y2[2]=9\n self.failUnless( y2[2] is not masked)\n self.failUnless( y2.mask is not m)\n self.failUnless( allequal(y2.mask, 0))\n \n y3 = array(x1*1.0, mask=m)\n self.failUnless(filled(y3).dtype is (x1*1.0).dtype)\n \n x4 = arange(4)\n x4[2] = masked\n y4 = resize(x4, (8,))\n self.failUnless( eq(concatenate([x4,x4]), y4))\n self.failUnless( eq(getmask(y4),[0,0,1,0,0,0,1,0]))\n y5 = repeat(x4, (2,2,2,2))\n self.failUnless( eq(y5, [0,0,1,1,2,2,3,3]))\n y6 = repeat(x4, 2)\n self.failUnless( eq(y5, y6))\n \n def check_testPut(self):\n \"Test of put\"\n d = arange(5)\n n = [0,0,0,1,1]\n m = make_mask(n)\n x = array(d, mask = m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n x[[1,4]] = [10,40]\n self.failUnless( x.mask is not m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is not masked)\n self.failUnless( eq(x, [0,10,2,-1,40]))\n \n x = array(d, mask = m) \n x.put([-1,100,200])\n self.failUnless( eq(x, [-1,100,200,0,0]))\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n \n x = array(d, mask = m) \n x.putmask([30,40])\n self.failUnless( eq(x, [0,1,2,30,40]))\n self.failUnless( x.mask is None)\n \n x = array(d, mask = m) \n y = x.compressed()\n z = array(x, mask = m)\n z.put(y)\n assert eq (x, z)\n \n def check_testMaPut(self):\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]\n i = numpy.nonzero(m)\n putmask(xm, m, z)\n assert take(xm, i) == z\n put(ym, i, zm)\n assert take(ym, i) == zm\n \n def check_testOddFeatures(self):\n \"Test of other odd features\"\n x = arange(20); x=x.reshape(4,5)\n x.flat[5] = 12\n assert x[1,0] == 12\n z = x + 10j * x\n assert eq(z.real, x)\n assert eq(z.imag, 10*x)\n assert eq((z*conjugate(z)).real, 101*x*x)\n z.imag[...] = 0.0\n \n x = arange(10)\n x[3] = masked\n assert str(x[3]) == str(masked)\n c = x >= 8\n assert count(where(c,masked,masked)) == 0\n assert shape(where(c,masked,masked)) == c.shape\n z = where(c , x, masked)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is masked\n assert z[7] is masked\n assert z[8] is not masked\n assert z[9] is not masked\n assert eq(x,z)\n z = where(c , masked, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n z = masked_where(c, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n assert eq(x,z)\n x = array([1.,2.,3.,4.,5.])\n c = array([1,1,1,0,0])\n x[2] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n c[0] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n assert eq(masked_where(greater(x, 2), x), masked_greater(x,2))\n assert eq(masked_where(greater_equal(x, 2), x), masked_greater_equal(x,2))\n assert eq(masked_where(less(x, 2), x), masked_less(x,2))\n assert eq(masked_where(less_equal(x, 2), x), masked_less_equal(x,2))\n assert eq(masked_where(not_equal(x, 2), x), masked_not_equal(x,2))\n assert eq(masked_where(equal(x, 2), x), masked_equal(x,2))\n assert eq(masked_where(not_equal(x,2), x), masked_not_equal(x,2))\n assert eq(masked_inside(range(5), 1, 3), [0, 199, 199, 199, 4])\n assert eq(masked_outside(range(5), 1, 3),[199,1,2,3,199])\n assert eq(masked_inside(array(range(5), mask=[1,0,0,0,0]), 1, 3).mask, [1,1,1,1,0])\n assert eq(masked_outside(array(range(5), mask=[0,1,0,0,0]), 1, 3).mask, [1,1,0,0,1])\n assert eq(masked_equal(array(range(5), mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,0])\n assert eq(masked_not_equal(array([2,2,1,2,1], mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,1])\n assert eq(masked_where([1,1,0,0,0], [1,2,3,4,5]), [99,99,3,4,5])\n atest = ones((10,10,10), dtype=float32)\n btest = zeros(atest.shape, MaskType)\n ctest = masked_where(btest,atest)\n assert eq(atest,ctest)\n z = choose(c, (-x, x))\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n x = arange(6)\n x[5] = masked\n y = arange(6)*10\n y[2]= masked\n c = array([1,1,1,0,0,0], mask=[1,0,0,0,0,0])\n cm = c.filled(1)\n z = where(c,x,y)\n zm = where(cm,x,y)\n assert eq(z, zm)\n assert getmask(zm) is None\n assert eq(zm, [0,1,2,30,40,50])\n z = where(c, masked, 1)\n assert eq(z, [99,99,99,1,1,1])\n z = where(c, 1, masked)\n assert eq(z, [99, 1, 1, 99, 99, 99])\n \n def check_testMinMax(self):\n \"Test of minumum, maximum.\" \n assert eq(minimum([1,2,3],[4,0,9]), [1,0,3])\n assert eq(maximum([1,2,3],[4,0,9]), [4,2,9])\n x = arange(5)\n y = arange(5) - 2\n x[3] = masked\n y[0] = masked\n assert eq(minimum(x,y), where(less(x,y), x, y))\n assert eq(maximum(x,y), where(greater(x,y), x, y))\n assert minimum(x) == 0\n assert maximum(x) == 4\n \n def check_testTakeTransposeInnerOuter(self):\n \"Test of take, transpose, inner, outer products\"\n x = arange(24)\n y = numpy.arange(24)\n x[5:6] = masked\n x=x.reshape(2,3,4)\n y=y.reshape(2,3,4)\n assert eq(numpy.transpose(y,(2,0,1)), transpose(x,(2,0,1)))\n assert eq(numpy.take(y, (2,0,1), 1), take(x, (2,0,1), 1))\n assert eq(numpy.innerproduct(filled(x,0),filled(y,0)),\n innerproduct(x, y))\n assert eq(numpy.outerproduct(filled(x,0),filled(y,0)),\n outerproduct(x, y))\n y = array(['abc', 1, 'def', 2, 3], object)\n y[2] = masked\n t = take(y,[0,3,4])\n assert t[0].item() == 'abc'\n assert t[1].item() == 2\n assert t[2].item() == 3\n \n def check_testInplace(self):\n \"\"\"Test of inplace operations and rich comparisons\"\"\"\n y = arange(10)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x += 1\n assert eq(x, y+1)\n xm += 1\n assert eq(x, y+1)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x -= 1\n assert eq(x, y-1)\n xm -= 1\n assert eq(xm, y-1)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x *= 2.0\n assert eq(x, y*2)\n xm *= 2.0\n assert eq(xm, y*2)\n \n x = arange(10)*2\n xm = arange(10)\n xm[2] = masked\n x /= 2\n assert eq(x, y)\n xm /= 2\n assert eq(x, y)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x /= 2.0\n assert eq(x, y/2.0)\n xm /= arange(10)\n assert eq(xm, ones((10,)))\n \n x = arange(10).astype(float32)\n xm = arange(10)\n xm[2] = masked\n id1 = id(x.raw_data())\n x += 1.\n assert id1 == id(x.raw_data())\n assert eq(x, y+1.)\n \n def check_testPickle(self):\n \"Test of pickling\"\n x = arange(12)\n x[4:10:2] = masked\n x=x.reshape(4,3)\n f = open('test9.pik','wb')\n import pickle\n pickle.dump(x, f)\n f.close()\n f = open('test9.pik', 'rb')\n y = pickle.load(f)\n assert eq(x,y) \n \n def check_testMasked(self):\n \"Test of masked element\"\n xx=arange(6)\n xx[1] = masked\n self.failUnless(str(masked) == '--')\n self.failUnless(xx[1] is masked)\n # don't know why these should raise an exception...\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, masked)\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, 2)\n self.failUnlessRaises(Exception, lambda x,y: x+y, masked, xx)\n self.failUnlessRaises(Exception, lambda x,y: x+y, xx, masked)\n \n def check_testAverage1(self):\n \"Test of average.\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless(eq(2.0, average(ott)))\n self.failUnless(eq(2.0, average(ott, weights=[1., 1., 2., 1.])))\n result, wts = average(ott, weights=[1.,1.,2.,1.], returned=1)\n self.failUnless(eq(2.0, result))\n self.failUnless(wts == 4.0)\n ott[:] = masked\n self.failUnless(average(ott) is masked)\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n ott=ott.reshape(2,2)\n ott[:,1] = masked\n self.failUnless(eq(average(ott), [2.0, 0.0]))\n self.failUnless(average(ott,axis=1)[0] is masked)\n self.failUnless(eq([2.,0.], average(ott)))\n result, wts = average(ott, returned=1)\n self.failUnless(eq(wts, [1., 0.]))\n\n def check_testAverage2(self):\n \"More tests of average.\"\n w1 = [0,1,1,1,1,0]\n w2 = [[0,1,1,1,1,0],[1,0,0,0,0,1]]\n x=arange(6)\n self.failUnless(allclose(average(x), 2.5))\n self.failUnless(allclose(average(x, weights=w1), 2.5))\n y=array([arange(6), 2.0*arange(6)])\n self.failUnless(allclose(average(y, None), numpy.add.reduce(numpy.arange(6))*3./12.))\n self.failUnless(allclose(average(y, axis=0), numpy.arange(6) * 3./2.))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n self.failUnless(allclose(average(y, None, weights=w2), 20./6.))\n self.failUnless(allclose(average(y, axis=0, weights=w2), [0.,1.,2.,3.,4.,10.]))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n m1 = zeros(6)\n m2 = [0,0,1,1,0,0]\n m3 = [[0,0,1,1,0,0],[0,1,1,1,1,0]]\n m4 = ones(6)\n m5 = [0, 1, 1, 1, 1, 1]\n self.failUnless(allclose(average(masked_array(x, m1)), 2.5))\n self.failUnless(allclose(average(masked_array(x, m2)), 2.5))\n self.failUnless(average(masked_array(x, m4)) is masked)\n self.assertEqual(average(masked_array(x, m5)), 0.0)\n self.assertEqual(count(average(masked_array(x, m4))), 0)\n z = masked_array(y, m3)\n self.failUnless(allclose(average(z, None), 20./6.))\n self.failUnless(allclose(average(z, axis=0), [0.,1.,99.,99.,4.0, 7.5]))\n self.failUnless(allclose(average(z, axis=1), [2.5, 5.0]))\n self.failUnless(allclose( average(z,weights=w2), [0.,1., 99., 99., 4.0, 10.0]))\n \n a = arange(6)\n b = arange(6) * 3\n r1, w1 = average([[a,b],[b,a]], axis=1, returned=1)\n self.assertEqual(shape(r1) , shape(w1))\n self.assertEqual(r1.shape , w1.shape)\n r2, w2 = average(ones((2,2,3)), axis=0, weights=[3,1], returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), weights=ones((2,2,3)), returned=1)\n self.failUnless(shape(w2) == shape(r2))\n a2d = array([[1,2],[0,4]], float)\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n a2da = average(a2d)\n self.failUnless(eq (a2da, [0.5, 3.0]))\n a2dma = average(a2dm)\n self.failUnless(eq( a2dma, [1.0, 3.0]))\n a2dma = average(a2dm, axis=None)\n self.failUnless(eq(a2dma, 7./3.))\n a2dma = average(a2dm, axis=1)\n self.failUnless(eq(a2dma, [1.5, 4.0]))\n\n def check_testToPython(self):\n self.assertEqual(1, int(array(1)))\n self.assertEqual(1.0, float(array(1)))\n self.assertEqual(1, int(array([[[1]]])))\n self.assertEqual(1.0, float(array([[1]])))\n self.failUnlessRaises(ValueError, float, array([1,1]))\n self.failUnlessRaises(MAError, float, array([1],mask=[1]))\n self.failUnless(bool(array([0,1])))\n self.failUnless(bool(array([0,0],mask=[0,1])))\n self.failIf(bool(array([0,0])))\n self.failIf(bool(array([0,0],mask=[0,0])))\n\n def check_testScalarArithmetic(self):\n xm = array(0, mask=1)\n self.failUnless((1/array(0)).mask)\n self.failUnless((1 + xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless(maximum(xm, xm).mask)\n self.failUnless(minimum(xm, xm).mask)\n self.failUnless(xm.filled().dtype is xm.data.dtype)\n x = array(0, mask=0)\n self.failUnless(x.filled() is x.data)\n \ndef timingTest():\n for f in [testf, testinplace]:\n for n in [1000,10000,50000]:\n t = testta(n, f)\n t1 = testtb(n, f)\n t2 = testtc(n, f)\n print f.test_name\n print \"\"\"\\\nn = %7d \nnumpy time (ms) %6.1f \nMA maskless ratio %6.1f\nMA masked ratio %6.1f\n\"\"\" % (n, t*1000.0, t1/t, t2/t)\n\ndef testta(n, f):\n x=numpy.arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtb(n, f):\n x=arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtc(n, f):\n x=arange(n) + 1.0\n x[0] = masked\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testf(x):\n for i in range(25):\n y = x **2 + 2.0 * x - 1.0\n w = x **2 + 1.0\n z = (y / w) ** 2\n return z\ntestf.test_name = 'Simple arithmetic'\n\ndef testinplace(x):\n for i in range(25):\n y = x**2\n y += 2.0*x\n y -= 1.0\n y /= x\n return y\ntestinplace.test_name = 'Inplace operations'\n\nif __name__ == \"__main__\":\n ScipyTest('numpy.core.ma').run() \n #timingTest()\n", + "methods": [ + { + "name": "eq", + "long_name": "eq( v , w )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "v", + "w" + ], + "start_line": 5, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , * args , ** kwds )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 15, + "end_line": 17, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 276, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 32, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic1d", + "long_name": "check_testBasic1d( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 186, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 47, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic2d", + "long_name": "check_testBasic2d( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 2, + "token_count": 209, + "parameters": [ + "self" + ], + "start_line": 49, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "check_testArithmetic", + "long_name": "check_testArithmetic( self )", + "filename": "test_ma.py", + "nloc": 34, + "complexity": 2, + "token_count": 518, + "parameters": [ + "self" + ], + "start_line": 70, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "check_testMixedArithmetic", + "long_name": "check_testMixedArithmetic( self )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 106, + "end_line": 110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_testUfuncs1", + "long_name": "check_testUfuncs1( self )", + "filename": "test_ma.py", + "nloc": 29, + "complexity": 1, + "token_count": 600, + "parameters": [ + "self" + ], + "start_line": 112, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "check_xtestCount", + "long_name": "check_xtestCount( self )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 1, + "token_count": 174, + "parameters": [ + "self" + ], + "start_line": 142, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 156, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_testAddSumProd", + "long_name": "check_testAddSumProd( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 2, + "token_count": 361, + "parameters": [ + "self" + ], + "start_line": 164, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testCI", + "long_name": "check_testCI( self )", + "filename": "test_ma.py", + "nloc": 46, + "complexity": 1, + "token_count": 560, + "parameters": [ + "self" + ], + "start_line": 184, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 1 + }, + { + "name": "check_testCopySize", + "long_name": "check_testCopySize( self )", + "filename": "test_ma.py", + "nloc": 35, + "complexity": 1, + "token_count": 409, + "parameters": [ + "self" + ], + "start_line": 233, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 1 + }, + { + "name": "check_testPut", + "long_name": "check_testPut( self )", + "filename": "test_ma.py", + "nloc": 27, + "complexity": 1, + "token_count": 291, + "parameters": [ + "self" + ], + "start_line": 274, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "check_testMaPut", + "long_name": "check_testMaPut( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 101, + "parameters": [ + "self" + ], + "start_line": 305, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_testOddFeatures", + "long_name": "check_testOddFeatures( self )", + "filename": "test_ma.py", + "nloc": 88, + "complexity": 1, + "token_count": 1188, + "parameters": [ + "self" + ], + "start_line": 314, + "end_line": 402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 154, + "parameters": [ + "self" + ], + "start_line": 404, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testTakeTransposeInnerOuter", + "long_name": "check_testTakeTransposeInnerOuter( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 1, + "token_count": 235, + "parameters": [ + "self" + ], + "start_line": 417, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "check_testInplace", + "long_name": "check_testInplace( self )", + "filename": "test_ma.py", + "nloc": 44, + "complexity": 1, + "token_count": 315, + "parameters": [ + "self" + ], + "start_line": 437, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testPickle", + "long_name": "check_testPickle( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 489, + "end_line": 500, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testMasked", + "long_name": "check_testMasked( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 502, + "end_line": 512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage1", + "long_name": "check_testAverage1( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 1, + "token_count": 289, + "parameters": [ + "self" + ], + "start_line": 514, + "end_line": 531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage2", + "long_name": "check_testAverage2( self )", + "filename": "test_ma.py", + "nloc": 50, + "complexity": 1, + "token_count": 945, + "parameters": [ + "self" + ], + "start_line": 533, + "end_line": 583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testToPython", + "long_name": "check_testToPython( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 193, + "parameters": [ + "self" + ], + "start_line": 585, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testScalarArithmetic", + "long_name": "check_testScalarArithmetic( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 597, + "end_line": 607, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "timingTest", + "long_name": "timingTest( )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 3, + "token_count": 72, + "parameters": [], + "start_line": 609, + "end_line": 621, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "testta", + "long_name": "testta( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 40, + "parameters": [ + "n", + "f" + ], + "start_line": 623, + "end_line": 627, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtb", + "long_name": "testtb( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 38, + "parameters": [ + "n", + "f" + ], + "start_line": 629, + "end_line": 633, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtc", + "long_name": "testtc( n , f )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 44, + "parameters": [ + "n", + "f" + ], + "start_line": 635, + "end_line": 640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testf", + "long_name": "testf( x )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 48, + "parameters": [ + "x" + ], + "start_line": 642, + "end_line": 647, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testinplace", + "long_name": "testinplace( x )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 36, + "parameters": [ + "x" + ], + "start_line": 650, + "end_line": 656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "eq", + "long_name": "eq( v , w )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "v", + "w" + ], + "start_line": 5, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , * args , ** kwds )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 15, + "end_line": 17, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 276, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 32, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic1d", + "long_name": "check_testBasic1d( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 186, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 47, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic2d", + "long_name": "check_testBasic2d( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 2, + "token_count": 209, + "parameters": [ + "self" + ], + "start_line": 49, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "check_testArithmetic", + "long_name": "check_testArithmetic( self )", + "filename": "test_ma.py", + "nloc": 34, + "complexity": 2, + "token_count": 518, + "parameters": [ + "self" + ], + "start_line": 70, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "check_testMixedArithmetic", + "long_name": "check_testMixedArithmetic( self )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 106, + "end_line": 110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_testUfuncs1", + "long_name": "check_testUfuncs1( self )", + "filename": "test_ma.py", + "nloc": 29, + "complexity": 1, + "token_count": 600, + "parameters": [ + "self" + ], + "start_line": 112, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "check_xtestCount", + "long_name": "check_xtestCount( self )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 1, + "token_count": 174, + "parameters": [ + "self" + ], + "start_line": 142, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 156, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_testAddSumProd", + "long_name": "check_testAddSumProd( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 2, + "token_count": 361, + "parameters": [ + "self" + ], + "start_line": 164, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testCI", + "long_name": "check_testCI( self )", + "filename": "test_ma.py", + "nloc": 46, + "complexity": 1, + "token_count": 568, + "parameters": [ + "self" + ], + "start_line": 184, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 1 + }, + { + "name": "check_testCopySize", + "long_name": "check_testCopySize( self )", + "filename": "test_ma.py", + "nloc": 35, + "complexity": 1, + "token_count": 409, + "parameters": [ + "self" + ], + "start_line": 233, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 1 + }, + { + "name": "check_testPut", + "long_name": "check_testPut( self )", + "filename": "test_ma.py", + "nloc": 27, + "complexity": 1, + "token_count": 291, + "parameters": [ + "self" + ], + "start_line": 274, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "check_testMaPut", + "long_name": "check_testMaPut( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 101, + "parameters": [ + "self" + ], + "start_line": 305, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_testOddFeatures", + "long_name": "check_testOddFeatures( self )", + "filename": "test_ma.py", + "nloc": 88, + "complexity": 1, + "token_count": 1188, + "parameters": [ + "self" + ], + "start_line": 314, + "end_line": 402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 154, + "parameters": [ + "self" + ], + "start_line": 404, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testTakeTransposeInnerOuter", + "long_name": "check_testTakeTransposeInnerOuter( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 1, + "token_count": 247, + "parameters": [ + "self" + ], + "start_line": 417, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "check_testInplace", + "long_name": "check_testInplace( self )", + "filename": "test_ma.py", + "nloc": 44, + "complexity": 1, + "token_count": 315, + "parameters": [ + "self" + ], + "start_line": 437, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testPickle", + "long_name": "check_testPickle( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 489, + "end_line": 500, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testMasked", + "long_name": "check_testMasked( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 502, + "end_line": 512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage1", + "long_name": "check_testAverage1( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 1, + "token_count": 289, + "parameters": [ + "self" + ], + "start_line": 514, + "end_line": 531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage2", + "long_name": "check_testAverage2( self )", + "filename": "test_ma.py", + "nloc": 50, + "complexity": 1, + "token_count": 945, + "parameters": [ + "self" + ], + "start_line": 533, + "end_line": 583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testToPython", + "long_name": "check_testToPython( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 193, + "parameters": [ + "self" + ], + "start_line": 585, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testScalarArithmetic", + "long_name": "check_testScalarArithmetic( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 597, + "end_line": 607, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "timingTest", + "long_name": "timingTest( )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 3, + "token_count": 72, + "parameters": [], + "start_line": 609, + "end_line": 621, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "testta", + "long_name": "testta( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 40, + "parameters": [ + "n", + "f" + ], + "start_line": 623, + "end_line": 627, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtb", + "long_name": "testtb( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 38, + "parameters": [ + "n", + "f" + ], + "start_line": 629, + "end_line": 633, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtc", + "long_name": "testtc( n , f )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 44, + "parameters": [ + "n", + "f" + ], + "start_line": 635, + "end_line": 640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testf", + "long_name": "testf( x )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 48, + "parameters": [ + "x" + ], + "start_line": 642, + "end_line": 647, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testinplace", + "long_name": "testinplace( x )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 36, + "parameters": [ + "x" + ], + "start_line": 650, + "end_line": 656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "check_testCI", + "long_name": "check_testCI( self )", + "filename": "test_ma.py", + "nloc": 46, + "complexity": 1, + "token_count": 560, + "parameters": [ + "self" + ], + "start_line": 184, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 1 + }, + { + "name": "check_testTakeTransposeInnerOuter", + "long_name": "check_testTakeTransposeInnerOuter( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 1, + "token_count": 235, + "parameters": [ + "self" + ], + "start_line": 417, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + } + ], + "nloc": 604, + "complexity": 39, + "token_count": 7845, + "diff_parsed": { + "added": [ + " s1 = x1[1]", + " s2 = x2[1]", + " assert t[0] == 'abc'", + " assert t[1] == 2", + " assert t[2] == 3" + ], + "deleted": [ + " s1 = x1[1].item()", + " s2 = x2[1].item()", + " assert t[0].item() == 'abc'", + " assert t[1].item() == 2", + " assert t[2].item() == 3" + ] + } + }, + { + "old_path": "numpy/core/tests/test_multiarray.py", + "new_path": "numpy/core/tests/test_multiarray.py", + "filename": "test_multiarray.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -76,16 +76,16 @@ def setUp(self):\n def check_ellipsis_subscript(self):\n a,b = self.d\n self.failUnlessEqual(a[...], 0)\n- self.failUnlessEqual(b[...].item(), 'x')\n+ self.failUnlessEqual(b[...], 'x')\n self.failUnless(type(a[...]) is a.dtype)\n- self.failUnless(type(b[...]) is b.dtype)\n+ self.failUnless(type(b[...]) is str)\n \n def check_empty_subscript(self):\n a,b = self.d\n self.failUnlessEqual(a[()], 0)\n- self.failUnlessEqual(b[()].item(), 'x')\n+ self.failUnlessEqual(b[()], 'x')\n self.failUnless(type(a[()]) is a.dtype)\n- self.failUnless(type(b[()]) is b.dtype)\n+\tself.failUnless(type(b[()]) is str)\n \n def check_invalid_subscript(self):\n a,b = self.d\n", + "added_lines": 4, + "deleted_lines": 4, + "source_code": "\nfrom numpy.testing import *\nfrom numpy.core import *\n\nclass test_flags(ScipyTestCase):\n def setUp(self):\n self.a = arange(10)\n\n def check_writeable(self):\n mydict = locals()\n self.a.flags.writeable = False\n self.assertRaises(RuntimeError, runstring, 'self.a[0] = 3', mydict)\n self.a.flags.writeable = True\n self.a[0] = 5\n self.a[0] = 0\n\n def check_otherflags(self):\n assert_equal(self.a.flags.carray, True)\n assert_equal(self.a.flags.farray, False)\n assert_equal(self.a.flags.behaved, True)\n assert_equal(self.a.flags.fnc, False)\n assert_equal(self.a.flags.forc, True)\n assert_equal(self.a.flags.owndata, True)\n assert_equal(self.a.flags.writeable, True)\n assert_equal(self.a.flags.aligned, True)\n assert_equal(self.a.flags.updateifcopy, False)\n \n\nclass test_attributes(ScipyTestCase):\n def setUp(self):\n self.one = arange(10)\n self.two = arange(20).reshape(4,5)\n self.three = arange(60,dtype=float64).reshape(2,5,6)\n\n def check_attributes(self):\n assert_equal(self.one.shape, (10,))\n assert_equal(self.two.shape, (4,5))\n assert_equal(self.three.shape, (2,5,6))\n self.three.shape = (10,3,2)\n assert_equal(self.three.shape, (10,3,2))\n self.three.shape = (2,5,6)\n assert_equal(self.one.strides, (self.one.itemsize,))\n num = self.two.itemsize\n assert_equal(self.two.strides, (5*num, num))\n num = self.three.itemsize\n assert_equal(self.three.strides, (30*num, 6*num, num))\n assert_equal(self.one.ndim, 1)\n assert_equal(self.two.ndim, 2)\n assert_equal(self.three.ndim, 3)\n num = self.two.itemsize \n assert_equal(self.two.size, 20)\n assert_equal(self.two.nbytes, 20*num)\n assert_equal(self.two.itemsize, self.two.dtypedescr.itemsize)\n assert_equal(self.two.base, arange(20))\n\n def check_dtypeattr(self):\n assert_equal(self.one.dtype, int_)\n assert_equal(self.three.dtype, float_)\n assert_equal(self.one.dtypechar, 'l')\n assert_equal(self.three.dtypechar, 'd')\n self.failUnless(self.three.dtypestr[0] in '<>')\n assert_equal(self.one.dtypestr[1], 'i')\n assert_equal(self.three.dtypestr[1], 'f')\n\nclass test_dtypedescr(ScipyTestCase):\n def check_construction(self):\n d1 = dtypedescr('i4')\n assert_equal(d1, dtypedescr(int32))\n d2 = dtypedescr('f8')\n assert_equal(d2, dtypedescr(float64))\n \nclass test_zero_rank(ScipyTestCase):\n def setUp(self):\n self.d = array(0), array('x', object)\n \n def check_ellipsis_subscript(self):\n a,b = self.d\n self.failUnlessEqual(a[...], 0)\n self.failUnlessEqual(b[...], 'x')\n self.failUnless(type(a[...]) is a.dtype)\n self.failUnless(type(b[...]) is str)\n \n def check_empty_subscript(self):\n a,b = self.d\n self.failUnlessEqual(a[()], 0)\n self.failUnlessEqual(b[()], 'x')\n self.failUnless(type(a[()]) is a.dtype)\n\tself.failUnless(type(b[()]) is str)\n\n def check_invalid_subscript(self):\n a,b = self.d\n self.failUnlessRaises(IndexError, lambda x: x[0], a)\n self.failUnlessRaises(IndexError, lambda x: x[0], b)\n self.failUnlessRaises(IndexError, lambda x: x[array([], int)], a)\n self.failUnlessRaises(IndexError, lambda x: x[array([], int)], b)\n\n def check_ellipsis_subscript_assignment(self):\n a,b = self.d\n a[...] = 42\n self.failUnlessEqual(a, 42)\n b[...] = ''\n self.failUnlessEqual(b.item(), '')\n \n def check_empty_subscript_assignment(self):\n a,b = self.d\n a[()] = 42\n self.failUnlessEqual(a, 42)\n b[()] = ''\n self.failUnlessEqual(b.item(), '')\n\n def check_invalid_subscript_assignment(self):\n a,b = self.d\n def assign(x, i, v):\n x[i] = v\n self.failUnlessRaises(IndexError, assign, a, 0, 42)\n self.failUnlessRaises(IndexError, assign, b, 0, '')\n self.failUnlessRaises(TypeError, assign, a, (), '')\n\n def check_newaxis(self):\n a,b = self.d\n self.failUnlessEqual(a[newaxis].shape, (1,))\n self.failUnlessEqual(a[..., newaxis].shape, (1,))\n self.failUnlessEqual(a[newaxis, ...].shape, (1,))\n self.failUnlessEqual(a[..., newaxis].shape, (1,))\n self.failUnlessEqual(a[newaxis, ..., newaxis].shape, (1,1))\n self.failUnlessEqual(a[..., newaxis, newaxis].shape, (1,1))\n self.failUnlessEqual(a[newaxis, newaxis, ...].shape, (1,1))\n self.failUnlessEqual(a[(newaxis,)*10].shape, (1,)*10)\n\n def check_invalid_newaxis(self):\n a,b = self.d\n def subscript(x, i): x[i]\n self.failUnlessRaises(IndexError, subscript, a, (newaxis, 0))\n self.failUnlessRaises(IndexError, subscript, a, (newaxis,)*50)\n\nif __name__ == \"__main__\":\n ScipyTest('numpy.core.multiarray').run()\n", + "source_code_before": "\nfrom numpy.testing import *\nfrom numpy.core import *\n\nclass test_flags(ScipyTestCase):\n def setUp(self):\n self.a = arange(10)\n\n def check_writeable(self):\n mydict = locals()\n self.a.flags.writeable = False\n self.assertRaises(RuntimeError, runstring, 'self.a[0] = 3', mydict)\n self.a.flags.writeable = True\n self.a[0] = 5\n self.a[0] = 0\n\n def check_otherflags(self):\n assert_equal(self.a.flags.carray, True)\n assert_equal(self.a.flags.farray, False)\n assert_equal(self.a.flags.behaved, True)\n assert_equal(self.a.flags.fnc, False)\n assert_equal(self.a.flags.forc, True)\n assert_equal(self.a.flags.owndata, True)\n assert_equal(self.a.flags.writeable, True)\n assert_equal(self.a.flags.aligned, True)\n assert_equal(self.a.flags.updateifcopy, False)\n \n\nclass test_attributes(ScipyTestCase):\n def setUp(self):\n self.one = arange(10)\n self.two = arange(20).reshape(4,5)\n self.three = arange(60,dtype=float64).reshape(2,5,6)\n\n def check_attributes(self):\n assert_equal(self.one.shape, (10,))\n assert_equal(self.two.shape, (4,5))\n assert_equal(self.three.shape, (2,5,6))\n self.three.shape = (10,3,2)\n assert_equal(self.three.shape, (10,3,2))\n self.three.shape = (2,5,6)\n assert_equal(self.one.strides, (self.one.itemsize,))\n num = self.two.itemsize\n assert_equal(self.two.strides, (5*num, num))\n num = self.three.itemsize\n assert_equal(self.three.strides, (30*num, 6*num, num))\n assert_equal(self.one.ndim, 1)\n assert_equal(self.two.ndim, 2)\n assert_equal(self.three.ndim, 3)\n num = self.two.itemsize \n assert_equal(self.two.size, 20)\n assert_equal(self.two.nbytes, 20*num)\n assert_equal(self.two.itemsize, self.two.dtypedescr.itemsize)\n assert_equal(self.two.base, arange(20))\n\n def check_dtypeattr(self):\n assert_equal(self.one.dtype, int_)\n assert_equal(self.three.dtype, float_)\n assert_equal(self.one.dtypechar, 'l')\n assert_equal(self.three.dtypechar, 'd')\n self.failUnless(self.three.dtypestr[0] in '<>')\n assert_equal(self.one.dtypestr[1], 'i')\n assert_equal(self.three.dtypestr[1], 'f')\n\nclass test_dtypedescr(ScipyTestCase):\n def check_construction(self):\n d1 = dtypedescr('i4')\n assert_equal(d1, dtypedescr(int32))\n d2 = dtypedescr('f8')\n assert_equal(d2, dtypedescr(float64))\n \nclass test_zero_rank(ScipyTestCase):\n def setUp(self):\n self.d = array(0), array('x', object)\n \n def check_ellipsis_subscript(self):\n a,b = self.d\n self.failUnlessEqual(a[...], 0)\n self.failUnlessEqual(b[...].item(), 'x')\n self.failUnless(type(a[...]) is a.dtype)\n self.failUnless(type(b[...]) is b.dtype)\n \n def check_empty_subscript(self):\n a,b = self.d\n self.failUnlessEqual(a[()], 0)\n self.failUnlessEqual(b[()].item(), 'x')\n self.failUnless(type(a[()]) is a.dtype)\n self.failUnless(type(b[()]) is b.dtype)\n\n def check_invalid_subscript(self):\n a,b = self.d\n self.failUnlessRaises(IndexError, lambda x: x[0], a)\n self.failUnlessRaises(IndexError, lambda x: x[0], b)\n self.failUnlessRaises(IndexError, lambda x: x[array([], int)], a)\n self.failUnlessRaises(IndexError, lambda x: x[array([], int)], b)\n\n def check_ellipsis_subscript_assignment(self):\n a,b = self.d\n a[...] = 42\n self.failUnlessEqual(a, 42)\n b[...] = ''\n self.failUnlessEqual(b.item(), '')\n \n def check_empty_subscript_assignment(self):\n a,b = self.d\n a[()] = 42\n self.failUnlessEqual(a, 42)\n b[()] = ''\n self.failUnlessEqual(b.item(), '')\n\n def check_invalid_subscript_assignment(self):\n a,b = self.d\n def assign(x, i, v):\n x[i] = v\n self.failUnlessRaises(IndexError, assign, a, 0, 42)\n self.failUnlessRaises(IndexError, assign, b, 0, '')\n self.failUnlessRaises(TypeError, assign, a, (), '')\n\n def check_newaxis(self):\n a,b = self.d\n self.failUnlessEqual(a[newaxis].shape, (1,))\n self.failUnlessEqual(a[..., newaxis].shape, (1,))\n self.failUnlessEqual(a[newaxis, ...].shape, (1,))\n self.failUnlessEqual(a[..., newaxis].shape, (1,))\n self.failUnlessEqual(a[newaxis, ..., newaxis].shape, (1,1))\n self.failUnlessEqual(a[..., newaxis, newaxis].shape, (1,1))\n self.failUnlessEqual(a[newaxis, newaxis, ...].shape, (1,1))\n self.failUnlessEqual(a[(newaxis,)*10].shape, (1,)*10)\n\n def check_invalid_newaxis(self):\n a,b = self.d\n def subscript(x, i): x[i]\n self.failUnlessRaises(IndexError, subscript, a, (newaxis, 0))\n self.failUnlessRaises(IndexError, subscript, a, (newaxis,)*50)\n\nif __name__ == \"__main__\":\n ScipyTest('numpy.core.multiarray').run()\n", + "methods": [ + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_multiarray.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 6, + "end_line": 7, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_writeable", + "long_name": "check_writeable( self )", + "filename": "test_multiarray.py", + "nloc": 7, + "complexity": 1, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9, + "end_line": 15, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_otherflags", + "long_name": "check_otherflags( self )", + "filename": "test_multiarray.py", + "nloc": 10, + "complexity": 1, + "token_count": 113, + "parameters": [ + "self" + ], + "start_line": 17, + "end_line": 26, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_multiarray.py", + "nloc": 4, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 30, + "end_line": 33, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "check_attributes", + "long_name": "check_attributes( self )", + "filename": "test_multiarray.py", + "nloc": 20, + "complexity": 1, + "token_count": 245, + "parameters": [ + "self" + ], + "start_line": 35, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "check_dtypeattr", + "long_name": "check_dtypeattr( self )", + "filename": "test_multiarray.py", + "nloc": 8, + "complexity": 1, + "token_count": 86, + "parameters": [ + "self" + ], + "start_line": 56, + "end_line": 63, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_construction", + "long_name": "check_construction( self )", + "filename": "test_multiarray.py", + "nloc": 5, + "complexity": 1, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 66, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_multiarray.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 73, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_ellipsis_subscript", + "long_name": "check_ellipsis_subscript( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 64, + "parameters": [ + "self" + ], + "start_line": 76, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_empty_subscript", + "long_name": "check_empty_subscript( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 83, + "end_line": 88, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_invalid_subscript", + "long_name": "check_invalid_subscript( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 88, + "parameters": [ + "self" + ], + "start_line": 90, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_ellipsis_subscript_assignment", + "long_name": "check_ellipsis_subscript_assignment( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 97, + "end_line": 102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_empty_subscript_assignment", + "long_name": "check_empty_subscript_assignment( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 104, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_invalid_subscript_assignment.assign", + "long_name": "check_invalid_subscript_assignment.assign( x , i , v )", + "filename": "test_multiarray.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "x", + "i", + "v" + ], + "start_line": 113, + "end_line": 114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 2 + }, + { + "name": "check_invalid_subscript_assignment", + "long_name": "check_invalid_subscript_assignment( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 111, + "end_line": 117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_newaxis", + "long_name": "check_newaxis( self )", + "filename": "test_multiarray.py", + "nloc": 10, + "complexity": 1, + "token_count": 168, + "parameters": [ + "self" + ], + "start_line": 119, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "check_invalid_newaxis.subscript", + "long_name": "check_invalid_newaxis.subscript( x , i )", + "filename": "test_multiarray.py", + "nloc": 3, + "complexity": 1, + "token_count": 44, + "parameters": [ + "x", + "i" + ], + "start_line": 132, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 2 + } + ], + "methods_before": [ + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_multiarray.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 6, + "end_line": 7, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_writeable", + "long_name": "check_writeable( self )", + "filename": "test_multiarray.py", + "nloc": 7, + "complexity": 1, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9, + "end_line": 15, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_otherflags", + "long_name": "check_otherflags( self )", + "filename": "test_multiarray.py", + "nloc": 10, + "complexity": 1, + "token_count": 113, + "parameters": [ + "self" + ], + "start_line": 17, + "end_line": 26, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_multiarray.py", + "nloc": 4, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 30, + "end_line": 33, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "check_attributes", + "long_name": "check_attributes( self )", + "filename": "test_multiarray.py", + "nloc": 20, + "complexity": 1, + "token_count": 245, + "parameters": [ + "self" + ], + "start_line": 35, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "check_dtypeattr", + "long_name": "check_dtypeattr( self )", + "filename": "test_multiarray.py", + "nloc": 8, + "complexity": 1, + "token_count": 86, + "parameters": [ + "self" + ], + "start_line": 56, + "end_line": 63, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_construction", + "long_name": "check_construction( self )", + "filename": "test_multiarray.py", + "nloc": 5, + "complexity": 1, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 66, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_multiarray.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 73, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_ellipsis_subscript", + "long_name": "check_ellipsis_subscript( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 70, + "parameters": [ + "self" + ], + "start_line": 76, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_empty_subscript", + "long_name": "check_empty_subscript( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 74, + "parameters": [ + "self" + ], + "start_line": 83, + "end_line": 88, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_invalid_subscript", + "long_name": "check_invalid_subscript( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 88, + "parameters": [ + "self" + ], + "start_line": 90, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_ellipsis_subscript_assignment", + "long_name": "check_ellipsis_subscript_assignment( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 97, + "end_line": 102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_empty_subscript_assignment", + "long_name": "check_empty_subscript_assignment( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 104, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_invalid_subscript_assignment.assign", + "long_name": "check_invalid_subscript_assignment.assign( x , i , v )", + "filename": "test_multiarray.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "x", + "i", + "v" + ], + "start_line": 113, + "end_line": 114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 2 + }, + { + "name": "check_invalid_subscript_assignment", + "long_name": "check_invalid_subscript_assignment( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 111, + "end_line": 117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_newaxis", + "long_name": "check_newaxis( self )", + "filename": "test_multiarray.py", + "nloc": 10, + "complexity": 1, + "token_count": 168, + "parameters": [ + "self" + ], + "start_line": 119, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "check_invalid_newaxis.subscript", + "long_name": "check_invalid_newaxis.subscript( x , i )", + "filename": "test_multiarray.py", + "nloc": 3, + "complexity": 1, + "token_count": 44, + "parameters": [ + "x", + "i" + ], + "start_line": 132, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 2 + } + ], + "changed_methods": [ + { + "name": "check_empty_subscript", + "long_name": "check_empty_subscript( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 83, + "end_line": 88, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_ellipsis_subscript", + "long_name": "check_ellipsis_subscript( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 64, + "parameters": [ + "self" + ], + "start_line": 76, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + } + ], + "nloc": 118, + "complexity": 17, + "token_count": 1288, + "diff_parsed": { + "added": [ + " self.failUnlessEqual(b[...], 'x')", + " self.failUnless(type(b[...]) is str)", + " self.failUnlessEqual(b[()], 'x')", + "\tself.failUnless(type(b[()]) is str)" + ], + "deleted": [ + " self.failUnlessEqual(b[...].item(), 'x')", + " self.failUnless(type(b[...]) is b.dtype)", + " self.failUnlessEqual(b[()].item(), 'x')", + " self.failUnless(type(b[()]) is b.dtype)" + ] + } + } + ] + }, + { + "hash": "74cc5f80fedd223b3dace284a7456c5d16187b52", + "msg": "Fix up use of aligned keyword.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-11T18:36:18+00:00", + "author_timezone": 0, + "committer_date": "2006-01-11T18:36:18+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "f547239676d6803e8644bacb3023aa0aed031425" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 17, + "insertions": 19, + "lines": 36, + "files": 2, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.5, + "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": "@@ -8140,9 +8140,11 @@ arraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n \tPyArray_Descr *descr, *conv;\n \tint align=0;\n \tBool copy=FALSE;\n+\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};\n \t\n-\tif (!PyArg_ParseTuple(args, \"O|iO&\", &odescr, &align,\n-\t\t\t PyArray_BoolConverter, ©))\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 \t\n \tif (align) {\n@@ -8152,8 +8154,7 @@ arraydescr_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\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, \n-\t\t\t\t\t\t\t\t 1);\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", + "added_lines": 5, + "deleted_lines": 4, + "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\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\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=NULL;\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\tdescr = PyArray_DescrFromType(PyArray_INTP);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else 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} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\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=NULL;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\tdescr = PyArray_DescrFromType(PyArray_INT);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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} else 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) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\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\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 if (PyBigArray_CheckExact(obj)) \n return PyArray_BIG_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\t\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\t\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\t\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\t\n dest_strides_ptr = dest_strides;\n\t\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\t\n new_data = (char *)_pya_malloc(stride);\n\t\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\t\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\t\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\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\nstatic PyArray_Descr **userdescrs=NULL;\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\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\t\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\n/* If destination is not the right type, then src \n will be cast to destination. \n*/\n\n/* Does a flat iterator-based copy. \n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however. \n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n \n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError, \n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->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, elsize);\n PyArray_INCREF(dest);\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 memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\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\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t dest->descr, 0,\n\t\t\t\t\t dest->nd, FORTRAN_IF(dest));\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\t\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/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\t\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\t\n return (PyObject *)ret;\t\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_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 (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}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize / sizeof(Py_UNICODE);\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\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, itemsize);\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/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\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\t\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\t\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 fwrite(sep, 1, n3, fp);\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\t\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\t\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\t\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\t\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\t\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\t\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \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\t\t\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\t\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\nstatic PyObject *\narray_item_nice(PyArrayObject *self, int i) \n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\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\t\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 SIZEOF_INT == SIZEOF_INTP\n#define array_ass_item array_ass_big_item\n#else\nstatic int\narray_ass_item(PyArrayObject *self, int 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\t\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\t\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\t\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\t\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\t\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\t\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\t\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);\t\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\t\n nd_old = nd_new = 0;\n\t\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\t\t\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 }\t \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\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\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);\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->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\t\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);\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}\n\t}\n\t\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, PyArray_ITEMSIZE(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}\t\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\t\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/* 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;\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\t\t\t\t\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\t\t\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\treturn PyArray_ToScalar(self->data, self);\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\treturn PyArray_ToScalar(self->data, self);\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n\t/* wrap arguments into a mapiter object */\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(op, oned);\n if (mit == NULL) return NULL;\n if (!mit->view) { /* fancy indexing */\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 Py_DECREF(mit);\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\t\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\t\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;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\t\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\t\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\t\t\t\t\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\t\t\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(index, oned);\n if (mit == NULL) return -1;\n if (!mit->view) {\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 Py_DECREF(mit);\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\t\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\treturn PyArray_Return((PyArrayObject *)array_subscript(self, op));\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n (inquiry)array_length,\t\t /*mp_length*/\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 \narray_getsegcount(PyArrayObject *self, int *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 \narray_getreadbuf(PyArrayObject *self, int 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 \narray_getwritebuf(PyArrayObject *self, int 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 \narray_getcharbuf(PyArrayObject *self, int 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 (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};\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\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;\t\n\t\n} NumericOps;\n\nstatic NumericOps n_ops = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL};\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\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);\t \n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\t\n SET(true_divide);\t\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\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;\t\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\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);\t \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\treturn dict;\t\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\t\t\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}\t\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}\t\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 *\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 PyObject *\narray_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.power);\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 *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.power);\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\t\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;\t \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 an \"\\\n\t\t\t\t\"int; 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;\t \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;\t \n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v) \n{\t \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;\t \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;\t \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*/\t\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 ilow, int ihigh) \n{\n PyArrayObject *r;\n int l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n \t\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\n self->dimensions[0] = l;\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 ilow, int ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\t\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\t\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\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, 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\n\nstatic PySequenceMethods array_as_sequence = {\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};\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\t\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\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\t\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\t\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\t\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\t\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\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\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 return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\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.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\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\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\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; ind == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tintp sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\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\t\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;\t\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by a single segment array of the provided \n dimensions and element size. If numbytes is 0 it will be calculated from \n the provided shape and element size.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\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;\t\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 */\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, \n\t\t\t intp *newstrides, int oldnd)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\t\n\told = *des;\n\t*des = old->subarray->base;\n\n\tmydim = newdims + oldnd;\n\tif (PyTuple_Check(old->subarray->shape)) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t\t\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tnumnew = 1;\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\t\n\tnewnd = oldnd + numnew;\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\t/* Make new strides */\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\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{\t\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\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);\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\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\t\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { /* strides is NULL too */\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\t\t\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\t\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 {\n\t\t\tif (data == NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"if 'strides' is given in \" \\\n\t\t\t\t\t\t\"array creation, data must \" \\\n\t\t\t\t\t\t\"be given too\");\n\t\t\t\tgoto fail;\n\t\t\t} \n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t} \t\n\t\t\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\t\tif (descr == &OBJECT_Descr) {\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 and some object passed in */\n\tif ((obj != NULL) && (subtype != &PyArray_Type) && \n\t (subtype != &PyBigArray_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 (!(self->flags & OWNDATA)) { /* did not allocate own data */\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\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\t\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*/\nstatic PyObject * \nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape)\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\t\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n \"resize only works on contiguous arrays\");\n return NULL;\n }\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\t\t\n\t\trefcnt = REFCOUNT(self);\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\t\t\t\t\n\t\tif (newsize == 0) sd = self->descr->elsize;\t\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 0, &(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);\t\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);\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\twhile (size--) {\n\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\ttoptr += itemsize;\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\t\t\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, itemsize);\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\", \n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", 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\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*/\t\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\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 &fortran)) \n\t\tgoto fail;\n\t\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\t\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\\\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 NULL, 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\t\tbuffer.len -= offset;\n\t\tbuffer.ptr += offset;\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\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 (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\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 (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 PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\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\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\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;\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 != NULL) {\n\t\tif (PyArray_Check(new->base)) \n\t\t\tnew = (PyArrayObject *)new->base;\n\t}\n\tnumbytes = PyArray_MultiplyList(new->dimensions, \n\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes, \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 if (PyBigArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_BIG_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}\t\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 *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISEXTENDED(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->descr->elsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\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 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\t\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\t\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\t\n\telse if (newtype->elsize > self->descr->elsize) {\n\t\t\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\t\t\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\t\t\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\ttemp = (PyArrayObject *)\\\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\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tPy_DECREF(newtype);\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator */\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\ttemp->descr = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype; \n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\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\t\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"arrdescr\");\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_type_get(PyArrayObject *self)\n{\n Py_INCREF(self->descr->typeobj);\n return (PyObject *)self->descr->typeobj;\n}\n\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);\n\tif (new == NULL) return -1;\n\t\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) {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}\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{\t\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{\t\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); \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);\t\t\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));\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->descr->elsize);\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 {\"dtype\", \n\t (getter)array_type_get, \n\t NULL,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n\t{\"dtypedescr\", \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.dtypedescr object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\t\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.bigndarray\",\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 NULL, \t\t\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\t\t\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n NULL, \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/* A standard array will subclass from the Big Array and \n add the array_as_sequence table\n and the array_as_buffer table\n */\n\nstatic PyTypeObject PyArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n};\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\t\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;\t\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\t\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, sizeof(Py_UNICODE)*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\t\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, 2*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\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\t\n\tif (minitype == NULL) \n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\t\n if (max < 0) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\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 \t\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\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\t\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\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_BOOL);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_LONG);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_DOUBLE);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_CDOUBLE);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\n finish:\n\t\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\t\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\t\n l=PyObject_Length(v);\n if(l < 0) return -1; \n\t\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\t\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 *= sizeof(Py_UNICODE);\n\t}\n\n\tret = (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\n\tif (ret == NULL) return NULL;\n\n ret->descr->f->setitem(op, ret->data, ret);\n\t\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 unless return value is NULL*/\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\tPyArray_Descr *savetype=typecode;\n\t\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\t\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 return NULL;\n }\n\t\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 return NULL;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\treturn NULL;\n\t\t}\n\t\tif (type == PyArray_UNICODE) itemsize*=sizeof(Py_UNICODE);\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\t\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\t\n if(!r) {Py_XINCREF(savetype); return NULL;}\n if(Assign_Array(r,s) == -1) {\n\t\tPy_XINCREF(savetype);\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\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\t\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\t\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\t\t\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\t\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\t\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, elsize);\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\t\t\t\t\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\t\t\t\t\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 oelsize);\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);\t\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\t\t\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*sizeof(Py_UNICODE);\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize/sizeof(Py_UNICODE);\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\t\n\tPy_DECREF(out);\n\treturn NULL;\n\t\n}\n\t \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\t\t\t\t\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * outsize;\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\t\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 */\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) \n{\n\t\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\t\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 (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\t\t\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 != &PyBigArray_Type)) {\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 (subtype != &PyBigArray_Type)) {\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\t\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 != &PyBigArray_Type)) {\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\t\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}\t\t\n\t\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;\t \n\t\telse _MY_FAIL \n\t\t\tbreak;\t\t \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;\t\t \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;\t\t \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\t\tbreak;\n\tcase 'S':\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase 'U':\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize *= sizeof(Py_UNICODE);\n\t\tbreak;\t \n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\t\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/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_fromstructinterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r, *ret;\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_XDECREF(intype);\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_XDECREF(intype);\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 ret = array_fromarray((PyArrayObject*)r, intype, flags);\n Py_DECREF(r);\n return ret;\n}\n\n/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n PyObject *tstr=NULL, *shape=NULL; \n\tPyArrayObject *ret=NULL;\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\t\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\tPy_XDECREF(intype);\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\tPy_XDECREF(intype);\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\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n\n fail:\n\tPy_XDECREF(intype);\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* steals a reference to typecode */\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Descr *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode == NULL) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyObject *obj;\n\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", typecode->type,\n\t\t\t\t\t\t typecode->elsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(typecode->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\n if (new == NULL) {Py_XDECREF(typecode); 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\t\tPy_DECREF(typecode);\n return NULL;\n }\n r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n/* Steals a reference to newtype --- which can be NULL */\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Descr *newtype, int min_depth, \n\t\t int max_depth, int flags) \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 = array_fromarray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if ((r = array_fromstructinterface(op, newtype, flags)) != \\\n\t\t Py_NotImplemented) {\n }\n else if ((r = array_frominterface(op, newtype, flags)) !=\t\\\n\t\t Py_NotImplemented) {\n\t}\n else if (PyObject_HasAttrString(op, \"__array__\")) {\n /* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, newtype, flags);\n }\n\telse {\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\t\t\t\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 PyErr_Clear();\n else\n seq = TRUE;\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\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\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\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_FromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n\t\tint max_depth, int requires) \n{\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\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 array_fromobject(op, descr, min_depth, max_depth,\n \t\t\t\trequires);\t\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 or PyBigArray_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) || PyBigArray_CheckExact(op)) return op;\n \n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FROM_OF(op, ENSUREARRAY);\n Py_DECREF(op);\n return new;\n}\n\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 * sizeof(Py_UNICODE)\\\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.\t\t \n\t\t*/\n\t}\n\treturn ret;\n}\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\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\t\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\t\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\t\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/* 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\niter_length(PyArrayIterObject *self) \n{\n return (int) 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, itemsize);\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\t\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, itemsize);\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;\t\t\t\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */ \t\n\t\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, size);\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);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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\t\t\t\t\t FORCECAST | ALIGNED);\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,\n\t\t\t\t itemsize);\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, itemsize);\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, itemsize);\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\t\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\t\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0);\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, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\t\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, itemsize);\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, itemsize);\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);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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_FromAny(obj, indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\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\t\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n (inquiry)iter_length,\t\t /*mp_length*/\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;\t\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\t{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 0, /* 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/* 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/* 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);\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\t\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\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\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 sizeof(intp));\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\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\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 sizeof(intp));\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 sizeof(intp));\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\t\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\t \n\tif (mit->view) return;\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\n\tsub = PyObject_GetItem((PyObject *)arr, mit->indexobj);\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\t\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\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\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= 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) *indptr, (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);\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\t\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->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_IndexError,\t\t\t\\\n\t\t\t\t\"arrays used as indices must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_IndexError, \"too many indices\");\n\t\tgoto fail;\n\t}\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\t\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);\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 ret:\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\t\n\tint i, err=0;\n\t\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\t\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\t\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);\t\n\t\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\t\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\t\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\t\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\t\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\t\n return (PyObject *)multi;\n\t\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\t_pya_free(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);\t\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 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/*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;\t\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(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 dtypedescr objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"dtype\", 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\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\tchar basic_=self->kind;\n\tchar endian = self->byteorder;\n\t\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\t\n\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t self->elsize);\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{\"subdescr\", \n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"arrdescr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"dtypestr\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\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\t\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\t\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, \"dtypedescr\");\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\tobj = PyString_FromFormat(\"%c%d\",self->kind, self->elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\t\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\t\n\tif (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\t\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\t\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\t\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*/\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\t\t\t\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 dtypedescr 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 dtypedescr object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\t\t\t\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);\t\t\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(\"dtypedescr(\");\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 dtypedescr 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\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtypedescr\",\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 0, \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", + "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\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\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=NULL;\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\tdescr = PyArray_DescrFromType(PyArray_INTP);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else 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} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\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=NULL;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\tdescr = PyArray_DescrFromType(PyArray_INT);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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} else 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) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\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\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 if (PyBigArray_CheckExact(obj)) \n return PyArray_BIG_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\t\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\t\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\t\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\t\n dest_strides_ptr = dest_strides;\n\t\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\t\n new_data = (char *)_pya_malloc(stride);\n\t\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\t\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\t\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\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\nstatic PyArray_Descr **userdescrs=NULL;\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\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\t\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\n/* If destination is not the right type, then src \n will be cast to destination. \n*/\n\n/* Does a flat iterator-based copy. \n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however. \n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n \n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError, \n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->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, elsize);\n PyArray_INCREF(dest);\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 memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\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\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t dest->descr, 0,\n\t\t\t\t\t dest->nd, FORTRAN_IF(dest));\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\t\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/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\t\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\t\n return (PyObject *)ret;\t\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_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 (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}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize / sizeof(Py_UNICODE);\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\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, itemsize);\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/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\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\t\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\t\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 fwrite(sep, 1, n3, fp);\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\t\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\t\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\t\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\t\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\t\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\t\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \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\t\t\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\t\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\nstatic PyObject *\narray_item_nice(PyArrayObject *self, int i) \n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\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\t\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 SIZEOF_INT == SIZEOF_INTP\n#define array_ass_item array_ass_big_item\n#else\nstatic int\narray_ass_item(PyArrayObject *self, int 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\t\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\t\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\t\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\t\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\t\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\t\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\t\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);\t\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\t\n nd_old = nd_new = 0;\n\t\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\t\t\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 }\t \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\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\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);\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->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\t\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);\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}\n\t}\n\t\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, PyArray_ITEMSIZE(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}\t\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\t\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/* 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;\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\t\t\t\t\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\t\t\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\treturn PyArray_ToScalar(self->data, self);\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\treturn PyArray_ToScalar(self->data, self);\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n\t/* wrap arguments into a mapiter object */\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(op, oned);\n if (mit == NULL) return NULL;\n if (!mit->view) { /* fancy indexing */\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 Py_DECREF(mit);\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\t\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\t\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;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\t\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\t\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\t\t\t\t\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\t\t\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(index, oned);\n if (mit == NULL) return -1;\n if (!mit->view) {\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 Py_DECREF(mit);\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\t\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\treturn PyArray_Return((PyArrayObject *)array_subscript(self, op));\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n (inquiry)array_length,\t\t /*mp_length*/\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 \narray_getsegcount(PyArrayObject *self, int *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 \narray_getreadbuf(PyArrayObject *self, int 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 \narray_getwritebuf(PyArrayObject *self, int 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 \narray_getcharbuf(PyArrayObject *self, int 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 (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};\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\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;\t\n\t\n} NumericOps;\n\nstatic NumericOps n_ops = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL};\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\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);\t \n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\t\n SET(true_divide);\t\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\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;\t\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\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);\t \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\treturn dict;\t\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\t\t\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}\t\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}\t\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 *\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 PyObject *\narray_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.power);\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 *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.power);\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\t\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;\t \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 an \"\\\n\t\t\t\t\"int; 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;\t \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;\t \n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v) \n{\t \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;\t \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;\t \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*/\t\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 ilow, int ihigh) \n{\n PyArrayObject *r;\n int l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n \t\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\n self->dimensions[0] = l;\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 ilow, int ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\t\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\t\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\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, 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\n\nstatic PySequenceMethods array_as_sequence = {\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};\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\t\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\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\t\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\t\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\t\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\t\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\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\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 return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\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.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\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\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\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; ind == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tintp sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\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\t\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;\t\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by a single segment array of the provided \n dimensions and element size. If numbytes is 0 it will be calculated from \n the provided shape and element size.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\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;\t\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 */\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, \n\t\t\t intp *newstrides, int oldnd)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\t\n\told = *des;\n\t*des = old->subarray->base;\n\n\tmydim = newdims + oldnd;\n\tif (PyTuple_Check(old->subarray->shape)) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t\t\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tnumnew = 1;\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\t\n\tnewnd = oldnd + numnew;\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\t/* Make new strides */\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\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{\t\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\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);\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\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\t\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { /* strides is NULL too */\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\t\t\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\t\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 {\n\t\t\tif (data == NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"if 'strides' is given in \" \\\n\t\t\t\t\t\t\"array creation, data must \" \\\n\t\t\t\t\t\t\"be given too\");\n\t\t\t\tgoto fail;\n\t\t\t} \n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t} \t\n\t\t\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\t\tif (descr == &OBJECT_Descr) {\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 and some object passed in */\n\tif ((obj != NULL) && (subtype != &PyArray_Type) && \n\t (subtype != &PyBigArray_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 (!(self->flags & OWNDATA)) { /* did not allocate own data */\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\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\t\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*/\nstatic PyObject * \nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape)\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\t\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n \"resize only works on contiguous arrays\");\n return NULL;\n }\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\t\t\n\t\trefcnt = REFCOUNT(self);\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\t\t\t\t\n\t\tif (newsize == 0) sd = self->descr->elsize;\t\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 0, &(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);\t\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);\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\twhile (size--) {\n\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\ttoptr += itemsize;\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\t\t\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, itemsize);\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\", \n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", 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\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*/\t\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\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 &fortran)) \n\t\tgoto fail;\n\t\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\t\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\\\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 NULL, 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\t\tbuffer.len -= offset;\n\t\tbuffer.ptr += offset;\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\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 (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\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 (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 PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\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\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\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;\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 != NULL) {\n\t\tif (PyArray_Check(new->base)) \n\t\t\tnew = (PyArrayObject *)new->base;\n\t}\n\tnumbytes = PyArray_MultiplyList(new->dimensions, \n\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes, \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 if (PyBigArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_BIG_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}\t\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 *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISEXTENDED(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->descr->elsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\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 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\t\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\t\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\t\n\telse if (newtype->elsize > self->descr->elsize) {\n\t\t\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\t\t\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\t\t\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\ttemp = (PyArrayObject *)\\\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\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tPy_DECREF(newtype);\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator */\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\ttemp->descr = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype; \n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\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\t\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"arrdescr\");\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_type_get(PyArrayObject *self)\n{\n Py_INCREF(self->descr->typeobj);\n return (PyObject *)self->descr->typeobj;\n}\n\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);\n\tif (new == NULL) return -1;\n\t\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) {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}\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{\t\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{\t\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); \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);\t\t\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));\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->descr->elsize);\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 {\"dtype\", \n\t (getter)array_type_get, \n\t NULL,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n\t{\"dtypedescr\", \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.dtypedescr object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\t\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.bigndarray\",\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 NULL, \t\t\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\t\t\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n NULL, \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/* A standard array will subclass from the Big Array and \n add the array_as_sequence table\n and the array_as_buffer table\n */\n\nstatic PyTypeObject PyArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n};\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\t\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;\t\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\t\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, sizeof(Py_UNICODE)*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\t\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, 2*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\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\t\n\tif (minitype == NULL) \n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\t\n if (max < 0) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\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 \t\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\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\t\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\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_BOOL);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_LONG);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_DOUBLE);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_CDOUBLE);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\n finish:\n\t\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\t\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\t\n l=PyObject_Length(v);\n if(l < 0) return -1; \n\t\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\t\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 *= sizeof(Py_UNICODE);\n\t}\n\n\tret = (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\n\tif (ret == NULL) return NULL;\n\n ret->descr->f->setitem(op, ret->data, ret);\n\t\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 unless return value is NULL*/\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\tPyArray_Descr *savetype=typecode;\n\t\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\t\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 return NULL;\n }\n\t\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 return NULL;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\treturn NULL;\n\t\t}\n\t\tif (type == PyArray_UNICODE) itemsize*=sizeof(Py_UNICODE);\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\t\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\t\n if(!r) {Py_XINCREF(savetype); return NULL;}\n if(Assign_Array(r,s) == -1) {\n\t\tPy_XINCREF(savetype);\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\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\t\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\t\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\t\t\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\t\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\t\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, elsize);\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\t\t\t\t\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\t\t\t\t\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 oelsize);\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);\t\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\t\t\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*sizeof(Py_UNICODE);\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize/sizeof(Py_UNICODE);\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\t\n\tPy_DECREF(out);\n\treturn NULL;\n\t\n}\n\t \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\t\t\t\t\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * outsize;\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\t\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 */\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) \n{\n\t\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\t\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 (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\t\t\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 != &PyBigArray_Type)) {\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 (subtype != &PyBigArray_Type)) {\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\t\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 != &PyBigArray_Type)) {\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\t\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}\t\t\n\t\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;\t \n\t\telse _MY_FAIL \n\t\t\tbreak;\t\t \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;\t\t \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;\t\t \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\t\tbreak;\n\tcase 'S':\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase 'U':\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize *= sizeof(Py_UNICODE);\n\t\tbreak;\t \n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\t\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/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_fromstructinterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r, *ret;\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_XDECREF(intype);\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_XDECREF(intype);\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 ret = array_fromarray((PyArrayObject*)r, intype, flags);\n Py_DECREF(r);\n return ret;\n}\n\n/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n PyObject *tstr=NULL, *shape=NULL; \n\tPyArrayObject *ret=NULL;\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\t\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\tPy_XDECREF(intype);\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\tPy_XDECREF(intype);\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\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n\n fail:\n\tPy_XDECREF(intype);\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* steals a reference to typecode */\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Descr *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode == NULL) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyObject *obj;\n\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", typecode->type,\n\t\t\t\t\t\t typecode->elsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(typecode->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\n if (new == NULL) {Py_XDECREF(typecode); 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\t\tPy_DECREF(typecode);\n return NULL;\n }\n r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n/* Steals a reference to newtype --- which can be NULL */\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Descr *newtype, int min_depth, \n\t\t int max_depth, int flags) \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 = array_fromarray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if ((r = array_fromstructinterface(op, newtype, flags)) != \\\n\t\t Py_NotImplemented) {\n }\n else if ((r = array_frominterface(op, newtype, flags)) !=\t\\\n\t\t Py_NotImplemented) {\n\t}\n else if (PyObject_HasAttrString(op, \"__array__\")) {\n /* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, newtype, flags);\n }\n\telse {\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\t\t\t\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 PyErr_Clear();\n else\n seq = TRUE;\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\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\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\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_FromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n\t\tint max_depth, int requires) \n{\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\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 array_fromobject(op, descr, min_depth, max_depth,\n \t\t\t\trequires);\t\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 or PyBigArray_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) || PyBigArray_CheckExact(op)) return op;\n \n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FROM_OF(op, ENSUREARRAY);\n Py_DECREF(op);\n return new;\n}\n\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 * sizeof(Py_UNICODE)\\\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.\t\t \n\t\t*/\n\t}\n\treturn ret;\n}\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\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\t\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\t\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\t\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/* 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\niter_length(PyArrayIterObject *self) \n{\n return (int) 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, itemsize);\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\t\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, itemsize);\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;\t\t\t\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */ \t\n\t\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, size);\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);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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\t\t\t\t\t FORCECAST | ALIGNED);\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,\n\t\t\t\t itemsize);\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, itemsize);\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, itemsize);\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\t\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\t\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0);\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, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\t\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, itemsize);\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, itemsize);\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);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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_FromAny(obj, indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\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\t\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n (inquiry)iter_length,\t\t /*mp_length*/\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;\t\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\t{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 0, /* 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/* 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/* 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);\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\t\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\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\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 sizeof(intp));\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\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\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 sizeof(intp));\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 sizeof(intp));\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\t\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\t \n\tif (mit->view) return;\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\n\tsub = PyObject_GetItem((PyObject *)arr, mit->indexobj);\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\t\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\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\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= 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) *indptr, (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);\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\t\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->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_IndexError,\t\t\t\\\n\t\t\t\t\"arrays used as indices must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_IndexError, \"too many indices\");\n\t\tgoto fail;\n\t}\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\t\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);\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 ret:\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\t\n\tint i, err=0;\n\t\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\t\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\t\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);\t\n\t\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\t\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\t\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\t\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\t\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\t\n return (PyObject *)multi;\n\t\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\t_pya_free(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);\t\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 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/*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;\t\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(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 dtypedescr objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"dtype\", 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\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\tchar basic_=self->kind;\n\tchar endian = self->byteorder;\n\t\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\t\n\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t self->elsize);\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{\"subdescr\", \n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"arrdescr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"dtypestr\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\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\t\n\tif (!PyArg_ParseTuple(args, \"O|iO&\", &odescr, &align,\n\t\t\t PyArray_BoolConverter, ©))\n\t\treturn NULL;\n\t\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, \n\t\t\t\t\t\t\t\t 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, \"dtypedescr\");\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\tobj = PyString_FromFormat(\"%c%d\",self->kind, self->elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\t\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\t\n\tif (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\t\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\t\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\t\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*/\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\t\t\t\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 dtypedescr 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 dtypedescr object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\t\t\t\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);\t\t\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(\"dtypedescr(\");\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 dtypedescr 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\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtypedescr\",\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 0, \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", + "methods": [ + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 19, + "token_count": 391, + "parameters": [ + "o" + ], + "start_line": 31, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 59, + "complexity": 19, + "token_count": 394, + "parameters": [ + "o" + ], + "start_line": 103, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 86, + "parameters": [ + "obj", + "default_" + ], + "start_line": 173, + "end_line": 191, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "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": 212, + "end_line": 240, + "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": 246, + "end_line": 275, + "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": 281, + "end_line": 331, + "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": 354, + "end_line": 385, + "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": 388, + "end_line": 422, + "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": 438, + "end_line": 460, + "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": 466, + "end_line": 487, + "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": 491, + "end_line": 529, + "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": 534, + "end_line": 554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "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": 562, + "end_line": 577, + "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": 583, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 607, + "end_line": 687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "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": 79, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 691, + "end_line": 705, + "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": 718, + "end_line": 744, + "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": 750, + "end_line": 764, + "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 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 772, + "end_line": 792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 11, + "token_count": 468, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 801, + "end_line": 883, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 899, + "end_line": 902, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 912, + "end_line": 934, + "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": 948, + "end_line": 988, + "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": 1003, + "end_line": 1044, + "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": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1051, + "end_line": 1142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "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": 1148, + "end_line": 1177, + "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": 1180, + "end_line": 1216, + "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": 1225, + "end_line": 1262, + "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": 1269, + "end_line": 1277, + "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": 1280, + "end_line": 1305, + "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 i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1308, + "end_line": 1311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 1315, + "end_line": 1350, + "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 i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1356, + "end_line": 1359, + "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": 1365, + "end_line": 1373, + "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": 1379, + "end_line": 1429, + "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": 1436, + "end_line": 1481, + "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": 1485, + "end_line": 1579, + "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": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1582, + "end_line": 1619, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1631, + "end_line": 1684, + "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": 53, + "complexity": 12, + "token_count": 380, + "parameters": [ + "mit", + "op" + ], + "start_line": 1687, + "end_line": 1747, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "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": 1750, + "end_line": 1777, + "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": 1780, + "end_line": 1799, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 28, + "token_count": 659, + "parameters": [ + "self", + "op" + ], + "start_line": 1823, + "end_line": 1938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 91, + "complexity": 28, + "token_count": 581, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 1953, + "end_line": 2055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2064, + "end_line": 2067, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , int * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2086, + "end_line": 2098, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2101, + "end_line": 2116, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2120, + "end_line": 2129, + "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 segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2132, + "end_line": 2143, + "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": 34, + "complexity": 1, + "token_count": 162, + "parameters": [ + "dict" + ], + "start_line": 2214, + "end_line": 2247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 2, + "token_count": 183, + "parameters": [], + "start_line": 2257, + "end_line": 2296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "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": 2299, + "end_line": 2322, + "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": 2326, + "end_line": 2349, + "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": 2353, + "end_line": 2360, + "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": 2363, + "end_line": 2370, + "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": 2373, + "end_line": 2381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 2384, + "end_line": 2387, + "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": 2390, + "end_line": 2393, + "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": 2396, + "end_line": 2399, + "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": 2402, + "end_line": 2405, + "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": 2408, + "end_line": 2411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2414, + "end_line": 2417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2420, + "end_line": 2423, + "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": 2426, + "end_line": 2429, + "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": 2432, + "end_line": 2435, + "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": 2438, + "end_line": 2441, + "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": 2444, + "end_line": 2447, + "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": 2450, + "end_line": 2453, + "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": 2456, + "end_line": 2459, + "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": 2462, + "end_line": 2465, + "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": 2468, + "end_line": 2471, + "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": 2474, + "end_line": 2477, + "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": 2480, + "end_line": 2483, + "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": 2486, + "end_line": 2489, + "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": 2492, + "end_line": 2495, + "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 * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2498, + "end_line": 2501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2504, + "end_line": 2507, + "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": 2510, + "end_line": 2513, + "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": 2516, + "end_line": 2519, + "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": 2522, + "end_line": 2525, + "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": 2528, + "end_line": 2531, + "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": 2534, + "end_line": 2537, + "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": 2540, + "end_line": 2543, + "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": 2546, + "end_line": 2550, + "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": 2553, + "end_line": 2557, + "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": 2561, + "end_line": 2579, + "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": 2582, + "end_line": 2599, + "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": 2604, + "end_line": 2619, + "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": 2623, + "end_line": 2649, + "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": 2652, + "end_line": 2677, + "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": 2680, + "end_line": 2702, + "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": 2705, + "end_line": 2727, + "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": 2730, + "end_line": 2752, + "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": 2755, + "end_line": 2759, + "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 ilow , int ihigh)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 11, + "token_count": 259, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 2820, + "end_line": 2860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , int ilow , int ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 2864, + "end_line": 2885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 2888, + "end_line": 2900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 2921, + "end_line": 2968, + "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": 2971, + "end_line": 3007, + "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": 3016, + "end_line": 3033, + "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": 3036, + "end_line": 3048, + "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": 3051, + "end_line": 3063, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_richcompare", + "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 13, + "token_count": 273, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3066, + "end_line": 3143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 164, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3146, + "end_line": 3175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 3181, + "end_line": 3201, + "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": 21, + "complexity": 7, + "token_count": 161, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3209, + "end_line": 3232, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 111, + "parameters": [ + "ap" + ], + "start_line": 3238, + "end_line": 3254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 109, + "parameters": [ + "ap" + ], + "start_line": 3258, + "end_line": 3274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 3277, + "end_line": 3294, + "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": 3297, + "end_line": 3330, + "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": 3337, + "end_line": 3364, + "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 * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 84, + "parameters": [ + "elsize", + "nd", + "numbytes", + "dims", + "newstrides" + ], + "start_line": 3373, + "end_line": 3388, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 3408, + "end_line": 3432, + "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": 3438, + "end_line": 3460, + "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)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 6, + "token_count": 229, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd" + ], + "start_line": 3464, + "end_line": 3506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 130, + "complexity": 26, + "token_count": 761, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3514, + "end_line": 3672, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 159, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", + "filename": "arrayobject.c", + "nloc": 82, + "complexity": 15, + "token_count": 497, + "parameters": [ + "self", + "newshape" + ], + "start_line": 3681, + "end_line": 3779, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "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": 3785, + "end_line": 3802, + "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": 41, + "complexity": 6, + "token_count": 229, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3806, + "end_line": 3848, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 18, + "token_count": 570, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 3851, + "end_line": 3965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 115, + "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": 3969, + "end_line": 3977, + "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": 3983, + "end_line": 3986, + "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": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 3989, + "end_line": 3993, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 3996, + "end_line": 3999, + "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": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4003, + "end_line": 4032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 4036, + "end_line": 4039, + "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": 36, + "complexity": 7, + "token_count": 231, + "parameters": [ + "self", + "obj" + ], + "start_line": 4042, + "end_line": 4080, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "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": 4084, + "end_line": 4091, + "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": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 4094, + "end_line": 4102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 4106, + "end_line": 4112, + "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": 4115, + "end_line": 4129, + "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": 4132, + "end_line": 4176, + "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": 4180, + "end_line": 4183, + "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": 4186, + "end_line": 4197, + "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": 4200, + "end_line": 4211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typechar_get", + "long_name": "array_typechar_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 4215, + "end_line": 4222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 4227, + "end_line": 4230, + "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": 4233, + "end_line": 4237, + "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": 15, + "token_count": 443, + "parameters": [ + "self", + "arg" + ], + "start_line": 4251, + "end_line": 4336, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "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": 4339, + "end_line": 4357, + "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": 4360, + "end_line": 4378, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_type_get", + "long_name": "array_type_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4381, + "end_line": 4385, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 4390, + "end_line": 4400, + "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": 4404, + "end_line": 4429, + "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": 32, + "complexity": 4, + "token_count": 189, + "parameters": [ + "self", + "val" + ], + "start_line": 4433, + "end_line": 4466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "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": 4469, + "end_line": 4502, + "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": 205, + "parameters": [ + "self", + "val" + ], + "start_line": 4505, + "end_line": 4542, + "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": 4545, + "end_line": 4548, + "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": 346, + "parameters": [ + "self", + "val" + ], + "start_line": 4551, + "end_line": 4601, + "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": 4703, + "end_line": 4710, + "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": 4812, + "end_line": 4845, + "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": 161, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 4848, + "end_line": 4870, + "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": 4877, + "end_line": 4903, + "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": 4909, + "end_line": 4941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 120, + "complexity": 31, + "token_count": 691, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 4953, + "end_line": 5089, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 137, + "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": 5092, + "end_line": 5115, + "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": 23, + "complexity": 6, + "token_count": 146, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5120, + "end_line": 5148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 21, + "token_count": 367, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5153, + "end_line": 5217, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "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": 5224, + "end_line": 5233, + "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": 5239, + "end_line": 5332, + "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": 280, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5342, + "end_line": 5388, + "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": 5398, + "end_line": 5451, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_fromarray", + "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 32, + "token_count": 673, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5455, + "end_line": 5584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 505, + "parameters": [ + "str" + ], + "start_line": 5588, + "end_line": 5696, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "array_fromstructinterface", + "long_name": "array_fromstructinterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 6, + "token_count": 274, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5700, + "end_line": 5744, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_frominterface", + "long_name": "array_frominterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 134, + "complexity": 28, + "token_count": 839, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5748, + "end_line": 5891, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 144, + "top_nesting_level": 0 + }, + { + "name": "array_fromattr", + "long_name": "array_fromattr( PyObject * op , PyArray_Descr * typecode , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 178, + "parameters": [ + "op", + "typecode", + "flags" + ], + "start_line": 5895, + "end_line": 5925, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "array_fromobject", + "long_name": "array_fromobject( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 17, + "token_count": 330, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags" + ], + "start_line": 5929, + "end_line": 6005, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 77, + "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": 6010, + "end_line": 6013, + "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": 6020, + "end_line": 6033, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 8, + "token_count": 117, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires" + ], + "start_line": 6079, + "end_line": 6098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 81, + "parameters": [ + "op" + ], + "start_line": 6111, + "end_line": 6127, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 6135, + "end_line": 6223, + "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": 134, + "parameters": [ + "from", + "to" + ], + "start_line": 6228, + "end_line": 6256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 6269, + "end_line": 6307, + "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": 6315, + "end_line": 6332, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "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": 6337, + "end_line": 6347, + "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": 6350, + "end_line": 6354, + "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": 16, + "parameters": [ + "self" + ], + "start_line": 6357, + "end_line": 6360, + "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": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6364, + "end_line": 6414, + "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": 6417, + "end_line": 6471, + "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": 664, + "parameters": [ + "self", + "ind" + ], + "start_line": 6475, + "end_line": 6608, + "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": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6612, + "end_line": 6644, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "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": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6647, + "end_line": 6689, + "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": 692, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 6692, + "end_line": 6826, + "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": 6839, + "end_line": 6884, + "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": 6889, + "end_line": 6893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 6965, + "end_line": 7027, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 104, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7035, + "end_line": 7051, + "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": 7058, + "end_line": 7127, + "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": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7131, + "end_line": 7168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7174, + "end_line": 7218, + "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": 99, + "complexity": 22, + "token_count": 670, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7236, + "end_line": 7366, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 460, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7372, + "end_line": 7445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned)", + "filename": "arrayobject.c", + "nloc": 112, + "complexity": 25, + "token_count": 758, + "parameters": [ + "indexobj", + "oned" + ], + "start_line": 7448, + "end_line": 7583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "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": 7587, + "end_line": 7596, + "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": 231, + "parameters": [ + "n" + ], + "start_line": 7667, + "end_line": 7716, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "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": 265, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 7719, + "end_line": 7764, + "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": 7767, + "end_line": 7786, + "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": 41, + "parameters": [ + "multi" + ], + "start_line": 7789, + "end_line": 7796, + "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": 7799, + "end_line": 7809, + "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": 7812, + "end_line": 7822, + "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": 7825, + "end_line": 7828, + "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": 7831, + "end_line": 7843, + "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": 7873, + "end_line": 7880, + "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": 7939, + "end_line": 7948, + "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": 7966, + "end_line": 7988, + "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": 64, + "parameters": [ + "self" + ], + "start_line": 7994, + "end_line": 8004, + "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": 8022, + "end_line": 8030, + "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": 11, + "complexity": 3, + "token_count": 60, + "parameters": [ + "self" + ], + "start_line": 8033, + "end_line": 8045, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 8048, + "end_line": 8067, + "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": 8074, + "end_line": 8081, + "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": 8084, + "end_line": 8091, + "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": 8094, + "end_line": 8101, + "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": 8137, + "end_line": 8189, + "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": 50, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "args" + ], + "start_line": 8195, + "end_line": 8252, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8260, + "end_line": 8302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 8322, + "end_line": 8388, + "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": 8399, + "end_line": 8407, + "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": 8422, + "end_line": 8467, + "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": 8470, + "end_line": 8479, + "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": 8482, + "end_line": 8492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 19, + "token_count": 391, + "parameters": [ + "o" + ], + "start_line": 31, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 59, + "complexity": 19, + "token_count": 394, + "parameters": [ + "o" + ], + "start_line": 103, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 86, + "parameters": [ + "obj", + "default_" + ], + "start_line": 173, + "end_line": 191, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "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": 212, + "end_line": 240, + "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": 246, + "end_line": 275, + "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": 281, + "end_line": 331, + "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": 354, + "end_line": 385, + "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": 388, + "end_line": 422, + "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": 438, + "end_line": 460, + "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": 466, + "end_line": 487, + "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": 491, + "end_line": 529, + "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": 534, + "end_line": 554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "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": 562, + "end_line": 577, + "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": 583, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 607, + "end_line": 687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "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": 79, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 691, + "end_line": 705, + "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": 718, + "end_line": 744, + "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": 750, + "end_line": 764, + "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 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 772, + "end_line": 792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 11, + "token_count": 468, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 801, + "end_line": 883, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 899, + "end_line": 902, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 912, + "end_line": 934, + "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": 948, + "end_line": 988, + "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": 1003, + "end_line": 1044, + "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": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1051, + "end_line": 1142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "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": 1148, + "end_line": 1177, + "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": 1180, + "end_line": 1216, + "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": 1225, + "end_line": 1262, + "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": 1269, + "end_line": 1277, + "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": 1280, + "end_line": 1305, + "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 i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1308, + "end_line": 1311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 1315, + "end_line": 1350, + "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 i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1356, + "end_line": 1359, + "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": 1365, + "end_line": 1373, + "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": 1379, + "end_line": 1429, + "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": 1436, + "end_line": 1481, + "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": 1485, + "end_line": 1579, + "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": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1582, + "end_line": 1619, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1631, + "end_line": 1684, + "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": 53, + "complexity": 12, + "token_count": 380, + "parameters": [ + "mit", + "op" + ], + "start_line": 1687, + "end_line": 1747, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "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": 1750, + "end_line": 1777, + "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": 1780, + "end_line": 1799, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 28, + "token_count": 659, + "parameters": [ + "self", + "op" + ], + "start_line": 1823, + "end_line": 1938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 91, + "complexity": 28, + "token_count": 581, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 1953, + "end_line": 2055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2064, + "end_line": 2067, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , int * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2086, + "end_line": 2098, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2101, + "end_line": 2116, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2120, + "end_line": 2129, + "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 segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2132, + "end_line": 2143, + "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": 34, + "complexity": 1, + "token_count": 162, + "parameters": [ + "dict" + ], + "start_line": 2214, + "end_line": 2247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 2, + "token_count": 183, + "parameters": [], + "start_line": 2257, + "end_line": 2296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "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": 2299, + "end_line": 2322, + "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": 2326, + "end_line": 2349, + "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": 2353, + "end_line": 2360, + "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": 2363, + "end_line": 2370, + "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": 2373, + "end_line": 2381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 2384, + "end_line": 2387, + "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": 2390, + "end_line": 2393, + "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": 2396, + "end_line": 2399, + "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": 2402, + "end_line": 2405, + "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": 2408, + "end_line": 2411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2414, + "end_line": 2417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2420, + "end_line": 2423, + "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": 2426, + "end_line": 2429, + "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": 2432, + "end_line": 2435, + "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": 2438, + "end_line": 2441, + "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": 2444, + "end_line": 2447, + "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": 2450, + "end_line": 2453, + "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": 2456, + "end_line": 2459, + "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": 2462, + "end_line": 2465, + "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": 2468, + "end_line": 2471, + "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": 2474, + "end_line": 2477, + "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": 2480, + "end_line": 2483, + "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": 2486, + "end_line": 2489, + "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": 2492, + "end_line": 2495, + "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 * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2498, + "end_line": 2501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2504, + "end_line": 2507, + "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": 2510, + "end_line": 2513, + "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": 2516, + "end_line": 2519, + "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": 2522, + "end_line": 2525, + "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": 2528, + "end_line": 2531, + "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": 2534, + "end_line": 2537, + "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": 2540, + "end_line": 2543, + "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": 2546, + "end_line": 2550, + "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": 2553, + "end_line": 2557, + "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": 2561, + "end_line": 2579, + "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": 2582, + "end_line": 2599, + "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": 2604, + "end_line": 2619, + "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": 2623, + "end_line": 2649, + "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": 2652, + "end_line": 2677, + "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": 2680, + "end_line": 2702, + "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": 2705, + "end_line": 2727, + "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": 2730, + "end_line": 2752, + "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": 2755, + "end_line": 2759, + "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 ilow , int ihigh)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 11, + "token_count": 259, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 2820, + "end_line": 2860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , int ilow , int ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 2864, + "end_line": 2885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 2888, + "end_line": 2900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 2921, + "end_line": 2968, + "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": 2971, + "end_line": 3007, + "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": 3016, + "end_line": 3033, + "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": 3036, + "end_line": 3048, + "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": 3051, + "end_line": 3063, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_richcompare", + "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 13, + "token_count": 273, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3066, + "end_line": 3143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 164, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3146, + "end_line": 3175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 3181, + "end_line": 3201, + "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": 21, + "complexity": 7, + "token_count": 161, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3209, + "end_line": 3232, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 111, + "parameters": [ + "ap" + ], + "start_line": 3238, + "end_line": 3254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 109, + "parameters": [ + "ap" + ], + "start_line": 3258, + "end_line": 3274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 3277, + "end_line": 3294, + "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": 3297, + "end_line": 3330, + "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": 3337, + "end_line": 3364, + "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 * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 84, + "parameters": [ + "elsize", + "nd", + "numbytes", + "dims", + "newstrides" + ], + "start_line": 3373, + "end_line": 3388, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 3408, + "end_line": 3432, + "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": 3438, + "end_line": 3460, + "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)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 6, + "token_count": 229, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd" + ], + "start_line": 3464, + "end_line": 3506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 130, + "complexity": 26, + "token_count": 761, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3514, + "end_line": 3672, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 159, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", + "filename": "arrayobject.c", + "nloc": 82, + "complexity": 15, + "token_count": 497, + "parameters": [ + "self", + "newshape" + ], + "start_line": 3681, + "end_line": 3779, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "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": 3785, + "end_line": 3802, + "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": 41, + "complexity": 6, + "token_count": 229, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3806, + "end_line": 3848, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 18, + "token_count": 570, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 3851, + "end_line": 3965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 115, + "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": 3969, + "end_line": 3977, + "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": 3983, + "end_line": 3986, + "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": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 3989, + "end_line": 3993, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 3996, + "end_line": 3999, + "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": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4003, + "end_line": 4032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 4036, + "end_line": 4039, + "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": 36, + "complexity": 7, + "token_count": 231, + "parameters": [ + "self", + "obj" + ], + "start_line": 4042, + "end_line": 4080, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "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": 4084, + "end_line": 4091, + "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": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 4094, + "end_line": 4102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 4106, + "end_line": 4112, + "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": 4115, + "end_line": 4129, + "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": 4132, + "end_line": 4176, + "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": 4180, + "end_line": 4183, + "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": 4186, + "end_line": 4197, + "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": 4200, + "end_line": 4211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typechar_get", + "long_name": "array_typechar_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 4215, + "end_line": 4222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 4227, + "end_line": 4230, + "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": 4233, + "end_line": 4237, + "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": 15, + "token_count": 443, + "parameters": [ + "self", + "arg" + ], + "start_line": 4251, + "end_line": 4336, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "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": 4339, + "end_line": 4357, + "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": 4360, + "end_line": 4378, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_type_get", + "long_name": "array_type_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4381, + "end_line": 4385, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 4390, + "end_line": 4400, + "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": 4404, + "end_line": 4429, + "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": 32, + "complexity": 4, + "token_count": 189, + "parameters": [ + "self", + "val" + ], + "start_line": 4433, + "end_line": 4466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "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": 4469, + "end_line": 4502, + "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": 205, + "parameters": [ + "self", + "val" + ], + "start_line": 4505, + "end_line": 4542, + "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": 4545, + "end_line": 4548, + "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": 346, + "parameters": [ + "self", + "val" + ], + "start_line": 4551, + "end_line": 4601, + "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": 4703, + "end_line": 4710, + "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": 4812, + "end_line": 4845, + "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": 161, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 4848, + "end_line": 4870, + "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": 4877, + "end_line": 4903, + "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": 4909, + "end_line": 4941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 120, + "complexity": 31, + "token_count": 691, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 4953, + "end_line": 5089, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 137, + "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": 5092, + "end_line": 5115, + "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": 23, + "complexity": 6, + "token_count": 146, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5120, + "end_line": 5148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 21, + "token_count": 367, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5153, + "end_line": 5217, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "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": 5224, + "end_line": 5233, + "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": 5239, + "end_line": 5332, + "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": 280, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5342, + "end_line": 5388, + "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": 5398, + "end_line": 5451, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_fromarray", + "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 32, + "token_count": 673, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5455, + "end_line": 5584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 505, + "parameters": [ + "str" + ], + "start_line": 5588, + "end_line": 5696, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "array_fromstructinterface", + "long_name": "array_fromstructinterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 6, + "token_count": 274, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5700, + "end_line": 5744, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_frominterface", + "long_name": "array_frominterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 134, + "complexity": 28, + "token_count": 839, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5748, + "end_line": 5891, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 144, + "top_nesting_level": 0 + }, + { + "name": "array_fromattr", + "long_name": "array_fromattr( PyObject * op , PyArray_Descr * typecode , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 178, + "parameters": [ + "op", + "typecode", + "flags" + ], + "start_line": 5895, + "end_line": 5925, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "array_fromobject", + "long_name": "array_fromobject( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 17, + "token_count": 330, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags" + ], + "start_line": 5929, + "end_line": 6005, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 77, + "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": 6010, + "end_line": 6013, + "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": 6020, + "end_line": 6033, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 8, + "token_count": 117, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires" + ], + "start_line": 6079, + "end_line": 6098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 81, + "parameters": [ + "op" + ], + "start_line": 6111, + "end_line": 6127, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 6135, + "end_line": 6223, + "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": 134, + "parameters": [ + "from", + "to" + ], + "start_line": 6228, + "end_line": 6256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 6269, + "end_line": 6307, + "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": 6315, + "end_line": 6332, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "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": 6337, + "end_line": 6347, + "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": 6350, + "end_line": 6354, + "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": 16, + "parameters": [ + "self" + ], + "start_line": 6357, + "end_line": 6360, + "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": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6364, + "end_line": 6414, + "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": 6417, + "end_line": 6471, + "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": 664, + "parameters": [ + "self", + "ind" + ], + "start_line": 6475, + "end_line": 6608, + "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": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6612, + "end_line": 6644, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "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": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6647, + "end_line": 6689, + "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": 692, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 6692, + "end_line": 6826, + "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": 6839, + "end_line": 6884, + "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": 6889, + "end_line": 6893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 6965, + "end_line": 7027, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 104, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7035, + "end_line": 7051, + "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": 7058, + "end_line": 7127, + "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": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7131, + "end_line": 7168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7174, + "end_line": 7218, + "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": 99, + "complexity": 22, + "token_count": 670, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7236, + "end_line": 7366, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 460, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7372, + "end_line": 7445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned)", + "filename": "arrayobject.c", + "nloc": 112, + "complexity": 25, + "token_count": 758, + "parameters": [ + "indexobj", + "oned" + ], + "start_line": 7448, + "end_line": 7583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "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": 7587, + "end_line": 7596, + "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": 231, + "parameters": [ + "n" + ], + "start_line": 7667, + "end_line": 7716, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "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": 265, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 7719, + "end_line": 7764, + "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": 7767, + "end_line": 7786, + "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": 41, + "parameters": [ + "multi" + ], + "start_line": 7789, + "end_line": 7796, + "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": 7799, + "end_line": 7809, + "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": 7812, + "end_line": 7822, + "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": 7825, + "end_line": 7828, + "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": 7831, + "end_line": 7843, + "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": 7873, + "end_line": 7880, + "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": 7939, + "end_line": 7948, + "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": 7966, + "end_line": 7988, + "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": 64, + "parameters": [ + "self" + ], + "start_line": 7994, + "end_line": 8004, + "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": 8022, + "end_line": 8030, + "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": 11, + "complexity": 3, + "token_count": 60, + "parameters": [ + "self" + ], + "start_line": 8033, + "end_line": 8045, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 8048, + "end_line": 8067, + "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": 8074, + "end_line": 8081, + "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": 8084, + "end_line": 8091, + "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": 8094, + "end_line": 8101, + "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": 47, + "complexity": 13, + "token_count": 251, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 8137, + "end_line": 8188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_reduce", + "long_name": "arraydescr_reduce( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 50, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "args" + ], + "start_line": 8194, + "end_line": 8251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8259, + "end_line": 8301, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 8321, + "end_line": 8387, + "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": 8398, + "end_line": 8406, + "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": 8421, + "end_line": 8466, + "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": 8469, + "end_line": 8478, + "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": 8481, + "end_line": 8491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "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": 8137, + "end_line": 8189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 53, + "top_nesting_level": 0 + } + ], + "nloc": 6781, + "complexity": 1442, + "token_count": 39869, + "diff_parsed": { + "added": [ + "\tstatic char *kwlist[] = {\"dtype\", \"align\", \"copy\", NULL};", + "\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\",", + "\t\t\t\t\t kwlist, &odescr, &align,", + "\t\t\t\t\t PyArray_BoolConverter, ©))", + "\t\t\tconv = _convert_from_commastring(odescr, 1);" + ], + "deleted": [ + "\tif (!PyArg_ParseTuple(args, \"O|iO&\", &odescr, &align,", + "\t\t\t PyArray_BoolConverter, ©))", + "\t\t\tconv = _convert_from_commastring(odescr,", + "\t\t\t\t\t\t\t\t 1);" + ] + } + }, + { + "old_path": "numpy/core/src/multiarraymodule.c", + "new_path": "numpy/core/src/multiarraymodule.c", + "filename": "multiarraymodule.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -3498,12 +3498,6 @@ _convert_from_list(PyObject *obj, int align, int try_descr)\n \t\tkey = PyString_FromFormat(\"f%d\", i+1);\n \t\tret = PyArray_DescrConverter(PyList_GET_ITEM(obj, i), &conv);\n \t\tPyTuple_SET_ITEM(tup, 0, (PyObject *)conv);\n-\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n-\t\tPyDict_SetItem(fields, key, tup);\n-\t\tPy_DECREF(tup);\n-\t\tPyList_SET_ITEM(nameslist, i, key);\n-\t\tif (ret == PY_FAIL) goto fail;\n-\t\ttotalsize += conv->elsize;\n \t\tif (align) {\n \t\t\tint _align;\n \t\t\t_align = conv->alignment;\n@@ -3511,6 +3505,12 @@ _convert_from_list(PyObject *obj, int align, int try_descr)\n \t\t\t\t((totalsize + _align - 1)/_align)*_align;\n \t\t\tmaxalign = MAX(maxalign, _align);\n \t\t}\n+\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n+\t\tPyDict_SetItem(fields, key, tup);\n+\t\tPy_DECREF(tup);\n+\t\tPyList_SET_ITEM(nameslist, i, key);\n+\t\tif (ret == PY_FAIL) goto fail;\n+\t\ttotalsize += conv->elsize;\n \t}\n \tkey = PyInt_FromLong(-1);\n \tPyDict_SetItem(fields, key, nameslist);\n@@ -3677,8 +3677,15 @@ _convert_from_dict(PyObject *obj, int align)\n \t\t\t}\n \t\t\tif (offset > totalsize) totalsize = offset;\n \t\t}\n-\t\telse \n+\t\telse {\n \t\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\n+\t\t\tif (align) {\n+\t\t\t\tint _align = newdescr->alignment;\n+\t\t\t\tif (_align > 1) totalsize =\t\t\\\n+\t\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n+\t\t\t\tmaxalign = MAX(maxalign,_align);\n+\t\t\t}\n+\t\t}\n \t\tif (len == 3) PyTuple_SET_ITEM(tup, 2, item);\n \t\tname = PyObject_GetItem(names, index);\n \t\tPy_DECREF(index);\n@@ -3690,12 +3697,6 @@ _convert_from_dict(PyObject *obj, int align)\n \t\tPy_DECREF(tup);\n \t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n \t\ttotalsize += newdescr->elsize;\n-\t\tif (align) {\n-\t\t\tint _align = newdescr->alignment;\n-\t\t\tif (_align > 1) totalsize =\t\t\t\\\n-\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n-\t\t\tmaxalign = MAX(maxalign,_align);\n-\t\t}\n \t}\n \n \tnew = PyArray_DescrNewFromType(PyArray_VOID);\n", + "added_lines": 14, + "deleted_lines": 13, + "source_code": "/*\n Python Multiarray Module -- A useful collection of functions for creating and\n using ndarrays\n\n Original file \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n Modified for numpy_core in 2005 \n\n Travis E. Oliphant\n Assistant Professor at\n Brigham Young University\n \n*/\n\n/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */\n\n#include \"Python.h\"\n#include \"structmember.h\"\n/*#include \n#include \n*/\n\n#define _MULTIARRAYMODULE\n#include \"numpy/arrayobject.h\"\n\n#define PyAO PyArrayObject\n\nstatic PyObject *typeDict=NULL; /* Must be explicitly loaded */\nstatic PyObject *_numpy_internal=NULL; /* A Python module for callbacks */\n\n\nstatic PyArray_Descr *\n_arraydescr_fromobj(PyObject *obj)\n{\n\tPyObject *dtypedescr;\n\tPyArray_Descr *new;\n\tint ret;\n\t\n\tdtypedescr = PyObject_GetAttrString(obj, \"dtypedescr\");\n\tPyErr_Clear();\n\tif (dtypedescr) {\n\t\tret = PyArray_DescrConverter(dtypedescr, &new);\n\t\tPy_DECREF(dtypedescr);\n\t\tif (ret) return new;\n\t\tPyErr_Clear();\n\t}\n\treturn NULL;\n}\n\n\n/* Including this file is the only way I know how to declare functions\n static in each file, and store the pointers from functions in both\n arrayobject.c and multiarraymodule.c for the C-API \n\n Declarying an external pointer-containing variable in arrayobject.c\n and trying to copy it to PyArray_API, did not work.\n\n Think about two modules with a common api that import each other...\n\n This file would just be the module calls. \n*/\n\n#include \"arrayobject.c\"\n\n\n/* An Error object -- rarely used? */\nstatic PyObject *MultiArrayError;\n\n/*MULTIARRAY_API\n Multiply a List of ints\n*/\nstatic int\nPyArray_MultiplyIntList(register int *l1, register int n) \n{\n\tregister int s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Multiply a List\n*/\nstatic intp \nPyArray_MultiplyList(register intp *l1, register int n) \n{\n\tregister intp s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Produce a pointer into array\n*/\nstatic char *\nPyArray_GetPtr(PyArrayObject *obj, register intp* ind)\n{\n\tregister int n = obj->nd;\n\tregister intp *strides = obj->strides;\n\tregister char *dptr = obj->data;\n\t\n\twhile (n--) dptr += (*strides++) * (*ind++);\n\treturn dptr;\n}\n\n/*MULTIARRAY_API\n Get axis from an object (possibly None) -- a converter function,\n*/\nstatic int \nPyArray_AxisConverter(PyObject *obj, int *axis)\n{\n\tif (obj == Py_None) {\n\t\t*axis = MAX_DIMS;\n\t}\n\telse {\n\t\t*axis = (int) PyInt_AsLong(obj);\n\t\tif (PyErr_Occurred()) {\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Compare Lists\n*/\nstatic int \nPyArray_CompareLists(intp *l1, intp *l2, int n) \n{\n int i;\n for(i=0;iob_type;\n\t\n\tPy_INCREF(self->descr);\n\tnew = PyArray_NewFromDescr(subtype,\n\t\t\t\t self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides,\n\t\t\t\t self->data,\n\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (new==NULL) return NULL;\n\tPy_INCREF(self);\n PyArray_BASE(new) = (PyObject *)self;\n\t\n\tif (type != NULL) {\n\t\tif (PyObject_SetAttrString(new, \"dtypedescr\", \n\t\t\t\t\t (PyObject *)type) < 0) {\n\t\t\tPy_DECREF(new);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tPy_DECREF(type);\n\t}\n\treturn new;\t\n}\n\n/*MULTIARRAY_API\n Ravel\n*/\nstatic PyObject *\nPyArray_Ravel(PyArrayObject *a, int fortran)\n{\n\tPyArray_Dims newdim = {NULL,1};\n\tintp val[1] = {-1};\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tnewdim.ptr = val;\n\tif (!fortran && PyArray_ISCONTIGUOUS(a)) {\n\t\tif (a->nd == 1) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\treturn PyArray_Newshape(a, &newdim);\n\t}\n\telse\n\t return PyArray_Flatten(a, fortran);\n}\n\n/*MULTIARRAY_API\n Flatten\n*/\nstatic PyObject *\nPyArray_Flatten(PyArrayObject *a, int fortran)\n{\n\tPyObject *ret, *new;\n\tintp size;\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tsize = PyArray_SIZE(a);\n\tPy_INCREF(a->descr);\n\tret = PyArray_NewFromDescr(a->ob_type,\n\t\t\t\t a->descr,\n\t\t\t\t 1, &size,\n\t\t\t\t NULL,\n\t\t\t\t NULL,\n\t\t\t\t 0, (PyObject *)a);\n\t\n\tif (ret== NULL) return NULL;\n\tif (fortran) {\n\t\tnew = PyArray_Transpose(a, NULL);\n\t\tif (new == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tPy_INCREF(a);\n\t\tnew = (PyObject *)a;\n\t}\n\tif (PyArray_CopyInto((PyArrayObject *)ret, (PyArrayObject *)new) < 0) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn NULL;\n\t}\n\tPy_DECREF(new);\n\treturn ret;\n}\n\n\n/* For back-ward compatability *\n\n/ * Not recommended */\n\n/*MULTIARRAY_API\n Reshape an array\n*/\nstatic PyObject *\nPyArray_Reshape(PyArrayObject *self, PyObject *shape) \n{\n PyObject *ret;\n PyArray_Dims newdims;\n\n if (!PyArray_IntpConverter(shape, &newdims)) return NULL;\n ret = PyArray_Newshape(self, &newdims);\n PyDimMem_FREE(newdims.ptr);\n return ret;\n}\n\nstatic int\n_check_ones(PyArrayObject *self, int newnd, intp* newdims, intp *strides)\n{\n\tint nd;\n\tintp *dims;\n\tBool done=FALSE;\n\tint j, k;\n\n\tnd = self->nd;\n\tdims = self->dimensions;\n\n\tfor (k=0, j=0; !done && (jstrides[j];\n\t\t\tj++; k++;\n\t\t}\n\t\telse if ((kptr;\n PyArrayObject *ret;\n\tchar msg[] = \"total size of new array must be unchanged\";\n\tint n = newdims->len;\n Bool same;\n\tintp *strides = NULL;\n\tintp newstrides[MAX_DIMS];\n\n /* Quick check to make sure anything needs to be done */\n if (n == self->nd) {\n same = TRUE;\n i=0;\n while(same && i= 0) {\n\t\t\tif ((s_known == 0) || (s_original % s_known != 0)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdimensions[i_unknown] = s_original/s_known;\n\t\t} else {\n\t\t\tif (s_original != s_known) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t}\n \n\tPy_INCREF(self->descr);\n\tret = (PyAO *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t self->descr,\n\t\t\t\t\t n, dimensions,\n\t\t\t\t\t strides,\n\t\t\t\t\t self->data,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (ret== NULL) return NULL;\n\t\n Py_INCREF(self);\n ret->base = (PyObject *)self;\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\n\t\n return (PyObject *)ret;\n}\n\n/* return a new view of the array object with all of its unit-length \n dimensions squeezed out if needed, otherwise\n return the same array.\n */\n\n/*MULTIARRAY_API*/\nstatic PyObject *\nPyArray_Squeeze(PyArrayObject *self)\n{\n\tint nd = self->nd;\n\tint newnd = nd;\n\tintp dimensions[MAX_DIMS];\n\tintp strides[MAX_DIMS];\n\tint i,j;\n\tPyObject *ret;\n\n\tif (nd == 0) {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\tfor (j=0, i=0; idimensions[i] == 1) {\n\t\t\tnewnd -= 1;\n\t\t}\n\t\telse {\n\t\t\tdimensions[j] = self->dimensions[i];\n\t\t\tstrides[j++] = self->strides[i];\n\t\t}\n\t}\n\t\n\tPy_INCREF(self->descr);\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t self->descr,\n\t\t\t\t newnd, dimensions, \n\t\t\t\t strides, self->data, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPyArray_FLAGS(ret) &= ~OWN_DATA;\n\tPyArray_BASE(ret) = (PyObject *)self;\n\tPy_INCREF(self);\n\treturn (PyObject *)ret;\n}\n\n\n/*MULTIARRAY_API\n Mean\n*/\nstatic PyObject *\nPyArray_Mean(PyArrayObject *self, int axis, int rtype)\n{\n\tPyObject *obj1=NULL, *obj2=NULL;\n\tPyObject *new, *ret;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\n\tobj1 = PyArray_GenericReduceFunction((PyAO *)new, n_ops.add, axis,\n\t\t\t\t\t rtype);\n\tobj2 = PyFloat_FromDouble((double) PyArray_DIM(new,axis));\n Py_DECREF(new);\n\tif (obj1 == NULL || obj2 == NULL) {\n\t\tPy_XDECREF(obj1);\n\t\tPy_XDECREF(obj2);\n\t\treturn NULL;\n\t}\n\n\tret = PyNumber_Divide(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n}\n\n/* Set variance to 1 to by-pass square-root calculation and return variance */\n/*MULTIARRAY_API\n Std\n*/\nstatic PyObject *\nPyArray_Std(PyArrayObject *self, int axis, int rtype, int variance)\n{\n\tPyObject *obj1=NULL, *obj2=NULL, *new=NULL;\n\tPyObject *ret=NULL, *newshape=NULL;\n\tint i, n;\n\tintp val;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\t\n\t/* Compute and reshape mean */\n\tobj1 = PyArray_EnsureArray(PyArray_Mean((PyAO *)new, axis, rtype));\n\tif (obj1 == NULL) {Py_DECREF(new); return NULL;} \n\tn = PyArray_NDIM(new);\n\tnewshape = PyTuple_New(n);\n\tif (newshape == NULL) {Py_DECREF(obj1); Py_DECREF(new); return NULL;}\n\tfor (i=0; ind != 1) {\n Py_DECREF(cond);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"condition must be 1-d array\");\n return NULL;\n }\n\n res = PyArray_Nonzero(cond);\n Py_DECREF(cond);\n\tret = PyArray_Take(self, res, axis);\n\tPy_DECREF(res);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Nonzero\n*/\nstatic PyObject *\nPyArray_Nonzero(PyArrayObject *self)\n{\n int n=self->nd, j;\n\tintp count=0, i, size;\n\tPyArrayIterObject *it=NULL;\n\tPyObject *ret=NULL, *item;\n\tintp *dptr[MAX_DIMS];\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (it==NULL) return NULL;\n\n\tsize = it->size;\n\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) count++;\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\n\tPyArray_ITER_RESET(it);\n\tif (n==1) {\n\t\tret = PyArray_New(self->ob_type, 1, &count, PyArray_INTP, \n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)self);\n\t\tif (ret == NULL) goto fail;\n\t\tdptr[0] = (intp *)PyArray_DATA(ret);\n\t\t\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\t*(dptr[0])++ = i;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\t\t\n\t}\n\telse {\n\t\tret = PyTuple_New(n);\n\t\tfor (j=0; job_type, 1, &count, \n\t\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0,\n\t\t\t\t\t (PyObject *)self);\n\t\t\tif (item == NULL) goto fail;\n\t\t\tPyTuple_SET_ITEM(ret, j, item);\n\t\t\tdptr[j] = (intp *)PyArray_DATA(item);\n\t\t}\n\t\t\n\t\t/* reset contiguous so that coordinates gets updated */\n\t\tit->contiguous = 0;\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\tfor (j=0; jcoordinates[j];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\n\n\tPy_DECREF(it);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(ret);\n\tPy_XDECREF(it);\n\treturn NULL;\n \n}\n\n/*MULTIARRAY_API\n Clip\n*/\nstatic PyObject *\nPyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max)\n{\n\tPyObject *selector=NULL, *newtup=NULL, *ret=NULL;\n\tPyObject *res1=NULL, *res2=NULL, *res3=NULL;\n\tPyObject *two;\n\n\ttwo = PyInt_FromLong((long)2);\n\tres1 = PyArray_GenericBinaryFunction(self, max, n_ops.greater);\n\tres2 = PyArray_GenericBinaryFunction(self, min, n_ops.less);\n\tif ((res1 == NULL) || (res2 == NULL)) {\n\t\tPy_DECREF(two);\n\t\tPy_XDECREF(res1);\n\t\tPy_XDECREF(res2);\n\t}\n\tres3 = PyNumber_Multiply(two, res1);\n\tPy_DECREF(two); \n\tPy_DECREF(res1); \n\tif (res3 == NULL) return NULL;\n\n\tselector = PyArray_EnsureArray(PyNumber_Add(res2, res3));\n\tPy_DECREF(res2);\n\tPy_DECREF(res3);\n\tif (selector == NULL) return NULL;\n\n\tnewtup = Py_BuildValue(\"(OOO)\", (PyObject *)self, min, max);\n\tif (newtup == NULL) {Py_DECREF(selector); return NULL;}\n\tret = PyArray_Choose((PyAO *)selector, newtup);\n\tPy_DECREF(selector);\n\tPy_DECREF(newtup);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Conjugate\n*/\nstatic PyObject *\nPyArray_Conjugate(PyArrayObject *self)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyObject *new;\n\t\tintp size, i;\n\t\t/* Make a copy */\n\t\tnew = PyArray_NewCopy(self, -1);\n\t\tif (new==NULL) return NULL;\n\t\tsize = PyArray_SIZE(new);\n\t\tif (self->descr->type_num == PyArray_CFLOAT) {\n\t\t\tcfloat *dptr = (cfloat *) PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CDOUBLE) {\n\t\t\tcdouble *dptr = (cdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CLONGDOUBLE) {\n\t\t\tclongdouble *dptr = (clongdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\t\t\t\n\t\t}\t\t\n\t\treturn new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *) self;\n\t}\n}\n\n/*MULTIARRAY_API\n Trace\n*/\nstatic PyObject *\nPyArray_Trace(PyArrayObject *self, int offset, int axis1, int axis2, \nint rtype)\n{\n\tPyObject *diag=NULL, *ret=NULL;\n\n\tdiag = PyArray_Diagonal(self, offset, axis1, axis2);\n\tif (diag == NULL) return NULL;\n\tret = PyArray_GenericReduceFunction((PyAO *)diag, n_ops.add, -1, rtype);\n\tPy_DECREF(diag);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Diagonal\n*/\nstatic PyObject *\nPyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)\n{\n\tint n = self->nd;\n\tPyObject *new;\n\tPyArray_Dims newaxes;\n\tintp dims[MAX_DIMS];\n\tint i, pos;\t\n\n\tnewaxes.ptr = dims;\n\tif (n < 2) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"array.ndim must be >= 2\");\n\t\treturn NULL;\n\t}\n\tif (axis1 < 0) axis1 += n;\n\tif (axis2 < 0) axis2 += n;\n\tif ((axis1 == axis2) || (axis1 < 0) || (axis1 >= n) ||\t\\\n\t (axis2 < 0) || (axis2 >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \"axis1(=%d) and axis2(=%d) \"\\\n\t\t\t \"must be different and within range (nd=%d)\",\n\t\t\t axis1, axis2, n);\n\t\treturn NULL;\n\t}\n \n\tnewaxes.len = n;\n\t/* insert at the end */\n\tnewaxes.ptr[n-2] = axis1;\n\tnewaxes.ptr[n-1] = axis2;\n\tpos = 0;\n\tfor (i=0; idimensions[0];\n\t\tn2 = self->dimensions[1];\n\t\tstep = n2+1;\n\t\tif (offset < 0) {\n\t\t\tstart = -n2 * offset;\n\t\t\tstop = MIN(n2, n1+offset)*(n2+1) - n2*offset;\n\t\t}\n\t\telse {\n\t\t\tstart = offset;\n\t\t\tstop = MIN(n1, n2-offset)*(n2+1) + offset;\n\t\t}\n\t\t\n\t\t/* count = ceil((stop-start)/step) */\n\t\tcount = ((stop-start) / step) + (((stop-start) % step) != 0);\n\t\t\t\n\t\tindices = PyArray_New(&PyArray_Type, 1, &count, \n\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0, NULL);\n\t\tif (indices == NULL) {\n\t\t\tPy_DECREF(self); return NULL;\n\t\t}\n\t\tdptr = (intp *)PyArray_DATA(indices);\n\t\tfor (n1=start; n1descr;\n\n\t\tmydiagonal = PyList_New(0);\n\t\tif (mydiagonal == NULL) {Py_DECREF(self); return NULL;}\n\t\tn1 = self->dimensions[0];\n\t\tfor (i=0; i 3)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"C arrays of only 1-3 dimensions available\");\n\t\tPy_XDECREF(typedescr);\n\t\treturn -1;\n\t}\n\tif ((ap = (PyArrayObject*)PyArray_FromAny(*op, typedescr, nd, nd,\n\t\t\t\t\t\t CARRAY_FLAGS)) == NULL)\n\t\treturn -1;\n\tswitch(nd) {\n\tcase 1:\n\t\t*((char **)ptr) = ap->data;\n\t\tbreak;\n\tcase 2:\n\t\tn = ap->dimensions[0];\n\t\tptr2 = (char **)_pya_malloc(n * sizeof(char *));\n\t\tif (!ptr2) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0];\n\t\t}\n\t\t*((char ***)ptr) = ptr2;\n\t\tbreak;\t\t\n\tcase 3:\n\t\tn = ap->dimensions[0];\n\t\tm = ap->dimensions[1];\n\t\tptr3 = (char ***)_pya_malloc(n*(m+1) * sizeof(char *));\n\t\tif (!ptr3) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0] + \\\n\t\t\t\t\tj*ap->strides[1];\n\t\t\t}\n\t\t}\n\t\t*((char ****)ptr) = ptr3;\n\t}\n\tmemcpy(dims, ap->dimensions, nd*sizeof(intp));\n\t*op = (PyObject *)ap;\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_MemoryError, \"no memory\");\n\treturn -1;\n}\n\n/* Deprecated --- Use PyArray_AsCArray instead */\n\n/*MULTIARRAY_API\n Convert to a 1D C-array\n*/\nstatic int \nPyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) \n{\n\tintp newd1;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, descr) == -1)\n\t\treturn -1;\t\n\t*d1 = (int) newd1;\n\treturn 0;\n}\n\n/*MULTIARRAY_API\n Convert to a 2D C-array\n*/\nstatic int \nPyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) \n{\n\tintp newdims[2];\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, newdims, 2, descr) == -1)\n\t\treturn -1;\n\n\t*d1 = (int ) newdims[0];\n\t*d2 = (int ) newdims[1];\n return 0;\n}\n\n/* End Deprecated */\n\n/*MULTIARRAY_API\n Free pointers created if As2D is called\n*/\nstatic int \nPyArray_Free(PyObject *op, void *ptr) \n{\n PyArrayObject *ap = (PyArrayObject *)op;\n\t\n if ((ap->nd < 1) || (ap->nd > 3)) \n\t\treturn -1;\n if (ap->nd >= 2) {\n\t\t_pya_free(ptr);\n }\n Py_DECREF(ap);\n return 0;\n}\n\n\nstatic PyObject *\n_swap_and_concat(PyObject *op, int axis, int n)\n{\n\tPyObject *newtup=NULL;\n\tPyObject *otmp, *arr;\n\tint i;\n\n\tnewtup = PyTuple_New(n);\n\tif (newtup==NULL) return NULL;\n\tfor (i=0; i= MAX_DIMS) {\n\t\t\totmp = PyArray_Ravel(mps[i],0);\n\t\t\tPy_DECREF(mps[i]);\n\t\t\tmps[i] = (PyArrayObject *)otmp;\n\t\t}\n\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\tif (prior2 > prior1) {\n\t\t\tprior1 = prior2;\n\t\t\tsubtype = mps[i]->ob_type;\n\t\t\tret = mps[i];\n\t\t}\n\t}\n\t\n\tnew_dim = 0;\n\tfor(i=0; ind;\n\t\telse {\n\t\t\tif (nd != mps[i]->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"arrays must have same \"\\\n\t\t\t\t\t\t\"number of dimensions\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CompareLists(mps[0]->dimensions+1, \n\t\t\t\t\t\t mps[i]->dimensions+1, \n\t\t\t\t\t\t nd-1)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"array dimensions must \"\\\n\t\t\t\t\t\t\"agree except for d_0\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (nd == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"0-d arrays can't be concatenated\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnew_dim += mps[i]->dimensions[0];\n\t}\n\t\n\ttmp = mps[0]->dimensions[0];\n\tmps[0]->dimensions[0] = new_dim;\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(subtype, \n\t\t\t\t\t\t mps[0]->descr, nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ret);\n\tmps[0]->dimensions[0] = tmp;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tdata = ret->data;\n\tfor(i=0; idata, numbytes);\n\t\tdata += numbytes;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; ind;\n\tif (n <= 1) {\n\t\tPy_INCREF(ap);\n\t\treturn (PyObject *)ap;\n\t}\n\n\tif (a1 < 0) a1 += n;\n\tif (a2 < 0) a2 += n;\n\tif ((a1 < 0) || (a1 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis1 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tif ((a2 < 0) || (a2 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis2 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tnew_axes.ptr = dims;\n\tnew_axes.len = n;\n\n\tfor (i=0; ind;\n\t\tfor(i=0; ilen;\n\t\taxes = permute->ptr;\n\t\tif (n > ap->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many axes for this array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tfor(i=0; ind+axis;\n\t\t\tif (axis < 0 || axis >= ap->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"invalid axis for this array\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tpermutation[i] = axis;\n\t\t}\n\t}\n\t\n\t/* this allocates memory for dimensions and strides (but fills them\n\t incorrectly), sets up descr, and points data at ap->data. */\n\tPy_INCREF(ap->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t ap->descr, \n\t\t\t\t n, permutation, \n\t\t\t\t NULL, ap->data, ap->flags,\n\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) return NULL;\n\t\n\t/* point at true owner of memory: */\n\tret->base = (PyObject *)ap;\n\tPy_INCREF(ap);\n\t\n\tfor(i=0; idimensions[i] = ap->dimensions[permutation[i]];\n\t\tret->strides[i] = ap->strides[permutation[i]];\n\t}\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\t\n\n\treturn (PyObject *)ret;\t\n}\n\n/*MULTIARRAY_API\n Repeat the array.\n*/\nstatic PyObject *\nPyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis)\n{\n\tintp *counts;\n\tintp n, n_outer, i, j, k, chunk, total;\n\tintp tmp;\n\tint nd;\n\tPyArrayObject *repeats=NULL;\n\tPyObject *ap=NULL;\n\tPyArrayObject *ret=NULL;\n\tchar *new_data, *old_data;\n\n\trepeats = (PyAO *)PyArray_ContiguousFromAny(op, PyArray_INTP, 0, 1);\n\tif (repeats == NULL) return NULL;\n\tnd = repeats->nd;\n\tcounts = (intp *)repeats->data;\n\n\tif ((ap=_check_axis(aop, &axis, CARRAY_FLAGS))==NULL) {\n\t\tPy_DECREF(repeats);\n\t\treturn NULL;\n\t}\n\n\taop = (PyAO *)ap;\n\n\tif (nd == 1)\n\t\tn = repeats->dimensions[0];\n\telse /* nd == 0 */\n\t\tn = aop->dimensions[axis];\n\n\tif (aop->dimensions[axis] != n) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"a.shape[axis] != len(repeats)\");\n\t\tgoto fail;\n\t}\n\n\t\n\tif (nd == 0) \n\t\ttotal = counts[0]*n;\n\telse {\n\t\t\n\t\ttotal = 0;\n\t\tfor(j=0; jdimensions[axis] = total;\n\tPy_INCREF(aop->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(aop->ob_type, \n\t\t\t\t\t\t aop->descr,\n\t\t\t\t\t\t aop->nd,\n\t\t\t\t\t\t aop->dimensions,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)aop);\n\taop->dimensions[axis] = n;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tnew_data = ret->data;\n\told_data = aop->data;\n\t\n\tchunk = aop->descr->elsize;\n\tfor(i=axis+1; ind; i++) {\n\t\tchunk *= aop->dimensions[i];\n\t}\n\t\n\tn_outer = 1;\n\tfor(i=0; idimensions[i];\n\n\tfor(i=0; ind < mps[i]->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many dimensions\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (!PyArray_CompareLists(ap->dimensions+(ap->nd-mps[i]->nd),\n\t\t\t\t mps[i]->dimensions, mps[i]->nd)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"array dimensions must agree\");\n\t\t\tgoto fail;\n\t\t}\n\t\tsizes[i] = PyArray_NBYTES(mps[i]);\n\t}\n\t\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t\t\t mps[0]->descr,\n\t\t\t\t\t\t ap->nd,\n\t\t\t\t\t\t ap->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\telsize = ret->descr->elsize;\n\tm = PyArray_SIZE(ret);\n\tself_data = (intp *)ap->data;\n\tret_data = ret->data;\n\t\n\tfor (i=0; i= n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid entry in choice array\");\n\t\t\tgoto fail;\n\t\t}\n\t\toffset = i*elsize;\n\t\tif (offset >= sizes[mi]) {offset = offset % sizes[mi]; }\n\t\tmemmove(ret_data, mps[mi]->data+offset, elsize);\n\t\tret_data += elsize; self_data++;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; idescr->f->sort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize);\n\n\tif (needcopy) {\n\t\tchar *buffer;\n\t\tbuffer = PyDataMem_NEW(N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(buffer, (intp) elsize, it->dataptr, \n\t\t\t\t astride, N, elsize);\n\t\t\tif (sort(buffer, N, op) < 0) {\n\t\t\t\tPyDataMem_FREE(buffer); goto fail;\n\t\t\t}\n\t\t\t_strided_copy(it->dataptr, astride, buffer, \n\t\t\t\t (intp) elsize, N, elsize);\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyDataMem_FREE(buffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tif (sort(it->dataptr, N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\t\n\t\n\tEND_THREADS\n\t\n\tPy_DECREF(it);\n\treturn 0;\n\n fail:\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nstatic PyObject*\n_new_argsort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\n\tPyArrayIterObject *it=NULL;\n\tPyArrayIterObject *rit=NULL;\n\tPyObject *ret;\n\tint needcopy=0, i;\n\tintp N, size;\n\tint elsize;\n\tintp astride, rstride, *iptr;\n\tPyArray_ArgSortFunc *argsort;\n\tBEGIN_THREADS_DEF \n\n\tret = PyArray_New(op->ob_type, op->nd,\n\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) return NULL;\n\n\tit = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)op, axis);\n\trit = (PyArrayIterObject *)PyArray_IterAllButAxis(ret, axis);\n\tif (rit == NULL || it == NULL) goto fail;\n\n\tBEGIN_THREADS\n\n\targsort = op->descr->f->argsort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize) || \\\n\t\t(rstride != sizeof(intp));\n\t\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(elsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(valbuffer, (intp) elsize, it->dataptr,\n\t\t\t\t astride, N, elsize);\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idataptr, rstride, indbuffer, \n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idataptr, (intp *)rit->dataptr, \n\t\t\t\t N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\t\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\tPy_DECREF(rit);\n\treturn ret;\n\n fail:\n\n\tEND_THREADS\n\n\tPy_DECREF(ret);\n\tPy_XDECREF(it);\n\tPy_XDECREF(rit);\n\treturn NULL;\n}\n\n\n/* Be sure to save this global_compare when necessary */\n\nstatic PyArrayObject *global_obj;\n\nstatic int \nqsortCompare (const void *a, const void *b) \n{\n\treturn global_obj->descr->f->compare(a,b,global_obj);\n}\n\n/* Consumes reference to ap (op gets it)\n op contains a version of the array with axes swapped if\n local variable axis is not the last dimension.\n orign must be defined locally. \n*/\n\n#define SWAPAXES(op, ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* Consumes reference to ap (op gets it)\n origin must be previously defined locally. \n SWAPAXES must have been called previously. \n op contains the swapped version of the array. \n*/\n#define SWAPBACK(op, ap) {\t \\\n\t\tif (axis != orign) { \\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* These swap axes in-place if necessary */\n#define SWAPINTP(a,b) {intp c; c=(a); (a) = (b); (b) = c;}\n#define SWAPAXES2(ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN); \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define SWAPBACK2(ap) {\t\t \\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n/*MULTIARRAY_API\n Sort an array in-place\n*/\nstatic int\nPyArray_Sort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *store_arr=NULL;\n\tchar *ip;\n\tint i, n, m, elsize, orign;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) return 0;\n\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\treturn -1;\n\t}\n\tif (!PyArray_ISWRITEABLE(op)) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"attempted sort on unwriteable array.\");\n\t\treturn -1;\n\t}\n\n\t/* Determine if we should use type-specific algorithm or not */\n\tif (op->descr->f->sort[which] != NULL) {\n\t\treturn _new_sort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || \\\n\t op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"desired sort not supported for this type\");\n\t\treturn -1;\n\t}\n\n\tSWAPAXES2(op);\n\n ap = (PyArrayObject *)PyArray_FromAny((PyObject *)op, \n\t\t\t\t\t NULL, 1, 0, \n\t\t\t\t\t DEFAULT_FLAGS | UPDATEIFCOPY);\t\n\tif (ap == NULL) goto fail;\n\t\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(ap)/m;\n\n\t/* Store global -- allows re-entry -- restore before leaving*/\n\tstore_arr = global_obj; \n\tglobal_obj = ap;\n\t\n\tfor (ip=ap->data, i=0; idescr->elsize;\n\tconst intp *ipa = ip1;\n\tconst intp *ipb = ip2;\t\n\treturn global_obj->descr->f->compare(global_data + (isize * *ipa),\n global_data + (isize * *ipb), \n\t\t\t\t\t global_obj);\n}\n\n/*MULTIARRAY_API\n ArgSort an array\n*/\nstatic PyObject *\nPyArray_ArgSort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *ret=NULL, *store;\n\tintp *ip;\n\tintp i, j, n, m, orign;\n\tint argsort_elsize;\n\tchar *store_ptr;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t\t op->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, \n\t\t\t\t\t\t (PyObject *)op);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)ret->data) = 0;\n\t\treturn (PyObject *)ret;\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\treturn NULL;\n\t}\n\n\t/* Determine if we should use new algorithm or not */\n\tif (op->descr->f->argsort[which] != NULL) {\n\t\treturn _new_argsort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"requested sort not available for type\");\n\t\tgoto fail;\n\t}\n\n\tSWAPAXES(ap, op);\n\n\top = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ap, \n\t\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t\t 1, 0);\n\n\tif (op == NULL) return NULL;\n\t\n\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) goto fail;\n\t\n\t\n\tip = (intp *)ret->data;\n\targsort_elsize = op->descr->elsize;\n\tm = op->dimensions[op->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(op)/m;\n\tstore_ptr = global_data;\n\tglobal_data = op->data;\n\tstore = global_obj;\n\tglobal_obj = op;\n\tfor (i=0; i 0 in lexsort\");\n\t\treturn NULL;\n\t}\n\tmps = (PyArrayObject **) _pya_malloc(n*sizeof(PyArrayObject));\n\tif (mps==NULL) return PyErr_NoMemory();\n\tits = (PyArrayIterObject **) _pya_malloc(n*sizeof(PyArrayIterObject));\n\tif (its == NULL) {_pya_free(mps); return PyErr_NoMemory();}\n\tfor (i=0; i0) {\n\t\t\tif ((mps[i]->nd != mps[0]->nd) ||\t\\\n\t\t\t (!PyArray_CompareLists(mps[i]->dimensions,\n\t\t\t\t\t\t mps[0]->dimensions,\n\t\t\t\t\t\t mps[0]->nd))) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"all keys need to be the same shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (!mps[i]->descr->f->argsort[PyArray_MERGESORT]) {\n\t\t\tPyErr_Format(PyExc_TypeError, \n\t\t\t\t \"merge sort not available for item %d\", i);\n\t\t\tgoto fail;\n\t\t}\n\t\tits[i] = (PyArrayIterObject *)PyArray_IterAllButAxis\t\\\n\t\t\t((PyObject *)mps[i], axis);\n\t\tif (its[i]==NULL) goto fail;\n\t}\n\n\t/* Now we can check the axis */\n\tnd = mps[0]->nd;\n\tif ((nd==0) || (PyArray_SIZE(mps[0])==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)(ret->data)) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += nd;\n\tif ((axis < 0) || (axis >= nd)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\tgoto fail;\n\t}\n\n\t/* Now do the sorting */\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t mps[0]->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (ret == NULL) goto fail;\n\n\trit = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ret, axis);\n\tif (rit == NULL) goto fail;\n\n\tsize = rit->size;\n\tN = mps[0]->dimensions[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n maxelsize = mps[0]->descr->elsize;\n\tneedcopy = (rstride != sizeof(intp));\n\tfor (j=0; jflags & ALIGNED) || \\\n\t\t\t(mps[j]->strides[axis] != (intp)mps[j]->descr->elsize);\n if (mps[j]->descr->elsize > maxelsize) \n maxelsize = mps[j]->descr->elsize;\n\t}\n\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(maxelsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*maxelsize);\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idescr->elsize;\n\t\t\t\tastride = mps[j]->strides[axis];\t\n\t\t\t\targsort = mps[j]->descr->f->argsort[PyArray_MERGESORT];\n\t\t\t\t_strided_copy(valbuffer, (intp) elsize, its[j]->dataptr,\n\t\t\t\t\t astride, N, elsize);\n\t\t\t\tif (argsort(valbuffer, (intp *)indbuffer, N, mps[j]) < 0) {\n\t\t\t\t\tPyDataMem_FREE(valbuffer); goto fail;\n\t\t\t\t}\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\t_strided_copy(rit->dataptr, rstride, indbuffer,\n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idescr->f->argsort[PyArray_MERGESORT];\n\t\t\t\tif (argsort(its[j]->dataptr, (intp *)rit->dataptr,\n\t\t\t\t\t N, mps[j]) < 0) goto fail;\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\n\tfor (i=0; idescr->f->compare;\n\tintp min_i, max_i, i, j;\n\tint location, elsize = ap1->descr->elsize;\n\tintp elements = ap1->dimensions[ap1->nd-1];\n\tintp n = PyArray_SIZE(ap2);\n\tintp *rp = (intp *)ret->data;\n\tchar *ip = ap2->data;\n\tchar *vp = ap1->data;\n\n\tfor (j=0; j 0) {\n\t\t\t\t\tif (compare(ip, vp+elsize*(--i), ap2) \\\n\t\t\t\t\t != 0) {\n\t\t\t\t\t\ti = i+1; break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmin_i = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (location < 0) {\n\t\t\t\tmax_i = i;\n\t\t\t} else {\n\t\t\t\tmin_i = i+1;\n\t\t\t}\n\t\t}\n\t\t*rp = min_i;\n\t}\n}\n\n/*MULTIARRAY_API\n Numeric.searchsorted(a,v)\n*/\nstatic PyObject *\nPyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n\tint typenum = 0;\n\n\t/* \n PyObject *args;\n args = Py_BuildValue(\"O\",op2);\n\tPy_DELEGATE_ARGS(((PyObject *)op1), searchsorted, args);\n Py_XDECREF(args);\n\t*/\n\n\ttypenum = PyArray_ObjectType((PyObject *)op1, 0);\n\ttypenum = PyArray_ObjectType(op2, typenum);\n\tret = NULL;\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op1, \n\t\t\t\t\t\t\t typenum, \n\t\t\t\t\t\t\t 1, 1);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tret = (PyArrayObject *)PyArray_New(ap2->ob_type, ap2->nd, \n\t\t\t\t\t ap2->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap2);\n\tif (ret == NULL) goto fail;\n\n\tif (ap2->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tgoto fail;\n\t}\n\t\n\tlocal_where(ap1, ap2, ret); \n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n\n\n/* Could perhaps be redone to not make contiguous arrays \n */\n\n/*MULTIARRAY_API\n Numeric.innerproduct(a,v)\n*/\nstatic PyObject *\nPyArray_InnerProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tintp i, j, l, i1, i2, n1, n2;\n\tint typenum;\n\tintp is1, is2, os;\n\tchar *ip1, *ip2, *op;\n\tintp dimensions[MAX_DIMS], nd;\n\tPyArray_DotFunc *dot;\n\tPyTypeObject *subtype;\n double prior1, prior2;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\t\t\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny(op1, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n \n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\tif (ret == NULL) goto fail;\n\n\tdot = (ret->descr->f->dotfunc);\n\t\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\n\t\n\tis1 = ap1->strides[ap1->nd-1]; \n\tis2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t\totherDim = ap2->nd - 1;\n\t}\n\telse {\n\t\tmatchDim = 0;\n\t\totherDim = 0;\n\t}\n\n\tif (ap2->dimensions[matchDim] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"objects are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-2; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\tif(ap2->nd > 1) {\n\t\tdimensions[j++] = ap2->dimensions[ap2->nd-1];\n\t}\n\t/*\n\tfprintf(stderr, \"nd=%d dimensions=\", nd);\n\t for(i=0; i prior1 ? ap2->ob_type : ap1->ob_type);\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\n\n\tif (ret == NULL) goto fail;\n\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\t\t\n\tis1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\tif(ap1->nd > 1)\n\t\tis1r = ap1->strides[ap1->nd-2];\n\telse\n\t\tis1r = ap1->strides[ap1->nd-1];\n\tis2r = ap2->strides[otherDim];\n\n\top = ret->data; os = ret->descr->elsize;\n\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t 2, dims, \n\t\t\t\t NULL, NULL, 0, arr);\n\n\tif (ret == NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn NULL;\n\t}\n\t/* do 2-d loop */\n\toptr = PyArray_DATA(ret);\n\tstr2 = elsize*dims[0];\n\tfor (i=0; idimensions[0];\n\tn2 = ap2->dimensions[0];\n\n\tif (n1 < n2) { \n\t\tret = ap1; ap1 = ap2; ap2 = ret; \n\t\tret = NULL; i = n1;n1=n2;n2=i;\n\t}\n\tlength = n1;\n\tn = n2;\n\tswitch(mode) {\n\tcase 0:\t\n\t\tlength = length-n+1;\n\t\tn_left = n_right = 0;\n\t\tbreak;\n\tcase 1:\n\t\tn_left = (intp)(n/2);\n\t\tn_right = n-n_left-1;\n\t\tbreak;\n\tcase 2:\n\t\tn_right = n-1;\n\t\tn_left = n-1;\n\t\tlength = length+n-1;\n\t\tbreak;\n\tdefault:\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mode must be 0, 1, or 2\");\n\t\tgoto fail;\n\t}\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t\n\tret = (PyArrayObject *)PyArray_New(subtype, 1,\n\t\t\t\t\t &length, typenum, \n\t\t\t\t\t NULL, NULL, 0, 0,\n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\tif (ret == NULL) goto fail;\n\t\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"function not available for this data type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[0]; is2 = ap2->strides[0];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data; ip2 = ap2->data+n_left*is2;\n\tn = n-n_left;\n\tfor(i=0; idescr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Min\n*/\nstatic PyObject *\nPyArray_Min(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tret = PyArray_GenericReduceFunction(arr, n_ops.minimum, axis,\n\t\t\t\t\t arr->descr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Ptp\n*/\nstatic PyObject *\nPyArray_Ptp(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\tPyObject *obj1=NULL, *obj2=NULL;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tobj1 = PyArray_Max(arr, axis);\n\tif (obj1 == NULL) goto fail;\n\tobj2 = PyArray_Min(arr, axis);\n\tif (obj2 == NULL) goto fail;\n\tPy_DECREF(arr);\n\tret = PyNumber_Subtract(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(obj1);\n\tPy_XDECREF(obj2);\n\treturn NULL;\n}\n\n\n/*MULTIARRAY_API\n ArgMax\n*/\nstatic PyObject *\nPyArray_ArgMax(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap=NULL, *rp=NULL;\n\tPyArray_ArgFunc* arg_func;\n\tchar *ip;\n\tintp *rptr;\n\tintp i, n, orign, m;\n\tint elsize;\n\t\n\tif ((ap=(PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny((PyObject *)op, \n\t\t\t\t\t PyArray_NOTYPE, 1, 0);\n\n\tPy_DECREF(op);\n\tif (ap == NULL) return NULL;\n\t\n\targ_func = ap->descr->f->argmax;\n\tif (arg_func == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"data type not ordered\");\n\t\tgoto fail;\n\t}\n\n\trp = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd-1,\n\t\t\t\t\t ap->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)ap);\n\tif (rp == NULL) goto fail;\n\n\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) {\n\t\tPyErr_SetString(MultiArrayError, \n\t\t\t\t\"attempt to get argmax/argmin \"\\\n\t\t\t\t\"of an empty sequence??\");\n\t\tgoto fail;\n\t}\n\tn = PyArray_SIZE(ap)/m;\n\trptr = (intp *)rp->data;\n\tfor (ip = ap->data, i=0; ind + indices->nd - 1;\n for (i=0; i< nd; i++) {\n if (i < axis) {\n shape[i] = self->dimensions[i];\n n *= shape[i];\n } else {\n if (i < axis+indices->nd) {\n shape[i] = indices->dimensions[i-axis];\n m *= shape[i];\n } else {\n shape[i] = self->dimensions[i-indices->nd+1];\n chunk *= shape[i];\n }\n }\n }\n\tPy_INCREF(self->descr);\n ret = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t nd, shape, \n\t\t\t\t\t\t NULL, NULL, 0, \n\t\t\t\t\t\t (PyObject *)self);\n\t\n if (ret == NULL) goto fail;\n\t\n max_item = self->dimensions[axis];\n chunk = chunk * ret->descr->elsize;\n src = self->data;\n dest = ret->data;\n\t\n for(i=0; idata))[j];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\t\"index out of range for \"\\\n\t\t\t\t\t\t\"array\");\n goto fail;\n }\n memmove(dest, src+tmp*chunk, chunk);\n dest += chunk;\n }\n src += chunk*max_item;\n }\n\t\n PyArray_INCREF(ret);\n\n Py_XDECREF(indices);\n Py_XDECREF(self);\n\n return (PyObject *)ret;\n\t\n\t\n fail:\n Py_XDECREF(ret);\n Py_XDECREF(indices);\n Py_XDECREF(self);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array\n*/\nstatic PyObject *\nPyArray_Put(PyArrayObject *self, PyObject* values0, PyObject *indices0) \n{\n PyArrayObject *indices, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype; \n char *src, *dest;\n\n indices = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \"put: first argument must be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \"put: first argument must be contiguous\");\n return NULL;\n }\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0);\n if (indices == NULL) goto fail;\n ni = PyArray_SIZE(indices);\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\n if (thistype == PyArray_OBJECT) { \n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n Py_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+tmp*chunk)));\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n\n }\n\n Py_XDECREF(values);\n Py_XDECREF(indices);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(indices);\n Py_XDECREF(values);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array according to a mask.\n*/\nstatic PyObject *\nPyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) \n{\n PyArrayObject *mask, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype;\n char *src, *dest;\n\n mask = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"putmask: first argument must \"\\\n\t\t\t\t\"be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: first argument must be contiguous\");\n return NULL;\n }\n\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n mask = (PyArrayObject *)\\\n\t\tPyArray_FROM_OTF(mask0, PyArray_BOOL, CARRAY_FLAGS | FORCECAST);\n\tif (mask == NULL) goto fail;\n ni = PyArray_SIZE(mask);\n if (ni != max_item) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: mask and data must be \"\\\n\t\t\t\t\"the same size\");\n goto fail;\n }\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n\tif (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\t /* zero if null array */\n if (nv > 0) {\n if (thistype == PyArray_OBJECT) {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) {\n\t\t\t\t\tPy_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+i*chunk)));\n memmove(dest + i * chunk, src, chunk);\n }\n\t\t\t}\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) memmove(dest + i * chunk, src, chunk);\n\t\t\t}\n\t\t}\n }\n\n Py_XDECREF(values);\n Py_XDECREF(mask);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(mask);\n Py_XDECREF(values);\n return NULL;\n}\n\n\n/* This conversion function can be used with the \"O&\" argument for\n PyArg_ParseTuple. It will immediately return an object of array type\n or will convert to a CARRAY any other object. \n\n If you use PyArray_Converter, you must DECREF the array when finished\n as you get a new reference to it.\n*/\n \n/*MULTIARRAY_API\n Useful to pass as converter function for O& processing in\n PyArgs_ParseTuple.\n*/\nstatic int \nPyArray_Converter(PyObject *object, PyObject **address) \n{\n if (PyArray_Check(object)) {\n *address = object;\n\t\tPy_INCREF(object);\n return PY_SUCCEED;\n }\n else {\n\t\t*address = PyArray_FromAny(object, NULL, 0, 0, CARRAY_FLAGS);\n\t\tif (*address == NULL) return PY_FAIL;\n\t\treturn PY_SUCCEED;\n }\n}\n\n/*MULTIARRAY_API\n Convert an object to true / false\n*/\nstatic int\nPyArray_BoolConverter(PyObject *object, Bool *val)\n{ \n if (PyObject_IsTrue(object))\n *val=TRUE;\n else *val=FALSE;\n if (PyErr_Occurred())\n return PY_FAIL;\n return PY_SUCCEED;\n}\n\n\n/*MULTIARRAY_API\n Typestr converter\n*/\nstatic int\nPyArray_TypestrConvert(int itemsize, int gentype)\n{\n\tregister int newtype = gentype;\n\t\n\tif (gentype == PyArray_GENBOOLLTR) {\n\t\tif (itemsize == 1)\n\t\t\tnewtype = PyArray_BOOL;\n\t\telse \n\t\t\tnewtype = PyArray_NOTYPE;\n\t}\n\telse if (gentype == PyArray_SIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_INT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_INT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_INT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_INT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_INT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\n\t}\n\n\telse if (gentype == PyArray_UNSIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_UINT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_UINT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_UINT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_UINT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_UINT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t\tbreak;\n\t\t}\n\t}\n\telse if (gentype == PyArray_FLOATINGLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 4:\n\t\t\tnewtype = PyArray_FLOAT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_FLOAT64;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 10:\n\t\t\tnewtype = PyArray_FLOAT80;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 12:\n\t\t\tnewtype = PyArray_FLOAT96;\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_FLOAT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\t\n\telse if (gentype == PyArray_COMPLEXLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 8:\n\t\t\tnewtype = PyArray_COMPLEX64;\n\t\t\tbreak;\n\t\tcase 16:\n\t\t\tnewtype = PyArray_COMPLEX128;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 20:\n\t\t\tnewtype = PyArray_COMPLEX160;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 24:\n\t\t\tnewtype = PyArray_COMPLEX192;\t\t\t\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 32:\n\t\t\tnewtype = PyArray_COMPLEX256;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\n\treturn newtype;\n}\n\n\n/* this function takes a Python object which exposes the (single-segment)\n buffer interface and returns a pointer to the data segment\n \n You should increment the reference count by one of buf->base\n if you will hang on to a reference\n\n You only get a borrowed reference to the object. Do not free the\n memory...\n*/\n\n\n/*MULTIARRAY_API\n Get buffer chunk from object\n*/\nstatic int\nPyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)\n{\n int buflen;\n\n buf->ptr = NULL;\n buf->flags = BEHAVED_FLAGS;\n buf->base = NULL;\n\n\tif (obj == Py_None)\n\t\treturn PY_SUCCEED;\n\n if (PyObject_AsWriteBuffer(obj, &(buf->ptr), &buflen) < 0) {\n PyErr_Clear();\n buf->flags &= ~WRITEABLE;\n if (PyObject_AsReadBuffer(obj, (const void **)&(buf->ptr), \n &buflen) < 0)\n return PY_FAIL;\n }\n buf->len = (intp) buflen;\n \n /* Point to the base of the buffer object if present */\n if (PyBuffer_Check(obj)) buf->base = ((PyArray_Chunk *)obj)->base;\n if (buf->base == NULL) buf->base = obj;\n \n return PY_SUCCEED; \n}\n\n\n\n/* This function takes a Python sequence object and allocates and\n fills in an intp array with the converted values.\n\n **Remember to free the pointer seq.ptr when done using\n PyDimMem_FREE(seq.ptr)**\n*/\n\n/*MULTIARRAY_API\n Get intp chunk from sequence\n*/\nstatic int\nPyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)\n{\n int len;\n int nd;\n\n seq->ptr = NULL;\n if (obj == Py_None) return PY_SUCCEED;\n len = PySequence_Size(obj);\n if (len == -1) { /* Check to see if it is a number */\n if (PyNumber_Check(obj)) len = 1;\n }\n if (len < 0) {\n PyErr_SetString(PyExc_TypeError, \n \"expected sequence object with len >= 0\");\n return PY_FAIL;\n }\n if (len > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError, \"sequence too large; \" \\\n \"must be smaller than %d\", MAX_DIMS);\n return PY_FAIL;\n }\n\tif (len > 0) {\n\t\tseq->ptr = PyDimMem_NEW(len);\n\t\tif (seq->ptr == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n seq->len = len;\n nd = PyArray_IntpFromSequence(obj, (intp *)seq->ptr, len);\n if (nd == -1 || nd != len) {\n\t\tPyDimMem_FREE(seq->ptr);\n\t\tseq->ptr=NULL;\n\t\treturn PY_FAIL;\n\t}\n return PY_SUCCEED;\n}\n\n\n/* A tuple type would be either (generic typeobject, typesize) \n or (fixed-length data-type, shape) \n\n or (inheriting data-type, new-data-type)\n The new data-type must have the same itemsize as the inheriting data-type\n unless the latter is 0 \n \n Thus (int32, {'real':(int16,0),'imag',(int16,2)})\n\n is one way to specify a descriptor that will give \n a['real'] and a['imag'] to an int32 array.\n*/\n\n/* leave type reference alone */\nstatic PyArray_Descr *\n_use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) \n{\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n\t\n\t*errflag = 0;\n\tif (!PyArray_DescrConverter(newobj, &conv)) {\n\t\treturn NULL;\n\t}\n\t*errflag = 1;\n\tif (type == &OBJECT_Descr) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"cannot base a new descriptor on an\"\\\n\t\t\t\t\" OBJECT descriptor.\");\n\t\treturn NULL;\n\t}\n\tnew = PyArray_DescrNew(type);\n\tif (new == NULL) return NULL;\n\n\tif (new->elsize && new->elsize != conv->elsize) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mismatch in size of old\"\\\n\t\t\t\t\"and new data-descriptor\");\n\t\treturn NULL;\n\t}\n\tnew->elsize = conv->elsize;\n\tif (conv->fields != Py_None) {\n\t\tnew->fields = conv->fields;\n\t\tPy_XINCREF(new->fields);\n\t}\n\tPy_DECREF(conv);\n\t*errflag = 0;\n\treturn new;\n}\n\nstatic PyArray_Descr *\n_convert_from_tuple(PyObject *obj) \n{\n\tPyArray_Descr *type, *res;\n\tPyObject *val;\n\tint errflag;\n\t\n\tif (PyTuple_GET_SIZE(obj) != 2) return NULL;\n\n\tif (!PyArray_DescrConverter(PyTuple_GET_ITEM(obj,0), &type)) \n\t\treturn NULL;\n\tval = PyTuple_GET_ITEM(obj,1);\n\t/* try to interpret next item as a type */\n\tres = _use_inherit(type, val, &errflag);\n\tif (res || errflag) {\n\t\tPy_DECREF(type);\n\t\tif (res) return res;\n\t\telse return NULL;\n\t}\n\tPyErr_Clear();\n\t/* We get here if res was NULL but errflag wasn't set\n\t --- i.e. the conversion to a data-descr failed in _use_inherit\n\t*/\n\n\tif (type->elsize == 0) { /* interpret next item as a typesize */\n\t\tint itemsize;\n\t\titemsize = PyArray_PyIntAsInt(PyTuple_GET_ITEM(obj,1));\n\t\tif (error_converting(itemsize)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid itemsize in generic type \"\\\n\t\t\t\t\t\"tuple\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(type);\n\t\ttype->elsize = itemsize;\n\t}\n\telse {\n\t\t/* interpret next item as shape (if it's a tuple)\n\t\t and reset the type to PyArray_VOID with \n\t\t anew fields attribute. \n\t */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyArray_Descr *newdescr;\n\t\tif (!(PyArray_IntpConverter(val, &shape)) || \n\t\t (shape.len > MAX_DIMS)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnewdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tif (newdescr == NULL) {PyDimMem_FREE(shape.ptr); goto fail;}\n\t\tnewdescr->elsize = type->elsize;\n\t\tnewdescr->elsize *= PyArray_MultiplyList(shape.ptr, \n\t\t\t\t\t\t\t shape.len);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tnewdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tnewdescr->subarray->base = type;\n\t\tPy_INCREF(val);\n\t\tnewdescr->subarray->shape = val;\n\t\tPy_XDECREF(newdescr->fields);\n\t\tnewdescr->fields = NULL;\n\t\ttype = newdescr;\n\t}\n\treturn type;\n\n fail:\n\tPy_XDECREF(type);\n\treturn NULL;\n}\n\n/* obj is a list. Each item is a tuple with\n\n(field-name, data-type (either a list or a string), and an optional \n shape parameter).\n*/\nstatic PyArray_Descr *\n_convert_from_array_descr(PyObject *obj)\n{\n\tint n, i, totalsize;\n\tint ret;\n\tPyObject *fields, *item, *newobj;\n\tPyObject *name, *key, *tup;\n\tPyObject *nameslist;\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n\t\n\tn = PyList_GET_SIZE(obj);\t\n\tnameslist = PyList_New(n);\n\tif (!nameslist) return NULL;\n\ttotalsize = 0;\n\tfields = PyDict_New();\n\tfor (i=0; ielsize;\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(tup);\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n\tnew->elsize = totalsize;\n\treturn new;\n \n fail:\n\tPy_DECREF(fields);\n\tPy_DECREF(nameslist);\n\treturn NULL;\n\n}\n\n/* a list specifying a data-type can just be\n a list of formats. The names for the fields\n will default to f1, f2, f3, and so forth.\n\n or it can be an array_descr format string -- in which case\n align must be 0. \n*/\n\nstatic PyArray_Descr *\n_convert_from_list(PyObject *obj, int align, int try_descr)\n{\n\tint n, i;\n\tint totalsize;\n\tPyObject *fields;\n\tPyArray_Descr *conv=NULL;\n\tPyArray_Descr *new;\n\tPyObject *key, *tup;\n\tPyObject *nameslist=NULL;\n \tint ret;\n\tint maxalign=0;\n\t\n\tn = PyList_GET_SIZE(obj);\n\ttotalsize = 0;\n\tif (n==0) return NULL;\n\tnameslist = PyList_New(n);\n\tif (!nameslist) return NULL;\n\tfields = PyDict_New();\n\tfor (i=0; ialignment;\n\t\t\tif (_align > 1) totalsize =\t\t\t\\\n\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\tmaxalign = MAX(maxalign, _align);\n\t\t}\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\tPyDict_SetItem(fields, key, tup);\n\t\tPy_DECREF(tup);\n\t\tPyList_SET_ITEM(nameslist, i, key);\n\t\tif (ret == PY_FAIL) goto fail;\n\t\ttotalsize += conv->elsize;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n\tif (maxalign > 1) {\n\t\ttotalsize = ((totalsize+maxalign-1)/maxalign)*maxalign;\n\t}\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\treturn new;\n\n fail:\n\tPy_DECREF(nameslist);\n\tPy_DECREF(fields);\n\tif (!try_descr) return NULL;\n\tif (align) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"failed to convert from list of formats \"\\\n\t\t\t\t\"and align cannot be 1 for conversion from \"\\\n\t\t\t\t\"array_descr structure\");\n\t\treturn NULL;\n\t}\n\tPyErr_Clear();\n\treturn _convert_from_array_descr(obj);\n}\n\n\n/* comma-separated string */\n/* this is the format developed by the numarray records module */\n/* and implemented by the format parser in that module */\n/* this is an alternative implementation found in the _internal.py \n file patterned after that one -- the approach is to try to convert \n to a list (with tuples if any repeat information is present) \n and then call the _convert_from_list)\n*/\n\nstatic PyArray_Descr *\n_convert_from_commastring(PyObject *obj, int align)\n{\n\tPyObject *listobj;\n\tPyArray_Descr *res;\n\n\tif (!PyString_Check(obj)) return NULL;\n listobj = PyObject_CallMethod(_numpy_internal, \"_commastring\",\n\t\t\t\t \"O\", obj);\n\tif (!listobj) return NULL;\n\tres = _convert_from_list(listobj, align, 0);\n\tPy_DECREF(listobj);\n\tif (!res && !PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_ValueError, \"invalid data-type\");\n\t\treturn NULL;\n\t}\n\treturn res;\n}\n\n\n\n/* a dictionary specifying a data-type\n must have at least two and up to four\n keys These must all be sequences of the same length.\n\n \"names\" --- field names \n \"formats\" --- the data-type descriptors for the field.\n \n Optional:\n\n \"offsets\" --- integers indicating the offset into the \n record of the start of the field.\n\t\t if not given, then \"consecutive offsets\" \n\t\t will be assumed and placed in the dictionary.\n \n \"titles\" --- Allows the use of an additional key\n for the fields dictionary.\n \nAttribute-lookup-based field names merely has to query the fields \ndictionary of the data-descriptor. Any result present can be used\nto return the correct field.\n\nSo, the notion of what is a name and what is a title is really quite\narbitrary. \n\nWhat does distinguish a title, however, is that if it is not None, \nit will be placed at the end of the tuple inserted into the \nfields dictionary.\n\nIf the dictionary does not have \"names\" and \"formats\" entries,\nthen it will be checked for conformity and used directly. \n*/\n\nstatic PyArray_Descr *\n_use_fields_dict(PyObject *obj, int align)\n{\n return (PyArray_Descr *)PyObject_CallMethod(_numpy_internal, \n\t\t\t\t\t\t \"_usefields\", \n\t\t\t\t\t\t \"Oi\", obj, align);\n}\n\nstatic PyArray_Descr *\n_convert_from_dict(PyObject *obj, int align)\n{\n\tPyArray_Descr *new;\n\tPyObject *fields=NULL;\n\tPyObject *names, *offsets, *descrs, *titles, *key;\n\tint n, i;\n\tint totalsize;\n\tint maxalign=0;\n\t\n\tfields = PyDict_New();\n\tif (fields == NULL) return (PyArray_Descr *)PyErr_NoMemory();\n\t\n\tnames = PyDict_GetItemString(obj, \"names\");\n\tdescrs = PyDict_GetItemString(obj, \"formats\");\n\n\tif (!names || !descrs) {\n\t\tPy_DECREF(fields);\n\t\treturn _use_fields_dict(obj, align);\n\t}\n\tn = PyObject_Length(names);\n\toffsets = PyDict_GetItemString(obj, \"offsets\");\n\ttitles = PyDict_GetItemString(obj, \"titles\");\n\tif ((n > PyObject_Length(descrs)) ||\t\t\t\\\n\t (offsets && (n > PyObject_Length(offsets))) ||\t\\\n\t (titles && (n > PyObject_Length(titles)))) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"all items in the dictionary must have\" \\\n\t\t\t\t\" the same length.\");\n\t\tgoto fail;\n\t}\n\n\ttotalsize = 0;\n\tfor(i=0; i totalsize) totalsize = offset;\n\t\t}\n\t\telse {\n\t\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\n\t\t\tif (align) {\n\t\t\t\tint _align = newdescr->alignment;\n\t\t\t\tif (_align > 1) totalsize =\t\t\\\n\t\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\t\tmaxalign = MAX(maxalign,_align);\n\t\t\t}\n\t\t}\n\t\tif (len == 3) PyTuple_SET_ITEM(tup, 2, item);\n\t\tname = PyObject_GetItem(names, index);\n\t\tPy_DECREF(index);\n\n\t\t/* Insert into dictionary */\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) PyDict_SetItem(fields, item, tup);\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n\t\ttotalsize += newdescr->elsize;\n\t}\n\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tif (new == NULL) goto fail;\n\tif (maxalign > 1)\n\t\ttotalsize = ((totalsize + maxalign - 1)/maxalign)*maxalign;\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, names);\n\tPy_DECREF(key);\n\tnew->fields = fields;\n\treturn new;\n\n fail:\n\tPy_XDECREF(fields);\n\treturn NULL;\n}\n\n/* \n any object with \n the .fields attribute and/or .itemsize attribute \n (if the .fields attribute does not give\n the total size -- i.e. a partial record naming).\n If itemsize is given it must be >= size computed from fields\n \n The .fields attribute must return a convertible dictionary if \n present. Result inherits from PyArray_VOID.\n*/\n\n\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to NULL\n*/\nstatic int\nPyArray_DescrConverter2(PyObject *obj, PyArray_Descr **at)\n{\n\tif (obj == Py_None) {\n\t\t*at = NULL;\n\t\treturn PY_SUCCEED;\n\t}\n\telse return PyArray_DescrConverter(obj, at);\n}\n\n/* This function takes a Python object representing a type and converts it \n to a the correct PyArray_Descr * structure to describe the type.\n \n Many objects can be used to represent a data-type which in NumPy is\n quite a flexible concept. \n\n This is the central code that converts Python objects to \n Type-descriptor objects that are used throughout numpy.\n */\n\n/* new reference in *at */\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to &LONG_descr\n*/\nstatic int\nPyArray_DescrConverter(PyObject *obj, PyArray_Descr **at)\n{\n char *type;\n int check_num=PyArray_NOTYPE+10;\n\tint len;\n\tPyObject *item;\n\tint elsize = 0;\n\tchar endian = '=';\n\n\t*at=NULL;\n\t\n\t/* default */\n if (obj == Py_None) {\n\t\t*at = PyArray_DescrFromType(PyArray_LONG);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n\tif (PyArray_DescrCheck(obj)) {\n\t\t*at = (PyArray_Descr *)obj;\n\t\tPy_INCREF(*at);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n if (PyType_Check(obj)) {\n\t\tif (PyType_IsSubtype((PyTypeObject *)obj, \n\t\t\t\t &PyGenericArrType_Type)) {\n\t\t\t*at = PyArray_DescrFromTypeObject(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t\telse return PY_FAIL;\n\t\t}\n\t\tcheck_num = PyArray_OBJECT;\n\t\tif (obj == (PyObject *)(&PyInt_Type))\n\t\t\tcheck_num = PyArray_LONG;\n\t\telse if (obj == (PyObject *)(&PyLong_Type))\n\t\t\tcheck_num = PyArray_LONGLONG;\n\t\telse if (obj == (PyObject *)(&PyFloat_Type)) \n\t\t\tcheck_num = PyArray_DOUBLE;\n\t\telse if (obj == (PyObject *)(&PyComplex_Type)) \n\t\t\tcheck_num = PyArray_CDOUBLE;\n\t\telse if (obj == (PyObject *)(&PyBool_Type))\n\t\t\tcheck_num = PyArray_BOOL;\n else if (obj == (PyObject *)(&PyString_Type))\n check_num = PyArray_STRING;\n else if (obj == (PyObject *)(&PyUnicode_Type))\n check_num = PyArray_UNICODE;\n\t\telse if (obj == (PyObject *)(&PyBuffer_Type))\n\t\t\tcheck_num = PyArray_VOID;\n\t\telse {\n\t\t\t*at = _arraydescr_fromobj(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* or a typecode string */\n\n\tif (PyString_Check(obj)) {\n\t\t/* Check for a string typecode. */\n\t\ttype = PyString_AS_STRING(obj);\n\t\tlen = PyString_GET_SIZE(obj);\n\t\tif (len <= 0) goto fail;\n\t\tcheck_num = (int) type[0];\n\t\tif ((char) check_num == '>' || (char) check_num == '<' || \\\n\t\t (char) check_num == '|') {\n\t\t\tif (len <= 1) goto fail;\n\t\t\tendian = (char) check_num;\n\t\t\ttype++; len--;\n\t\t\tcheck_num = (int) type[0];\n\t\t\tif (endian == '|') endian = '=';\n\t\t}\n\t\tif (len > 1) {\n\t\t\telsize = atoi(type+1);\n\t\t\tif (len > 2 && elsize < 10) {\n\t\t\t\t/* perhaps commas present */\n\t\t\t\tint i;\n\t\t\t\tfor (i=1;ielsize == 0) && (elsize != 0)) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->elsize = elsize;\n\t}\n\tif (endian != '=' && PyArray_ISNBO(endian)) endian = '='; \n\t\n\tif (endian != '=' && (*at)->byteorder != '|' &&\t\\\n\t (*at)->byteorder != endian) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->byteorder = endian;\n\t}\n\t\n return PY_SUCCEED;\n\n fail:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"data type not understood\");\n\t*at=NULL;\n\treturn PY_FAIL;\n}\t\n\n/*MULTIARRAY_API\n Convert object to endian\n*/\nstatic int\nPyArray_ByteorderConverter(PyObject *obj, char *endian)\n{\n\tchar *str;\n\t*endian = PyArray_SWAP;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Byteorder string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\t*endian = str[0];\n\tif (str[0] != PyArray_BIG && str[0] != PyArray_LITTLE &&\t\\\n\t str[0] != PyArray_NATIVE) {\n\t\tif (str[0] == 'b' || str[0] == 'B')\n\t\t\t*endian = PyArray_BIG;\n\t\telse if (str[0] == 'l' || str[0] == 'L')\n\t\t\t*endian = PyArray_LITTLE;\n\t\telse if (str[0] == 'n' || str[0] == 'N')\n\t\t\t*endian = PyArray_NATIVE;\n\t\telse if (str[0] == 'i' || str[0] == 'I')\n\t\t\t*endian = PyArray_IGNORE;\n\t\telse if (str[0] == 's' || str[0] == 'S')\n\t\t\t*endian = PyArray_SWAP;\n\t\telse {\n\t\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t\t \"%s is an unrecognized byteorder\",\n\t\t\t\t str);\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Convert object to sort kind \n*/\nstatic int\nPyArray_SortkindConverter(PyObject *obj, PyArray_SORTKIND *sortkind)\n{\n\tchar *str;\n\t*sortkind = PyArray_QUICKSORT;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Sort kind string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\tif (str[0] == 'q' || str[0] == 'Q')\n\t\t*sortkind = PyArray_QUICKSORT;\n\telse if (str[0] == 'h' || str[0] == 'H')\n\t\t*sortkind = PyArray_HEAPSORT;\n\telse if (str[0] == 'm' || str[0] == 'M')\n\t\t*sortkind = PyArray_MERGESORT;\n\telse if (str[0] == 't' || str[0] == 'T')\n\t\t*sortkind = PyArray_TIMSORT;\n\telse {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"%s is an unrecognized kind of sort\",\n\t\t\t str);\n\t\treturn PY_FAIL;\n\t}\n\treturn PY_SUCCEED;\n}\n\n\n/* This function returns true if the two typecodes are \n equivalent (same basic kind and same itemsize).\n*/\n\n/*MULTIARRAY_API*/\nstatic Bool\nPyArray_EquivTypes(PyArray_Descr *typ1, PyArray_Descr *typ2)\n{\n\tregister int typenum1=typ1->type_num;\n\tregister int typenum2=typ2->type_num;\n\tregister int size1=typ1->elsize;\n\tregister int size2=typ2->elsize;\n\n\tif (size1 != size2) return FALSE;\n\tif (typ1->fields != typ2->fields) return FALSE;\n\tif (PyArray_ISNBO(typ1->byteorder) != PyArray_ISNBO(typ2->byteorder))\n\t\treturn FALSE;\n\n\tif (typenum1 == PyArray_VOID || \\\n\t typenum2 == PyArray_VOID) {\n\t\treturn ((typenum1 == typenum2) && \n\t\t\t(typ1->typeobj == typ2->typeobj) &&\n\t\t\t(typ1->fields == typ2->fields));\n\t}\n\treturn (typ1->kind == typ2->kind);\n}\n\n/*** END C-API FUNCTIONS **/\n\n\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_fromobject[] = \"array(object, dtype=None, copy=1, fortran=0, \"\\\n \"subok=0)\\n\"\\\n \"will return a new array formed from the given object type given.\\n\"\\\n \"Object can anything with an __array__ method, or any object\\n\"\\\n \"exposing the array interface, or any (nested) sequence.\\n\"\\\n \"If no type is given, then the type will be determined as the\\n\"\\\n \"minimum type required to hold the objects in the sequence.\\n\"\\\n \"If copy is zero and sequence is already an array with the right \\n\"\\\n \"type, a reference will be returned. If the sequence is an array,\\n\"\\\n \"type can be used only to upcast the array. For downcasting \\n\"\\\n \"use .astype(t) method. If subok is true, then subclasses of the\\n\"\\\n \"array may be returned. Otherwise, a base-class ndarray is returned\";\n\nstatic PyObject *\n_array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n{\n\tPyObject *op, *ret=NULL;\n\tstatic char *kwd[]= {\"object\", \"dtype\", \"copy\", \"fortran\", \"subok\", \n NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tPyArray_Descr *type=NULL;\n\tPyArray_Descr *oldtype=NULL;\n\tBool fortran=FALSE;\n\tint flags=0;\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&\", kwd, &op, \n\t\t\t\t\tPyArray_DescrConverter2,\n &type, \n\t\t\t\t\tPyArray_BoolConverter, ©, \n\t\t\t\t\tPyArray_BoolConverter, &fortran,\n PyArray_BoolConverter, &subok)) \n\t\treturn NULL;\n\n\t/* fast exit if simple call */\n\tif ((PyArray_CheckExact(op) || PyBigArray_CheckExact(op))) {\n\t\tif (type==NULL) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\treturn op;\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn PyArray_NewCopy((PyArrayObject*)op, \n\t\t\t\t\t\t fortran);\n\t\t\t}\n\t\t}\n\t\t/* One more chance */\n\t\toldtype = PyArray_DESCR(op);\n\t\tif (PyArray_EquivTypes(oldtype, type)) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\treturn op;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op,\n\t\t\t\t\t\t fortran);\n\t\t\t\tif (oldtype == type) return ret;\n\t\t\t\tPy_INCREF(oldtype);\n\t\t\t\tPy_DECREF(PyArray_DESCR(ret));\n\t\t\t\tPyArray_DESCR(ret) = oldtype;\n\t\t\t\treturn ret;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (copy) {\n\t\tflags = ENSURECOPY;\n\t}\n\tif (fortran) {\n\t\tflags |= FORTRAN;\n\t}\n if (!subok) {\n flags |= ENSUREARRAY;\n }\n\n\tif ((ret = PyArray_FromAny(op, type, 0, 0, flags)) == NULL) \n\t\treturn NULL;\n\n\treturn ret;\n}\n\n/* accepts NULL type */\n/* steals referenct to type */\n/*MULTIARRAY_API\n Empty\n*/\nstatic PyObject *\nPyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n \n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type, nd, dims, \n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n PyArray_FillObjectArray(ret, Py_None);\n\t}\n\treturn (PyObject *)ret;\n}\n\n\nstatic char doc_empty[] = \"empty((d1,...,dn),dtype=int,fortran=0) will return a new array\\n of shape (d1,...,dn) and given type with all its entries uninitialized. This can be faster than zeros.\";\n\nstatic PyObject *\narray_empty(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter, &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Empty(shape.len, shape.ptr, typecode, fortran); \n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_scalar[] = \"scalar(dtypedescr,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtypedescr must be a valid data-type descriptor. If dtypedescr corresponds to an OBJECT descriptor, then obj can be any object, otherwise obj must be a string. If obj is not given it will be interpreted as None for object type and zeros for all other types.\";\n\nstatic PyObject *\narray_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"dtypedescr\",\"obj\", NULL};\n\tPyArray_Descr *typecode;\n\tPyObject *obj=NULL;\n\tint alloc=0;\n\tvoid *dptr;\n\tPyObject *ret;\n\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|O\",\n\t\t\t\t\t kwlist, &PyArrayDescr_Type, \n\t\t\t\t\t &typecode,\n\t\t\t\t\t &obj)) \n\t\treturn NULL;\n\t\t\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\t\t\\\n\t\t\t\t\"itemsize cannot be zero\");\n\t\treturn NULL;\n\t}\n\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (obj == NULL) obj = Py_None;\n\t\tdptr = &obj;\n\t}\n\telse {\n\t\tif (obj == NULL) {\n\t\t\tdptr = _pya_malloc(typecode->elsize);\n\t\t\tif (dptr == NULL) {\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemset(dptr, '\\0', typecode->elsize);\n\t\t\talloc = 1;\n\t\t}\n\t\telse {\n\t\t\tif (!PyString_Check(obj)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"initializing object must \"\\\n\t\t\t\t\t\t\"be a string\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tif (PyString_GET_SIZE(obj) < typecode->elsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"initialization string is too\"\\\n\t\t\t\t\t\t\" small\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdptr = PyString_AS_STRING(obj);\n\t\t}\n\t}\n\n\tret = PyArray_Scalar(dptr, typecode, NULL);\n\t\n\t/* free dptr which contains zeros */\n\tif (alloc) _pya_free(dptr);\n\treturn ret;\n}\n\n\n/* steal a reference */\n/* accepts NULL type */\n/*MULTIARRAY_API\n Zeros\n*/\nstatic PyObject *\nPyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n\tintp n;\n\n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type,\n\t\t\t\t\t\t nd, dims, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n\t\tPyObject *zero = PyInt_FromLong(0);\n PyArray_FillObjectArray(ret, zero);\n Py_DECREF(zero);\n\t}\n\telse {\n\t\tn = PyArray_NBYTES(ret);\n\t\tmemset(ret->data, 0, n);\n\t}\n\treturn (PyObject *)ret;\n\n}\n\nstatic char doc_zeros[] = \"zeros((d1,...,dn),dtype=int,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.\";\n\n\nstatic PyObject *\narray_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Zeros(shape.len, shape.ptr, typecode, (int) fortran);\n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_set_typeDict[] = \"set_typeDict(dict) set the internal \"\\\n\t\"dictionary that can look up an array type using a registered \"\\\n\t\"code\";\n\nstatic PyObject *\narray_set_typeDict(PyObject *ignored, PyObject *args)\n{\n\tPyObject *dict;\n\tif (!PyArg_ParseTuple(args, \"O\", &dict)) return NULL;\n\tPy_XDECREF(typeDict); /* Decrement old reference (if any)*/\n\ttypeDict = dict;\n\tPy_INCREF(dict); /* Create an internal reference to it */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, intp n)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\n\t\n\tif (dtype == &OBJECT_Descr) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Cannot create an object array from a\"\\\n\t\t\t\t\" string.\");\n\t\tPy_DECREF(dtype);\n\t\treturn NULL;\n\t}\n\t\n\titemsize = dtype->elsize;\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"zero-valued itemsize\");\n\t\tPy_DECREF(dtype);\n\t\treturn NULL;\n\t}\n\t\n\tif (n < 0 ) {\n\t\tif (slen % itemsize != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"string size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\t\tn = slen/itemsize;\n\t} else {\n\t\tif (slen < n*itemsize) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"string is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t dtype,\n\t\t\t\t\t\t\t 1, &n, \n\t\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t\t 0, NULL)) == NULL)\n\t\treturn NULL;\n\t\t\n\tmemcpy(ret->data, data, n*dtype->elsize);\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_fromString[] = \"fromstring(string, dtype=int, count=-1) returns a new 1d array initialized from the raw binary data in string. If count is positive, the new array will have count elements, otherwise it's size is determined by the size of string.\";\n\nstatic PyObject *\narray_fromString(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tchar *data;\n\tlonglong nin=-1;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&L\", kwlist, \n\t\t\t\t\t &data, &s, \n\t\t\t\t\t PyArray_DescrConverter, &descr,\n\t\t\t\t\t &nin)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin);\n}\n\n/* This needs an open file object and reads it in directly. \n memory-mapped files handled differently through buffer interface.\n\nfile pointer number in resulting 1d array \n(can easily reshape later, -1 for to end of file)\ntype of array\nsep is a separator string for character-based data (or NULL for binary)\n \" \" means whitespace\n*/\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep)\n{\n\tPyArrayObject *r;\n\tsize_t nread = 0;\n\tPyArray_ScanFunc *scan;\n\tBool binary;\n\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"0-sized elements.\");\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\n\tif (num == -1 && binary) { /* Get size for binary file*/\n\t\tintp start, numbytes;\n\t\tstart = (intp )ftell(fp);\n\t\tfseek(fp, 0, SEEK_END);\n\t\tnumbytes = (intp )ftell(fp) - start;\n\t\trewind(fp);\n\t\tif (numbytes == -1) {\n\t\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\t\"could not seek in file\");\n\t\t\treturn NULL;\n\t\t}\n\t\tnum = numbytes / typecode->elsize;\n\t}\n\t\n\tif (binary) { /* binary data */\n\t\tr = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t 0, NULL);\n\t\tif (r==NULL) return NULL;\n\t\tnread = fread(r->data, typecode->elsize, num, fp);\n\t}\n\telse { /* character reading */\n\t\tintp i;\n\t\tchar *dptr;\n\t\tint done=0;\n\n\t\tscan = typecode->f->scanfunc;\n\t\tif (scan == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character files with that \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (num != -1) { /* number to read is known */\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode, \n\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\tdptr = r->data;\n\t\t\tfor (i=0; i < num; i++) {\n\t\t\t\tif (done) break;\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\t\t\t\tif (done < -2) break;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\telse { /* we have to watch for the end of the file and \n\t\t\t reallocate at the end */\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * typecode->elsize;\n\t\t\tdptr = r->data;\n\t\t\twhile (!done) {\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\n\t\t\t\t/* end of file reached trying to \n\t\t\t\t scan value. done is 1 or 2\n\t\t\t\t if end of file reached trying to\n\t\t\t\t scan separator. Still good value.\n\t\t\t\t*/\n\t\t\t\tif (done < -2) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t\tif (!done && thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tr->data = PyDataMem_RENEW(r->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = r->data + (totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tr->data = PyDataMem_RENEW(r->data, nread*r->descr->elsize);\n\t\t\tPyArray_DIM(r,0) = nread;\n\t\t\tnum = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\tif (nread < num) {\n\t\tfprintf(stderr, \"%ld items requested but only %ld read\\n\", \n\t\t\t(long) num, (long) nread);\n\t\tr->data = PyDataMem_RENEW(r->data, nread * r->descr->elsize);\n\t\tPyArray_DIM(r,0) = nread;\n\t}\n\treturn (PyObject *)r;\n}\n\nstatic char doc_fromfile[] = \\\n\t\"fromfile(file=, dtype=int, count=-1, sep='')\\n\"\t\\\n\t\"\\n\"\\\n\t\" Return an array of the given data type from a \\n\"\\\n\t\" (text or binary) file. The file argument can be an open file\\n\"\\\n\t\" or a string with the name of a file to read from. If\\n\"\\\n\t\" count==-1, then the entire file is read, otherwise count is\\n\"\\\n\t\" the number of items of the given type read in. If sep is ''\\n\"\\\n\t\" then read a binary file, otherwise it gives the separator\\n\"\\\n\t\" between elements in a text file.\\n\"\\\n\t\"\\n\"\\\n\t\" WARNING: This function should be used sparingly, as it is not\\n\"\\\n\t\" a robust method of persistence. But it can be useful to\\n\"\\\n\t\" read in simply-formatted or binary data quickly.\";\n\nstatic PyObject *\narray_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *file=NULL, *ret;\n\tFILE *fp;\n\tchar *sep=\"\";\n\tchar *mode=NULL;\n\tlonglong nin=-1;\n\tstatic char *kwlist[] = {\"file\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *type=NULL;\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Ls\", kwlist, \n\t\t\t\t\t &file,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\tif (type == NULL) type = PyArray_DescrFromType(PyArray_LONG);\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"rb\";\n\t\telse mode=\"r\";\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), mode);\n\t\tif (file==NULL) return NULL;\n\t}\n\telse {\n\t\tPy_INCREF(file);\n\t}\n\tfp = PyFile_AsFile(file);\n\tif (fp == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\"first argument must be an open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_FromFile(fp, type, (intp) nin, sep);\n\tPy_DECREF(file);\n\treturn ret;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, \n\t\t intp count, intp offset) \n{\n\tPyArrayObject *ret;\n\tchar *data;\n\tint ts;\n\tintp s, n;\n\tint itemsize;\n\tint write=1;\n\n\n\tif (type->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot create an OBJECT array from memory\"\\\n\t\t\t\t\" buffer\");\n\t\tPy_DECREF(type);\n\t\treturn NULL;\n\t}\n\tif (type->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"itemsize cannot be zero in type\");\n\t\tPy_DECREF(type);\n\t\treturn NULL; \t\t\n\t}\n\n\tif (buf->ob_type->tp_as_buffer == NULL || \\\n\t (buf->ob_type->tp_as_buffer->bf_getwritebuffer == NULL &&\t\\\n\t buf->ob_type->tp_as_buffer->bf_getreadbuffer == NULL)) {\n\t\tPyObject *newbuf;\n\t\tnewbuf = PyObject_GetAttrString(buf, \"__buffer__\");\n\t\tif (newbuf == NULL) {Py_DECREF(type); return NULL;}\n\t\tbuf = newbuf;\n\t}\n\telse {Py_INCREF(buf);}\n\n\tif (PyObject_AsWriteBuffer(buf, (void *)&data, &ts)==-1) {\n\t\twrite = 0;\n\t\tPyErr_Clear();\n\t\tif (PyObject_AsReadBuffer(buf, (void *)&data, &ts)==-1) {\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((offset < 0) || (offset >= ts)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"offset must be positive and smaller than %\"\n\t\t\t INTP_FMT, (intp)ts);\n\t}\n\n\tdata += offset;\n\ts = (intp)ts - offset;\n\tn = (intp)count;\n\titemsize = type->elsize;\n\t\n\tif (n < 0 ) {\n\t\tif (s % itemsize != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tn = s/itemsize;\n\t} else {\n\t\tif (s < n*itemsize) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t type, \n\t\t\t\t\t\t\t 1, &n, \n\t\t\t\t\t\t\t NULL, data, \n\t\t\t\t\t\t\t DEFAULT_FLAGS,\n\t\t\t\t\t\t\t NULL)) == NULL) {\n\t\tPy_DECREF(buf);\n\t\treturn NULL;\n\t}\n\t\n\tif (!write) ret->flags &= ~WRITEABLE;\n\n\t/* Store a reference for decref on deallocation */\n\tret->base = buf;\n\tPyArray_UpdateFlags(ret, ALIGNED);\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_frombuffer[] = \\\n\t\"frombuffer(buffer=, dtype=int, count=-1, offset=0)\\n\"\\\n\t\"\\n\"\t\t\t\t\t\t\t\t\\\n\t\" Returns a 1-d array of data type dtype from buffer. The buffer\\n\"\\\n\t\" argument must be an object that exposes the buffer interface.\\n\"\\\n\t\" If count is -1 then the entire buffer is used, otherwise, count\\n\"\\\n\t\" is the size of the output. If offset is given then jump that\\n\"\\\n\t\" far into the buffer. If the buffer has data that is out\\n\" \\\n\t\" not in machine byte-order, than use a propert data type\\n\"\\\n\t\" descriptor. The data will not\\n\" \\\n\t\" be byteswapped, but the array will manage it in future\\n\"\\\n\t\" operations.\\n\";\n\nstatic PyObject *\narray_frombuffer(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *obj=NULL;\n\tlonglong nin=-1, offset=0;\n\tstatic char *kwlist[] = {\"buffer\", \"dtype\", \"count\", \"offset\", NULL};\n\tPyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&LL\", kwlist, \n\t\t\t\t\t &obj,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &offset)) {\n\t\treturn NULL;\n\t}\n\tif (type==NULL)\n\t\ttype = PyArray_DescrFromType(PyArray_LONG);\n\t\n\treturn PyArray_FromBuffer(obj, type, (intp)nin, (intp)offset);\n}\n\n\nstatic char doc_concatenate[] = \"concatenate((a1,a2,...),axis=None).\";\n\nstatic PyObject *\narray_concatenate(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *a0;\n\tint axis=0;\n\tstatic char *kwlist[] = {\"seq\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist,\n\t\t\t\t\t &a0,\n\t\t\t\t\t PyArray_AxisConverter, &axis))\n\t\treturn NULL;\n\treturn PyArray_Concatenate(a0, axis);\n}\n\nstatic char doc_innerproduct[] = \\\n\t\"inner(a,b) returns the dot product of two arrays, which has\\n\"\\\n\t\"shape a.shape[:-1] + b.shape[:-1] with elements computed by\\n\" \\\n\t\"the product of the elements from the last dimensions of a and b.\";\n\nstatic PyObject *array_innerproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *b0, *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a0, &b0)) return NULL;\n\t\n\treturn _ARET(PyArray_InnerProduct(a0, b0));\n}\n\nstatic char doc_matrixproduct[] = \\\n\t\"dot(a,v) returns matrix-multiplication between a and b. \\n\"\\\n\t\"The product-sum is over the last dimension of a and the \\n\"\\\n\t\"second-to-last dimension of b.\";\n\nstatic PyObject *array_matrixproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *v, *a;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a, &v)) return NULL;\n\t\n\treturn _ARET(PyArray_MatrixProduct(a, v));\n}\n\nstatic char doc_fastCopyAndTranspose[] = \"_fastCopyAndTranspose(a)\";\n\nstatic PyObject *array_fastCopyAndTranspose(PyObject *dummy, PyObject *args) {\n\tPyObject *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &a0)) return NULL;\n\t\n\treturn _ARET(PyArray_CopyAndTranspose(a0));\n}\n\nstatic char doc_correlate[] = \"cross_correlate(a,v, mode=0)\";\n\nstatic PyObject *array_correlate(PyObject *dummy, PyObject *args, PyObject *kwds) {\n\tPyObject *shape, *a0;\n\tint mode=0;\n\tstatic char *kwlist[] = {\"a\", \"v\", \"mode\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO|i\", kwlist, \n\t\t\t\t\t &a0, &shape, &mode)) return NULL;\n\t\n\treturn PyArray_Correlate(a0, shape, mode);\n}\n\n\n/*MULTIARRAY_API\n Arange, \n*/\nstatic PyObject *\nPyArray_Arange(double start, double stop, double step, int type_num)\n{\n\tintp length;\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *obj;\n\tint ret;\n\n\tlength = (intp ) ceil((stop - start)/step);\n \n\tif (length <= 0) {\n\t\tlength = 0;\n\t\treturn PyArray_New(&PyArray_Type, 1, &length, type_num,\n\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t}\n\n\trange = PyArray_New(&PyArray_Type, 1, &length, type_num, \n\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (range == NULL) return NULL;\n\n\tfuncs = PyArray_DESCR(range)->f; \n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tobj = PyFloat_FromDouble(start);\n\tret = funcs->setitem(obj, PyArray_DATA(range), (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 1) return range;\n\n\tobj = PyFloat_FromDouble(start + step);\n\tret = funcs->setitem(obj, PyArray_DATA(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 2) return range;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\treturn NULL;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\t\n\treturn range;\n\n fail:\n\tPy_DECREF(range);\n\treturn NULL;\n}\n\n/* the formula is \n len = (intp) ceil((start - stop) / step);\n*/\nstatic intp\n_calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, int cmplx)\n{\n\tintp len;\n\tPyObject *val;\n\tdouble value;\n\t\n\t*next = PyNumber_Subtract(stop, start);\n\tif (!(*next)) return -1;\n\tval = PyNumber_TrueDivide(*next, step);\n\tPy_DECREF(*next); *next=NULL;\n\tif (!val) return -1;\n\tif (cmplx && PyComplex_Check(val)) {\n\t\tvalue = PyComplex_RealAsDouble(val);\n\t\tif (error_converting(value)) {Py_DECREF(val); return -1;}\n\t\tlen = (intp) ceil(value);\n\t\tvalue = PyComplex_ImagAsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = MIN(len, (intp) ceil(value));\n\t}\n\telse {\n\t\tvalue = PyFloat_AsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = (intp) ceil(value);\n\t}\n\t\n\tif (len > 0) {\n\t\t*next = PyNumber_Add(start, step);\n\t\tif (!next) return -1;\n\t}\n\treturn len;\n}\n\n/* this doesn't change the references */\n/*MULTIARRAY_API\n ArangeObj,\n*/\nstatic PyObject *\nPyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr *dtype) \n{\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *next;\n\tintp length;\n\n\tif (!dtype) {\n\t\tPyArray_Descr *deftype;\n\t\tPyArray_Descr *newtype;\n\t\tdeftype = PyArray_DescrFromType(PyArray_LONG);\n\t\tnewtype = PyArray_DescrFromObject(start, deftype);\n\t\tPy_DECREF(deftype);\n\t\tdeftype = newtype;\n\t\tif (stop && stop != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(stop, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tif (step && step != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(step, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tdtype = deftype;\n\t}\n\telse Py_INCREF(dtype);\n\n\tif (!step || step == Py_None) {\n\t\tstep = PyInt_FromLong(1);\n\t}\n\telse Py_XINCREF(step);\n\n\tif (!stop || stop == Py_None) {\n\t\tstop = start;\n\t\tstart = PyInt_FromLong(0);\n\t}\n\telse Py_INCREF(start);\n\n\t/* calculate the length and next = start + step*/\n\tlength = _calc_length(start, stop, step, &next, \n\t\t\t PyTypeNum_ISCOMPLEX(dtype->type_num));\n\n\tif (PyErr_Occurred()) {Py_DECREF(dtype); goto fail;}\n\tif (length <= 0) {\n\t\tlength = 0;\n\t\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\t\tPy_DECREF(step); Py_DECREF(start); return range;\n\t}\n\n\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\tif (range == NULL) goto fail;\n\n\tfuncs = PyArray_DESCR(range)->f;\n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tif (funcs->setitem(start, PyArray_DATA(range), (PyArrayObject *)range) < 0)\n\t\tgoto fail;\n\tif (length == 1) goto finish;\n\tif (funcs->setitem(next, PyArray_DATA(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range) < 0) goto fail;\n\tif (length == 2) goto finish;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\tgoto fail;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\n finish:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_DECREF(next);\n\treturn range;\n\t\n fail:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_XDECREF(next);\n\treturn NULL;\n}\n\n\nstatic char doc_arange[] = \"arange(start, stop=None, step=1, dtype=int)\\n\\n Just like range() except it returns an array whose type can be\\n specified by the keyword argument typecode.\";\n\nstatic PyObject *\narray_arange(PyObject *ignored, PyObject *args, PyObject *kws) {\n\tPyObject *o_start=NULL, *o_stop=NULL, *o_step=NULL;\n\tstatic char *kwd[]= {\"start\", \"stop\", \"step\", \"dtype\", NULL};\n\tPyArray_Descr *typecode=NULL;\n\t\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|OOO&\", kwd, &o_start,\n\t\t\t\t\t&o_stop, &o_step, \n\t\t\t\t\tPyArray_DescrConverter, \n\t\t\t\t\t&typecode)) \n\t\treturn NULL;\n\n\treturn PyArray_ArangeObj(o_start, o_stop, o_step, typecode);\n}\n\n\nstatic char \ndoc_set_string_function[] = \"set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.\";\n\nstatic PyObject *\narray_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *op;\n\tint repr=1;\n\tstatic char *kwlist[] = {\"f\", \"repr\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|i\", kwlist, \n\t\t\t\t\t&op, &repr)) return NULL; \n\tif (!PyCallable_Check(op)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"Argument must be callable.\");\n\t\treturn NULL;\n\t}\n\tPyArray_SetStringFunction(op, repr);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char \ndoc_set_ops_function[] = \"set_numeric_ops(op=func, ...) sets some or all of the number methods for all array objects. Don't forget **dict can be used as the argument list. Returns the functions that were replaced -- can be stored and set later.\";\n\nstatic PyObject *\narray_set_ops_function(PyObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *oldops=NULL;\n\t\n\tif ((oldops = PyArray_GetNumericOps())==NULL) return NULL;\n\n\t/* Should probably ensure that objects are at least callable */\n\t/* Leave this to the caller for now --- error will be raised\n\t later when use is attempted \n\t*/\n\tif (kwds && PyArray_SetNumericOps(kwds) == -1) {\n\t\tPy_DECREF(oldops);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"one or more objects not callable\");\n\t\treturn NULL;\n\t}\n\treturn oldops;\n}\n\n\n/*MULTIARRAY_API\n Where\n*/\nstatic PyObject *\nPyArray_Where(PyObject *condition, PyObject *x, PyObject *y)\n{\n\tPyArrayObject *arr;\n\tPyObject *tup=NULL, *obj=NULL;\n\tPyObject *ret=NULL, *zero=NULL;\n\n\n\tarr = (PyArrayObject *)PyArray_FromAny(condition, NULL, 0, 0, 0);\n\tif (arr == NULL) return NULL;\n\n\tif ((x==NULL) && (y==NULL)) {\n\t\tret = PyArray_Nonzero(arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\n\tif ((x==NULL) || (y==NULL)) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \"either both or neither \"\n\t\t\t\t\"of x and y should be given\");\n\t\treturn NULL;\n\t}\n\n\n\tzero = PyInt_FromLong((long) 0);\n\n\tobj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, \n\t\t\t\t\t\t\t\tn_ops.not_equal));\n\tPy_DECREF(zero);\n\tPy_DECREF(arr);\n\tif (obj == NULL) return NULL;\n\n\ttup = Py_BuildValue(\"(OO)\", y, x);\n\tif (tup == NULL) {Py_DECREF(obj); return NULL;}\n\n\tret = PyArray_Choose((PyAO *)obj, tup);\n\n\tPy_DECREF(obj);\n\tPy_DECREF(tup);\n\treturn ret;\n}\n\nstatic char doc_where[] = \"where(condition, | x, y) is shaped like condition\"\\\n\t\" and has elements of x and y where condition is respectively true or\"\\\n\t\" false. If x or y are not given, then it is equivalent to\"\\\n\t\" nonzero(condition).\";\n\nstatic PyObject *\narray_where(PyObject *ignored, PyObject *args)\n{\n\tPyObject *obj=NULL, *x=NULL, *y=NULL;\n\t\n\tif (!PyArg_ParseTuple(args, \"O|OO\", &obj, &x, &y)) return NULL;\n\n\treturn PyArray_Where(obj, x, y);\n\n}\n\nstatic char doc_lexsort[] = \"lexsort(keys=, axis=-1) returns an array of indexes\"\\\n\t\" similar to argsort except the sorting is done using the provided sorting\"\\\n\t\" keys. First the sort is done using key[0], then the resulting list of\"\\\n\t\" indexes is further manipulated by sorting on key[0]. And so forth\"\\\n\t\" The result is a sort on multiple keys. If the keys represented columns\" \\\n\t\" of a spread-sheet, for example, this would sort using multiple columns.\"\\\n\t\" The keys argument must be a tuple of things that can be converted to \"\\\n\t\" arrays of the same shape.\";\n\nstatic PyObject *\narray_lexsort(PyObject *ignored, PyObject *args, PyObject *kwds)\n{\n\tint axis=-1;\n\tPyObject *obj;\n\tstatic char *kwlist[] = {\"keys\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|i\", kwlist, \n\t\t\t\t\t &PyTuple_Type, &obj, &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_LexSort(obj, axis));\n}\n\n#undef _ARET\n\n\nstatic char doc_register_dtype[] = \\\n\t\"register_dtype(a) registers a new type object -- gives it a typenum\";\n\nstatic PyObject *\narray_register_dtype(PyObject *dummy, PyObject *args)\n{\n\tPyObject *dtype;\n\tint ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &dtype)) return NULL;\n\t\n\tret = PyArray_RegisterDataType((PyTypeObject *)dtype);\n\tif (ret < 0)\n\t\treturn NULL;\n\treturn PyInt_FromLong((long) ret);\n}\n\nstatic char doc_can_cast_safely[] = \\\n\t\"can_cast_safely(from=d1, to=d2) returns True if data type d1 \"\\\n\t\"can be cast to data type d2 without losing precision.\";\n\nstatic PyObject *\narray_can_cast_safely(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *d1=NULL;\n\tPyArray_Descr *d2=NULL;\n\tBool ret;\n\tPyObject *retobj;\n\tstatic char *kwlist[] = {\"from\", \"to\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O&O&\", kwlist, \n\t\t\t\t\tPyArray_DescrConverter, &d1,\n\t\t\t\t\tPyArray_DescrConverter, &d2))\n\t\treturn NULL;\n\tif (d1 == NULL || d2 == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"did not understand one of the types; \"\t\\\n\t\t\t\t\"'None' not accepted\");\n\t\treturn NULL;\n\t}\n\t\t\n\tret = PyArray_CanCastTo(d1, d2);\n\tretobj = (ret ? Py_True : Py_False);\n\tPy_INCREF(retobj);\n\treturn retobj;\n}\n\nstatic char doc_new_buffer[] = \\\n\t\"newbuffer(size) return a new uninitialized buffer object of size \"\n\t\"bytes\";\n\nstatic PyObject *\nnew_buffer(PyObject *dummy, PyObject *args)\n{\n\tint size;\n\n\tif(!PyArg_ParseTuple(args, \"i\", &size))\n\t\treturn NULL;\n\t\n\treturn PyBuffer_New(size);\n}\n\nstatic char doc_buffer_buffer[] = \\\n\t\"getbuffer(obj [,offset[, size]]) create a buffer object from the \"\\\n\t\"given object\\n referencing a slice of length size starting at \"\\\n\t\"offset. Default\\n is the entire buffer. A read-write buffer is \"\\\n\t\"attempted followed by a read-only buffer.\";\n\nstatic PyObject *\nbuffer_buffer(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj;\n\tint offset=0, size=Py_END_OF_BUFFER, n;\n\tvoid *unused;\n\tstatic char *kwlist[] = {\"object\", \"offset\", \"size\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ii\", kwlist, \n\t\t\t\t\t &obj, &offset, &size))\n\t\treturn NULL;\n\n\n\tif (PyObject_AsWriteBuffer(obj, &unused, &n) < 0) {\n\t\tPyErr_Clear();\n\t\treturn PyBuffer_FromObject(obj, offset, size);\t\t\n\t}\n\telse\n\t\treturn PyBuffer_FromReadWriteObject(obj, offset, size);\n}\n\n\nstatic struct PyMethodDef array_module_methods[] = {\n\t{\"set_string_function\", (PyCFunction)array_set_string_function, \n\t METH_VARARGS|METH_KEYWORDS, doc_set_string_function},\n\t{\"set_numeric_ops\", (PyCFunction)array_set_ops_function,\n\t METH_VARARGS|METH_KEYWORDS, doc_set_ops_function},\n\t{\"set_typeDict\", (PyCFunction)array_set_typeDict,\n\t METH_VARARGS, doc_set_typeDict},\n\n\t{\"array\",\t(PyCFunction)_array_fromobject, \n\t METH_VARARGS|METH_KEYWORDS, doc_fromobject},\n\t{\"arange\", (PyCFunction)array_arange, \n\t METH_VARARGS|METH_KEYWORDS, doc_arange},\n\t{\"zeros\",\t(PyCFunction)array_zeros, \n\t METH_VARARGS|METH_KEYWORDS, doc_zeros},\n\t{\"empty\",\t(PyCFunction)array_empty, \n\t METH_VARARGS|METH_KEYWORDS, doc_empty},\n\t{\"scalar\", (PyCFunction)array_scalar,\n\t METH_VARARGS|METH_KEYWORDS, doc_scalar},\n\t{\"where\", (PyCFunction)array_where,\n\t METH_VARARGS, doc_where},\n\t{\"lexsort\", (PyCFunction)array_lexsort,\n\t METH_VARARGS | METH_KEYWORDS, doc_lexsort},\n\t{\"fromstring\",(PyCFunction)array_fromString,\n\t METH_VARARGS|METH_KEYWORDS, doc_fromString},\n\t{\"concatenate\", (PyCFunction)array_concatenate, \n\t METH_VARARGS|METH_KEYWORDS, doc_concatenate},\n\t{\"inner\", (PyCFunction)array_innerproduct, \n\t METH_VARARGS, doc_innerproduct}, \n\t{\"dot\", (PyCFunction)array_matrixproduct, \n\t METH_VARARGS, doc_matrixproduct}, \n\t{\"_fastCopyAndTranspose\", (PyCFunction)array_fastCopyAndTranspose, \n\t METH_VARARGS, doc_fastCopyAndTranspose},\n\t{\"correlate\", (PyCFunction)array_correlate, \n\t METH_VARARGS | METH_KEYWORDS, doc_correlate},\n\t{\"frombuffer\", (PyCFunction)array_frombuffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_frombuffer},\n\t{\"fromfile\", (PyCFunction)array_fromfile,\n\t METH_VARARGS | METH_KEYWORDS, doc_fromfile},\n\t{\"register_dtype\", (PyCFunction)array_register_dtype,\n\t METH_VARARGS, doc_register_dtype},\n\t{\"can_cast\", (PyCFunction)array_can_cast_safely,\n\t METH_VARARGS | METH_KEYWORDS, doc_can_cast_safely},\t\t\n\t{\"newbuffer\", (PyCFunction)new_buffer,\n\t METH_VARARGS, doc_new_buffer},\t\n\t{\"getbuffer\", (PyCFunction)buffer_buffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_buffer_buffer},\t\n\t{NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n#include \"__multiarray_api.c\"\n\n/* Establish scalar-type hierarchy */\n\n/* For dual inheritance we need to make sure that the objects being\n inherited from have the tp->mro object initialized. This is\n not necessarily true for the basic type objects of Python (it is \n checked for single inheritance but not dual in PyType_Ready).\n\n Thus, we call PyType_Ready on the standard Python Types, here.\n*/ \nstatic int\nsetup_scalartypes(PyObject *dict)\n{\n\n\tinitialize_numeric_types();\n\n if (PyType_Ready(&PyBool_Type) < 0) return -1;\n if (PyType_Ready(&PyInt_Type) < 0) return -1;\n if (PyType_Ready(&PyFloat_Type) < 0) return -1;\n if (PyType_Ready(&PyComplex_Type) < 0) return -1;\n if (PyType_Ready(&PyString_Type) < 0) return -1;\n if (PyType_Ready(&PyUnicode_Type) < 0) return -1;\n\n#define SINGLE_INHERIT(child, parent) \\\n Py##child##ArrType_Type.tp_base = &Py##parent##ArrType_Type;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) {\t\t\\\n PyErr_Print(); \\\n PyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1;\t\t\t\t\t\t\\\n }\n \n if (PyType_Ready(&PyGenericArrType_Type) < 0)\n return -1;\n\n SINGLE_INHERIT(Number, Generic);\n SINGLE_INHERIT(Integer, Number);\n SINGLE_INHERIT(Inexact, Number);\n SINGLE_INHERIT(SignedInteger, Integer);\n SINGLE_INHERIT(UnsignedInteger, Integer);\n SINGLE_INHERIT(Floating, Inexact);\n SINGLE_INHERIT(ComplexFloating, Inexact);\n SINGLE_INHERIT(Flexible, Generic);\n SINGLE_INHERIT(Character, Flexible);\n\t\n#define DUAL_INHERIT(child, parent1, parent2) \\\n Py##child##ArrType_Type.tp_base = &Py##parent2##ArrType_Type;\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent2##ArrType_Type,\t\\\n\t\t\t &Py##parent1##_Type);\t\t\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\n\n#define DUAL_INHERIT2(child, parent1, parent2)\t\t\t\t\\\n Py##child##ArrType_Type.tp_base = &Py##parent1##_Type;\t\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent1##_Type,\t\t\\\n\t\t\t &Py##parent2##ArrType_Type);\t\t\\\n\tPy##child##ArrType_Type.tp_richcompare =\t\t\t\\\n\t\tPy##parent1##_Type.tp_richcompare;\t\t\t\\\n\tPy##child##ArrType_Type.tp_compare =\t\t\t\t\\\n\t\tPy##parent1##_Type.tp_compare;\t\t\t\t\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\n\n SINGLE_INHERIT(Bool, Generic);\n SINGLE_INHERIT(Byte, SignedInteger);\n SINGLE_INHERIT(Short, SignedInteger);\n#if SIZEOF_INT == SIZEOF_LONG\n DUAL_INHERIT(Int, Int, SignedInteger);\n#else\n SINGLE_INHERIT(Int, SignedInteger);\n#endif\n DUAL_INHERIT(Long, Int, SignedInteger);\n#if SIZEOF_LONGLONG == SIZEOF_LONG\n DUAL_INHERIT(LongLong, Int, SignedInteger);\n#else\n SINGLE_INHERIT(LongLong, SignedInteger);\n#endif\n\n /* fprintf(stderr, \"tp_free = %p, PyObject_Del = %p, int_tp_free = %p, base.tp_free = %p\\n\", PyIntArrType_Type.tp_free, PyObject_Del, PyInt_Type.tp_free, PySignedIntegerArrType_Type.tp_free);\n\t */\n\tSINGLE_INHERIT(UByte, UnsignedInteger);\n SINGLE_INHERIT(UShort, UnsignedInteger);\n SINGLE_INHERIT(UInt, UnsignedInteger);\n SINGLE_INHERIT(ULong, UnsignedInteger);\n SINGLE_INHERIT(ULongLong, UnsignedInteger);\n\n SINGLE_INHERIT(Float, Floating);\n DUAL_INHERIT(Double, Float, Floating);\n SINGLE_INHERIT(LongDouble, Floating);\n\n SINGLE_INHERIT(CFloat, ComplexFloating);\n DUAL_INHERIT(CDouble, Complex, ComplexFloating);\n SINGLE_INHERIT(CLongDouble, ComplexFloating);\n\n DUAL_INHERIT2(String, String, Character);\n DUAL_INHERIT2(Unicode, Unicode, Character);\n\t\n SINGLE_INHERIT(Void, Flexible);\n \n SINGLE_INHERIT(Object, Generic);\n\n return 0;\n\n#undef SINGLE_INHERIT\n#undef DUAL_INHERIT\n\n\t/* Clean up string and unicode array types so they act more like\n\t strings -- get their tables from the standard types.\n\t*/\n}\n\n/* place a flag dictionary in d */\n\nstatic void\nset_flaginfo(PyObject *d)\n{\n PyObject *s;\n PyObject *newd;\n \n newd = PyDict_New();\n\n PyDict_SetItemString(newd, \"OWNDATA\", s=PyInt_FromLong(OWNDATA));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"FORTRAN\", s=PyInt_FromLong(FORTRAN));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"CONTIGUOUS\", s=PyInt_FromLong(CONTIGUOUS));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"ALIGNED\", s=PyInt_FromLong(ALIGNED));\n Py_DECREF(s);\n\n PyDict_SetItemString(newd, \"UPDATEIFCOPY\", s=PyInt_FromLong(UPDATEIFCOPY));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"WRITEABLE\", s=PyInt_FromLong(WRITEABLE));\n Py_DECREF(s);\n \n PyDict_SetItemString(d, \"_flagdict\", newd);\n Py_DECREF(newd);\n return;\n}\n\n\n/* Initialization function for the module */\n\nDL_EXPORT(void) initmultiarray(void) {\n\tPyObject *m, *d, *s;\n\tPyObject *c_api;\n\t\n\t/* Create the module and add the functions */\n\tm = Py_InitModule(\"multiarray\", array_module_methods);\n\tif (!m) goto err;\n\n\t/* Add some symbolic constants to the module */\n\td = PyModule_GetDict(m);\n\tif (!d) goto err; \n\n\t/* Create the module and add the functions */\n\tif (PyType_Ready(&PyBigArray_Type) < 0) \n\t\treturn;\n\n PyArray_Type.tp_base = &PyBigArray_Type;\n\n PyArray_Type.tp_as_mapping = &array_as_mapping;\n\t/* Even though, this would be inherited, it needs to be set now\n\t so that the __getitem__ will map to the as_mapping descriptor\n\t*/\n PyArray_Type.tp_as_number = &array_as_number; \n\t/* For good measure */\n\tPyArray_Type.tp_as_sequence = &array_as_sequence;\n\tPyArray_Type.tp_as_buffer = &array_as_buffer;\t\n PyArray_Type.tp_flags = (Py_TPFLAGS_DEFAULT \n\t\t\t\t | Py_TPFLAGS_BASETYPE\n\t\t\t\t | Py_TPFLAGS_CHECKTYPES);\n PyArray_Type.tp_doc = Arraytype__doc__;\n\n\tif (PyType_Ready(&PyArray_Type) < 0)\n return;\n\n if (setup_scalartypes(d) < 0) goto err;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMultiIter_Type.tp_iter = PyObject_SelfIter;\n\tif (PyType_Ready(&PyArrayIter_Type) < 0)\n\t\treturn; \n \n\tif (PyType_Ready(&PyArrayMapIter_Type) < 0)\n return; \n\n\tif (PyType_Ready(&PyArrayMultiIter_Type) < 0)\n\t\treturn;\n\n\tif (PyType_Ready(&PyArrayDescr_Type) < 0)\n\t\treturn;\n\n\tc_api = PyCObject_FromVoidPtr((void *)PyArray_API, NULL);\n\tif (PyErr_Occurred()) goto err;\n\tPyDict_SetItemString(d, \"_ARRAY_API\", c_api);\n\tPy_DECREF(c_api);\n\tif (PyErr_Occurred()) goto err;\n\n\tMultiArrayError = PyString_FromString (\"multiarray.error\");\n\tPyDict_SetItemString (d, \"error\", MultiArrayError);\n\t\n\ts = PyString_FromString(\"3.0\");\n\tPyDict_SetItemString(d, \"__version__\", s);\n\tPy_DECREF(s);\n Py_INCREF(&PyBigArray_Type);\n\tPyDict_SetItemString(d, \"bigndarray\", (PyObject *)&PyBigArray_Type);\n Py_INCREF(&PyArray_Type);\n\tPyDict_SetItemString(d, \"ndarray\", (PyObject *)&PyArray_Type);\n Py_INCREF(&PyArrayIter_Type);\n\tPyDict_SetItemString(d, \"flatiter\", (PyObject *)&PyArrayIter_Type);\n Py_INCREF(&PyArrayMultiIter_Type);\n\tPyDict_SetItemString(d, \"broadcast\", \n\t\t\t (PyObject *)&PyArrayMultiIter_Type);\n\tPy_INCREF(&PyArrayDescr_Type);\n\tPyDict_SetItemString(d, \"dtypedescr\", (PyObject *)&PyArrayDescr_Type);\n\n\t/* Doesn't need to be exposed to Python \n Py_INCREF(&PyArrayMapIter_Type);\n\tPyDict_SetItemString(d, \"mapiter\", (PyObject *)&PyArrayMapIter_Type);\n\t*/\n set_flaginfo(d);\n\n\tif (set_typeinfo(d) != 0) goto err;\n\n\t_numpy_internal =\t\t\t\t\t\t\\\n\t\tPyImport_ImportModule(\"numpy.core._internal\");\n\tif (_numpy_internal != NULL) return;\n\n err:\t\n\t/* Check for errors */\n\tif (PyErr_Occurred())\n PyErr_Print();\n\t\tPy_FatalError(\"can't initialize module multiarray\");\n\n\treturn;\n}\n\n", + "source_code_before": "/*\n Python Multiarray Module -- A useful collection of functions for creating and\n using ndarrays\n\n Original file \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n Modified for numpy_core in 2005 \n\n Travis E. Oliphant\n Assistant Professor at\n Brigham Young University\n \n*/\n\n/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */\n\n#include \"Python.h\"\n#include \"structmember.h\"\n/*#include \n#include \n*/\n\n#define _MULTIARRAYMODULE\n#include \"numpy/arrayobject.h\"\n\n#define PyAO PyArrayObject\n\nstatic PyObject *typeDict=NULL; /* Must be explicitly loaded */\nstatic PyObject *_numpy_internal=NULL; /* A Python module for callbacks */\n\n\nstatic PyArray_Descr *\n_arraydescr_fromobj(PyObject *obj)\n{\n\tPyObject *dtypedescr;\n\tPyArray_Descr *new;\n\tint ret;\n\t\n\tdtypedescr = PyObject_GetAttrString(obj, \"dtypedescr\");\n\tPyErr_Clear();\n\tif (dtypedescr) {\n\t\tret = PyArray_DescrConverter(dtypedescr, &new);\n\t\tPy_DECREF(dtypedescr);\n\t\tif (ret) return new;\n\t\tPyErr_Clear();\n\t}\n\treturn NULL;\n}\n\n\n/* Including this file is the only way I know how to declare functions\n static in each file, and store the pointers from functions in both\n arrayobject.c and multiarraymodule.c for the C-API \n\n Declarying an external pointer-containing variable in arrayobject.c\n and trying to copy it to PyArray_API, did not work.\n\n Think about two modules with a common api that import each other...\n\n This file would just be the module calls. \n*/\n\n#include \"arrayobject.c\"\n\n\n/* An Error object -- rarely used? */\nstatic PyObject *MultiArrayError;\n\n/*MULTIARRAY_API\n Multiply a List of ints\n*/\nstatic int\nPyArray_MultiplyIntList(register int *l1, register int n) \n{\n\tregister int s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Multiply a List\n*/\nstatic intp \nPyArray_MultiplyList(register intp *l1, register int n) \n{\n\tregister intp s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Produce a pointer into array\n*/\nstatic char *\nPyArray_GetPtr(PyArrayObject *obj, register intp* ind)\n{\n\tregister int n = obj->nd;\n\tregister intp *strides = obj->strides;\n\tregister char *dptr = obj->data;\n\t\n\twhile (n--) dptr += (*strides++) * (*ind++);\n\treturn dptr;\n}\n\n/*MULTIARRAY_API\n Get axis from an object (possibly None) -- a converter function,\n*/\nstatic int \nPyArray_AxisConverter(PyObject *obj, int *axis)\n{\n\tif (obj == Py_None) {\n\t\t*axis = MAX_DIMS;\n\t}\n\telse {\n\t\t*axis = (int) PyInt_AsLong(obj);\n\t\tif (PyErr_Occurred()) {\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Compare Lists\n*/\nstatic int \nPyArray_CompareLists(intp *l1, intp *l2, int n) \n{\n int i;\n for(i=0;iob_type;\n\t\n\tPy_INCREF(self->descr);\n\tnew = PyArray_NewFromDescr(subtype,\n\t\t\t\t self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides,\n\t\t\t\t self->data,\n\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (new==NULL) return NULL;\n\tPy_INCREF(self);\n PyArray_BASE(new) = (PyObject *)self;\n\t\n\tif (type != NULL) {\n\t\tif (PyObject_SetAttrString(new, \"dtypedescr\", \n\t\t\t\t\t (PyObject *)type) < 0) {\n\t\t\tPy_DECREF(new);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tPy_DECREF(type);\n\t}\n\treturn new;\t\n}\n\n/*MULTIARRAY_API\n Ravel\n*/\nstatic PyObject *\nPyArray_Ravel(PyArrayObject *a, int fortran)\n{\n\tPyArray_Dims newdim = {NULL,1};\n\tintp val[1] = {-1};\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tnewdim.ptr = val;\n\tif (!fortran && PyArray_ISCONTIGUOUS(a)) {\n\t\tif (a->nd == 1) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\treturn PyArray_Newshape(a, &newdim);\n\t}\n\telse\n\t return PyArray_Flatten(a, fortran);\n}\n\n/*MULTIARRAY_API\n Flatten\n*/\nstatic PyObject *\nPyArray_Flatten(PyArrayObject *a, int fortran)\n{\n\tPyObject *ret, *new;\n\tintp size;\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tsize = PyArray_SIZE(a);\n\tPy_INCREF(a->descr);\n\tret = PyArray_NewFromDescr(a->ob_type,\n\t\t\t\t a->descr,\n\t\t\t\t 1, &size,\n\t\t\t\t NULL,\n\t\t\t\t NULL,\n\t\t\t\t 0, (PyObject *)a);\n\t\n\tif (ret== NULL) return NULL;\n\tif (fortran) {\n\t\tnew = PyArray_Transpose(a, NULL);\n\t\tif (new == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tPy_INCREF(a);\n\t\tnew = (PyObject *)a;\n\t}\n\tif (PyArray_CopyInto((PyArrayObject *)ret, (PyArrayObject *)new) < 0) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn NULL;\n\t}\n\tPy_DECREF(new);\n\treturn ret;\n}\n\n\n/* For back-ward compatability *\n\n/ * Not recommended */\n\n/*MULTIARRAY_API\n Reshape an array\n*/\nstatic PyObject *\nPyArray_Reshape(PyArrayObject *self, PyObject *shape) \n{\n PyObject *ret;\n PyArray_Dims newdims;\n\n if (!PyArray_IntpConverter(shape, &newdims)) return NULL;\n ret = PyArray_Newshape(self, &newdims);\n PyDimMem_FREE(newdims.ptr);\n return ret;\n}\n\nstatic int\n_check_ones(PyArrayObject *self, int newnd, intp* newdims, intp *strides)\n{\n\tint nd;\n\tintp *dims;\n\tBool done=FALSE;\n\tint j, k;\n\n\tnd = self->nd;\n\tdims = self->dimensions;\n\n\tfor (k=0, j=0; !done && (jstrides[j];\n\t\t\tj++; k++;\n\t\t}\n\t\telse if ((kptr;\n PyArrayObject *ret;\n\tchar msg[] = \"total size of new array must be unchanged\";\n\tint n = newdims->len;\n Bool same;\n\tintp *strides = NULL;\n\tintp newstrides[MAX_DIMS];\n\n /* Quick check to make sure anything needs to be done */\n if (n == self->nd) {\n same = TRUE;\n i=0;\n while(same && i= 0) {\n\t\t\tif ((s_known == 0) || (s_original % s_known != 0)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdimensions[i_unknown] = s_original/s_known;\n\t\t} else {\n\t\t\tif (s_original != s_known) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t}\n \n\tPy_INCREF(self->descr);\n\tret = (PyAO *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t self->descr,\n\t\t\t\t\t n, dimensions,\n\t\t\t\t\t strides,\n\t\t\t\t\t self->data,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (ret== NULL) return NULL;\n\t\n Py_INCREF(self);\n ret->base = (PyObject *)self;\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\n\t\n return (PyObject *)ret;\n}\n\n/* return a new view of the array object with all of its unit-length \n dimensions squeezed out if needed, otherwise\n return the same array.\n */\n\n/*MULTIARRAY_API*/\nstatic PyObject *\nPyArray_Squeeze(PyArrayObject *self)\n{\n\tint nd = self->nd;\n\tint newnd = nd;\n\tintp dimensions[MAX_DIMS];\n\tintp strides[MAX_DIMS];\n\tint i,j;\n\tPyObject *ret;\n\n\tif (nd == 0) {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\tfor (j=0, i=0; idimensions[i] == 1) {\n\t\t\tnewnd -= 1;\n\t\t}\n\t\telse {\n\t\t\tdimensions[j] = self->dimensions[i];\n\t\t\tstrides[j++] = self->strides[i];\n\t\t}\n\t}\n\t\n\tPy_INCREF(self->descr);\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t self->descr,\n\t\t\t\t newnd, dimensions, \n\t\t\t\t strides, self->data, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPyArray_FLAGS(ret) &= ~OWN_DATA;\n\tPyArray_BASE(ret) = (PyObject *)self;\n\tPy_INCREF(self);\n\treturn (PyObject *)ret;\n}\n\n\n/*MULTIARRAY_API\n Mean\n*/\nstatic PyObject *\nPyArray_Mean(PyArrayObject *self, int axis, int rtype)\n{\n\tPyObject *obj1=NULL, *obj2=NULL;\n\tPyObject *new, *ret;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\n\tobj1 = PyArray_GenericReduceFunction((PyAO *)new, n_ops.add, axis,\n\t\t\t\t\t rtype);\n\tobj2 = PyFloat_FromDouble((double) PyArray_DIM(new,axis));\n Py_DECREF(new);\n\tif (obj1 == NULL || obj2 == NULL) {\n\t\tPy_XDECREF(obj1);\n\t\tPy_XDECREF(obj2);\n\t\treturn NULL;\n\t}\n\n\tret = PyNumber_Divide(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n}\n\n/* Set variance to 1 to by-pass square-root calculation and return variance */\n/*MULTIARRAY_API\n Std\n*/\nstatic PyObject *\nPyArray_Std(PyArrayObject *self, int axis, int rtype, int variance)\n{\n\tPyObject *obj1=NULL, *obj2=NULL, *new=NULL;\n\tPyObject *ret=NULL, *newshape=NULL;\n\tint i, n;\n\tintp val;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\t\n\t/* Compute and reshape mean */\n\tobj1 = PyArray_EnsureArray(PyArray_Mean((PyAO *)new, axis, rtype));\n\tif (obj1 == NULL) {Py_DECREF(new); return NULL;} \n\tn = PyArray_NDIM(new);\n\tnewshape = PyTuple_New(n);\n\tif (newshape == NULL) {Py_DECREF(obj1); Py_DECREF(new); return NULL;}\n\tfor (i=0; ind != 1) {\n Py_DECREF(cond);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"condition must be 1-d array\");\n return NULL;\n }\n\n res = PyArray_Nonzero(cond);\n Py_DECREF(cond);\n\tret = PyArray_Take(self, res, axis);\n\tPy_DECREF(res);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Nonzero\n*/\nstatic PyObject *\nPyArray_Nonzero(PyArrayObject *self)\n{\n int n=self->nd, j;\n\tintp count=0, i, size;\n\tPyArrayIterObject *it=NULL;\n\tPyObject *ret=NULL, *item;\n\tintp *dptr[MAX_DIMS];\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (it==NULL) return NULL;\n\n\tsize = it->size;\n\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) count++;\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\n\tPyArray_ITER_RESET(it);\n\tif (n==1) {\n\t\tret = PyArray_New(self->ob_type, 1, &count, PyArray_INTP, \n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)self);\n\t\tif (ret == NULL) goto fail;\n\t\tdptr[0] = (intp *)PyArray_DATA(ret);\n\t\t\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\t*(dptr[0])++ = i;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\t\t\n\t}\n\telse {\n\t\tret = PyTuple_New(n);\n\t\tfor (j=0; job_type, 1, &count, \n\t\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0,\n\t\t\t\t\t (PyObject *)self);\n\t\t\tif (item == NULL) goto fail;\n\t\t\tPyTuple_SET_ITEM(ret, j, item);\n\t\t\tdptr[j] = (intp *)PyArray_DATA(item);\n\t\t}\n\t\t\n\t\t/* reset contiguous so that coordinates gets updated */\n\t\tit->contiguous = 0;\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\tfor (j=0; jcoordinates[j];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\n\n\tPy_DECREF(it);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(ret);\n\tPy_XDECREF(it);\n\treturn NULL;\n \n}\n\n/*MULTIARRAY_API\n Clip\n*/\nstatic PyObject *\nPyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max)\n{\n\tPyObject *selector=NULL, *newtup=NULL, *ret=NULL;\n\tPyObject *res1=NULL, *res2=NULL, *res3=NULL;\n\tPyObject *two;\n\n\ttwo = PyInt_FromLong((long)2);\n\tres1 = PyArray_GenericBinaryFunction(self, max, n_ops.greater);\n\tres2 = PyArray_GenericBinaryFunction(self, min, n_ops.less);\n\tif ((res1 == NULL) || (res2 == NULL)) {\n\t\tPy_DECREF(two);\n\t\tPy_XDECREF(res1);\n\t\tPy_XDECREF(res2);\n\t}\n\tres3 = PyNumber_Multiply(two, res1);\n\tPy_DECREF(two); \n\tPy_DECREF(res1); \n\tif (res3 == NULL) return NULL;\n\n\tselector = PyArray_EnsureArray(PyNumber_Add(res2, res3));\n\tPy_DECREF(res2);\n\tPy_DECREF(res3);\n\tif (selector == NULL) return NULL;\n\n\tnewtup = Py_BuildValue(\"(OOO)\", (PyObject *)self, min, max);\n\tif (newtup == NULL) {Py_DECREF(selector); return NULL;}\n\tret = PyArray_Choose((PyAO *)selector, newtup);\n\tPy_DECREF(selector);\n\tPy_DECREF(newtup);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Conjugate\n*/\nstatic PyObject *\nPyArray_Conjugate(PyArrayObject *self)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyObject *new;\n\t\tintp size, i;\n\t\t/* Make a copy */\n\t\tnew = PyArray_NewCopy(self, -1);\n\t\tif (new==NULL) return NULL;\n\t\tsize = PyArray_SIZE(new);\n\t\tif (self->descr->type_num == PyArray_CFLOAT) {\n\t\t\tcfloat *dptr = (cfloat *) PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CDOUBLE) {\n\t\t\tcdouble *dptr = (cdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CLONGDOUBLE) {\n\t\t\tclongdouble *dptr = (clongdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\t\t\t\n\t\t}\t\t\n\t\treturn new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *) self;\n\t}\n}\n\n/*MULTIARRAY_API\n Trace\n*/\nstatic PyObject *\nPyArray_Trace(PyArrayObject *self, int offset, int axis1, int axis2, \nint rtype)\n{\n\tPyObject *diag=NULL, *ret=NULL;\n\n\tdiag = PyArray_Diagonal(self, offset, axis1, axis2);\n\tif (diag == NULL) return NULL;\n\tret = PyArray_GenericReduceFunction((PyAO *)diag, n_ops.add, -1, rtype);\n\tPy_DECREF(diag);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Diagonal\n*/\nstatic PyObject *\nPyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)\n{\n\tint n = self->nd;\n\tPyObject *new;\n\tPyArray_Dims newaxes;\n\tintp dims[MAX_DIMS];\n\tint i, pos;\t\n\n\tnewaxes.ptr = dims;\n\tif (n < 2) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"array.ndim must be >= 2\");\n\t\treturn NULL;\n\t}\n\tif (axis1 < 0) axis1 += n;\n\tif (axis2 < 0) axis2 += n;\n\tif ((axis1 == axis2) || (axis1 < 0) || (axis1 >= n) ||\t\\\n\t (axis2 < 0) || (axis2 >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \"axis1(=%d) and axis2(=%d) \"\\\n\t\t\t \"must be different and within range (nd=%d)\",\n\t\t\t axis1, axis2, n);\n\t\treturn NULL;\n\t}\n \n\tnewaxes.len = n;\n\t/* insert at the end */\n\tnewaxes.ptr[n-2] = axis1;\n\tnewaxes.ptr[n-1] = axis2;\n\tpos = 0;\n\tfor (i=0; idimensions[0];\n\t\tn2 = self->dimensions[1];\n\t\tstep = n2+1;\n\t\tif (offset < 0) {\n\t\t\tstart = -n2 * offset;\n\t\t\tstop = MIN(n2, n1+offset)*(n2+1) - n2*offset;\n\t\t}\n\t\telse {\n\t\t\tstart = offset;\n\t\t\tstop = MIN(n1, n2-offset)*(n2+1) + offset;\n\t\t}\n\t\t\n\t\t/* count = ceil((stop-start)/step) */\n\t\tcount = ((stop-start) / step) + (((stop-start) % step) != 0);\n\t\t\t\n\t\tindices = PyArray_New(&PyArray_Type, 1, &count, \n\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0, NULL);\n\t\tif (indices == NULL) {\n\t\t\tPy_DECREF(self); return NULL;\n\t\t}\n\t\tdptr = (intp *)PyArray_DATA(indices);\n\t\tfor (n1=start; n1descr;\n\n\t\tmydiagonal = PyList_New(0);\n\t\tif (mydiagonal == NULL) {Py_DECREF(self); return NULL;}\n\t\tn1 = self->dimensions[0];\n\t\tfor (i=0; i 3)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"C arrays of only 1-3 dimensions available\");\n\t\tPy_XDECREF(typedescr);\n\t\treturn -1;\n\t}\n\tif ((ap = (PyArrayObject*)PyArray_FromAny(*op, typedescr, nd, nd,\n\t\t\t\t\t\t CARRAY_FLAGS)) == NULL)\n\t\treturn -1;\n\tswitch(nd) {\n\tcase 1:\n\t\t*((char **)ptr) = ap->data;\n\t\tbreak;\n\tcase 2:\n\t\tn = ap->dimensions[0];\n\t\tptr2 = (char **)_pya_malloc(n * sizeof(char *));\n\t\tif (!ptr2) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0];\n\t\t}\n\t\t*((char ***)ptr) = ptr2;\n\t\tbreak;\t\t\n\tcase 3:\n\t\tn = ap->dimensions[0];\n\t\tm = ap->dimensions[1];\n\t\tptr3 = (char ***)_pya_malloc(n*(m+1) * sizeof(char *));\n\t\tif (!ptr3) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0] + \\\n\t\t\t\t\tj*ap->strides[1];\n\t\t\t}\n\t\t}\n\t\t*((char ****)ptr) = ptr3;\n\t}\n\tmemcpy(dims, ap->dimensions, nd*sizeof(intp));\n\t*op = (PyObject *)ap;\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_MemoryError, \"no memory\");\n\treturn -1;\n}\n\n/* Deprecated --- Use PyArray_AsCArray instead */\n\n/*MULTIARRAY_API\n Convert to a 1D C-array\n*/\nstatic int \nPyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) \n{\n\tintp newd1;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, descr) == -1)\n\t\treturn -1;\t\n\t*d1 = (int) newd1;\n\treturn 0;\n}\n\n/*MULTIARRAY_API\n Convert to a 2D C-array\n*/\nstatic int \nPyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) \n{\n\tintp newdims[2];\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, newdims, 2, descr) == -1)\n\t\treturn -1;\n\n\t*d1 = (int ) newdims[0];\n\t*d2 = (int ) newdims[1];\n return 0;\n}\n\n/* End Deprecated */\n\n/*MULTIARRAY_API\n Free pointers created if As2D is called\n*/\nstatic int \nPyArray_Free(PyObject *op, void *ptr) \n{\n PyArrayObject *ap = (PyArrayObject *)op;\n\t\n if ((ap->nd < 1) || (ap->nd > 3)) \n\t\treturn -1;\n if (ap->nd >= 2) {\n\t\t_pya_free(ptr);\n }\n Py_DECREF(ap);\n return 0;\n}\n\n\nstatic PyObject *\n_swap_and_concat(PyObject *op, int axis, int n)\n{\n\tPyObject *newtup=NULL;\n\tPyObject *otmp, *arr;\n\tint i;\n\n\tnewtup = PyTuple_New(n);\n\tif (newtup==NULL) return NULL;\n\tfor (i=0; i= MAX_DIMS) {\n\t\t\totmp = PyArray_Ravel(mps[i],0);\n\t\t\tPy_DECREF(mps[i]);\n\t\t\tmps[i] = (PyArrayObject *)otmp;\n\t\t}\n\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\tif (prior2 > prior1) {\n\t\t\tprior1 = prior2;\n\t\t\tsubtype = mps[i]->ob_type;\n\t\t\tret = mps[i];\n\t\t}\n\t}\n\t\n\tnew_dim = 0;\n\tfor(i=0; ind;\n\t\telse {\n\t\t\tif (nd != mps[i]->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"arrays must have same \"\\\n\t\t\t\t\t\t\"number of dimensions\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CompareLists(mps[0]->dimensions+1, \n\t\t\t\t\t\t mps[i]->dimensions+1, \n\t\t\t\t\t\t nd-1)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"array dimensions must \"\\\n\t\t\t\t\t\t\"agree except for d_0\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (nd == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"0-d arrays can't be concatenated\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnew_dim += mps[i]->dimensions[0];\n\t}\n\t\n\ttmp = mps[0]->dimensions[0];\n\tmps[0]->dimensions[0] = new_dim;\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(subtype, \n\t\t\t\t\t\t mps[0]->descr, nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ret);\n\tmps[0]->dimensions[0] = tmp;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tdata = ret->data;\n\tfor(i=0; idata, numbytes);\n\t\tdata += numbytes;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; ind;\n\tif (n <= 1) {\n\t\tPy_INCREF(ap);\n\t\treturn (PyObject *)ap;\n\t}\n\n\tif (a1 < 0) a1 += n;\n\tif (a2 < 0) a2 += n;\n\tif ((a1 < 0) || (a1 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis1 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tif ((a2 < 0) || (a2 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis2 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tnew_axes.ptr = dims;\n\tnew_axes.len = n;\n\n\tfor (i=0; ind;\n\t\tfor(i=0; ilen;\n\t\taxes = permute->ptr;\n\t\tif (n > ap->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many axes for this array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tfor(i=0; ind+axis;\n\t\t\tif (axis < 0 || axis >= ap->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"invalid axis for this array\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tpermutation[i] = axis;\n\t\t}\n\t}\n\t\n\t/* this allocates memory for dimensions and strides (but fills them\n\t incorrectly), sets up descr, and points data at ap->data. */\n\tPy_INCREF(ap->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t ap->descr, \n\t\t\t\t n, permutation, \n\t\t\t\t NULL, ap->data, ap->flags,\n\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) return NULL;\n\t\n\t/* point at true owner of memory: */\n\tret->base = (PyObject *)ap;\n\tPy_INCREF(ap);\n\t\n\tfor(i=0; idimensions[i] = ap->dimensions[permutation[i]];\n\t\tret->strides[i] = ap->strides[permutation[i]];\n\t}\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\t\n\n\treturn (PyObject *)ret;\t\n}\n\n/*MULTIARRAY_API\n Repeat the array.\n*/\nstatic PyObject *\nPyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis)\n{\n\tintp *counts;\n\tintp n, n_outer, i, j, k, chunk, total;\n\tintp tmp;\n\tint nd;\n\tPyArrayObject *repeats=NULL;\n\tPyObject *ap=NULL;\n\tPyArrayObject *ret=NULL;\n\tchar *new_data, *old_data;\n\n\trepeats = (PyAO *)PyArray_ContiguousFromAny(op, PyArray_INTP, 0, 1);\n\tif (repeats == NULL) return NULL;\n\tnd = repeats->nd;\n\tcounts = (intp *)repeats->data;\n\n\tif ((ap=_check_axis(aop, &axis, CARRAY_FLAGS))==NULL) {\n\t\tPy_DECREF(repeats);\n\t\treturn NULL;\n\t}\n\n\taop = (PyAO *)ap;\n\n\tif (nd == 1)\n\t\tn = repeats->dimensions[0];\n\telse /* nd == 0 */\n\t\tn = aop->dimensions[axis];\n\n\tif (aop->dimensions[axis] != n) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"a.shape[axis] != len(repeats)\");\n\t\tgoto fail;\n\t}\n\n\t\n\tif (nd == 0) \n\t\ttotal = counts[0]*n;\n\telse {\n\t\t\n\t\ttotal = 0;\n\t\tfor(j=0; jdimensions[axis] = total;\n\tPy_INCREF(aop->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(aop->ob_type, \n\t\t\t\t\t\t aop->descr,\n\t\t\t\t\t\t aop->nd,\n\t\t\t\t\t\t aop->dimensions,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)aop);\n\taop->dimensions[axis] = n;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tnew_data = ret->data;\n\told_data = aop->data;\n\t\n\tchunk = aop->descr->elsize;\n\tfor(i=axis+1; ind; i++) {\n\t\tchunk *= aop->dimensions[i];\n\t}\n\t\n\tn_outer = 1;\n\tfor(i=0; idimensions[i];\n\n\tfor(i=0; ind < mps[i]->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many dimensions\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (!PyArray_CompareLists(ap->dimensions+(ap->nd-mps[i]->nd),\n\t\t\t\t mps[i]->dimensions, mps[i]->nd)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"array dimensions must agree\");\n\t\t\tgoto fail;\n\t\t}\n\t\tsizes[i] = PyArray_NBYTES(mps[i]);\n\t}\n\t\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t\t\t mps[0]->descr,\n\t\t\t\t\t\t ap->nd,\n\t\t\t\t\t\t ap->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\telsize = ret->descr->elsize;\n\tm = PyArray_SIZE(ret);\n\tself_data = (intp *)ap->data;\n\tret_data = ret->data;\n\t\n\tfor (i=0; i= n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid entry in choice array\");\n\t\t\tgoto fail;\n\t\t}\n\t\toffset = i*elsize;\n\t\tif (offset >= sizes[mi]) {offset = offset % sizes[mi]; }\n\t\tmemmove(ret_data, mps[mi]->data+offset, elsize);\n\t\tret_data += elsize; self_data++;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; idescr->f->sort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize);\n\n\tif (needcopy) {\n\t\tchar *buffer;\n\t\tbuffer = PyDataMem_NEW(N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(buffer, (intp) elsize, it->dataptr, \n\t\t\t\t astride, N, elsize);\n\t\t\tif (sort(buffer, N, op) < 0) {\n\t\t\t\tPyDataMem_FREE(buffer); goto fail;\n\t\t\t}\n\t\t\t_strided_copy(it->dataptr, astride, buffer, \n\t\t\t\t (intp) elsize, N, elsize);\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyDataMem_FREE(buffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tif (sort(it->dataptr, N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\t\n\t\n\tEND_THREADS\n\t\n\tPy_DECREF(it);\n\treturn 0;\n\n fail:\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nstatic PyObject*\n_new_argsort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\n\tPyArrayIterObject *it=NULL;\n\tPyArrayIterObject *rit=NULL;\n\tPyObject *ret;\n\tint needcopy=0, i;\n\tintp N, size;\n\tint elsize;\n\tintp astride, rstride, *iptr;\n\tPyArray_ArgSortFunc *argsort;\n\tBEGIN_THREADS_DEF \n\n\tret = PyArray_New(op->ob_type, op->nd,\n\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) return NULL;\n\n\tit = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)op, axis);\n\trit = (PyArrayIterObject *)PyArray_IterAllButAxis(ret, axis);\n\tif (rit == NULL || it == NULL) goto fail;\n\n\tBEGIN_THREADS\n\n\targsort = op->descr->f->argsort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize) || \\\n\t\t(rstride != sizeof(intp));\n\t\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(elsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(valbuffer, (intp) elsize, it->dataptr,\n\t\t\t\t astride, N, elsize);\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idataptr, rstride, indbuffer, \n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idataptr, (intp *)rit->dataptr, \n\t\t\t\t N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\t\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\tPy_DECREF(rit);\n\treturn ret;\n\n fail:\n\n\tEND_THREADS\n\n\tPy_DECREF(ret);\n\tPy_XDECREF(it);\n\tPy_XDECREF(rit);\n\treturn NULL;\n}\n\n\n/* Be sure to save this global_compare when necessary */\n\nstatic PyArrayObject *global_obj;\n\nstatic int \nqsortCompare (const void *a, const void *b) \n{\n\treturn global_obj->descr->f->compare(a,b,global_obj);\n}\n\n/* Consumes reference to ap (op gets it)\n op contains a version of the array with axes swapped if\n local variable axis is not the last dimension.\n orign must be defined locally. \n*/\n\n#define SWAPAXES(op, ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* Consumes reference to ap (op gets it)\n origin must be previously defined locally. \n SWAPAXES must have been called previously. \n op contains the swapped version of the array. \n*/\n#define SWAPBACK(op, ap) {\t \\\n\t\tif (axis != orign) { \\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* These swap axes in-place if necessary */\n#define SWAPINTP(a,b) {intp c; c=(a); (a) = (b); (b) = c;}\n#define SWAPAXES2(ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN); \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define SWAPBACK2(ap) {\t\t \\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n/*MULTIARRAY_API\n Sort an array in-place\n*/\nstatic int\nPyArray_Sort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *store_arr=NULL;\n\tchar *ip;\n\tint i, n, m, elsize, orign;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) return 0;\n\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\treturn -1;\n\t}\n\tif (!PyArray_ISWRITEABLE(op)) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"attempted sort on unwriteable array.\");\n\t\treturn -1;\n\t}\n\n\t/* Determine if we should use type-specific algorithm or not */\n\tif (op->descr->f->sort[which] != NULL) {\n\t\treturn _new_sort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || \\\n\t op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"desired sort not supported for this type\");\n\t\treturn -1;\n\t}\n\n\tSWAPAXES2(op);\n\n ap = (PyArrayObject *)PyArray_FromAny((PyObject *)op, \n\t\t\t\t\t NULL, 1, 0, \n\t\t\t\t\t DEFAULT_FLAGS | UPDATEIFCOPY);\t\n\tif (ap == NULL) goto fail;\n\t\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(ap)/m;\n\n\t/* Store global -- allows re-entry -- restore before leaving*/\n\tstore_arr = global_obj; \n\tglobal_obj = ap;\n\t\n\tfor (ip=ap->data, i=0; idescr->elsize;\n\tconst intp *ipa = ip1;\n\tconst intp *ipb = ip2;\t\n\treturn global_obj->descr->f->compare(global_data + (isize * *ipa),\n global_data + (isize * *ipb), \n\t\t\t\t\t global_obj);\n}\n\n/*MULTIARRAY_API\n ArgSort an array\n*/\nstatic PyObject *\nPyArray_ArgSort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *ret=NULL, *store;\n\tintp *ip;\n\tintp i, j, n, m, orign;\n\tint argsort_elsize;\n\tchar *store_ptr;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t\t op->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, \n\t\t\t\t\t\t (PyObject *)op);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)ret->data) = 0;\n\t\treturn (PyObject *)ret;\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\treturn NULL;\n\t}\n\n\t/* Determine if we should use new algorithm or not */\n\tif (op->descr->f->argsort[which] != NULL) {\n\t\treturn _new_argsort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"requested sort not available for type\");\n\t\tgoto fail;\n\t}\n\n\tSWAPAXES(ap, op);\n\n\top = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ap, \n\t\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t\t 1, 0);\n\n\tif (op == NULL) return NULL;\n\t\n\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) goto fail;\n\t\n\t\n\tip = (intp *)ret->data;\n\targsort_elsize = op->descr->elsize;\n\tm = op->dimensions[op->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(op)/m;\n\tstore_ptr = global_data;\n\tglobal_data = op->data;\n\tstore = global_obj;\n\tglobal_obj = op;\n\tfor (i=0; i 0 in lexsort\");\n\t\treturn NULL;\n\t}\n\tmps = (PyArrayObject **) _pya_malloc(n*sizeof(PyArrayObject));\n\tif (mps==NULL) return PyErr_NoMemory();\n\tits = (PyArrayIterObject **) _pya_malloc(n*sizeof(PyArrayIterObject));\n\tif (its == NULL) {_pya_free(mps); return PyErr_NoMemory();}\n\tfor (i=0; i0) {\n\t\t\tif ((mps[i]->nd != mps[0]->nd) ||\t\\\n\t\t\t (!PyArray_CompareLists(mps[i]->dimensions,\n\t\t\t\t\t\t mps[0]->dimensions,\n\t\t\t\t\t\t mps[0]->nd))) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"all keys need to be the same shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (!mps[i]->descr->f->argsort[PyArray_MERGESORT]) {\n\t\t\tPyErr_Format(PyExc_TypeError, \n\t\t\t\t \"merge sort not available for item %d\", i);\n\t\t\tgoto fail;\n\t\t}\n\t\tits[i] = (PyArrayIterObject *)PyArray_IterAllButAxis\t\\\n\t\t\t((PyObject *)mps[i], axis);\n\t\tif (its[i]==NULL) goto fail;\n\t}\n\n\t/* Now we can check the axis */\n\tnd = mps[0]->nd;\n\tif ((nd==0) || (PyArray_SIZE(mps[0])==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)(ret->data)) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += nd;\n\tif ((axis < 0) || (axis >= nd)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\tgoto fail;\n\t}\n\n\t/* Now do the sorting */\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t mps[0]->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (ret == NULL) goto fail;\n\n\trit = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ret, axis);\n\tif (rit == NULL) goto fail;\n\n\tsize = rit->size;\n\tN = mps[0]->dimensions[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n maxelsize = mps[0]->descr->elsize;\n\tneedcopy = (rstride != sizeof(intp));\n\tfor (j=0; jflags & ALIGNED) || \\\n\t\t\t(mps[j]->strides[axis] != (intp)mps[j]->descr->elsize);\n if (mps[j]->descr->elsize > maxelsize) \n maxelsize = mps[j]->descr->elsize;\n\t}\n\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(maxelsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*maxelsize);\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idescr->elsize;\n\t\t\t\tastride = mps[j]->strides[axis];\t\n\t\t\t\targsort = mps[j]->descr->f->argsort[PyArray_MERGESORT];\n\t\t\t\t_strided_copy(valbuffer, (intp) elsize, its[j]->dataptr,\n\t\t\t\t\t astride, N, elsize);\n\t\t\t\tif (argsort(valbuffer, (intp *)indbuffer, N, mps[j]) < 0) {\n\t\t\t\t\tPyDataMem_FREE(valbuffer); goto fail;\n\t\t\t\t}\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\t_strided_copy(rit->dataptr, rstride, indbuffer,\n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idescr->f->argsort[PyArray_MERGESORT];\n\t\t\t\tif (argsort(its[j]->dataptr, (intp *)rit->dataptr,\n\t\t\t\t\t N, mps[j]) < 0) goto fail;\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\n\tfor (i=0; idescr->f->compare;\n\tintp min_i, max_i, i, j;\n\tint location, elsize = ap1->descr->elsize;\n\tintp elements = ap1->dimensions[ap1->nd-1];\n\tintp n = PyArray_SIZE(ap2);\n\tintp *rp = (intp *)ret->data;\n\tchar *ip = ap2->data;\n\tchar *vp = ap1->data;\n\n\tfor (j=0; j 0) {\n\t\t\t\t\tif (compare(ip, vp+elsize*(--i), ap2) \\\n\t\t\t\t\t != 0) {\n\t\t\t\t\t\ti = i+1; break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmin_i = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (location < 0) {\n\t\t\t\tmax_i = i;\n\t\t\t} else {\n\t\t\t\tmin_i = i+1;\n\t\t\t}\n\t\t}\n\t\t*rp = min_i;\n\t}\n}\n\n/*MULTIARRAY_API\n Numeric.searchsorted(a,v)\n*/\nstatic PyObject *\nPyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n\tint typenum = 0;\n\n\t/* \n PyObject *args;\n args = Py_BuildValue(\"O\",op2);\n\tPy_DELEGATE_ARGS(((PyObject *)op1), searchsorted, args);\n Py_XDECREF(args);\n\t*/\n\n\ttypenum = PyArray_ObjectType((PyObject *)op1, 0);\n\ttypenum = PyArray_ObjectType(op2, typenum);\n\tret = NULL;\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op1, \n\t\t\t\t\t\t\t typenum, \n\t\t\t\t\t\t\t 1, 1);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tret = (PyArrayObject *)PyArray_New(ap2->ob_type, ap2->nd, \n\t\t\t\t\t ap2->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap2);\n\tif (ret == NULL) goto fail;\n\n\tif (ap2->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tgoto fail;\n\t}\n\t\n\tlocal_where(ap1, ap2, ret); \n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n\n\n/* Could perhaps be redone to not make contiguous arrays \n */\n\n/*MULTIARRAY_API\n Numeric.innerproduct(a,v)\n*/\nstatic PyObject *\nPyArray_InnerProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tintp i, j, l, i1, i2, n1, n2;\n\tint typenum;\n\tintp is1, is2, os;\n\tchar *ip1, *ip2, *op;\n\tintp dimensions[MAX_DIMS], nd;\n\tPyArray_DotFunc *dot;\n\tPyTypeObject *subtype;\n double prior1, prior2;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\t\t\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny(op1, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n \n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\tif (ret == NULL) goto fail;\n\n\tdot = (ret->descr->f->dotfunc);\n\t\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\n\t\n\tis1 = ap1->strides[ap1->nd-1]; \n\tis2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t\totherDim = ap2->nd - 1;\n\t}\n\telse {\n\t\tmatchDim = 0;\n\t\totherDim = 0;\n\t}\n\n\tif (ap2->dimensions[matchDim] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"objects are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-2; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\tif(ap2->nd > 1) {\n\t\tdimensions[j++] = ap2->dimensions[ap2->nd-1];\n\t}\n\t/*\n\tfprintf(stderr, \"nd=%d dimensions=\", nd);\n\t for(i=0; i prior1 ? ap2->ob_type : ap1->ob_type);\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\n\n\tif (ret == NULL) goto fail;\n\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\t\t\n\tis1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\tif(ap1->nd > 1)\n\t\tis1r = ap1->strides[ap1->nd-2];\n\telse\n\t\tis1r = ap1->strides[ap1->nd-1];\n\tis2r = ap2->strides[otherDim];\n\n\top = ret->data; os = ret->descr->elsize;\n\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t 2, dims, \n\t\t\t\t NULL, NULL, 0, arr);\n\n\tif (ret == NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn NULL;\n\t}\n\t/* do 2-d loop */\n\toptr = PyArray_DATA(ret);\n\tstr2 = elsize*dims[0];\n\tfor (i=0; idimensions[0];\n\tn2 = ap2->dimensions[0];\n\n\tif (n1 < n2) { \n\t\tret = ap1; ap1 = ap2; ap2 = ret; \n\t\tret = NULL; i = n1;n1=n2;n2=i;\n\t}\n\tlength = n1;\n\tn = n2;\n\tswitch(mode) {\n\tcase 0:\t\n\t\tlength = length-n+1;\n\t\tn_left = n_right = 0;\n\t\tbreak;\n\tcase 1:\n\t\tn_left = (intp)(n/2);\n\t\tn_right = n-n_left-1;\n\t\tbreak;\n\tcase 2:\n\t\tn_right = n-1;\n\t\tn_left = n-1;\n\t\tlength = length+n-1;\n\t\tbreak;\n\tdefault:\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mode must be 0, 1, or 2\");\n\t\tgoto fail;\n\t}\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t\n\tret = (PyArrayObject *)PyArray_New(subtype, 1,\n\t\t\t\t\t &length, typenum, \n\t\t\t\t\t NULL, NULL, 0, 0,\n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\tif (ret == NULL) goto fail;\n\t\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"function not available for this data type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[0]; is2 = ap2->strides[0];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data; ip2 = ap2->data+n_left*is2;\n\tn = n-n_left;\n\tfor(i=0; idescr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Min\n*/\nstatic PyObject *\nPyArray_Min(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tret = PyArray_GenericReduceFunction(arr, n_ops.minimum, axis,\n\t\t\t\t\t arr->descr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Ptp\n*/\nstatic PyObject *\nPyArray_Ptp(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\tPyObject *obj1=NULL, *obj2=NULL;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tobj1 = PyArray_Max(arr, axis);\n\tif (obj1 == NULL) goto fail;\n\tobj2 = PyArray_Min(arr, axis);\n\tif (obj2 == NULL) goto fail;\n\tPy_DECREF(arr);\n\tret = PyNumber_Subtract(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(obj1);\n\tPy_XDECREF(obj2);\n\treturn NULL;\n}\n\n\n/*MULTIARRAY_API\n ArgMax\n*/\nstatic PyObject *\nPyArray_ArgMax(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap=NULL, *rp=NULL;\n\tPyArray_ArgFunc* arg_func;\n\tchar *ip;\n\tintp *rptr;\n\tintp i, n, orign, m;\n\tint elsize;\n\t\n\tif ((ap=(PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny((PyObject *)op, \n\t\t\t\t\t PyArray_NOTYPE, 1, 0);\n\n\tPy_DECREF(op);\n\tif (ap == NULL) return NULL;\n\t\n\targ_func = ap->descr->f->argmax;\n\tif (arg_func == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"data type not ordered\");\n\t\tgoto fail;\n\t}\n\n\trp = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd-1,\n\t\t\t\t\t ap->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)ap);\n\tif (rp == NULL) goto fail;\n\n\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) {\n\t\tPyErr_SetString(MultiArrayError, \n\t\t\t\t\"attempt to get argmax/argmin \"\\\n\t\t\t\t\"of an empty sequence??\");\n\t\tgoto fail;\n\t}\n\tn = PyArray_SIZE(ap)/m;\n\trptr = (intp *)rp->data;\n\tfor (ip = ap->data, i=0; ind + indices->nd - 1;\n for (i=0; i< nd; i++) {\n if (i < axis) {\n shape[i] = self->dimensions[i];\n n *= shape[i];\n } else {\n if (i < axis+indices->nd) {\n shape[i] = indices->dimensions[i-axis];\n m *= shape[i];\n } else {\n shape[i] = self->dimensions[i-indices->nd+1];\n chunk *= shape[i];\n }\n }\n }\n\tPy_INCREF(self->descr);\n ret = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t nd, shape, \n\t\t\t\t\t\t NULL, NULL, 0, \n\t\t\t\t\t\t (PyObject *)self);\n\t\n if (ret == NULL) goto fail;\n\t\n max_item = self->dimensions[axis];\n chunk = chunk * ret->descr->elsize;\n src = self->data;\n dest = ret->data;\n\t\n for(i=0; idata))[j];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\t\"index out of range for \"\\\n\t\t\t\t\t\t\"array\");\n goto fail;\n }\n memmove(dest, src+tmp*chunk, chunk);\n dest += chunk;\n }\n src += chunk*max_item;\n }\n\t\n PyArray_INCREF(ret);\n\n Py_XDECREF(indices);\n Py_XDECREF(self);\n\n return (PyObject *)ret;\n\t\n\t\n fail:\n Py_XDECREF(ret);\n Py_XDECREF(indices);\n Py_XDECREF(self);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array\n*/\nstatic PyObject *\nPyArray_Put(PyArrayObject *self, PyObject* values0, PyObject *indices0) \n{\n PyArrayObject *indices, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype; \n char *src, *dest;\n\n indices = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \"put: first argument must be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \"put: first argument must be contiguous\");\n return NULL;\n }\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0);\n if (indices == NULL) goto fail;\n ni = PyArray_SIZE(indices);\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\n if (thistype == PyArray_OBJECT) { \n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n Py_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+tmp*chunk)));\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n\n }\n\n Py_XDECREF(values);\n Py_XDECREF(indices);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(indices);\n Py_XDECREF(values);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array according to a mask.\n*/\nstatic PyObject *\nPyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) \n{\n PyArrayObject *mask, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype;\n char *src, *dest;\n\n mask = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"putmask: first argument must \"\\\n\t\t\t\t\"be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: first argument must be contiguous\");\n return NULL;\n }\n\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n mask = (PyArrayObject *)\\\n\t\tPyArray_FROM_OTF(mask0, PyArray_BOOL, CARRAY_FLAGS | FORCECAST);\n\tif (mask == NULL) goto fail;\n ni = PyArray_SIZE(mask);\n if (ni != max_item) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: mask and data must be \"\\\n\t\t\t\t\"the same size\");\n goto fail;\n }\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n\tif (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\t /* zero if null array */\n if (nv > 0) {\n if (thistype == PyArray_OBJECT) {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) {\n\t\t\t\t\tPy_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+i*chunk)));\n memmove(dest + i * chunk, src, chunk);\n }\n\t\t\t}\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) memmove(dest + i * chunk, src, chunk);\n\t\t\t}\n\t\t}\n }\n\n Py_XDECREF(values);\n Py_XDECREF(mask);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(mask);\n Py_XDECREF(values);\n return NULL;\n}\n\n\n/* This conversion function can be used with the \"O&\" argument for\n PyArg_ParseTuple. It will immediately return an object of array type\n or will convert to a CARRAY any other object. \n\n If you use PyArray_Converter, you must DECREF the array when finished\n as you get a new reference to it.\n*/\n \n/*MULTIARRAY_API\n Useful to pass as converter function for O& processing in\n PyArgs_ParseTuple.\n*/\nstatic int \nPyArray_Converter(PyObject *object, PyObject **address) \n{\n if (PyArray_Check(object)) {\n *address = object;\n\t\tPy_INCREF(object);\n return PY_SUCCEED;\n }\n else {\n\t\t*address = PyArray_FromAny(object, NULL, 0, 0, CARRAY_FLAGS);\n\t\tif (*address == NULL) return PY_FAIL;\n\t\treturn PY_SUCCEED;\n }\n}\n\n/*MULTIARRAY_API\n Convert an object to true / false\n*/\nstatic int\nPyArray_BoolConverter(PyObject *object, Bool *val)\n{ \n if (PyObject_IsTrue(object))\n *val=TRUE;\n else *val=FALSE;\n if (PyErr_Occurred())\n return PY_FAIL;\n return PY_SUCCEED;\n}\n\n\n/*MULTIARRAY_API\n Typestr converter\n*/\nstatic int\nPyArray_TypestrConvert(int itemsize, int gentype)\n{\n\tregister int newtype = gentype;\n\t\n\tif (gentype == PyArray_GENBOOLLTR) {\n\t\tif (itemsize == 1)\n\t\t\tnewtype = PyArray_BOOL;\n\t\telse \n\t\t\tnewtype = PyArray_NOTYPE;\n\t}\n\telse if (gentype == PyArray_SIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_INT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_INT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_INT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_INT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_INT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\n\t}\n\n\telse if (gentype == PyArray_UNSIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_UINT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_UINT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_UINT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_UINT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_UINT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t\tbreak;\n\t\t}\n\t}\n\telse if (gentype == PyArray_FLOATINGLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 4:\n\t\t\tnewtype = PyArray_FLOAT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_FLOAT64;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 10:\n\t\t\tnewtype = PyArray_FLOAT80;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 12:\n\t\t\tnewtype = PyArray_FLOAT96;\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_FLOAT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\t\n\telse if (gentype == PyArray_COMPLEXLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 8:\n\t\t\tnewtype = PyArray_COMPLEX64;\n\t\t\tbreak;\n\t\tcase 16:\n\t\t\tnewtype = PyArray_COMPLEX128;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 20:\n\t\t\tnewtype = PyArray_COMPLEX160;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 24:\n\t\t\tnewtype = PyArray_COMPLEX192;\t\t\t\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 32:\n\t\t\tnewtype = PyArray_COMPLEX256;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\n\treturn newtype;\n}\n\n\n/* this function takes a Python object which exposes the (single-segment)\n buffer interface and returns a pointer to the data segment\n \n You should increment the reference count by one of buf->base\n if you will hang on to a reference\n\n You only get a borrowed reference to the object. Do not free the\n memory...\n*/\n\n\n/*MULTIARRAY_API\n Get buffer chunk from object\n*/\nstatic int\nPyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)\n{\n int buflen;\n\n buf->ptr = NULL;\n buf->flags = BEHAVED_FLAGS;\n buf->base = NULL;\n\n\tif (obj == Py_None)\n\t\treturn PY_SUCCEED;\n\n if (PyObject_AsWriteBuffer(obj, &(buf->ptr), &buflen) < 0) {\n PyErr_Clear();\n buf->flags &= ~WRITEABLE;\n if (PyObject_AsReadBuffer(obj, (const void **)&(buf->ptr), \n &buflen) < 0)\n return PY_FAIL;\n }\n buf->len = (intp) buflen;\n \n /* Point to the base of the buffer object if present */\n if (PyBuffer_Check(obj)) buf->base = ((PyArray_Chunk *)obj)->base;\n if (buf->base == NULL) buf->base = obj;\n \n return PY_SUCCEED; \n}\n\n\n\n/* This function takes a Python sequence object and allocates and\n fills in an intp array with the converted values.\n\n **Remember to free the pointer seq.ptr when done using\n PyDimMem_FREE(seq.ptr)**\n*/\n\n/*MULTIARRAY_API\n Get intp chunk from sequence\n*/\nstatic int\nPyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)\n{\n int len;\n int nd;\n\n seq->ptr = NULL;\n if (obj == Py_None) return PY_SUCCEED;\n len = PySequence_Size(obj);\n if (len == -1) { /* Check to see if it is a number */\n if (PyNumber_Check(obj)) len = 1;\n }\n if (len < 0) {\n PyErr_SetString(PyExc_TypeError, \n \"expected sequence object with len >= 0\");\n return PY_FAIL;\n }\n if (len > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError, \"sequence too large; \" \\\n \"must be smaller than %d\", MAX_DIMS);\n return PY_FAIL;\n }\n\tif (len > 0) {\n\t\tseq->ptr = PyDimMem_NEW(len);\n\t\tif (seq->ptr == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n seq->len = len;\n nd = PyArray_IntpFromSequence(obj, (intp *)seq->ptr, len);\n if (nd == -1 || nd != len) {\n\t\tPyDimMem_FREE(seq->ptr);\n\t\tseq->ptr=NULL;\n\t\treturn PY_FAIL;\n\t}\n return PY_SUCCEED;\n}\n\n\n/* A tuple type would be either (generic typeobject, typesize) \n or (fixed-length data-type, shape) \n\n or (inheriting data-type, new-data-type)\n The new data-type must have the same itemsize as the inheriting data-type\n unless the latter is 0 \n \n Thus (int32, {'real':(int16,0),'imag',(int16,2)})\n\n is one way to specify a descriptor that will give \n a['real'] and a['imag'] to an int32 array.\n*/\n\n/* leave type reference alone */\nstatic PyArray_Descr *\n_use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) \n{\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n\t\n\t*errflag = 0;\n\tif (!PyArray_DescrConverter(newobj, &conv)) {\n\t\treturn NULL;\n\t}\n\t*errflag = 1;\n\tif (type == &OBJECT_Descr) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"cannot base a new descriptor on an\"\\\n\t\t\t\t\" OBJECT descriptor.\");\n\t\treturn NULL;\n\t}\n\tnew = PyArray_DescrNew(type);\n\tif (new == NULL) return NULL;\n\n\tif (new->elsize && new->elsize != conv->elsize) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mismatch in size of old\"\\\n\t\t\t\t\"and new data-descriptor\");\n\t\treturn NULL;\n\t}\n\tnew->elsize = conv->elsize;\n\tif (conv->fields != Py_None) {\n\t\tnew->fields = conv->fields;\n\t\tPy_XINCREF(new->fields);\n\t}\n\tPy_DECREF(conv);\n\t*errflag = 0;\n\treturn new;\n}\n\nstatic PyArray_Descr *\n_convert_from_tuple(PyObject *obj) \n{\n\tPyArray_Descr *type, *res;\n\tPyObject *val;\n\tint errflag;\n\t\n\tif (PyTuple_GET_SIZE(obj) != 2) return NULL;\n\n\tif (!PyArray_DescrConverter(PyTuple_GET_ITEM(obj,0), &type)) \n\t\treturn NULL;\n\tval = PyTuple_GET_ITEM(obj,1);\n\t/* try to interpret next item as a type */\n\tres = _use_inherit(type, val, &errflag);\n\tif (res || errflag) {\n\t\tPy_DECREF(type);\n\t\tif (res) return res;\n\t\telse return NULL;\n\t}\n\tPyErr_Clear();\n\t/* We get here if res was NULL but errflag wasn't set\n\t --- i.e. the conversion to a data-descr failed in _use_inherit\n\t*/\n\n\tif (type->elsize == 0) { /* interpret next item as a typesize */\n\t\tint itemsize;\n\t\titemsize = PyArray_PyIntAsInt(PyTuple_GET_ITEM(obj,1));\n\t\tif (error_converting(itemsize)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid itemsize in generic type \"\\\n\t\t\t\t\t\"tuple\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(type);\n\t\ttype->elsize = itemsize;\n\t}\n\telse {\n\t\t/* interpret next item as shape (if it's a tuple)\n\t\t and reset the type to PyArray_VOID with \n\t\t anew fields attribute. \n\t */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyArray_Descr *newdescr;\n\t\tif (!(PyArray_IntpConverter(val, &shape)) || \n\t\t (shape.len > MAX_DIMS)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnewdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tif (newdescr == NULL) {PyDimMem_FREE(shape.ptr); goto fail;}\n\t\tnewdescr->elsize = type->elsize;\n\t\tnewdescr->elsize *= PyArray_MultiplyList(shape.ptr, \n\t\t\t\t\t\t\t shape.len);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tnewdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tnewdescr->subarray->base = type;\n\t\tPy_INCREF(val);\n\t\tnewdescr->subarray->shape = val;\n\t\tPy_XDECREF(newdescr->fields);\n\t\tnewdescr->fields = NULL;\n\t\ttype = newdescr;\n\t}\n\treturn type;\n\n fail:\n\tPy_XDECREF(type);\n\treturn NULL;\n}\n\n/* obj is a list. Each item is a tuple with\n\n(field-name, data-type (either a list or a string), and an optional \n shape parameter).\n*/\nstatic PyArray_Descr *\n_convert_from_array_descr(PyObject *obj)\n{\n\tint n, i, totalsize;\n\tint ret;\n\tPyObject *fields, *item, *newobj;\n\tPyObject *name, *key, *tup;\n\tPyObject *nameslist;\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n\t\n\tn = PyList_GET_SIZE(obj);\t\n\tnameslist = PyList_New(n);\n\tif (!nameslist) return NULL;\n\ttotalsize = 0;\n\tfields = PyDict_New();\n\tfor (i=0; ielsize;\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(tup);\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n\tnew->elsize = totalsize;\n\treturn new;\n \n fail:\n\tPy_DECREF(fields);\n\tPy_DECREF(nameslist);\n\treturn NULL;\n\n}\n\n/* a list specifying a data-type can just be\n a list of formats. The names for the fields\n will default to f1, f2, f3, and so forth.\n\n or it can be an array_descr format string -- in which case\n align must be 0. \n*/\n\nstatic PyArray_Descr *\n_convert_from_list(PyObject *obj, int align, int try_descr)\n{\n\tint n, i;\n\tint totalsize;\n\tPyObject *fields;\n\tPyArray_Descr *conv=NULL;\n\tPyArray_Descr *new;\n\tPyObject *key, *tup;\n\tPyObject *nameslist=NULL;\n \tint ret;\n\tint maxalign=0;\n\t\n\tn = PyList_GET_SIZE(obj);\n\ttotalsize = 0;\n\tif (n==0) return NULL;\n\tnameslist = PyList_New(n);\n\tif (!nameslist) return NULL;\n\tfields = PyDict_New();\n\tfor (i=0; ielsize;\n\t\tif (align) {\n\t\t\tint _align;\n\t\t\t_align = conv->alignment;\n\t\t\tif (_align > 1) totalsize =\t\t\t\\\n\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\tmaxalign = MAX(maxalign, _align);\n\t\t}\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n\tif (maxalign > 1) {\n\t\ttotalsize = ((totalsize+maxalign-1)/maxalign)*maxalign;\n\t}\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\treturn new;\n\n fail:\n\tPy_DECREF(nameslist);\n\tPy_DECREF(fields);\n\tif (!try_descr) return NULL;\n\tif (align) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"failed to convert from list of formats \"\\\n\t\t\t\t\"and align cannot be 1 for conversion from \"\\\n\t\t\t\t\"array_descr structure\");\n\t\treturn NULL;\n\t}\n\tPyErr_Clear();\n\treturn _convert_from_array_descr(obj);\n}\n\n\n/* comma-separated string */\n/* this is the format developed by the numarray records module */\n/* and implemented by the format parser in that module */\n/* this is an alternative implementation found in the _internal.py \n file patterned after that one -- the approach is to try to convert \n to a list (with tuples if any repeat information is present) \n and then call the _convert_from_list)\n*/\n\nstatic PyArray_Descr *\n_convert_from_commastring(PyObject *obj, int align)\n{\n\tPyObject *listobj;\n\tPyArray_Descr *res;\n\n\tif (!PyString_Check(obj)) return NULL;\n listobj = PyObject_CallMethod(_numpy_internal, \"_commastring\",\n\t\t\t\t \"O\", obj);\n\tif (!listobj) return NULL;\n\tres = _convert_from_list(listobj, align, 0);\n\tPy_DECREF(listobj);\n\tif (!res && !PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_ValueError, \"invalid data-type\");\n\t\treturn NULL;\n\t}\n\treturn res;\n}\n\n\n\n/* a dictionary specifying a data-type\n must have at least two and up to four\n keys These must all be sequences of the same length.\n\n \"names\" --- field names \n \"formats\" --- the data-type descriptors for the field.\n \n Optional:\n\n \"offsets\" --- integers indicating the offset into the \n record of the start of the field.\n\t\t if not given, then \"consecutive offsets\" \n\t\t will be assumed and placed in the dictionary.\n \n \"titles\" --- Allows the use of an additional key\n for the fields dictionary.\n \nAttribute-lookup-based field names merely has to query the fields \ndictionary of the data-descriptor. Any result present can be used\nto return the correct field.\n\nSo, the notion of what is a name and what is a title is really quite\narbitrary. \n\nWhat does distinguish a title, however, is that if it is not None, \nit will be placed at the end of the tuple inserted into the \nfields dictionary.\n\nIf the dictionary does not have \"names\" and \"formats\" entries,\nthen it will be checked for conformity and used directly. \n*/\n\nstatic PyArray_Descr *\n_use_fields_dict(PyObject *obj, int align)\n{\n return (PyArray_Descr *)PyObject_CallMethod(_numpy_internal, \n\t\t\t\t\t\t \"_usefields\", \n\t\t\t\t\t\t \"Oi\", obj, align);\n}\n\nstatic PyArray_Descr *\n_convert_from_dict(PyObject *obj, int align)\n{\n\tPyArray_Descr *new;\n\tPyObject *fields=NULL;\n\tPyObject *names, *offsets, *descrs, *titles, *key;\n\tint n, i;\n\tint totalsize;\n\tint maxalign=0;\n\t\n\tfields = PyDict_New();\n\tif (fields == NULL) return (PyArray_Descr *)PyErr_NoMemory();\n\t\n\tnames = PyDict_GetItemString(obj, \"names\");\n\tdescrs = PyDict_GetItemString(obj, \"formats\");\n\n\tif (!names || !descrs) {\n\t\tPy_DECREF(fields);\n\t\treturn _use_fields_dict(obj, align);\n\t}\n\tn = PyObject_Length(names);\n\toffsets = PyDict_GetItemString(obj, \"offsets\");\n\ttitles = PyDict_GetItemString(obj, \"titles\");\n\tif ((n > PyObject_Length(descrs)) ||\t\t\t\\\n\t (offsets && (n > PyObject_Length(offsets))) ||\t\\\n\t (titles && (n > PyObject_Length(titles)))) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"all items in the dictionary must have\" \\\n\t\t\t\t\" the same length.\");\n\t\tgoto fail;\n\t}\n\n\ttotalsize = 0;\n\tfor(i=0; i totalsize) totalsize = offset;\n\t\t}\n\t\telse \n\t\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\n\t\tif (len == 3) PyTuple_SET_ITEM(tup, 2, item);\n\t\tname = PyObject_GetItem(names, index);\n\t\tPy_DECREF(index);\n\n\t\t/* Insert into dictionary */\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) PyDict_SetItem(fields, item, tup);\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n\t\ttotalsize += newdescr->elsize;\n\t\tif (align) {\n\t\t\tint _align = newdescr->alignment;\n\t\t\tif (_align > 1) totalsize =\t\t\t\\\n\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\tmaxalign = MAX(maxalign,_align);\n\t\t}\n\t}\n\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tif (new == NULL) goto fail;\n\tif (maxalign > 1)\n\t\ttotalsize = ((totalsize + maxalign - 1)/maxalign)*maxalign;\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, names);\n\tPy_DECREF(key);\n\tnew->fields = fields;\n\treturn new;\n\n fail:\n\tPy_XDECREF(fields);\n\treturn NULL;\n}\n\n/* \n any object with \n the .fields attribute and/or .itemsize attribute \n (if the .fields attribute does not give\n the total size -- i.e. a partial record naming).\n If itemsize is given it must be >= size computed from fields\n \n The .fields attribute must return a convertible dictionary if \n present. Result inherits from PyArray_VOID.\n*/\n\n\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to NULL\n*/\nstatic int\nPyArray_DescrConverter2(PyObject *obj, PyArray_Descr **at)\n{\n\tif (obj == Py_None) {\n\t\t*at = NULL;\n\t\treturn PY_SUCCEED;\n\t}\n\telse return PyArray_DescrConverter(obj, at);\n}\n\n/* This function takes a Python object representing a type and converts it \n to a the correct PyArray_Descr * structure to describe the type.\n \n Many objects can be used to represent a data-type which in NumPy is\n quite a flexible concept. \n\n This is the central code that converts Python objects to \n Type-descriptor objects that are used throughout numpy.\n */\n\n/* new reference in *at */\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to &LONG_descr\n*/\nstatic int\nPyArray_DescrConverter(PyObject *obj, PyArray_Descr **at)\n{\n char *type;\n int check_num=PyArray_NOTYPE+10;\n\tint len;\n\tPyObject *item;\n\tint elsize = 0;\n\tchar endian = '=';\n\n\t*at=NULL;\n\t\n\t/* default */\n if (obj == Py_None) {\n\t\t*at = PyArray_DescrFromType(PyArray_LONG);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n\tif (PyArray_DescrCheck(obj)) {\n\t\t*at = (PyArray_Descr *)obj;\n\t\tPy_INCREF(*at);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n if (PyType_Check(obj)) {\n\t\tif (PyType_IsSubtype((PyTypeObject *)obj, \n\t\t\t\t &PyGenericArrType_Type)) {\n\t\t\t*at = PyArray_DescrFromTypeObject(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t\telse return PY_FAIL;\n\t\t}\n\t\tcheck_num = PyArray_OBJECT;\n\t\tif (obj == (PyObject *)(&PyInt_Type))\n\t\t\tcheck_num = PyArray_LONG;\n\t\telse if (obj == (PyObject *)(&PyLong_Type))\n\t\t\tcheck_num = PyArray_LONGLONG;\n\t\telse if (obj == (PyObject *)(&PyFloat_Type)) \n\t\t\tcheck_num = PyArray_DOUBLE;\n\t\telse if (obj == (PyObject *)(&PyComplex_Type)) \n\t\t\tcheck_num = PyArray_CDOUBLE;\n\t\telse if (obj == (PyObject *)(&PyBool_Type))\n\t\t\tcheck_num = PyArray_BOOL;\n else if (obj == (PyObject *)(&PyString_Type))\n check_num = PyArray_STRING;\n else if (obj == (PyObject *)(&PyUnicode_Type))\n check_num = PyArray_UNICODE;\n\t\telse if (obj == (PyObject *)(&PyBuffer_Type))\n\t\t\tcheck_num = PyArray_VOID;\n\t\telse {\n\t\t\t*at = _arraydescr_fromobj(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* or a typecode string */\n\n\tif (PyString_Check(obj)) {\n\t\t/* Check for a string typecode. */\n\t\ttype = PyString_AS_STRING(obj);\n\t\tlen = PyString_GET_SIZE(obj);\n\t\tif (len <= 0) goto fail;\n\t\tcheck_num = (int) type[0];\n\t\tif ((char) check_num == '>' || (char) check_num == '<' || \\\n\t\t (char) check_num == '|') {\n\t\t\tif (len <= 1) goto fail;\n\t\t\tendian = (char) check_num;\n\t\t\ttype++; len--;\n\t\t\tcheck_num = (int) type[0];\n\t\t\tif (endian == '|') endian = '=';\n\t\t}\n\t\tif (len > 1) {\n\t\t\telsize = atoi(type+1);\n\t\t\tif (len > 2 && elsize < 10) {\n\t\t\t\t/* perhaps commas present */\n\t\t\t\tint i;\n\t\t\t\tfor (i=1;ielsize == 0) && (elsize != 0)) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->elsize = elsize;\n\t}\n\tif (endian != '=' && PyArray_ISNBO(endian)) endian = '='; \n\t\n\tif (endian != '=' && (*at)->byteorder != '|' &&\t\\\n\t (*at)->byteorder != endian) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->byteorder = endian;\n\t}\n\t\n return PY_SUCCEED;\n\n fail:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"data type not understood\");\n\t*at=NULL;\n\treturn PY_FAIL;\n}\t\n\n/*MULTIARRAY_API\n Convert object to endian\n*/\nstatic int\nPyArray_ByteorderConverter(PyObject *obj, char *endian)\n{\n\tchar *str;\n\t*endian = PyArray_SWAP;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Byteorder string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\t*endian = str[0];\n\tif (str[0] != PyArray_BIG && str[0] != PyArray_LITTLE &&\t\\\n\t str[0] != PyArray_NATIVE) {\n\t\tif (str[0] == 'b' || str[0] == 'B')\n\t\t\t*endian = PyArray_BIG;\n\t\telse if (str[0] == 'l' || str[0] == 'L')\n\t\t\t*endian = PyArray_LITTLE;\n\t\telse if (str[0] == 'n' || str[0] == 'N')\n\t\t\t*endian = PyArray_NATIVE;\n\t\telse if (str[0] == 'i' || str[0] == 'I')\n\t\t\t*endian = PyArray_IGNORE;\n\t\telse if (str[0] == 's' || str[0] == 'S')\n\t\t\t*endian = PyArray_SWAP;\n\t\telse {\n\t\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t\t \"%s is an unrecognized byteorder\",\n\t\t\t\t str);\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Convert object to sort kind \n*/\nstatic int\nPyArray_SortkindConverter(PyObject *obj, PyArray_SORTKIND *sortkind)\n{\n\tchar *str;\n\t*sortkind = PyArray_QUICKSORT;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Sort kind string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\tif (str[0] == 'q' || str[0] == 'Q')\n\t\t*sortkind = PyArray_QUICKSORT;\n\telse if (str[0] == 'h' || str[0] == 'H')\n\t\t*sortkind = PyArray_HEAPSORT;\n\telse if (str[0] == 'm' || str[0] == 'M')\n\t\t*sortkind = PyArray_MERGESORT;\n\telse if (str[0] == 't' || str[0] == 'T')\n\t\t*sortkind = PyArray_TIMSORT;\n\telse {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"%s is an unrecognized kind of sort\",\n\t\t\t str);\n\t\treturn PY_FAIL;\n\t}\n\treturn PY_SUCCEED;\n}\n\n\n/* This function returns true if the two typecodes are \n equivalent (same basic kind and same itemsize).\n*/\n\n/*MULTIARRAY_API*/\nstatic Bool\nPyArray_EquivTypes(PyArray_Descr *typ1, PyArray_Descr *typ2)\n{\n\tregister int typenum1=typ1->type_num;\n\tregister int typenum2=typ2->type_num;\n\tregister int size1=typ1->elsize;\n\tregister int size2=typ2->elsize;\n\n\tif (size1 != size2) return FALSE;\n\tif (typ1->fields != typ2->fields) return FALSE;\n\tif (PyArray_ISNBO(typ1->byteorder) != PyArray_ISNBO(typ2->byteorder))\n\t\treturn FALSE;\n\n\tif (typenum1 == PyArray_VOID || \\\n\t typenum2 == PyArray_VOID) {\n\t\treturn ((typenum1 == typenum2) && \n\t\t\t(typ1->typeobj == typ2->typeobj) &&\n\t\t\t(typ1->fields == typ2->fields));\n\t}\n\treturn (typ1->kind == typ2->kind);\n}\n\n/*** END C-API FUNCTIONS **/\n\n\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_fromobject[] = \"array(object, dtype=None, copy=1, fortran=0, \"\\\n \"subok=0)\\n\"\\\n \"will return a new array formed from the given object type given.\\n\"\\\n \"Object can anything with an __array__ method, or any object\\n\"\\\n \"exposing the array interface, or any (nested) sequence.\\n\"\\\n \"If no type is given, then the type will be determined as the\\n\"\\\n \"minimum type required to hold the objects in the sequence.\\n\"\\\n \"If copy is zero and sequence is already an array with the right \\n\"\\\n \"type, a reference will be returned. If the sequence is an array,\\n\"\\\n \"type can be used only to upcast the array. For downcasting \\n\"\\\n \"use .astype(t) method. If subok is true, then subclasses of the\\n\"\\\n \"array may be returned. Otherwise, a base-class ndarray is returned\";\n\nstatic PyObject *\n_array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n{\n\tPyObject *op, *ret=NULL;\n\tstatic char *kwd[]= {\"object\", \"dtype\", \"copy\", \"fortran\", \"subok\", \n NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tPyArray_Descr *type=NULL;\n\tPyArray_Descr *oldtype=NULL;\n\tBool fortran=FALSE;\n\tint flags=0;\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&\", kwd, &op, \n\t\t\t\t\tPyArray_DescrConverter2,\n &type, \n\t\t\t\t\tPyArray_BoolConverter, ©, \n\t\t\t\t\tPyArray_BoolConverter, &fortran,\n PyArray_BoolConverter, &subok)) \n\t\treturn NULL;\n\n\t/* fast exit if simple call */\n\tif ((PyArray_CheckExact(op) || PyBigArray_CheckExact(op))) {\n\t\tif (type==NULL) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\treturn op;\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn PyArray_NewCopy((PyArrayObject*)op, \n\t\t\t\t\t\t fortran);\n\t\t\t}\n\t\t}\n\t\t/* One more chance */\n\t\toldtype = PyArray_DESCR(op);\n\t\tif (PyArray_EquivTypes(oldtype, type)) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\treturn op;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op,\n\t\t\t\t\t\t fortran);\n\t\t\t\tif (oldtype == type) return ret;\n\t\t\t\tPy_INCREF(oldtype);\n\t\t\t\tPy_DECREF(PyArray_DESCR(ret));\n\t\t\t\tPyArray_DESCR(ret) = oldtype;\n\t\t\t\treturn ret;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (copy) {\n\t\tflags = ENSURECOPY;\n\t}\n\tif (fortran) {\n\t\tflags |= FORTRAN;\n\t}\n if (!subok) {\n flags |= ENSUREARRAY;\n }\n\n\tif ((ret = PyArray_FromAny(op, type, 0, 0, flags)) == NULL) \n\t\treturn NULL;\n\n\treturn ret;\n}\n\n/* accepts NULL type */\n/* steals referenct to type */\n/*MULTIARRAY_API\n Empty\n*/\nstatic PyObject *\nPyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n \n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type, nd, dims, \n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n PyArray_FillObjectArray(ret, Py_None);\n\t}\n\treturn (PyObject *)ret;\n}\n\n\nstatic char doc_empty[] = \"empty((d1,...,dn),dtype=int,fortran=0) will return a new array\\n of shape (d1,...,dn) and given type with all its entries uninitialized. This can be faster than zeros.\";\n\nstatic PyObject *\narray_empty(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter, &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Empty(shape.len, shape.ptr, typecode, fortran); \n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_scalar[] = \"scalar(dtypedescr,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtypedescr must be a valid data-type descriptor. If dtypedescr corresponds to an OBJECT descriptor, then obj can be any object, otherwise obj must be a string. If obj is not given it will be interpreted as None for object type and zeros for all other types.\";\n\nstatic PyObject *\narray_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"dtypedescr\",\"obj\", NULL};\n\tPyArray_Descr *typecode;\n\tPyObject *obj=NULL;\n\tint alloc=0;\n\tvoid *dptr;\n\tPyObject *ret;\n\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|O\",\n\t\t\t\t\t kwlist, &PyArrayDescr_Type, \n\t\t\t\t\t &typecode,\n\t\t\t\t\t &obj)) \n\t\treturn NULL;\n\t\t\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\t\t\\\n\t\t\t\t\"itemsize cannot be zero\");\n\t\treturn NULL;\n\t}\n\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (obj == NULL) obj = Py_None;\n\t\tdptr = &obj;\n\t}\n\telse {\n\t\tif (obj == NULL) {\n\t\t\tdptr = _pya_malloc(typecode->elsize);\n\t\t\tif (dptr == NULL) {\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemset(dptr, '\\0', typecode->elsize);\n\t\t\talloc = 1;\n\t\t}\n\t\telse {\n\t\t\tif (!PyString_Check(obj)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"initializing object must \"\\\n\t\t\t\t\t\t\"be a string\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tif (PyString_GET_SIZE(obj) < typecode->elsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"initialization string is too\"\\\n\t\t\t\t\t\t\" small\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdptr = PyString_AS_STRING(obj);\n\t\t}\n\t}\n\n\tret = PyArray_Scalar(dptr, typecode, NULL);\n\t\n\t/* free dptr which contains zeros */\n\tif (alloc) _pya_free(dptr);\n\treturn ret;\n}\n\n\n/* steal a reference */\n/* accepts NULL type */\n/*MULTIARRAY_API\n Zeros\n*/\nstatic PyObject *\nPyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n\tintp n;\n\n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type,\n\t\t\t\t\t\t nd, dims, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n\t\tPyObject *zero = PyInt_FromLong(0);\n PyArray_FillObjectArray(ret, zero);\n Py_DECREF(zero);\n\t}\n\telse {\n\t\tn = PyArray_NBYTES(ret);\n\t\tmemset(ret->data, 0, n);\n\t}\n\treturn (PyObject *)ret;\n\n}\n\nstatic char doc_zeros[] = \"zeros((d1,...,dn),dtype=int,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.\";\n\n\nstatic PyObject *\narray_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Zeros(shape.len, shape.ptr, typecode, (int) fortran);\n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_set_typeDict[] = \"set_typeDict(dict) set the internal \"\\\n\t\"dictionary that can look up an array type using a registered \"\\\n\t\"code\";\n\nstatic PyObject *\narray_set_typeDict(PyObject *ignored, PyObject *args)\n{\n\tPyObject *dict;\n\tif (!PyArg_ParseTuple(args, \"O\", &dict)) return NULL;\n\tPy_XDECREF(typeDict); /* Decrement old reference (if any)*/\n\ttypeDict = dict;\n\tPy_INCREF(dict); /* Create an internal reference to it */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, intp n)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\n\t\n\tif (dtype == &OBJECT_Descr) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Cannot create an object array from a\"\\\n\t\t\t\t\" string.\");\n\t\tPy_DECREF(dtype);\n\t\treturn NULL;\n\t}\n\t\n\titemsize = dtype->elsize;\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"zero-valued itemsize\");\n\t\tPy_DECREF(dtype);\n\t\treturn NULL;\n\t}\n\t\n\tif (n < 0 ) {\n\t\tif (slen % itemsize != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"string size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\t\tn = slen/itemsize;\n\t} else {\n\t\tif (slen < n*itemsize) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"string is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t dtype,\n\t\t\t\t\t\t\t 1, &n, \n\t\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t\t 0, NULL)) == NULL)\n\t\treturn NULL;\n\t\t\n\tmemcpy(ret->data, data, n*dtype->elsize);\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_fromString[] = \"fromstring(string, dtype=int, count=-1) returns a new 1d array initialized from the raw binary data in string. If count is positive, the new array will have count elements, otherwise it's size is determined by the size of string.\";\n\nstatic PyObject *\narray_fromString(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tchar *data;\n\tlonglong nin=-1;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&L\", kwlist, \n\t\t\t\t\t &data, &s, \n\t\t\t\t\t PyArray_DescrConverter, &descr,\n\t\t\t\t\t &nin)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin);\n}\n\n/* This needs an open file object and reads it in directly. \n memory-mapped files handled differently through buffer interface.\n\nfile pointer number in resulting 1d array \n(can easily reshape later, -1 for to end of file)\ntype of array\nsep is a separator string for character-based data (or NULL for binary)\n \" \" means whitespace\n*/\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep)\n{\n\tPyArrayObject *r;\n\tsize_t nread = 0;\n\tPyArray_ScanFunc *scan;\n\tBool binary;\n\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"0-sized elements.\");\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\n\tif (num == -1 && binary) { /* Get size for binary file*/\n\t\tintp start, numbytes;\n\t\tstart = (intp )ftell(fp);\n\t\tfseek(fp, 0, SEEK_END);\n\t\tnumbytes = (intp )ftell(fp) - start;\n\t\trewind(fp);\n\t\tif (numbytes == -1) {\n\t\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\t\"could not seek in file\");\n\t\t\treturn NULL;\n\t\t}\n\t\tnum = numbytes / typecode->elsize;\n\t}\n\t\n\tif (binary) { /* binary data */\n\t\tr = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t 0, NULL);\n\t\tif (r==NULL) return NULL;\n\t\tnread = fread(r->data, typecode->elsize, num, fp);\n\t}\n\telse { /* character reading */\n\t\tintp i;\n\t\tchar *dptr;\n\t\tint done=0;\n\n\t\tscan = typecode->f->scanfunc;\n\t\tif (scan == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character files with that \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (num != -1) { /* number to read is known */\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode, \n\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\tdptr = r->data;\n\t\t\tfor (i=0; i < num; i++) {\n\t\t\t\tif (done) break;\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\t\t\t\tif (done < -2) break;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\telse { /* we have to watch for the end of the file and \n\t\t\t reallocate at the end */\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * typecode->elsize;\n\t\t\tdptr = r->data;\n\t\t\twhile (!done) {\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\n\t\t\t\t/* end of file reached trying to \n\t\t\t\t scan value. done is 1 or 2\n\t\t\t\t if end of file reached trying to\n\t\t\t\t scan separator. Still good value.\n\t\t\t\t*/\n\t\t\t\tif (done < -2) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t\tif (!done && thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tr->data = PyDataMem_RENEW(r->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = r->data + (totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tr->data = PyDataMem_RENEW(r->data, nread*r->descr->elsize);\n\t\t\tPyArray_DIM(r,0) = nread;\n\t\t\tnum = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\tif (nread < num) {\n\t\tfprintf(stderr, \"%ld items requested but only %ld read\\n\", \n\t\t\t(long) num, (long) nread);\n\t\tr->data = PyDataMem_RENEW(r->data, nread * r->descr->elsize);\n\t\tPyArray_DIM(r,0) = nread;\n\t}\n\treturn (PyObject *)r;\n}\n\nstatic char doc_fromfile[] = \\\n\t\"fromfile(file=, dtype=int, count=-1, sep='')\\n\"\t\\\n\t\"\\n\"\\\n\t\" Return an array of the given data type from a \\n\"\\\n\t\" (text or binary) file. The file argument can be an open file\\n\"\\\n\t\" or a string with the name of a file to read from. If\\n\"\\\n\t\" count==-1, then the entire file is read, otherwise count is\\n\"\\\n\t\" the number of items of the given type read in. If sep is ''\\n\"\\\n\t\" then read a binary file, otherwise it gives the separator\\n\"\\\n\t\" between elements in a text file.\\n\"\\\n\t\"\\n\"\\\n\t\" WARNING: This function should be used sparingly, as it is not\\n\"\\\n\t\" a robust method of persistence. But it can be useful to\\n\"\\\n\t\" read in simply-formatted or binary data quickly.\";\n\nstatic PyObject *\narray_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *file=NULL, *ret;\n\tFILE *fp;\n\tchar *sep=\"\";\n\tchar *mode=NULL;\n\tlonglong nin=-1;\n\tstatic char *kwlist[] = {\"file\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *type=NULL;\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Ls\", kwlist, \n\t\t\t\t\t &file,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\tif (type == NULL) type = PyArray_DescrFromType(PyArray_LONG);\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"rb\";\n\t\telse mode=\"r\";\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), mode);\n\t\tif (file==NULL) return NULL;\n\t}\n\telse {\n\t\tPy_INCREF(file);\n\t}\n\tfp = PyFile_AsFile(file);\n\tif (fp == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\"first argument must be an open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_FromFile(fp, type, (intp) nin, sep);\n\tPy_DECREF(file);\n\treturn ret;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, \n\t\t intp count, intp offset) \n{\n\tPyArrayObject *ret;\n\tchar *data;\n\tint ts;\n\tintp s, n;\n\tint itemsize;\n\tint write=1;\n\n\n\tif (type->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot create an OBJECT array from memory\"\\\n\t\t\t\t\" buffer\");\n\t\tPy_DECREF(type);\n\t\treturn NULL;\n\t}\n\tif (type->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"itemsize cannot be zero in type\");\n\t\tPy_DECREF(type);\n\t\treturn NULL; \t\t\n\t}\n\n\tif (buf->ob_type->tp_as_buffer == NULL || \\\n\t (buf->ob_type->tp_as_buffer->bf_getwritebuffer == NULL &&\t\\\n\t buf->ob_type->tp_as_buffer->bf_getreadbuffer == NULL)) {\n\t\tPyObject *newbuf;\n\t\tnewbuf = PyObject_GetAttrString(buf, \"__buffer__\");\n\t\tif (newbuf == NULL) {Py_DECREF(type); return NULL;}\n\t\tbuf = newbuf;\n\t}\n\telse {Py_INCREF(buf);}\n\n\tif (PyObject_AsWriteBuffer(buf, (void *)&data, &ts)==-1) {\n\t\twrite = 0;\n\t\tPyErr_Clear();\n\t\tif (PyObject_AsReadBuffer(buf, (void *)&data, &ts)==-1) {\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((offset < 0) || (offset >= ts)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"offset must be positive and smaller than %\"\n\t\t\t INTP_FMT, (intp)ts);\n\t}\n\n\tdata += offset;\n\ts = (intp)ts - offset;\n\tn = (intp)count;\n\titemsize = type->elsize;\n\t\n\tif (n < 0 ) {\n\t\tif (s % itemsize != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tn = s/itemsize;\n\t} else {\n\t\tif (s < n*itemsize) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t type, \n\t\t\t\t\t\t\t 1, &n, \n\t\t\t\t\t\t\t NULL, data, \n\t\t\t\t\t\t\t DEFAULT_FLAGS,\n\t\t\t\t\t\t\t NULL)) == NULL) {\n\t\tPy_DECREF(buf);\n\t\treturn NULL;\n\t}\n\t\n\tif (!write) ret->flags &= ~WRITEABLE;\n\n\t/* Store a reference for decref on deallocation */\n\tret->base = buf;\n\tPyArray_UpdateFlags(ret, ALIGNED);\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_frombuffer[] = \\\n\t\"frombuffer(buffer=, dtype=int, count=-1, offset=0)\\n\"\\\n\t\"\\n\"\t\t\t\t\t\t\t\t\\\n\t\" Returns a 1-d array of data type dtype from buffer. The buffer\\n\"\\\n\t\" argument must be an object that exposes the buffer interface.\\n\"\\\n\t\" If count is -1 then the entire buffer is used, otherwise, count\\n\"\\\n\t\" is the size of the output. If offset is given then jump that\\n\"\\\n\t\" far into the buffer. If the buffer has data that is out\\n\" \\\n\t\" not in machine byte-order, than use a propert data type\\n\"\\\n\t\" descriptor. The data will not\\n\" \\\n\t\" be byteswapped, but the array will manage it in future\\n\"\\\n\t\" operations.\\n\";\n\nstatic PyObject *\narray_frombuffer(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *obj=NULL;\n\tlonglong nin=-1, offset=0;\n\tstatic char *kwlist[] = {\"buffer\", \"dtype\", \"count\", \"offset\", NULL};\n\tPyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&LL\", kwlist, \n\t\t\t\t\t &obj,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &offset)) {\n\t\treturn NULL;\n\t}\n\tif (type==NULL)\n\t\ttype = PyArray_DescrFromType(PyArray_LONG);\n\t\n\treturn PyArray_FromBuffer(obj, type, (intp)nin, (intp)offset);\n}\n\n\nstatic char doc_concatenate[] = \"concatenate((a1,a2,...),axis=None).\";\n\nstatic PyObject *\narray_concatenate(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *a0;\n\tint axis=0;\n\tstatic char *kwlist[] = {\"seq\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist,\n\t\t\t\t\t &a0,\n\t\t\t\t\t PyArray_AxisConverter, &axis))\n\t\treturn NULL;\n\treturn PyArray_Concatenate(a0, axis);\n}\n\nstatic char doc_innerproduct[] = \\\n\t\"inner(a,b) returns the dot product of two arrays, which has\\n\"\\\n\t\"shape a.shape[:-1] + b.shape[:-1] with elements computed by\\n\" \\\n\t\"the product of the elements from the last dimensions of a and b.\";\n\nstatic PyObject *array_innerproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *b0, *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a0, &b0)) return NULL;\n\t\n\treturn _ARET(PyArray_InnerProduct(a0, b0));\n}\n\nstatic char doc_matrixproduct[] = \\\n\t\"dot(a,v) returns matrix-multiplication between a and b. \\n\"\\\n\t\"The product-sum is over the last dimension of a and the \\n\"\\\n\t\"second-to-last dimension of b.\";\n\nstatic PyObject *array_matrixproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *v, *a;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a, &v)) return NULL;\n\t\n\treturn _ARET(PyArray_MatrixProduct(a, v));\n}\n\nstatic char doc_fastCopyAndTranspose[] = \"_fastCopyAndTranspose(a)\";\n\nstatic PyObject *array_fastCopyAndTranspose(PyObject *dummy, PyObject *args) {\n\tPyObject *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &a0)) return NULL;\n\t\n\treturn _ARET(PyArray_CopyAndTranspose(a0));\n}\n\nstatic char doc_correlate[] = \"cross_correlate(a,v, mode=0)\";\n\nstatic PyObject *array_correlate(PyObject *dummy, PyObject *args, PyObject *kwds) {\n\tPyObject *shape, *a0;\n\tint mode=0;\n\tstatic char *kwlist[] = {\"a\", \"v\", \"mode\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO|i\", kwlist, \n\t\t\t\t\t &a0, &shape, &mode)) return NULL;\n\t\n\treturn PyArray_Correlate(a0, shape, mode);\n}\n\n\n/*MULTIARRAY_API\n Arange, \n*/\nstatic PyObject *\nPyArray_Arange(double start, double stop, double step, int type_num)\n{\n\tintp length;\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *obj;\n\tint ret;\n\n\tlength = (intp ) ceil((stop - start)/step);\n \n\tif (length <= 0) {\n\t\tlength = 0;\n\t\treturn PyArray_New(&PyArray_Type, 1, &length, type_num,\n\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t}\n\n\trange = PyArray_New(&PyArray_Type, 1, &length, type_num, \n\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (range == NULL) return NULL;\n\n\tfuncs = PyArray_DESCR(range)->f; \n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tobj = PyFloat_FromDouble(start);\n\tret = funcs->setitem(obj, PyArray_DATA(range), (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 1) return range;\n\n\tobj = PyFloat_FromDouble(start + step);\n\tret = funcs->setitem(obj, PyArray_DATA(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 2) return range;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\treturn NULL;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\t\n\treturn range;\n\n fail:\n\tPy_DECREF(range);\n\treturn NULL;\n}\n\n/* the formula is \n len = (intp) ceil((start - stop) / step);\n*/\nstatic intp\n_calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, int cmplx)\n{\n\tintp len;\n\tPyObject *val;\n\tdouble value;\n\t\n\t*next = PyNumber_Subtract(stop, start);\n\tif (!(*next)) return -1;\n\tval = PyNumber_TrueDivide(*next, step);\n\tPy_DECREF(*next); *next=NULL;\n\tif (!val) return -1;\n\tif (cmplx && PyComplex_Check(val)) {\n\t\tvalue = PyComplex_RealAsDouble(val);\n\t\tif (error_converting(value)) {Py_DECREF(val); return -1;}\n\t\tlen = (intp) ceil(value);\n\t\tvalue = PyComplex_ImagAsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = MIN(len, (intp) ceil(value));\n\t}\n\telse {\n\t\tvalue = PyFloat_AsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = (intp) ceil(value);\n\t}\n\t\n\tif (len > 0) {\n\t\t*next = PyNumber_Add(start, step);\n\t\tif (!next) return -1;\n\t}\n\treturn len;\n}\n\n/* this doesn't change the references */\n/*MULTIARRAY_API\n ArangeObj,\n*/\nstatic PyObject *\nPyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr *dtype) \n{\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *next;\n\tintp length;\n\n\tif (!dtype) {\n\t\tPyArray_Descr *deftype;\n\t\tPyArray_Descr *newtype;\n\t\tdeftype = PyArray_DescrFromType(PyArray_LONG);\n\t\tnewtype = PyArray_DescrFromObject(start, deftype);\n\t\tPy_DECREF(deftype);\n\t\tdeftype = newtype;\n\t\tif (stop && stop != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(stop, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tif (step && step != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(step, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tdtype = deftype;\n\t}\n\telse Py_INCREF(dtype);\n\n\tif (!step || step == Py_None) {\n\t\tstep = PyInt_FromLong(1);\n\t}\n\telse Py_XINCREF(step);\n\n\tif (!stop || stop == Py_None) {\n\t\tstop = start;\n\t\tstart = PyInt_FromLong(0);\n\t}\n\telse Py_INCREF(start);\n\n\t/* calculate the length and next = start + step*/\n\tlength = _calc_length(start, stop, step, &next, \n\t\t\t PyTypeNum_ISCOMPLEX(dtype->type_num));\n\n\tif (PyErr_Occurred()) {Py_DECREF(dtype); goto fail;}\n\tif (length <= 0) {\n\t\tlength = 0;\n\t\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\t\tPy_DECREF(step); Py_DECREF(start); return range;\n\t}\n\n\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\tif (range == NULL) goto fail;\n\n\tfuncs = PyArray_DESCR(range)->f;\n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tif (funcs->setitem(start, PyArray_DATA(range), (PyArrayObject *)range) < 0)\n\t\tgoto fail;\n\tif (length == 1) goto finish;\n\tif (funcs->setitem(next, PyArray_DATA(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range) < 0) goto fail;\n\tif (length == 2) goto finish;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\tgoto fail;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\n finish:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_DECREF(next);\n\treturn range;\n\t\n fail:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_XDECREF(next);\n\treturn NULL;\n}\n\n\nstatic char doc_arange[] = \"arange(start, stop=None, step=1, dtype=int)\\n\\n Just like range() except it returns an array whose type can be\\n specified by the keyword argument typecode.\";\n\nstatic PyObject *\narray_arange(PyObject *ignored, PyObject *args, PyObject *kws) {\n\tPyObject *o_start=NULL, *o_stop=NULL, *o_step=NULL;\n\tstatic char *kwd[]= {\"start\", \"stop\", \"step\", \"dtype\", NULL};\n\tPyArray_Descr *typecode=NULL;\n\t\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|OOO&\", kwd, &o_start,\n\t\t\t\t\t&o_stop, &o_step, \n\t\t\t\t\tPyArray_DescrConverter, \n\t\t\t\t\t&typecode)) \n\t\treturn NULL;\n\n\treturn PyArray_ArangeObj(o_start, o_stop, o_step, typecode);\n}\n\n\nstatic char \ndoc_set_string_function[] = \"set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.\";\n\nstatic PyObject *\narray_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *op;\n\tint repr=1;\n\tstatic char *kwlist[] = {\"f\", \"repr\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|i\", kwlist, \n\t\t\t\t\t&op, &repr)) return NULL; \n\tif (!PyCallable_Check(op)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"Argument must be callable.\");\n\t\treturn NULL;\n\t}\n\tPyArray_SetStringFunction(op, repr);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char \ndoc_set_ops_function[] = \"set_numeric_ops(op=func, ...) sets some or all of the number methods for all array objects. Don't forget **dict can be used as the argument list. Returns the functions that were replaced -- can be stored and set later.\";\n\nstatic PyObject *\narray_set_ops_function(PyObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *oldops=NULL;\n\t\n\tif ((oldops = PyArray_GetNumericOps())==NULL) return NULL;\n\n\t/* Should probably ensure that objects are at least callable */\n\t/* Leave this to the caller for now --- error will be raised\n\t later when use is attempted \n\t*/\n\tif (kwds && PyArray_SetNumericOps(kwds) == -1) {\n\t\tPy_DECREF(oldops);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"one or more objects not callable\");\n\t\treturn NULL;\n\t}\n\treturn oldops;\n}\n\n\n/*MULTIARRAY_API\n Where\n*/\nstatic PyObject *\nPyArray_Where(PyObject *condition, PyObject *x, PyObject *y)\n{\n\tPyArrayObject *arr;\n\tPyObject *tup=NULL, *obj=NULL;\n\tPyObject *ret=NULL, *zero=NULL;\n\n\n\tarr = (PyArrayObject *)PyArray_FromAny(condition, NULL, 0, 0, 0);\n\tif (arr == NULL) return NULL;\n\n\tif ((x==NULL) && (y==NULL)) {\n\t\tret = PyArray_Nonzero(arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\n\tif ((x==NULL) || (y==NULL)) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \"either both or neither \"\n\t\t\t\t\"of x and y should be given\");\n\t\treturn NULL;\n\t}\n\n\n\tzero = PyInt_FromLong((long) 0);\n\n\tobj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, \n\t\t\t\t\t\t\t\tn_ops.not_equal));\n\tPy_DECREF(zero);\n\tPy_DECREF(arr);\n\tif (obj == NULL) return NULL;\n\n\ttup = Py_BuildValue(\"(OO)\", y, x);\n\tif (tup == NULL) {Py_DECREF(obj); return NULL;}\n\n\tret = PyArray_Choose((PyAO *)obj, tup);\n\n\tPy_DECREF(obj);\n\tPy_DECREF(tup);\n\treturn ret;\n}\n\nstatic char doc_where[] = \"where(condition, | x, y) is shaped like condition\"\\\n\t\" and has elements of x and y where condition is respectively true or\"\\\n\t\" false. If x or y are not given, then it is equivalent to\"\\\n\t\" nonzero(condition).\";\n\nstatic PyObject *\narray_where(PyObject *ignored, PyObject *args)\n{\n\tPyObject *obj=NULL, *x=NULL, *y=NULL;\n\t\n\tif (!PyArg_ParseTuple(args, \"O|OO\", &obj, &x, &y)) return NULL;\n\n\treturn PyArray_Where(obj, x, y);\n\n}\n\nstatic char doc_lexsort[] = \"lexsort(keys=, axis=-1) returns an array of indexes\"\\\n\t\" similar to argsort except the sorting is done using the provided sorting\"\\\n\t\" keys. First the sort is done using key[0], then the resulting list of\"\\\n\t\" indexes is further manipulated by sorting on key[0]. And so forth\"\\\n\t\" The result is a sort on multiple keys. If the keys represented columns\" \\\n\t\" of a spread-sheet, for example, this would sort using multiple columns.\"\\\n\t\" The keys argument must be a tuple of things that can be converted to \"\\\n\t\" arrays of the same shape.\";\n\nstatic PyObject *\narray_lexsort(PyObject *ignored, PyObject *args, PyObject *kwds)\n{\n\tint axis=-1;\n\tPyObject *obj;\n\tstatic char *kwlist[] = {\"keys\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|i\", kwlist, \n\t\t\t\t\t &PyTuple_Type, &obj, &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_LexSort(obj, axis));\n}\n\n#undef _ARET\n\n\nstatic char doc_register_dtype[] = \\\n\t\"register_dtype(a) registers a new type object -- gives it a typenum\";\n\nstatic PyObject *\narray_register_dtype(PyObject *dummy, PyObject *args)\n{\n\tPyObject *dtype;\n\tint ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &dtype)) return NULL;\n\t\n\tret = PyArray_RegisterDataType((PyTypeObject *)dtype);\n\tif (ret < 0)\n\t\treturn NULL;\n\treturn PyInt_FromLong((long) ret);\n}\n\nstatic char doc_can_cast_safely[] = \\\n\t\"can_cast_safely(from=d1, to=d2) returns True if data type d1 \"\\\n\t\"can be cast to data type d2 without losing precision.\";\n\nstatic PyObject *\narray_can_cast_safely(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *d1=NULL;\n\tPyArray_Descr *d2=NULL;\n\tBool ret;\n\tPyObject *retobj;\n\tstatic char *kwlist[] = {\"from\", \"to\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O&O&\", kwlist, \n\t\t\t\t\tPyArray_DescrConverter, &d1,\n\t\t\t\t\tPyArray_DescrConverter, &d2))\n\t\treturn NULL;\n\tif (d1 == NULL || d2 == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"did not understand one of the types; \"\t\\\n\t\t\t\t\"'None' not accepted\");\n\t\treturn NULL;\n\t}\n\t\t\n\tret = PyArray_CanCastTo(d1, d2);\n\tretobj = (ret ? Py_True : Py_False);\n\tPy_INCREF(retobj);\n\treturn retobj;\n}\n\nstatic char doc_new_buffer[] = \\\n\t\"newbuffer(size) return a new uninitialized buffer object of size \"\n\t\"bytes\";\n\nstatic PyObject *\nnew_buffer(PyObject *dummy, PyObject *args)\n{\n\tint size;\n\n\tif(!PyArg_ParseTuple(args, \"i\", &size))\n\t\treturn NULL;\n\t\n\treturn PyBuffer_New(size);\n}\n\nstatic char doc_buffer_buffer[] = \\\n\t\"getbuffer(obj [,offset[, size]]) create a buffer object from the \"\\\n\t\"given object\\n referencing a slice of length size starting at \"\\\n\t\"offset. Default\\n is the entire buffer. A read-write buffer is \"\\\n\t\"attempted followed by a read-only buffer.\";\n\nstatic PyObject *\nbuffer_buffer(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj;\n\tint offset=0, size=Py_END_OF_BUFFER, n;\n\tvoid *unused;\n\tstatic char *kwlist[] = {\"object\", \"offset\", \"size\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ii\", kwlist, \n\t\t\t\t\t &obj, &offset, &size))\n\t\treturn NULL;\n\n\n\tif (PyObject_AsWriteBuffer(obj, &unused, &n) < 0) {\n\t\tPyErr_Clear();\n\t\treturn PyBuffer_FromObject(obj, offset, size);\t\t\n\t}\n\telse\n\t\treturn PyBuffer_FromReadWriteObject(obj, offset, size);\n}\n\n\nstatic struct PyMethodDef array_module_methods[] = {\n\t{\"set_string_function\", (PyCFunction)array_set_string_function, \n\t METH_VARARGS|METH_KEYWORDS, doc_set_string_function},\n\t{\"set_numeric_ops\", (PyCFunction)array_set_ops_function,\n\t METH_VARARGS|METH_KEYWORDS, doc_set_ops_function},\n\t{\"set_typeDict\", (PyCFunction)array_set_typeDict,\n\t METH_VARARGS, doc_set_typeDict},\n\n\t{\"array\",\t(PyCFunction)_array_fromobject, \n\t METH_VARARGS|METH_KEYWORDS, doc_fromobject},\n\t{\"arange\", (PyCFunction)array_arange, \n\t METH_VARARGS|METH_KEYWORDS, doc_arange},\n\t{\"zeros\",\t(PyCFunction)array_zeros, \n\t METH_VARARGS|METH_KEYWORDS, doc_zeros},\n\t{\"empty\",\t(PyCFunction)array_empty, \n\t METH_VARARGS|METH_KEYWORDS, doc_empty},\n\t{\"scalar\", (PyCFunction)array_scalar,\n\t METH_VARARGS|METH_KEYWORDS, doc_scalar},\n\t{\"where\", (PyCFunction)array_where,\n\t METH_VARARGS, doc_where},\n\t{\"lexsort\", (PyCFunction)array_lexsort,\n\t METH_VARARGS | METH_KEYWORDS, doc_lexsort},\n\t{\"fromstring\",(PyCFunction)array_fromString,\n\t METH_VARARGS|METH_KEYWORDS, doc_fromString},\n\t{\"concatenate\", (PyCFunction)array_concatenate, \n\t METH_VARARGS|METH_KEYWORDS, doc_concatenate},\n\t{\"inner\", (PyCFunction)array_innerproduct, \n\t METH_VARARGS, doc_innerproduct}, \n\t{\"dot\", (PyCFunction)array_matrixproduct, \n\t METH_VARARGS, doc_matrixproduct}, \n\t{\"_fastCopyAndTranspose\", (PyCFunction)array_fastCopyAndTranspose, \n\t METH_VARARGS, doc_fastCopyAndTranspose},\n\t{\"correlate\", (PyCFunction)array_correlate, \n\t METH_VARARGS | METH_KEYWORDS, doc_correlate},\n\t{\"frombuffer\", (PyCFunction)array_frombuffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_frombuffer},\n\t{\"fromfile\", (PyCFunction)array_fromfile,\n\t METH_VARARGS | METH_KEYWORDS, doc_fromfile},\n\t{\"register_dtype\", (PyCFunction)array_register_dtype,\n\t METH_VARARGS, doc_register_dtype},\n\t{\"can_cast\", (PyCFunction)array_can_cast_safely,\n\t METH_VARARGS | METH_KEYWORDS, doc_can_cast_safely},\t\t\n\t{\"newbuffer\", (PyCFunction)new_buffer,\n\t METH_VARARGS, doc_new_buffer},\t\n\t{\"getbuffer\", (PyCFunction)buffer_buffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_buffer_buffer},\t\n\t{NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n#include \"__multiarray_api.c\"\n\n/* Establish scalar-type hierarchy */\n\n/* For dual inheritance we need to make sure that the objects being\n inherited from have the tp->mro object initialized. This is\n not necessarily true for the basic type objects of Python (it is \n checked for single inheritance but not dual in PyType_Ready).\n\n Thus, we call PyType_Ready on the standard Python Types, here.\n*/ \nstatic int\nsetup_scalartypes(PyObject *dict)\n{\n\n\tinitialize_numeric_types();\n\n if (PyType_Ready(&PyBool_Type) < 0) return -1;\n if (PyType_Ready(&PyInt_Type) < 0) return -1;\n if (PyType_Ready(&PyFloat_Type) < 0) return -1;\n if (PyType_Ready(&PyComplex_Type) < 0) return -1;\n if (PyType_Ready(&PyString_Type) < 0) return -1;\n if (PyType_Ready(&PyUnicode_Type) < 0) return -1;\n\n#define SINGLE_INHERIT(child, parent) \\\n Py##child##ArrType_Type.tp_base = &Py##parent##ArrType_Type;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) {\t\t\\\n PyErr_Print(); \\\n PyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1;\t\t\t\t\t\t\\\n }\n \n if (PyType_Ready(&PyGenericArrType_Type) < 0)\n return -1;\n\n SINGLE_INHERIT(Number, Generic);\n SINGLE_INHERIT(Integer, Number);\n SINGLE_INHERIT(Inexact, Number);\n SINGLE_INHERIT(SignedInteger, Integer);\n SINGLE_INHERIT(UnsignedInteger, Integer);\n SINGLE_INHERIT(Floating, Inexact);\n SINGLE_INHERIT(ComplexFloating, Inexact);\n SINGLE_INHERIT(Flexible, Generic);\n SINGLE_INHERIT(Character, Flexible);\n\t\n#define DUAL_INHERIT(child, parent1, parent2) \\\n Py##child##ArrType_Type.tp_base = &Py##parent2##ArrType_Type;\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent2##ArrType_Type,\t\\\n\t\t\t &Py##parent1##_Type);\t\t\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\n\n#define DUAL_INHERIT2(child, parent1, parent2)\t\t\t\t\\\n Py##child##ArrType_Type.tp_base = &Py##parent1##_Type;\t\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent1##_Type,\t\t\\\n\t\t\t &Py##parent2##ArrType_Type);\t\t\\\n\tPy##child##ArrType_Type.tp_richcompare =\t\t\t\\\n\t\tPy##parent1##_Type.tp_richcompare;\t\t\t\\\n\tPy##child##ArrType_Type.tp_compare =\t\t\t\t\\\n\t\tPy##parent1##_Type.tp_compare;\t\t\t\t\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\n\n SINGLE_INHERIT(Bool, Generic);\n SINGLE_INHERIT(Byte, SignedInteger);\n SINGLE_INHERIT(Short, SignedInteger);\n#if SIZEOF_INT == SIZEOF_LONG\n DUAL_INHERIT(Int, Int, SignedInteger);\n#else\n SINGLE_INHERIT(Int, SignedInteger);\n#endif\n DUAL_INHERIT(Long, Int, SignedInteger);\n#if SIZEOF_LONGLONG == SIZEOF_LONG\n DUAL_INHERIT(LongLong, Int, SignedInteger);\n#else\n SINGLE_INHERIT(LongLong, SignedInteger);\n#endif\n\n /* fprintf(stderr, \"tp_free = %p, PyObject_Del = %p, int_tp_free = %p, base.tp_free = %p\\n\", PyIntArrType_Type.tp_free, PyObject_Del, PyInt_Type.tp_free, PySignedIntegerArrType_Type.tp_free);\n\t */\n\tSINGLE_INHERIT(UByte, UnsignedInteger);\n SINGLE_INHERIT(UShort, UnsignedInteger);\n SINGLE_INHERIT(UInt, UnsignedInteger);\n SINGLE_INHERIT(ULong, UnsignedInteger);\n SINGLE_INHERIT(ULongLong, UnsignedInteger);\n\n SINGLE_INHERIT(Float, Floating);\n DUAL_INHERIT(Double, Float, Floating);\n SINGLE_INHERIT(LongDouble, Floating);\n\n SINGLE_INHERIT(CFloat, ComplexFloating);\n DUAL_INHERIT(CDouble, Complex, ComplexFloating);\n SINGLE_INHERIT(CLongDouble, ComplexFloating);\n\n DUAL_INHERIT2(String, String, Character);\n DUAL_INHERIT2(Unicode, Unicode, Character);\n\t\n SINGLE_INHERIT(Void, Flexible);\n \n SINGLE_INHERIT(Object, Generic);\n\n return 0;\n\n#undef SINGLE_INHERIT\n#undef DUAL_INHERIT\n\n\t/* Clean up string and unicode array types so they act more like\n\t strings -- get their tables from the standard types.\n\t*/\n}\n\n/* place a flag dictionary in d */\n\nstatic void\nset_flaginfo(PyObject *d)\n{\n PyObject *s;\n PyObject *newd;\n \n newd = PyDict_New();\n\n PyDict_SetItemString(newd, \"OWNDATA\", s=PyInt_FromLong(OWNDATA));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"FORTRAN\", s=PyInt_FromLong(FORTRAN));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"CONTIGUOUS\", s=PyInt_FromLong(CONTIGUOUS));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"ALIGNED\", s=PyInt_FromLong(ALIGNED));\n Py_DECREF(s);\n\n PyDict_SetItemString(newd, \"UPDATEIFCOPY\", s=PyInt_FromLong(UPDATEIFCOPY));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"WRITEABLE\", s=PyInt_FromLong(WRITEABLE));\n Py_DECREF(s);\n \n PyDict_SetItemString(d, \"_flagdict\", newd);\n Py_DECREF(newd);\n return;\n}\n\n\n/* Initialization function for the module */\n\nDL_EXPORT(void) initmultiarray(void) {\n\tPyObject *m, *d, *s;\n\tPyObject *c_api;\n\t\n\t/* Create the module and add the functions */\n\tm = Py_InitModule(\"multiarray\", array_module_methods);\n\tif (!m) goto err;\n\n\t/* Add some symbolic constants to the module */\n\td = PyModule_GetDict(m);\n\tif (!d) goto err; \n\n\t/* Create the module and add the functions */\n\tif (PyType_Ready(&PyBigArray_Type) < 0) \n\t\treturn;\n\n PyArray_Type.tp_base = &PyBigArray_Type;\n\n PyArray_Type.tp_as_mapping = &array_as_mapping;\n\t/* Even though, this would be inherited, it needs to be set now\n\t so that the __getitem__ will map to the as_mapping descriptor\n\t*/\n PyArray_Type.tp_as_number = &array_as_number; \n\t/* For good measure */\n\tPyArray_Type.tp_as_sequence = &array_as_sequence;\n\tPyArray_Type.tp_as_buffer = &array_as_buffer;\t\n PyArray_Type.tp_flags = (Py_TPFLAGS_DEFAULT \n\t\t\t\t | Py_TPFLAGS_BASETYPE\n\t\t\t\t | Py_TPFLAGS_CHECKTYPES);\n PyArray_Type.tp_doc = Arraytype__doc__;\n\n\tif (PyType_Ready(&PyArray_Type) < 0)\n return;\n\n if (setup_scalartypes(d) < 0) goto err;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMultiIter_Type.tp_iter = PyObject_SelfIter;\n\tif (PyType_Ready(&PyArrayIter_Type) < 0)\n\t\treturn; \n \n\tif (PyType_Ready(&PyArrayMapIter_Type) < 0)\n return; \n\n\tif (PyType_Ready(&PyArrayMultiIter_Type) < 0)\n\t\treturn;\n\n\tif (PyType_Ready(&PyArrayDescr_Type) < 0)\n\t\treturn;\n\n\tc_api = PyCObject_FromVoidPtr((void *)PyArray_API, NULL);\n\tif (PyErr_Occurred()) goto err;\n\tPyDict_SetItemString(d, \"_ARRAY_API\", c_api);\n\tPy_DECREF(c_api);\n\tif (PyErr_Occurred()) goto err;\n\n\tMultiArrayError = PyString_FromString (\"multiarray.error\");\n\tPyDict_SetItemString (d, \"error\", MultiArrayError);\n\t\n\ts = PyString_FromString(\"3.0\");\n\tPyDict_SetItemString(d, \"__version__\", s);\n\tPy_DECREF(s);\n Py_INCREF(&PyBigArray_Type);\n\tPyDict_SetItemString(d, \"bigndarray\", (PyObject *)&PyBigArray_Type);\n Py_INCREF(&PyArray_Type);\n\tPyDict_SetItemString(d, \"ndarray\", (PyObject *)&PyArray_Type);\n Py_INCREF(&PyArrayIter_Type);\n\tPyDict_SetItemString(d, \"flatiter\", (PyObject *)&PyArrayIter_Type);\n Py_INCREF(&PyArrayMultiIter_Type);\n\tPyDict_SetItemString(d, \"broadcast\", \n\t\t\t (PyObject *)&PyArrayMultiIter_Type);\n\tPy_INCREF(&PyArrayDescr_Type);\n\tPyDict_SetItemString(d, \"dtypedescr\", (PyObject *)&PyArrayDescr_Type);\n\n\t/* Doesn't need to be exposed to Python \n Py_INCREF(&PyArrayMapIter_Type);\n\tPyDict_SetItemString(d, \"mapiter\", (PyObject *)&PyArrayMapIter_Type);\n\t*/\n set_flaginfo(d);\n\n\tif (set_typeinfo(d) != 0) goto err;\n\n\t_numpy_internal =\t\t\t\t\t\t\\\n\t\tPyImport_ImportModule(\"numpy.core._internal\");\n\tif (_numpy_internal != NULL) return;\n\n err:\t\n\t/* Check for errors */\n\tif (PyErr_Occurred())\n PyErr_Print();\n\t\tPy_FatalError(\"can't initialize module multiarray\");\n\n\treturn;\n}\n\n", + "methods": [ + { + "name": "_arraydescr_fromobj", + "long_name": "_arraydescr_fromobj( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 15, + "complexity": 3, + "token_count": 67, + "parameters": [ + "obj" + ], + "start_line": 34, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyIntList", + "long_name": "PyArray_MultiplyIntList( register int * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 74, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyList", + "long_name": "PyArray_MultiplyList( register intp * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 85, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPtr", + "long_name": "PyArray_GetPtr( PyArrayObject * obj , register intp * ind)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 61, + "parameters": [ + "obj", + "ind" + ], + "start_line": 96, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AxisConverter", + "long_name": "PyArray_AxisConverter( PyObject * obj , int * axis)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 53, + "parameters": [ + "obj", + "axis" + ], + "start_line": 110, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CompareLists", + "long_name": "PyArray_CompareLists( intp * l1 , intp * l2 , int n)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 3, + "token_count": 51, + "parameters": [ + "l1", + "l2", + "n" + ], + "start_line": 128, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_View", + "long_name": "PyArray_View( PyArrayObject * self , PyArray_Descr * type , PyTypeObject * pytype)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self", + "type", + "pytype" + ], + "start_line": 142, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ravel", + "long_name": "PyArray_Ravel( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 102, + "parameters": [ + "a", + "fortran" + ], + "start_line": 178, + "end_line": 195, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Flatten", + "long_name": "PyArray_Flatten( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 6, + "token_count": 176, + "parameters": [ + "a", + "fortran" + ], + "start_line": 201, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Reshape", + "long_name": "PyArray_Reshape( PyArrayObject * self , PyObject * shape)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "shape" + ], + "start_line": 247, + "end_line": 256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_check_ones", + "long_name": "_check_ones( PyArrayObject * self , int newnd , intp * newdims , intp * strides)", + "filename": "multiarraymodule.c", + "nloc": 25, + "complexity": 12, + "token_count": 189, + "parameters": [ + "self", + "newnd", + "newdims", + "strides" + ], + "start_line": 259, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Newshape", + "long_name": "PyArray_Newshape( PyArrayObject * self , PyArray_Dims * newdims)", + "filename": "multiarraymodule.c", + "nloc": 72, + "complexity": 17, + "token_count": 409, + "parameters": [ + "self", + "newdims" + ], + "start_line": 296, + "end_line": 383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Squeeze", + "long_name": "PyArray_Squeeze( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 34, + "complexity": 5, + "token_count": 204, + "parameters": [ + "self" + ], + "start_line": 392, + "end_line": 427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Mean", + "long_name": "PyArray_Mean( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 19, + "complexity": 4, + "token_count": 139, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 434, + "end_line": 455, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Std", + "long_name": "PyArray_Std( PyArrayObject * self , int axis , int rtype , int variance)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 13, + "token_count": 450, + "parameters": [ + "self", + "axis", + "rtype", + "variance" + ], + "start_line": 462, + "end_line": 521, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sum", + "long_name": "PyArray_Sum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 528, + "end_line": 538, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Prod", + "long_name": "PyArray_Prod( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 544, + "end_line": 554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CumSum", + "long_name": "PyArray_CumSum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 560, + "end_line": 570, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CumProd", + "long_name": "PyArray_CumProd( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 576, + "end_line": 587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Any", + "long_name": "PyArray_Any( PyArrayObject * self , int axis)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "axis" + ], + "start_line": 593, + "end_line": 604, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_All", + "long_name": "PyArray_All( PyArrayObject * self , int axis)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "axis" + ], + "start_line": 610, + "end_line": 621, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Compress", + "long_name": "PyArray_Compress( PyArrayObject * self , PyObject * condition , int axis)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 3, + "token_count": 110, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 628, + "end_line": 648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Nonzero", + "long_name": "PyArray_Nonzero( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 13, + "token_count": 414, + "parameters": [ + "self" + ], + "start_line": 654, + "end_line": 713, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Clip", + "long_name": "PyArray_Clip( PyArrayObject * self , PyObject * min , PyObject * max)", + "filename": "multiarraymodule.c", + "nloc": 28, + "complexity": 6, + "token_count": 237, + "parameters": [ + "self", + "min", + "max" + ], + "start_line": 719, + "end_line": 749, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Conjugate", + "long_name": "PyArray_Conjugate( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 9, + "token_count": 228, + "parameters": [ + "self" + ], + "start_line": 755, + "end_line": 791, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Trace", + "long_name": "PyArray_Trace( PyArrayObject * self , int offset , int axis1 , int axis2 , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 81, + "parameters": [ + "self", + "offset", + "axis1", + "axis2", + "rtype" + ], + "start_line": 797, + "end_line": 807, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Diagonal", + "long_name": "PyArray_Diagonal( PyArrayObject * self , int offset , int axis1 , int axis2)", + "filename": "multiarraymodule.c", + "nloc": 104, + "complexity": 23, + "token_count": 774, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 813, + "end_line": 932, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AsCArray", + "long_name": "PyArray_AsCArray( PyObject ** op , * ptr , intp * dims , int nd , PyArray_Descr * typedescr)", + "filename": "multiarraymodule.c", + "nloc": 50, + "complexity": 12, + "token_count": 400, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 948, + "end_line": 999, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As1D", + "long_name": "PyArray_As1D( PyObject ** op , char ** ptr , int * d1 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 71, + "parameters": [ + "op", + "ptr", + "d1", + "typecode" + ], + "start_line": 1007, + "end_line": 1017, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As2D", + "long_name": "PyArray_As2D( PyObject ** op , char ** * ptr , int * d1 , int * d2 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 92, + "parameters": [ + "op", + "ptr", + "d1", + "d2", + "typecode" + ], + "start_line": 1023, + "end_line": 1035, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Free", + "long_name": "PyArray_Free( PyObject * op , * ptr)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 4, + "token_count": 67, + "parameters": [ + "op", + "ptr" + ], + "start_line": 1043, + "end_line": 1054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "_swap_and_concat", + "long_name": "_swap_and_concat( PyObject * op , int axis , int n)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 6, + "token_count": 185, + "parameters": [ + "op", + "axis", + "n" + ], + "start_line": 1058, + "end_line": 1086, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Concatenate", + "long_name": "PyArray_Concatenate( PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 92, + "complexity": 20, + "token_count": 617, + "parameters": [ + "op", + "axis" + ], + "start_line": 1098, + "end_line": 1202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 105, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SwapAxes", + "long_name": "PyArray_SwapAxes( PyArrayObject * ap , int a1 , int a2)", + "filename": "multiarraymodule.c", + "nloc": 38, + "complexity": 12, + "token_count": 227, + "parameters": [ + "ap", + "a1", + "a2" + ], + "start_line": 1208, + "end_line": 1249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Transpose", + "long_name": "PyArray_Transpose( PyArrayObject * ap , PyArray_Dims * permute)", + "filename": "multiarraymodule.c", + "nloc": 46, + "complexity": 10, + "token_count": 309, + "parameters": [ + "ap", + "permute" + ], + "start_line": 1255, + "end_line": 1308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Repeat", + "long_name": "PyArray_Repeat( PyArrayObject * aop , PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 78, + "complexity": 15, + "token_count": 523, + "parameters": [ + "aop", + "op", + "axis" + ], + "start_line": 1314, + "end_line": 1409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 63, + "complexity": 13, + "token_count": 427, + "parameters": [ + "op", + "retn" + ], + "start_line": 1413, + "end_line": 1482, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Choose", + "long_name": "PyArray_Choose( PyArrayObject * ip , PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 15, + "token_count": 518, + "parameters": [ + "ip", + "op" + ], + "start_line": 1489, + "end_line": 1570, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 82, + "top_nesting_level": 0 + }, + { + "name": "_strided_copy", + "long_name": "_strided_copy( char * dst , intp dststride , char * src , intp srcstride , intp num , int elsize)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 48, + "parameters": [ + "dst", + "dststride", + "src", + "srcstride", + "num", + "elsize" + ], + "start_line": 1573, + "end_line": 1580, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "_new_sort", + "long_name": "_new_sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 8, + "token_count": 284, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1591, + "end_line": 1645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "_new_argsort", + "long_name": "_new_argsort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 67, + "complexity": 13, + "token_count": 498, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1648, + "end_line": 1726, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "qsortCompare", + "long_name": "qsortCompare( const * a , const * b)", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "a", + "b" + ], + "start_line": 1734, + "end_line": 1737, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sort", + "long_name": "PyArray_Sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 52, + "complexity": 14, + "token_count": 353, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1792, + "end_line": 1858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "argsort_static_compare", + "long_name": "argsort_static_compare( const * ip1 , const * ip2)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 1, + "token_count": 67, + "parameters": [ + "ip1", + "ip2" + ], + "start_line": 1864, + "end_line": 1872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgSort", + "long_name": "PyArray_ArgSort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 15, + "token_count": 493, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1878, + "end_line": 1958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_LexSort", + "long_name": "PyArray_LexSort( PyObject * sort_keys , int axis)", + "filename": "multiarraymodule.c", + "nloc": 132, + "complexity": 36, + "token_count": 1162, + "parameters": [ + "sort_keys", + "axis" + ], + "start_line": 1970, + "end_line": 2114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 145, + "top_nesting_level": 0 + }, + { + "name": "local_where", + "long_name": "local_where( PyArrayObject * ap1 , PyArrayObject * ap2 , PyArrayObject * ret)", + "filename": "multiarraymodule.c", + "nloc": 35, + "complexity": 7, + "token_count": 243, + "parameters": [ + "ap1", + "ap2", + "ret" + ], + "start_line": 2118, + "end_line": 2153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SearchSorted", + "long_name": "PyArray_SearchSorted( PyArrayObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 5, + "token_count": 231, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2159, + "end_line": 2204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 82, + "complexity": 17, + "token_count": 659, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2215, + "end_line": 2317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 102, + "complexity": 20, + "token_count": 804, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2325, + "end_line": 2452, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 128, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 284, + "parameters": [ + "op" + ], + "start_line": 2458, + "end_line": 2512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Correlate", + "long_name": "PyArray_Correlate( PyObject * op1 , PyObject * op2 , int mode)", + "filename": "multiarraymodule.c", + "nloc": 95, + "complexity": 15, + "token_count": 674, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2518, + "end_line": 2625, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgMin", + "long_name": "PyArray_ArgMin( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 5, + "token_count": 141, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2632, + "end_line": 2656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Max", + "long_name": "PyArray_Max( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 71, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2662, + "end_line": 2673, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Min", + "long_name": "PyArray_Min( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 71, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2679, + "end_line": 2690, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ptp", + "long_name": "PyArray_Ptp( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 4, + "token_count": 138, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2696, + "end_line": 2719, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgMax", + "long_name": "PyArray_ArgMax( PyArrayObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 7, + "token_count": 326, + "parameters": [ + "op", + "axis" + ], + "start_line": 2726, + "end_line": 2783, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Take", + "long_name": "PyArray_Take( PyArrayObject * self0 , PyObject * indices0 , int axis)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 473, + "parameters": [ + "self0", + "indices0", + "axis" + ], + "start_line": 2790, + "end_line": 2865, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Put", + "long_name": "PyArray_Put( PyArrayObject * self , PyObject * values0 , PyObject * indices0)", + "filename": "multiarraymodule.c", + "nloc": 63, + "complexity": 15, + "token_count": 465, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 2871, + "end_line": 2940, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PutMask", + "long_name": "PyArray_PutMask( PyArrayObject * self , PyObject * values0 , PyObject * mask0)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 422, + "parameters": [ + "self", + "values0", + "mask0" + ], + "start_line": 2946, + "end_line": 3017, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Converter", + "long_name": "PyArray_Converter( PyObject * object , PyObject ** address)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 66, + "parameters": [ + "object", + "address" + ], + "start_line": 3033, + "end_line": 3045, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BoolConverter", + "long_name": "PyArray_BoolConverter( PyObject * object , Bool * val)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "object", + "val" + ], + "start_line": 3051, + "end_line": 3059, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_TypestrConvert", + "long_name": "PyArray_TypestrConvert( int itemsize , int gentype)", + "filename": "multiarraymodule.c", + "nloc": 96, + "complexity": 35, + "token_count": 308, + "parameters": [ + "itemsize", + "gentype" + ], + "start_line": 3066, + "end_line": 3181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BufferConverter", + "long_name": "PyArray_BufferConverter( PyObject * obj , PyArray_Chunk * buf)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 6, + "token_count": 147, + "parameters": [ + "obj", + "buf" + ], + "start_line": 3199, + "end_line": 3224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpConverter", + "long_name": "PyArray_IntpConverter( PyObject * obj , PyArray_Dims * seq)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 10, + "token_count": 189, + "parameters": [ + "obj", + "seq" + ], + "start_line": 3239, + "end_line": 3275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "_use_inherit", + "long_name": "_use_inherit( PyArray_Descr * type , PyObject * newobj , int * errflag)", + "filename": "multiarraymodule.c", + "nloc": 32, + "complexity": 7, + "token_count": 161, + "parameters": [ + "type", + "newobj", + "errflag" + ], + "start_line": 3293, + "end_line": 3326, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_tuple", + "long_name": "_convert_from_tuple( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 57, + "complexity": 11, + "token_count": 335, + "parameters": [ + "obj" + ], + "start_line": 3329, + "end_line": 3397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 69, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 60, + "complexity": 11, + "token_count": 395, + "parameters": [ + "obj" + ], + "start_line": 3405, + "end_line": 3467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 62, + "complexity": 11, + "token_count": 392, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3478, + "end_line": 3541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_commastring", + "long_name": "_convert_from_commastring( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 92, + "parameters": [ + "obj", + "align" + ], + "start_line": 3554, + "end_line": 3570, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_use_fields_dict", + "long_name": "_use_fields_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 1, + "token_count": 29, + "parameters": [ + "obj", + "align" + ], + "start_line": 3607, + "end_line": 3612, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_dict", + "long_name": "_convert_from_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 93, + "complexity": 25, + "token_count": 641, + "parameters": [ + "obj", + "align" + ], + "start_line": 3615, + "end_line": 3717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter2", + "long_name": "PyArray_DescrConverter2( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 37, + "parameters": [ + "obj", + "at" + ], + "start_line": 3735, + "end_line": 3742, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter", + "long_name": "PyArray_DescrConverter( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 148, + "complexity": 58, + "token_count": 921, + "parameters": [ + "obj", + "at" + ], + "start_line": 3759, + "end_line": 3941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 183, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ByteorderConverter", + "long_name": "PyArray_ByteorderConverter( PyObject * obj , char * endian)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 16, + "token_count": 218, + "parameters": [ + "obj", + "endian" + ], + "start_line": 3947, + "end_line": 3979, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SortkindConverter", + "long_name": "PyArray_SortkindConverter( PyObject * obj , PyArray_SORTKIND * sortkind)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 11, + "token_count": 162, + "parameters": [ + "obj", + "sortkind" + ], + "start_line": 3985, + "end_line": 4011, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EquivTypes", + "long_name": "PyArray_EquivTypes( PyArray_Descr * typ1 , PyArray_Descr * typ2)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 8, + "token_count": 138, + "parameters": [ + "typ1", + "typ2" + ], + "start_line": 4020, + "end_line": 4039, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 59, + "complexity": 15, + "token_count": 325, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4060, + "end_line": 4125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Empty", + "long_name": "PyArray_Empty( int nd , intp * dims , PyArray_Descr * type , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 14, + "complexity": 4, + "token_count": 96, + "parameters": [ + "nd", + "dims", + "type", + "fortran" + ], + "start_line": 4133, + "end_line": 4148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_empty", + "long_name": "array_empty( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 2, + "token_count": 130, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4154, + "end_line": 4178, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_scalar", + "long_name": "array_scalar( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 10, + "token_count": 254, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4183, + "end_line": 4241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zeros", + "long_name": "PyArray_Zeros( int nd , intp * dims , PyArray_Descr * type , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 4, + "token_count": 134, + "parameters": [ + "nd", + "dims", + "type", + "fortran" + ], + "start_line": 4250, + "end_line": 4274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_zeros", + "long_name": "array_zeros( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 2, + "token_count": 133, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4280, + "end_line": 4304, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_set_typeDict", + "long_name": "array_set_typeDict( PyObject * ignored , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "ignored", + "args" + ], + "start_line": 4311, + "end_line": 4320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n)", + "filename": "multiarraymodule.c", + "nloc": 46, + "complexity": 8, + "token_count": 222, + "parameters": [ + "data", + "slen", + "dtype", + "n" + ], + "start_line": 4325, + "end_line": 4376, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 15, + "complexity": 2, + "token_count": 103, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4381, + "end_line": 4397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 111, + "complexity": 22, + "token_count": 649, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4411, + "end_line": 4536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_fromfile", + "long_name": "array_fromfile( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 7, + "token_count": 225, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4554, + "end_line": 4592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromBuffer", + "long_name": "PyArray_FromBuffer( PyObject * buf , PyArray_Descr * type , intp count , intp offset)", + "filename": "multiarraymodule.c", + "nloc": 83, + "complexity": 16, + "token_count": 446, + "parameters": [ + "buf", + "type", + "count", + "offset" + ], + "start_line": 4596, + "end_line": 4689, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "array_frombuffer", + "long_name": "array_frombuffer( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 121, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4705, + "end_line": 4722, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_concatenate", + "long_name": "array_concatenate( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 73, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 4728, + "end_line": 4739, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_innerproduct", + "long_name": "array_innerproduct( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 5, + "complexity": 2, + "token_count": 49, + "parameters": [ + "dummy", + "args" + ], + "start_line": 4746, + "end_line": 4752, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_matrixproduct", + "long_name": "array_matrixproduct( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 5, + "complexity": 2, + "token_count": 49, + "parameters": [ + "dummy", + "args" + ], + "start_line": 4759, + "end_line": 4765, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_fastCopyAndTranspose", + "long_name": "array_fastCopyAndTranspose( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 5, + "complexity": 2, + "token_count": 41, + "parameters": [ + "dummy", + "args" + ], + "start_line": 4769, + "end_line": 4775, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_correlate", + "long_name": "array_correlate( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 4779, + "end_line": 4788, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Arange", + "long_name": "PyArray_Arange( double start , double stop , double step , int type_num)", + "filename": "multiarraymodule.c", + "nloc": 40, + "complexity": 9, + "token_count": 300, + "parameters": [ + "start", + "stop", + "step", + "type_num" + ], + "start_line": 4795, + "end_line": 4846, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "_calc_length", + "long_name": "_calc_length( PyObject * start , PyObject * stop , PyObject * step , PyObject ** next , int cmplx)", + "filename": "multiarraymodule.c", + "nloc": 31, + "complexity": 10, + "token_count": 235, + "parameters": [ + "start", + "stop", + "step", + "next", + "cmplx" + ], + "start_line": 4852, + "end_line": 4884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArangeObj", + "long_name": "PyArray_ArangeObj( PyObject * start , PyObject * stop , PyObject * step , PyArray_Descr * dtype)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 19, + "token_count": 461, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 4891, + "end_line": 4975, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "array_arange", + "long_name": "array_arange( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 100, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4981, + "end_line": 4993, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_set_string_function", + "long_name": "array_set_string_function( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 98, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5000, + "end_line": 5016, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "array_set_ops_function", + "long_name": "array_set_ops_function( PyObject * self , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 5022, + "end_line": 5039, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Where", + "long_name": "PyArray_Where( PyObject * condition , PyObject * x , PyObject * y)", + "filename": "multiarraymodule.c", + "nloc": 31, + "complexity": 8, + "token_count": 231, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5046, + "end_line": 5086, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_where", + "long_name": "array_where( PyObject * ignored , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 60, + "parameters": [ + "ignored", + "args" + ], + "start_line": 5094, + "end_line": 5102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_lexsort", + "long_name": "array_lexsort( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 5114, + "end_line": 5124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_register_dtype", + "long_name": "array_register_dtype( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 3, + "token_count": 64, + "parameters": [ + "dummy", + "args" + ], + "start_line": 5133, + "end_line": 5144, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_can_cast_safely", + "long_name": "array_can_cast_safely( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 5, + "token_count": 128, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5151, + "end_line": 5174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "new_buffer", + "long_name": "new_buffer( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 7, + "complexity": 2, + "token_count": 37, + "parameters": [ + "dummy", + "args" + ], + "start_line": 5181, + "end_line": 5189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "buffer_buffer", + "long_name": "buffer_buffer( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 120, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5198, + "end_line": 5216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "setup_scalartypes", + "long_name": "setup_scalartypes( PyObject * dict)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 10, + "token_count": 351, + "parameters": [ + "dict" + ], + "start_line": 5280, + "end_line": 5393, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 114, + "top_nesting_level": 0 + }, + { + "name": "set_flaginfo", + "long_name": "set_flaginfo( PyObject * d)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 1, + "token_count": 152, + "parameters": [ + "d" + ], + "start_line": 5398, + "end_line": 5422, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "initmultiarray", + "long_name": "initmultiarray()", + "filename": "multiarraymodule.c", + "nloc": 63, + "complexity": 15, + "token_count": 434, + "parameters": [], + "start_line": 5427, + "end_line": 5520, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "_arraydescr_fromobj", + "long_name": "_arraydescr_fromobj( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 15, + "complexity": 3, + "token_count": 67, + "parameters": [ + "obj" + ], + "start_line": 34, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyIntList", + "long_name": "PyArray_MultiplyIntList( register int * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 74, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyList", + "long_name": "PyArray_MultiplyList( register intp * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 85, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPtr", + "long_name": "PyArray_GetPtr( PyArrayObject * obj , register intp * ind)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 61, + "parameters": [ + "obj", + "ind" + ], + "start_line": 96, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AxisConverter", + "long_name": "PyArray_AxisConverter( PyObject * obj , int * axis)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 53, + "parameters": [ + "obj", + "axis" + ], + "start_line": 110, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CompareLists", + "long_name": "PyArray_CompareLists( intp * l1 , intp * l2 , int n)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 3, + "token_count": 51, + "parameters": [ + "l1", + "l2", + "n" + ], + "start_line": 128, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_View", + "long_name": "PyArray_View( PyArrayObject * self , PyArray_Descr * type , PyTypeObject * pytype)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self", + "type", + "pytype" + ], + "start_line": 142, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ravel", + "long_name": "PyArray_Ravel( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 102, + "parameters": [ + "a", + "fortran" + ], + "start_line": 178, + "end_line": 195, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Flatten", + "long_name": "PyArray_Flatten( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 6, + "token_count": 176, + "parameters": [ + "a", + "fortran" + ], + "start_line": 201, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Reshape", + "long_name": "PyArray_Reshape( PyArrayObject * self , PyObject * shape)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "shape" + ], + "start_line": 247, + "end_line": 256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_check_ones", + "long_name": "_check_ones( PyArrayObject * self , int newnd , intp * newdims , intp * strides)", + "filename": "multiarraymodule.c", + "nloc": 25, + "complexity": 12, + "token_count": 189, + "parameters": [ + "self", + "newnd", + "newdims", + "strides" + ], + "start_line": 259, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Newshape", + "long_name": "PyArray_Newshape( PyArrayObject * self , PyArray_Dims * newdims)", + "filename": "multiarraymodule.c", + "nloc": 72, + "complexity": 17, + "token_count": 409, + "parameters": [ + "self", + "newdims" + ], + "start_line": 296, + "end_line": 383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Squeeze", + "long_name": "PyArray_Squeeze( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 34, + "complexity": 5, + "token_count": 204, + "parameters": [ + "self" + ], + "start_line": 392, + "end_line": 427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Mean", + "long_name": "PyArray_Mean( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 19, + "complexity": 4, + "token_count": 139, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 434, + "end_line": 455, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Std", + "long_name": "PyArray_Std( PyArrayObject * self , int axis , int rtype , int variance)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 13, + "token_count": 450, + "parameters": [ + "self", + "axis", + "rtype", + "variance" + ], + "start_line": 462, + "end_line": 521, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sum", + "long_name": "PyArray_Sum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 528, + "end_line": 538, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Prod", + "long_name": "PyArray_Prod( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 544, + "end_line": 554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CumSum", + "long_name": "PyArray_CumSum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 560, + "end_line": 570, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CumProd", + "long_name": "PyArray_CumProd( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 576, + "end_line": 587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Any", + "long_name": "PyArray_Any( PyArrayObject * self , int axis)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "axis" + ], + "start_line": 593, + "end_line": 604, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_All", + "long_name": "PyArray_All( PyArrayObject * self , int axis)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "axis" + ], + "start_line": 610, + "end_line": 621, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Compress", + "long_name": "PyArray_Compress( PyArrayObject * self , PyObject * condition , int axis)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 3, + "token_count": 110, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 628, + "end_line": 648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Nonzero", + "long_name": "PyArray_Nonzero( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 13, + "token_count": 414, + "parameters": [ + "self" + ], + "start_line": 654, + "end_line": 713, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Clip", + "long_name": "PyArray_Clip( PyArrayObject * self , PyObject * min , PyObject * max)", + "filename": "multiarraymodule.c", + "nloc": 28, + "complexity": 6, + "token_count": 237, + "parameters": [ + "self", + "min", + "max" + ], + "start_line": 719, + "end_line": 749, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Conjugate", + "long_name": "PyArray_Conjugate( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 9, + "token_count": 228, + "parameters": [ + "self" + ], + "start_line": 755, + "end_line": 791, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Trace", + "long_name": "PyArray_Trace( PyArrayObject * self , int offset , int axis1 , int axis2 , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 81, + "parameters": [ + "self", + "offset", + "axis1", + "axis2", + "rtype" + ], + "start_line": 797, + "end_line": 807, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Diagonal", + "long_name": "PyArray_Diagonal( PyArrayObject * self , int offset , int axis1 , int axis2)", + "filename": "multiarraymodule.c", + "nloc": 104, + "complexity": 23, + "token_count": 774, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 813, + "end_line": 932, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AsCArray", + "long_name": "PyArray_AsCArray( PyObject ** op , * ptr , intp * dims , int nd , PyArray_Descr * typedescr)", + "filename": "multiarraymodule.c", + "nloc": 50, + "complexity": 12, + "token_count": 400, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 948, + "end_line": 999, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As1D", + "long_name": "PyArray_As1D( PyObject ** op , char ** ptr , int * d1 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 71, + "parameters": [ + "op", + "ptr", + "d1", + "typecode" + ], + "start_line": 1007, + "end_line": 1017, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As2D", + "long_name": "PyArray_As2D( PyObject ** op , char ** * ptr , int * d1 , int * d2 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 92, + "parameters": [ + "op", + "ptr", + "d1", + "d2", + "typecode" + ], + "start_line": 1023, + "end_line": 1035, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Free", + "long_name": "PyArray_Free( PyObject * op , * ptr)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 4, + "token_count": 67, + "parameters": [ + "op", + "ptr" + ], + "start_line": 1043, + "end_line": 1054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "_swap_and_concat", + "long_name": "_swap_and_concat( PyObject * op , int axis , int n)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 6, + "token_count": 185, + "parameters": [ + "op", + "axis", + "n" + ], + "start_line": 1058, + "end_line": 1086, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Concatenate", + "long_name": "PyArray_Concatenate( PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 92, + "complexity": 20, + "token_count": 617, + "parameters": [ + "op", + "axis" + ], + "start_line": 1098, + "end_line": 1202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 105, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SwapAxes", + "long_name": "PyArray_SwapAxes( PyArrayObject * ap , int a1 , int a2)", + "filename": "multiarraymodule.c", + "nloc": 38, + "complexity": 12, + "token_count": 227, + "parameters": [ + "ap", + "a1", + "a2" + ], + "start_line": 1208, + "end_line": 1249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Transpose", + "long_name": "PyArray_Transpose( PyArrayObject * ap , PyArray_Dims * permute)", + "filename": "multiarraymodule.c", + "nloc": 46, + "complexity": 10, + "token_count": 309, + "parameters": [ + "ap", + "permute" + ], + "start_line": 1255, + "end_line": 1308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Repeat", + "long_name": "PyArray_Repeat( PyArrayObject * aop , PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 78, + "complexity": 15, + "token_count": 523, + "parameters": [ + "aop", + "op", + "axis" + ], + "start_line": 1314, + "end_line": 1409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 63, + "complexity": 13, + "token_count": 427, + "parameters": [ + "op", + "retn" + ], + "start_line": 1413, + "end_line": 1482, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Choose", + "long_name": "PyArray_Choose( PyArrayObject * ip , PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 15, + "token_count": 518, + "parameters": [ + "ip", + "op" + ], + "start_line": 1489, + "end_line": 1570, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 82, + "top_nesting_level": 0 + }, + { + "name": "_strided_copy", + "long_name": "_strided_copy( char * dst , intp dststride , char * src , intp srcstride , intp num , int elsize)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 48, + "parameters": [ + "dst", + "dststride", + "src", + "srcstride", + "num", + "elsize" + ], + "start_line": 1573, + "end_line": 1580, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "_new_sort", + "long_name": "_new_sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 8, + "token_count": 284, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1591, + "end_line": 1645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "_new_argsort", + "long_name": "_new_argsort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 67, + "complexity": 13, + "token_count": 498, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1648, + "end_line": 1726, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "qsortCompare", + "long_name": "qsortCompare( const * a , const * b)", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "a", + "b" + ], + "start_line": 1734, + "end_line": 1737, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sort", + "long_name": "PyArray_Sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 52, + "complexity": 14, + "token_count": 353, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1792, + "end_line": 1858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "argsort_static_compare", + "long_name": "argsort_static_compare( const * ip1 , const * ip2)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 1, + "token_count": 67, + "parameters": [ + "ip1", + "ip2" + ], + "start_line": 1864, + "end_line": 1872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgSort", + "long_name": "PyArray_ArgSort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 15, + "token_count": 493, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1878, + "end_line": 1958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_LexSort", + "long_name": "PyArray_LexSort( PyObject * sort_keys , int axis)", + "filename": "multiarraymodule.c", + "nloc": 132, + "complexity": 36, + "token_count": 1162, + "parameters": [ + "sort_keys", + "axis" + ], + "start_line": 1970, + "end_line": 2114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 145, + "top_nesting_level": 0 + }, + { + "name": "local_where", + "long_name": "local_where( PyArrayObject * ap1 , PyArrayObject * ap2 , PyArrayObject * ret)", + "filename": "multiarraymodule.c", + "nloc": 35, + "complexity": 7, + "token_count": 243, + "parameters": [ + "ap1", + "ap2", + "ret" + ], + "start_line": 2118, + "end_line": 2153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SearchSorted", + "long_name": "PyArray_SearchSorted( PyArrayObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 5, + "token_count": 231, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2159, + "end_line": 2204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 82, + "complexity": 17, + "token_count": 659, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2215, + "end_line": 2317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 102, + "complexity": 20, + "token_count": 804, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2325, + "end_line": 2452, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 128, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 284, + "parameters": [ + "op" + ], + "start_line": 2458, + "end_line": 2512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Correlate", + "long_name": "PyArray_Correlate( PyObject * op1 , PyObject * op2 , int mode)", + "filename": "multiarraymodule.c", + "nloc": 95, + "complexity": 15, + "token_count": 674, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2518, + "end_line": 2625, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgMin", + "long_name": "PyArray_ArgMin( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 5, + "token_count": 141, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2632, + "end_line": 2656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Max", + "long_name": "PyArray_Max( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 71, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2662, + "end_line": 2673, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Min", + "long_name": "PyArray_Min( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 71, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2679, + "end_line": 2690, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ptp", + "long_name": "PyArray_Ptp( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 4, + "token_count": 138, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2696, + "end_line": 2719, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgMax", + "long_name": "PyArray_ArgMax( PyArrayObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 7, + "token_count": 326, + "parameters": [ + "op", + "axis" + ], + "start_line": 2726, + "end_line": 2783, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Take", + "long_name": "PyArray_Take( PyArrayObject * self0 , PyObject * indices0 , int axis)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 473, + "parameters": [ + "self0", + "indices0", + "axis" + ], + "start_line": 2790, + "end_line": 2865, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Put", + "long_name": "PyArray_Put( PyArrayObject * self , PyObject * values0 , PyObject * indices0)", + "filename": "multiarraymodule.c", + "nloc": 63, + "complexity": 15, + "token_count": 465, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 2871, + "end_line": 2940, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PutMask", + "long_name": "PyArray_PutMask( PyArrayObject * self , PyObject * values0 , PyObject * mask0)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 422, + "parameters": [ + "self", + "values0", + "mask0" + ], + "start_line": 2946, + "end_line": 3017, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Converter", + "long_name": "PyArray_Converter( PyObject * object , PyObject ** address)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 66, + "parameters": [ + "object", + "address" + ], + "start_line": 3033, + "end_line": 3045, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BoolConverter", + "long_name": "PyArray_BoolConverter( PyObject * object , Bool * val)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "object", + "val" + ], + "start_line": 3051, + "end_line": 3059, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_TypestrConvert", + "long_name": "PyArray_TypestrConvert( int itemsize , int gentype)", + "filename": "multiarraymodule.c", + "nloc": 96, + "complexity": 35, + "token_count": 308, + "parameters": [ + "itemsize", + "gentype" + ], + "start_line": 3066, + "end_line": 3181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BufferConverter", + "long_name": "PyArray_BufferConverter( PyObject * obj , PyArray_Chunk * buf)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 6, + "token_count": 147, + "parameters": [ + "obj", + "buf" + ], + "start_line": 3199, + "end_line": 3224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpConverter", + "long_name": "PyArray_IntpConverter( PyObject * obj , PyArray_Dims * seq)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 10, + "token_count": 189, + "parameters": [ + "obj", + "seq" + ], + "start_line": 3239, + "end_line": 3275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "_use_inherit", + "long_name": "_use_inherit( PyArray_Descr * type , PyObject * newobj , int * errflag)", + "filename": "multiarraymodule.c", + "nloc": 32, + "complexity": 7, + "token_count": 161, + "parameters": [ + "type", + "newobj", + "errflag" + ], + "start_line": 3293, + "end_line": 3326, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_tuple", + "long_name": "_convert_from_tuple( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 57, + "complexity": 11, + "token_count": 335, + "parameters": [ + "obj" + ], + "start_line": 3329, + "end_line": 3397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 69, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 60, + "complexity": 11, + "token_count": 395, + "parameters": [ + "obj" + ], + "start_line": 3405, + "end_line": 3467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 62, + "complexity": 11, + "token_count": 392, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3478, + "end_line": 3541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_commastring", + "long_name": "_convert_from_commastring( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 92, + "parameters": [ + "obj", + "align" + ], + "start_line": 3554, + "end_line": 3570, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_use_fields_dict", + "long_name": "_use_fields_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 1, + "token_count": 29, + "parameters": [ + "obj", + "align" + ], + "start_line": 3607, + "end_line": 3612, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_dict", + "long_name": "_convert_from_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 92, + "complexity": 25, + "token_count": 639, + "parameters": [ + "obj", + "align" + ], + "start_line": 3615, + "end_line": 3716, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 102, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter2", + "long_name": "PyArray_DescrConverter2( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 37, + "parameters": [ + "obj", + "at" + ], + "start_line": 3734, + "end_line": 3741, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter", + "long_name": "PyArray_DescrConverter( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 148, + "complexity": 58, + "token_count": 921, + "parameters": [ + "obj", + "at" + ], + "start_line": 3758, + "end_line": 3940, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 183, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ByteorderConverter", + "long_name": "PyArray_ByteorderConverter( PyObject * obj , char * endian)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 16, + "token_count": 218, + "parameters": [ + "obj", + "endian" + ], + "start_line": 3946, + "end_line": 3978, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SortkindConverter", + "long_name": "PyArray_SortkindConverter( PyObject * obj , PyArray_SORTKIND * sortkind)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 11, + "token_count": 162, + "parameters": [ + "obj", + "sortkind" + ], + "start_line": 3984, + "end_line": 4010, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EquivTypes", + "long_name": "PyArray_EquivTypes( PyArray_Descr * typ1 , PyArray_Descr * typ2)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 8, + "token_count": 138, + "parameters": [ + "typ1", + "typ2" + ], + "start_line": 4019, + "end_line": 4038, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 59, + "complexity": 15, + "token_count": 325, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4059, + "end_line": 4124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Empty", + "long_name": "PyArray_Empty( int nd , intp * dims , PyArray_Descr * type , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 14, + "complexity": 4, + "token_count": 96, + "parameters": [ + "nd", + "dims", + "type", + "fortran" + ], + "start_line": 4132, + "end_line": 4147, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_empty", + "long_name": "array_empty( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 2, + "token_count": 130, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4153, + "end_line": 4177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_scalar", + "long_name": "array_scalar( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 10, + "token_count": 254, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4182, + "end_line": 4240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zeros", + "long_name": "PyArray_Zeros( int nd , intp * dims , PyArray_Descr * type , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 4, + "token_count": 134, + "parameters": [ + "nd", + "dims", + "type", + "fortran" + ], + "start_line": 4249, + "end_line": 4273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_zeros", + "long_name": "array_zeros( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 2, + "token_count": 133, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4279, + "end_line": 4303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_set_typeDict", + "long_name": "array_set_typeDict( PyObject * ignored , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "ignored", + "args" + ], + "start_line": 4310, + "end_line": 4319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n)", + "filename": "multiarraymodule.c", + "nloc": 46, + "complexity": 8, + "token_count": 222, + "parameters": [ + "data", + "slen", + "dtype", + "n" + ], + "start_line": 4324, + "end_line": 4375, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 15, + "complexity": 2, + "token_count": 103, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4380, + "end_line": 4396, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 111, + "complexity": 22, + "token_count": 649, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4410, + "end_line": 4535, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_fromfile", + "long_name": "array_fromfile( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 7, + "token_count": 225, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4553, + "end_line": 4591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromBuffer", + "long_name": "PyArray_FromBuffer( PyObject * buf , PyArray_Descr * type , intp count , intp offset)", + "filename": "multiarraymodule.c", + "nloc": 83, + "complexity": 16, + "token_count": 446, + "parameters": [ + "buf", + "type", + "count", + "offset" + ], + "start_line": 4595, + "end_line": 4688, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "array_frombuffer", + "long_name": "array_frombuffer( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 121, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4704, + "end_line": 4721, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_concatenate", + "long_name": "array_concatenate( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 73, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 4727, + "end_line": 4738, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_innerproduct", + "long_name": "array_innerproduct( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 5, + "complexity": 2, + "token_count": 49, + "parameters": [ + "dummy", + "args" + ], + "start_line": 4745, + "end_line": 4751, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_matrixproduct", + "long_name": "array_matrixproduct( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 5, + "complexity": 2, + "token_count": 49, + "parameters": [ + "dummy", + "args" + ], + "start_line": 4758, + "end_line": 4764, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_fastCopyAndTranspose", + "long_name": "array_fastCopyAndTranspose( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 5, + "complexity": 2, + "token_count": 41, + "parameters": [ + "dummy", + "args" + ], + "start_line": 4768, + "end_line": 4774, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_correlate", + "long_name": "array_correlate( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 4778, + "end_line": 4787, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Arange", + "long_name": "PyArray_Arange( double start , double stop , double step , int type_num)", + "filename": "multiarraymodule.c", + "nloc": 40, + "complexity": 9, + "token_count": 300, + "parameters": [ + "start", + "stop", + "step", + "type_num" + ], + "start_line": 4794, + "end_line": 4845, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "_calc_length", + "long_name": "_calc_length( PyObject * start , PyObject * stop , PyObject * step , PyObject ** next , int cmplx)", + "filename": "multiarraymodule.c", + "nloc": 31, + "complexity": 10, + "token_count": 235, + "parameters": [ + "start", + "stop", + "step", + "next", + "cmplx" + ], + "start_line": 4851, + "end_line": 4883, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArangeObj", + "long_name": "PyArray_ArangeObj( PyObject * start , PyObject * stop , PyObject * step , PyArray_Descr * dtype)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 19, + "token_count": 461, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 4890, + "end_line": 4974, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "array_arange", + "long_name": "array_arange( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 100, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4980, + "end_line": 4992, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_set_string_function", + "long_name": "array_set_string_function( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 98, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 4999, + "end_line": 5015, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "array_set_ops_function", + "long_name": "array_set_ops_function( PyObject * self , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 5021, + "end_line": 5038, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Where", + "long_name": "PyArray_Where( PyObject * condition , PyObject * x , PyObject * y)", + "filename": "multiarraymodule.c", + "nloc": 31, + "complexity": 8, + "token_count": 231, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5045, + "end_line": 5085, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_where", + "long_name": "array_where( PyObject * ignored , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 60, + "parameters": [ + "ignored", + "args" + ], + "start_line": 5093, + "end_line": 5101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_lexsort", + "long_name": "array_lexsort( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 5113, + "end_line": 5123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_register_dtype", + "long_name": "array_register_dtype( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 3, + "token_count": 64, + "parameters": [ + "dummy", + "args" + ], + "start_line": 5132, + "end_line": 5143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_can_cast_safely", + "long_name": "array_can_cast_safely( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 5, + "token_count": 128, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5150, + "end_line": 5173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "new_buffer", + "long_name": "new_buffer( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 7, + "complexity": 2, + "token_count": 37, + "parameters": [ + "dummy", + "args" + ], + "start_line": 5180, + "end_line": 5188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "buffer_buffer", + "long_name": "buffer_buffer( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 120, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5197, + "end_line": 5215, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "setup_scalartypes", + "long_name": "setup_scalartypes( PyObject * dict)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 10, + "token_count": 351, + "parameters": [ + "dict" + ], + "start_line": 5279, + "end_line": 5392, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 114, + "top_nesting_level": 0 + }, + { + "name": "set_flaginfo", + "long_name": "set_flaginfo( PyObject * d)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 1, + "token_count": 152, + "parameters": [ + "d" + ], + "start_line": 5397, + "end_line": 5421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "initmultiarray", + "long_name": "initmultiarray()", + "filename": "multiarraymodule.c", + "nloc": 63, + "complexity": 15, + "token_count": 434, + "parameters": [], + "start_line": 5426, + "end_line": 5519, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 62, + "complexity": 11, + "token_count": 392, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3478, + "end_line": 3541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_dict", + "long_name": "_convert_from_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 93, + "complexity": 25, + "token_count": 641, + "parameters": [ + "obj", + "align" + ], + "start_line": 3615, + "end_line": 3717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + } + ], + "nloc": 4153, + "complexity": 910, + "token_count": 27155, + "diff_parsed": { + "added": [ + "\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));", + "\t\tPyDict_SetItem(fields, key, tup);", + "\t\tPy_DECREF(tup);", + "\t\tPyList_SET_ITEM(nameslist, i, key);", + "\t\tif (ret == PY_FAIL) goto fail;", + "\t\ttotalsize += conv->elsize;", + "\t\telse {", + "\t\t\tif (align) {", + "\t\t\t\tint _align = newdescr->alignment;", + "\t\t\t\tif (_align > 1) totalsize =\t\t\\", + "\t\t\t\t\t((totalsize + _align - 1)/_align)*_align;", + "\t\t\t\tmaxalign = MAX(maxalign,_align);", + "\t\t\t}", + "\t\t}" + ], + "deleted": [ + "\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));", + "\t\tPyDict_SetItem(fields, key, tup);", + "\t\tPy_DECREF(tup);", + "\t\tPyList_SET_ITEM(nameslist, i, key);", + "\t\tif (ret == PY_FAIL) goto fail;", + "\t\ttotalsize += conv->elsize;", + "\t\telse", + "\t\tif (align) {", + "\t\t\tint _align = newdescr->alignment;", + "\t\t\tif (_align > 1) totalsize =\t\t\t\\", + "\t\t\t\t((totalsize + _align - 1)/_align)*_align;", + "\t\t\tmaxalign = MAX(maxalign,_align);", + "\t\t}" + ] + } + } + ] + }, + { + "hash": "f1a1c7c72fb77edbd38c08414174052dcdd7ba79", + "msg": "started filling in missing ma.array methods", + "author": { + "name": "sasha", + "email": "sasha@localhost" + }, + "committer": { + "name": "sasha", + "email": "sasha@localhost" + }, + "author_date": "2006-01-11T23:15:13+00:00", + "author_timezone": 0, + "committer_date": "2006-01-11T23:15:13+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "74cc5f80fedd223b3dace284a7456c5d16187b52" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 0, + "insertions": 91, + "lines": 91, + "files": 2, + "dmm_unit_size": 0.4074074074074074, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 0.9259259259259259, + "modified_files": [ + { + "old_path": "numpy/core/ma.py", + "new_path": "numpy/core/ma.py", + "filename": "ma.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -2078,5 +2078,75 @@ def asarray(data, dtype=None):\n return data\n return array(data, dtype=dtype, copy=0)\n \n+# Add methods to support ndarray interface\n+# XXX: I is better to to change the masked_*_operation adaptors\n+# XXX: to wrap ndarray methods directly to create ma.array methods.\n+from types import MethodType\n+def _m(f):\n+ return MethodType(f, None, array)\n+def not_implemented(*args, **kwds):\n+ raise NotImplementedError, \"not yet implemented for numpy.ma arrays\"\n+array.all = _m(alltrue)\n+array.any = _m(sometrue)\n+array.argmax = _m(argmax)\n+array.argmin = _m(argmin)\n+array.argsort = _m(argsort)\n+array.base = property(_m(not_implemented))\n+array.byteswap = _m(not_implemented)\n+\n+def _choose(self, *args):\n+ return choose(self, args)\n+array.choose = _m(_choose)\n+del _choose\n+\n+array.clip = _m(not_implemented)\n+\n+def _compress(self, cond, axis=None):\n+ return compress(cond, self, axis)\n+array.compress = _m(_compress)\n+del _compress\n+\n+array.conj = array.conjugate = _m(conjugate)\n+array.copy = _m(not_implemented)\n+array.cumprod = _m(not_implemented)\n+array.cumsum = _m(not_implemented)\n+array.diagonal = _m(diagonal)\n+array.dtypedescr = property(_m(not_implemented))\n+array.dtypestr = property(_m(not_implemented))\n+array.dump = _m(not_implemented)\n+array.dumps = _m(not_implemented)\n+array.fill = _m(not_implemented)\n+array.flags = property(_m(not_implemented))\n+array.flatten = _m(ravel)\n+array.getfield = _m(not_implemented)\n+array.max = _m(maximum)\n+array.mean = _m(average)\n+array.min = _m(minimum)\n+array.nbytes = property(_m(not_implemented))\n+array.ndim = _m(not_implemented)\n+array.newbyteorder = _m(not_implemented)\n+array.nonzero = _m(nonzero)\n+array.prod = _m(product)\n+array.ptp = _m(not_implemented)\n+array.repeat = _m(repeat)\n+array.resize = _m(resize)\n+array.searchsorted = _m(not_implemented)\n+array.setfield = _m(not_implemented)\n+array.setflags = _m(not_implemented)\n+array.sort = _m(not_implemented) # NB: ndarray.sort is inplace\n+array.squeeze = _m(not_implemented)\n+array.std = _m(not_implemented)\n+array.strides = property(_m(not_implemented))\n+array.sum = _m(sum)\n+array.swapaxes = _m(not_implemented)\n+array.take = _m(take)\n+array.tofile = _m(not_implemented)\n+array.trace = _m(not_implemented)\n+array.transpose = _m(transpose)\n+array.var = _m(not_implemented)\n+array.view = _m(not_implemented)\n+del _m, MethodType, not_implemented\n+\n+\n masked = MaskedArray([0], int, mask=[1])[0:0]\n masked = masked[0:0]\n", + "added_lines": 70, + "deleted_lines": 0, + "source_code": "\"\"\"MA: a facility for dealing with missing observations\nMA is generally used as a numpy.array look-alike.\nby Paul F. Dubois.\n\nCopyright 1999, 2000, 2001 Regents of the University of California.\nReleased for unlimited redistribution.\nAdapted for numpy_core 2005 by Travis Oliphant and\n(mainly) Paul Dubois.\n\"\"\"\nimport string, types, sys\n\nimport umath\nimport oldnumeric\nfrom numeric import e, pi, newaxis, ndarray, inf\nfrom oldnumeric import typecodes, amax, amin\nfrom numerictypes import *\nimport numeric\n\n \nMaskType=bool_\ndivide_tolerance = 1.e-35\n\nclass MAError (Exception):\n def __init__ (self, args=None):\n \"Create an exception\"\n self.args = args\n def __str__(self):\n \"Calculate the string representation\"\n return str(self.args)\n __repr__ = __str__\n\nclass _MaskedPrintOption:\n \"One instance of this class, masked_print_option, is created.\"\n def __init__ (self, display):\n \"Create the masked print option object.\"\n self.set_display(display)\n self._enabled = 1\n\n def display (self):\n \"Show what prints for masked values.\"\n return self._display\n\n def set_display (self, s):\n \"set_display(s) sets what prints for masked values.\"\n self._display = s\n\n def enabled (self):\n \"Is the use of the display value enabled?\"\n return self._enabled\n\n def enable(self, flag=1):\n \"Set the enabling flag to flag.\"\n self._enabled = flag\n\n def __str__ (self):\n return str(self._display)\n\n __repr__ = __str__\n \n#if you single index into a masked location you get this object.\nmasked_print_option = _MaskedPrintOption('--')\n\n# Use single element arrays or scalars.\ndefault_real_fill_value = 1.e20\ndefault_complex_fill_value = 1.e20 + 0.0j\ndefault_character_fill_value = '-'\ndefault_integer_fill_value = 999999\ndefault_object_fill_value = '?'\n\ndef default_fill_value (obj):\n \"Function to calculate default fill value for an object.\"\n if isinstance(obj, types.FloatType):\n return default_real_fill_value\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return default_integer_fill_value\n elif isinstance(obj, types.StringType):\n return default_character_fill_value\n elif isinstance(obj, types.ComplexType):\n return default_complex_fill_value\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return default_real_fill_value\n if x in typecodes['Integer']:\n return default_integer_fill_value\n if x in typecodes['Complex']:\n return default_complex_fill_value\n if x in typecodes['Character']:\n return default_character_fill_value\n if x in typecodes['UnsignedInteger']:\n return umath.absolute(default_integer_fill_value)\n return default_object_fill_value\n else:\n return default_object_fill_value\n\ndef minimum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking minima.\"\n if isinstance(obj, types.FloatType):\n return numeric.inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return numeric.inf\n if x in typecodes['Integer']:\n return sys.maxint\n if x in typecodes['UnsignedInteger']:\n return sys.maxint\n else:\n raise TypeError, 'Unsuitable type for calculating minimum.'\n\ndef maximum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking maxima.\"\n if isinstance(obj, types.FloatType):\n return -inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return -sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return -inf\n if x in typecodes['Integer']:\n return -sys.maxint\n if x in typecodes['UnsignedInteger']:\n return 0\n else:\n raise TypeError, 'Unsuitable type for calculating maximum.'\n\ndef set_fill_value (a, fill_value):\n \"Set fill value of a if it is a masked array.\"\n if isMaskedArray(a):\n a.set_fill_value (fill_value)\n\ndef getmask (a):\n \"\"\"Mask of values in a; could be None.\n Returns None if a is not a masked array.\n To get an array for sure use getmaskarray.\"\"\"\n if isinstance(a, MaskedArray):\n return a.raw_mask()\n else:\n return None\n\ndef getmaskarray (a):\n \"\"\"Mask of values in a; an array of zeros if mask is None\n or not a masked array, and is a byte-sized integer.\n Do not try to add up entries, for example.\n \"\"\"\n m = getmask(a)\n if m is None:\n return make_mask_none(shape(a))\n else:\n return m\n\ndef is_mask (m):\n \"\"\"Is m a legal mask? Does not check contents, only type.\n \"\"\"\n if m is None or (isinstance(m, ndarray) and \\\n m.dtype is MaskType):\n return 1\n else:\n return 0\n\ndef make_mask (m, copy=0, flag=0):\n \"\"\"make_mask(m, copy=0, flag=0)\n return m as a mask, creating a copy if necessary or requested.\n Can accept any sequence of integers or None. Does not check\n that contents must be 0s and 1s.\n if flag, return None if m contains no true elements.\n \"\"\"\n if m is None:\n return None\n elif isinstance(m, ndarray):\n if m.dtype is MaskType:\n if copy:\n result = numeric.array(m, dtype=MaskType, copy=copy)\n else:\n result = m\n else:\n result = m.astype(MaskType)\n else:\n result = filled(m,True).astype(MaskType)\n\n if flag and not oldnumeric.sometrue(oldnumeric.ravel(result)):\n return None\n else:\n return result\n\ndef make_mask_none (s):\n \"Return a mask of all zeros of shape s.\"\n result = numeric.zeros(s, dtype=MaskType)\n result.shape = s\n return result\n\ndef mask_or (m1, m2):\n \"\"\"Logical or of the mask candidates m1 and m2, treating None as false.\n Result may equal m1 or m2 if the other is None.\n \"\"\"\n if m1 is None: return make_mask(m2)\n if m2 is None: return make_mask(m1)\n if m1 is m2 and is_mask(m1): return m1\n return make_mask(umath.logical_or(m1, m2))\n\ndef filled (a, value = None):\n \"\"\"a as a contiguous numeric array with any masked areas replaced by value\n if value is None or the special element \"masked\", get_fill_value(a)\n is used instead.\n\n If a is already a contiguous numeric array, a itself is returned.\n\n filled(a) can be used to be sure that the result is numeric when\n passing an object a to other software ignorant of MA, in particular to\n numeric itself.\n \"\"\"\n if isinstance(a, MaskedArray):\n return a.filled(value)\n elif isinstance(a, ndarray) and a.flags['CONTIGUOUS']:\n return a\n elif isinstance(a, types.DictType):\n return numeric.array(a, 'O')\n else:\n return numeric.array(a)\n\ndef get_fill_value (a):\n \"\"\"\n The fill value of a, if it has one; otherwise, the default fill value\n for that type.\n \"\"\"\n if isMaskedArray(a):\n result = a.fill_value()\n else:\n result = default_fill_value(a)\n return result\n\ndef common_fill_value (a, b):\n \"The common fill_value of a and b, if there is one, or None\"\n t1 = get_fill_value(a)\n t2 = get_fill_value(b)\n if t1 == t2: return t1\n return None\n\n# Domain functions return 1 where the argument(s) are not in the domain.\nclass domain_check_interval:\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n def __init__(self, y1, y2):\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n self.y1 = y1\n self.y2 = y2\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.logical_or(umath.greater (x, self.y2),\n umath.less(x, self.y1)\n )\n\nclass domain_tan:\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n def __init__(self, eps):\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n self.eps = eps\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less(umath.absolute(umath.cos(x)), self.eps)\n\nclass domain_greater:\n \"domain_greater(v)(x) = true where x <= v\"\n def __init__(self, critical_value):\n \"domain_greater(v)(x) = true where x <= v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less_equal (x, self.critical_value)\n\nclass domain_greater_equal:\n \"domain_greater_equal(v)(x) = true where x < v\"\n def __init__(self, critical_value):\n \"domain_greater_equal(v)(x) = true where x < v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less (x, self.critical_value)\n\nclass masked_unary_operation:\n def __init__ (self, aufunc, fill=0, domain=None):\n \"\"\" masked_unary_operation(aufunc, fill=0, domain=None)\n aufunc(fill) must be defined\n self(x) returns aufunc(x)\n with masked values where domain(x) is true or getmask(x) is true.\n \"\"\"\n self.f = aufunc\n self.fill = fill\n self.domain = domain\n self.__doc__ = getattr(aufunc, \"__doc__\", str(aufunc))\n\n def __call__ (self, a, *args, **kwargs):\n \"Execute the call behavior.\"\n# numeric tries to return scalars rather than arrays when given scalars.\n m = getmask(a)\n d1 = filled(a, self.fill)\n if self.domain is not None:\n m = mask_or(m, self.domain(d1))\n result = self.f(d1, *args, **kwargs)\n if m is not None:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\n\nclass domain_safe_divide:\n def __init__ (self, tolerance=divide_tolerance):\n self.tolerance = tolerance\n def __call__ (self, a, b):\n return umath.absolute(a) * self.tolerance >= umath.absolute(b)\n\nclass domained_binary_operation:\n \"\"\"Binary operations that have a domain, like divide. These are complicated so they\n are a separate class. They have no reduce, outer or accumulate.\n \"\"\"\n def __init__ (self, abfunc, domain, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.domain = domain\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__(self, a, b):\n \"Execute the call behavior.\"\n ma = getmask(a)\n mb = getmask(b)\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n t = self.domain(d1, d2)\n\n if oldnumeric.sometrue(t, None):\n d2 = where(t, self.filly, d2)\n mb = mask_or(mb, t)\n m = mask_or(ma, mb)\n result = self.f(d1, d2)\n if m is not None:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n \n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nclass masked_binary_operation:\n def __init__ (self, abfunc, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__ (self, a, b, *args, **kwargs):\n \"Execute the call behavior.\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n result = self.f(d1, d2, *args, **kwargs)\n if m is not None:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis with this function.\"\"\"\n m = getmask(target)\n t = filled(target, self.filly)\n if t.shape == ():\n t = t.reshape(1)\n if m is not None:\n m = make_mask(m, copy=1)\n m.shape = (1,)\n if m is None:\n return masked_array (self.f.reduce (t, axis))\n else:\n t = masked_array (t, m)\n t = self.f.reduce(filled(t, self.filly), axis)\n m = umath.logical_and.reduce(m, axis)\n if isinstance(t, ndarray):\n return masked_array(t, m, get_fill_value(target))\n elif m:\n return masked\n else:\n return t\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n m = None\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = self.f.outer(filled(a, self.fillx), filled(b, self.filly))\n return masked_array(d, m)\n\n def accumulate (self, target, axis=0):\n \"\"\"Accumulate target along axis after filling with y fill value.\"\"\"\n t = filled(target, self.filly)\n return masked_array (self.f.accumulate (t, axis))\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nsqrt = masked_unary_operation(umath.sqrt, 0.0, domain_greater_equal(0.0))\nlog = masked_unary_operation(umath.log, 1.0, domain_greater(0.0))\nlog10 = masked_unary_operation(umath.log10, 1.0, domain_greater(0.0))\nexp = masked_unary_operation(umath.exp)\nconjugate = masked_unary_operation(umath.conjugate)\nsin = masked_unary_operation(umath.sin)\ncos = masked_unary_operation(umath.cos)\ntan = masked_unary_operation(umath.tan, 0.0, domain_tan(1.e-35))\narcsin = masked_unary_operation(umath.arcsin, 0.0, domain_check_interval(-1.0, 1.0))\narccos = masked_unary_operation(umath.arccos, 0.0, domain_check_interval(-1.0, 1.0))\narctan = masked_unary_operation(umath.arctan)\n# Missing from numeric\narcsinh = masked_unary_operation(umath.arcsinh)\narccosh = masked_unary_operation(umath.arccosh)\narctanh = masked_unary_operation(umath.arctanh)\nsinh = masked_unary_operation(umath.sinh)\ncosh = masked_unary_operation(umath.cosh)\ntanh = masked_unary_operation(umath.tanh)\nabsolute = masked_unary_operation(umath.absolute)\nfabs = masked_unary_operation(umath.fabs)\nnegative = masked_unary_operation(umath.negative)\nnonzero = masked_unary_operation(oldnumeric.nonzero)\naround = masked_unary_operation(oldnumeric.round_)\nfloor = masked_unary_operation(umath.floor)\nceil = masked_unary_operation(umath.ceil)\nsometrue = masked_unary_operation(oldnumeric.sometrue)\nalltrue = masked_unary_operation(oldnumeric.alltrue, 1)\nlogical_not = masked_unary_operation(umath.logical_not)\n\nadd = masked_binary_operation(umath.add)\nsubtract = masked_binary_operation(umath.subtract)\nsubtract.reduce = None\nmultiply = masked_binary_operation(umath.multiply, 1, 1)\ndivide = domained_binary_operation(umath.divide, domain_safe_divide(), 0, 1)\ntrue_divide = domained_binary_operation(umath.true_divide, domain_safe_divide(), 0, 1)\nfloor_divide = domained_binary_operation(umath.floor_divide, domain_safe_divide(), 0, 1)\nremainder = domained_binary_operation(umath.remainder, domain_safe_divide(), 0, 1)\nfmod = domained_binary_operation(umath.fmod, domain_safe_divide(), 0, 1)\nhypot = masked_binary_operation(umath.hypot)\narctan2 = masked_binary_operation(umath.arctan2, 0.0, 1.0)\narctan2.reduce = None\nequal = masked_binary_operation(umath.equal)\nequal.reduce = None\nnot_equal = masked_binary_operation(umath.not_equal)\nnot_equal.reduce = None\nless_equal = masked_binary_operation(umath.less_equal)\nless_equal.reduce = None\ngreater_equal = masked_binary_operation(umath.greater_equal)\ngreater_equal.reduce = None\nless = masked_binary_operation(umath.less)\nless.reduce = None\ngreater = masked_binary_operation(umath.greater)\ngreater.reduce = None\nlogical_and = masked_binary_operation(umath.logical_and)\nlogical_or = masked_binary_operation(umath.logical_or)\nlogical_xor = masked_binary_operation(umath.logical_xor)\nbitwise_and = masked_binary_operation(umath.bitwise_and)\nbitwise_or = masked_binary_operation(umath.bitwise_or)\nbitwise_xor = masked_binary_operation(umath.bitwise_xor)\n\ndef rank (object):\n return oldnumeric.rank(filled(object))\n\ndef shape (object):\n return oldnumeric.shape(filled(object))\n\ndef size (object, axis=None):\n return oldnumeric.size(filled(object), axis)\n\nclass MaskedArray (object):\n \"\"\"Arrays with possibly masked values.\n Masked values of 1 exclude the corresponding element from \n any computation.\n\n Construction:\n x = array(data, dtype=None, copy=True, fortran=False,\n mask = None, fill_value=None)\n\n If copy=False, every effort is made not to copy the data:\n If data is a MaskedArray, and argument mask=None,\n then the candidate data is data.data and the\n mask used is data.mask. If data is a numeric array,\n it is used as the candidate raw data.\n If dtypechar is not None and\n is != data.dtypechar then a data copy is required.\n Otherwise, the candidate is used.\n\n If a data copy is required, raw data stored is the result of:\n numeric.array(data, dtype=dtypechar, copy=copy)\n\n If mask is None there are no masked values. Otherwise mask must\n be convertible to an array of booleans with the same shape as x.\n\n fill_value is used to fill in masked values when necessary,\n such as when printing and in method/function filled().\n The fill_value is not used for computation within this module.\n \"\"\"\n __array_priority__ = 10.1\n def __init__(self, data, dtype=None, copy=True, fortran=False, \n mask=None, fill_value=None):\n \"\"\"array(data, dtype=None, copy=True, fortran=False, mask=None, fill_value=None)\n If data already a numeric array, its dtype becomes the default value of dtype.\n \"\"\"\n tc = dtype\n need_data_copied = copy\n if isinstance(data, MaskedArray):\n c = data.data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n if mask is None:\n mask = data.mask\n elif mask is not None: #attempting to change the mask\n need_data_copied = True\n\n elif isinstance(data, ndarray):\n c = data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n else:\n need_data_copied = False #because I'll do it now\n c = numeric.array(data, dtype=tc, copy=True, fortran=fortran)\n\n if need_data_copied:\n if tc == ctc:\n self._data = numeric.array(c, dtype=tc, copy=True, fortran=fortran)\n else:\n self._data = c.astype(tc)\n else:\n self._data = c\n\n if mask is None:\n self._mask = None\n self._shared_mask = 0\n else:\n self._mask = make_mask (mask)\n if self._mask is None:\n self._shared_mask = 0\n else:\n self._shared_mask = (self._mask is mask)\n nm = size(self._mask)\n nd = size(self._data)\n if nm != nd:\n if nm == 1:\n self._mask = oldnumeric.resize(self._mask, self._data.shape)\n self._shared_mask = 0\n elif nd == 1:\n self._data = oldnumeric.resize(self._data, self._mask.shape)\n self._data.shape = self._mask.shape\n else:\n raise MAError, \"Mask and data not compatible.\"\n elif nm == 1 and shape(self._mask) != shape(self._data):\n self.unshare_mask()\n self._mask.shape = self._data.shape\n\n self.set_fill_value(fill_value)\n\n def __array__ (self, t = None):\n \"Special hook for numeric. Converts to numeric if possible.\"\n if self._mask is not None:\n if oldnumeric.ravel(self._mask).any():\n raise MAError, \\\n \"\"\"Cannot automatically convert masked array to numeric because data\n is masked in one or more locations.\n \"\"\"\n else: # Mask is all false\n # Optimize to avoid future invocations of this section.\n self._mask = None\n self._shared_mask = 0\n if t:\n return self._data.astype(t)\n else:\n return self._data\n\n def __array_wrap__ (self, array):\n \"\"\"Special hook for ufuncs. Converts to Masked array with\n the same mask as self.\"\"\"\n return MaskedArray(array, copy=False, mask=self._mask,\n fill_value = self._fill_value)\n \n def _get_shape(self):\n \"Return the current shape.\"\n return self._data.shape\n\n def _set_shape (self, newshape):\n \"Set the array's shape.\"\n self._data.shape = newshape\n if self._mask is not None:\n self._mask = self._mask.copy()\n self._mask.shape = newshape\n\n def _get_flat(self):\n \"\"\"Calculate the flat value.\n \"\"\"\n if self._mask is None:\n return masked_array(self._data.ravel(), mask=None,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.ravel(),\n mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_flat (self, value):\n \"x.flat = value\"\n y = self.ravel()\n y[:] = value\n\n def _get_real(self):\n \"Get the real part of a complex array.\"\n if self._mask is None:\n return masked_array(self._data.real, mask=None,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.real, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_real (self, value):\n \"x.real = value\"\n y = self.real\n y[...] = value\n\n def _get_imaginary(self):\n \"Get the imaginary part of a complex array.\"\n if self._mask is None:\n return masked_array(self._data.imag, mask=None,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.imag, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_imaginary (self, value):\n \"x.imaginary = value\"\n y = self.imaginary\n y[...] = value\n\n def __str__(self):\n \"\"\"Calculate the str representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n if masked_print_option.enabled():\n f = masked_print_option\n # XXX: Without the following special case masked\n # XXX: would print as \"[--]\", not \"--\". Can we avoid\n # XXX: checks for masked by choosing a different value\n # XXX: for the masked singleton? 2005-01-05 -- sasha\n if self is masked:\n return str(f)\n # convert to object array to make filled work\n self = self.astype(object)\n else:\n f = self.fill_value()\n res = self.filled(f)\n return str(res)\n\n def __repr__(self):\n \"\"\"Calculate the repr representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n with_mask = \"\"\"\\\narray(data =\n %(data)s,\n mask =\n %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n with_mask1 = \"\"\"\\\narray(data = %(data)s,\n mask = %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n without_mask = \"\"\"array(\n %(data)s)\"\"\"\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n\n n = len(self.shape)\n if self._mask is None:\n if n <=1:\n return without_mask1 % {'data':str(self.filled())}\n return without_mask % {'data':str(self.filled())}\n else:\n if n <=1:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n if self._mask is None:\n return without_mask % {'data':str(self.filled())}\n else:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n\n def __float__(self):\n \"Convert self to float.\"\n self.unmask()\n if self._mask is not None:\n raise MAError, 'Cannot convert masked element to a Python float.'\n return float(self.data.item())\n\n def __int__(self):\n \"Convert self to int.\"\n self.unmask()\n if self._mask is not None:\n raise MAError, 'Cannot convert masked element to a Python int.'\n return int(self.data.item())\n\n def __getitem__(self, i):\n \"Get item described by i. Not a copy as in previous versions.\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i]\n if m is None:\n return dout\n mi = m[i]\n if mi.size == 1:\n if mi: \n return masked\n else:\n return dout\n else:\n return masked_array(dout, mi, fill_value=self._fill_value)\n\n def __getslice__(self, i, j):\n \"Get slice described by i, j\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i:j]\n if m is None:\n return masked_array(dout, fill_value=self._fill_value)\n else:\n return masked_array(dout, mask = m[i:j], fill_value=self._fill_value)\n\n# --------\n# setitem and setslice notes\n# note that if value is masked, it means to mask those locations.\n# setting a value changes the mask to match the value in those locations.\n\n def __setitem__(self, index, value):\n \"Set item described by index. If value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, 'Cannot alter the masked element.'\n if value is masked:\n if self._mask is None:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n else:\n self.unshare_mask()\n self._mask[index] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[index] = value\n if m is None:\n if self._mask is not None:\n self.unshare_mask()\n self._mask[index] = False\n else:\n if self._mask is None:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = True\n else:\n self.unshare_mask()\n self._mask[index] = m\n\n def __setslice__(self, i, j, value):\n \"Set slice i:j; if value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, \"Cannot alter the 'masked' object.\"\n if value is masked:\n if self._mask is None:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n self._mask[i:j] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[i:j] = value\n if m is None:\n if self._mask is not None:\n self.unshare_mask()\n self._mask[i:j] = False\n else:\n if self._mask is None:\n self._mask = make_mask_none(self._data.shape)\n self._shared_mask = False\n self._mask[i:j] = m\n\n def __nonzero__(self):\n \"\"\"returns true if any element is non-zero or masked\n\n \"\"\"\n # XXX: This changes bool conversion logic from MA.\n # XXX: In MA bool(a) == len(a) != 0, but in numpy\n # XXX: scalars do not have len \n m = self._mask\n d = self._data\n return bool(m is not None and m.any()\n or d is not None and d.any())\n \n def __len__ (self):\n \"\"\"Return length of first dimension. This is weird but Python's\n slicing behavior depends on it.\"\"\"\n return len(self._data)\n\n def __and__(self, other):\n \"Return bitwise_and\"\n return bitwise_and(self, other)\n\n def __or__(self, other):\n \"Return bitwise_or\"\n return bitwise_or(self, other)\n\n def __xor__(self, other):\n \"Return bitwise_xor\"\n return bitwise_xor(self, other)\n\n __rand__ = __and__\n __ror__ = __or__\n __rxor__ = __xor__\n\n def __abs__(self):\n \"Return absolute(self)\"\n return absolute(self)\n\n def __neg__(self):\n \"Return negative(self)\"\n return negative(self)\n\n def __pos__(self):\n \"Return array(self)\"\n return array(self)\n\n def __add__(self, other):\n \"Return add(self, other)\"\n return add(self, other)\n\n __radd__ = __add__\n\n def __mod__ (self, other):\n \"Return remainder(self, other)\"\n return remainder(self, other)\n\n def __rmod__ (self, other):\n \"Return remainder(other, self)\"\n return remainder(other, self)\n\n def __lshift__ (self, n):\n return left_shift(self, n)\n\n def __rshift__ (self, n):\n return right_shift(self, n)\n\n def __sub__(self, other):\n \"Return subtract(self, other)\"\n return subtract(self, other)\n\n def __rsub__(self, other):\n \"Return subtract(other, self)\"\n return subtract(other, self)\n\n def __mul__(self, other):\n \"Return multiply(self, other)\"\n return multiply(self, other)\n\n __rmul__ = __mul__\n\n def __div__(self, other):\n \"Return divide(self, other)\"\n return divide(self, other)\n\n def __rdiv__(self, other):\n \"Return divide(other, self)\"\n return divide(other, self)\n\n def __truediv__(self, other):\n \"Return divide(self, other)\"\n return true_divide(self, other)\n\n def __rtruediv__(self, other):\n \"Return divide(other, self)\"\n return true_divide(other, self)\n\n def __floordiv__(self, other):\n \"Return divide(self, other)\"\n return floor_divide(self, other)\n\n def __rfloordiv__(self, other):\n \"Return divide(other, self)\"\n return floor_divide(other, self)\n\n def __pow__(self,other, third=None):\n \"Return power(self, other, third)\"\n return power(self, other, third)\n\n def __sqrt__(self):\n \"Return sqrt(self)\"\n return sqrt(self)\n\n def __iadd__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is None:\n self._data += f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not None\n else:\n result = add(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __imul__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is None:\n self._data *= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not None\n else:\n result = multiply(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __isub__(self, other):\n \"Subtract other from self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is None:\n self._data -= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not None\n else:\n result = subtract(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n\n\n def __idiv__(self, other):\n \"Divide self by other in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n mo = getmask(other)\n result = divide(self, masked_array(f, mask=mo))\n self._data = result.data\n dm = result.raw_mask()\n if dm is not self._mask:\n self._mask = dm\n self._shared_mask = 1\n return self\n\n def __eq__(self,other):\n return equal(self,other)\n\n def __ne__(self,other):\n return not_equal(self,other)\n\n def __lt__(self,other):\n return less(self,other)\n\n def __le__(self,other):\n return less_equal(self,other)\n\n def __gt__(self,other):\n return greater(self,other)\n\n def __ge__(self,other):\n return greater_equal(self,other)\n\n def astype (self, tc):\n \"return self as array of given type.\"\n d = self._data.astype(tc)\n return array(d, mask=self._mask)\n\n def byte_swapped(self):\n \"\"\"Returns the raw data field, byte_swapped. Included for consistency\n with numeric but doesn't make sense in this context.\n \"\"\"\n return self._data.byte_swapped()\n\n def compressed (self):\n \"A 1-D array of all the non-masked data.\"\n d = oldnumeric.ravel(self._data)\n if self._mask is None:\n return array(d)\n else:\n m = 1 - oldnumeric.ravel(self._mask)\n c = oldnumeric.compress(m, d)\n return array(c, copy=0)\n\n def count (self, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n m = self._mask\n s = self._data.shape\n ls = len(s)\n if m is None:\n if ls == 0:\n return 1\n if ls == 1:\n return s[0]\n if axis is None:\n return reduce(lambda x,y:x*y, s)\n else:\n n = s[axis]\n t = list(s)\n del t[axis]\n return ones(t) * n\n if axis is None:\n w = oldnumeric.ravel(m).astype(int) \n n1 = size(w)\n if n1 == 1:\n n2 = w[0]\n else:\n n2 = umath.add.reduce(w)\n return n1 - n2\n else:\n n1 = size(m, axis)\n n2 = sum(m.astype(int), axis)\n return n1 - n2\n\n def dot (self, other):\n \"s.dot(other) = innerproduct(s, other)\"\n return innerproduct(self, other)\n\n def fill_value(self):\n \"Get the current fill value.\"\n return self._fill_value\n\n def filled (self, fill_value=None):\n \"\"\"A numeric array with masked values filled. If fill_value is None,\n use self.fill_value().\n\n If mask is None, copy data only if not contiguous.\n Result is always a contiguous, numeric array.\n# Is contiguous really necessary now?\n \"\"\"\n d = self._data\n m = self._mask\n if m is None:\n if d.flags['CONTIGUOUS']:\n return d\n else:\n return d.copy()\n else:\n if fill_value is None:\n value = self._fill_value\n else:\n value = fill_value\n\n if self is masked:\n result = numeric.array(value).reshape(*d.shape)\n else:\n try:\n result = numeric.array(d, dtype=d.dtype, copy=1)\n result[m] = value\n except (TypeError, AttributeError):\n #ok, can't put that value in here\n value = numeric.array(value, dtype=object)\n d = d.astype(object)\n result = oldnumeric.choose(m, (d, value))\n except IndexError:\n #ok, if scalar\n if d.shape:\n raise\n elif m:\n result = numeric.array(value, dtype=d.dtype)\n else:\n result = d\n return result\n\n def ids (self):\n \"\"\"Return the ids of the data and mask areas\"\"\"\n return (id(self._data), id(self._mask))\n\n def iscontiguous (self):\n \"Is the data contiguous?\"\n return self._data.flags['CONTIGUOUS']\n\n def itemsize(self):\n \"Item size of each data item.\"\n return self._data.itemsize\n\n\n def outer(self, other):\n \"s.outer(other) = outerproduct(s, other)\"\n return outerproduct(self, other)\n\n def put (self, values):\n \"\"\"Set the non-masked entries of self to filled(values).\n No change to mask\n \"\"\"\n iota = numeric.arange(self.size)\n d = self._data\n if self._mask is None:\n ind = iota\n else:\n ind = oldnumeric.compress(1 - self._mask, iota)\n d[ind] = filled(values).astype(d.dtype)\n\n def putmask (self, values):\n \"\"\"Set the masked entries of self to filled(values).\n Mask changed to None.\n \"\"\"\n d = self._data\n if self._mask is not None:\n d[self._mask] = filled(values).astype(d.dtype)\n self._shared_mask = 0\n self._mask = None\n\n def ravel (self):\n \"\"\"Return a 1-D view of self.\"\"\"\n if self._mask is None:\n return masked_array(self._data.ravel())\n else:\n return masked_array(self._data.ravel(), self._mask.ravel())\n\n def raw_data (self):\n \"\"\" Obsolete; use data property instead.\n The raw data; portions may be meaningless.\n May be noncontiguous. Expert use only.\"\"\"\n return self._data\n data = property(fget=raw_data, \n doc=\"The data, but values at masked locations are meaningless.\")\n\n def raw_mask (self):\n \"\"\" Obsolete; use mask property instead.\n May be noncontiguous. Expert use only.\n \"\"\"\n return self._mask\n mask = property(fget=raw_mask, \n doc=\"The mask, may be None. Values where mask true are meaningless.\")\n\n def reshape (self, *s):\n \"\"\"This array reshaped to shape s\"\"\"\n d = self._data.reshape(*s)\n if self._mask is None:\n return masked_array(d)\n else:\n m = self._mask.reshape(*s)\n return masked_array(d, m)\n\n def set_fill_value (self, v=None):\n \"Set the fill value to v. Omit v to restore default.\"\n if v is None:\n v = default_fill_value (self.raw_data())\n self._fill_value = v\n\n def _get_size (self):\n return self._data.size\n size = property(fget=_get_size, doc=\"Number of elements in the array.\")\n## CHECK THIS: signature of numeric.array.size?\n \n def _get_dtypechar(self):\n return self._data.dtypechar\n dtypechar = property(fget=_get_dtypechar, doc=\"type character of the array.\")\n\n def _get_dtype(self):\n return self._data.dtype\n dtype = property(fget=_get_dtype, doc=\"type of the array elements.\")\n\n def item(self):\n \"Return Python scalar if possible.\"\n if self._mask is not None:\n m = oldnumeric.ravel(self._mask)\n try:\n if m[0]:\n return masked\n except IndexError:\n return masked\n return self._data.item()\n\n def tolist(self, fill_value=None):\n \"Convert to list\"\n return self.filled(fill_value).tolist()\n\n def tostring(self, fill_value=None):\n \"Convert to string\"\n return self.filled(fill_value).tostring()\n\n def unmask (self):\n \"Replace the mask by None if possible.\"\n if self._mask is None: return\n m = make_mask(self._mask, flag=1)\n if m is None:\n self._mask = None\n self._shared_mask = 0\n\n def unshare_mask (self):\n \"If currently sharing mask, make a copy.\"\n if self._shared_mask:\n self._mask = make_mask (self._mask, copy=1, flag=0)\n self._shared_mask = 0\n\n shape = property(_get_shape, _set_shape,\n doc = 'tuple giving the shape of the array')\n\n flat = property(_get_flat, _set_flat,\n doc = 'Access array in flat form.')\n\n real = property(_get_real, _set_real,\n doc = 'Access the real part of the array')\n\n imaginary = property(_get_imaginary, _set_imaginary,\n doc = 'Access the imaginary part of the array')\n\n imag = imaginary\n\n#end class MaskedArray\n\narray = MaskedArray\n\ndef isMaskedArray (x):\n \"Is x a masked array, that is, an instance of MaskedArray?\"\n return isinstance(x, MaskedArray)\n\nisarray = isMaskedArray\nisMA = isMaskedArray #backward compatibility\n\ndef allclose (a, b, fill_value=1, rtol=1.e-5, atol=1.e-8):\n \"\"\" Returns true if all components of a and b are equal\n subject to given tolerances.\n If fill_value is 1, masked values considered equal.\n If fill_value is 0, masked values considered unequal.\n The relative error rtol should be positive and << 1.0\n The absolute error atol comes into play for those elements\n of b that are very small or zero; it says how small a must be also.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a)\n d2 = filled(b)\n x = filled(array(d1, copy=0, mask=m), fill_value).astype(float)\n y = filled(array(d2, copy=0, mask=m), 1).astype(float)\n d = umath.less_equal(umath.absolute(x-y), atol + rtol * umath.absolute(y))\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n\ndef allequal (a, b, fill_value=1):\n \"\"\"\n True if all entries of a and b are equal, using\n fill_value as a truth value where either or both are masked.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n if m is None:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n elif fill_value:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n dm = array(d, mask=m, copy=0)\n return oldnumeric.alltrue(oldnumeric.ravel(filled(dm, 1)))\n else:\n return 0\n\ndef masked_values (data, value, rtol=1.e-5, atol=1.e-8, copy=1):\n \"\"\"\n masked_values(data, value, rtol=1.e-5, atol=1.e-8)\n Create a masked array; mask is None if possible.\n If copy==0, and otherwise possible, result\n may share data values with original array.\n Let d = filled(data, value). Returns d\n masked where abs(data-value)<= atol + rtol * abs(value)\n if d is of a floating point type. Otherwise returns\n masked_object(d, value, copy)\n \"\"\"\n abs = umath.absolute\n d = filled(data, value)\n if issubclass(d.dtype, numeric.floating):\n m = umath.less_equal(abs(d-value), atol+rtol*abs(value))\n m = make_mask(m, flag=1)\n return array(d, mask = m, copy=copy,\n fill_value=value)\n else:\n return masked_object(d, value, copy=copy)\n\ndef masked_object (data, value, copy=1):\n \"Create array masked where exactly data equal to value\"\n d = filled(data, value)\n dm = make_mask(umath.equal(d, value), flag=1)\n return array(d, mask=dm, copy=copy, fill_value=value)\n\ndef arrayrange(start, stop=None, step=1, dtype=None):\n \"\"\"Just like range() except it returns a array whose type can be specified\n by the keyword argument dtypechar.\n \"\"\"\n return array(numeric.arrayrange(start, stop, step, dtype))\n\narange = arrayrange\n\ndef fromstring (s, t):\n \"Construct a masked array from a string. Result will have no mask.\"\n return masked_array(numeric.fromstring(s, t))\n\ndef left_shift (a, n):\n \"Left shift n bits\"\n m = getmask(a)\n if m is None:\n d = umath.left_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.left_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef right_shift (a, n):\n \"Right shift n bits\"\n m = getmask(a)\n if m is None:\n d = umath.right_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.right_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef resize (a, new_shape):\n \"\"\"resize(a, new_shape) returns a new array with the specified shape.\n The original array's total size can be any size.\"\"\"\n m = getmask(a)\n if m is not None:\n m = oldnumeric.resize(m, new_shape)\n result = array(oldnumeric.resize(filled(a), new_shape), mask=m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n \"\"\"\n af = filled(a)\n if isinstance(repeats, types.IntType):\n repeats = tuple([repeats]*(shape(af)[axis]))\n\n m = getmask(a)\n if m is not None:\n m = oldnumeric.repeat(m, repeats, axis)\n d = oldnumeric.repeat(af, repeats, axis)\n result = masked_array(d, m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef identity(n):\n \"\"\"identity(n) returns the identity matrix of shape n x n.\n \"\"\"\n return array(numeric.identity(n))\n\ndef indices (dimensions, dtype=None):\n \"\"\"indices(dimensions,dtype=None) returns an array representing a grid\n of indices with row-only, and column-only variation.\n \"\"\"\n return array(numeric.indices(dimensions, dtype))\n\ndef zeros (shape, dtype=int):\n \"\"\"zeros(n, dtype=int) =\n an array of all zeros of the given length or shape.\"\"\"\n return array(numeric.zeros(shape, dtype))\n\ndef ones (shape, dtype=int):\n \"\"\"ones(n, dtype=int) =\n an array of all ones of the given length or shape.\"\"\"\n return array(numeric.ones(shape, dtype))\n\n\ndef count (a, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n a = masked_array(a)\n return a.count(axis)\n\ndef power (a, b, third=None):\n \"a**b\"\n if third is not None:\n raise MAError, \"3-argument power not supported.\"\n ma = getmask(a)\n mb = getmask(b)\n m = mask_or(ma, mb)\n fa = filled(a, 1)\n fb = filled(b, 1)\n if fb.dtypechar in typecodes[\"Integer\"]:\n return masked_array(umath.power(fa, fb), m)\n md = make_mask(umath.less_equal (fa, 0), flag=1)\n m = mask_or(m, md)\n if m is None:\n return masked_array(umath.power(fa, fb))\n else:\n fa = numeric.where(m, 1, fa)\n return masked_array(umath.power(fa, fb), m)\n\ndef masked_array (a, mask=None, fill_value=None):\n \"\"\"masked_array(a, mask=None) =\n array(a, mask=mask, copy=0, fill_value=fill_value)\n \"\"\"\n return array(a, mask=mask, copy=0, fill_value=fill_value)\n\nsum = add.reduce\nproduct = multiply.reduce\n\ndef average (a, axis=0, weights=None, returned = 0):\n \"\"\"average(a, axis=0, weights=None)\n Computes average along indicated axis.\n If axis is None, average over the entire array\n Inputs can be integer or floating types; result is of type float.\n\n If weights are given, result is sum(a*weights)/(sum(weights)*1.0)\n weights must have a's shape or be the 1-d with length the size\n of a in the given axis.\n\n If returned, return a tuple: the result and the sum of the weights\n or count of values. Results will have the same shape.\n\n masked values in the weights will be set to 0.0\n \"\"\"\n a = masked_array(a)\n mask = a.mask\n ash = a.shape\n if ash == ():\n ash = (1,)\n if axis is None:\n if mask is None:\n if weights is None:\n n = add.reduce(a.raw_data().ravel())\n d = reduce(lambda x, y: x * y, ash, 1.0)\n else:\n w = filled(weights, 0.0).ravel()\n n = umath.add.reduce(a.raw_data().ravel() * w)\n d = umath.add.reduce(w)\n del w\n else:\n if weights is None:\n n = add.reduce(a.ravel())\n w = oldnumeric.choose(mask, (1.0,0.0)).ravel()\n d = umath.add.reduce(w)\n del w\n else:\n w = array(filled(weights, 0.0), float, mask=mask).ravel()\n n = add.reduce(a.ravel() * w)\n d = add.reduce(w)\n del w\n else:\n if mask is None:\n if weights is None:\n d = ash[axis] * 1.0\n n = umath.add.reduce(a.raw_data(), axis)\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = numeric.array(w, float, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * ones(ash, float)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w, r\n else:\n raise ValueError, 'average: weights wrong shape.'\n else:\n if weights is None:\n n = add.reduce(a, axis)\n w = numeric.choose(mask, (1.0, 0.0))\n d = umath.add.reduce(w, axis)\n del w\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = array(w, float, mask=mask, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * masked_array(ones(ash, float), mask)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n else:\n raise ValueError, 'average: weights wrong shape.'\n del w\n #print n, d, repr(mask), repr(weights)\n if n is masked or d is masked: return masked\n result = divide (n, d)\n del n\n\n if isinstance(result, MaskedArray):\n result.unmask()\n if returned:\n if not isinstance(d, MaskedArray):\n d = masked_array(d)\n if not d.shape == result.shape:\n d = ones(result.shape, float) * d\n d.unmask()\n if returned:\n return result, d\n else:\n return result\n\ndef where (condition, x, y):\n \"\"\"where(condition, x, y) is x where condition is nonzero, y otherwise.\n condition must be convertible to an integer array.\n Answer is always the shape of condition.\n The type depends on x and y. It is integer if both x and y are\n the value masked.\n \"\"\"\n fc = filled(not_equal(condition,0), 0)\n if x is masked:\n xv = 0\n xm = 1\n else:\n xv = filled(x)\n xm = getmask(x)\n if xm is None: xm = 0\n if y is masked:\n yv = 0\n ym = 1\n else:\n yv = filled(y)\n ym = getmask(y)\n if ym is None: ym = 0\n d = numeric.choose(fc, (yv, xv))\n md = numeric.choose(fc, (ym, xm))\n m = getmask(condition)\n m = make_mask(mask_or(m, md), copy=0, flag=1)\n return masked_array(d, m)\n\ndef choose (indices, t):\n \"Returns array shaped like indices with elements chosen from t\"\n def fmask (x):\n if x is masked: return 1\n return filled(x)\n def nmask (x):\n if x is masked: return 1\n m = getmask(x)\n if m is None: return 0\n return m\n c = filled(indices,0)\n masks = [nmask(x) for x in t]\n a = [fmask(x) for x in t]\n d = numeric.choose(c, a)\n m = numeric.choose(c, masks)\n m = make_mask(mask_or(m, getmask(indices)), copy=0, flag=1)\n return masked_array(d, m)\n\ndef masked_where(condition, x, copy=1):\n \"\"\"Return x as an array masked where condition is true.\n Also masked where x or condition masked.\n \"\"\"\n cm = filled(condition,1)\n m = mask_or(getmask(x), cm)\n return array(filled(x), copy=copy, mask=m)\n\ndef masked_greater(x, value, copy=1):\n \"masked_greater(x, value) = x masked where x > value\"\n return masked_where(greater(x, value), x, copy)\n\ndef masked_greater_equal(x, value, copy=1):\n \"masked_greater_equal(x, value) = x masked where x >= value\"\n return masked_where(greater_equal(x, value), x, copy)\n\ndef masked_less(x, value, copy=1):\n \"masked_less(x, value) = x masked where x < value\"\n return masked_where(less(x, value), x, copy)\n\ndef masked_less_equal(x, value, copy=1):\n \"masked_less_equal(x, value) = x masked where x <= value\"\n return masked_where(less_equal(x, value), x, copy)\n\ndef masked_not_equal(x, value, copy=1):\n \"masked_not_equal(x, value) = x masked where x != value\"\n d = filled(x,0)\n c = umath.not_equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_equal(x, value, copy=1):\n \"\"\"masked_equal(x, value) = x masked where x == value\n For floating point consider masked_values(x, value) instead.\n \"\"\"\n d = filled(x,0)\n c = umath.equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_inside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are inside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d=filled(x, 0)\n c = umath.logical_and(umath.less_equal(d, v2), umath.greater_equal(d, v1))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef masked_outside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are outside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d = filled(x,0)\n c = umath.logical_or(umath.less(d, v1), umath.greater(d, v2))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef reshape (a, *newshape):\n \"Copy of a with a new shape.\"\n m = getmask(a)\n d = filled(a).reshape(*newshape)\n if m is None:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.reshape(m, *newshape))\n\ndef ravel (a):\n \"a as one-dimensional, may share data and mask\"\n m = getmask(a)\n d = oldnumeric.ravel(filled(a))\n if m is None:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.ravel(m))\n\ndef concatenate (arrays, axis=0):\n \"Concatenate the arrays along the given axis\"\n d = []\n for x in arrays:\n d.append(filled(x))\n d = numeric.concatenate(d, axis)\n for x in arrays:\n if getmask(x) is not None: break\n else:\n return masked_array(d)\n dm = []\n for x in arrays:\n dm.append(getmaskarray(x))\n dm = numeric.concatenate(dm, axis)\n return masked_array(d, mask=dm)\n\ndef take (a, indices, axis=0):\n \"take(a, indices, axis=0) returns selection of items from a.\"\n m = getmask(a)\n d = masked_array(a).raw_data()\n if m is None:\n return masked_array(numeric.take(d, indices, axis))\n else:\n return masked_array(numeric.take(d, indices, axis),\n mask = numeric.take(m, indices, axis))\n\ndef transpose(a, axes=None):\n \"transpose(a, axes=None) reorder dimensions per tuple axes\"\n m = getmask(a)\n d = filled(a)\n if m is None:\n return masked_array(numeric.transpose(d, axes))\n else:\n return masked_array(numeric.transpose(d, axes),\n mask = numeric.transpose(m, axes))\n\n\ndef put(a, indices, values):\n \"\"\"put(a, indices, values) sets storage-indexed locations to corresponding values.\n\n Values and indices are filled if necessary.\n\n \"\"\"\n d = a.raw_data()\n ind = filled(indices)\n v = filled(values)\n numeric.put (d, ind, v)\n m = getmask(a)\n if m is not None:\n a.unshare_mask()\n numeric.put(a.raw_mask(), ind, 0)\n\ndef putmask(a, mask, values):\n \"putmask(a, mask, values) sets a where mask is true.\"\n if mask is None:\n return\n numeric.putmask(a.raw_data(), mask, values)\n m = getmask(a)\n if m is None: return\n a.unshare_mask()\n numeric.putmask(a.raw_mask(), mask, 0)\n\ndef innerproduct(a,b):\n \"\"\"innerproduct(a,b) returns the dot product of two arrays, which has\n shape a.shape[:-1] + b.shape[:-1] with elements computed by summing the\n product of the elements from the last dimensions of a and b.\n Masked elements are replace by zeros.\n \"\"\"\n fa = filled(a, 0)\n fb = filled(b, 0)\n if len(fa.shape) == 0: fa.shape = (1,)\n if len(fb.shape) == 0: fb.shape = (1,)\n return masked_array(numeric.innerproduct(fa, fb))\n\ndef outerproduct(a, b):\n \"\"\"outerproduct(a,b) = {a[i]*b[j]}, has shape (len(a),len(b))\"\"\"\n fa = filled(a,0).ravel()\n fb = filled(b,0).ravel()\n d = numeric.outerproduct(fa, fb)\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n return masked_array(d)\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = make_mask(1-numeric.outerproduct(1-ma,1-mb), copy=0)\n return masked_array(d, m)\n\ndef dot(a, b):\n \"\"\"dot(a,b) returns matrix-multiplication between a and b. The product-sum\n is over the last dimension of a and the second-to-last dimension of b.\n Masked values are replaced by zeros. See also innerproduct.\n \"\"\"\n return innerproduct(filled(a,0), numeric.swapaxes(filled(b,0), -1, -2))\n\ndef compress(condition, x, dimension=-1):\n \"\"\"Select those parts of x for which condition is true.\n Masked values in condition are considered false.\n \"\"\"\n c = filled(condition, 0)\n m = getmask(x)\n if m is not None:\n m=numeric.compress(c, m, dimension)\n d = numeric.compress(c, filled(x), dimension)\n return masked_array(d, m)\n\nclass _minimum_operation:\n \"Object to calculate minima\"\n def __init__ (self):\n \"\"\"minimum(a, b) or minimum(a)\n In one argument case returns the scalar minimum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is None:\n d = amin(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amin(ac.raw_data())\n else:\n return where(less(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is None:\n t = filled(target)\n return masked_array (umath.minimum.reduce (t, axis))\n else:\n t = umath.minimum.reduce(filled(target, minimum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n m = None\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.minimum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nminimum = _minimum_operation ()\n\nclass _maximum_operation:\n \"Object to calculate maxima\"\n def __init__ (self):\n \"\"\"maximum(a, b) or maximum(a)\n In one argument case returns the scalar maximum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is None:\n d = amax(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amax(ac.raw_data())\n else:\n return where(greater(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is None:\n t = filled(target)\n return masked_array (umath.maximum.reduce (t, axis))\n else:\n t = umath.maximum.reduce(filled(target, maximum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n m = None\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.maximum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nmaximum = _maximum_operation ()\n\ndef sort (x, axis = -1, fill_value=None):\n \"\"\"If x does not have a mask, return a masked array formed from the\n result of numeric.sort(x, axis).\n Otherwise, fill x with fill_value. Sort it.\n Set a mask where the result is equal to fill_value.\n Note that this may have unintended consequences if the data contains the\n fill value at a non-masked site.\n\n If fill_value is not given the default fill value for x's type will be\n used.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n d = filled(x, fill_value)\n s = oldnumeric.sort(d, axis)\n if getmask(x) is None:\n return masked_array(s)\n return masked_values(s, fill_value, copy=0)\n\ndef diagonal(a, k = 0, axis1=0, axis2=1):\n \"\"\"diagonal(a,k=0,axis1=0, axis2=1) = the k'th diagonal of a\"\"\"\n d = oldnumeric.diagonal(filled(a), k, axis1, axis2)\n m = getmask(a)\n if m is None:\n return masked_array(d, m)\n else:\n return masked_array(d, oldnumeric.diagonal(m, k, axis1, axis2))\n\ndef argsort (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for sorting along given axis.\n if fill_value is None, use get_fill_value(x)\n Returns a numpy array.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argsort(d, axis)\n\ndef argmin (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return indices for minimum values along given axis.\n if fill_value is None, use get_fill_value(x).\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argmin(d, axis)\n\ndef argmax (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for maximum along given axis.\n if fill_value is None, use -get_fill_value(x) if it exists.\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n try:\n fill_value = - fill_value\n except:\n pass\n d = filled(x, fill_value)\n return oldnumeric.argmax(d, axis)\n\ndef fromfunction (f, s):\n \"\"\"apply f to s to create array as in umath.\"\"\"\n return masked_array(numeric.fromfunction(f,s))\n\ndef asarray(data, dtype=None):\n \"\"\"asarray(data, dtype) = array(data, dtype, copy=0)\n \"\"\"\n if isinstance(data, MaskedArray) and \\\n (dtype is None or dtype == data.dtype):\n return data\n return array(data, dtype=dtype, copy=0)\n\n# Add methods to support ndarray interface\n# XXX: I is better to to change the masked_*_operation adaptors\n# XXX: to wrap ndarray methods directly to create ma.array methods.\nfrom types import MethodType\ndef _m(f):\n return MethodType(f, None, array)\ndef not_implemented(*args, **kwds):\n raise NotImplementedError, \"not yet implemented for numpy.ma arrays\"\narray.all = _m(alltrue)\narray.any = _m(sometrue)\narray.argmax = _m(argmax)\narray.argmin = _m(argmin)\narray.argsort = _m(argsort)\narray.base = property(_m(not_implemented))\narray.byteswap = _m(not_implemented)\n\ndef _choose(self, *args):\n return choose(self, args)\narray.choose = _m(_choose)\ndel _choose\n\narray.clip = _m(not_implemented)\n\ndef _compress(self, cond, axis=None):\n return compress(cond, self, axis)\narray.compress = _m(_compress)\ndel _compress\n\narray.conj = array.conjugate = _m(conjugate)\narray.copy = _m(not_implemented)\narray.cumprod = _m(not_implemented)\narray.cumsum = _m(not_implemented)\narray.diagonal = _m(diagonal)\narray.dtypedescr = property(_m(not_implemented))\narray.dtypestr = property(_m(not_implemented))\narray.dump = _m(not_implemented)\narray.dumps = _m(not_implemented)\narray.fill = _m(not_implemented)\narray.flags = property(_m(not_implemented))\narray.flatten = _m(ravel)\narray.getfield = _m(not_implemented)\narray.max = _m(maximum)\narray.mean = _m(average)\narray.min = _m(minimum)\narray.nbytes = property(_m(not_implemented))\narray.ndim = _m(not_implemented)\narray.newbyteorder = _m(not_implemented)\narray.nonzero = _m(nonzero)\narray.prod = _m(product)\narray.ptp = _m(not_implemented)\narray.repeat = _m(repeat)\narray.resize = _m(resize)\narray.searchsorted = _m(not_implemented)\narray.setfield = _m(not_implemented)\narray.setflags = _m(not_implemented)\narray.sort = _m(not_implemented) # NB: ndarray.sort is inplace\narray.squeeze = _m(not_implemented)\narray.std = _m(not_implemented)\narray.strides = property(_m(not_implemented))\narray.sum = _m(sum)\narray.swapaxes = _m(not_implemented)\narray.take = _m(take)\narray.tofile = _m(not_implemented)\narray.trace = _m(not_implemented)\narray.transpose = _m(transpose)\narray.var = _m(not_implemented)\narray.view = _m(not_implemented)\ndel _m, MethodType, not_implemented\n\n\nmasked = MaskedArray([0], int, mask=[1])[0:0]\nmasked = masked[0:0]\n", + "source_code_before": "\"\"\"MA: a facility for dealing with missing observations\nMA is generally used as a numpy.array look-alike.\nby Paul F. Dubois.\n\nCopyright 1999, 2000, 2001 Regents of the University of California.\nReleased for unlimited redistribution.\nAdapted for numpy_core 2005 by Travis Oliphant and\n(mainly) Paul Dubois.\n\"\"\"\nimport string, types, sys\n\nimport umath\nimport oldnumeric\nfrom numeric import e, pi, newaxis, ndarray, inf\nfrom oldnumeric import typecodes, amax, amin\nfrom numerictypes import *\nimport numeric\n\n \nMaskType=bool_\ndivide_tolerance = 1.e-35\n\nclass MAError (Exception):\n def __init__ (self, args=None):\n \"Create an exception\"\n self.args = args\n def __str__(self):\n \"Calculate the string representation\"\n return str(self.args)\n __repr__ = __str__\n\nclass _MaskedPrintOption:\n \"One instance of this class, masked_print_option, is created.\"\n def __init__ (self, display):\n \"Create the masked print option object.\"\n self.set_display(display)\n self._enabled = 1\n\n def display (self):\n \"Show what prints for masked values.\"\n return self._display\n\n def set_display (self, s):\n \"set_display(s) sets what prints for masked values.\"\n self._display = s\n\n def enabled (self):\n \"Is the use of the display value enabled?\"\n return self._enabled\n\n def enable(self, flag=1):\n \"Set the enabling flag to flag.\"\n self._enabled = flag\n\n def __str__ (self):\n return str(self._display)\n\n __repr__ = __str__\n \n#if you single index into a masked location you get this object.\nmasked_print_option = _MaskedPrintOption('--')\n\n# Use single element arrays or scalars.\ndefault_real_fill_value = 1.e20\ndefault_complex_fill_value = 1.e20 + 0.0j\ndefault_character_fill_value = '-'\ndefault_integer_fill_value = 999999\ndefault_object_fill_value = '?'\n\ndef default_fill_value (obj):\n \"Function to calculate default fill value for an object.\"\n if isinstance(obj, types.FloatType):\n return default_real_fill_value\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return default_integer_fill_value\n elif isinstance(obj, types.StringType):\n return default_character_fill_value\n elif isinstance(obj, types.ComplexType):\n return default_complex_fill_value\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return default_real_fill_value\n if x in typecodes['Integer']:\n return default_integer_fill_value\n if x in typecodes['Complex']:\n return default_complex_fill_value\n if x in typecodes['Character']:\n return default_character_fill_value\n if x in typecodes['UnsignedInteger']:\n return umath.absolute(default_integer_fill_value)\n return default_object_fill_value\n else:\n return default_object_fill_value\n\ndef minimum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking minima.\"\n if isinstance(obj, types.FloatType):\n return numeric.inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return numeric.inf\n if x in typecodes['Integer']:\n return sys.maxint\n if x in typecodes['UnsignedInteger']:\n return sys.maxint\n else:\n raise TypeError, 'Unsuitable type for calculating minimum.'\n\ndef maximum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking maxima.\"\n if isinstance(obj, types.FloatType):\n return -inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return -sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return -inf\n if x in typecodes['Integer']:\n return -sys.maxint\n if x in typecodes['UnsignedInteger']:\n return 0\n else:\n raise TypeError, 'Unsuitable type for calculating maximum.'\n\ndef set_fill_value (a, fill_value):\n \"Set fill value of a if it is a masked array.\"\n if isMaskedArray(a):\n a.set_fill_value (fill_value)\n\ndef getmask (a):\n \"\"\"Mask of values in a; could be None.\n Returns None if a is not a masked array.\n To get an array for sure use getmaskarray.\"\"\"\n if isinstance(a, MaskedArray):\n return a.raw_mask()\n else:\n return None\n\ndef getmaskarray (a):\n \"\"\"Mask of values in a; an array of zeros if mask is None\n or not a masked array, and is a byte-sized integer.\n Do not try to add up entries, for example.\n \"\"\"\n m = getmask(a)\n if m is None:\n return make_mask_none(shape(a))\n else:\n return m\n\ndef is_mask (m):\n \"\"\"Is m a legal mask? Does not check contents, only type.\n \"\"\"\n if m is None or (isinstance(m, ndarray) and \\\n m.dtype is MaskType):\n return 1\n else:\n return 0\n\ndef make_mask (m, copy=0, flag=0):\n \"\"\"make_mask(m, copy=0, flag=0)\n return m as a mask, creating a copy if necessary or requested.\n Can accept any sequence of integers or None. Does not check\n that contents must be 0s and 1s.\n if flag, return None if m contains no true elements.\n \"\"\"\n if m is None:\n return None\n elif isinstance(m, ndarray):\n if m.dtype is MaskType:\n if copy:\n result = numeric.array(m, dtype=MaskType, copy=copy)\n else:\n result = m\n else:\n result = m.astype(MaskType)\n else:\n result = filled(m,True).astype(MaskType)\n\n if flag and not oldnumeric.sometrue(oldnumeric.ravel(result)):\n return None\n else:\n return result\n\ndef make_mask_none (s):\n \"Return a mask of all zeros of shape s.\"\n result = numeric.zeros(s, dtype=MaskType)\n result.shape = s\n return result\n\ndef mask_or (m1, m2):\n \"\"\"Logical or of the mask candidates m1 and m2, treating None as false.\n Result may equal m1 or m2 if the other is None.\n \"\"\"\n if m1 is None: return make_mask(m2)\n if m2 is None: return make_mask(m1)\n if m1 is m2 and is_mask(m1): return m1\n return make_mask(umath.logical_or(m1, m2))\n\ndef filled (a, value = None):\n \"\"\"a as a contiguous numeric array with any masked areas replaced by value\n if value is None or the special element \"masked\", get_fill_value(a)\n is used instead.\n\n If a is already a contiguous numeric array, a itself is returned.\n\n filled(a) can be used to be sure that the result is numeric when\n passing an object a to other software ignorant of MA, in particular to\n numeric itself.\n \"\"\"\n if isinstance(a, MaskedArray):\n return a.filled(value)\n elif isinstance(a, ndarray) and a.flags['CONTIGUOUS']:\n return a\n elif isinstance(a, types.DictType):\n return numeric.array(a, 'O')\n else:\n return numeric.array(a)\n\ndef get_fill_value (a):\n \"\"\"\n The fill value of a, if it has one; otherwise, the default fill value\n for that type.\n \"\"\"\n if isMaskedArray(a):\n result = a.fill_value()\n else:\n result = default_fill_value(a)\n return result\n\ndef common_fill_value (a, b):\n \"The common fill_value of a and b, if there is one, or None\"\n t1 = get_fill_value(a)\n t2 = get_fill_value(b)\n if t1 == t2: return t1\n return None\n\n# Domain functions return 1 where the argument(s) are not in the domain.\nclass domain_check_interval:\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n def __init__(self, y1, y2):\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n self.y1 = y1\n self.y2 = y2\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.logical_or(umath.greater (x, self.y2),\n umath.less(x, self.y1)\n )\n\nclass domain_tan:\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n def __init__(self, eps):\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n self.eps = eps\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less(umath.absolute(umath.cos(x)), self.eps)\n\nclass domain_greater:\n \"domain_greater(v)(x) = true where x <= v\"\n def __init__(self, critical_value):\n \"domain_greater(v)(x) = true where x <= v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less_equal (x, self.critical_value)\n\nclass domain_greater_equal:\n \"domain_greater_equal(v)(x) = true where x < v\"\n def __init__(self, critical_value):\n \"domain_greater_equal(v)(x) = true where x < v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less (x, self.critical_value)\n\nclass masked_unary_operation:\n def __init__ (self, aufunc, fill=0, domain=None):\n \"\"\" masked_unary_operation(aufunc, fill=0, domain=None)\n aufunc(fill) must be defined\n self(x) returns aufunc(x)\n with masked values where domain(x) is true or getmask(x) is true.\n \"\"\"\n self.f = aufunc\n self.fill = fill\n self.domain = domain\n self.__doc__ = getattr(aufunc, \"__doc__\", str(aufunc))\n\n def __call__ (self, a, *args, **kwargs):\n \"Execute the call behavior.\"\n# numeric tries to return scalars rather than arrays when given scalars.\n m = getmask(a)\n d1 = filled(a, self.fill)\n if self.domain is not None:\n m = mask_or(m, self.domain(d1))\n result = self.f(d1, *args, **kwargs)\n if m is not None:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\n\nclass domain_safe_divide:\n def __init__ (self, tolerance=divide_tolerance):\n self.tolerance = tolerance\n def __call__ (self, a, b):\n return umath.absolute(a) * self.tolerance >= umath.absolute(b)\n\nclass domained_binary_operation:\n \"\"\"Binary operations that have a domain, like divide. These are complicated so they\n are a separate class. They have no reduce, outer or accumulate.\n \"\"\"\n def __init__ (self, abfunc, domain, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.domain = domain\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__(self, a, b):\n \"Execute the call behavior.\"\n ma = getmask(a)\n mb = getmask(b)\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n t = self.domain(d1, d2)\n\n if oldnumeric.sometrue(t, None):\n d2 = where(t, self.filly, d2)\n mb = mask_or(mb, t)\n m = mask_or(ma, mb)\n result = self.f(d1, d2)\n if m is not None:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n \n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nclass masked_binary_operation:\n def __init__ (self, abfunc, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__ (self, a, b, *args, **kwargs):\n \"Execute the call behavior.\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n result = self.f(d1, d2, *args, **kwargs)\n if m is not None:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis with this function.\"\"\"\n m = getmask(target)\n t = filled(target, self.filly)\n if t.shape == ():\n t = t.reshape(1)\n if m is not None:\n m = make_mask(m, copy=1)\n m.shape = (1,)\n if m is None:\n return masked_array (self.f.reduce (t, axis))\n else:\n t = masked_array (t, m)\n t = self.f.reduce(filled(t, self.filly), axis)\n m = umath.logical_and.reduce(m, axis)\n if isinstance(t, ndarray):\n return masked_array(t, m, get_fill_value(target))\n elif m:\n return masked\n else:\n return t\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n m = None\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = self.f.outer(filled(a, self.fillx), filled(b, self.filly))\n return masked_array(d, m)\n\n def accumulate (self, target, axis=0):\n \"\"\"Accumulate target along axis after filling with y fill value.\"\"\"\n t = filled(target, self.filly)\n return masked_array (self.f.accumulate (t, axis))\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nsqrt = masked_unary_operation(umath.sqrt, 0.0, domain_greater_equal(0.0))\nlog = masked_unary_operation(umath.log, 1.0, domain_greater(0.0))\nlog10 = masked_unary_operation(umath.log10, 1.0, domain_greater(0.0))\nexp = masked_unary_operation(umath.exp)\nconjugate = masked_unary_operation(umath.conjugate)\nsin = masked_unary_operation(umath.sin)\ncos = masked_unary_operation(umath.cos)\ntan = masked_unary_operation(umath.tan, 0.0, domain_tan(1.e-35))\narcsin = masked_unary_operation(umath.arcsin, 0.0, domain_check_interval(-1.0, 1.0))\narccos = masked_unary_operation(umath.arccos, 0.0, domain_check_interval(-1.0, 1.0))\narctan = masked_unary_operation(umath.arctan)\n# Missing from numeric\narcsinh = masked_unary_operation(umath.arcsinh)\narccosh = masked_unary_operation(umath.arccosh)\narctanh = masked_unary_operation(umath.arctanh)\nsinh = masked_unary_operation(umath.sinh)\ncosh = masked_unary_operation(umath.cosh)\ntanh = masked_unary_operation(umath.tanh)\nabsolute = masked_unary_operation(umath.absolute)\nfabs = masked_unary_operation(umath.fabs)\nnegative = masked_unary_operation(umath.negative)\nnonzero = masked_unary_operation(oldnumeric.nonzero)\naround = masked_unary_operation(oldnumeric.round_)\nfloor = masked_unary_operation(umath.floor)\nceil = masked_unary_operation(umath.ceil)\nsometrue = masked_unary_operation(oldnumeric.sometrue)\nalltrue = masked_unary_operation(oldnumeric.alltrue, 1)\nlogical_not = masked_unary_operation(umath.logical_not)\n\nadd = masked_binary_operation(umath.add)\nsubtract = masked_binary_operation(umath.subtract)\nsubtract.reduce = None\nmultiply = masked_binary_operation(umath.multiply, 1, 1)\ndivide = domained_binary_operation(umath.divide, domain_safe_divide(), 0, 1)\ntrue_divide = domained_binary_operation(umath.true_divide, domain_safe_divide(), 0, 1)\nfloor_divide = domained_binary_operation(umath.floor_divide, domain_safe_divide(), 0, 1)\nremainder = domained_binary_operation(umath.remainder, domain_safe_divide(), 0, 1)\nfmod = domained_binary_operation(umath.fmod, domain_safe_divide(), 0, 1)\nhypot = masked_binary_operation(umath.hypot)\narctan2 = masked_binary_operation(umath.arctan2, 0.0, 1.0)\narctan2.reduce = None\nequal = masked_binary_operation(umath.equal)\nequal.reduce = None\nnot_equal = masked_binary_operation(umath.not_equal)\nnot_equal.reduce = None\nless_equal = masked_binary_operation(umath.less_equal)\nless_equal.reduce = None\ngreater_equal = masked_binary_operation(umath.greater_equal)\ngreater_equal.reduce = None\nless = masked_binary_operation(umath.less)\nless.reduce = None\ngreater = masked_binary_operation(umath.greater)\ngreater.reduce = None\nlogical_and = masked_binary_operation(umath.logical_and)\nlogical_or = masked_binary_operation(umath.logical_or)\nlogical_xor = masked_binary_operation(umath.logical_xor)\nbitwise_and = masked_binary_operation(umath.bitwise_and)\nbitwise_or = masked_binary_operation(umath.bitwise_or)\nbitwise_xor = masked_binary_operation(umath.bitwise_xor)\n\ndef rank (object):\n return oldnumeric.rank(filled(object))\n\ndef shape (object):\n return oldnumeric.shape(filled(object))\n\ndef size (object, axis=None):\n return oldnumeric.size(filled(object), axis)\n\nclass MaskedArray (object):\n \"\"\"Arrays with possibly masked values.\n Masked values of 1 exclude the corresponding element from \n any computation.\n\n Construction:\n x = array(data, dtype=None, copy=True, fortran=False,\n mask = None, fill_value=None)\n\n If copy=False, every effort is made not to copy the data:\n If data is a MaskedArray, and argument mask=None,\n then the candidate data is data.data and the\n mask used is data.mask. If data is a numeric array,\n it is used as the candidate raw data.\n If dtypechar is not None and\n is != data.dtypechar then a data copy is required.\n Otherwise, the candidate is used.\n\n If a data copy is required, raw data stored is the result of:\n numeric.array(data, dtype=dtypechar, copy=copy)\n\n If mask is None there are no masked values. Otherwise mask must\n be convertible to an array of booleans with the same shape as x.\n\n fill_value is used to fill in masked values when necessary,\n such as when printing and in method/function filled().\n The fill_value is not used for computation within this module.\n \"\"\"\n __array_priority__ = 10.1\n def __init__(self, data, dtype=None, copy=True, fortran=False, \n mask=None, fill_value=None):\n \"\"\"array(data, dtype=None, copy=True, fortran=False, mask=None, fill_value=None)\n If data already a numeric array, its dtype becomes the default value of dtype.\n \"\"\"\n tc = dtype\n need_data_copied = copy\n if isinstance(data, MaskedArray):\n c = data.data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n if mask is None:\n mask = data.mask\n elif mask is not None: #attempting to change the mask\n need_data_copied = True\n\n elif isinstance(data, ndarray):\n c = data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n else:\n need_data_copied = False #because I'll do it now\n c = numeric.array(data, dtype=tc, copy=True, fortran=fortran)\n\n if need_data_copied:\n if tc == ctc:\n self._data = numeric.array(c, dtype=tc, copy=True, fortran=fortran)\n else:\n self._data = c.astype(tc)\n else:\n self._data = c\n\n if mask is None:\n self._mask = None\n self._shared_mask = 0\n else:\n self._mask = make_mask (mask)\n if self._mask is None:\n self._shared_mask = 0\n else:\n self._shared_mask = (self._mask is mask)\n nm = size(self._mask)\n nd = size(self._data)\n if nm != nd:\n if nm == 1:\n self._mask = oldnumeric.resize(self._mask, self._data.shape)\n self._shared_mask = 0\n elif nd == 1:\n self._data = oldnumeric.resize(self._data, self._mask.shape)\n self._data.shape = self._mask.shape\n else:\n raise MAError, \"Mask and data not compatible.\"\n elif nm == 1 and shape(self._mask) != shape(self._data):\n self.unshare_mask()\n self._mask.shape = self._data.shape\n\n self.set_fill_value(fill_value)\n\n def __array__ (self, t = None):\n \"Special hook for numeric. Converts to numeric if possible.\"\n if self._mask is not None:\n if oldnumeric.ravel(self._mask).any():\n raise MAError, \\\n \"\"\"Cannot automatically convert masked array to numeric because data\n is masked in one or more locations.\n \"\"\"\n else: # Mask is all false\n # Optimize to avoid future invocations of this section.\n self._mask = None\n self._shared_mask = 0\n if t:\n return self._data.astype(t)\n else:\n return self._data\n\n def __array_wrap__ (self, array):\n \"\"\"Special hook for ufuncs. Converts to Masked array with\n the same mask as self.\"\"\"\n return MaskedArray(array, copy=False, mask=self._mask,\n fill_value = self._fill_value)\n \n def _get_shape(self):\n \"Return the current shape.\"\n return self._data.shape\n\n def _set_shape (self, newshape):\n \"Set the array's shape.\"\n self._data.shape = newshape\n if self._mask is not None:\n self._mask = self._mask.copy()\n self._mask.shape = newshape\n\n def _get_flat(self):\n \"\"\"Calculate the flat value.\n \"\"\"\n if self._mask is None:\n return masked_array(self._data.ravel(), mask=None,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.ravel(),\n mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_flat (self, value):\n \"x.flat = value\"\n y = self.ravel()\n y[:] = value\n\n def _get_real(self):\n \"Get the real part of a complex array.\"\n if self._mask is None:\n return masked_array(self._data.real, mask=None,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.real, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_real (self, value):\n \"x.real = value\"\n y = self.real\n y[...] = value\n\n def _get_imaginary(self):\n \"Get the imaginary part of a complex array.\"\n if self._mask is None:\n return masked_array(self._data.imag, mask=None,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.imag, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_imaginary (self, value):\n \"x.imaginary = value\"\n y = self.imaginary\n y[...] = value\n\n def __str__(self):\n \"\"\"Calculate the str representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n if masked_print_option.enabled():\n f = masked_print_option\n # XXX: Without the following special case masked\n # XXX: would print as \"[--]\", not \"--\". Can we avoid\n # XXX: checks for masked by choosing a different value\n # XXX: for the masked singleton? 2005-01-05 -- sasha\n if self is masked:\n return str(f)\n # convert to object array to make filled work\n self = self.astype(object)\n else:\n f = self.fill_value()\n res = self.filled(f)\n return str(res)\n\n def __repr__(self):\n \"\"\"Calculate the repr representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n with_mask = \"\"\"\\\narray(data =\n %(data)s,\n mask =\n %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n with_mask1 = \"\"\"\\\narray(data = %(data)s,\n mask = %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n without_mask = \"\"\"array(\n %(data)s)\"\"\"\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n\n n = len(self.shape)\n if self._mask is None:\n if n <=1:\n return without_mask1 % {'data':str(self.filled())}\n return without_mask % {'data':str(self.filled())}\n else:\n if n <=1:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n if self._mask is None:\n return without_mask % {'data':str(self.filled())}\n else:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n\n def __float__(self):\n \"Convert self to float.\"\n self.unmask()\n if self._mask is not None:\n raise MAError, 'Cannot convert masked element to a Python float.'\n return float(self.data.item())\n\n def __int__(self):\n \"Convert self to int.\"\n self.unmask()\n if self._mask is not None:\n raise MAError, 'Cannot convert masked element to a Python int.'\n return int(self.data.item())\n\n def __getitem__(self, i):\n \"Get item described by i. Not a copy as in previous versions.\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i]\n if m is None:\n return dout\n mi = m[i]\n if mi.size == 1:\n if mi: \n return masked\n else:\n return dout\n else:\n return masked_array(dout, mi, fill_value=self._fill_value)\n\n def __getslice__(self, i, j):\n \"Get slice described by i, j\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i:j]\n if m is None:\n return masked_array(dout, fill_value=self._fill_value)\n else:\n return masked_array(dout, mask = m[i:j], fill_value=self._fill_value)\n\n# --------\n# setitem and setslice notes\n# note that if value is masked, it means to mask those locations.\n# setting a value changes the mask to match the value in those locations.\n\n def __setitem__(self, index, value):\n \"Set item described by index. If value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, 'Cannot alter the masked element.'\n if value is masked:\n if self._mask is None:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n else:\n self.unshare_mask()\n self._mask[index] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[index] = value\n if m is None:\n if self._mask is not None:\n self.unshare_mask()\n self._mask[index] = False\n else:\n if self._mask is None:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = True\n else:\n self.unshare_mask()\n self._mask[index] = m\n\n def __setslice__(self, i, j, value):\n \"Set slice i:j; if value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, \"Cannot alter the 'masked' object.\"\n if value is masked:\n if self._mask is None:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n self._mask[i:j] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[i:j] = value\n if m is None:\n if self._mask is not None:\n self.unshare_mask()\n self._mask[i:j] = False\n else:\n if self._mask is None:\n self._mask = make_mask_none(self._data.shape)\n self._shared_mask = False\n self._mask[i:j] = m\n\n def __nonzero__(self):\n \"\"\"returns true if any element is non-zero or masked\n\n \"\"\"\n # XXX: This changes bool conversion logic from MA.\n # XXX: In MA bool(a) == len(a) != 0, but in numpy\n # XXX: scalars do not have len \n m = self._mask\n d = self._data\n return bool(m is not None and m.any()\n or d is not None and d.any())\n \n def __len__ (self):\n \"\"\"Return length of first dimension. This is weird but Python's\n slicing behavior depends on it.\"\"\"\n return len(self._data)\n\n def __and__(self, other):\n \"Return bitwise_and\"\n return bitwise_and(self, other)\n\n def __or__(self, other):\n \"Return bitwise_or\"\n return bitwise_or(self, other)\n\n def __xor__(self, other):\n \"Return bitwise_xor\"\n return bitwise_xor(self, other)\n\n __rand__ = __and__\n __ror__ = __or__\n __rxor__ = __xor__\n\n def __abs__(self):\n \"Return absolute(self)\"\n return absolute(self)\n\n def __neg__(self):\n \"Return negative(self)\"\n return negative(self)\n\n def __pos__(self):\n \"Return array(self)\"\n return array(self)\n\n def __add__(self, other):\n \"Return add(self, other)\"\n return add(self, other)\n\n __radd__ = __add__\n\n def __mod__ (self, other):\n \"Return remainder(self, other)\"\n return remainder(self, other)\n\n def __rmod__ (self, other):\n \"Return remainder(other, self)\"\n return remainder(other, self)\n\n def __lshift__ (self, n):\n return left_shift(self, n)\n\n def __rshift__ (self, n):\n return right_shift(self, n)\n\n def __sub__(self, other):\n \"Return subtract(self, other)\"\n return subtract(self, other)\n\n def __rsub__(self, other):\n \"Return subtract(other, self)\"\n return subtract(other, self)\n\n def __mul__(self, other):\n \"Return multiply(self, other)\"\n return multiply(self, other)\n\n __rmul__ = __mul__\n\n def __div__(self, other):\n \"Return divide(self, other)\"\n return divide(self, other)\n\n def __rdiv__(self, other):\n \"Return divide(other, self)\"\n return divide(other, self)\n\n def __truediv__(self, other):\n \"Return divide(self, other)\"\n return true_divide(self, other)\n\n def __rtruediv__(self, other):\n \"Return divide(other, self)\"\n return true_divide(other, self)\n\n def __floordiv__(self, other):\n \"Return divide(self, other)\"\n return floor_divide(self, other)\n\n def __rfloordiv__(self, other):\n \"Return divide(other, self)\"\n return floor_divide(other, self)\n\n def __pow__(self,other, third=None):\n \"Return power(self, other, third)\"\n return power(self, other, third)\n\n def __sqrt__(self):\n \"Return sqrt(self)\"\n return sqrt(self)\n\n def __iadd__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is None:\n self._data += f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not None\n else:\n result = add(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __imul__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is None:\n self._data *= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not None\n else:\n result = multiply(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __isub__(self, other):\n \"Subtract other from self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is None:\n self._data -= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not None\n else:\n result = subtract(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n\n\n def __idiv__(self, other):\n \"Divide self by other in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n mo = getmask(other)\n result = divide(self, masked_array(f, mask=mo))\n self._data = result.data\n dm = result.raw_mask()\n if dm is not self._mask:\n self._mask = dm\n self._shared_mask = 1\n return self\n\n def __eq__(self,other):\n return equal(self,other)\n\n def __ne__(self,other):\n return not_equal(self,other)\n\n def __lt__(self,other):\n return less(self,other)\n\n def __le__(self,other):\n return less_equal(self,other)\n\n def __gt__(self,other):\n return greater(self,other)\n\n def __ge__(self,other):\n return greater_equal(self,other)\n\n def astype (self, tc):\n \"return self as array of given type.\"\n d = self._data.astype(tc)\n return array(d, mask=self._mask)\n\n def byte_swapped(self):\n \"\"\"Returns the raw data field, byte_swapped. Included for consistency\n with numeric but doesn't make sense in this context.\n \"\"\"\n return self._data.byte_swapped()\n\n def compressed (self):\n \"A 1-D array of all the non-masked data.\"\n d = oldnumeric.ravel(self._data)\n if self._mask is None:\n return array(d)\n else:\n m = 1 - oldnumeric.ravel(self._mask)\n c = oldnumeric.compress(m, d)\n return array(c, copy=0)\n\n def count (self, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n m = self._mask\n s = self._data.shape\n ls = len(s)\n if m is None:\n if ls == 0:\n return 1\n if ls == 1:\n return s[0]\n if axis is None:\n return reduce(lambda x,y:x*y, s)\n else:\n n = s[axis]\n t = list(s)\n del t[axis]\n return ones(t) * n\n if axis is None:\n w = oldnumeric.ravel(m).astype(int) \n n1 = size(w)\n if n1 == 1:\n n2 = w[0]\n else:\n n2 = umath.add.reduce(w)\n return n1 - n2\n else:\n n1 = size(m, axis)\n n2 = sum(m.astype(int), axis)\n return n1 - n2\n\n def dot (self, other):\n \"s.dot(other) = innerproduct(s, other)\"\n return innerproduct(self, other)\n\n def fill_value(self):\n \"Get the current fill value.\"\n return self._fill_value\n\n def filled (self, fill_value=None):\n \"\"\"A numeric array with masked values filled. If fill_value is None,\n use self.fill_value().\n\n If mask is None, copy data only if not contiguous.\n Result is always a contiguous, numeric array.\n# Is contiguous really necessary now?\n \"\"\"\n d = self._data\n m = self._mask\n if m is None:\n if d.flags['CONTIGUOUS']:\n return d\n else:\n return d.copy()\n else:\n if fill_value is None:\n value = self._fill_value\n else:\n value = fill_value\n\n if self is masked:\n result = numeric.array(value).reshape(*d.shape)\n else:\n try:\n result = numeric.array(d, dtype=d.dtype, copy=1)\n result[m] = value\n except (TypeError, AttributeError):\n #ok, can't put that value in here\n value = numeric.array(value, dtype=object)\n d = d.astype(object)\n result = oldnumeric.choose(m, (d, value))\n except IndexError:\n #ok, if scalar\n if d.shape:\n raise\n elif m:\n result = numeric.array(value, dtype=d.dtype)\n else:\n result = d\n return result\n\n def ids (self):\n \"\"\"Return the ids of the data and mask areas\"\"\"\n return (id(self._data), id(self._mask))\n\n def iscontiguous (self):\n \"Is the data contiguous?\"\n return self._data.flags['CONTIGUOUS']\n\n def itemsize(self):\n \"Item size of each data item.\"\n return self._data.itemsize\n\n\n def outer(self, other):\n \"s.outer(other) = outerproduct(s, other)\"\n return outerproduct(self, other)\n\n def put (self, values):\n \"\"\"Set the non-masked entries of self to filled(values).\n No change to mask\n \"\"\"\n iota = numeric.arange(self.size)\n d = self._data\n if self._mask is None:\n ind = iota\n else:\n ind = oldnumeric.compress(1 - self._mask, iota)\n d[ind] = filled(values).astype(d.dtype)\n\n def putmask (self, values):\n \"\"\"Set the masked entries of self to filled(values).\n Mask changed to None.\n \"\"\"\n d = self._data\n if self._mask is not None:\n d[self._mask] = filled(values).astype(d.dtype)\n self._shared_mask = 0\n self._mask = None\n\n def ravel (self):\n \"\"\"Return a 1-D view of self.\"\"\"\n if self._mask is None:\n return masked_array(self._data.ravel())\n else:\n return masked_array(self._data.ravel(), self._mask.ravel())\n\n def raw_data (self):\n \"\"\" Obsolete; use data property instead.\n The raw data; portions may be meaningless.\n May be noncontiguous. Expert use only.\"\"\"\n return self._data\n data = property(fget=raw_data, \n doc=\"The data, but values at masked locations are meaningless.\")\n\n def raw_mask (self):\n \"\"\" Obsolete; use mask property instead.\n May be noncontiguous. Expert use only.\n \"\"\"\n return self._mask\n mask = property(fget=raw_mask, \n doc=\"The mask, may be None. Values where mask true are meaningless.\")\n\n def reshape (self, *s):\n \"\"\"This array reshaped to shape s\"\"\"\n d = self._data.reshape(*s)\n if self._mask is None:\n return masked_array(d)\n else:\n m = self._mask.reshape(*s)\n return masked_array(d, m)\n\n def set_fill_value (self, v=None):\n \"Set the fill value to v. Omit v to restore default.\"\n if v is None:\n v = default_fill_value (self.raw_data())\n self._fill_value = v\n\n def _get_size (self):\n return self._data.size\n size = property(fget=_get_size, doc=\"Number of elements in the array.\")\n## CHECK THIS: signature of numeric.array.size?\n \n def _get_dtypechar(self):\n return self._data.dtypechar\n dtypechar = property(fget=_get_dtypechar, doc=\"type character of the array.\")\n\n def _get_dtype(self):\n return self._data.dtype\n dtype = property(fget=_get_dtype, doc=\"type of the array elements.\")\n\n def item(self):\n \"Return Python scalar if possible.\"\n if self._mask is not None:\n m = oldnumeric.ravel(self._mask)\n try:\n if m[0]:\n return masked\n except IndexError:\n return masked\n return self._data.item()\n\n def tolist(self, fill_value=None):\n \"Convert to list\"\n return self.filled(fill_value).tolist()\n\n def tostring(self, fill_value=None):\n \"Convert to string\"\n return self.filled(fill_value).tostring()\n\n def unmask (self):\n \"Replace the mask by None if possible.\"\n if self._mask is None: return\n m = make_mask(self._mask, flag=1)\n if m is None:\n self._mask = None\n self._shared_mask = 0\n\n def unshare_mask (self):\n \"If currently sharing mask, make a copy.\"\n if self._shared_mask:\n self._mask = make_mask (self._mask, copy=1, flag=0)\n self._shared_mask = 0\n\n shape = property(_get_shape, _set_shape,\n doc = 'tuple giving the shape of the array')\n\n flat = property(_get_flat, _set_flat,\n doc = 'Access array in flat form.')\n\n real = property(_get_real, _set_real,\n doc = 'Access the real part of the array')\n\n imaginary = property(_get_imaginary, _set_imaginary,\n doc = 'Access the imaginary part of the array')\n\n imag = imaginary\n\n#end class MaskedArray\n\narray = MaskedArray\n\ndef isMaskedArray (x):\n \"Is x a masked array, that is, an instance of MaskedArray?\"\n return isinstance(x, MaskedArray)\n\nisarray = isMaskedArray\nisMA = isMaskedArray #backward compatibility\n\ndef allclose (a, b, fill_value=1, rtol=1.e-5, atol=1.e-8):\n \"\"\" Returns true if all components of a and b are equal\n subject to given tolerances.\n If fill_value is 1, masked values considered equal.\n If fill_value is 0, masked values considered unequal.\n The relative error rtol should be positive and << 1.0\n The absolute error atol comes into play for those elements\n of b that are very small or zero; it says how small a must be also.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a)\n d2 = filled(b)\n x = filled(array(d1, copy=0, mask=m), fill_value).astype(float)\n y = filled(array(d2, copy=0, mask=m), 1).astype(float)\n d = umath.less_equal(umath.absolute(x-y), atol + rtol * umath.absolute(y))\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n\ndef allequal (a, b, fill_value=1):\n \"\"\"\n True if all entries of a and b are equal, using\n fill_value as a truth value where either or both are masked.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n if m is None:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n elif fill_value:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n dm = array(d, mask=m, copy=0)\n return oldnumeric.alltrue(oldnumeric.ravel(filled(dm, 1)))\n else:\n return 0\n\ndef masked_values (data, value, rtol=1.e-5, atol=1.e-8, copy=1):\n \"\"\"\n masked_values(data, value, rtol=1.e-5, atol=1.e-8)\n Create a masked array; mask is None if possible.\n If copy==0, and otherwise possible, result\n may share data values with original array.\n Let d = filled(data, value). Returns d\n masked where abs(data-value)<= atol + rtol * abs(value)\n if d is of a floating point type. Otherwise returns\n masked_object(d, value, copy)\n \"\"\"\n abs = umath.absolute\n d = filled(data, value)\n if issubclass(d.dtype, numeric.floating):\n m = umath.less_equal(abs(d-value), atol+rtol*abs(value))\n m = make_mask(m, flag=1)\n return array(d, mask = m, copy=copy,\n fill_value=value)\n else:\n return masked_object(d, value, copy=copy)\n\ndef masked_object (data, value, copy=1):\n \"Create array masked where exactly data equal to value\"\n d = filled(data, value)\n dm = make_mask(umath.equal(d, value), flag=1)\n return array(d, mask=dm, copy=copy, fill_value=value)\n\ndef arrayrange(start, stop=None, step=1, dtype=None):\n \"\"\"Just like range() except it returns a array whose type can be specified\n by the keyword argument dtypechar.\n \"\"\"\n return array(numeric.arrayrange(start, stop, step, dtype))\n\narange = arrayrange\n\ndef fromstring (s, t):\n \"Construct a masked array from a string. Result will have no mask.\"\n return masked_array(numeric.fromstring(s, t))\n\ndef left_shift (a, n):\n \"Left shift n bits\"\n m = getmask(a)\n if m is None:\n d = umath.left_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.left_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef right_shift (a, n):\n \"Right shift n bits\"\n m = getmask(a)\n if m is None:\n d = umath.right_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.right_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef resize (a, new_shape):\n \"\"\"resize(a, new_shape) returns a new array with the specified shape.\n The original array's total size can be any size.\"\"\"\n m = getmask(a)\n if m is not None:\n m = oldnumeric.resize(m, new_shape)\n result = array(oldnumeric.resize(filled(a), new_shape), mask=m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n \"\"\"\n af = filled(a)\n if isinstance(repeats, types.IntType):\n repeats = tuple([repeats]*(shape(af)[axis]))\n\n m = getmask(a)\n if m is not None:\n m = oldnumeric.repeat(m, repeats, axis)\n d = oldnumeric.repeat(af, repeats, axis)\n result = masked_array(d, m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef identity(n):\n \"\"\"identity(n) returns the identity matrix of shape n x n.\n \"\"\"\n return array(numeric.identity(n))\n\ndef indices (dimensions, dtype=None):\n \"\"\"indices(dimensions,dtype=None) returns an array representing a grid\n of indices with row-only, and column-only variation.\n \"\"\"\n return array(numeric.indices(dimensions, dtype))\n\ndef zeros (shape, dtype=int):\n \"\"\"zeros(n, dtype=int) =\n an array of all zeros of the given length or shape.\"\"\"\n return array(numeric.zeros(shape, dtype))\n\ndef ones (shape, dtype=int):\n \"\"\"ones(n, dtype=int) =\n an array of all ones of the given length or shape.\"\"\"\n return array(numeric.ones(shape, dtype))\n\n\ndef count (a, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n a = masked_array(a)\n return a.count(axis)\n\ndef power (a, b, third=None):\n \"a**b\"\n if third is not None:\n raise MAError, \"3-argument power not supported.\"\n ma = getmask(a)\n mb = getmask(b)\n m = mask_or(ma, mb)\n fa = filled(a, 1)\n fb = filled(b, 1)\n if fb.dtypechar in typecodes[\"Integer\"]:\n return masked_array(umath.power(fa, fb), m)\n md = make_mask(umath.less_equal (fa, 0), flag=1)\n m = mask_or(m, md)\n if m is None:\n return masked_array(umath.power(fa, fb))\n else:\n fa = numeric.where(m, 1, fa)\n return masked_array(umath.power(fa, fb), m)\n\ndef masked_array (a, mask=None, fill_value=None):\n \"\"\"masked_array(a, mask=None) =\n array(a, mask=mask, copy=0, fill_value=fill_value)\n \"\"\"\n return array(a, mask=mask, copy=0, fill_value=fill_value)\n\nsum = add.reduce\nproduct = multiply.reduce\n\ndef average (a, axis=0, weights=None, returned = 0):\n \"\"\"average(a, axis=0, weights=None)\n Computes average along indicated axis.\n If axis is None, average over the entire array\n Inputs can be integer or floating types; result is of type float.\n\n If weights are given, result is sum(a*weights)/(sum(weights)*1.0)\n weights must have a's shape or be the 1-d with length the size\n of a in the given axis.\n\n If returned, return a tuple: the result and the sum of the weights\n or count of values. Results will have the same shape.\n\n masked values in the weights will be set to 0.0\n \"\"\"\n a = masked_array(a)\n mask = a.mask\n ash = a.shape\n if ash == ():\n ash = (1,)\n if axis is None:\n if mask is None:\n if weights is None:\n n = add.reduce(a.raw_data().ravel())\n d = reduce(lambda x, y: x * y, ash, 1.0)\n else:\n w = filled(weights, 0.0).ravel()\n n = umath.add.reduce(a.raw_data().ravel() * w)\n d = umath.add.reduce(w)\n del w\n else:\n if weights is None:\n n = add.reduce(a.ravel())\n w = oldnumeric.choose(mask, (1.0,0.0)).ravel()\n d = umath.add.reduce(w)\n del w\n else:\n w = array(filled(weights, 0.0), float, mask=mask).ravel()\n n = add.reduce(a.ravel() * w)\n d = add.reduce(w)\n del w\n else:\n if mask is None:\n if weights is None:\n d = ash[axis] * 1.0\n n = umath.add.reduce(a.raw_data(), axis)\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = numeric.array(w, float, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * ones(ash, float)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w, r\n else:\n raise ValueError, 'average: weights wrong shape.'\n else:\n if weights is None:\n n = add.reduce(a, axis)\n w = numeric.choose(mask, (1.0, 0.0))\n d = umath.add.reduce(w, axis)\n del w\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = array(w, float, mask=mask, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * masked_array(ones(ash, float), mask)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n else:\n raise ValueError, 'average: weights wrong shape.'\n del w\n #print n, d, repr(mask), repr(weights)\n if n is masked or d is masked: return masked\n result = divide (n, d)\n del n\n\n if isinstance(result, MaskedArray):\n result.unmask()\n if returned:\n if not isinstance(d, MaskedArray):\n d = masked_array(d)\n if not d.shape == result.shape:\n d = ones(result.shape, float) * d\n d.unmask()\n if returned:\n return result, d\n else:\n return result\n\ndef where (condition, x, y):\n \"\"\"where(condition, x, y) is x where condition is nonzero, y otherwise.\n condition must be convertible to an integer array.\n Answer is always the shape of condition.\n The type depends on x and y. It is integer if both x and y are\n the value masked.\n \"\"\"\n fc = filled(not_equal(condition,0), 0)\n if x is masked:\n xv = 0\n xm = 1\n else:\n xv = filled(x)\n xm = getmask(x)\n if xm is None: xm = 0\n if y is masked:\n yv = 0\n ym = 1\n else:\n yv = filled(y)\n ym = getmask(y)\n if ym is None: ym = 0\n d = numeric.choose(fc, (yv, xv))\n md = numeric.choose(fc, (ym, xm))\n m = getmask(condition)\n m = make_mask(mask_or(m, md), copy=0, flag=1)\n return masked_array(d, m)\n\ndef choose (indices, t):\n \"Returns array shaped like indices with elements chosen from t\"\n def fmask (x):\n if x is masked: return 1\n return filled(x)\n def nmask (x):\n if x is masked: return 1\n m = getmask(x)\n if m is None: return 0\n return m\n c = filled(indices,0)\n masks = [nmask(x) for x in t]\n a = [fmask(x) for x in t]\n d = numeric.choose(c, a)\n m = numeric.choose(c, masks)\n m = make_mask(mask_or(m, getmask(indices)), copy=0, flag=1)\n return masked_array(d, m)\n\ndef masked_where(condition, x, copy=1):\n \"\"\"Return x as an array masked where condition is true.\n Also masked where x or condition masked.\n \"\"\"\n cm = filled(condition,1)\n m = mask_or(getmask(x), cm)\n return array(filled(x), copy=copy, mask=m)\n\ndef masked_greater(x, value, copy=1):\n \"masked_greater(x, value) = x masked where x > value\"\n return masked_where(greater(x, value), x, copy)\n\ndef masked_greater_equal(x, value, copy=1):\n \"masked_greater_equal(x, value) = x masked where x >= value\"\n return masked_where(greater_equal(x, value), x, copy)\n\ndef masked_less(x, value, copy=1):\n \"masked_less(x, value) = x masked where x < value\"\n return masked_where(less(x, value), x, copy)\n\ndef masked_less_equal(x, value, copy=1):\n \"masked_less_equal(x, value) = x masked where x <= value\"\n return masked_where(less_equal(x, value), x, copy)\n\ndef masked_not_equal(x, value, copy=1):\n \"masked_not_equal(x, value) = x masked where x != value\"\n d = filled(x,0)\n c = umath.not_equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_equal(x, value, copy=1):\n \"\"\"masked_equal(x, value) = x masked where x == value\n For floating point consider masked_values(x, value) instead.\n \"\"\"\n d = filled(x,0)\n c = umath.equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_inside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are inside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d=filled(x, 0)\n c = umath.logical_and(umath.less_equal(d, v2), umath.greater_equal(d, v1))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef masked_outside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are outside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d = filled(x,0)\n c = umath.logical_or(umath.less(d, v1), umath.greater(d, v2))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef reshape (a, *newshape):\n \"Copy of a with a new shape.\"\n m = getmask(a)\n d = filled(a).reshape(*newshape)\n if m is None:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.reshape(m, *newshape))\n\ndef ravel (a):\n \"a as one-dimensional, may share data and mask\"\n m = getmask(a)\n d = oldnumeric.ravel(filled(a))\n if m is None:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.ravel(m))\n\ndef concatenate (arrays, axis=0):\n \"Concatenate the arrays along the given axis\"\n d = []\n for x in arrays:\n d.append(filled(x))\n d = numeric.concatenate(d, axis)\n for x in arrays:\n if getmask(x) is not None: break\n else:\n return masked_array(d)\n dm = []\n for x in arrays:\n dm.append(getmaskarray(x))\n dm = numeric.concatenate(dm, axis)\n return masked_array(d, mask=dm)\n\ndef take (a, indices, axis=0):\n \"take(a, indices, axis=0) returns selection of items from a.\"\n m = getmask(a)\n d = masked_array(a).raw_data()\n if m is None:\n return masked_array(numeric.take(d, indices, axis))\n else:\n return masked_array(numeric.take(d, indices, axis),\n mask = numeric.take(m, indices, axis))\n\ndef transpose(a, axes=None):\n \"transpose(a, axes=None) reorder dimensions per tuple axes\"\n m = getmask(a)\n d = filled(a)\n if m is None:\n return masked_array(numeric.transpose(d, axes))\n else:\n return masked_array(numeric.transpose(d, axes),\n mask = numeric.transpose(m, axes))\n\n\ndef put(a, indices, values):\n \"\"\"put(a, indices, values) sets storage-indexed locations to corresponding values.\n\n Values and indices are filled if necessary.\n\n \"\"\"\n d = a.raw_data()\n ind = filled(indices)\n v = filled(values)\n numeric.put (d, ind, v)\n m = getmask(a)\n if m is not None:\n a.unshare_mask()\n numeric.put(a.raw_mask(), ind, 0)\n\ndef putmask(a, mask, values):\n \"putmask(a, mask, values) sets a where mask is true.\"\n if mask is None:\n return\n numeric.putmask(a.raw_data(), mask, values)\n m = getmask(a)\n if m is None: return\n a.unshare_mask()\n numeric.putmask(a.raw_mask(), mask, 0)\n\ndef innerproduct(a,b):\n \"\"\"innerproduct(a,b) returns the dot product of two arrays, which has\n shape a.shape[:-1] + b.shape[:-1] with elements computed by summing the\n product of the elements from the last dimensions of a and b.\n Masked elements are replace by zeros.\n \"\"\"\n fa = filled(a, 0)\n fb = filled(b, 0)\n if len(fa.shape) == 0: fa.shape = (1,)\n if len(fb.shape) == 0: fb.shape = (1,)\n return masked_array(numeric.innerproduct(fa, fb))\n\ndef outerproduct(a, b):\n \"\"\"outerproduct(a,b) = {a[i]*b[j]}, has shape (len(a),len(b))\"\"\"\n fa = filled(a,0).ravel()\n fb = filled(b,0).ravel()\n d = numeric.outerproduct(fa, fb)\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n return masked_array(d)\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = make_mask(1-numeric.outerproduct(1-ma,1-mb), copy=0)\n return masked_array(d, m)\n\ndef dot(a, b):\n \"\"\"dot(a,b) returns matrix-multiplication between a and b. The product-sum\n is over the last dimension of a and the second-to-last dimension of b.\n Masked values are replaced by zeros. See also innerproduct.\n \"\"\"\n return innerproduct(filled(a,0), numeric.swapaxes(filled(b,0), -1, -2))\n\ndef compress(condition, x, dimension=-1):\n \"\"\"Select those parts of x for which condition is true.\n Masked values in condition are considered false.\n \"\"\"\n c = filled(condition, 0)\n m = getmask(x)\n if m is not None:\n m=numeric.compress(c, m, dimension)\n d = numeric.compress(c, filled(x), dimension)\n return masked_array(d, m)\n\nclass _minimum_operation:\n \"Object to calculate minima\"\n def __init__ (self):\n \"\"\"minimum(a, b) or minimum(a)\n In one argument case returns the scalar minimum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is None:\n d = amin(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amin(ac.raw_data())\n else:\n return where(less(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is None:\n t = filled(target)\n return masked_array (umath.minimum.reduce (t, axis))\n else:\n t = umath.minimum.reduce(filled(target, minimum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n m = None\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.minimum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nminimum = _minimum_operation ()\n\nclass _maximum_operation:\n \"Object to calculate maxima\"\n def __init__ (self):\n \"\"\"maximum(a, b) or maximum(a)\n In one argument case returns the scalar maximum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is None:\n d = amax(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amax(ac.raw_data())\n else:\n return where(greater(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is None:\n t = filled(target)\n return masked_array (umath.maximum.reduce (t, axis))\n else:\n t = umath.maximum.reduce(filled(target, maximum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n m = None\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.maximum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nmaximum = _maximum_operation ()\n\ndef sort (x, axis = -1, fill_value=None):\n \"\"\"If x does not have a mask, return a masked array formed from the\n result of numeric.sort(x, axis).\n Otherwise, fill x with fill_value. Sort it.\n Set a mask where the result is equal to fill_value.\n Note that this may have unintended consequences if the data contains the\n fill value at a non-masked site.\n\n If fill_value is not given the default fill value for x's type will be\n used.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n d = filled(x, fill_value)\n s = oldnumeric.sort(d, axis)\n if getmask(x) is None:\n return masked_array(s)\n return masked_values(s, fill_value, copy=0)\n\ndef diagonal(a, k = 0, axis1=0, axis2=1):\n \"\"\"diagonal(a,k=0,axis1=0, axis2=1) = the k'th diagonal of a\"\"\"\n d = oldnumeric.diagonal(filled(a), k, axis1, axis2)\n m = getmask(a)\n if m is None:\n return masked_array(d, m)\n else:\n return masked_array(d, oldnumeric.diagonal(m, k, axis1, axis2))\n\ndef argsort (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for sorting along given axis.\n if fill_value is None, use get_fill_value(x)\n Returns a numpy array.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argsort(d, axis)\n\ndef argmin (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return indices for minimum values along given axis.\n if fill_value is None, use get_fill_value(x).\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argmin(d, axis)\n\ndef argmax (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for maximum along given axis.\n if fill_value is None, use -get_fill_value(x) if it exists.\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n try:\n fill_value = - fill_value\n except:\n pass\n d = filled(x, fill_value)\n return oldnumeric.argmax(d, axis)\n\ndef fromfunction (f, s):\n \"\"\"apply f to s to create array as in umath.\"\"\"\n return masked_array(numeric.fromfunction(f,s))\n\ndef asarray(data, dtype=None):\n \"\"\"asarray(data, dtype) = array(data, dtype, copy=0)\n \"\"\"\n if isinstance(data, MaskedArray) and \\\n (dtype is None or dtype == data.dtype):\n return data\n return array(data, dtype=dtype, copy=0)\n\nmasked = MaskedArray([0], int, mask=[1])[0:0]\nmasked = masked[0:0]\n", + "methods": [ + { + "name": "__init__", + "long_name": "__init__( self , args = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 24, + "end_line": 26, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 27, + "end_line": 29, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , display )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "display" + ], + "start_line": 34, + "end_line": 37, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "display", + "long_name": "display( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 39, + "end_line": 41, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "set_display", + "long_name": "set_display( self , s )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "s" + ], + "start_line": 43, + "end_line": 45, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enabled", + "long_name": "enabled( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 47, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enable", + "long_name": "enable( self , flag = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "flag" + ], + "start_line": 51, + "end_line": 53, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 55, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "default_fill_value", + "long_name": "default_fill_value( obj )", + "filename": "ma.py", + "nloc": 25, + "complexity": 13, + "token_count": 144, + "parameters": [ + "obj" + ], + "start_line": 70, + "end_line": 94, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "minimum_fill_value", + "long_name": "minimum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 105, + "parameters": [ + "obj" + ], + "start_line": 96, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "maximum_fill_value", + "long_name": "maximum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 103, + "parameters": [ + "obj" + ], + "start_line": 113, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( a , fill_value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 2, + "token_count": 20, + "parameters": [ + "a", + "fill_value" + ], + "start_line": 130, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "getmask", + "long_name": "getmask( a )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "a" + ], + "start_line": 135, + "end_line": 142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "getmaskarray", + "long_name": "getmaskarray( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 144, + "end_line": 153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "is_mask", + "long_name": "is_mask( m )", + "filename": "ma.py", + "nloc": 6, + "complexity": 4, + "token_count": 33, + "parameters": [ + "m" + ], + "start_line": 155, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "make_mask", + "long_name": "make_mask( m , copy = 0 , flag = 0 )", + "filename": "ma.py", + "nloc": 17, + "complexity": 7, + "token_count": 107, + "parameters": [ + "m", + "copy", + "flag" + ], + "start_line": 164, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "make_mask_none", + "long_name": "make_mask_none( s )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 25, + "parameters": [ + "s" + ], + "start_line": 189, + "end_line": 193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "mask_or", + "long_name": "mask_or( m1 , m2 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 5, + "token_count": 52, + "parameters": [ + "m1", + "m2" + ], + "start_line": 195, + "end_line": 202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "filled", + "long_name": "filled( a , value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 5, + "token_count": 70, + "parameters": [ + "a", + "value" + ], + "start_line": 204, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "get_fill_value", + "long_name": "get_fill_value( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 224, + "end_line": 233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "common_fill_value", + "long_name": "common_fill_value( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a", + "b" + ], + "start_line": 235, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , y1 , y2 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "y1", + "y2" + ], + "start_line": 245, + "end_line": 248, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 35, + "parameters": [ + "self", + "x" + ], + "start_line": 250, + "end_line": 254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , eps )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "eps" + ], + "start_line": 258, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "x" + ], + "start_line": 262, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 268, + "end_line": 270, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 272, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 278, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 282, + "end_line": 284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , aufunc , fill = 0 , domain = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "aufunc", + "fill", + "domain" + ], + "start_line": 287, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 16, + "complexity": 5, + "token_count": 112, + "parameters": [ + "self", + "a", + "args", + "kwargs" + ], + "start_line": 298, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 316, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , tolerance = divide_tolerance )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "tolerance" + ], + "start_line": 321, + "end_line": 322, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 323, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , domain , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 53, + "parameters": [ + "self", + "abfunc", + "domain", + "fillx", + "filly" + ], + "start_line": 330, + "end_line": 338, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 147, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 340, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 363, + "end_line": 364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "abfunc", + "fillx", + "filly" + ], + "start_line": 367, + "end_line": 374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 113, + "parameters": [ + "self", + "a", + "b", + "args", + "kwargs" + ], + "start_line": 376, + "end_line": 390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 20, + "complexity": 6, + "token_count": 157, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 392, + "end_line": 412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 414, + "end_line": 425, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "accumulate", + "long_name": "accumulate( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 427, + "end_line": 430, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 431, + "end_line": 432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "rank", + "long_name": "rank( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 494, + "end_line": 495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 497, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( object , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 21, + "parameters": [ + "object", + "axis" + ], + "start_line": 500, + "end_line": 501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , data , dtype = None , copy = True , fortran = False , mask = None , fill_value = None )", + "filename": "ma.py", + "nloc": 56, + "complexity": 18, + "token_count": 379, + "parameters": [ + "self", + "data", + "dtype", + "copy", + "fortran", + "mask", + "fill_value" + ], + "start_line": 532, + "end_line": 594, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "__array__", + "long_name": "__array__( self , t = None )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 67, + "parameters": [ + "self", + "t" + ], + "start_line": 596, + "end_line": 611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__array_wrap__", + "long_name": "__array_wrap__( self , array )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "array" + ], + "start_line": 613, + "end_line": 617, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_shape", + "long_name": "_get_shape( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 619, + "end_line": 621, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_set_shape", + "long_name": "_set_shape( self , newshape )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "newshape" + ], + "start_line": 623, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_get_flat", + "long_name": "_get_flat( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 630, + "end_line": 639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "_set_flat", + "long_name": "_set_flat( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "value" + ], + "start_line": 641, + "end_line": 644, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_real", + "long_name": "_get_real( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 646, + "end_line": 653, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_real", + "long_name": "_set_real( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 655, + "end_line": 658, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_imaginary", + "long_name": "_get_imaginary( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 660, + "end_line": 667, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_imaginary", + "long_name": "_set_imaginary( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 669, + "end_line": 672, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 674, + "end_line": 691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "ma.py", + "nloc": 42, + "complexity": 5, + "token_count": 207, + "parameters": [ + "self" + ], + "start_line": 693, + "end_line": 738, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 1 + }, + { + "name": "__float__", + "long_name": "__float__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 740, + "end_line": 745, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__int__", + "long_name": "__int__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 747, + "end_line": 752, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , i )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 70, + "parameters": [ + "self", + "i" + ], + "start_line": 754, + "end_line": 768, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 770, + "end_line": 778, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__setitem__", + "long_name": "__setitem__( self , index , value )", + "filename": "ma.py", + "nloc": 27, + "complexity": 7, + "token_count": 157, + "parameters": [ + "self", + "index", + "value" + ], + "start_line": 785, + "end_line": 811, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "__setslice__", + "long_name": "__setslice__( self , i , j , value )", + "filename": "ma.py", + "nloc": 23, + "complexity": 7, + "token_count": 155, + "parameters": [ + "self", + "i", + "j", + "value" + ], + "start_line": 813, + "end_line": 835, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "__nonzero__", + "long_name": "__nonzero__( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 837, + "end_line": 847, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 849, + "end_line": 852, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__and__", + "long_name": "__and__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 854, + "end_line": 856, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__or__", + "long_name": "__or__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 858, + "end_line": 860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__xor__", + "long_name": "__xor__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 862, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__abs__", + "long_name": "__abs__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 870, + "end_line": 872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__neg__", + "long_name": "__neg__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 874, + "end_line": 876, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pos__", + "long_name": "__pos__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 878, + "end_line": 880, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__add__", + "long_name": "__add__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 882, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mod__", + "long_name": "__mod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 888, + "end_line": 890, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rmod__", + "long_name": "__rmod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 892, + "end_line": 894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__lshift__", + "long_name": "__lshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 896, + "end_line": 897, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__rshift__", + "long_name": "__rshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 899, + "end_line": 900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__sub__", + "long_name": "__sub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 902, + "end_line": 904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rsub__", + "long_name": "__rsub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 906, + "end_line": 908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mul__", + "long_name": "__mul__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 910, + "end_line": 912, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__div__", + "long_name": "__div__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 916, + "end_line": 918, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rdiv__", + "long_name": "__rdiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 920, + "end_line": 922, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__truediv__", + "long_name": "__truediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 924, + "end_line": 926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rtruediv__", + "long_name": "__rtruediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 928, + "end_line": 930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__floordiv__", + "long_name": "__floordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 932, + "end_line": 934, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rfloordiv__", + "long_name": "__rfloordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 936, + "end_line": 938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pow__", + "long_name": "__pow__( self , other , third = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "other", + "third" + ], + "start_line": 940, + "end_line": 942, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__sqrt__", + "long_name": "__sqrt__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 944, + "end_line": 946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__iadd__", + "long_name": "__iadd__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 948, + "end_line": 989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__imul__", + "long_name": "__imul__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 251, + "parameters": [ + "self", + "other" + ], + "start_line": 991, + "end_line": 1032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__isub__", + "long_name": "__isub__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 1034, + "end_line": 1075, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__idiv__", + "long_name": "__idiv__( self , other )", + "filename": "ma.py", + "nloc": 38, + "complexity": 12, + "token_count": 233, + "parameters": [ + "self", + "other" + ], + "start_line": 1079, + "end_line": 1116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 1 + }, + { + "name": "__eq__", + "long_name": "__eq__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1118, + "end_line": 1119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ne__", + "long_name": "__ne__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1121, + "end_line": 1122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__lt__", + "long_name": "__lt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1124, + "end_line": 1125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__le__", + "long_name": "__le__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1127, + "end_line": 1128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__gt__", + "long_name": "__gt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1130, + "end_line": 1131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ge__", + "long_name": "__ge__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1133, + "end_line": 1134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "astype", + "long_name": "astype( self , tc )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "tc" + ], + "start_line": 1136, + "end_line": 1139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "byte_swapped", + "long_name": "byte_swapped( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 1141, + "end_line": 1145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "compressed", + "long_name": "compressed( self )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 1147, + "end_line": 1155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "count", + "long_name": "count( self , axis = None )", + "filename": "ma.py", + "nloc": 29, + "complexity": 7, + "token_count": 173, + "parameters": [ + "self", + "axis" + ], + "start_line": 1157, + "end_line": 1185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "dot", + "long_name": "dot( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1187, + "end_line": 1189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "fill_value", + "long_name": "fill_value( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1191, + "end_line": 1193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "filled", + "long_name": "filled( self , fill_value = None )", + "filename": "ma.py", + "nloc": 31, + "complexity": 9, + "token_count": 183, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1195, + "end_line": 1235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + }, + { + "name": "ids", + "long_name": "ids( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 1237, + "end_line": 1239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "iscontiguous", + "long_name": "iscontiguous( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 1241, + "end_line": 1243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "itemsize", + "long_name": "itemsize( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 1245, + "end_line": 1247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1250, + "end_line": 1252, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "put", + "long_name": "put( self , values )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "values" + ], + "start_line": 1254, + "end_line": 1264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "putmask", + "long_name": "putmask( self , values )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "values" + ], + "start_line": 1266, + "end_line": 1274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "ravel", + "long_name": "ravel( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 1276, + "end_line": 1281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "raw_data", + "long_name": "raw_data( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1283, + "end_line": 1287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "raw_mask", + "long_name": "raw_mask( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1291, + "end_line": 1295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "reshape", + "long_name": "reshape( self , * s )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self", + "s" + ], + "start_line": 1299, + "end_line": 1306, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( self , v = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self", + "v" + ], + "start_line": 1308, + "end_line": 1312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_size", + "long_name": "_get_size( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1314, + "end_line": 1315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtypechar", + "long_name": "_get_dtypechar( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1319, + "end_line": 1320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtype", + "long_name": "_get_dtype( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1323, + "end_line": 1324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "item", + "long_name": "item( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 4, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 1327, + "end_line": 1336, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "tolist", + "long_name": "tolist( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1338, + "end_line": 1340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "tostring", + "long_name": "tostring( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1342, + "end_line": 1344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "unmask", + "long_name": "unmask( self )", + "filename": "ma.py", + "nloc": 7, + "complexity": 3, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 1346, + "end_line": 1352, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "unshare_mask", + "long_name": "unshare_mask( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 1354, + "end_line": 1358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "isMaskedArray", + "long_name": "isMaskedArray( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "x" + ], + "start_line": 1378, + "end_line": 1380, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "allclose", + "long_name": "allclose( a , b , fill_value = 1 , rtol = 1 . e - 5 , atol = 1 . e - 8 )", + "filename": "ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 140, + "parameters": [ + "a", + "b", + "fill_value", + "rtol", + "atol" + ], + "start_line": 1385, + "end_line": 1400, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "allequal", + "long_name": "allequal( a , b , fill_value = 1 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 3, + "token_count": 125, + "parameters": [ + "a", + "b", + "fill_value" + ], + "start_line": 1402, + "end_line": 1420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "masked_values", + "long_name": "masked_values( data , value , rtol = 1 . e - 5 , atol = 1 . e - 8 , copy = 1 )", + "filename": "ma.py", + "nloc": 10, + "complexity": 2, + "token_count": 115, + "parameters": [ + "data", + "value", + "rtol", + "atol", + "copy" + ], + "start_line": 1422, + "end_line": 1441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "masked_object", + "long_name": "masked_object( data , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "data", + "value", + "copy" + ], + "start_line": 1443, + "end_line": 1447, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayrange", + "long_name": "arrayrange( start , stop = None , step = 1 , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 34, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 1449, + "end_line": 1453, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "fromstring", + "long_name": "fromstring( s , t )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "s", + "t" + ], + "start_line": 1457, + "end_line": 1459, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "left_shift", + "long_name": "left_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1461, + "end_line": 1469, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "right_shift", + "long_name": "right_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1471, + "end_line": 1479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 1481, + "end_line": 1489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 101, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 1491, + "end_line": 1506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "identity", + "long_name": "identity( n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "n" + ], + "start_line": 1508, + "end_line": 1511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "indices", + "long_name": "indices( dimensions , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "dimensions", + "dtype" + ], + "start_line": 1513, + "end_line": 1517, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "zeros", + "long_name": "zeros( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1519, + "end_line": 1522, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ones", + "long_name": "ones( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1524, + "end_line": 1527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "count", + "long_name": "count( a , axis = None )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a", + "axis" + ], + "start_line": 1530, + "end_line": 1533, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "power", + "long_name": "power( a , b , third = None )", + "filename": "ma.py", + "nloc": 18, + "complexity": 4, + "token_count": 152, + "parameters": [ + "a", + "b", + "third" + ], + "start_line": 1535, + "end_line": 1552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "masked_array", + "long_name": "masked_array( a , mask = None , fill_value = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "mask", + "fill_value" + ], + "start_line": 1554, + "end_line": 1558, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "average", + "long_name": "average( a , axis = 0 , weights = None , returned = 0 )", + "filename": "ma.py", + "nloc": 92, + "complexity": 22, + "token_count": 741, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 1563, + "end_line": 1670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "where", + "long_name": "where( condition , x , y )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 149, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 1672, + "end_line": 1698, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "choose.fmask", + "long_name": "choose.fmask( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 2, + "token_count": 17, + "parameters": [ + "x" + ], + "start_line": 1702, + "end_line": 1704, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "choose.nmask", + "long_name": "choose.nmask( x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 3, + "token_count": 27, + "parameters": [ + "x" + ], + "start_line": 1705, + "end_line": 1709, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "choose", + "long_name": "choose( indices , t )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 93, + "parameters": [ + "indices", + "t" + ], + "start_line": 1700, + "end_line": 1716, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "masked_where", + "long_name": "masked_where( condition , x , copy = 1 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 47, + "parameters": [ + "condition", + "x", + "copy" + ], + "start_line": 1718, + "end_line": 1724, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "masked_greater", + "long_name": "masked_greater( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1726, + "end_line": 1728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_greater_equal", + "long_name": "masked_greater_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1730, + "end_line": 1732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less", + "long_name": "masked_less( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1734, + "end_line": 1736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less_equal", + "long_name": "masked_less_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1738, + "end_line": 1740, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_not_equal", + "long_name": "masked_not_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1742, + "end_line": 1747, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "masked_equal", + "long_name": "masked_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1749, + "end_line": 1756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "masked_inside", + "long_name": "masked_inside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1758, + "end_line": 1769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "masked_outside", + "long_name": "masked_outside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1771, + "end_line": 1782, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , * newshape )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 56, + "parameters": [ + "a", + "newshape" + ], + "start_line": 1784, + "end_line": 1791, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( a )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "a" + ], + "start_line": 1793, + "end_line": 1800, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "concatenate", + "long_name": "concatenate( arrays , axis = 0 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 5, + "token_count": 97, + "parameters": [ + "arrays", + "axis" + ], + "start_line": 1802, + "end_line": 1816, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 76, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 1818, + "end_line": 1826, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "a", + "axes" + ], + "start_line": 1828, + "end_line": 1836, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , indices , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 70, + "parameters": [ + "a", + "indices", + "values" + ], + "start_line": 1839, + "end_line": 1852, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 61, + "parameters": [ + "a", + "mask", + "values" + ], + "start_line": 1854, + "end_line": 1862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "innerproduct", + "long_name": "innerproduct( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 3, + "token_count": 72, + "parameters": [ + "a", + "b" + ], + "start_line": 1864, + "end_line": 1874, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "outerproduct", + "long_name": "outerproduct( a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 110, + "parameters": [ + "a", + "b" + ], + "start_line": 1876, + "end_line": 1888, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dot", + "long_name": "dot( a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 36, + "parameters": [ + "a", + "b" + ], + "start_line": 1890, + "end_line": 1895, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , x , dimension = - 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 67, + "parameters": [ + "condition", + "x", + "dimension" + ], + "start_line": 1897, + "end_line": 1906, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1910, + "end_line": 1914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1916, + "end_line": 1929, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1931, + "end_line": 1940, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1942, + "end_line": 1953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1959, + "end_line": 1963, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1965, + "end_line": 1978, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1980, + "end_line": 1989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1991, + "end_line": 2002, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "sort", + "long_name": "sort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 8, + "complexity": 3, + "token_count": 68, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2006, + "end_line": 2023, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , k = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 73, + "parameters": [ + "a", + "k", + "axis1", + "axis2" + ], + "start_line": 2025, + "end_line": 2032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2034, + "end_line": 2041, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2043, + "end_line": 2051, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 52, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2053, + "end_line": 2067, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "fromfunction", + "long_name": "fromfunction( f , s )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "f", + "s" + ], + "start_line": 2069, + "end_line": 2071, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( data , dtype = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 46, + "parameters": [ + "data", + "dtype" + ], + "start_line": 2073, + "end_line": 2079, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_m", + "long_name": "_m( f )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "f" + ], + "start_line": 2085, + "end_line": 2086, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "not_implemented", + "long_name": "not_implemented( * args , ** kwds )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "args", + "kwds" + ], + "start_line": 2087, + "end_line": 2088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_choose", + "long_name": "_choose( self , * args )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 2097, + "end_line": 2098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_compress", + "long_name": "_compress( self , cond , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "cond", + "axis" + ], + "start_line": 2104, + "end_line": 2105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "__init__", + "long_name": "__init__( self , args = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 24, + "end_line": 26, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 27, + "end_line": 29, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , display )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "display" + ], + "start_line": 34, + "end_line": 37, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "display", + "long_name": "display( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 39, + "end_line": 41, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "set_display", + "long_name": "set_display( self , s )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "s" + ], + "start_line": 43, + "end_line": 45, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enabled", + "long_name": "enabled( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 47, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enable", + "long_name": "enable( self , flag = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "flag" + ], + "start_line": 51, + "end_line": 53, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 55, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "default_fill_value", + "long_name": "default_fill_value( obj )", + "filename": "ma.py", + "nloc": 25, + "complexity": 13, + "token_count": 144, + "parameters": [ + "obj" + ], + "start_line": 70, + "end_line": 94, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "minimum_fill_value", + "long_name": "minimum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 105, + "parameters": [ + "obj" + ], + "start_line": 96, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "maximum_fill_value", + "long_name": "maximum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 103, + "parameters": [ + "obj" + ], + "start_line": 113, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( a , fill_value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 2, + "token_count": 20, + "parameters": [ + "a", + "fill_value" + ], + "start_line": 130, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "getmask", + "long_name": "getmask( a )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "a" + ], + "start_line": 135, + "end_line": 142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "getmaskarray", + "long_name": "getmaskarray( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 144, + "end_line": 153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "is_mask", + "long_name": "is_mask( m )", + "filename": "ma.py", + "nloc": 6, + "complexity": 4, + "token_count": 33, + "parameters": [ + "m" + ], + "start_line": 155, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "make_mask", + "long_name": "make_mask( m , copy = 0 , flag = 0 )", + "filename": "ma.py", + "nloc": 17, + "complexity": 7, + "token_count": 107, + "parameters": [ + "m", + "copy", + "flag" + ], + "start_line": 164, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "make_mask_none", + "long_name": "make_mask_none( s )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 25, + "parameters": [ + "s" + ], + "start_line": 189, + "end_line": 193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "mask_or", + "long_name": "mask_or( m1 , m2 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 5, + "token_count": 52, + "parameters": [ + "m1", + "m2" + ], + "start_line": 195, + "end_line": 202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "filled", + "long_name": "filled( a , value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 5, + "token_count": 70, + "parameters": [ + "a", + "value" + ], + "start_line": 204, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "get_fill_value", + "long_name": "get_fill_value( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 224, + "end_line": 233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "common_fill_value", + "long_name": "common_fill_value( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a", + "b" + ], + "start_line": 235, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , y1 , y2 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "y1", + "y2" + ], + "start_line": 245, + "end_line": 248, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 35, + "parameters": [ + "self", + "x" + ], + "start_line": 250, + "end_line": 254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , eps )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "eps" + ], + "start_line": 258, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "x" + ], + "start_line": 262, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 268, + "end_line": 270, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 272, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 278, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 282, + "end_line": 284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , aufunc , fill = 0 , domain = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "aufunc", + "fill", + "domain" + ], + "start_line": 287, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 16, + "complexity": 5, + "token_count": 112, + "parameters": [ + "self", + "a", + "args", + "kwargs" + ], + "start_line": 298, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 316, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , tolerance = divide_tolerance )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "tolerance" + ], + "start_line": 321, + "end_line": 322, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 323, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , domain , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 53, + "parameters": [ + "self", + "abfunc", + "domain", + "fillx", + "filly" + ], + "start_line": 330, + "end_line": 338, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 147, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 340, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 363, + "end_line": 364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "abfunc", + "fillx", + "filly" + ], + "start_line": 367, + "end_line": 374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 113, + "parameters": [ + "self", + "a", + "b", + "args", + "kwargs" + ], + "start_line": 376, + "end_line": 390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 20, + "complexity": 6, + "token_count": 157, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 392, + "end_line": 412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 414, + "end_line": 425, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "accumulate", + "long_name": "accumulate( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 427, + "end_line": 430, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 431, + "end_line": 432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "rank", + "long_name": "rank( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 494, + "end_line": 495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 497, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( object , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 21, + "parameters": [ + "object", + "axis" + ], + "start_line": 500, + "end_line": 501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , data , dtype = None , copy = True , fortran = False , mask = None , fill_value = None )", + "filename": "ma.py", + "nloc": 56, + "complexity": 18, + "token_count": 379, + "parameters": [ + "self", + "data", + "dtype", + "copy", + "fortran", + "mask", + "fill_value" + ], + "start_line": 532, + "end_line": 594, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "__array__", + "long_name": "__array__( self , t = None )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 67, + "parameters": [ + "self", + "t" + ], + "start_line": 596, + "end_line": 611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__array_wrap__", + "long_name": "__array_wrap__( self , array )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "array" + ], + "start_line": 613, + "end_line": 617, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_shape", + "long_name": "_get_shape( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 619, + "end_line": 621, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_set_shape", + "long_name": "_set_shape( self , newshape )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "newshape" + ], + "start_line": 623, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_get_flat", + "long_name": "_get_flat( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 630, + "end_line": 639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "_set_flat", + "long_name": "_set_flat( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "value" + ], + "start_line": 641, + "end_line": 644, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_real", + "long_name": "_get_real( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 646, + "end_line": 653, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_real", + "long_name": "_set_real( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 655, + "end_line": 658, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_imaginary", + "long_name": "_get_imaginary( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 660, + "end_line": 667, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_imaginary", + "long_name": "_set_imaginary( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 669, + "end_line": 672, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 674, + "end_line": 691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "ma.py", + "nloc": 42, + "complexity": 5, + "token_count": 207, + "parameters": [ + "self" + ], + "start_line": 693, + "end_line": 738, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 1 + }, + { + "name": "__float__", + "long_name": "__float__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 740, + "end_line": 745, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__int__", + "long_name": "__int__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 747, + "end_line": 752, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , i )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 70, + "parameters": [ + "self", + "i" + ], + "start_line": 754, + "end_line": 768, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 770, + "end_line": 778, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__setitem__", + "long_name": "__setitem__( self , index , value )", + "filename": "ma.py", + "nloc": 27, + "complexity": 7, + "token_count": 157, + "parameters": [ + "self", + "index", + "value" + ], + "start_line": 785, + "end_line": 811, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "__setslice__", + "long_name": "__setslice__( self , i , j , value )", + "filename": "ma.py", + "nloc": 23, + "complexity": 7, + "token_count": 155, + "parameters": [ + "self", + "i", + "j", + "value" + ], + "start_line": 813, + "end_line": 835, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "__nonzero__", + "long_name": "__nonzero__( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 837, + "end_line": 847, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 849, + "end_line": 852, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__and__", + "long_name": "__and__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 854, + "end_line": 856, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__or__", + "long_name": "__or__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 858, + "end_line": 860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__xor__", + "long_name": "__xor__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 862, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__abs__", + "long_name": "__abs__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 870, + "end_line": 872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__neg__", + "long_name": "__neg__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 874, + "end_line": 876, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pos__", + "long_name": "__pos__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 878, + "end_line": 880, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__add__", + "long_name": "__add__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 882, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mod__", + "long_name": "__mod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 888, + "end_line": 890, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rmod__", + "long_name": "__rmod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 892, + "end_line": 894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__lshift__", + "long_name": "__lshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 896, + "end_line": 897, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__rshift__", + "long_name": "__rshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 899, + "end_line": 900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__sub__", + "long_name": "__sub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 902, + "end_line": 904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rsub__", + "long_name": "__rsub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 906, + "end_line": 908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mul__", + "long_name": "__mul__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 910, + "end_line": 912, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__div__", + "long_name": "__div__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 916, + "end_line": 918, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rdiv__", + "long_name": "__rdiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 920, + "end_line": 922, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__truediv__", + "long_name": "__truediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 924, + "end_line": 926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rtruediv__", + "long_name": "__rtruediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 928, + "end_line": 930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__floordiv__", + "long_name": "__floordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 932, + "end_line": 934, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rfloordiv__", + "long_name": "__rfloordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 936, + "end_line": 938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pow__", + "long_name": "__pow__( self , other , third = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "other", + "third" + ], + "start_line": 940, + "end_line": 942, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__sqrt__", + "long_name": "__sqrt__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 944, + "end_line": 946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__iadd__", + "long_name": "__iadd__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 948, + "end_line": 989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__imul__", + "long_name": "__imul__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 251, + "parameters": [ + "self", + "other" + ], + "start_line": 991, + "end_line": 1032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__isub__", + "long_name": "__isub__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 1034, + "end_line": 1075, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__idiv__", + "long_name": "__idiv__( self , other )", + "filename": "ma.py", + "nloc": 38, + "complexity": 12, + "token_count": 233, + "parameters": [ + "self", + "other" + ], + "start_line": 1079, + "end_line": 1116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 1 + }, + { + "name": "__eq__", + "long_name": "__eq__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1118, + "end_line": 1119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ne__", + "long_name": "__ne__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1121, + "end_line": 1122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__lt__", + "long_name": "__lt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1124, + "end_line": 1125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__le__", + "long_name": "__le__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1127, + "end_line": 1128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__gt__", + "long_name": "__gt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1130, + "end_line": 1131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ge__", + "long_name": "__ge__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1133, + "end_line": 1134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "astype", + "long_name": "astype( self , tc )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "tc" + ], + "start_line": 1136, + "end_line": 1139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "byte_swapped", + "long_name": "byte_swapped( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 1141, + "end_line": 1145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "compressed", + "long_name": "compressed( self )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 1147, + "end_line": 1155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "count", + "long_name": "count( self , axis = None )", + "filename": "ma.py", + "nloc": 29, + "complexity": 7, + "token_count": 173, + "parameters": [ + "self", + "axis" + ], + "start_line": 1157, + "end_line": 1185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "dot", + "long_name": "dot( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1187, + "end_line": 1189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "fill_value", + "long_name": "fill_value( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1191, + "end_line": 1193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "filled", + "long_name": "filled( self , fill_value = None )", + "filename": "ma.py", + "nloc": 31, + "complexity": 9, + "token_count": 183, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1195, + "end_line": 1235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + }, + { + "name": "ids", + "long_name": "ids( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 1237, + "end_line": 1239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "iscontiguous", + "long_name": "iscontiguous( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 1241, + "end_line": 1243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "itemsize", + "long_name": "itemsize( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 1245, + "end_line": 1247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1250, + "end_line": 1252, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "put", + "long_name": "put( self , values )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "values" + ], + "start_line": 1254, + "end_line": 1264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "putmask", + "long_name": "putmask( self , values )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "values" + ], + "start_line": 1266, + "end_line": 1274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "ravel", + "long_name": "ravel( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 1276, + "end_line": 1281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "raw_data", + "long_name": "raw_data( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1283, + "end_line": 1287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "raw_mask", + "long_name": "raw_mask( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1291, + "end_line": 1295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "reshape", + "long_name": "reshape( self , * s )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self", + "s" + ], + "start_line": 1299, + "end_line": 1306, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( self , v = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self", + "v" + ], + "start_line": 1308, + "end_line": 1312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_size", + "long_name": "_get_size( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1314, + "end_line": 1315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtypechar", + "long_name": "_get_dtypechar( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1319, + "end_line": 1320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtype", + "long_name": "_get_dtype( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1323, + "end_line": 1324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "item", + "long_name": "item( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 4, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 1327, + "end_line": 1336, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "tolist", + "long_name": "tolist( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1338, + "end_line": 1340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "tostring", + "long_name": "tostring( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1342, + "end_line": 1344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "unmask", + "long_name": "unmask( self )", + "filename": "ma.py", + "nloc": 7, + "complexity": 3, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 1346, + "end_line": 1352, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "unshare_mask", + "long_name": "unshare_mask( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 1354, + "end_line": 1358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "isMaskedArray", + "long_name": "isMaskedArray( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "x" + ], + "start_line": 1378, + "end_line": 1380, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "allclose", + "long_name": "allclose( a , b , fill_value = 1 , rtol = 1 . e - 5 , atol = 1 . e - 8 )", + "filename": "ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 140, + "parameters": [ + "a", + "b", + "fill_value", + "rtol", + "atol" + ], + "start_line": 1385, + "end_line": 1400, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "allequal", + "long_name": "allequal( a , b , fill_value = 1 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 3, + "token_count": 125, + "parameters": [ + "a", + "b", + "fill_value" + ], + "start_line": 1402, + "end_line": 1420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "masked_values", + "long_name": "masked_values( data , value , rtol = 1 . e - 5 , atol = 1 . e - 8 , copy = 1 )", + "filename": "ma.py", + "nloc": 10, + "complexity": 2, + "token_count": 115, + "parameters": [ + "data", + "value", + "rtol", + "atol", + "copy" + ], + "start_line": 1422, + "end_line": 1441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "masked_object", + "long_name": "masked_object( data , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "data", + "value", + "copy" + ], + "start_line": 1443, + "end_line": 1447, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayrange", + "long_name": "arrayrange( start , stop = None , step = 1 , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 34, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 1449, + "end_line": 1453, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "fromstring", + "long_name": "fromstring( s , t )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "s", + "t" + ], + "start_line": 1457, + "end_line": 1459, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "left_shift", + "long_name": "left_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1461, + "end_line": 1469, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "right_shift", + "long_name": "right_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1471, + "end_line": 1479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 1481, + "end_line": 1489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 101, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 1491, + "end_line": 1506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "identity", + "long_name": "identity( n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "n" + ], + "start_line": 1508, + "end_line": 1511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "indices", + "long_name": "indices( dimensions , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "dimensions", + "dtype" + ], + "start_line": 1513, + "end_line": 1517, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "zeros", + "long_name": "zeros( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1519, + "end_line": 1522, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ones", + "long_name": "ones( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1524, + "end_line": 1527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "count", + "long_name": "count( a , axis = None )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a", + "axis" + ], + "start_line": 1530, + "end_line": 1533, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "power", + "long_name": "power( a , b , third = None )", + "filename": "ma.py", + "nloc": 18, + "complexity": 4, + "token_count": 152, + "parameters": [ + "a", + "b", + "third" + ], + "start_line": 1535, + "end_line": 1552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "masked_array", + "long_name": "masked_array( a , mask = None , fill_value = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "mask", + "fill_value" + ], + "start_line": 1554, + "end_line": 1558, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "average", + "long_name": "average( a , axis = 0 , weights = None , returned = 0 )", + "filename": "ma.py", + "nloc": 92, + "complexity": 22, + "token_count": 741, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 1563, + "end_line": 1670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "where", + "long_name": "where( condition , x , y )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 149, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 1672, + "end_line": 1698, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "choose.fmask", + "long_name": "choose.fmask( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 2, + "token_count": 17, + "parameters": [ + "x" + ], + "start_line": 1702, + "end_line": 1704, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "choose.nmask", + "long_name": "choose.nmask( x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 3, + "token_count": 27, + "parameters": [ + "x" + ], + "start_line": 1705, + "end_line": 1709, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "choose", + "long_name": "choose( indices , t )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 93, + "parameters": [ + "indices", + "t" + ], + "start_line": 1700, + "end_line": 1716, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "masked_where", + "long_name": "masked_where( condition , x , copy = 1 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 47, + "parameters": [ + "condition", + "x", + "copy" + ], + "start_line": 1718, + "end_line": 1724, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "masked_greater", + "long_name": "masked_greater( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1726, + "end_line": 1728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_greater_equal", + "long_name": "masked_greater_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1730, + "end_line": 1732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less", + "long_name": "masked_less( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1734, + "end_line": 1736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less_equal", + "long_name": "masked_less_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1738, + "end_line": 1740, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_not_equal", + "long_name": "masked_not_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1742, + "end_line": 1747, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "masked_equal", + "long_name": "masked_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1749, + "end_line": 1756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "masked_inside", + "long_name": "masked_inside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1758, + "end_line": 1769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "masked_outside", + "long_name": "masked_outside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1771, + "end_line": 1782, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , * newshape )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 56, + "parameters": [ + "a", + "newshape" + ], + "start_line": 1784, + "end_line": 1791, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( a )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "a" + ], + "start_line": 1793, + "end_line": 1800, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "concatenate", + "long_name": "concatenate( arrays , axis = 0 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 5, + "token_count": 97, + "parameters": [ + "arrays", + "axis" + ], + "start_line": 1802, + "end_line": 1816, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 76, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 1818, + "end_line": 1826, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "a", + "axes" + ], + "start_line": 1828, + "end_line": 1836, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , indices , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 70, + "parameters": [ + "a", + "indices", + "values" + ], + "start_line": 1839, + "end_line": 1852, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 61, + "parameters": [ + "a", + "mask", + "values" + ], + "start_line": 1854, + "end_line": 1862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "innerproduct", + "long_name": "innerproduct( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 3, + "token_count": 72, + "parameters": [ + "a", + "b" + ], + "start_line": 1864, + "end_line": 1874, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "outerproduct", + "long_name": "outerproduct( a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 110, + "parameters": [ + "a", + "b" + ], + "start_line": 1876, + "end_line": 1888, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dot", + "long_name": "dot( a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 36, + "parameters": [ + "a", + "b" + ], + "start_line": 1890, + "end_line": 1895, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , x , dimension = - 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 67, + "parameters": [ + "condition", + "x", + "dimension" + ], + "start_line": 1897, + "end_line": 1906, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1910, + "end_line": 1914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1916, + "end_line": 1929, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1931, + "end_line": 1940, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1942, + "end_line": 1953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1959, + "end_line": 1963, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1965, + "end_line": 1978, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1980, + "end_line": 1989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1991, + "end_line": 2002, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "sort", + "long_name": "sort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 8, + "complexity": 3, + "token_count": 68, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2006, + "end_line": 2023, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , k = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 73, + "parameters": [ + "a", + "k", + "axis1", + "axis2" + ], + "start_line": 2025, + "end_line": 2032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2034, + "end_line": 2041, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2043, + "end_line": 2051, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 52, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2053, + "end_line": 2067, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "fromfunction", + "long_name": "fromfunction( f , s )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "f", + "s" + ], + "start_line": 2069, + "end_line": 2071, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( data , dtype = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 46, + "parameters": [ + "data", + "dtype" + ], + "start_line": 2073, + "end_line": 2079, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "_m", + "long_name": "_m( f )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "f" + ], + "start_line": 2085, + "end_line": 2086, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "not_implemented", + "long_name": "not_implemented( * args , ** kwds )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "args", + "kwds" + ], + "start_line": 2087, + "end_line": 2088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_compress", + "long_name": "_compress( self , cond , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "cond", + "axis" + ], + "start_line": 2104, + "end_line": 2105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_choose", + "long_name": "_choose( self , * args )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 2097, + "end_line": 2098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "nloc": 1678, + "complexity": 455, + "token_count": 11686, + "diff_parsed": { + "added": [ + "# Add methods to support ndarray interface", + "# XXX: I is better to to change the masked_*_operation adaptors", + "# XXX: to wrap ndarray methods directly to create ma.array methods.", + "from types import MethodType", + "def _m(f):", + " return MethodType(f, None, array)", + "def not_implemented(*args, **kwds):", + " raise NotImplementedError, \"not yet implemented for numpy.ma arrays\"", + "array.all = _m(alltrue)", + "array.any = _m(sometrue)", + "array.argmax = _m(argmax)", + "array.argmin = _m(argmin)", + "array.argsort = _m(argsort)", + "array.base = property(_m(not_implemented))", + "array.byteswap = _m(not_implemented)", + "", + "def _choose(self, *args):", + " return choose(self, args)", + "array.choose = _m(_choose)", + "del _choose", + "", + "array.clip = _m(not_implemented)", + "", + "def _compress(self, cond, axis=None):", + " return compress(cond, self, axis)", + "array.compress = _m(_compress)", + "del _compress", + "", + "array.conj = array.conjugate = _m(conjugate)", + "array.copy = _m(not_implemented)", + "array.cumprod = _m(not_implemented)", + "array.cumsum = _m(not_implemented)", + "array.diagonal = _m(diagonal)", + "array.dtypedescr = property(_m(not_implemented))", + "array.dtypestr = property(_m(not_implemented))", + "array.dump = _m(not_implemented)", + "array.dumps = _m(not_implemented)", + "array.fill = _m(not_implemented)", + "array.flags = property(_m(not_implemented))", + "array.flatten = _m(ravel)", + "array.getfield = _m(not_implemented)", + "array.max = _m(maximum)", + "array.mean = _m(average)", + "array.min = _m(minimum)", + "array.nbytes = property(_m(not_implemented))", + "array.ndim = _m(not_implemented)", + "array.newbyteorder = _m(not_implemented)", + "array.nonzero = _m(nonzero)", + "array.prod = _m(product)", + "array.ptp = _m(not_implemented)", + "array.repeat = _m(repeat)", + "array.resize = _m(resize)", + "array.searchsorted = _m(not_implemented)", + "array.setfield = _m(not_implemented)", + "array.setflags = _m(not_implemented)", + "array.sort = _m(not_implemented) # NB: ndarray.sort is inplace", + "array.squeeze = _m(not_implemented)", + "array.std = _m(not_implemented)", + "array.strides = property(_m(not_implemented))", + "array.sum = _m(sum)", + "array.swapaxes = _m(not_implemented)", + "array.take = _m(take)", + "array.tofile = _m(not_implemented)", + "array.trace = _m(not_implemented)", + "array.transpose = _m(transpose)", + "array.var = _m(not_implemented)", + "array.view = _m(not_implemented)", + "del _m, MethodType, not_implemented", + "", + "" + ], + "deleted": [] + } + }, + { + "old_path": "numpy/core/tests/test_ma.py", + "new_path": "numpy/core/tests/test_ma.py", + "filename": "test_ma.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -605,6 +605,27 @@ def check_testScalarArithmetic(self):\n self.failUnless(xm.filled().dtype is xm.data.dtype)\n x = array(0, mask=0)\n self.failUnless(x.filled() is x.data)\n+\n+ def check_testArrayMethods(self):\n+ a = array([1,3,2])\n+ b = array([1,3,2], mask=[1,0,1])\n+ self.failUnless(eq(a.any(), a.data.any()))\n+ self.failUnless(eq(a.all(), a.data.all()))\n+ self.failUnless(eq(a.argmax(), a.data.argmax()))\n+ self.failUnless(eq(a.argmin(), a.data.argmin()))\n+ self.failUnless(eq(a.choose(0,1,2,3,4), a.data.choose(0,1,2,3,4)))\n+ self.failUnless(eq(a.compress([1,0,1]), a.data.compress([1,0,1])))\n+ self.failUnless(eq(a.conj(), a.data.conj()))\n+ self.failUnless(eq(a.conjugate(), a.data.conjugate()))\n+ m = array([[1,2],[3,4]])\n+ self.failUnless(eq(m.diagonal(), m.data.diagonal()))\n+ self.failUnless(eq(a.sum(), a.data.sum()))\n+ self.failUnless(eq(a.take([1,2]), a.data.take([1,2])))\n+ self.failUnless(eq(m.transpose(), m.data.transpose()))\n+ \n+ def check_testAPI(self):\n+ self.failIf([m for m in dir(numpy.ndarray)\n+ if m not in dir(array) and not m.startswith('_')])\n \n def timingTest():\n for f in [testf, testinplace]:\n", + "added_lines": 21, + "deleted_lines": 0, + "source_code": "import numpy \nimport types, time\nfrom numpy.core.ma import *\nfrom numpy.testing import ScipyTestCase, ScipyTest\ndef eq(v,w):\n result = allclose(v,w)\n if not result:\n print \"\"\"Not eq:\n%s\n----\n%s\"\"\"% (str(v), str(w))\n return result\n\nclass test_ma(ScipyTestCase):\n def __init__(self, *args, **kwds):\n ScipyTestCase.__init__(self, *args, **kwds)\n self.setUp()\n \n def setUp (self):\n x=numpy.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])\n y=numpy.array([5.,0.,3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])\n a10 = 10.\n m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]\n m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0 ,0, 1]\n xm = array(x, mask=m1)\n ym = array(y, mask=m2)\n z = numpy.array([-.5, 0., .5, .8])\n zm = array(z, mask=[0,1,0,0])\n xf = numpy.where(m1, 1.e+20, x)\n s = x.shape\n xm.set_fill_value(1.e+20)\n self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf, s)\n\n def check_testBasic1d(self):\n \"Test of basic array creation and properties in 1 dimension.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual(xm.dtype, x.dtype)\n self.assertEqual(xm.dtypechar, x.dtypechar)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual(count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n\n def check_testBasic2d(self):\n \"Test of basic array creation and properties in 2 dimensions.\"\n for s in [(4,3), (6,2)]: \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n x.shape = s\n y.shape = s\n xm.shape = s\n ym.shape = s\n xf.shape = s\n \n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual( count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n self.setUp()\n\n def check_testArithmetic (self):\n \"Test of basic arithmetic.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n a2d = array([[1,2],[0,4]])\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n self.failUnless(eq (a2d * a2d, a2d * a2dm))\n self.failUnless(eq (a2d + a2d, a2d + a2dm))\n self.failUnless(eq (a2d - a2d, a2d - a2dm))\n for s in [(12,), (4,3), (2,6)]: \n x = x.reshape(s)\n y = y.reshape(s)\n xm = xm.reshape(s)\n ym = ym.reshape(s)\n xf = xf.reshape(s)\n self.failUnless(eq(-x, -xm))\n self.failUnless(eq(x + y, xm + ym))\n self.failUnless(eq(x - y, xm - ym))\n self.failUnless(eq(x * y, xm * ym))\n self.failUnless(eq(x / y, xm / ym))\n self.failUnless(eq(a10 + y, a10 + ym))\n self.failUnless(eq(a10 - y, a10 - ym))\n self.failUnless(eq(a10 * y, a10 * ym))\n self.failUnless(eq(a10 / y, a10 / ym))\n self.failUnless(eq(x + a10, xm + a10))\n self.failUnless(eq(x - a10, xm - a10))\n self.failUnless(eq(x * a10, xm * a10))\n self.failUnless(eq(x / a10, xm / a10))\n self.failUnless(eq(x**2, xm**2))\n self.failUnless(eq(abs(x)**2.5, abs(xm) **2.5))\n self.failUnless(eq(x**y, xm**ym))\n self.failUnless(eq(numpy.add(x,y), add(xm, ym)))\n self.failUnless(eq(numpy.subtract(x,y), subtract(xm, ym)))\n self.failUnless(eq(numpy.multiply(x,y), multiply(xm, ym)))\n self.failUnless(eq(numpy.divide(x,y), divide(xm, ym)))\n\n\n def check_testMixedArithmetic(self):\n na = numpy.array([1])\n ma = array([1])\n self.failUnless(isinstance(na + ma, MaskedArray))\n self.failUnless(isinstance(ma + na, MaskedArray))\n \n def check_testUfuncs1 (self):\n \"Test various functions such as sin, cos.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.cos(x), cos(xm)))\n self.failUnless (eq(numpy.cosh(x), cosh(xm)))\n self.failUnless (eq(numpy.sin(x), sin(xm)))\n self.failUnless (eq(numpy.sinh(x), sinh(xm)))\n self.failUnless (eq(numpy.tan(x), tan(xm)))\n self.failUnless (eq(numpy.tanh(x), tanh(xm)))\n self.failUnless (eq(numpy.sqrt(abs(x)), sqrt(xm)))\n self.failUnless (eq(numpy.log(abs(x)), log(xm)))\n self.failUnless (eq(numpy.log10(abs(x)), log10(xm)))\n self.failUnless (eq(numpy.exp(x), exp(xm)))\n self.failUnless (eq(numpy.arcsin(z), arcsin(zm)))\n self.failUnless (eq(numpy.arccos(z), arccos(zm)))\n self.failUnless (eq(numpy.arctan(z), arctan(zm)))\n self.failUnless (eq(numpy.arctan2(x, y), arctan2(xm, ym)))\n self.failUnless (eq(numpy.absolute(x), absolute(xm)))\n self.failUnless (eq(numpy.equal(x,y), equal(xm, ym)))\n self.failUnless (eq(numpy.not_equal(x,y), not_equal(xm, ym)))\n self.failUnless (eq(numpy.less(x,y), less(xm, ym)))\n self.failUnless (eq(numpy.greater(x,y), greater(xm, ym)))\n self.failUnless (eq(numpy.less_equal(x,y), less_equal(xm, ym)))\n self.failUnless (eq(numpy.greater_equal(x,y), greater_equal(xm, ym)))\n self.failUnless (eq(numpy.conjugate(x), conjugate(xm)))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,ym))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((x,y))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,y))))\n self.failUnless (eq(numpy.concatenate((x,y,x)), concatenate((x,ym,x))))\n \n def check_xtestCount (self):\n \"Test count\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless( isinstance(count(ott), types.IntType))\n self.assertEqual(3, count(ott))\n self.assertEqual(1, count(1))\n self.failUnless (eq(0, array(1,mask=[1])))\n ott=ott.reshape((2,2))\n assert isMaskedArray(count(ott,0))\n assert isinstance(count(ott), types.IntType)\n self.failUnless (eq(3, count(ott)))\n assert getmask(count(ott,0)) is None\n self.failUnless (eq([1,2],count(ott,0)))\n \n def check_testMinMax (self):\n \"Test minimum and maximum.\" \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n xr = numpy.ravel(x) #max doesn't work if shaped\n xmr = ravel(xm)\n self.failUnless (eq(max(xr), maximum(xmr))) #true because of careful selection of data\n self.failUnless (eq(min(xr), minimum(xmr))) #true because of careful selection of data\n\n def check_testAddSumProd (self):\n \"Test add, sum, product.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.add.reduce(x), add.reduce(x)))\n self.failUnless (eq(numpy.add.accumulate(x), add.accumulate(x)))\n self.failUnless (eq(4, sum(array(4))))\n self.failUnless (eq(4, sum(array(4), axis=0)))\n self.failUnless (eq(numpy.sum(x), sum(x)))\n self.failUnless (eq(numpy.sum(filled(xm,0)), sum(xm)))\n self.failUnless (eq(numpy.sum(x,0), sum(x,0)))\n self.failUnless (eq(numpy.product(x), product(x)))\n self.failUnless (eq(numpy.product(x,0), product(x,0)))\n self.failUnless (eq(numpy.product(filled(xm,1)), product(xm)))\n if len(s) > 1:\n self.failUnless (eq(numpy.concatenate((x,y),1), concatenate((xm,ym),1)))\n self.failUnless (eq(numpy.add.reduce(x,1), add.reduce(x,1)))\n self.failUnless (eq(numpy.sum(x,1), sum(x,1)))\n self.failUnless (eq(numpy.product(x,1), product(x,1)))\n \n \n def check_testCI(self):\n \"Test of conversions and indexing\"\n x1 = numpy.array([1,2,4,3])\n x2 = array(x1, mask = [1,0,0,0])\n x3 = array(x1, mask = [0,1,0,1])\n x4 = array(x1)\n # test conversion to strings\n junk, garbage = str(x2), repr(x2)\n assert eq(numpy.sort(x1),sort(x2, fill_value=0))\n # tests of indexing\n assert type(x2[1]) is type(x1[1])\n assert x1[1] == x2[1]\n assert x2[0] is masked\n assert eq(x1[2],x2[2])\n assert eq(x1[2:5],x2[2:5])\n assert eq(x1[:],x2[:])\n assert eq(x1[1:], x3[1:])\n x1[2]=9\n x2[2]=9\n assert eq(x1,x2)\n x1[1:3] = 99\n x2[1:3] = 99\n assert eq(x1,x2)\n x2[1] = masked\n assert eq(x1,x2)\n x2[1:3]=masked\n assert eq(x1,x2)\n x2[:] = x1\n x2[1] = masked\n assert allequal(getmask(x2),array([0,1,0,0]))\n x3[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x3), array([0,1,1,0]))\n x4[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x4), array([0,1,1,0]))\n assert allequal(x4, array([1,2,3,4]))\n x1 = numpy.arange(5)*1.0\n x2 = masked_values(x1, 3.0)\n assert eq(x1,x2)\n assert allequal(array([0,0,0,1,0],MaskType), x2.mask)\n assert eq(3.0, x2.fill_value())\n x1 = array([1,'hello',2,3],object)\n x2 = numpy.array([1,'hello',2,3],object)\n s1 = x1[1]\n s2 = x2[1]\n self.assertEqual(type(s2), str)\n self.assertEqual(type(s1), str)\n self.assertEqual(s1, s2)\n assert x1[1:1].shape == (0,)\n \n def check_testCopySize(self):\n \"Tests of some subtle points of copying and sizing.\"\n n = [0,0,1,0,0]\n m = make_mask(n)\n m2 = make_mask(m)\n self.failUnless(m is m2)\n m3 = make_mask(m, copy=1)\n self.failUnless(m is not m3)\n \n x1 = numpy.arange(5)\n y1 = array(x1, mask=m)\n self.failUnless( y1.raw_data() is not x1)\n self.failUnless( allequal(x1,y1.raw_data()))\n self.failUnless( y1.mask is m)\n \n y1a = array(y1, copy=0)\n self.failUnless( y1a.raw_data() is y1.raw_data())\n self.failUnless( y1a.mask is y1.mask)\n \n y2 = array(x1, mask=m, copy=0)\n self.failUnless( y2.raw_data() is x1)\n self.failUnless( y2.mask is m)\n self.failUnless( y2[2] is masked)\n y2[2]=9\n self.failUnless( y2[2] is not masked)\n self.failUnless( y2.mask is not m)\n self.failUnless( allequal(y2.mask, 0))\n \n y3 = array(x1*1.0, mask=m)\n self.failUnless(filled(y3).dtype is (x1*1.0).dtype)\n \n x4 = arange(4)\n x4[2] = masked\n y4 = resize(x4, (8,))\n self.failUnless( eq(concatenate([x4,x4]), y4))\n self.failUnless( eq(getmask(y4),[0,0,1,0,0,0,1,0]))\n y5 = repeat(x4, (2,2,2,2))\n self.failUnless( eq(y5, [0,0,1,1,2,2,3,3]))\n y6 = repeat(x4, 2)\n self.failUnless( eq(y5, y6))\n \n def check_testPut(self):\n \"Test of put\"\n d = arange(5)\n n = [0,0,0,1,1]\n m = make_mask(n)\n x = array(d, mask = m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n x[[1,4]] = [10,40]\n self.failUnless( x.mask is not m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is not masked)\n self.failUnless( eq(x, [0,10,2,-1,40]))\n \n x = array(d, mask = m) \n x.put([-1,100,200])\n self.failUnless( eq(x, [-1,100,200,0,0]))\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n \n x = array(d, mask = m) \n x.putmask([30,40])\n self.failUnless( eq(x, [0,1,2,30,40]))\n self.failUnless( x.mask is None)\n \n x = array(d, mask = m) \n y = x.compressed()\n z = array(x, mask = m)\n z.put(y)\n assert eq (x, z)\n \n def check_testMaPut(self):\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]\n i = numpy.nonzero(m)\n putmask(xm, m, z)\n assert take(xm, i) == z\n put(ym, i, zm)\n assert take(ym, i) == zm\n \n def check_testOddFeatures(self):\n \"Test of other odd features\"\n x = arange(20); x=x.reshape(4,5)\n x.flat[5] = 12\n assert x[1,0] == 12\n z = x + 10j * x\n assert eq(z.real, x)\n assert eq(z.imag, 10*x)\n assert eq((z*conjugate(z)).real, 101*x*x)\n z.imag[...] = 0.0\n \n x = arange(10)\n x[3] = masked\n assert str(x[3]) == str(masked)\n c = x >= 8\n assert count(where(c,masked,masked)) == 0\n assert shape(where(c,masked,masked)) == c.shape\n z = where(c , x, masked)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is masked\n assert z[7] is masked\n assert z[8] is not masked\n assert z[9] is not masked\n assert eq(x,z)\n z = where(c , masked, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n z = masked_where(c, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n assert eq(x,z)\n x = array([1.,2.,3.,4.,5.])\n c = array([1,1,1,0,0])\n x[2] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n c[0] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n assert eq(masked_where(greater(x, 2), x), masked_greater(x,2))\n assert eq(masked_where(greater_equal(x, 2), x), masked_greater_equal(x,2))\n assert eq(masked_where(less(x, 2), x), masked_less(x,2))\n assert eq(masked_where(less_equal(x, 2), x), masked_less_equal(x,2))\n assert eq(masked_where(not_equal(x, 2), x), masked_not_equal(x,2))\n assert eq(masked_where(equal(x, 2), x), masked_equal(x,2))\n assert eq(masked_where(not_equal(x,2), x), masked_not_equal(x,2))\n assert eq(masked_inside(range(5), 1, 3), [0, 199, 199, 199, 4])\n assert eq(masked_outside(range(5), 1, 3),[199,1,2,3,199])\n assert eq(masked_inside(array(range(5), mask=[1,0,0,0,0]), 1, 3).mask, [1,1,1,1,0])\n assert eq(masked_outside(array(range(5), mask=[0,1,0,0,0]), 1, 3).mask, [1,1,0,0,1])\n assert eq(masked_equal(array(range(5), mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,0])\n assert eq(masked_not_equal(array([2,2,1,2,1], mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,1])\n assert eq(masked_where([1,1,0,0,0], [1,2,3,4,5]), [99,99,3,4,5])\n atest = ones((10,10,10), dtype=float32)\n btest = zeros(atest.shape, MaskType)\n ctest = masked_where(btest,atest)\n assert eq(atest,ctest)\n z = choose(c, (-x, x))\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n x = arange(6)\n x[5] = masked\n y = arange(6)*10\n y[2]= masked\n c = array([1,1,1,0,0,0], mask=[1,0,0,0,0,0])\n cm = c.filled(1)\n z = where(c,x,y)\n zm = where(cm,x,y)\n assert eq(z, zm)\n assert getmask(zm) is None\n assert eq(zm, [0,1,2,30,40,50])\n z = where(c, masked, 1)\n assert eq(z, [99,99,99,1,1,1])\n z = where(c, 1, masked)\n assert eq(z, [99, 1, 1, 99, 99, 99])\n \n def check_testMinMax(self):\n \"Test of minumum, maximum.\" \n assert eq(minimum([1,2,3],[4,0,9]), [1,0,3])\n assert eq(maximum([1,2,3],[4,0,9]), [4,2,9])\n x = arange(5)\n y = arange(5) - 2\n x[3] = masked\n y[0] = masked\n assert eq(minimum(x,y), where(less(x,y), x, y))\n assert eq(maximum(x,y), where(greater(x,y), x, y))\n assert minimum(x) == 0\n assert maximum(x) == 4\n \n def check_testTakeTransposeInnerOuter(self):\n \"Test of take, transpose, inner, outer products\"\n x = arange(24)\n y = numpy.arange(24)\n x[5:6] = masked\n x=x.reshape(2,3,4)\n y=y.reshape(2,3,4)\n assert eq(numpy.transpose(y,(2,0,1)), transpose(x,(2,0,1)))\n assert eq(numpy.take(y, (2,0,1), 1), take(x, (2,0,1), 1))\n assert eq(numpy.innerproduct(filled(x,0),filled(y,0)),\n innerproduct(x, y))\n assert eq(numpy.outerproduct(filled(x,0),filled(y,0)),\n outerproduct(x, y))\n y = array(['abc', 1, 'def', 2, 3], object)\n y[2] = masked\n t = take(y,[0,3,4])\n assert t[0] == 'abc'\n assert t[1] == 2\n assert t[2] == 3\n \n def check_testInplace(self):\n \"\"\"Test of inplace operations and rich comparisons\"\"\"\n y = arange(10)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x += 1\n assert eq(x, y+1)\n xm += 1\n assert eq(x, y+1)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x -= 1\n assert eq(x, y-1)\n xm -= 1\n assert eq(xm, y-1)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x *= 2.0\n assert eq(x, y*2)\n xm *= 2.0\n assert eq(xm, y*2)\n \n x = arange(10)*2\n xm = arange(10)\n xm[2] = masked\n x /= 2\n assert eq(x, y)\n xm /= 2\n assert eq(x, y)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x /= 2.0\n assert eq(x, y/2.0)\n xm /= arange(10)\n assert eq(xm, ones((10,)))\n \n x = arange(10).astype(float32)\n xm = arange(10)\n xm[2] = masked\n id1 = id(x.raw_data())\n x += 1.\n assert id1 == id(x.raw_data())\n assert eq(x, y+1.)\n \n def check_testPickle(self):\n \"Test of pickling\"\n x = arange(12)\n x[4:10:2] = masked\n x=x.reshape(4,3)\n f = open('test9.pik','wb')\n import pickle\n pickle.dump(x, f)\n f.close()\n f = open('test9.pik', 'rb')\n y = pickle.load(f)\n assert eq(x,y) \n \n def check_testMasked(self):\n \"Test of masked element\"\n xx=arange(6)\n xx[1] = masked\n self.failUnless(str(masked) == '--')\n self.failUnless(xx[1] is masked)\n # don't know why these should raise an exception...\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, masked)\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, 2)\n self.failUnlessRaises(Exception, lambda x,y: x+y, masked, xx)\n self.failUnlessRaises(Exception, lambda x,y: x+y, xx, masked)\n \n def check_testAverage1(self):\n \"Test of average.\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless(eq(2.0, average(ott)))\n self.failUnless(eq(2.0, average(ott, weights=[1., 1., 2., 1.])))\n result, wts = average(ott, weights=[1.,1.,2.,1.], returned=1)\n self.failUnless(eq(2.0, result))\n self.failUnless(wts == 4.0)\n ott[:] = masked\n self.failUnless(average(ott) is masked)\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n ott=ott.reshape(2,2)\n ott[:,1] = masked\n self.failUnless(eq(average(ott), [2.0, 0.0]))\n self.failUnless(average(ott,axis=1)[0] is masked)\n self.failUnless(eq([2.,0.], average(ott)))\n result, wts = average(ott, returned=1)\n self.failUnless(eq(wts, [1., 0.]))\n\n def check_testAverage2(self):\n \"More tests of average.\"\n w1 = [0,1,1,1,1,0]\n w2 = [[0,1,1,1,1,0],[1,0,0,0,0,1]]\n x=arange(6)\n self.failUnless(allclose(average(x), 2.5))\n self.failUnless(allclose(average(x, weights=w1), 2.5))\n y=array([arange(6), 2.0*arange(6)])\n self.failUnless(allclose(average(y, None), numpy.add.reduce(numpy.arange(6))*3./12.))\n self.failUnless(allclose(average(y, axis=0), numpy.arange(6) * 3./2.))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n self.failUnless(allclose(average(y, None, weights=w2), 20./6.))\n self.failUnless(allclose(average(y, axis=0, weights=w2), [0.,1.,2.,3.,4.,10.]))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n m1 = zeros(6)\n m2 = [0,0,1,1,0,0]\n m3 = [[0,0,1,1,0,0],[0,1,1,1,1,0]]\n m4 = ones(6)\n m5 = [0, 1, 1, 1, 1, 1]\n self.failUnless(allclose(average(masked_array(x, m1)), 2.5))\n self.failUnless(allclose(average(masked_array(x, m2)), 2.5))\n self.failUnless(average(masked_array(x, m4)) is masked)\n self.assertEqual(average(masked_array(x, m5)), 0.0)\n self.assertEqual(count(average(masked_array(x, m4))), 0)\n z = masked_array(y, m3)\n self.failUnless(allclose(average(z, None), 20./6.))\n self.failUnless(allclose(average(z, axis=0), [0.,1.,99.,99.,4.0, 7.5]))\n self.failUnless(allclose(average(z, axis=1), [2.5, 5.0]))\n self.failUnless(allclose( average(z,weights=w2), [0.,1., 99., 99., 4.0, 10.0]))\n \n a = arange(6)\n b = arange(6) * 3\n r1, w1 = average([[a,b],[b,a]], axis=1, returned=1)\n self.assertEqual(shape(r1) , shape(w1))\n self.assertEqual(r1.shape , w1.shape)\n r2, w2 = average(ones((2,2,3)), axis=0, weights=[3,1], returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), weights=ones((2,2,3)), returned=1)\n self.failUnless(shape(w2) == shape(r2))\n a2d = array([[1,2],[0,4]], float)\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n a2da = average(a2d)\n self.failUnless(eq (a2da, [0.5, 3.0]))\n a2dma = average(a2dm)\n self.failUnless(eq( a2dma, [1.0, 3.0]))\n a2dma = average(a2dm, axis=None)\n self.failUnless(eq(a2dma, 7./3.))\n a2dma = average(a2dm, axis=1)\n self.failUnless(eq(a2dma, [1.5, 4.0]))\n\n def check_testToPython(self):\n self.assertEqual(1, int(array(1)))\n self.assertEqual(1.0, float(array(1)))\n self.assertEqual(1, int(array([[[1]]])))\n self.assertEqual(1.0, float(array([[1]])))\n self.failUnlessRaises(ValueError, float, array([1,1]))\n self.failUnlessRaises(MAError, float, array([1],mask=[1]))\n self.failUnless(bool(array([0,1])))\n self.failUnless(bool(array([0,0],mask=[0,1])))\n self.failIf(bool(array([0,0])))\n self.failIf(bool(array([0,0],mask=[0,0])))\n\n def check_testScalarArithmetic(self):\n xm = array(0, mask=1)\n self.failUnless((1/array(0)).mask)\n self.failUnless((1 + xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless(maximum(xm, xm).mask)\n self.failUnless(minimum(xm, xm).mask)\n self.failUnless(xm.filled().dtype is xm.data.dtype)\n x = array(0, mask=0)\n self.failUnless(x.filled() is x.data)\n\n def check_testArrayMethods(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnless(eq(a.any(), a.data.any()))\n self.failUnless(eq(a.all(), a.data.all()))\n self.failUnless(eq(a.argmax(), a.data.argmax()))\n self.failUnless(eq(a.argmin(), a.data.argmin()))\n self.failUnless(eq(a.choose(0,1,2,3,4), a.data.choose(0,1,2,3,4)))\n self.failUnless(eq(a.compress([1,0,1]), a.data.compress([1,0,1])))\n self.failUnless(eq(a.conj(), a.data.conj()))\n self.failUnless(eq(a.conjugate(), a.data.conjugate()))\n m = array([[1,2],[3,4]])\n self.failUnless(eq(m.diagonal(), m.data.diagonal()))\n self.failUnless(eq(a.sum(), a.data.sum()))\n self.failUnless(eq(a.take([1,2]), a.data.take([1,2])))\n self.failUnless(eq(m.transpose(), m.data.transpose()))\n \n def check_testAPI(self):\n self.failIf([m for m in dir(numpy.ndarray)\n if m not in dir(array) and not m.startswith('_')])\n \ndef timingTest():\n for f in [testf, testinplace]:\n for n in [1000,10000,50000]:\n t = testta(n, f)\n t1 = testtb(n, f)\n t2 = testtc(n, f)\n print f.test_name\n print \"\"\"\\\nn = %7d \nnumpy time (ms) %6.1f \nMA maskless ratio %6.1f\nMA masked ratio %6.1f\n\"\"\" % (n, t*1000.0, t1/t, t2/t)\n\ndef testta(n, f):\n x=numpy.arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtb(n, f):\n x=arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtc(n, f):\n x=arange(n) + 1.0\n x[0] = masked\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testf(x):\n for i in range(25):\n y = x **2 + 2.0 * x - 1.0\n w = x **2 + 1.0\n z = (y / w) ** 2\n return z\ntestf.test_name = 'Simple arithmetic'\n\ndef testinplace(x):\n for i in range(25):\n y = x**2\n y += 2.0*x\n y -= 1.0\n y /= x\n return y\ntestinplace.test_name = 'Inplace operations'\n\nif __name__ == \"__main__\":\n ScipyTest('numpy.core.ma').run() \n #timingTest()\n", + "source_code_before": "import numpy \nimport types, time\nfrom numpy.core.ma import *\nfrom numpy.testing import ScipyTestCase, ScipyTest\ndef eq(v,w):\n result = allclose(v,w)\n if not result:\n print \"\"\"Not eq:\n%s\n----\n%s\"\"\"% (str(v), str(w))\n return result\n\nclass test_ma(ScipyTestCase):\n def __init__(self, *args, **kwds):\n ScipyTestCase.__init__(self, *args, **kwds)\n self.setUp()\n \n def setUp (self):\n x=numpy.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])\n y=numpy.array([5.,0.,3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])\n a10 = 10.\n m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]\n m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0 ,0, 1]\n xm = array(x, mask=m1)\n ym = array(y, mask=m2)\n z = numpy.array([-.5, 0., .5, .8])\n zm = array(z, mask=[0,1,0,0])\n xf = numpy.where(m1, 1.e+20, x)\n s = x.shape\n xm.set_fill_value(1.e+20)\n self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf, s)\n\n def check_testBasic1d(self):\n \"Test of basic array creation and properties in 1 dimension.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual(xm.dtype, x.dtype)\n self.assertEqual(xm.dtypechar, x.dtypechar)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual(count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n\n def check_testBasic2d(self):\n \"Test of basic array creation and properties in 2 dimensions.\"\n for s in [(4,3), (6,2)]: \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n x.shape = s\n y.shape = s\n xm.shape = s\n ym.shape = s\n xf.shape = s\n \n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual( count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n self.setUp()\n\n def check_testArithmetic (self):\n \"Test of basic arithmetic.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n a2d = array([[1,2],[0,4]])\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n self.failUnless(eq (a2d * a2d, a2d * a2dm))\n self.failUnless(eq (a2d + a2d, a2d + a2dm))\n self.failUnless(eq (a2d - a2d, a2d - a2dm))\n for s in [(12,), (4,3), (2,6)]: \n x = x.reshape(s)\n y = y.reshape(s)\n xm = xm.reshape(s)\n ym = ym.reshape(s)\n xf = xf.reshape(s)\n self.failUnless(eq(-x, -xm))\n self.failUnless(eq(x + y, xm + ym))\n self.failUnless(eq(x - y, xm - ym))\n self.failUnless(eq(x * y, xm * ym))\n self.failUnless(eq(x / y, xm / ym))\n self.failUnless(eq(a10 + y, a10 + ym))\n self.failUnless(eq(a10 - y, a10 - ym))\n self.failUnless(eq(a10 * y, a10 * ym))\n self.failUnless(eq(a10 / y, a10 / ym))\n self.failUnless(eq(x + a10, xm + a10))\n self.failUnless(eq(x - a10, xm - a10))\n self.failUnless(eq(x * a10, xm * a10))\n self.failUnless(eq(x / a10, xm / a10))\n self.failUnless(eq(x**2, xm**2))\n self.failUnless(eq(abs(x)**2.5, abs(xm) **2.5))\n self.failUnless(eq(x**y, xm**ym))\n self.failUnless(eq(numpy.add(x,y), add(xm, ym)))\n self.failUnless(eq(numpy.subtract(x,y), subtract(xm, ym)))\n self.failUnless(eq(numpy.multiply(x,y), multiply(xm, ym)))\n self.failUnless(eq(numpy.divide(x,y), divide(xm, ym)))\n\n\n def check_testMixedArithmetic(self):\n na = numpy.array([1])\n ma = array([1])\n self.failUnless(isinstance(na + ma, MaskedArray))\n self.failUnless(isinstance(ma + na, MaskedArray))\n \n def check_testUfuncs1 (self):\n \"Test various functions such as sin, cos.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.cos(x), cos(xm)))\n self.failUnless (eq(numpy.cosh(x), cosh(xm)))\n self.failUnless (eq(numpy.sin(x), sin(xm)))\n self.failUnless (eq(numpy.sinh(x), sinh(xm)))\n self.failUnless (eq(numpy.tan(x), tan(xm)))\n self.failUnless (eq(numpy.tanh(x), tanh(xm)))\n self.failUnless (eq(numpy.sqrt(abs(x)), sqrt(xm)))\n self.failUnless (eq(numpy.log(abs(x)), log(xm)))\n self.failUnless (eq(numpy.log10(abs(x)), log10(xm)))\n self.failUnless (eq(numpy.exp(x), exp(xm)))\n self.failUnless (eq(numpy.arcsin(z), arcsin(zm)))\n self.failUnless (eq(numpy.arccos(z), arccos(zm)))\n self.failUnless (eq(numpy.arctan(z), arctan(zm)))\n self.failUnless (eq(numpy.arctan2(x, y), arctan2(xm, ym)))\n self.failUnless (eq(numpy.absolute(x), absolute(xm)))\n self.failUnless (eq(numpy.equal(x,y), equal(xm, ym)))\n self.failUnless (eq(numpy.not_equal(x,y), not_equal(xm, ym)))\n self.failUnless (eq(numpy.less(x,y), less(xm, ym)))\n self.failUnless (eq(numpy.greater(x,y), greater(xm, ym)))\n self.failUnless (eq(numpy.less_equal(x,y), less_equal(xm, ym)))\n self.failUnless (eq(numpy.greater_equal(x,y), greater_equal(xm, ym)))\n self.failUnless (eq(numpy.conjugate(x), conjugate(xm)))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,ym))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((x,y))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,y))))\n self.failUnless (eq(numpy.concatenate((x,y,x)), concatenate((x,ym,x))))\n \n def check_xtestCount (self):\n \"Test count\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless( isinstance(count(ott), types.IntType))\n self.assertEqual(3, count(ott))\n self.assertEqual(1, count(1))\n self.failUnless (eq(0, array(1,mask=[1])))\n ott=ott.reshape((2,2))\n assert isMaskedArray(count(ott,0))\n assert isinstance(count(ott), types.IntType)\n self.failUnless (eq(3, count(ott)))\n assert getmask(count(ott,0)) is None\n self.failUnless (eq([1,2],count(ott,0)))\n \n def check_testMinMax (self):\n \"Test minimum and maximum.\" \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n xr = numpy.ravel(x) #max doesn't work if shaped\n xmr = ravel(xm)\n self.failUnless (eq(max(xr), maximum(xmr))) #true because of careful selection of data\n self.failUnless (eq(min(xr), minimum(xmr))) #true because of careful selection of data\n\n def check_testAddSumProd (self):\n \"Test add, sum, product.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.add.reduce(x), add.reduce(x)))\n self.failUnless (eq(numpy.add.accumulate(x), add.accumulate(x)))\n self.failUnless (eq(4, sum(array(4))))\n self.failUnless (eq(4, sum(array(4), axis=0)))\n self.failUnless (eq(numpy.sum(x), sum(x)))\n self.failUnless (eq(numpy.sum(filled(xm,0)), sum(xm)))\n self.failUnless (eq(numpy.sum(x,0), sum(x,0)))\n self.failUnless (eq(numpy.product(x), product(x)))\n self.failUnless (eq(numpy.product(x,0), product(x,0)))\n self.failUnless (eq(numpy.product(filled(xm,1)), product(xm)))\n if len(s) > 1:\n self.failUnless (eq(numpy.concatenate((x,y),1), concatenate((xm,ym),1)))\n self.failUnless (eq(numpy.add.reduce(x,1), add.reduce(x,1)))\n self.failUnless (eq(numpy.sum(x,1), sum(x,1)))\n self.failUnless (eq(numpy.product(x,1), product(x,1)))\n \n \n def check_testCI(self):\n \"Test of conversions and indexing\"\n x1 = numpy.array([1,2,4,3])\n x2 = array(x1, mask = [1,0,0,0])\n x3 = array(x1, mask = [0,1,0,1])\n x4 = array(x1)\n # test conversion to strings\n junk, garbage = str(x2), repr(x2)\n assert eq(numpy.sort(x1),sort(x2, fill_value=0))\n # tests of indexing\n assert type(x2[1]) is type(x1[1])\n assert x1[1] == x2[1]\n assert x2[0] is masked\n assert eq(x1[2],x2[2])\n assert eq(x1[2:5],x2[2:5])\n assert eq(x1[:],x2[:])\n assert eq(x1[1:], x3[1:])\n x1[2]=9\n x2[2]=9\n assert eq(x1,x2)\n x1[1:3] = 99\n x2[1:3] = 99\n assert eq(x1,x2)\n x2[1] = masked\n assert eq(x1,x2)\n x2[1:3]=masked\n assert eq(x1,x2)\n x2[:] = x1\n x2[1] = masked\n assert allequal(getmask(x2),array([0,1,0,0]))\n x3[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x3), array([0,1,1,0]))\n x4[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x4), array([0,1,1,0]))\n assert allequal(x4, array([1,2,3,4]))\n x1 = numpy.arange(5)*1.0\n x2 = masked_values(x1, 3.0)\n assert eq(x1,x2)\n assert allequal(array([0,0,0,1,0],MaskType), x2.mask)\n assert eq(3.0, x2.fill_value())\n x1 = array([1,'hello',2,3],object)\n x2 = numpy.array([1,'hello',2,3],object)\n s1 = x1[1]\n s2 = x2[1]\n self.assertEqual(type(s2), str)\n self.assertEqual(type(s1), str)\n self.assertEqual(s1, s2)\n assert x1[1:1].shape == (0,)\n \n def check_testCopySize(self):\n \"Tests of some subtle points of copying and sizing.\"\n n = [0,0,1,0,0]\n m = make_mask(n)\n m2 = make_mask(m)\n self.failUnless(m is m2)\n m3 = make_mask(m, copy=1)\n self.failUnless(m is not m3)\n \n x1 = numpy.arange(5)\n y1 = array(x1, mask=m)\n self.failUnless( y1.raw_data() is not x1)\n self.failUnless( allequal(x1,y1.raw_data()))\n self.failUnless( y1.mask is m)\n \n y1a = array(y1, copy=0)\n self.failUnless( y1a.raw_data() is y1.raw_data())\n self.failUnless( y1a.mask is y1.mask)\n \n y2 = array(x1, mask=m, copy=0)\n self.failUnless( y2.raw_data() is x1)\n self.failUnless( y2.mask is m)\n self.failUnless( y2[2] is masked)\n y2[2]=9\n self.failUnless( y2[2] is not masked)\n self.failUnless( y2.mask is not m)\n self.failUnless( allequal(y2.mask, 0))\n \n y3 = array(x1*1.0, mask=m)\n self.failUnless(filled(y3).dtype is (x1*1.0).dtype)\n \n x4 = arange(4)\n x4[2] = masked\n y4 = resize(x4, (8,))\n self.failUnless( eq(concatenate([x4,x4]), y4))\n self.failUnless( eq(getmask(y4),[0,0,1,0,0,0,1,0]))\n y5 = repeat(x4, (2,2,2,2))\n self.failUnless( eq(y5, [0,0,1,1,2,2,3,3]))\n y6 = repeat(x4, 2)\n self.failUnless( eq(y5, y6))\n \n def check_testPut(self):\n \"Test of put\"\n d = arange(5)\n n = [0,0,0,1,1]\n m = make_mask(n)\n x = array(d, mask = m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n x[[1,4]] = [10,40]\n self.failUnless( x.mask is not m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is not masked)\n self.failUnless( eq(x, [0,10,2,-1,40]))\n \n x = array(d, mask = m) \n x.put([-1,100,200])\n self.failUnless( eq(x, [-1,100,200,0,0]))\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n \n x = array(d, mask = m) \n x.putmask([30,40])\n self.failUnless( eq(x, [0,1,2,30,40]))\n self.failUnless( x.mask is None)\n \n x = array(d, mask = m) \n y = x.compressed()\n z = array(x, mask = m)\n z.put(y)\n assert eq (x, z)\n \n def check_testMaPut(self):\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]\n i = numpy.nonzero(m)\n putmask(xm, m, z)\n assert take(xm, i) == z\n put(ym, i, zm)\n assert take(ym, i) == zm\n \n def check_testOddFeatures(self):\n \"Test of other odd features\"\n x = arange(20); x=x.reshape(4,5)\n x.flat[5] = 12\n assert x[1,0] == 12\n z = x + 10j * x\n assert eq(z.real, x)\n assert eq(z.imag, 10*x)\n assert eq((z*conjugate(z)).real, 101*x*x)\n z.imag[...] = 0.0\n \n x = arange(10)\n x[3] = masked\n assert str(x[3]) == str(masked)\n c = x >= 8\n assert count(where(c,masked,masked)) == 0\n assert shape(where(c,masked,masked)) == c.shape\n z = where(c , x, masked)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is masked\n assert z[7] is masked\n assert z[8] is not masked\n assert z[9] is not masked\n assert eq(x,z)\n z = where(c , masked, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n z = masked_where(c, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n assert eq(x,z)\n x = array([1.,2.,3.,4.,5.])\n c = array([1,1,1,0,0])\n x[2] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n c[0] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n assert eq(masked_where(greater(x, 2), x), masked_greater(x,2))\n assert eq(masked_where(greater_equal(x, 2), x), masked_greater_equal(x,2))\n assert eq(masked_where(less(x, 2), x), masked_less(x,2))\n assert eq(masked_where(less_equal(x, 2), x), masked_less_equal(x,2))\n assert eq(masked_where(not_equal(x, 2), x), masked_not_equal(x,2))\n assert eq(masked_where(equal(x, 2), x), masked_equal(x,2))\n assert eq(masked_where(not_equal(x,2), x), masked_not_equal(x,2))\n assert eq(masked_inside(range(5), 1, 3), [0, 199, 199, 199, 4])\n assert eq(masked_outside(range(5), 1, 3),[199,1,2,3,199])\n assert eq(masked_inside(array(range(5), mask=[1,0,0,0,0]), 1, 3).mask, [1,1,1,1,0])\n assert eq(masked_outside(array(range(5), mask=[0,1,0,0,0]), 1, 3).mask, [1,1,0,0,1])\n assert eq(masked_equal(array(range(5), mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,0])\n assert eq(masked_not_equal(array([2,2,1,2,1], mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,1])\n assert eq(masked_where([1,1,0,0,0], [1,2,3,4,5]), [99,99,3,4,5])\n atest = ones((10,10,10), dtype=float32)\n btest = zeros(atest.shape, MaskType)\n ctest = masked_where(btest,atest)\n assert eq(atest,ctest)\n z = choose(c, (-x, x))\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n x = arange(6)\n x[5] = masked\n y = arange(6)*10\n y[2]= masked\n c = array([1,1,1,0,0,0], mask=[1,0,0,0,0,0])\n cm = c.filled(1)\n z = where(c,x,y)\n zm = where(cm,x,y)\n assert eq(z, zm)\n assert getmask(zm) is None\n assert eq(zm, [0,1,2,30,40,50])\n z = where(c, masked, 1)\n assert eq(z, [99,99,99,1,1,1])\n z = where(c, 1, masked)\n assert eq(z, [99, 1, 1, 99, 99, 99])\n \n def check_testMinMax(self):\n \"Test of minumum, maximum.\" \n assert eq(minimum([1,2,3],[4,0,9]), [1,0,3])\n assert eq(maximum([1,2,3],[4,0,9]), [4,2,9])\n x = arange(5)\n y = arange(5) - 2\n x[3] = masked\n y[0] = masked\n assert eq(minimum(x,y), where(less(x,y), x, y))\n assert eq(maximum(x,y), where(greater(x,y), x, y))\n assert minimum(x) == 0\n assert maximum(x) == 4\n \n def check_testTakeTransposeInnerOuter(self):\n \"Test of take, transpose, inner, outer products\"\n x = arange(24)\n y = numpy.arange(24)\n x[5:6] = masked\n x=x.reshape(2,3,4)\n y=y.reshape(2,3,4)\n assert eq(numpy.transpose(y,(2,0,1)), transpose(x,(2,0,1)))\n assert eq(numpy.take(y, (2,0,1), 1), take(x, (2,0,1), 1))\n assert eq(numpy.innerproduct(filled(x,0),filled(y,0)),\n innerproduct(x, y))\n assert eq(numpy.outerproduct(filled(x,0),filled(y,0)),\n outerproduct(x, y))\n y = array(['abc', 1, 'def', 2, 3], object)\n y[2] = masked\n t = take(y,[0,3,4])\n assert t[0] == 'abc'\n assert t[1] == 2\n assert t[2] == 3\n \n def check_testInplace(self):\n \"\"\"Test of inplace operations and rich comparisons\"\"\"\n y = arange(10)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x += 1\n assert eq(x, y+1)\n xm += 1\n assert eq(x, y+1)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x -= 1\n assert eq(x, y-1)\n xm -= 1\n assert eq(xm, y-1)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x *= 2.0\n assert eq(x, y*2)\n xm *= 2.0\n assert eq(xm, y*2)\n \n x = arange(10)*2\n xm = arange(10)\n xm[2] = masked\n x /= 2\n assert eq(x, y)\n xm /= 2\n assert eq(x, y)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x /= 2.0\n assert eq(x, y/2.0)\n xm /= arange(10)\n assert eq(xm, ones((10,)))\n \n x = arange(10).astype(float32)\n xm = arange(10)\n xm[2] = masked\n id1 = id(x.raw_data())\n x += 1.\n assert id1 == id(x.raw_data())\n assert eq(x, y+1.)\n \n def check_testPickle(self):\n \"Test of pickling\"\n x = arange(12)\n x[4:10:2] = masked\n x=x.reshape(4,3)\n f = open('test9.pik','wb')\n import pickle\n pickle.dump(x, f)\n f.close()\n f = open('test9.pik', 'rb')\n y = pickle.load(f)\n assert eq(x,y) \n \n def check_testMasked(self):\n \"Test of masked element\"\n xx=arange(6)\n xx[1] = masked\n self.failUnless(str(masked) == '--')\n self.failUnless(xx[1] is masked)\n # don't know why these should raise an exception...\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, masked)\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, 2)\n self.failUnlessRaises(Exception, lambda x,y: x+y, masked, xx)\n self.failUnlessRaises(Exception, lambda x,y: x+y, xx, masked)\n \n def check_testAverage1(self):\n \"Test of average.\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless(eq(2.0, average(ott)))\n self.failUnless(eq(2.0, average(ott, weights=[1., 1., 2., 1.])))\n result, wts = average(ott, weights=[1.,1.,2.,1.], returned=1)\n self.failUnless(eq(2.0, result))\n self.failUnless(wts == 4.0)\n ott[:] = masked\n self.failUnless(average(ott) is masked)\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n ott=ott.reshape(2,2)\n ott[:,1] = masked\n self.failUnless(eq(average(ott), [2.0, 0.0]))\n self.failUnless(average(ott,axis=1)[0] is masked)\n self.failUnless(eq([2.,0.], average(ott)))\n result, wts = average(ott, returned=1)\n self.failUnless(eq(wts, [1., 0.]))\n\n def check_testAverage2(self):\n \"More tests of average.\"\n w1 = [0,1,1,1,1,0]\n w2 = [[0,1,1,1,1,0],[1,0,0,0,0,1]]\n x=arange(6)\n self.failUnless(allclose(average(x), 2.5))\n self.failUnless(allclose(average(x, weights=w1), 2.5))\n y=array([arange(6), 2.0*arange(6)])\n self.failUnless(allclose(average(y, None), numpy.add.reduce(numpy.arange(6))*3./12.))\n self.failUnless(allclose(average(y, axis=0), numpy.arange(6) * 3./2.))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n self.failUnless(allclose(average(y, None, weights=w2), 20./6.))\n self.failUnless(allclose(average(y, axis=0, weights=w2), [0.,1.,2.,3.,4.,10.]))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n m1 = zeros(6)\n m2 = [0,0,1,1,0,0]\n m3 = [[0,0,1,1,0,0],[0,1,1,1,1,0]]\n m4 = ones(6)\n m5 = [0, 1, 1, 1, 1, 1]\n self.failUnless(allclose(average(masked_array(x, m1)), 2.5))\n self.failUnless(allclose(average(masked_array(x, m2)), 2.5))\n self.failUnless(average(masked_array(x, m4)) is masked)\n self.assertEqual(average(masked_array(x, m5)), 0.0)\n self.assertEqual(count(average(masked_array(x, m4))), 0)\n z = masked_array(y, m3)\n self.failUnless(allclose(average(z, None), 20./6.))\n self.failUnless(allclose(average(z, axis=0), [0.,1.,99.,99.,4.0, 7.5]))\n self.failUnless(allclose(average(z, axis=1), [2.5, 5.0]))\n self.failUnless(allclose( average(z,weights=w2), [0.,1., 99., 99., 4.0, 10.0]))\n \n a = arange(6)\n b = arange(6) * 3\n r1, w1 = average([[a,b],[b,a]], axis=1, returned=1)\n self.assertEqual(shape(r1) , shape(w1))\n self.assertEqual(r1.shape , w1.shape)\n r2, w2 = average(ones((2,2,3)), axis=0, weights=[3,1], returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), weights=ones((2,2,3)), returned=1)\n self.failUnless(shape(w2) == shape(r2))\n a2d = array([[1,2],[0,4]], float)\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n a2da = average(a2d)\n self.failUnless(eq (a2da, [0.5, 3.0]))\n a2dma = average(a2dm)\n self.failUnless(eq( a2dma, [1.0, 3.0]))\n a2dma = average(a2dm, axis=None)\n self.failUnless(eq(a2dma, 7./3.))\n a2dma = average(a2dm, axis=1)\n self.failUnless(eq(a2dma, [1.5, 4.0]))\n\n def check_testToPython(self):\n self.assertEqual(1, int(array(1)))\n self.assertEqual(1.0, float(array(1)))\n self.assertEqual(1, int(array([[[1]]])))\n self.assertEqual(1.0, float(array([[1]])))\n self.failUnlessRaises(ValueError, float, array([1,1]))\n self.failUnlessRaises(MAError, float, array([1],mask=[1]))\n self.failUnless(bool(array([0,1])))\n self.failUnless(bool(array([0,0],mask=[0,1])))\n self.failIf(bool(array([0,0])))\n self.failIf(bool(array([0,0],mask=[0,0])))\n\n def check_testScalarArithmetic(self):\n xm = array(0, mask=1)\n self.failUnless((1/array(0)).mask)\n self.failUnless((1 + xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless(maximum(xm, xm).mask)\n self.failUnless(minimum(xm, xm).mask)\n self.failUnless(xm.filled().dtype is xm.data.dtype)\n x = array(0, mask=0)\n self.failUnless(x.filled() is x.data)\n \ndef timingTest():\n for f in [testf, testinplace]:\n for n in [1000,10000,50000]:\n t = testta(n, f)\n t1 = testtb(n, f)\n t2 = testtc(n, f)\n print f.test_name\n print \"\"\"\\\nn = %7d \nnumpy time (ms) %6.1f \nMA maskless ratio %6.1f\nMA masked ratio %6.1f\n\"\"\" % (n, t*1000.0, t1/t, t2/t)\n\ndef testta(n, f):\n x=numpy.arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtb(n, f):\n x=arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtc(n, f):\n x=arange(n) + 1.0\n x[0] = masked\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testf(x):\n for i in range(25):\n y = x **2 + 2.0 * x - 1.0\n w = x **2 + 1.0\n z = (y / w) ** 2\n return z\ntestf.test_name = 'Simple arithmetic'\n\ndef testinplace(x):\n for i in range(25):\n y = x**2\n y += 2.0*x\n y -= 1.0\n y /= x\n return y\ntestinplace.test_name = 'Inplace operations'\n\nif __name__ == \"__main__\":\n ScipyTest('numpy.core.ma').run() \n #timingTest()\n", + "methods": [ + { + "name": "eq", + "long_name": "eq( v , w )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "v", + "w" + ], + "start_line": 5, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , * args , ** kwds )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 15, + "end_line": 17, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 276, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 32, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic1d", + "long_name": "check_testBasic1d( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 186, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 47, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic2d", + "long_name": "check_testBasic2d( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 2, + "token_count": 209, + "parameters": [ + "self" + ], + "start_line": 49, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "check_testArithmetic", + "long_name": "check_testArithmetic( self )", + "filename": "test_ma.py", + "nloc": 34, + "complexity": 2, + "token_count": 518, + "parameters": [ + "self" + ], + "start_line": 70, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "check_testMixedArithmetic", + "long_name": "check_testMixedArithmetic( self )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 106, + "end_line": 110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_testUfuncs1", + "long_name": "check_testUfuncs1( self )", + "filename": "test_ma.py", + "nloc": 29, + "complexity": 1, + "token_count": 600, + "parameters": [ + "self" + ], + "start_line": 112, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "check_xtestCount", + "long_name": "check_xtestCount( self )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 1, + "token_count": 174, + "parameters": [ + "self" + ], + "start_line": 142, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 156, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_testAddSumProd", + "long_name": "check_testAddSumProd( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 2, + "token_count": 361, + "parameters": [ + "self" + ], + "start_line": 164, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testCI", + "long_name": "check_testCI( self )", + "filename": "test_ma.py", + "nloc": 46, + "complexity": 1, + "token_count": 560, + "parameters": [ + "self" + ], + "start_line": 184, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 1 + }, + { + "name": "check_testCopySize", + "long_name": "check_testCopySize( self )", + "filename": "test_ma.py", + "nloc": 35, + "complexity": 1, + "token_count": 409, + "parameters": [ + "self" + ], + "start_line": 233, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 1 + }, + { + "name": "check_testPut", + "long_name": "check_testPut( self )", + "filename": "test_ma.py", + "nloc": 27, + "complexity": 1, + "token_count": 291, + "parameters": [ + "self" + ], + "start_line": 274, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "check_testMaPut", + "long_name": "check_testMaPut( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 101, + "parameters": [ + "self" + ], + "start_line": 305, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_testOddFeatures", + "long_name": "check_testOddFeatures( self )", + "filename": "test_ma.py", + "nloc": 88, + "complexity": 1, + "token_count": 1188, + "parameters": [ + "self" + ], + "start_line": 314, + "end_line": 402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 154, + "parameters": [ + "self" + ], + "start_line": 404, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testTakeTransposeInnerOuter", + "long_name": "check_testTakeTransposeInnerOuter( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 1, + "token_count": 235, + "parameters": [ + "self" + ], + "start_line": 417, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "check_testInplace", + "long_name": "check_testInplace( self )", + "filename": "test_ma.py", + "nloc": 44, + "complexity": 1, + "token_count": 315, + "parameters": [ + "self" + ], + "start_line": 437, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testPickle", + "long_name": "check_testPickle( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 489, + "end_line": 500, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testMasked", + "long_name": "check_testMasked( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 502, + "end_line": 512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage1", + "long_name": "check_testAverage1( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 1, + "token_count": 289, + "parameters": [ + "self" + ], + "start_line": 514, + "end_line": 531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage2", + "long_name": "check_testAverage2( self )", + "filename": "test_ma.py", + "nloc": 50, + "complexity": 1, + "token_count": 945, + "parameters": [ + "self" + ], + "start_line": 533, + "end_line": 583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testToPython", + "long_name": "check_testToPython( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 193, + "parameters": [ + "self" + ], + "start_line": 585, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testScalarArithmetic", + "long_name": "check_testScalarArithmetic( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 597, + "end_line": 607, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testArrayMethods", + "long_name": "check_testArrayMethods( self )", + "filename": "test_ma.py", + "nloc": 16, + "complexity": 1, + "token_count": 351, + "parameters": [ + "self" + ], + "start_line": 609, + "end_line": 624, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "check_testAPI", + "long_name": "check_testAPI( self )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 4, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 626, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "timingTest", + "long_name": "timingTest( )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 3, + "token_count": 72, + "parameters": [], + "start_line": 630, + "end_line": 642, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "testta", + "long_name": "testta( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 40, + "parameters": [ + "n", + "f" + ], + "start_line": 644, + "end_line": 648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtb", + "long_name": "testtb( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 38, + "parameters": [ + "n", + "f" + ], + "start_line": 650, + "end_line": 654, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtc", + "long_name": "testtc( n , f )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 44, + "parameters": [ + "n", + "f" + ], + "start_line": 656, + "end_line": 661, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testf", + "long_name": "testf( x )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 48, + "parameters": [ + "x" + ], + "start_line": 663, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testinplace", + "long_name": "testinplace( x )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 36, + "parameters": [ + "x" + ], + "start_line": 671, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "eq", + "long_name": "eq( v , w )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "v", + "w" + ], + "start_line": 5, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , * args , ** kwds )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 15, + "end_line": 17, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 276, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 32, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic1d", + "long_name": "check_testBasic1d( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 186, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 47, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic2d", + "long_name": "check_testBasic2d( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 2, + "token_count": 209, + "parameters": [ + "self" + ], + "start_line": 49, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "check_testArithmetic", + "long_name": "check_testArithmetic( self )", + "filename": "test_ma.py", + "nloc": 34, + "complexity": 2, + "token_count": 518, + "parameters": [ + "self" + ], + "start_line": 70, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "check_testMixedArithmetic", + "long_name": "check_testMixedArithmetic( self )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 106, + "end_line": 110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_testUfuncs1", + "long_name": "check_testUfuncs1( self )", + "filename": "test_ma.py", + "nloc": 29, + "complexity": 1, + "token_count": 600, + "parameters": [ + "self" + ], + "start_line": 112, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "check_xtestCount", + "long_name": "check_xtestCount( self )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 1, + "token_count": 174, + "parameters": [ + "self" + ], + "start_line": 142, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 156, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_testAddSumProd", + "long_name": "check_testAddSumProd( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 2, + "token_count": 361, + "parameters": [ + "self" + ], + "start_line": 164, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testCI", + "long_name": "check_testCI( self )", + "filename": "test_ma.py", + "nloc": 46, + "complexity": 1, + "token_count": 560, + "parameters": [ + "self" + ], + "start_line": 184, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 1 + }, + { + "name": "check_testCopySize", + "long_name": "check_testCopySize( self )", + "filename": "test_ma.py", + "nloc": 35, + "complexity": 1, + "token_count": 409, + "parameters": [ + "self" + ], + "start_line": 233, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 1 + }, + { + "name": "check_testPut", + "long_name": "check_testPut( self )", + "filename": "test_ma.py", + "nloc": 27, + "complexity": 1, + "token_count": 291, + "parameters": [ + "self" + ], + "start_line": 274, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "check_testMaPut", + "long_name": "check_testMaPut( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 101, + "parameters": [ + "self" + ], + "start_line": 305, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_testOddFeatures", + "long_name": "check_testOddFeatures( self )", + "filename": "test_ma.py", + "nloc": 88, + "complexity": 1, + "token_count": 1188, + "parameters": [ + "self" + ], + "start_line": 314, + "end_line": 402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 154, + "parameters": [ + "self" + ], + "start_line": 404, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testTakeTransposeInnerOuter", + "long_name": "check_testTakeTransposeInnerOuter( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 1, + "token_count": 235, + "parameters": [ + "self" + ], + "start_line": 417, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "check_testInplace", + "long_name": "check_testInplace( self )", + "filename": "test_ma.py", + "nloc": 44, + "complexity": 1, + "token_count": 315, + "parameters": [ + "self" + ], + "start_line": 437, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testPickle", + "long_name": "check_testPickle( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 489, + "end_line": 500, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testMasked", + "long_name": "check_testMasked( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 502, + "end_line": 512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage1", + "long_name": "check_testAverage1( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 1, + "token_count": 289, + "parameters": [ + "self" + ], + "start_line": 514, + "end_line": 531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage2", + "long_name": "check_testAverage2( self )", + "filename": "test_ma.py", + "nloc": 50, + "complexity": 1, + "token_count": 945, + "parameters": [ + "self" + ], + "start_line": 533, + "end_line": 583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testToPython", + "long_name": "check_testToPython( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 193, + "parameters": [ + "self" + ], + "start_line": 585, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testScalarArithmetic", + "long_name": "check_testScalarArithmetic( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 597, + "end_line": 607, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "timingTest", + "long_name": "timingTest( )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 3, + "token_count": 72, + "parameters": [], + "start_line": 609, + "end_line": 621, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "testta", + "long_name": "testta( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 40, + "parameters": [ + "n", + "f" + ], + "start_line": 623, + "end_line": 627, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtb", + "long_name": "testtb( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 38, + "parameters": [ + "n", + "f" + ], + "start_line": 629, + "end_line": 633, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtc", + "long_name": "testtc( n , f )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 44, + "parameters": [ + "n", + "f" + ], + "start_line": 635, + "end_line": 640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testf", + "long_name": "testf( x )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 48, + "parameters": [ + "x" + ], + "start_line": 642, + "end_line": 647, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testinplace", + "long_name": "testinplace( x )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 36, + "parameters": [ + "x" + ], + "start_line": 650, + "end_line": 656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "check_testAPI", + "long_name": "check_testAPI( self )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 4, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 626, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_testArrayMethods", + "long_name": "check_testArrayMethods( self )", + "filename": "test_ma.py", + "nloc": 16, + "complexity": 1, + "token_count": 351, + "parameters": [ + "self" + ], + "start_line": 609, + "end_line": 624, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + } + ], + "nloc": 623, + "complexity": 44, + "token_count": 8236, + "diff_parsed": { + "added": [ + "", + " def check_testArrayMethods(self):", + " a = array([1,3,2])", + " b = array([1,3,2], mask=[1,0,1])", + " self.failUnless(eq(a.any(), a.data.any()))", + " self.failUnless(eq(a.all(), a.data.all()))", + " self.failUnless(eq(a.argmax(), a.data.argmax()))", + " self.failUnless(eq(a.argmin(), a.data.argmin()))", + " self.failUnless(eq(a.choose(0,1,2,3,4), a.data.choose(0,1,2,3,4)))", + " self.failUnless(eq(a.compress([1,0,1]), a.data.compress([1,0,1])))", + " self.failUnless(eq(a.conj(), a.data.conj()))", + " self.failUnless(eq(a.conjugate(), a.data.conjugate()))", + " m = array([[1,2],[3,4]])", + " self.failUnless(eq(m.diagonal(), m.data.diagonal()))", + " self.failUnless(eq(a.sum(), a.data.sum()))", + " self.failUnless(eq(a.take([1,2]), a.data.take([1,2])))", + " self.failUnless(eq(m.transpose(), m.data.transpose()))", + "", + " def check_testAPI(self):", + " self.failIf([m for m in dir(numpy.ndarray)", + " if m not in dir(array) and not m.startswith('_')])" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "a41d567109efa6c887b972da0b20b50f096cd279", + "msg": "Use better functions for inverse hyperbolic functions, and expose log1p and expm1.\nThe functions are transformations mainly due to Kahan.", + "author": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "committer": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "author_date": "2006-01-12T02:45:53+00:00", + "author_timezone": 0, + "committer_date": "2006-01-12T02:45:53+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "f1a1c7c72fb77edbd38c08414174052dcdd7ba79" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 106, + "insertions": 189, + "lines": 295, + "files": 4, + "dmm_unit_size": 0.6, + "dmm_unit_complexity": 0.6, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/core/code_generators/generate_umath.py", + "new_path": "numpy/core/code_generators/generate_umath.py", + "filename": "generate_umath.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -235,11 +235,21 @@\n (1, 1), None,\n \"e**x elementwise.\"\n ],\n+'expm1' : [nointM, nointM,\n+ (\"expm1,\"*6, '\"expm1\"'),\n+ (1, 1), None,\n+ \"e**x-1 elementwise.\"\n+ ],\n 'log' : [nointM, nointM,\n (\"log,\"*6, '\"log\"'),\n (1, 1), None,\n \"logarithm base e elementwise.\"\n ],\n+'log1p' : [nointM, nointM,\n+ (\"log1p,\"*6, '\"log1p\"'),\n+ (1, 1), None,\n+ \"log(1+x) to base e elementwise.\"\n+ ],\n 'log10' : [nointM, nointM,\n (\"log10,\"*6, '\"log10\"'),\n (1, 1), None,\n", + "added_lines": 10, + "deleted_lines": 0, + "source_code": "\nimport string\nimport re\n\nZero = \"PyUFunc_Zero\"\nOne = \"PyUFunc_One\"\nNone_ = \"PyUFunc_None\"\n#each entry in defdict is \n\n#name: [string of chars for which it is defined,\n#\tstring of characters using func interface,\n#\ttuple of strings giving funcs for data,\n# (in, out), or (instr, outstr) giving the signature as character codes,\n# identity,\n#\tdocstring,\n# output specification (optional)\n# ]\n\nall = '?bBhHiIlLqQfdgFDGO'\nints = 'bBhHiIlLqQ'\nintsO = ints + 'O'\nbintsO = '?'+ints+'O'\nflts = 'fdg'\nfltsO = flts+'O'\nfltsM = flts+'M'\ncmplx = 'FDG'\ncmplxO = cmplx+'O'\ncmplxM = cmplx+'M'\nnoint = flts+cmplx+'O'\nnointM = flts+cmplx+'M'\nallM = '?'+ints+flts+cmplxM\nnobool = all[1:]\nnobool_or_obj = all[1:-1]\nintflt = ints+flts\nnocmplx = '?'+ints+flts\nnocmplxO = nocmplx+'O'\nnocmplxM = nocmplx+'M'\nnoobj = all[:-1]\n\ndefdict = {\n'add': [all,'O',(\"PyNumber_Add\",),\n (2,1), Zero,\n \"adds the arguments elementwise.\"\n ],\n'subtract' : [all,'O',(\"PyNumber_Subtract\",),\n (2,1), Zero,\n \"subtracts the arguments elementwise.\"\n ],\n'multiply' : [all,cmplxO,\n (\"prod,\"*3,\"PyNumber_Multiply\",),\n (2,1), One,\n \"multiplies the arguments elementwise.\"\n ],\n'divide' : [nobool,cmplxO,\n (\"quot,\"*3,\"PyNumber_Divide\",),\n (2,1), One,\n \"divides the arguments elementwise.\"\n ],\n'floor_divide' : [nobool, cmplxO,\n (\"floor_quot,\"*3,\n \"PyNumber_FloorDivide\"),\n (2,1), One,\n \"floor divides the arguments elementwise.\"\n ],\n'true_divide' : [nobool, cmplxO,\n (\"quot,\"*3,\"PyNumber_TrueDivide\"),\n (2,1), One,\n \"true divides the arguments elementwise.\",\n 'f'*4+'d'*6+flts+cmplxO\n ],\n'conjugate' : [nobool_or_obj, 'M',\n ('\"conjugate\"',),\n (1,1), None,\n \"takes the conjugate of x elementwise.\"\n ],\n\n'fmod' : [intflt,fltsM,\n (\"fmod,\"*3, \"fmod\"),\n (2,1), Zero,\n \"computes (C-like) x1 % x2 elementwise.\"\n ],\n'power' : [nobool,noint,\n (\"pow,\"*6,\n \"PyNumber_Power\"),\n (2,1), One,\n \"computes x1**x2 elementwise.\"\n ],\n'absolute' : [all,'O',\n (\"PyNumber_Absolute\",),\n (1,1), None,\n \"takes |x| elementwise.\",\n nocmplx+fltsO\n ],\n'negative' : [all,cmplxO,\n (\"neg,\"*3,\"PyNumber_Negative\"),\n (1,1), None,\n \"determines -x elementwise\",\n ],\n'sign' : [nobool,'',(),(1,1),None,\n \"returns -1 if x < 0 and 0 if x==0 and 1 if x > 0\"\n ],\n'greater' : [all,'',(),(2,1), None,\n \"returns elementwise x1 > x2 in a bool array.\",\n '?'*len(all)\n ],\n'greater_equal' : [all,'',(),(2,1), None,\n \"returns elementwise x1 >= x2 in a bool array.\",\n '?'*len(all)\n ],\n'less' : [all,'',(),(2,1), None,\n \"returns elementwise x1 < x2 in a bool array.\",\n '?'*len(all)\n ],\n'less_equal' : [all,'',(),(2,1), None,\n \"returns elementwise x1 <= x2 in a bool array\",\n '?'*len(all)\n ],\n'equal' : [all, '', (), (2,1), None,\n \"returns elementwise x1 == x2 in a bool array\",\n '?'*len(all)\n ],\n'not_equal' : [all, '', (), (2,1), None,\n \"returns elementwise x1 |= x2\",\n '?'*len(all)\n ],\n'logical_and': [allM,'M',('\"logical_and\"',),\n (2,1), One,\n \"returns x1 and x2 elementwise.\",\n '?'*len(nocmplxM+cmplx)\n ],\n'logical_or': [allM,'M',('\"logical_or\"',),\n (2,1), Zero, \n \"returns x1 or x2 elementwise.\",\n '?'*len(nocmplxM+cmplx)\n ],\n'logical_xor': [allM, 'M', ('\"logical_xor\"',),\n (2,1), None,\n \"returns x1 xor x2 elementwise.\",\n '?'*len(nocmplxM+cmplx)\n ],\n'logical_not' : [allM, 'M', ('\"logical_not\"',),\n (1,1), None,\n \"returns not x elementwise.\",\n '?'*len(nocmplxM+cmplx)\n ],\n'maximum' : [noobj,'',(),\n (2,1), None,\n \"returns maximum (if x1 > x2: x1; else: x2) elementwise.\"],\n'minimum' : [noobj,'',(),\n (2,1), None,\n \"returns minimum (if x1 < x2: x1; else: x2) elementwise\"],\n'bitwise_and' : [bintsO,'O',(\"PyNumber_And\",),\n (2,1), One,\n \"computes x1 & x2 elementwise.\"],\n'bitwise_or' : [bintsO, 'O', (\"PyNumber_Or\",),\n (2,1), Zero,\n \"computes x1 | x2 elementwise.\"],\n'bitwise_xor' : [bintsO, 'O', (\"PyNumber_Xor\",),\n (2,1), None,\n \"computes x1 ^ x2 elementwise.\"],\n'invert' : [bintsO,'O', (\"PyNumber_Invert\",),\n (1,1), None,\n \"computes ~x (bit inversion) elementwise.\"\n ],\n'left_shift' : [intsO, 'O', (\"PyNumber_Lshift\",),\n (2,1), None,\n \"computes x1 << x2 (x1 shifted to left by x2 bits) elementwise.\"\n ],\n'right_shift' : [intsO, 'O', (\"PyNumber_Rshift\",),\n (2,1), None,\n \"computes x1 >> x2 (x1 shifted to right by x2 bits) elementwise.\"\n ],\n'arccos' : [nointM, nointM,\n (\"acos,\"*6, '\"arccos\"'),\n (1, 1), None,\n \"inverse cosine elementwise.\"\n ],\n'arcsin': [nointM, nointM,\n (\"asin,\"*6, '\"arcsin\"'),\n (1, 1), None,\n \"inverse sine elementwise.\"\n ],\n'arctan': [nointM, nointM,\n (\"atan,\"*6, '\"arctan\"'),\n (1, 1), None,\n \"inverse tangent elementwise.\"\n ],\n'arccosh' : [nointM, nointM,\n (\"acosh,\"*6, '\"arccosh\"'),\n (1, 1), None,\n \"inverse hyperbolic cosine elementwise.\"\n ],\n'arcsinh': [nointM, nointM,\n (\"asinh,\"*6, '\"arcsinh\"'),\n (1, 1), None,\n \"inverse hyperbolic sine elementwise.\"\n ],\n'arctanh': [nointM, nointM,\n (\"atanh,\"*6, '\"arctanh\"'),\n (1, 1), None,\n \"inverse hyperbolic tangent elementwise.\"\n ],\n'cos': [nointM, nointM,\n (\"cos,\"*6, '\"cos\"'),\n (1, 1), None,\n \"cosine elementwise.\"\n ],\n'sin': [nointM, nointM,\n (\"sin,\"*6, '\"sin\"'),\n (1, 1), None,\n \"sine elementwise.\"\n ],\n'tan': [nointM, nointM,\n (\"tan,\"*6, '\"tan\"'),\n (1, 1), None,\n \"tangent elementwise.\"\n ],\n'cosh': [nointM, nointM,\n (\"cosh,\"*6, '\"cosh\"'),\n (1, 1), None,\n \"hyperbolic cosine elementwise.\"\n ],\n'sinh': [nointM, nointM,\n (\"sinh,\"*6, '\"sinh\"'),\n (1, 1), None,\n \"hyperbolic sine elementwise.\"\n ],\n'tanh': [nointM, nointM,\n (\"tanh,\"*6, '\"tanh\"'),\n (1, 1), None,\n \"hyperbolic tangent elementwise.\"\n ],\n'exp' : [nointM, nointM,\n (\"exp,\"*6, '\"exp\"'),\n (1, 1), None,\n \"e**x elementwise.\"\n ],\n'expm1' : [nointM, nointM,\n (\"expm1,\"*6, '\"expm1\"'),\n (1, 1), None,\n \"e**x-1 elementwise.\"\n ],\n'log' : [nointM, nointM,\n (\"log,\"*6, '\"log\"'),\n (1, 1), None,\n \"logarithm base e elementwise.\"\n ],\n'log1p' : [nointM, nointM,\n (\"log1p,\"*6, '\"log1p\"'),\n (1, 1), None,\n \"log(1+x) to base e elementwise.\"\n ],\n'log10' : [nointM, nointM,\n (\"log10,\"*6, '\"log10\"'),\n (1, 1), None,\n \"logarithm base 10 elementwise.\"\n ],\n'sqrt' : [nointM, nointM,\n (\"sqrt,\"*6, '\"sqrt\"'),\n (1,1), None,\n \"square-root elementwise.\"\n ],\n'ceil' : [fltsM, fltsM,\n (\"ceil,\"*3, '\"ceil\"'),\n (1,1), None,\n \"elementwise smallest integer >= x.\"\n ],\n'fabs' : [fltsM, fltsM,\n (\"fabs,\"*3, '\"fabs\"'),\n (1,1), None,\n \"absolute values.\"\n ],\n'floor' : [fltsM, fltsM,\n (\"floor,\"*3, '\"floor\"'),\n (1,1), None,\n \"elementwise largest integer <= x\"\n ],\n'arctan2' : [fltsM, fltsM,\n (\"atan2,\"*3, '\"arctan2\"'),\n (2,1), None,\n \"a safe and correct arctan(x1/x2)\"\n ],\n\n'remainder' : [intflt, 'O',\n (\"PyObject_Remainder\"),\n (2,1), None,\n \"computes x1-n*x2 where n is floor(x1 / x2)\"],\n\n'hypot' : [fltsM, fltsM,\n (\"hypot,\"*3, '\"hypot\"'),\n (2,1), None,\n \"sqrt(x1**2 + x2**2) elementwise\"\n ],\n\n'isnan' : [flts+cmplx, '',\n (), (1,1), None,\n \"returns True where x is Not-A-Number\",\n '?'*len(flts+cmplx)\n ],\n\n'isinf' : [flts+cmplx, '',\n (), (1,1), None,\n \"returns True where x is +inf or -inf\",\n '?'*len(flts+cmplx)\n ],\n\n'isfinite' : [flts+cmplx, '',\n (), (1,1), None,\n \"returns True where x is finite\",\n '?'*len(flts+cmplx)\n ],\n\n'signbit' : [flts,'',\n (),(1,1),None,\n \"returns True where signbit of x is set (x<0).\",\n '?'*len(flts)\n ],\n\n'modf' : [flts,'',\n (),(1,2),None,\n \"breaks x into fractional (y1) and integral (y2) parts.\\\\n\\\\n Each output has the same sign as the input.\"\n ]\n}\n\n\ndef indent(st,spaces):\n indention = ' '*spaces\n indented = indention + string.replace(st,'\\n','\\n'+indention)\n # trim off any trailing spaces\n indented = re.sub(r' +$',r'',indented)\n return indented\n\nchartoname = {'?': 'bool',\n 'b': 'byte',\n 'B': 'ubyte',\n 'h': 'short',\n 'H': 'ushort',\n 'i': 'int',\n 'I': 'uint',\n 'l': 'long',\n 'L': 'ulong',\n 'q': 'longlong',\n 'Q': 'ulonglong',\n 'f': 'float',\n 'd': 'double',\n 'g': 'longdouble',\n 'F': 'cfloat',\n 'D': 'cdouble',\n 'G': 'clongdouble',\n 'O': 'OBJECT',\n 'M': 'OBJECT',\n }\n\nchartotype1 = {'f': 'f_f',\n 'd': 'd_d',\n 'g': 'g_g',\n 'F': 'F_F',\n 'D': 'D_D',\n 'G': 'G_G',\n 'O': 'O_O',\n 'M': 'O_O_method'}\n\nchartotype2 = {'f': 'ff_f',\n 'd': 'dd_d',\n 'g': 'gg_g',\n 'F': 'FF_F',\n 'D': 'DD_D',\n 'G': 'GG_G',\n 'O': 'OO_O',\n 'M': 'O_O_method'}\n#for each name\n# 1) create functions, data, and signature\n# 2) fill in functions and data in InitOperators\n# 3) add function. \n\ndef make_arrays(funcdict):\n # functions array contains an entry for every type implemented\n # NULL should be placed where PyUfunc_ style function will be filled in later\n #\n code1list = []\n code2list = []\n for name, vals in funcdict.iteritems():\n funclist = []\n datalist = []\n siglist = []\n k=0;\n sub=0;\n numin, numout = vals[3]\n\n if numin > 1:\n thedict = chartotype2 # two inputs and one output\n else: \n thedict = chartotype1 # one input and one output\n\n instr = ''.join([x*numin for x in list(vals[0])])\n if len(vals) > 6:\n if isinstance(vals[6],type('')):\n outstr = vals[6]\n else: # a tuple specifying input signature, output signature\n instr, outstr = vals[6]\n else:\n outstr = ''.join([x*numout for x in list(vals[0])])\n\n _valslen = len(vals[0])\n assert _valslen*numout == len(outstr), \"input/output signature doesn't match\"\n assert len(instr) == _valslen*numin, \"input/output signature doesn't match\"\n\n for char in vals[0]:\n if char in vals[1]: # use generic function-based interface\n funclist.append('NULL')\n astr = '%s_functions[%d] = PyUFunc_%s;' % \\\n (name, k, thedict[char])\n code2list.append(astr)\n thisfunc = vals[2][sub] \n if len(thisfunc) > 8 and thisfunc[:8] == \"PyNumber\": \n astr = '%s_data[%d] = (void *) %s;' % \\\n (name, k, thisfunc)\n code2list.append(astr)\n datalist.append('(void *)NULL');\n else:\n datalist.append('(void *)%s' % thisfunc)\n sub += 1\n else: # individual wrapper interface\n datalist.append('(void *)NULL'); \n funclist.append('%s_%s' % (chartoname[char].upper(), name))\n\n insubstr = instr[numin*k:numin*(k+1)]\n outsubstr = outstr[numout*k:numout*(k+1)]\n siglist.extend(['PyArray_%s' % chartoname[x].upper() for x in insubstr])\n siglist.extend(['PyArray_%s' % chartoname[x].upper() for x in outsubstr])\n k += 1\n funcnames = ', '.join(funclist)\n signames = ', '.join(siglist)\n datanames = ', '.join(datalist)\n code1list.append(\"static PyUFuncGenericFunction %s_functions[] = { %s };\" \\\n % (name, funcnames))\n code1list.append(\"static void * %s_data[] = { %s };\" \\\n % (name, datanames))\n code1list.append(\"static char %s_signatures[] = { %s };\" \\\n % (name, signames)) \n return \"\\n\".join(code1list),\"\\n\".join(code2list)\n\ndef make_ufuncs(funcdict):\n code3list = []\n for name, vals in funcdict.items():\n mlist = []\n mlist.append(\\\nr\"\"\"f = PyUFunc_FromFuncAndData(%s_functions, %s_data, %s_signatures, %d,\n %d, %d, %s, \"%s\",\n \"%s\", 0);\"\"\" % (name,name,name,len(vals[0]),\n vals[3][0], vals[3][1], vals[4],\n name, vals[5]))\n mlist.append(r\"\"\"PyDict_SetItemString(dictionary, \"%s\", f);\"\"\"%name)\n mlist.append(r\"\"\"Py_DECREF(f);\"\"\")\n code3list.append('\\n'.join(mlist)) \n return '\\n'.join(code3list)\n \n\ndef convert_vals(funcdict):\n for name, vals in funcdict.iteritems():\n if vals[4] is None:\n vals[4] = None_\n vals2 = vals[2]\n if len(vals2) > 0:\n alist = vals2[0].split(',')\n if len(alist) == 4:\n a = alist[0]\n if 'f' in vals[1]:\n newlist = [ a+'f', a, a+'l']\n else:\n newlist = ['nc_'+a+'f', 'nc_'+a, 'nc_'+a+'l']\n elif len(alist) == 7:\n a = alist[0]\n newlist = [a+'f', a, a+'l','nc_'+a+'f', 'nc_'+a, 'nc_'+a+'l']\n else:\n newlist = alist\n newlist = newlist + list(vals2[1:])\n vals[2] = tuple(newlist)\n funcdict[name] = vals\n\n\ndef make_code(funcdict,filename):\n convert_vals(funcdict)\n code1, code2 = make_arrays(funcdict)\n code3 = make_ufuncs(funcdict)\n code2 = indent(code2,4)\n code3 = indent(code3,4)\n code = r\"\"\"\n\n/** Warning this file is autogenerated!!!\n\n Please make changes to the code generator program (%s)\n**/\n\n%s\n\nstatic void\nInitOperators(PyObject *dictionary) {\n PyObject *f;\n\n%s\n%s\n}\n\"\"\" % (filename, code1, code2, code3)\n return code;\n\n\nif __name__ == \"__main__\":\n filename = __file__\n fid = open('__umath_generated.c','w')\n code = make_code(defdict, filename)\n fid.write(code)\n fid.close()\n", + "source_code_before": "\nimport string\nimport re\n\nZero = \"PyUFunc_Zero\"\nOne = \"PyUFunc_One\"\nNone_ = \"PyUFunc_None\"\n#each entry in defdict is \n\n#name: [string of chars for which it is defined,\n#\tstring of characters using func interface,\n#\ttuple of strings giving funcs for data,\n# (in, out), or (instr, outstr) giving the signature as character codes,\n# identity,\n#\tdocstring,\n# output specification (optional)\n# ]\n\nall = '?bBhHiIlLqQfdgFDGO'\nints = 'bBhHiIlLqQ'\nintsO = ints + 'O'\nbintsO = '?'+ints+'O'\nflts = 'fdg'\nfltsO = flts+'O'\nfltsM = flts+'M'\ncmplx = 'FDG'\ncmplxO = cmplx+'O'\ncmplxM = cmplx+'M'\nnoint = flts+cmplx+'O'\nnointM = flts+cmplx+'M'\nallM = '?'+ints+flts+cmplxM\nnobool = all[1:]\nnobool_or_obj = all[1:-1]\nintflt = ints+flts\nnocmplx = '?'+ints+flts\nnocmplxO = nocmplx+'O'\nnocmplxM = nocmplx+'M'\nnoobj = all[:-1]\n\ndefdict = {\n'add': [all,'O',(\"PyNumber_Add\",),\n (2,1), Zero,\n \"adds the arguments elementwise.\"\n ],\n'subtract' : [all,'O',(\"PyNumber_Subtract\",),\n (2,1), Zero,\n \"subtracts the arguments elementwise.\"\n ],\n'multiply' : [all,cmplxO,\n (\"prod,\"*3,\"PyNumber_Multiply\",),\n (2,1), One,\n \"multiplies the arguments elementwise.\"\n ],\n'divide' : [nobool,cmplxO,\n (\"quot,\"*3,\"PyNumber_Divide\",),\n (2,1), One,\n \"divides the arguments elementwise.\"\n ],\n'floor_divide' : [nobool, cmplxO,\n (\"floor_quot,\"*3,\n \"PyNumber_FloorDivide\"),\n (2,1), One,\n \"floor divides the arguments elementwise.\"\n ],\n'true_divide' : [nobool, cmplxO,\n (\"quot,\"*3,\"PyNumber_TrueDivide\"),\n (2,1), One,\n \"true divides the arguments elementwise.\",\n 'f'*4+'d'*6+flts+cmplxO\n ],\n'conjugate' : [nobool_or_obj, 'M',\n ('\"conjugate\"',),\n (1,1), None,\n \"takes the conjugate of x elementwise.\"\n ],\n\n'fmod' : [intflt,fltsM,\n (\"fmod,\"*3, \"fmod\"),\n (2,1), Zero,\n \"computes (C-like) x1 % x2 elementwise.\"\n ],\n'power' : [nobool,noint,\n (\"pow,\"*6,\n \"PyNumber_Power\"),\n (2,1), One,\n \"computes x1**x2 elementwise.\"\n ],\n'absolute' : [all,'O',\n (\"PyNumber_Absolute\",),\n (1,1), None,\n \"takes |x| elementwise.\",\n nocmplx+fltsO\n ],\n'negative' : [all,cmplxO,\n (\"neg,\"*3,\"PyNumber_Negative\"),\n (1,1), None,\n \"determines -x elementwise\",\n ],\n'sign' : [nobool,'',(),(1,1),None,\n \"returns -1 if x < 0 and 0 if x==0 and 1 if x > 0\"\n ],\n'greater' : [all,'',(),(2,1), None,\n \"returns elementwise x1 > x2 in a bool array.\",\n '?'*len(all)\n ],\n'greater_equal' : [all,'',(),(2,1), None,\n \"returns elementwise x1 >= x2 in a bool array.\",\n '?'*len(all)\n ],\n'less' : [all,'',(),(2,1), None,\n \"returns elementwise x1 < x2 in a bool array.\",\n '?'*len(all)\n ],\n'less_equal' : [all,'',(),(2,1), None,\n \"returns elementwise x1 <= x2 in a bool array\",\n '?'*len(all)\n ],\n'equal' : [all, '', (), (2,1), None,\n \"returns elementwise x1 == x2 in a bool array\",\n '?'*len(all)\n ],\n'not_equal' : [all, '', (), (2,1), None,\n \"returns elementwise x1 |= x2\",\n '?'*len(all)\n ],\n'logical_and': [allM,'M',('\"logical_and\"',),\n (2,1), One,\n \"returns x1 and x2 elementwise.\",\n '?'*len(nocmplxM+cmplx)\n ],\n'logical_or': [allM,'M',('\"logical_or\"',),\n (2,1), Zero, \n \"returns x1 or x2 elementwise.\",\n '?'*len(nocmplxM+cmplx)\n ],\n'logical_xor': [allM, 'M', ('\"logical_xor\"',),\n (2,1), None,\n \"returns x1 xor x2 elementwise.\",\n '?'*len(nocmplxM+cmplx)\n ],\n'logical_not' : [allM, 'M', ('\"logical_not\"',),\n (1,1), None,\n \"returns not x elementwise.\",\n '?'*len(nocmplxM+cmplx)\n ],\n'maximum' : [noobj,'',(),\n (2,1), None,\n \"returns maximum (if x1 > x2: x1; else: x2) elementwise.\"],\n'minimum' : [noobj,'',(),\n (2,1), None,\n \"returns minimum (if x1 < x2: x1; else: x2) elementwise\"],\n'bitwise_and' : [bintsO,'O',(\"PyNumber_And\",),\n (2,1), One,\n \"computes x1 & x2 elementwise.\"],\n'bitwise_or' : [bintsO, 'O', (\"PyNumber_Or\",),\n (2,1), Zero,\n \"computes x1 | x2 elementwise.\"],\n'bitwise_xor' : [bintsO, 'O', (\"PyNumber_Xor\",),\n (2,1), None,\n \"computes x1 ^ x2 elementwise.\"],\n'invert' : [bintsO,'O', (\"PyNumber_Invert\",),\n (1,1), None,\n \"computes ~x (bit inversion) elementwise.\"\n ],\n'left_shift' : [intsO, 'O', (\"PyNumber_Lshift\",),\n (2,1), None,\n \"computes x1 << x2 (x1 shifted to left by x2 bits) elementwise.\"\n ],\n'right_shift' : [intsO, 'O', (\"PyNumber_Rshift\",),\n (2,1), None,\n \"computes x1 >> x2 (x1 shifted to right by x2 bits) elementwise.\"\n ],\n'arccos' : [nointM, nointM,\n (\"acos,\"*6, '\"arccos\"'),\n (1, 1), None,\n \"inverse cosine elementwise.\"\n ],\n'arcsin': [nointM, nointM,\n (\"asin,\"*6, '\"arcsin\"'),\n (1, 1), None,\n \"inverse sine elementwise.\"\n ],\n'arctan': [nointM, nointM,\n (\"atan,\"*6, '\"arctan\"'),\n (1, 1), None,\n \"inverse tangent elementwise.\"\n ],\n'arccosh' : [nointM, nointM,\n (\"acosh,\"*6, '\"arccosh\"'),\n (1, 1), None,\n \"inverse hyperbolic cosine elementwise.\"\n ],\n'arcsinh': [nointM, nointM,\n (\"asinh,\"*6, '\"arcsinh\"'),\n (1, 1), None,\n \"inverse hyperbolic sine elementwise.\"\n ],\n'arctanh': [nointM, nointM,\n (\"atanh,\"*6, '\"arctanh\"'),\n (1, 1), None,\n \"inverse hyperbolic tangent elementwise.\"\n ],\n'cos': [nointM, nointM,\n (\"cos,\"*6, '\"cos\"'),\n (1, 1), None,\n \"cosine elementwise.\"\n ],\n'sin': [nointM, nointM,\n (\"sin,\"*6, '\"sin\"'),\n (1, 1), None,\n \"sine elementwise.\"\n ],\n'tan': [nointM, nointM,\n (\"tan,\"*6, '\"tan\"'),\n (1, 1), None,\n \"tangent elementwise.\"\n ],\n'cosh': [nointM, nointM,\n (\"cosh,\"*6, '\"cosh\"'),\n (1, 1), None,\n \"hyperbolic cosine elementwise.\"\n ],\n'sinh': [nointM, nointM,\n (\"sinh,\"*6, '\"sinh\"'),\n (1, 1), None,\n \"hyperbolic sine elementwise.\"\n ],\n'tanh': [nointM, nointM,\n (\"tanh,\"*6, '\"tanh\"'),\n (1, 1), None,\n \"hyperbolic tangent elementwise.\"\n ],\n'exp' : [nointM, nointM,\n (\"exp,\"*6, '\"exp\"'),\n (1, 1), None,\n \"e**x elementwise.\"\n ],\n'log' : [nointM, nointM,\n (\"log,\"*6, '\"log\"'),\n (1, 1), None,\n \"logarithm base e elementwise.\"\n ],\n'log10' : [nointM, nointM,\n (\"log10,\"*6, '\"log10\"'),\n (1, 1), None,\n \"logarithm base 10 elementwise.\"\n ],\n'sqrt' : [nointM, nointM,\n (\"sqrt,\"*6, '\"sqrt\"'),\n (1,1), None,\n \"square-root elementwise.\"\n ],\n'ceil' : [fltsM, fltsM,\n (\"ceil,\"*3, '\"ceil\"'),\n (1,1), None,\n \"elementwise smallest integer >= x.\"\n ],\n'fabs' : [fltsM, fltsM,\n (\"fabs,\"*3, '\"fabs\"'),\n (1,1), None,\n \"absolute values.\"\n ],\n'floor' : [fltsM, fltsM,\n (\"floor,\"*3, '\"floor\"'),\n (1,1), None,\n \"elementwise largest integer <= x\"\n ],\n'arctan2' : [fltsM, fltsM,\n (\"atan2,\"*3, '\"arctan2\"'),\n (2,1), None,\n \"a safe and correct arctan(x1/x2)\"\n ],\n\n'remainder' : [intflt, 'O',\n (\"PyObject_Remainder\"),\n (2,1), None,\n \"computes x1-n*x2 where n is floor(x1 / x2)\"],\n\n'hypot' : [fltsM, fltsM,\n (\"hypot,\"*3, '\"hypot\"'),\n (2,1), None,\n \"sqrt(x1**2 + x2**2) elementwise\"\n ],\n\n'isnan' : [flts+cmplx, '',\n (), (1,1), None,\n \"returns True where x is Not-A-Number\",\n '?'*len(flts+cmplx)\n ],\n\n'isinf' : [flts+cmplx, '',\n (), (1,1), None,\n \"returns True where x is +inf or -inf\",\n '?'*len(flts+cmplx)\n ],\n\n'isfinite' : [flts+cmplx, '',\n (), (1,1), None,\n \"returns True where x is finite\",\n '?'*len(flts+cmplx)\n ],\n\n'signbit' : [flts,'',\n (),(1,1),None,\n \"returns True where signbit of x is set (x<0).\",\n '?'*len(flts)\n ],\n\n'modf' : [flts,'',\n (),(1,2),None,\n \"breaks x into fractional (y1) and integral (y2) parts.\\\\n\\\\n Each output has the same sign as the input.\"\n ]\n}\n\n\ndef indent(st,spaces):\n indention = ' '*spaces\n indented = indention + string.replace(st,'\\n','\\n'+indention)\n # trim off any trailing spaces\n indented = re.sub(r' +$',r'',indented)\n return indented\n\nchartoname = {'?': 'bool',\n 'b': 'byte',\n 'B': 'ubyte',\n 'h': 'short',\n 'H': 'ushort',\n 'i': 'int',\n 'I': 'uint',\n 'l': 'long',\n 'L': 'ulong',\n 'q': 'longlong',\n 'Q': 'ulonglong',\n 'f': 'float',\n 'd': 'double',\n 'g': 'longdouble',\n 'F': 'cfloat',\n 'D': 'cdouble',\n 'G': 'clongdouble',\n 'O': 'OBJECT',\n 'M': 'OBJECT',\n }\n\nchartotype1 = {'f': 'f_f',\n 'd': 'd_d',\n 'g': 'g_g',\n 'F': 'F_F',\n 'D': 'D_D',\n 'G': 'G_G',\n 'O': 'O_O',\n 'M': 'O_O_method'}\n\nchartotype2 = {'f': 'ff_f',\n 'd': 'dd_d',\n 'g': 'gg_g',\n 'F': 'FF_F',\n 'D': 'DD_D',\n 'G': 'GG_G',\n 'O': 'OO_O',\n 'M': 'O_O_method'}\n#for each name\n# 1) create functions, data, and signature\n# 2) fill in functions and data in InitOperators\n# 3) add function. \n\ndef make_arrays(funcdict):\n # functions array contains an entry for every type implemented\n # NULL should be placed where PyUfunc_ style function will be filled in later\n #\n code1list = []\n code2list = []\n for name, vals in funcdict.iteritems():\n funclist = []\n datalist = []\n siglist = []\n k=0;\n sub=0;\n numin, numout = vals[3]\n\n if numin > 1:\n thedict = chartotype2 # two inputs and one output\n else: \n thedict = chartotype1 # one input and one output\n\n instr = ''.join([x*numin for x in list(vals[0])])\n if len(vals) > 6:\n if isinstance(vals[6],type('')):\n outstr = vals[6]\n else: # a tuple specifying input signature, output signature\n instr, outstr = vals[6]\n else:\n outstr = ''.join([x*numout for x in list(vals[0])])\n\n _valslen = len(vals[0])\n assert _valslen*numout == len(outstr), \"input/output signature doesn't match\"\n assert len(instr) == _valslen*numin, \"input/output signature doesn't match\"\n\n for char in vals[0]:\n if char in vals[1]: # use generic function-based interface\n funclist.append('NULL')\n astr = '%s_functions[%d] = PyUFunc_%s;' % \\\n (name, k, thedict[char])\n code2list.append(astr)\n thisfunc = vals[2][sub] \n if len(thisfunc) > 8 and thisfunc[:8] == \"PyNumber\": \n astr = '%s_data[%d] = (void *) %s;' % \\\n (name, k, thisfunc)\n code2list.append(astr)\n datalist.append('(void *)NULL');\n else:\n datalist.append('(void *)%s' % thisfunc)\n sub += 1\n else: # individual wrapper interface\n datalist.append('(void *)NULL'); \n funclist.append('%s_%s' % (chartoname[char].upper(), name))\n\n insubstr = instr[numin*k:numin*(k+1)]\n outsubstr = outstr[numout*k:numout*(k+1)]\n siglist.extend(['PyArray_%s' % chartoname[x].upper() for x in insubstr])\n siglist.extend(['PyArray_%s' % chartoname[x].upper() for x in outsubstr])\n k += 1\n funcnames = ', '.join(funclist)\n signames = ', '.join(siglist)\n datanames = ', '.join(datalist)\n code1list.append(\"static PyUFuncGenericFunction %s_functions[] = { %s };\" \\\n % (name, funcnames))\n code1list.append(\"static void * %s_data[] = { %s };\" \\\n % (name, datanames))\n code1list.append(\"static char %s_signatures[] = { %s };\" \\\n % (name, signames)) \n return \"\\n\".join(code1list),\"\\n\".join(code2list)\n\ndef make_ufuncs(funcdict):\n code3list = []\n for name, vals in funcdict.items():\n mlist = []\n mlist.append(\\\nr\"\"\"f = PyUFunc_FromFuncAndData(%s_functions, %s_data, %s_signatures, %d,\n %d, %d, %s, \"%s\",\n \"%s\", 0);\"\"\" % (name,name,name,len(vals[0]),\n vals[3][0], vals[3][1], vals[4],\n name, vals[5]))\n mlist.append(r\"\"\"PyDict_SetItemString(dictionary, \"%s\", f);\"\"\"%name)\n mlist.append(r\"\"\"Py_DECREF(f);\"\"\")\n code3list.append('\\n'.join(mlist)) \n return '\\n'.join(code3list)\n \n\ndef convert_vals(funcdict):\n for name, vals in funcdict.iteritems():\n if vals[4] is None:\n vals[4] = None_\n vals2 = vals[2]\n if len(vals2) > 0:\n alist = vals2[0].split(',')\n if len(alist) == 4:\n a = alist[0]\n if 'f' in vals[1]:\n newlist = [ a+'f', a, a+'l']\n else:\n newlist = ['nc_'+a+'f', 'nc_'+a, 'nc_'+a+'l']\n elif len(alist) == 7:\n a = alist[0]\n newlist = [a+'f', a, a+'l','nc_'+a+'f', 'nc_'+a, 'nc_'+a+'l']\n else:\n newlist = alist\n newlist = newlist + list(vals2[1:])\n vals[2] = tuple(newlist)\n funcdict[name] = vals\n\n\ndef make_code(funcdict,filename):\n convert_vals(funcdict)\n code1, code2 = make_arrays(funcdict)\n code3 = make_ufuncs(funcdict)\n code2 = indent(code2,4)\n code3 = indent(code3,4)\n code = r\"\"\"\n\n/** Warning this file is autogenerated!!!\n\n Please make changes to the code generator program (%s)\n**/\n\n%s\n\nstatic void\nInitOperators(PyObject *dictionary) {\n PyObject *f;\n\n%s\n%s\n}\n\"\"\" % (filename, code1, code2, code3)\n return code;\n\n\nif __name__ == \"__main__\":\n filename = __file__\n fid = open('__umath_generated.c','w')\n code = make_code(defdict, filename)\n fid.write(code)\n fid.close()\n", + "methods": [ + { + "name": "indent", + "long_name": "indent( st , spaces )", + "filename": "generate_umath.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "st", + "spaces" + ], + "start_line": 326, + "end_line": 331, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "make_arrays", + "long_name": "make_arrays( funcdict )", + "filename": "generate_umath.py", + "nloc": 58, + "complexity": 13, + "token_count": 468, + "parameters": [ + "funcdict" + ], + "start_line": 376, + "end_line": 441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "make_ufuncs", + "long_name": "make_ufuncs( funcdict )", + "filename": "generate_umath.py", + "nloc": 14, + "complexity": 2, + "token_count": 110, + "parameters": [ + "funcdict" + ], + "start_line": 443, + "end_line": 456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "convert_vals", + "long_name": "convert_vals( funcdict )", + "filename": "generate_umath.py", + "nloc": 21, + "complexity": 7, + "token_count": 186, + "parameters": [ + "funcdict" + ], + "start_line": 459, + "end_line": 479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "make_code", + "long_name": "make_code( funcdict , filename )", + "filename": "generate_umath.py", + "nloc": 24, + "complexity": 1, + "token_count": 58, + "parameters": [ + "funcdict", + "filename" + ], + "start_line": 482, + "end_line": 505, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "indent", + "long_name": "indent( st , spaces )", + "filename": "generate_umath.py", + "nloc": 5, + "complexity": 1, + "token_count": 44, + "parameters": [ + "st", + "spaces" + ], + "start_line": 316, + "end_line": 321, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "make_arrays", + "long_name": "make_arrays( funcdict )", + "filename": "generate_umath.py", + "nloc": 58, + "complexity": 13, + "token_count": 468, + "parameters": [ + "funcdict" + ], + "start_line": 366, + "end_line": 431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "make_ufuncs", + "long_name": "make_ufuncs( funcdict )", + "filename": "generate_umath.py", + "nloc": 14, + "complexity": 2, + "token_count": 110, + "parameters": [ + "funcdict" + ], + "start_line": 433, + "end_line": 446, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "convert_vals", + "long_name": "convert_vals( funcdict )", + "filename": "generate_umath.py", + "nloc": 21, + "complexity": 7, + "token_count": 186, + "parameters": [ + "funcdict" + ], + "start_line": 449, + "end_line": 469, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "make_code", + "long_name": "make_code( funcdict , filename )", + "filename": "generate_umath.py", + "nloc": 24, + "complexity": 1, + "token_count": 58, + "parameters": [ + "funcdict", + "filename" + ], + "start_line": 472, + "end_line": 495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 465, + "complexity": 24, + "token_count": 2740, + "diff_parsed": { + "added": [ + "'expm1' : [nointM, nointM,", + " (\"expm1,\"*6, '\"expm1\"'),", + " (1, 1), None,", + " \"e**x-1 elementwise.\"", + " ],", + "'log1p' : [nointM, nointM,", + " (\"log1p,\"*6, '\"log1p\"'),", + " (1, 1), None,", + " \"log(1+x) to base e elementwise.\"", + " ]," + ], + "deleted": [] + } + }, + { + "old_path": "numpy/core/setup.py", + "new_path": "numpy/core/setup.py", + "filename": "setup.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -57,6 +57,10 @@ def generate_config_h(ext, build_dir):\n moredefs.append('HAVE_LONGDOUBLE_FUNCS')\n if config_cmd.check_func('expf', **kws_args):\n moredefs.append('HAVE_FLOAT_FUNCS')\n+ if config_cmd.check_func('log1p', **kws_args):\n+ moredefs.append('HAVE_LOG1P')\n+ if config_cmd.check_func('expm1', **kws_args):\n+ moredefs.append('HAVE_EXPM1')\n if config_cmd.check_func('asinh', **kws_args):\n moredefs.append('HAVE_INVERSE_HYPERBOLIC')\n if config_cmd.check_func('atanhf', **kws_args):\n", + "added_lines": 4, + "deleted_lines": 0, + "source_code": "\nimport imp\nimport os\nfrom os.path import join\nfrom glob import glob\nfrom distutils.dep_util import newer,newer_group\n\ndef configuration(parent_package='',top_path=None):\n from numpy.distutils.misc_util import Configuration,dot_join\n from numpy.distutils.system_info import get_info\n\n config = Configuration('core',parent_package,top_path)\n local_dir = config.local_path\n codegen_dir = join(local_dir,'code_generators')\n\n generate_umath_py = join(codegen_dir,'generate_umath.py')\n n = dot_join(config.name,'generate_umath')\n generate_umath = imp.load_module('_'.join(n.split('.')),\n open(generate_umath_py,'U'),generate_umath_py,\n ('.py','U',1))\n\n header_dir = join(*(config.name.split('.')+['include','numpy']))\n\n def generate_config_h(ext, build_dir):\n target = join(build_dir,'config.h')\n if newer(__file__,target):\n config_cmd = config.get_config_cmd()\n print 'Generating',target\n #\n tc = generate_testcode(target)\n from distutils import sysconfig\n python_include = sysconfig.get_python_inc()\n result = config_cmd.try_run(tc,include_dirs=[python_include])\n if not result:\n raise \"ERROR: Failed to test configuration\"\n moredefs = []\n\n #\n mathlibs = []\n tc = testcode_mathlib()\n mathlibs_choices = [[],['m'],['cpml']]\n mathlib = os.environ.get('MATHLIB')\n if mathlib:\n mathlibs_choices.insert(0,mathlib.split(','))\n for libs in mathlibs_choices:\n if config_cmd.try_run(tc,libraries=libs):\n mathlibs = libs\n break\n else:\n raise \"math library missing; rerun setup.py after setting the MATHLIB env variable\"\n ext.libraries.extend(mathlibs)\n moredefs.append(('MATHLIB',','.join(mathlibs)))\n\n libs = mathlibs\n kws_args = {'libraries':libs,'decl':0,'headers':['math.h']}\n if config_cmd.check_func('expl', **kws_args):\n moredefs.append('HAVE_LONGDOUBLE_FUNCS')\n if config_cmd.check_func('expf', **kws_args):\n moredefs.append('HAVE_FLOAT_FUNCS')\n if config_cmd.check_func('log1p', **kws_args):\n moredefs.append('HAVE_LOG1P')\n if config_cmd.check_func('expm1', **kws_args):\n moredefs.append('HAVE_EXPM1')\n if config_cmd.check_func('asinh', **kws_args):\n moredefs.append('HAVE_INVERSE_HYPERBOLIC')\n if config_cmd.check_func('atanhf', **kws_args):\n moredefs.append('HAVE_INVERSE_HYPERBOLIC_FLOAT')\n if config_cmd.check_func('atanhl', **kws_args):\n moredefs.append('HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE')\n if config_cmd.check_func('isnan', **kws_args):\n moredefs.append('HAVE_ISNAN')\n if config_cmd.check_func('isinf', **kws_args):\n moredefs.append('HAVE_ISINF')\n\n if moredefs:\n target_f = open(target,'a')\n for d in moredefs:\n if isinstance(d,str):\n target_f.write('#define %s\\n' % (d))\n else:\n target_f.write('#define %s %s\\n' % (d[0],d[1]))\n target_f.close()\n else:\n mathlibs = []\n target_f = open(target)\n for line in target_f.readlines():\n s = '#define MATHLIB'\n if line.startswith(s):\n value = line[len(s):].strip()\n if value:\n mathlibs.extend(value.split(','))\n target_f.close()\n\n ext.libraries.extend(mathlibs)\n\n incl_dir = os.path.dirname(target)\n if incl_dir not in config.numpy_include_dirs:\n config.numpy_include_dirs.append(incl_dir)\n\n config.add_data_files((header_dir,target))\n return target\n\n def generate_api_func(header_file, module_name):\n def generate_api(ext,build_dir):\n target = join(build_dir, header_file)\n script = join(codegen_dir, module_name + '.py')\n if newer(script, target):\n sys.path.insert(0, codegen_dir)\n try:\n m = __import__(module_name)\n print 'executing',script\n m.generate_api(build_dir)\n finally:\n del sys.path[0]\n config.add_data_files((header_dir,target))\n return target\n return generate_api\n\n generate_array_api = generate_api_func('__multiarray_api.h',\n 'generate_array_api')\n generate_ufunc_api = generate_api_func('__ufunc_api.h',\n 'generate_ufunc_api')\n\n def generate_umath_c(ext,build_dir):\n target = join(build_dir,'__umath_generated.c')\n script = generate_umath_py\n if newer(script,target):\n f = open(target,'w')\n f.write(generate_umath.make_code(generate_umath.defdict,\n generate_umath.__file__))\n f.close()\n return []\n\n config.add_data_files(join('include','numpy','*.h'))\n config.add_include_dirs('src')\n\n config.numpy_include_dirs.extend(config.paths('include'))\n\n deps = [join('src','arrayobject.c'),\n join('src','arraymethods.c'),\n join('src','scalartypes.inc.src'),\n join('src','arraytypes.inc.src'),\n join('src','_signbit.c'),\n join('src','_isnan.c'),\n join('include','numpy','*object.h'),\n\t join(codegen_dir,'genapi.py'),\n\t join(codegen_dir,'*.txt')\n ]\n\n config.add_extension('multiarray',\n sources = [join('src','multiarraymodule.c'),\n generate_config_h,\n generate_array_api,\n join('src','scalartypes.inc.src'),\n join('src','arraytypes.inc.src'),\n join(codegen_dir,'generate_array_api.py'),\n join('*.py')\n ],\n depends = deps,\n )\n\n config.add_extension('umath',\n sources = [generate_config_h,\n join('src','umathmodule.c.src'),\n generate_umath_c,\n generate_ufunc_api,\n join('src','scalartypes.inc.src'),\n join('src','arraytypes.inc.src'),\n ],\n depends = [join('src','ufuncobject.c'),\n generate_umath_py,\n join(codegen_dir,'generate_ufunc_api.py'),\n ]+deps,\n )\n\n config.add_extension('_sort',\n sources=[join('src','_sortmodule.c.src'),\n generate_config_h,\n generate_array_api,\n ],\n )\n\n # Configure blasdot\n blas_info = get_info('blas_opt',0)\n #blas_info = {}\n def get_dotblas_sources(ext, build_dir):\n if blas_info:\n return ext.depends[:1]\n return None # no extension module will be built\n\n config.add_extension('_dotblas',\n sources = [get_dotblas_sources],\n depends=[join('blasdot','_dotblas.c'),\n join('blasdot','cblas.h'),\n ],\n include_dirs = ['blasdot'],\n extra_info = blas_info\n )\n\n\n config.add_data_dir('tests')\n config.make_svn_version_py()\n\n return config\n\ndef testcode_mathlib():\n return \"\"\"\\\n/* check whether libm is broken */\n#include \nint main(int argc, char *argv[])\n{\n return exp(-720.) > 1.0; /* typically an IEEE denormal */\n}\n\"\"\"\n\nimport sys\ndef generate_testcode(target):\n if sys.platform == 'win32':\n target = target.replace('\\\\','\\\\\\\\')\n testcode = [r'''\n#include \n#include \n#include \n\nint main(int argc, char **argv)\n{\n\n FILE *fp;\n\n fp = fopen(\"'''+target+'''\",\"w\");\n ''']\n\n c_size_test = r'''\n#ifndef %(sz)s\n fprintf(fp,\"#define %(sz)s %%d\\n\", sizeof(%(type)s));\n#else\n fprintf(fp,\"/* #define %(sz)s %%d */\\n\", %(sz)s);\n#endif\n'''\n for sz, t in [('SIZEOF_SHORT', 'short'),\n ('SIZEOF_INT', 'int'),\n ('SIZEOF_LONG', 'long'),\n ('SIZEOF_FLOAT', 'float'),\n ('SIZEOF_DOUBLE', 'double'),\n ('SIZEOF_LONG_DOUBLE', 'long double'),\n ('SIZEOF_PY_INTPTR_T', 'Py_intptr_t'),\n ]:\n testcode.append(c_size_test % {'sz' : sz, 'type' : t})\n\n testcode.append('#ifdef PY_LONG_LONG')\n testcode.append(c_size_test % {'sz' : 'SIZEOF_LONG_LONG',\n 'type' : 'PY_LONG_LONG'})\n testcode.append(c_size_test % {'sz' : 'SIZEOF_PY_LONG_LONG',\n 'type' : 'PY_LONG_LONG'})\n\n\n testcode.append(r'''\n#else\n fprintf(fp, \"/* PY_LONG_LONG not defined */\\n\");\n#endif\n#ifndef CHAR_BIT\n {\n unsigned char var = 2;\n int i=0;\n while (var >= 2) {\n var = var << 1;\n i++;\n }\n fprintf(fp,\"#define CHAR_BIT %d\\n\", i+1);\n }\n#else\n fprintf(fp, \"/* #define CHAR_BIT %d */\\n\", CHAR_BIT);\n#endif\n fclose(fp);\n return 0;\n}\n''')\n testcode = '\\n'.join(testcode)\n return testcode\n\nif __name__=='__main__':\n from numpy.distutils.core import setup\n setup(**configuration(top_path='').todict())\n", + "source_code_before": "\nimport imp\nimport os\nfrom os.path import join\nfrom glob import glob\nfrom distutils.dep_util import newer,newer_group\n\ndef configuration(parent_package='',top_path=None):\n from numpy.distutils.misc_util import Configuration,dot_join\n from numpy.distutils.system_info import get_info\n\n config = Configuration('core',parent_package,top_path)\n local_dir = config.local_path\n codegen_dir = join(local_dir,'code_generators')\n\n generate_umath_py = join(codegen_dir,'generate_umath.py')\n n = dot_join(config.name,'generate_umath')\n generate_umath = imp.load_module('_'.join(n.split('.')),\n open(generate_umath_py,'U'),generate_umath_py,\n ('.py','U',1))\n\n header_dir = join(*(config.name.split('.')+['include','numpy']))\n\n def generate_config_h(ext, build_dir):\n target = join(build_dir,'config.h')\n if newer(__file__,target):\n config_cmd = config.get_config_cmd()\n print 'Generating',target\n #\n tc = generate_testcode(target)\n from distutils import sysconfig\n python_include = sysconfig.get_python_inc()\n result = config_cmd.try_run(tc,include_dirs=[python_include])\n if not result:\n raise \"ERROR: Failed to test configuration\"\n moredefs = []\n\n #\n mathlibs = []\n tc = testcode_mathlib()\n mathlibs_choices = [[],['m'],['cpml']]\n mathlib = os.environ.get('MATHLIB')\n if mathlib:\n mathlibs_choices.insert(0,mathlib.split(','))\n for libs in mathlibs_choices:\n if config_cmd.try_run(tc,libraries=libs):\n mathlibs = libs\n break\n else:\n raise \"math library missing; rerun setup.py after setting the MATHLIB env variable\"\n ext.libraries.extend(mathlibs)\n moredefs.append(('MATHLIB',','.join(mathlibs)))\n\n libs = mathlibs\n kws_args = {'libraries':libs,'decl':0,'headers':['math.h']}\n if config_cmd.check_func('expl', **kws_args):\n moredefs.append('HAVE_LONGDOUBLE_FUNCS')\n if config_cmd.check_func('expf', **kws_args):\n moredefs.append('HAVE_FLOAT_FUNCS')\n if config_cmd.check_func('asinh', **kws_args):\n moredefs.append('HAVE_INVERSE_HYPERBOLIC')\n if config_cmd.check_func('atanhf', **kws_args):\n moredefs.append('HAVE_INVERSE_HYPERBOLIC_FLOAT')\n if config_cmd.check_func('atanhl', **kws_args):\n moredefs.append('HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE')\n if config_cmd.check_func('isnan', **kws_args):\n moredefs.append('HAVE_ISNAN')\n if config_cmd.check_func('isinf', **kws_args):\n moredefs.append('HAVE_ISINF')\n\n if moredefs:\n target_f = open(target,'a')\n for d in moredefs:\n if isinstance(d,str):\n target_f.write('#define %s\\n' % (d))\n else:\n target_f.write('#define %s %s\\n' % (d[0],d[1]))\n target_f.close()\n else:\n mathlibs = []\n target_f = open(target)\n for line in target_f.readlines():\n s = '#define MATHLIB'\n if line.startswith(s):\n value = line[len(s):].strip()\n if value:\n mathlibs.extend(value.split(','))\n target_f.close()\n\n ext.libraries.extend(mathlibs)\n\n incl_dir = os.path.dirname(target)\n if incl_dir not in config.numpy_include_dirs:\n config.numpy_include_dirs.append(incl_dir)\n\n config.add_data_files((header_dir,target))\n return target\n\n def generate_api_func(header_file, module_name):\n def generate_api(ext,build_dir):\n target = join(build_dir, header_file)\n script = join(codegen_dir, module_name + '.py')\n if newer(script, target):\n sys.path.insert(0, codegen_dir)\n try:\n m = __import__(module_name)\n print 'executing',script\n m.generate_api(build_dir)\n finally:\n del sys.path[0]\n config.add_data_files((header_dir,target))\n return target\n return generate_api\n\n generate_array_api = generate_api_func('__multiarray_api.h',\n 'generate_array_api')\n generate_ufunc_api = generate_api_func('__ufunc_api.h',\n 'generate_ufunc_api')\n\n def generate_umath_c(ext,build_dir):\n target = join(build_dir,'__umath_generated.c')\n script = generate_umath_py\n if newer(script,target):\n f = open(target,'w')\n f.write(generate_umath.make_code(generate_umath.defdict,\n generate_umath.__file__))\n f.close()\n return []\n\n config.add_data_files(join('include','numpy','*.h'))\n config.add_include_dirs('src')\n\n config.numpy_include_dirs.extend(config.paths('include'))\n\n deps = [join('src','arrayobject.c'),\n join('src','arraymethods.c'),\n join('src','scalartypes.inc.src'),\n join('src','arraytypes.inc.src'),\n join('src','_signbit.c'),\n join('src','_isnan.c'),\n join('include','numpy','*object.h'),\n\t join(codegen_dir,'genapi.py'),\n\t join(codegen_dir,'*.txt')\n ]\n\n config.add_extension('multiarray',\n sources = [join('src','multiarraymodule.c'),\n generate_config_h,\n generate_array_api,\n join('src','scalartypes.inc.src'),\n join('src','arraytypes.inc.src'),\n join(codegen_dir,'generate_array_api.py'),\n join('*.py')\n ],\n depends = deps,\n )\n\n config.add_extension('umath',\n sources = [generate_config_h,\n join('src','umathmodule.c.src'),\n generate_umath_c,\n generate_ufunc_api,\n join('src','scalartypes.inc.src'),\n join('src','arraytypes.inc.src'),\n ],\n depends = [join('src','ufuncobject.c'),\n generate_umath_py,\n join(codegen_dir,'generate_ufunc_api.py'),\n ]+deps,\n )\n\n config.add_extension('_sort',\n sources=[join('src','_sortmodule.c.src'),\n generate_config_h,\n generate_array_api,\n ],\n )\n\n # Configure blasdot\n blas_info = get_info('blas_opt',0)\n #blas_info = {}\n def get_dotblas_sources(ext, build_dir):\n if blas_info:\n return ext.depends[:1]\n return None # no extension module will be built\n\n config.add_extension('_dotblas',\n sources = [get_dotblas_sources],\n depends=[join('blasdot','_dotblas.c'),\n join('blasdot','cblas.h'),\n ],\n include_dirs = ['blasdot'],\n extra_info = blas_info\n )\n\n\n config.add_data_dir('tests')\n config.make_svn_version_py()\n\n return config\n\ndef testcode_mathlib():\n return \"\"\"\\\n/* check whether libm is broken */\n#include \nint main(int argc, char *argv[])\n{\n return exp(-720.) > 1.0; /* typically an IEEE denormal */\n}\n\"\"\"\n\nimport sys\ndef generate_testcode(target):\n if sys.platform == 'win32':\n target = target.replace('\\\\','\\\\\\\\')\n testcode = [r'''\n#include \n#include \n#include \n\nint main(int argc, char **argv)\n{\n\n FILE *fp;\n\n fp = fopen(\"'''+target+'''\",\"w\");\n ''']\n\n c_size_test = r'''\n#ifndef %(sz)s\n fprintf(fp,\"#define %(sz)s %%d\\n\", sizeof(%(type)s));\n#else\n fprintf(fp,\"/* #define %(sz)s %%d */\\n\", %(sz)s);\n#endif\n'''\n for sz, t in [('SIZEOF_SHORT', 'short'),\n ('SIZEOF_INT', 'int'),\n ('SIZEOF_LONG', 'long'),\n ('SIZEOF_FLOAT', 'float'),\n ('SIZEOF_DOUBLE', 'double'),\n ('SIZEOF_LONG_DOUBLE', 'long double'),\n ('SIZEOF_PY_INTPTR_T', 'Py_intptr_t'),\n ]:\n testcode.append(c_size_test % {'sz' : sz, 'type' : t})\n\n testcode.append('#ifdef PY_LONG_LONG')\n testcode.append(c_size_test % {'sz' : 'SIZEOF_LONG_LONG',\n 'type' : 'PY_LONG_LONG'})\n testcode.append(c_size_test % {'sz' : 'SIZEOF_PY_LONG_LONG',\n 'type' : 'PY_LONG_LONG'})\n\n\n testcode.append(r'''\n#else\n fprintf(fp, \"/* PY_LONG_LONG not defined */\\n\");\n#endif\n#ifndef CHAR_BIT\n {\n unsigned char var = 2;\n int i=0;\n while (var >= 2) {\n var = var << 1;\n i++;\n }\n fprintf(fp,\"#define CHAR_BIT %d\\n\", i+1);\n }\n#else\n fprintf(fp, \"/* #define CHAR_BIT %d */\\n\", CHAR_BIT);\n#endif\n fclose(fp);\n return 0;\n}\n''')\n testcode = '\\n'.join(testcode)\n return testcode\n\nif __name__=='__main__':\n from numpy.distutils.core import setup\n setup(**configuration(top_path='').todict())\n", + "methods": [ + { + "name": "configuration.generate_config_h", + "long_name": "configuration.generate_config_h( ext , build_dir )", + "filename": "setup.py", + "nloc": 70, + "complexity": 22, + "token_count": 515, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 24, + "end_line": 101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 1 + }, + { + "name": "configuration.configuration.generate_api_func.generate_api", + "long_name": "configuration.configuration.generate_api_func.generate_api( ext , build_dir )", + "filename": "setup.py", + "nloc": 13, + "complexity": 3, + "token_count": 82, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 104, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 2 + }, + { + "name": "configuration.generate_api_func", + "long_name": "configuration.generate_api_func( header_file , module_name )", + "filename": "setup.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "header_file", + "module_name" + ], + "start_line": 103, + "end_line": 117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "configuration.generate_umath_c", + "long_name": "configuration.generate_umath_c( ext , build_dir )", + "filename": "setup.py", + "nloc": 9, + "complexity": 2, + "token_count": 59, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 124, + "end_line": 132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "configuration.get_dotblas_sources", + "long_name": "configuration.get_dotblas_sources( ext , build_dir )", + "filename": "setup.py", + "nloc": 4, + "complexity": 2, + "token_count": 20, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 186, + "end_line": 189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "configuration", + "long_name": "configuration( parent_package = '' , top_path = None )", + "filename": "setup.py", + "nloc": 75, + "complexity": 1, + "token_count": 450, + "parameters": [ + "parent_package", + "top_path" + ], + "start_line": 8, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 197, + "top_nesting_level": 0 + }, + { + "name": "testcode_mathlib", + "long_name": "testcode_mathlib( )", + "filename": "setup.py", + "nloc": 9, + "complexity": 1, + "token_count": 6, + "parameters": [], + "start_line": 206, + "end_line": 214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "generate_testcode", + "long_name": "generate_testcode( target )", + "filename": "setup.py", + "nloc": 59, + "complexity": 3, + "token_count": 157, + "parameters": [ + "target" + ], + "start_line": 217, + "end_line": 279, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "configuration.generate_config_h", + "long_name": "configuration.generate_config_h( ext , build_dir )", + "filename": "setup.py", + "nloc": 66, + "complexity": 20, + "token_count": 481, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 24, + "end_line": 97, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 1 + }, + { + "name": "configuration.configuration.generate_api_func.generate_api", + "long_name": "configuration.configuration.generate_api_func.generate_api( ext , build_dir )", + "filename": "setup.py", + "nloc": 13, + "complexity": 3, + "token_count": 82, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 100, + "end_line": 112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 2 + }, + { + "name": "configuration.generate_api_func", + "long_name": "configuration.generate_api_func( header_file , module_name )", + "filename": "setup.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "header_file", + "module_name" + ], + "start_line": 99, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "configuration.generate_umath_c", + "long_name": "configuration.generate_umath_c( ext , build_dir )", + "filename": "setup.py", + "nloc": 9, + "complexity": 2, + "token_count": 59, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 120, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "configuration.get_dotblas_sources", + "long_name": "configuration.get_dotblas_sources( ext , build_dir )", + "filename": "setup.py", + "nloc": 4, + "complexity": 2, + "token_count": 20, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 182, + "end_line": 185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "configuration", + "long_name": "configuration( parent_package = '' , top_path = None )", + "filename": "setup.py", + "nloc": 75, + "complexity": 1, + "token_count": 450, + "parameters": [ + "parent_package", + "top_path" + ], + "start_line": 8, + "end_line": 200, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 193, + "top_nesting_level": 0 + }, + { + "name": "testcode_mathlib", + "long_name": "testcode_mathlib( )", + "filename": "setup.py", + "nloc": 9, + "complexity": 1, + "token_count": 6, + "parameters": [], + "start_line": 202, + "end_line": 210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "generate_testcode", + "long_name": "generate_testcode( target )", + "filename": "setup.py", + "nloc": 59, + "complexity": 3, + "token_count": 157, + "parameters": [ + "target" + ], + "start_line": 213, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "configuration", + "long_name": "configuration( parent_package = '' , top_path = None )", + "filename": "setup.py", + "nloc": 75, + "complexity": 1, + "token_count": 450, + "parameters": [ + "parent_package", + "top_path" + ], + "start_line": 8, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 197, + "top_nesting_level": 0 + }, + { + "name": "configuration.generate_config_h", + "long_name": "configuration.generate_config_h( ext , build_dir )", + "filename": "setup.py", + "nloc": 70, + "complexity": 22, + "token_count": 515, + "parameters": [ + "ext", + "build_dir" + ], + "start_line": 24, + "end_line": 101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 1 + } + ], + "nloc": 246, + "complexity": 35, + "token_count": 1349, + "diff_parsed": { + "added": [ + " if config_cmd.check_func('log1p', **kws_args):", + " moredefs.append('HAVE_LOG1P')", + " if config_cmd.check_func('expm1', **kws_args):", + " moredefs.append('HAVE_EXPM1')" + ], + "deleted": [] + } + }, + { + "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": "@@ -20,15 +20,41 @@ extern double modf (double, double *);\n #define M_PI 3.14159265358979323846264338328\n #endif\n \n+#ifndef HAVE_LOG1P\n+static double 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+#ifndef HAVE_EXPM1\n+static 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 #ifndef HAVE_INVERSE_HYPERBOLIC\n static double acosh(double x)\n {\n-\treturn log(x + sqrt((x-1.0)*(x+1.0)));\n+\treturn 2*log(sqrt((x+1.0)/2)+sqrt((x-1.0)/2));\n }\n \n static double asinh(double xx)\n {\n-\tdouble x;\n+\tdouble x, d;\n \tint sign;\n \tif (xx < 0.0) {\n \t\tsign = -1;\n@@ -38,15 +64,120 @@ static double asinh(double xx)\n \t\tsign = 1;\n \t\tx = xx;\n \t}\n-\treturn sign*log(x + sqrt(x*x+1.0));\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 \n static double atanh(double x)\n {\n-\treturn 0.5*log((1.0+x)/(1.0-x));\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+static float acoshf(float x)\n+{\n+\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n+}\n+\n+static 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+static float atanhf(float x)\n+{\n+\treturn 0.5*log1pf(2.0*x/(1.0-x));\n+}\n+#else\n+static float acoshf(float x)\n+{\n+ return (float)acosh((double)(x));\n+}\n+\n+static float asinhf(float x)\n+{\n+ return (float)asinh((double)(x));\n+}\n+\n+static 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+static longdouble acoshl(longdouble x)\n+{\n+\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n+}\n+\n+static 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+static longdouble atanhl(longdouble x)\n+{\n+\treturn 0.5*log1pl(2.0*x/(1.0-x));\n+}\n+#else\n+static longdouble acoshl(longdouble x)\n+{\n+ return (longdouble)acosh((double)(x));\n+}\n+\n+static longdouble asinhl(longdouble x)\n+{\n+ return (longdouble)asinh((double)(x));\n+}\n+\n+static longdouble atanhl(longdouble x)\n+{\n+ return (longdouble)atanh((double)(x));\n+}\n+#endif\n+#endif\n+\n+\n #ifdef HAVE_HYPOT\n #if !defined(NeXT) && !defined(_MSC_VER)\n extern double hypot(double, double);\n@@ -173,26 +304,26 @@ double hypot(double x, double y)\n \n /* First, the C functions that do the real work */\n \n-/* if C99 extensions not availble\n-\n-then define dummy functions that use the double versions for\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+ 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+ hypot, atan2, pow\n \n+ log1p, expm1\n */\n \n /**begin repeat\n \n-#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan)*2#\n-#typ=longdouble*16, float*16#\n-#c=l*16,f*16#\n-#TYPE=LONGDOUBLE*16, FLOAT*16#\n+#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan,log1p,expm1)*2#\n+#typ=longdouble*18, float*18#\n+#c=l*18,f*18#\n+#TYPE=LONGDOUBLE*18, FLOAT*18#\n */\n #ifndef HAVE_@TYPE@_FUNCS\n @typ@ @kind@@c@(@typ@ x) {\n@@ -233,95 +364,6 @@ hypot, atan2, pow\n /**end repeat**/\n \n \n-#if !defined(HAVE_INVERSE_HYPERBOLIC_FLOAT)\n-#ifdef HAVE_FLOAT_FUNCS\n-static float acoshf(float x)\n-{\n-\treturn logf(x + sqrtf((x-1.0)*(x+1.0)));\n-}\n-\n-static float asinhf(float xx)\n-{\n-\tfloat x;\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-\treturn sign*logf(x + sqrtf(x*x+1.0));\n-}\n-\n-static float atanhf(float x)\n-{\n-\treturn 0.5*logf((1.0+x)/(1.0-x));\n-}\n-#else\n-static float acoshf(float x)\n-{\n- return (float)acosh((double)(x));\n-}\n-\n-static float asinhf(float x)\n-{\n- return (float)asinh((double)(x));\n-}\n-\n-static 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-static longdouble acoshl(longdouble x)\n-{\n-\treturn logl(x + sqrtl((x-1.0)*(x+1.0)));\n-}\n-\n-static longdouble asinhl(longdouble xx)\n-{\n-\tlongdouble x;\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-\treturn sign*logl(x + sqrtl(x*x+1.0));\n-}\n-\n-static longdouble atanhl(longdouble x)\n-{\n-\treturn 0.5*logl((1.0+x)/(1.0-x));\n-}\n-#else\n-static longdouble acoshl(longdouble x)\n-{\n- return (longdouble)acosh((double)(x));\n-}\n-\n-static longdouble asinhl(longdouble x)\n-{\n- return (longdouble)asinh((double)(x));\n-}\n-\n-static longdouble atanhl(longdouble x)\n-{\n- return (longdouble)atanh((double)(x));\n-}\n-#endif\n-#endif\n-\n \n \n \n@@ -435,6 +477,15 @@ nc_log@c@(c@typ@ *x, c@typ@ *r)\n \treturn;\n }\n \n+static void\n+nc_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+\n static void\n nc_exp@c@(c@typ@ *x, c@typ@ *r)\n {\n@@ -444,6 +495,15 @@ nc_exp@c@(c@typ@ *x, c@typ@ *r)\n \treturn;\n }\n \n+static void\n+nc_expm1@c@(c@typ@ *x, c@typ@ *r)\n+{\n+\t@typ@ a = exp@c@(x->real-1);\n+\tr->real = a*cos@c@(x->imag);\n+\tr->imag = a*sin@c@(x->imag);\n+\treturn;\n+}\n+\n static void\n nc_pow@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n {\n", + "added_lines": 166, + "deleted_lines": 106, + "source_code": "/* -*- c -*- */\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#define _UMATHMODULE\n#include \"numpy/ufuncobject.h\"\n#include \"abstract.h\"\n#include \n\n\n/* A whole slew of basic math functions are provided originally 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#ifndef HAVE_LOG1P\nstatic double 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#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#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\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\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\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\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\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\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\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\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n#else\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\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\ndouble 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\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\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 log1p, expm1\n*/\n\n/**begin repeat\n\n#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan,log1p,expm1)*2#\n#typ=longdouble*18, float*18#\n#c=l*18,f*18#\n#TYPE=LONGDOUBLE*18, FLOAT*18#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\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@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@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\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\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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-1);\n\tr->real = a*cos@c@(x->imag);\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\t@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\t}\n\telse if (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n\t}\n\telse {\n\t\tnc_log@c@(a, r);\n\t\tnc_prod@c@(r, b, r);\n\t\tnc_exp@c@(r, r);\n\t}\n\treturn;\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; i> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n\t/* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>32) || (y>>32) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>64) || (y>>64) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n\treturn 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n\tulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n\tif (a0 < 0) { a = -a0; } else { a = a0; }\n\tif (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n\tah = (a >> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n /*\n\t ulonglong c = ((x + y)<<32) + w;\n\t if ((a0 < 0) ^ (b0 < 0))\n\t *c = -c;\n\t else\n\t *c = c\n\t */\n\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>31) || (y>>31) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>63) || (y>>63) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n\treturn 0;\n#endif\n}\n\n/** end direct numarray code **/\n\nstatic void\nBOOL_multiply(char **args, intp *dimensions, intp *steps, void *func) {\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 MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nULONGLONG_multiply(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\tulonglong temp;\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\telse if (temp < MIN_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nLONGLONG_multiply(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\tlonglong temp;\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=fmod*10, 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\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\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 memcpy(op, i1, sizeof(@typ@));\n else\n memcpy(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\n/* A whole slew of basic math functions are provided originally 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#ifndef HAVE_INVERSE_HYPERBOLIC\nstatic double acosh(double x)\n{\n\treturn log(x + sqrt((x-1.0)*(x+1.0)));\n}\n\nstatic double asinh(double xx)\n{\n\tdouble x;\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\treturn sign*log(x + sqrt(x*x+1.0));\n}\n\nstatic double atanh(double x)\n{\n\treturn 0.5*log((1.0+x)/(1.0-x));\n}\n#endif\n\n#ifdef HAVE_HYPOT\n#if !defined(NeXT) && !defined(_MSC_VER)\nextern double hypot(double, double);\n#endif\n#else\ndouble 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\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\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 availble\n\nthen define dummy functions that use the double versions for\n\nsin, cos, tan\nsinh, cosh, tanh,\nfabs, floor, ceil, fmod, sqrt, log10, log, exp, fabs\nasin, acos, atan,\nasinh, acosh, atanh\n\nhypot, atan2, pow\n\n*/\n\n/**begin repeat\n\n#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan)*2#\n#typ=longdouble*16, float*16#\n#c=l*16,f*16#\n#TYPE=LONGDOUBLE*16, FLOAT*16#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\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@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@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#if !defined(HAVE_INVERSE_HYPERBOLIC_FLOAT)\n#ifdef HAVE_FLOAT_FUNCS\nstatic float acoshf(float x)\n{\n\treturn logf(x + sqrtf((x-1.0)*(x+1.0)));\n}\n\nstatic float asinhf(float xx)\n{\n\tfloat x;\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\treturn sign*logf(x + sqrtf(x*x+1.0));\n}\n\nstatic float atanhf(float x)\n{\n\treturn 0.5*logf((1.0+x)/(1.0-x));\n}\n#else\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\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\nstatic longdouble acoshl(longdouble x)\n{\n\treturn logl(x + sqrtl((x-1.0)*(x+1.0)));\n}\n\nstatic longdouble asinhl(longdouble xx)\n{\n\tlongdouble x;\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\treturn sign*logl(x + sqrtl(x*x+1.0));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*logl((1.0+x)/(1.0-x));\n}\n#else\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\n}\n#endif\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\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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_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_pow@c@(c@typ@ *a, c@typ@ *b, c@typ@ *r)\n{\n\t@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\t}\n\telse if (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n\t}\n\telse {\n\t\tnc_log@c@(a, r);\n\t\tnc_prod@c@(r, b, r);\n\t\tnc_exp@c@(r, r);\n\t}\n\treturn;\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; i> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n\t/* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>32) || (y>>32) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>64) || (y>>64) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n\treturn 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n\tulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n\tif (a0 < 0) { a = -a0; } else { a = a0; }\n\tif (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n\tah = (a >> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n /*\n\t ulonglong c = ((x + y)<<32) + w;\n\t if ((a0 < 0) ^ (b0 < 0))\n\t *c = -c;\n\t else\n\t *c = c\n\t */\n\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>31) || (y>>31) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>63) || (y>>63) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n\treturn 0;\n#endif\n}\n\n/** end direct numarray code **/\n\nstatic void\nBOOL_multiply(char **args, intp *dimensions, intp *steps, void *func) {\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 MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nULONGLONG_multiply(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\tulonglong temp;\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\telse if (temp < MIN_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nLONGLONG_multiply(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\tlonglong temp;\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=fmod*10, 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\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\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 memcpy(op, i1, sizeof(@typ@));\n else\n memcpy(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 1e8) {", + "\t\td = x;", + "\t} else {", + "\t\td = sqrt(x*x + 1);", + "\t}", + "\treturn sign*log1p(x*(1.0 + x/(d+1)));", + "\treturn 0.5*log1p(2.0*x/(1.0-x));", + "#if !defined(HAVE_INVERSE_HYPERBOLIC_FLOAT)", + "#ifdef HAVE_FLOAT_FUNCS", + "static float acoshf(float x)", + "{", + "\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));", + "}", + "", + "static float asinhf(float xx)", + "{", + "\tfloat x, d;", + "\tint sign;", + "\tif (xx < 0.0) {", + "\t\tsign = -1;", + "\t\tx = -xx;", + "\t}", + "\telse {", + "\t\tsign = 1;", + "\t\tx = xx;", + "\t}", + "\tif (x > 1e5) {", + "\t\td = x;", + "\t} else {", + "\t\td = sqrtf(x*x + 1);", + "\t}", + "\treturn sign*log1pf(x*(1.0 + x/(d+1)));", + "}", + "", + "static float atanhf(float x)", + "{", + "\treturn 0.5*log1pf(2.0*x/(1.0-x));", + "}", + "#else", + "static float acoshf(float x)", + "{", + " return (float)acosh((double)(x));", + "}", + "", + "static float asinhf(float x)", + "{", + " return (float)asinh((double)(x));", + "}", + "", + "static float atanhf(float x)", + "{", + " return (float)atanh((double)(x));", + "}", + "#endif", + "#endif", + "", + "", + "#if !defined(HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE)", + "#ifdef HAVE_LONGDOUBLE_FUNCS", + "static longdouble acoshl(longdouble x)", + "{", + "\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));", + "}", + "", + "static longdouble asinhl(longdouble xx)", + "{", + "\tlongdouble x, d;", + "\tint sign;", + "\tif (xx < 0.0) {", + "\t\tsign = -1;", + "\t\tx = -xx;", + "\t}", + "\telse {", + "\t\tsign = 1;", + "\t\tx = xx;", + "\t}", + "\tif (x > 1e17) {", + "\t\td = x;", + "\t} else {", + "\t\td = sqrtl(x*x + 1);", + "\t}", + "\treturn sign*log1pl(x*(1.0 + x/(d+1)));", + "}", + "", + "static longdouble atanhl(longdouble x)", + "{", + "\treturn 0.5*log1pl(2.0*x/(1.0-x));", + "}", + "#else", + "static longdouble acoshl(longdouble x)", + "{", + " return (longdouble)acosh((double)(x));", + "}", + "", + "static longdouble asinhl(longdouble x)", + "{", + " return (longdouble)asinh((double)(x));", + "}", + "", + "static longdouble atanhl(longdouble x)", + "{", + " return (longdouble)atanh((double)(x));", + "}", + "#endif", + "#endif", + "", + "", + "/* if C99 extensions not available then define dummy functions that use the", + " double versions for", + " sin, cos, tan", + " sinh, cosh, tanh,", + " fabs, floor, ceil, fmod, sqrt, log10, log, exp, fabs", + " asin, acos, atan,", + " asinh, acosh, atanh", + " hypot, atan2, pow", + " log1p, expm1", + "#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan,log1p,expm1)*2#", + "#typ=longdouble*18, float*18#", + "#c=l*18,f*18#", + "#TYPE=LONGDOUBLE*18, FLOAT*18#", + "static void", + "nc_log1p@c@(c@typ@ *x, c@typ@ *r)", + "{", + "\t@typ@ l = hypot@c@(x->real + 1.0,x->imag);", + "\tr->imag = atan2@c@(x->imag, x->real + 1.0);", + "\tr->real = log@c@(l);", + "\treturn;", + "}", + "", + "static void", + "nc_expm1@c@(c@typ@ *x, c@typ@ *r)", + "{", + "\t@typ@ a = exp@c@(x->real-1);", + "\tr->real = a*cos@c@(x->imag);", + "\tr->imag = a*sin@c@(x->imag);", + "\treturn;", + "}", + "" + ], + "deleted": [ + "\treturn log(x + sqrt((x-1.0)*(x+1.0)));", + "\tdouble x;", + "\treturn sign*log(x + sqrt(x*x+1.0));", + "\treturn 0.5*log((1.0+x)/(1.0-x));", + "/* if C99 extensions not availble", + "", + "then define dummy functions that use the double versions for", + "sin, cos, tan", + "sinh, cosh, tanh,", + "fabs, floor, ceil, fmod, sqrt, log10, log, exp, fabs", + "asin, acos, atan,", + "asinh, acosh, atanh", + "hypot, atan2, pow", + "#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan)*2#", + "#typ=longdouble*16, float*16#", + "#c=l*16,f*16#", + "#TYPE=LONGDOUBLE*16, FLOAT*16#", + "#if !defined(HAVE_INVERSE_HYPERBOLIC_FLOAT)", + "#ifdef HAVE_FLOAT_FUNCS", + "static float acoshf(float x)", + "{", + "\treturn logf(x + sqrtf((x-1.0)*(x+1.0)));", + "}", + "", + "static float asinhf(float xx)", + "{", + "\tfloat x;", + "\tint sign;", + "\tif (xx < 0.0) {", + "\t\tsign = -1;", + "\t\tx = -xx;", + "\t}", + "\telse {", + "\t\tsign = 1;", + "\t\tx = xx;", + "\t}", + "\treturn sign*logf(x + sqrtf(x*x+1.0));", + "}", + "", + "static float atanhf(float x)", + "{", + "\treturn 0.5*logf((1.0+x)/(1.0-x));", + "}", + "#else", + "static float acoshf(float x)", + "{", + " return (float)acosh((double)(x));", + "}", + "", + "static float asinhf(float x)", + "{", + " return (float)asinh((double)(x));", + "}", + "", + "static float atanhf(float x)", + "{", + " return (float)atanh((double)(x));", + "}", + "#endif", + "#endif", + "", + "", + "#if !defined(HAVE_INVERSE_HYPERBOLIC_LONGDOUBLE)", + "#ifdef HAVE_LONGDOUBLE_FUNCS", + "static longdouble acoshl(longdouble x)", + "{", + "\treturn logl(x + sqrtl((x-1.0)*(x+1.0)));", + "}", + "", + "static longdouble asinhl(longdouble xx)", + "{", + "\tlongdouble x;", + "\tint sign;", + "\tif (xx < 0.0) {", + "\t\tsign = -1;", + "\t\tx = -xx;", + "\t}", + "\telse {", + "\t\tsign = 1;", + "\t\tx = xx;", + "\t}", + "\treturn sign*logl(x + sqrtl(x*x+1.0));", + "}", + "", + "static longdouble atanhl(longdouble x)", + "{", + "\treturn 0.5*logl((1.0+x)/(1.0-x));", + "}", + "#else", + "static longdouble acoshl(longdouble x)", + "{", + " return (longdouble)acosh((double)(x));", + "}", + "", + "static longdouble asinhl(longdouble x)", + "{", + " return (longdouble)asinh((double)(x));", + "}", + "", + "static longdouble atanhl(longdouble x)", + "{", + " return (longdouble)atanh((double)(x));", + "}", + "#endif", + "#endif", + "" + ] + } + }, + { + "old_path": "numpy/core/tests/test_umath.py", + "new_path": "numpy/core/tests/test_umath.py", + "filename": "test_umath.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -5,6 +5,15 @@\n import numpy.core.umath as ncu\n restore_path()\n \n+class test_log1p(ScipyTestCase):\n+ def check_log1p(self):\n+ assert_almost_equal(ncu.log1p(0.2), ncu.log(1.2))\n+ assert_almost_equal(ncu.log1p(1e-6), ncu.log(1+1e-6))\n+\n+class test_expm1(ScipyTestCase):\n+ def check_expm1(self):\n+ assert_almost_equal(ncu.expm1(0.2), ncu.exp(0.2)-1)\n+ assert_almost_equal(ncu.expm1(1e-6), ncu.exp(1e-6)-1)\n \n class test_maximum(ScipyTestCase):\n def check_reduce_complex(self):\n", + "added_lines": 9, + "deleted_lines": 0, + "source_code": "\nfrom numpy.testing import *\nset_package_path()\nfrom numpy.core.umath import minimum, maximum\nimport numpy.core.umath as ncu\nrestore_path()\n\nclass test_log1p(ScipyTestCase):\n def check_log1p(self):\n assert_almost_equal(ncu.log1p(0.2), ncu.log(1.2))\n assert_almost_equal(ncu.log1p(1e-6), ncu.log(1+1e-6))\n\nclass test_expm1(ScipyTestCase):\n def check_expm1(self):\n assert_almost_equal(ncu.expm1(0.2), ncu.exp(0.2)-1)\n assert_almost_equal(ncu.expm1(1e-6), ncu.exp(1e-6)-1)\n\nclass test_maximum(ScipyTestCase):\n def check_reduce_complex(self):\n assert_equal(maximum.reduce([1,2j]),1)\n assert_equal(maximum.reduce([1+3j,2j]),1+3j)\n\nclass test_minimum(ScipyTestCase):\n def check_reduce_complex(self):\n assert_equal(minimum.reduce([1,2j]),2j)\n\nclass test_floating_point(ScipyTestCase):\n def check_floating_point(self):\n assert_equal(ncu.FLOATING_POINT_SUPPORT, 1)\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", + "source_code_before": "\nfrom numpy.testing import *\nset_package_path()\nfrom numpy.core.umath import minimum, maximum\nimport numpy.core.umath as ncu\nrestore_path()\n\n\nclass test_maximum(ScipyTestCase):\n def check_reduce_complex(self):\n assert_equal(maximum.reduce([1,2j]),1)\n assert_equal(maximum.reduce([1+3j,2j]),1+3j)\n\nclass test_minimum(ScipyTestCase):\n def check_reduce_complex(self):\n assert_equal(minimum.reduce([1,2j]),2j)\n\nclass test_floating_point(ScipyTestCase):\n def check_floating_point(self):\n assert_equal(ncu.FLOATING_POINT_SUPPORT, 1)\n\nif __name__ == \"__main__\":\n ScipyTest().run()\n", + "methods": [ + { + "name": "check_log1p", + "long_name": "check_log1p( self )", + "filename": "test_umath.py", + "nloc": 3, + "complexity": 1, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 9, + "end_line": 11, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_expm1", + "long_name": "check_expm1( self )", + "filename": "test_umath.py", + "nloc": 3, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 14, + "end_line": 16, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_reduce_complex", + "long_name": "check_reduce_complex( self )", + "filename": "test_umath.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_reduce_complex", + "long_name": "check_reduce_complex( self )", + "filename": "test_umath.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 24, + "end_line": 25, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_floating_point", + "long_name": "check_floating_point( self )", + "filename": "test_umath.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 28, + "end_line": 29, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "check_reduce_complex", + "long_name": "check_reduce_complex( self )", + "filename": "test_umath.py", + "nloc": 3, + "complexity": 1, + "token_count": 39, + "parameters": [ + "self" + ], + "start_line": 10, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_reduce_complex", + "long_name": "check_reduce_complex( self )", + "filename": "test_umath.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 15, + "end_line": 16, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_floating_point", + "long_name": "check_floating_point( self )", + "filename": "test_umath.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 20, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "check_expm1", + "long_name": "check_expm1( self )", + "filename": "test_umath.py", + "nloc": 3, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 14, + "end_line": 16, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_log1p", + "long_name": "check_log1p( self )", + "filename": "test_umath.py", + "nloc": 3, + "complexity": 1, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 9, + "end_line": 11, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + } + ], + "nloc": 25, + "complexity": 5, + "token_count": 245, + "diff_parsed": { + "added": [ + "class test_log1p(ScipyTestCase):", + " def check_log1p(self):", + " assert_almost_equal(ncu.log1p(0.2), ncu.log(1.2))", + " assert_almost_equal(ncu.log1p(1e-6), ncu.log(1+1e-6))", + "", + "class test_expm1(ScipyTestCase):", + " def check_expm1(self):", + " assert_almost_equal(ncu.expm1(0.2), ncu.exp(0.2)-1)", + " assert_almost_equal(ncu.expm1(1e-6), ncu.exp(1e-6)-1)" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "470bc4b47535a4749037661881aad82a44b1fd9b", + "msg": "Fix the complex version of expm1", + "author": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "committer": { + "name": "cookedm", + "email": "cookedm@localhost" + }, + "author_date": "2006-01-12T03:08:22+00:00", + "author_timezone": 0, + "committer_date": "2006-01-12T03:08:22+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "a41d567109efa6c887b972da0b20b50f096cd279" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 2, + "insertions": 2, + "lines": 4, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "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": "@@ -498,8 +498,8 @@ nc_exp@c@(c@typ@ *x, c@typ@ *r)\n static void\n nc_expm1@c@(c@typ@ *x, c@typ@ *r)\n {\n-\t@typ@ a = exp@c@(x->real-1);\n-\tr->real = a*cos@c@(x->imag);\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", + "added_lines": 2, + "deleted_lines": 2, + "source_code": "/* -*- c -*- */\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#define _UMATHMODULE\n#include \"numpy/ufuncobject.h\"\n#include \"abstract.h\"\n#include \n\n\n/* A whole slew of basic math functions are provided originally 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#ifndef HAVE_LOG1P\nstatic double 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#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#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\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\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\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\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\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\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\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\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n#else\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\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\ndouble 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\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\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 log1p, expm1\n*/\n\n/**begin repeat\n\n#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan,log1p,expm1)*2#\n#typ=longdouble*18, float*18#\n#c=l*18,f*18#\n#TYPE=LONGDOUBLE*18, FLOAT*18#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\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@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@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\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\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@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\t}\n\telse if (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n\t}\n\telse {\n\t\tnc_log@c@(a, r);\n\t\tnc_prod@c@(r, b, r);\n\t\tnc_exp@c@(r, r);\n\t}\n\treturn;\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; i> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n\t/* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>32) || (y>>32) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>64) || (y>>64) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n\treturn 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n\tulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n\tif (a0 < 0) { a = -a0; } else { a = a0; }\n\tif (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n\tah = (a >> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n /*\n\t ulonglong c = ((x + y)<<32) + w;\n\t if ((a0 < 0) ^ (b0 < 0))\n\t *c = -c;\n\t else\n\t *c = c\n\t */\n\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>31) || (y>>31) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>63) || (y>>63) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n\treturn 0;\n#endif\n}\n\n/** end direct numarray code **/\n\nstatic void\nBOOL_multiply(char **args, intp *dimensions, intp *steps, void *func) {\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 MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nULONGLONG_multiply(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\tulonglong temp;\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\telse if (temp < MIN_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nLONGLONG_multiply(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\tlonglong temp;\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=fmod*10, 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\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\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 memcpy(op, i1, sizeof(@typ@));\n else\n memcpy(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\n/* A whole slew of basic math functions are provided originally 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#ifndef HAVE_LOG1P\nstatic double 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#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#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\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\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\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\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\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\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\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\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n#else\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\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\ndouble 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\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\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 log1p, expm1\n*/\n\n/**begin repeat\n\n#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan,log1p,expm1)*2#\n#typ=longdouble*18, float*18#\n#c=l*18,f*18#\n#TYPE=LONGDOUBLE*18, FLOAT*18#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\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@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@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\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\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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-1);\n\tr->real = a*cos@c@(x->imag);\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\t@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\t}\n\telse if (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n\t}\n\telse {\n\t\tnc_log@c@(a, r);\n\t\tnc_prod@c@(r, b, r);\n\t\tnc_exp@c@(r, r);\n\t}\n\treturn;\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; i> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n\t/* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>32) || (y>>32) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>64) || (y>>64) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n\treturn 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n\tulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n\tif (a0 < 0) { a = -a0; } else { a = a0; }\n\tif (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n\tah = (a >> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n /*\n\t ulonglong c = ((x + y)<<32) + w;\n\t if ((a0 < 0) ^ (b0 < 0))\n\t *c = -c;\n\t else\n\t *c = c\n\t */\n\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>31) || (y>>31) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>63) || (y>>63) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n\treturn 0;\n#endif\n}\n\n/** end direct numarray code **/\n\nstatic void\nBOOL_multiply(char **args, intp *dimensions, intp *steps, void *func) {\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 MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nULONGLONG_multiply(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\tulonglong temp;\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\telse if (temp < MIN_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nLONGLONG_multiply(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\tlonglong temp;\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=fmod*10, 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\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\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 memcpy(op, i1, sizeof(@typ@));\n else\n memcpy(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; ireal);", + "\tr->real = a*cos@c@(x->imag) - 1.0;" + ], + "deleted": [ + "\t@typ@ a = exp@c@(x->real-1);", + "\tr->real = a*cos@c@(x->imag);" + ] + } + } + ] + }, + { + "hash": "ece9e80e8eb587ed11958403a34fb8b9de0fdb51", + "msg": "Fix segfault in constructor when dtype not given.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-12T14:30:37+00:00", + "author_timezone": 0, + "committer_date": "2006-01-12T14:30:37+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "470bc4b47535a4749037661881aad82a44b1fd9b" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 2, + "insertions": 7, + "lines": 9, + "files": 1, + "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": "@@ -3884,15 +3884,20 @@ array_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n &strides,\n &fortran)) \n \t\tgoto fail;\n-\t\n+\n+\n+\tif (descr == NULL)\n+\t\tdescr = PyArray_DescrFromType(PyArray_LONG);\n+\n \ttype_num = descr->type_num;\n-\titemsize = descr->elsize;\t\n+\titemsize = descr->elsize;\n \n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n+\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\\\n \t\t\tPyArray_NewFromDescr(subtype, descr,\n", + "added_lines": 7, + "deleted_lines": 2, + "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\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\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=NULL;\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\tdescr = PyArray_DescrFromType(PyArray_INTP);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else 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} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\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=NULL;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\tdescr = PyArray_DescrFromType(PyArray_INT);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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} else 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) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\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\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 if (PyBigArray_CheckExact(obj)) \n return PyArray_BIG_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\t\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\t\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\t\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\t\n dest_strides_ptr = dest_strides;\n\t\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\t\n new_data = (char *)_pya_malloc(stride);\n\t\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\t\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\t\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\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\nstatic PyArray_Descr **userdescrs=NULL;\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\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\t\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\n/* If destination is not the right type, then src \n will be cast to destination. \n*/\n\n/* Does a flat iterator-based copy. \n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however. \n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n \n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError, \n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->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, elsize);\n PyArray_INCREF(dest);\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 memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\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\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t dest->descr, 0,\n\t\t\t\t\t dest->nd, FORTRAN_IF(dest));\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\t\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/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\t\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\t\n return (PyObject *)ret;\t\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_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 (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}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize / sizeof(Py_UNICODE);\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\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, itemsize);\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/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\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\t\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\t\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 fwrite(sep, 1, n3, fp);\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\t\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\t\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\t\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\t\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\t\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\t\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \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\t\t\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\t\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\nstatic PyObject *\narray_item_nice(PyArrayObject *self, int i) \n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\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\t\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 SIZEOF_INT == SIZEOF_INTP\n#define array_ass_item array_ass_big_item\n#else\nstatic int\narray_ass_item(PyArrayObject *self, int 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\t\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\t\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\t\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\t\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\t\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\t\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\t\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);\t\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\t\n nd_old = nd_new = 0;\n\t\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\t\t\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 }\t \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\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\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);\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->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\t\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);\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}\n\t}\n\t\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, PyArray_ITEMSIZE(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}\t\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\t\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/* 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;\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\t\t\t\t\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\t\t\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\treturn PyArray_ToScalar(self->data, self);\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\treturn PyArray_ToScalar(self->data, self);\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n\t/* wrap arguments into a mapiter object */\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(op, oned);\n if (mit == NULL) return NULL;\n if (!mit->view) { /* fancy indexing */\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 Py_DECREF(mit);\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\t\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\t\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;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\t\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\t\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\t\t\t\t\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\t\t\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(index, oned);\n if (mit == NULL) return -1;\n if (!mit->view) {\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 Py_DECREF(mit);\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\t\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\treturn PyArray_Return((PyArrayObject *)array_subscript(self, op));\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n (inquiry)array_length,\t\t /*mp_length*/\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 \narray_getsegcount(PyArrayObject *self, int *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 \narray_getreadbuf(PyArrayObject *self, int 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 \narray_getwritebuf(PyArrayObject *self, int 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 \narray_getcharbuf(PyArrayObject *self, int 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 (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};\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\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;\t\n\t\n} NumericOps;\n\nstatic NumericOps n_ops = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL};\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\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);\t \n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\t\n SET(true_divide);\t\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\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;\t\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\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);\t \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\treturn dict;\t\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\t\t\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}\t\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}\t\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 *\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 PyObject *\narray_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.power);\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 *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.power);\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\t\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;\t \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 an \"\\\n\t\t\t\t\"int; 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;\t \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;\t \n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v) \n{\t \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;\t \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;\t \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*/\t\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 ilow, int ihigh) \n{\n PyArrayObject *r;\n int l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n \t\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\n self->dimensions[0] = l;\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 ilow, int ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\t\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\t\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\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, 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\n\nstatic PySequenceMethods array_as_sequence = {\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};\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\t\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\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\t\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\t\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\t\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\t\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\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\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 return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\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.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\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\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\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; ind == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tintp sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\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\t\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;\t\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by a single segment array of the provided \n dimensions and element size. If numbytes is 0 it will be calculated from \n the provided shape and element size.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\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;\t\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 */\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, \n\t\t\t intp *newstrides, int oldnd)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\t\n\told = *des;\n\t*des = old->subarray->base;\n\n\tmydim = newdims + oldnd;\n\tif (PyTuple_Check(old->subarray->shape)) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t\t\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tnumnew = 1;\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\t\n\tnewnd = oldnd + numnew;\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\t/* Make new strides */\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\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{\t\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\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);\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\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\t\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { /* strides is NULL too */\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\t\t\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\t\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 {\n\t\t\tif (data == NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"if 'strides' is given in \" \\\n\t\t\t\t\t\t\"array creation, data must \" \\\n\t\t\t\t\t\t\"be given too\");\n\t\t\t\tgoto fail;\n\t\t\t} \n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t} \t\n\t\t\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\t\tif (descr == &OBJECT_Descr) {\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 and some object passed in */\n\tif ((obj != NULL) && (subtype != &PyArray_Type) && \n\t (subtype != &PyBigArray_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 (!(self->flags & OWNDATA)) { /* did not allocate own data */\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\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\t\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*/\nstatic PyObject * \nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape)\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\t\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n \"resize only works on contiguous arrays\");\n return NULL;\n }\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\t\t\n\t\trefcnt = REFCOUNT(self);\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\t\t\t\t\n\t\tif (newsize == 0) sd = self->descr->elsize;\t\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 0, &(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);\t\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);\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\twhile (size--) {\n\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\ttoptr += itemsize;\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\t\t\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, itemsize);\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\", \n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", 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\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*/\t\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\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 &fortran)) \n\t\tgoto fail;\n\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 if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\\\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 NULL, 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\t\tbuffer.len -= offset;\n\t\tbuffer.ptr += offset;\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\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 (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\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 (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 PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\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\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\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;\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 != NULL) {\n\t\tif (PyArray_Check(new->base)) \n\t\t\tnew = (PyArrayObject *)new->base;\n\t}\n\tnumbytes = PyArray_MultiplyList(new->dimensions, \n\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes, \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 if (PyBigArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_BIG_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}\t\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 *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISEXTENDED(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->descr->elsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\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 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\t\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\t\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\t\n\telse if (newtype->elsize > self->descr->elsize) {\n\t\t\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\t\t\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\t\t\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\ttemp = (PyArrayObject *)\\\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\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tPy_DECREF(newtype);\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator */\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\ttemp->descr = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype; \n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\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\t\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"arrdescr\");\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_type_get(PyArrayObject *self)\n{\n Py_INCREF(self->descr->typeobj);\n return (PyObject *)self->descr->typeobj;\n}\n\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);\n\tif (new == NULL) return -1;\n\t\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) {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}\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{\t\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{\t\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); \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);\t\t\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));\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->descr->elsize);\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 {\"dtype\", \n\t (getter)array_type_get, \n\t NULL,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n\t{\"dtypedescr\", \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.dtypedescr object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\t\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.bigndarray\",\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 NULL, \t\t\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\t\t\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n NULL, \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/* A standard array will subclass from the Big Array and \n add the array_as_sequence table\n and the array_as_buffer table\n */\n\nstatic PyTypeObject PyArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n};\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\t\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;\t\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\t\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, sizeof(Py_UNICODE)*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\t\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, 2*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\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\t\n\tif (minitype == NULL) \n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\t\n if (max < 0) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\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 \t\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\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\t\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\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_BOOL);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_LONG);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_DOUBLE);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_CDOUBLE);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\n finish:\n\t\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\t\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\t\n l=PyObject_Length(v);\n if(l < 0) return -1; \n\t\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\t\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 *= sizeof(Py_UNICODE);\n\t}\n\n\tret = (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\n\tif (ret == NULL) return NULL;\n\n ret->descr->f->setitem(op, ret->data, ret);\n\t\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 unless return value is NULL*/\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\tPyArray_Descr *savetype=typecode;\n\t\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\t\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 return NULL;\n }\n\t\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 return NULL;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\treturn NULL;\n\t\t}\n\t\tif (type == PyArray_UNICODE) itemsize*=sizeof(Py_UNICODE);\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\t\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\t\n if(!r) {Py_XINCREF(savetype); return NULL;}\n if(Assign_Array(r,s) == -1) {\n\t\tPy_XINCREF(savetype);\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\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\t\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\t\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\t\t\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\t\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\t\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, elsize);\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\t\t\t\t\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\t\t\t\t\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 oelsize);\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);\t\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\t\t\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*sizeof(Py_UNICODE);\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize/sizeof(Py_UNICODE);\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\t\n\tPy_DECREF(out);\n\treturn NULL;\n\t\n}\n\t \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\t\t\t\t\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * outsize;\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\t\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 */\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) \n{\n\t\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\t\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 (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\t\t\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 != &PyBigArray_Type)) {\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 (subtype != &PyBigArray_Type)) {\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\t\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 != &PyBigArray_Type)) {\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\t\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}\t\t\n\t\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;\t \n\t\telse _MY_FAIL \n\t\t\tbreak;\t\t \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;\t\t \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;\t\t \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\t\tbreak;\n\tcase 'S':\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase 'U':\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize *= sizeof(Py_UNICODE);\n\t\tbreak;\t \n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\t\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/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_fromstructinterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r, *ret;\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_XDECREF(intype);\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_XDECREF(intype);\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 ret = array_fromarray((PyArrayObject*)r, intype, flags);\n Py_DECREF(r);\n return ret;\n}\n\n/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n PyObject *tstr=NULL, *shape=NULL; \n\tPyArrayObject *ret=NULL;\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\t\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\tPy_XDECREF(intype);\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\tPy_XDECREF(intype);\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\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n\n fail:\n\tPy_XDECREF(intype);\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* steals a reference to typecode */\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Descr *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode == NULL) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyObject *obj;\n\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", typecode->type,\n\t\t\t\t\t\t typecode->elsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(typecode->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\n if (new == NULL) {Py_XDECREF(typecode); 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\t\tPy_DECREF(typecode);\n return NULL;\n }\n r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n/* Steals a reference to newtype --- which can be NULL */\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Descr *newtype, int min_depth, \n\t\t int max_depth, int flags) \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 = array_fromarray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if ((r = array_fromstructinterface(op, newtype, flags)) != \\\n\t\t Py_NotImplemented) {\n }\n else if ((r = array_frominterface(op, newtype, flags)) !=\t\\\n\t\t Py_NotImplemented) {\n\t}\n else if (PyObject_HasAttrString(op, \"__array__\")) {\n /* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, newtype, flags);\n }\n\telse {\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\t\t\t\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 PyErr_Clear();\n else\n seq = TRUE;\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\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\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\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_FromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n\t\tint max_depth, int requires) \n{\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\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 array_fromobject(op, descr, min_depth, max_depth,\n \t\t\t\trequires);\t\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 or PyBigArray_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) || PyBigArray_CheckExact(op)) return op;\n \n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FROM_OF(op, ENSUREARRAY);\n Py_DECREF(op);\n return new;\n}\n\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 * sizeof(Py_UNICODE)\\\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.\t\t \n\t\t*/\n\t}\n\treturn ret;\n}\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\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\t\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\t\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\t\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/* 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\niter_length(PyArrayIterObject *self) \n{\n return (int) 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, itemsize);\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\t\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, itemsize);\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;\t\t\t\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */ \t\n\t\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, size);\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);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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\t\t\t\t\t FORCECAST | ALIGNED);\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,\n\t\t\t\t itemsize);\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, itemsize);\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, itemsize);\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\t\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\t\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0);\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, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\t\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, itemsize);\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, itemsize);\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);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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_FromAny(obj, indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\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\t\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n (inquiry)iter_length,\t\t /*mp_length*/\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;\t\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\t{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 0, /* 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/* 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/* 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);\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\t\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\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\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 sizeof(intp));\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\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\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 sizeof(intp));\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 sizeof(intp));\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\t\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\t \n\tif (mit->view) return;\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\n\tsub = PyObject_GetItem((PyObject *)arr, mit->indexobj);\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\t\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\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\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= 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) *indptr, (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);\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\t\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->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_IndexError,\t\t\t\\\n\t\t\t\t\"arrays used as indices must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_IndexError, \"too many indices\");\n\t\tgoto fail;\n\t}\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\t\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);\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 ret:\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\t\n\tint i, err=0;\n\t\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\t\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\t\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);\t\n\t\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\t\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\t\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\t\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\t\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\t\n return (PyObject *)multi;\n\t\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\t_pya_free(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);\t\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 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/*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;\t\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(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 dtypedescr objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"dtype\", 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\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\tchar basic_=self->kind;\n\tchar endian = self->byteorder;\n\t\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\t\n\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t self->elsize);\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{\"subdescr\", \n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"arrdescr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"dtypestr\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\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\t\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\t\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, \"dtypedescr\");\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\tobj = PyString_FromFormat(\"%c%d\",self->kind, self->elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\t\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\t\n\tif (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\t\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\t\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\t\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*/\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\t\t\t\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 dtypedescr 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 dtypedescr object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\t\t\t\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);\t\t\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(\"dtypedescr(\");\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 dtypedescr 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\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtypedescr\",\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 0, \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", + "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\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\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=NULL;\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\tdescr = PyArray_DescrFromType(PyArray_INTP);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else 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} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\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=NULL;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\tdescr = PyArray_DescrFromType(PyArray_INT);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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} else 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) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\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\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 if (PyBigArray_CheckExact(obj)) \n return PyArray_BIG_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\t\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\t\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\t\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\t\n dest_strides_ptr = dest_strides;\n\t\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\t\n new_data = (char *)_pya_malloc(stride);\n\t\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\t\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\t\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\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\nstatic PyArray_Descr **userdescrs=NULL;\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\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\t\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\n/* If destination is not the right type, then src \n will be cast to destination. \n*/\n\n/* Does a flat iterator-based copy. \n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however. \n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n \n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError, \n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->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, elsize);\n PyArray_INCREF(dest);\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 memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\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\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t dest->descr, 0,\n\t\t\t\t\t dest->nd, FORTRAN_IF(dest));\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\t\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/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\t\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\t\n return (PyObject *)ret;\t\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_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 (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}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize / sizeof(Py_UNICODE);\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\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, itemsize);\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/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\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\t\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\t\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 fwrite(sep, 1, n3, fp);\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\t\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\t\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\t\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\t\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\t\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\t\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \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\t\t\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\t\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\nstatic PyObject *\narray_item_nice(PyArrayObject *self, int i) \n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\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\t\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 SIZEOF_INT == SIZEOF_INTP\n#define array_ass_item array_ass_big_item\n#else\nstatic int\narray_ass_item(PyArrayObject *self, int 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\t\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\t\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\t\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\t\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\t\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\t\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\t\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);\t\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\t\n nd_old = nd_new = 0;\n\t\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\t\t\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 }\t \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\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\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);\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->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\t\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);\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}\n\t}\n\t\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, PyArray_ITEMSIZE(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}\t\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\t\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/* 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;\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\t\t\t\t\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\t\t\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\treturn PyArray_ToScalar(self->data, self);\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\treturn PyArray_ToScalar(self->data, self);\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n\t/* wrap arguments into a mapiter object */\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(op, oned);\n if (mit == NULL) return NULL;\n if (!mit->view) { /* fancy indexing */\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 Py_DECREF(mit);\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\t\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\t\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;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\t\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\t\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\t\t\t\t\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\t\t\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(index, oned);\n if (mit == NULL) return -1;\n if (!mit->view) {\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 Py_DECREF(mit);\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\t\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\treturn PyArray_Return((PyArrayObject *)array_subscript(self, op));\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n (inquiry)array_length,\t\t /*mp_length*/\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 \narray_getsegcount(PyArrayObject *self, int *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 \narray_getreadbuf(PyArrayObject *self, int 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 \narray_getwritebuf(PyArrayObject *self, int 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 \narray_getcharbuf(PyArrayObject *self, int 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 (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};\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\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;\t\n\t\n} NumericOps;\n\nstatic NumericOps n_ops = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL};\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\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);\t \n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\t\n SET(true_divide);\t\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\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;\t\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\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);\t \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\treturn dict;\t\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\t\t\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}\t\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}\t\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 *\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 PyObject *\narray_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.power);\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 *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.power);\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\t\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;\t \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 an \"\\\n\t\t\t\t\"int; 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;\t \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;\t \n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v) \n{\t \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;\t \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;\t \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*/\t\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 ilow, int ihigh) \n{\n PyArrayObject *r;\n int l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n \t\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\n self->dimensions[0] = l;\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 ilow, int ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\t\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\t\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\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, 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\n\nstatic PySequenceMethods array_as_sequence = {\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};\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\t\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\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\t\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\t\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\t\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\t\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\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\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 return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\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.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\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\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\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; ind == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tintp sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\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\t\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;\t\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by a single segment array of the provided \n dimensions and element size. If numbytes is 0 it will be calculated from \n the provided shape and element size.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\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;\t\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 */\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, \n\t\t\t intp *newstrides, int oldnd)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\t\n\told = *des;\n\t*des = old->subarray->base;\n\n\tmydim = newdims + oldnd;\n\tif (PyTuple_Check(old->subarray->shape)) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t\t\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tnumnew = 1;\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\t\n\tnewnd = oldnd + numnew;\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\t/* Make new strides */\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\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{\t\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\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);\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\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\t\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { /* strides is NULL too */\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\t\t\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\t\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 {\n\t\t\tif (data == NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"if 'strides' is given in \" \\\n\t\t\t\t\t\t\"array creation, data must \" \\\n\t\t\t\t\t\t\"be given too\");\n\t\t\t\tgoto fail;\n\t\t\t} \n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t} \t\n\t\t\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\t\tif (descr == &OBJECT_Descr) {\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 and some object passed in */\n\tif ((obj != NULL) && (subtype != &PyArray_Type) && \n\t (subtype != &PyBigArray_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 (!(self->flags & OWNDATA)) { /* did not allocate own data */\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\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\t\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*/\nstatic PyObject * \nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape)\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\t\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n \"resize only works on contiguous arrays\");\n return NULL;\n }\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\t\t\n\t\trefcnt = REFCOUNT(self);\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\t\t\t\t\n\t\tif (newsize == 0) sd = self->descr->elsize;\t\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 0, &(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);\t\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);\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\twhile (size--) {\n\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\ttoptr += itemsize;\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\t\t\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, itemsize);\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\", \n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", 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\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*/\t\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\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 &fortran)) \n\t\tgoto fail;\n\t\n\ttype_num = descr->type_num;\n\titemsize = descr->elsize;\t\n\n if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\\\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 NULL, 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\t\tbuffer.len -= offset;\n\t\tbuffer.ptr += offset;\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\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 (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\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 (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 PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\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\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\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;\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 != NULL) {\n\t\tif (PyArray_Check(new->base)) \n\t\t\tnew = (PyArrayObject *)new->base;\n\t}\n\tnumbytes = PyArray_MultiplyList(new->dimensions, \n\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes, \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 if (PyBigArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_BIG_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}\t\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 *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISEXTENDED(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->descr->elsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\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 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\t\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\t\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\t\n\telse if (newtype->elsize > self->descr->elsize) {\n\t\t\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\t\t\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\t\t\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\ttemp = (PyArrayObject *)\\\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\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tPy_DECREF(newtype);\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator */\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\ttemp->descr = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype; \n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\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\t\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"arrdescr\");\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_type_get(PyArrayObject *self)\n{\n Py_INCREF(self->descr->typeobj);\n return (PyObject *)self->descr->typeobj;\n}\n\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);\n\tif (new == NULL) return -1;\n\t\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) {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}\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{\t\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{\t\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); \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);\t\t\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));\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->descr->elsize);\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 {\"dtype\", \n\t (getter)array_type_get, \n\t NULL,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n\t{\"dtypedescr\", \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.dtypedescr object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\t\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.bigndarray\",\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 NULL, \t\t\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\t\t\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n NULL, \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/* A standard array will subclass from the Big Array and \n add the array_as_sequence table\n and the array_as_buffer table\n */\n\nstatic PyTypeObject PyArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n};\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\t\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;\t\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\t\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, sizeof(Py_UNICODE)*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\t\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, 2*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\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\t\n\tif (minitype == NULL) \n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\t\n if (max < 0) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\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 \t\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\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\t\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\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_BOOL);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_LONG);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_DOUBLE);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_CDOUBLE);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\n finish:\n\t\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\t\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\t\n l=PyObject_Length(v);\n if(l < 0) return -1; \n\t\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\t\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 *= sizeof(Py_UNICODE);\n\t}\n\n\tret = (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\n\tif (ret == NULL) return NULL;\n\n ret->descr->f->setitem(op, ret->data, ret);\n\t\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 unless return value is NULL*/\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\tPyArray_Descr *savetype=typecode;\n\t\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\t\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 return NULL;\n }\n\t\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 return NULL;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\treturn NULL;\n\t\t}\n\t\tif (type == PyArray_UNICODE) itemsize*=sizeof(Py_UNICODE);\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\t\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\t\n if(!r) {Py_XINCREF(savetype); return NULL;}\n if(Assign_Array(r,s) == -1) {\n\t\tPy_XINCREF(savetype);\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\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\t\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\t\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\t\t\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\t\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\t\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, elsize);\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\t\t\t\t\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\t\t\t\t\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 oelsize);\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);\t\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\t\t\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*sizeof(Py_UNICODE);\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize/sizeof(Py_UNICODE);\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\t\n\tPy_DECREF(out);\n\treturn NULL;\n\t\n}\n\t \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\t\t\t\t\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * outsize;\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\t\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 */\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) \n{\n\t\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\t\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 (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\t\t\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 != &PyBigArray_Type)) {\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 (subtype != &PyBigArray_Type)) {\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\t\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 != &PyBigArray_Type)) {\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\t\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}\t\t\n\t\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;\t \n\t\telse _MY_FAIL \n\t\t\tbreak;\t\t \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;\t\t \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;\t\t \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\t\tbreak;\n\tcase 'S':\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase 'U':\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize *= sizeof(Py_UNICODE);\n\t\tbreak;\t \n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\t\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/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_fromstructinterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r, *ret;\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_XDECREF(intype);\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_XDECREF(intype);\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 ret = array_fromarray((PyArrayObject*)r, intype, flags);\n Py_DECREF(r);\n return ret;\n}\n\n/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n PyObject *tstr=NULL, *shape=NULL; \n\tPyArrayObject *ret=NULL;\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\t\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\tPy_XDECREF(intype);\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\tPy_XDECREF(intype);\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\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n\n fail:\n\tPy_XDECREF(intype);\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* steals a reference to typecode */\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Descr *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode == NULL) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyObject *obj;\n\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", typecode->type,\n\t\t\t\t\t\t typecode->elsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(typecode->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\n if (new == NULL) {Py_XDECREF(typecode); 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\t\tPy_DECREF(typecode);\n return NULL;\n }\n r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n/* Steals a reference to newtype --- which can be NULL */\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Descr *newtype, int min_depth, \n\t\t int max_depth, int flags) \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 = array_fromarray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if ((r = array_fromstructinterface(op, newtype, flags)) != \\\n\t\t Py_NotImplemented) {\n }\n else if ((r = array_frominterface(op, newtype, flags)) !=\t\\\n\t\t Py_NotImplemented) {\n\t}\n else if (PyObject_HasAttrString(op, \"__array__\")) {\n /* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, newtype, flags);\n }\n\telse {\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\t\t\t\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 PyErr_Clear();\n else\n seq = TRUE;\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\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\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\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_FromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n\t\tint max_depth, int requires) \n{\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\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 array_fromobject(op, descr, min_depth, max_depth,\n \t\t\t\trequires);\t\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 or PyBigArray_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) || PyBigArray_CheckExact(op)) return op;\n \n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FROM_OF(op, ENSUREARRAY);\n Py_DECREF(op);\n return new;\n}\n\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 * sizeof(Py_UNICODE)\\\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.\t\t \n\t\t*/\n\t}\n\treturn ret;\n}\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\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\t\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\t\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\t\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/* 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\niter_length(PyArrayIterObject *self) \n{\n return (int) 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, itemsize);\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\t\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, itemsize);\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;\t\t\t\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */ \t\n\t\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, size);\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);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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\t\t\t\t\t FORCECAST | ALIGNED);\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,\n\t\t\t\t itemsize);\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, itemsize);\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, itemsize);\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\t\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\t\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0);\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, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\t\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, itemsize);\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, itemsize);\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);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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_FromAny(obj, indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\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\t\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n (inquiry)iter_length,\t\t /*mp_length*/\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;\t\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\t{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 0, /* 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/* 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/* 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);\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\t\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\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\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 sizeof(intp));\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\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\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 sizeof(intp));\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 sizeof(intp));\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\t\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\t \n\tif (mit->view) return;\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\n\tsub = PyObject_GetItem((PyObject *)arr, mit->indexobj);\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\t\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\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\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= 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) *indptr, (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);\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\t\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->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_IndexError,\t\t\t\\\n\t\t\t\t\"arrays used as indices must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_IndexError, \"too many indices\");\n\t\tgoto fail;\n\t}\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\t\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);\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 ret:\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\t\n\tint i, err=0;\n\t\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\t\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\t\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);\t\n\t\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\t\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\t\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\t\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\t\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\t\n return (PyObject *)multi;\n\t\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\t_pya_free(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);\t\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 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/*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;\t\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(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 dtypedescr objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"dtype\", 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\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\tchar basic_=self->kind;\n\tchar endian = self->byteorder;\n\t\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\t\n\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t self->elsize);\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{\"subdescr\", \n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"arrdescr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"dtypestr\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\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\t\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\t\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, \"dtypedescr\");\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\tobj = PyString_FromFormat(\"%c%d\",self->kind, self->elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\t\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\t\n\tif (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\t\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\t\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\t\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*/\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\t\t\t\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 dtypedescr 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 dtypedescr object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\t\t\t\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);\t\t\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(\"dtypedescr(\");\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 dtypedescr 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\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtypedescr\",\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 0, \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", + "methods": [ + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 19, + "token_count": 391, + "parameters": [ + "o" + ], + "start_line": 31, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 59, + "complexity": 19, + "token_count": 394, + "parameters": [ + "o" + ], + "start_line": 103, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 86, + "parameters": [ + "obj", + "default_" + ], + "start_line": 173, + "end_line": 191, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "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": 212, + "end_line": 240, + "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": 246, + "end_line": 275, + "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": 281, + "end_line": 331, + "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": 354, + "end_line": 385, + "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": 388, + "end_line": 422, + "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": 438, + "end_line": 460, + "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": 466, + "end_line": 487, + "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": 491, + "end_line": 529, + "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": 534, + "end_line": 554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "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": 562, + "end_line": 577, + "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": 583, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 607, + "end_line": 687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "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": 79, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 691, + "end_line": 705, + "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": 718, + "end_line": 744, + "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": 750, + "end_line": 764, + "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 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 772, + "end_line": 792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 11, + "token_count": 468, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 801, + "end_line": 883, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 899, + "end_line": 902, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 912, + "end_line": 934, + "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": 948, + "end_line": 988, + "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": 1003, + "end_line": 1044, + "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": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1051, + "end_line": 1142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "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": 1148, + "end_line": 1177, + "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": 1180, + "end_line": 1216, + "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": 1225, + "end_line": 1262, + "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": 1269, + "end_line": 1277, + "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": 1280, + "end_line": 1305, + "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 i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1308, + "end_line": 1311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 1315, + "end_line": 1350, + "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 i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1356, + "end_line": 1359, + "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": 1365, + "end_line": 1373, + "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": 1379, + "end_line": 1429, + "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": 1436, + "end_line": 1481, + "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": 1485, + "end_line": 1579, + "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": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1582, + "end_line": 1619, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1631, + "end_line": 1684, + "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": 53, + "complexity": 12, + "token_count": 380, + "parameters": [ + "mit", + "op" + ], + "start_line": 1687, + "end_line": 1747, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "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": 1750, + "end_line": 1777, + "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": 1780, + "end_line": 1799, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 28, + "token_count": 659, + "parameters": [ + "self", + "op" + ], + "start_line": 1823, + "end_line": 1938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 91, + "complexity": 28, + "token_count": 581, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 1953, + "end_line": 2055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2064, + "end_line": 2067, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , int * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2086, + "end_line": 2098, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2101, + "end_line": 2116, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2120, + "end_line": 2129, + "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 segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2132, + "end_line": 2143, + "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": 34, + "complexity": 1, + "token_count": 162, + "parameters": [ + "dict" + ], + "start_line": 2214, + "end_line": 2247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 2, + "token_count": 183, + "parameters": [], + "start_line": 2257, + "end_line": 2296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "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": 2299, + "end_line": 2322, + "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": 2326, + "end_line": 2349, + "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": 2353, + "end_line": 2360, + "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": 2363, + "end_line": 2370, + "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": 2373, + "end_line": 2381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 2384, + "end_line": 2387, + "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": 2390, + "end_line": 2393, + "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": 2396, + "end_line": 2399, + "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": 2402, + "end_line": 2405, + "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": 2408, + "end_line": 2411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2414, + "end_line": 2417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2420, + "end_line": 2423, + "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": 2426, + "end_line": 2429, + "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": 2432, + "end_line": 2435, + "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": 2438, + "end_line": 2441, + "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": 2444, + "end_line": 2447, + "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": 2450, + "end_line": 2453, + "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": 2456, + "end_line": 2459, + "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": 2462, + "end_line": 2465, + "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": 2468, + "end_line": 2471, + "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": 2474, + "end_line": 2477, + "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": 2480, + "end_line": 2483, + "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": 2486, + "end_line": 2489, + "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": 2492, + "end_line": 2495, + "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 * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2498, + "end_line": 2501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2504, + "end_line": 2507, + "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": 2510, + "end_line": 2513, + "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": 2516, + "end_line": 2519, + "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": 2522, + "end_line": 2525, + "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": 2528, + "end_line": 2531, + "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": 2534, + "end_line": 2537, + "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": 2540, + "end_line": 2543, + "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": 2546, + "end_line": 2550, + "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": 2553, + "end_line": 2557, + "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": 2561, + "end_line": 2579, + "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": 2582, + "end_line": 2599, + "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": 2604, + "end_line": 2619, + "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": 2623, + "end_line": 2649, + "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": 2652, + "end_line": 2677, + "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": 2680, + "end_line": 2702, + "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": 2705, + "end_line": 2727, + "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": 2730, + "end_line": 2752, + "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": 2755, + "end_line": 2759, + "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 ilow , int ihigh)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 11, + "token_count": 259, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 2820, + "end_line": 2860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , int ilow , int ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 2864, + "end_line": 2885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 2888, + "end_line": 2900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 2921, + "end_line": 2968, + "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": 2971, + "end_line": 3007, + "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": 3016, + "end_line": 3033, + "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": 3036, + "end_line": 3048, + "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": 3051, + "end_line": 3063, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_richcompare", + "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 13, + "token_count": 273, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3066, + "end_line": 3143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 164, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3146, + "end_line": 3175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 3181, + "end_line": 3201, + "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": 21, + "complexity": 7, + "token_count": 161, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3209, + "end_line": 3232, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 111, + "parameters": [ + "ap" + ], + "start_line": 3238, + "end_line": 3254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 109, + "parameters": [ + "ap" + ], + "start_line": 3258, + "end_line": 3274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 3277, + "end_line": 3294, + "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": 3297, + "end_line": 3330, + "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": 3337, + "end_line": 3364, + "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 * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 84, + "parameters": [ + "elsize", + "nd", + "numbytes", + "dims", + "newstrides" + ], + "start_line": 3373, + "end_line": 3388, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 3408, + "end_line": 3432, + "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": 3438, + "end_line": 3460, + "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)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 6, + "token_count": 229, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd" + ], + "start_line": 3464, + "end_line": 3506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 130, + "complexity": 26, + "token_count": 761, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3514, + "end_line": 3672, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 159, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", + "filename": "arrayobject.c", + "nloc": 82, + "complexity": 15, + "token_count": 497, + "parameters": [ + "self", + "newshape" + ], + "start_line": 3681, + "end_line": 3779, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "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": 3785, + "end_line": 3802, + "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": 41, + "complexity": 6, + "token_count": 229, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3806, + "end_line": 3848, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 19, + "token_count": 583, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 3851, + "end_line": 3970, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "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": 3974, + "end_line": 3982, + "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": 3988, + "end_line": 3991, + "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": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 3994, + "end_line": 3998, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 4001, + "end_line": 4004, + "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": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4008, + "end_line": 4037, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 4041, + "end_line": 4044, + "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": 36, + "complexity": 7, + "token_count": 231, + "parameters": [ + "self", + "obj" + ], + "start_line": 4047, + "end_line": 4085, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "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": 4089, + "end_line": 4096, + "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": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 4099, + "end_line": 4107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 4111, + "end_line": 4117, + "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": 4120, + "end_line": 4134, + "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": 4137, + "end_line": 4181, + "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": 4185, + "end_line": 4188, + "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": 4191, + "end_line": 4202, + "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": 4205, + "end_line": 4216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typechar_get", + "long_name": "array_typechar_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 4220, + "end_line": 4227, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 4232, + "end_line": 4235, + "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": 4238, + "end_line": 4242, + "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": 15, + "token_count": 443, + "parameters": [ + "self", + "arg" + ], + "start_line": 4256, + "end_line": 4341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "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": 4344, + "end_line": 4362, + "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": 4365, + "end_line": 4383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_type_get", + "long_name": "array_type_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4386, + "end_line": 4390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 4395, + "end_line": 4405, + "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": 4409, + "end_line": 4434, + "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": 32, + "complexity": 4, + "token_count": 189, + "parameters": [ + "self", + "val" + ], + "start_line": 4438, + "end_line": 4471, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "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": 4474, + "end_line": 4507, + "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": 205, + "parameters": [ + "self", + "val" + ], + "start_line": 4510, + "end_line": 4547, + "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": 4550, + "end_line": 4553, + "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": 346, + "parameters": [ + "self", + "val" + ], + "start_line": 4556, + "end_line": 4606, + "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": 4708, + "end_line": 4715, + "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": 4817, + "end_line": 4850, + "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": 161, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 4853, + "end_line": 4875, + "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": 4882, + "end_line": 4908, + "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": 4914, + "end_line": 4946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 120, + "complexity": 31, + "token_count": 691, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 4958, + "end_line": 5094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 137, + "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": 5097, + "end_line": 5120, + "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": 23, + "complexity": 6, + "token_count": 146, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5125, + "end_line": 5153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 21, + "token_count": 367, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5158, + "end_line": 5222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "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": 5229, + "end_line": 5238, + "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": 5244, + "end_line": 5337, + "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": 280, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5347, + "end_line": 5393, + "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": 5403, + "end_line": 5456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_fromarray", + "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 32, + "token_count": 673, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5460, + "end_line": 5589, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 505, + "parameters": [ + "str" + ], + "start_line": 5593, + "end_line": 5701, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "array_fromstructinterface", + "long_name": "array_fromstructinterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 6, + "token_count": 274, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5705, + "end_line": 5749, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_frominterface", + "long_name": "array_frominterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 134, + "complexity": 28, + "token_count": 839, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5753, + "end_line": 5896, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 144, + "top_nesting_level": 0 + }, + { + "name": "array_fromattr", + "long_name": "array_fromattr( PyObject * op , PyArray_Descr * typecode , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 178, + "parameters": [ + "op", + "typecode", + "flags" + ], + "start_line": 5900, + "end_line": 5930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "array_fromobject", + "long_name": "array_fromobject( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 17, + "token_count": 330, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags" + ], + "start_line": 5934, + "end_line": 6010, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 77, + "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": 6015, + "end_line": 6018, + "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": 6025, + "end_line": 6038, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 8, + "token_count": 117, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires" + ], + "start_line": 6084, + "end_line": 6103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 81, + "parameters": [ + "op" + ], + "start_line": 6116, + "end_line": 6132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 6140, + "end_line": 6228, + "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": 134, + "parameters": [ + "from", + "to" + ], + "start_line": 6233, + "end_line": 6261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 6274, + "end_line": 6312, + "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": 6320, + "end_line": 6337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "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": 6342, + "end_line": 6352, + "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": 6355, + "end_line": 6359, + "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": 16, + "parameters": [ + "self" + ], + "start_line": 6362, + "end_line": 6365, + "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": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6369, + "end_line": 6419, + "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": 6422, + "end_line": 6476, + "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": 664, + "parameters": [ + "self", + "ind" + ], + "start_line": 6480, + "end_line": 6613, + "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": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6617, + "end_line": 6649, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "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": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6652, + "end_line": 6694, + "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": 692, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 6697, + "end_line": 6831, + "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": 6844, + "end_line": 6889, + "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": 6894, + "end_line": 6898, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 6970, + "end_line": 7032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 104, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7040, + "end_line": 7056, + "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": 7063, + "end_line": 7132, + "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": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7136, + "end_line": 7173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7179, + "end_line": 7223, + "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": 99, + "complexity": 22, + "token_count": 670, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7241, + "end_line": 7371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 460, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7377, + "end_line": 7450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned)", + "filename": "arrayobject.c", + "nloc": 112, + "complexity": 25, + "token_count": 758, + "parameters": [ + "indexobj", + "oned" + ], + "start_line": 7453, + "end_line": 7588, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "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": 7592, + "end_line": 7601, + "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": 231, + "parameters": [ + "n" + ], + "start_line": 7672, + "end_line": 7721, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "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": 265, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 7724, + "end_line": 7769, + "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": 7772, + "end_line": 7791, + "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": 41, + "parameters": [ + "multi" + ], + "start_line": 7794, + "end_line": 7801, + "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": 7804, + "end_line": 7814, + "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": 7817, + "end_line": 7827, + "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": 7830, + "end_line": 7833, + "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": 7836, + "end_line": 7848, + "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": 7878, + "end_line": 7885, + "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": 7944, + "end_line": 7953, + "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": 7971, + "end_line": 7993, + "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": 64, + "parameters": [ + "self" + ], + "start_line": 7999, + "end_line": 8009, + "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": 8027, + "end_line": 8035, + "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": 11, + "complexity": 3, + "token_count": 60, + "parameters": [ + "self" + ], + "start_line": 8038, + "end_line": 8050, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 8053, + "end_line": 8072, + "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": 8079, + "end_line": 8086, + "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": 8089, + "end_line": 8096, + "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": 8099, + "end_line": 8106, + "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": 8142, + "end_line": 8194, + "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": 50, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "args" + ], + "start_line": 8200, + "end_line": 8257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8265, + "end_line": 8307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 8327, + "end_line": 8393, + "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": 8404, + "end_line": 8412, + "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": 8427, + "end_line": 8472, + "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": 8475, + "end_line": 8484, + "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": 8487, + "end_line": 8497, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 19, + "token_count": 391, + "parameters": [ + "o" + ], + "start_line": 31, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 59, + "complexity": 19, + "token_count": 394, + "parameters": [ + "o" + ], + "start_line": 103, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 86, + "parameters": [ + "obj", + "default_" + ], + "start_line": 173, + "end_line": 191, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "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": 212, + "end_line": 240, + "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": 246, + "end_line": 275, + "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": 281, + "end_line": 331, + "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": 354, + "end_line": 385, + "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": 388, + "end_line": 422, + "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": 438, + "end_line": 460, + "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": 466, + "end_line": 487, + "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": 491, + "end_line": 529, + "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": 534, + "end_line": 554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "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": 562, + "end_line": 577, + "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": 583, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 607, + "end_line": 687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "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": 79, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 691, + "end_line": 705, + "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": 718, + "end_line": 744, + "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": 750, + "end_line": 764, + "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 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 772, + "end_line": 792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 11, + "token_count": 468, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 801, + "end_line": 883, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 899, + "end_line": 902, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 912, + "end_line": 934, + "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": 948, + "end_line": 988, + "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": 1003, + "end_line": 1044, + "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": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1051, + "end_line": 1142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "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": 1148, + "end_line": 1177, + "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": 1180, + "end_line": 1216, + "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": 1225, + "end_line": 1262, + "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": 1269, + "end_line": 1277, + "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": 1280, + "end_line": 1305, + "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 i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1308, + "end_line": 1311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 1315, + "end_line": 1350, + "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 i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1356, + "end_line": 1359, + "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": 1365, + "end_line": 1373, + "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": 1379, + "end_line": 1429, + "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": 1436, + "end_line": 1481, + "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": 1485, + "end_line": 1579, + "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": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1582, + "end_line": 1619, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1631, + "end_line": 1684, + "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": 53, + "complexity": 12, + "token_count": 380, + "parameters": [ + "mit", + "op" + ], + "start_line": 1687, + "end_line": 1747, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "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": 1750, + "end_line": 1777, + "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": 1780, + "end_line": 1799, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 28, + "token_count": 659, + "parameters": [ + "self", + "op" + ], + "start_line": 1823, + "end_line": 1938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 91, + "complexity": 28, + "token_count": 581, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 1953, + "end_line": 2055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2064, + "end_line": 2067, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , int * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2086, + "end_line": 2098, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2101, + "end_line": 2116, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2120, + "end_line": 2129, + "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 segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2132, + "end_line": 2143, + "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": 34, + "complexity": 1, + "token_count": 162, + "parameters": [ + "dict" + ], + "start_line": 2214, + "end_line": 2247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 2, + "token_count": 183, + "parameters": [], + "start_line": 2257, + "end_line": 2296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "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": 2299, + "end_line": 2322, + "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": 2326, + "end_line": 2349, + "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": 2353, + "end_line": 2360, + "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": 2363, + "end_line": 2370, + "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": 2373, + "end_line": 2381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 2384, + "end_line": 2387, + "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": 2390, + "end_line": 2393, + "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": 2396, + "end_line": 2399, + "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": 2402, + "end_line": 2405, + "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": 2408, + "end_line": 2411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2414, + "end_line": 2417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2420, + "end_line": 2423, + "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": 2426, + "end_line": 2429, + "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": 2432, + "end_line": 2435, + "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": 2438, + "end_line": 2441, + "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": 2444, + "end_line": 2447, + "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": 2450, + "end_line": 2453, + "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": 2456, + "end_line": 2459, + "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": 2462, + "end_line": 2465, + "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": 2468, + "end_line": 2471, + "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": 2474, + "end_line": 2477, + "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": 2480, + "end_line": 2483, + "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": 2486, + "end_line": 2489, + "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": 2492, + "end_line": 2495, + "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 * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2498, + "end_line": 2501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2504, + "end_line": 2507, + "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": 2510, + "end_line": 2513, + "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": 2516, + "end_line": 2519, + "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": 2522, + "end_line": 2525, + "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": 2528, + "end_line": 2531, + "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": 2534, + "end_line": 2537, + "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": 2540, + "end_line": 2543, + "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": 2546, + "end_line": 2550, + "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": 2553, + "end_line": 2557, + "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": 2561, + "end_line": 2579, + "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": 2582, + "end_line": 2599, + "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": 2604, + "end_line": 2619, + "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": 2623, + "end_line": 2649, + "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": 2652, + "end_line": 2677, + "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": 2680, + "end_line": 2702, + "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": 2705, + "end_line": 2727, + "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": 2730, + "end_line": 2752, + "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": 2755, + "end_line": 2759, + "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 ilow , int ihigh)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 11, + "token_count": 259, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 2820, + "end_line": 2860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , int ilow , int ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 2864, + "end_line": 2885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 2888, + "end_line": 2900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 2921, + "end_line": 2968, + "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": 2971, + "end_line": 3007, + "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": 3016, + "end_line": 3033, + "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": 3036, + "end_line": 3048, + "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": 3051, + "end_line": 3063, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_richcompare", + "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 13, + "token_count": 273, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3066, + "end_line": 3143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 164, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3146, + "end_line": 3175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 3181, + "end_line": 3201, + "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": 21, + "complexity": 7, + "token_count": 161, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3209, + "end_line": 3232, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 111, + "parameters": [ + "ap" + ], + "start_line": 3238, + "end_line": 3254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 109, + "parameters": [ + "ap" + ], + "start_line": 3258, + "end_line": 3274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 3277, + "end_line": 3294, + "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": 3297, + "end_line": 3330, + "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": 3337, + "end_line": 3364, + "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 * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 84, + "parameters": [ + "elsize", + "nd", + "numbytes", + "dims", + "newstrides" + ], + "start_line": 3373, + "end_line": 3388, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 3408, + "end_line": 3432, + "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": 3438, + "end_line": 3460, + "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)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 6, + "token_count": 229, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd" + ], + "start_line": 3464, + "end_line": 3506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 130, + "complexity": 26, + "token_count": 761, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3514, + "end_line": 3672, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 159, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", + "filename": "arrayobject.c", + "nloc": 82, + "complexity": 15, + "token_count": 497, + "parameters": [ + "self", + "newshape" + ], + "start_line": 3681, + "end_line": 3779, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "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": 3785, + "end_line": 3802, + "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": 41, + "complexity": 6, + "token_count": 229, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3806, + "end_line": 3848, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 18, + "token_count": 570, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 3851, + "end_line": 3965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 115, + "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": 3969, + "end_line": 3977, + "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": 3983, + "end_line": 3986, + "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": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 3989, + "end_line": 3993, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 3996, + "end_line": 3999, + "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": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4003, + "end_line": 4032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 4036, + "end_line": 4039, + "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": 36, + "complexity": 7, + "token_count": 231, + "parameters": [ + "self", + "obj" + ], + "start_line": 4042, + "end_line": 4080, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "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": 4084, + "end_line": 4091, + "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": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 4094, + "end_line": 4102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 4106, + "end_line": 4112, + "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": 4115, + "end_line": 4129, + "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": 4132, + "end_line": 4176, + "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": 4180, + "end_line": 4183, + "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": 4186, + "end_line": 4197, + "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": 4200, + "end_line": 4211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typechar_get", + "long_name": "array_typechar_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 4215, + "end_line": 4222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 4227, + "end_line": 4230, + "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": 4233, + "end_line": 4237, + "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": 15, + "token_count": 443, + "parameters": [ + "self", + "arg" + ], + "start_line": 4251, + "end_line": 4336, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "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": 4339, + "end_line": 4357, + "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": 4360, + "end_line": 4378, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_type_get", + "long_name": "array_type_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4381, + "end_line": 4385, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 4390, + "end_line": 4400, + "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": 4404, + "end_line": 4429, + "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": 32, + "complexity": 4, + "token_count": 189, + "parameters": [ + "self", + "val" + ], + "start_line": 4433, + "end_line": 4466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "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": 4469, + "end_line": 4502, + "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": 205, + "parameters": [ + "self", + "val" + ], + "start_line": 4505, + "end_line": 4542, + "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": 4545, + "end_line": 4548, + "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": 346, + "parameters": [ + "self", + "val" + ], + "start_line": 4551, + "end_line": 4601, + "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": 4703, + "end_line": 4710, + "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": 4812, + "end_line": 4845, + "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": 161, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 4848, + "end_line": 4870, + "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": 4877, + "end_line": 4903, + "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": 4909, + "end_line": 4941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 120, + "complexity": 31, + "token_count": 691, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 4953, + "end_line": 5089, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 137, + "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": 5092, + "end_line": 5115, + "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": 23, + "complexity": 6, + "token_count": 146, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5120, + "end_line": 5148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 21, + "token_count": 367, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5153, + "end_line": 5217, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "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": 5224, + "end_line": 5233, + "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": 5239, + "end_line": 5332, + "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": 280, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5342, + "end_line": 5388, + "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": 5398, + "end_line": 5451, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_fromarray", + "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 32, + "token_count": 673, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5455, + "end_line": 5584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 505, + "parameters": [ + "str" + ], + "start_line": 5588, + "end_line": 5696, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "array_fromstructinterface", + "long_name": "array_fromstructinterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 6, + "token_count": 274, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5700, + "end_line": 5744, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_frominterface", + "long_name": "array_frominterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 134, + "complexity": 28, + "token_count": 839, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5748, + "end_line": 5891, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 144, + "top_nesting_level": 0 + }, + { + "name": "array_fromattr", + "long_name": "array_fromattr( PyObject * op , PyArray_Descr * typecode , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 178, + "parameters": [ + "op", + "typecode", + "flags" + ], + "start_line": 5895, + "end_line": 5925, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "array_fromobject", + "long_name": "array_fromobject( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 17, + "token_count": 330, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags" + ], + "start_line": 5929, + "end_line": 6005, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 77, + "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": 6010, + "end_line": 6013, + "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": 6020, + "end_line": 6033, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 8, + "token_count": 117, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires" + ], + "start_line": 6079, + "end_line": 6098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 81, + "parameters": [ + "op" + ], + "start_line": 6111, + "end_line": 6127, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 6135, + "end_line": 6223, + "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": 134, + "parameters": [ + "from", + "to" + ], + "start_line": 6228, + "end_line": 6256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 6269, + "end_line": 6307, + "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": 6315, + "end_line": 6332, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "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": 6337, + "end_line": 6347, + "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": 6350, + "end_line": 6354, + "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": 16, + "parameters": [ + "self" + ], + "start_line": 6357, + "end_line": 6360, + "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": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6364, + "end_line": 6414, + "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": 6417, + "end_line": 6471, + "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": 664, + "parameters": [ + "self", + "ind" + ], + "start_line": 6475, + "end_line": 6608, + "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": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6612, + "end_line": 6644, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "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": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6647, + "end_line": 6689, + "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": 692, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 6692, + "end_line": 6826, + "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": 6839, + "end_line": 6884, + "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": 6889, + "end_line": 6893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 6965, + "end_line": 7027, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 104, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7035, + "end_line": 7051, + "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": 7058, + "end_line": 7127, + "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": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7131, + "end_line": 7168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7174, + "end_line": 7218, + "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": 99, + "complexity": 22, + "token_count": 670, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7236, + "end_line": 7366, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 460, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7372, + "end_line": 7445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned)", + "filename": "arrayobject.c", + "nloc": 112, + "complexity": 25, + "token_count": 758, + "parameters": [ + "indexobj", + "oned" + ], + "start_line": 7448, + "end_line": 7583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "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": 7587, + "end_line": 7596, + "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": 231, + "parameters": [ + "n" + ], + "start_line": 7667, + "end_line": 7716, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "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": 265, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 7719, + "end_line": 7764, + "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": 7767, + "end_line": 7786, + "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": 41, + "parameters": [ + "multi" + ], + "start_line": 7789, + "end_line": 7796, + "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": 7799, + "end_line": 7809, + "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": 7812, + "end_line": 7822, + "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": 7825, + "end_line": 7828, + "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": 7831, + "end_line": 7843, + "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": 7873, + "end_line": 7880, + "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": 7939, + "end_line": 7948, + "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": 7966, + "end_line": 7988, + "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": 64, + "parameters": [ + "self" + ], + "start_line": 7994, + "end_line": 8004, + "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": 8022, + "end_line": 8030, + "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": 11, + "complexity": 3, + "token_count": 60, + "parameters": [ + "self" + ], + "start_line": 8033, + "end_line": 8045, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 8048, + "end_line": 8067, + "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": 8074, + "end_line": 8081, + "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": 8084, + "end_line": 8091, + "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": 8094, + "end_line": 8101, + "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": 8137, + "end_line": 8189, + "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": 50, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "args" + ], + "start_line": 8195, + "end_line": 8252, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8260, + "end_line": 8302, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 8322, + "end_line": 8388, + "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": 8399, + "end_line": 8407, + "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": 8422, + "end_line": 8467, + "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": 8470, + "end_line": 8479, + "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": 8482, + "end_line": 8492, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 19, + "token_count": 583, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 3851, + "end_line": 3970, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + } + ], + "nloc": 6783, + "complexity": 1443, + "token_count": 39882, + "diff_parsed": { + "added": [ + "", + "", + "\tif (descr == NULL)", + "\t\tdescr = PyArray_DescrFromType(PyArray_LONG);", + "", + "\titemsize = descr->elsize;", + "" + ], + "deleted": [ + "", + "\titemsize = descr->elsize;" + ] + } + } + ] + }, + { + "hash": "071f111e8c14ac2286722fb147254aebd8ff98d3", + "msg": "Make (type, 1) case equivalent to type", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-12T21:23:07+00:00", + "author_timezone": 0, + "committer_date": "2006-01-12T21:23:07+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "ece9e80e8eb587ed11958403a34fb8b9de0fdb51" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 0, + "insertions": 5, + "lines": 5, + "files": 1, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/core/src/multiarraymodule.c", + "new_path": "numpy/core/src/multiarraymodule.c", + "filename": "multiarraymodule.c", + "extension": "c", + "change_type": "MODIFY", + "diff": "@@ -3375,6 +3375,11 @@ _convert_from_tuple(PyObject *obj)\n \t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n \t\t\tgoto fail;\n \t\t}\n+\t\t/* If (type, 1) was given, it is equivalent to type... */\n+\t\tif (shape.len == 1 && shape.ptr[0] == 1 && PyNumber_Check(val)) {\n+\t\t\tPyDimMem_FREE(shape.ptr);\n+\t\t\treturn type;\n+\t\t}\n \t\tnewdescr = PyArray_DescrNewFromType(PyArray_VOID);\n \t\tif (newdescr == NULL) {PyDimMem_FREE(shape.ptr); goto fail;}\n \t\tnewdescr->elsize = type->elsize;\n", + "added_lines": 5, + "deleted_lines": 0, + "source_code": "/*\n Python Multiarray Module -- A useful collection of functions for creating and\n using ndarrays\n\n Original file \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n Modified for numpy_core in 2005 \n\n Travis E. Oliphant\n Assistant Professor at\n Brigham Young University\n \n*/\n\n/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */\n\n#include \"Python.h\"\n#include \"structmember.h\"\n/*#include \n#include \n*/\n\n#define _MULTIARRAYMODULE\n#include \"numpy/arrayobject.h\"\n\n#define PyAO PyArrayObject\n\nstatic PyObject *typeDict=NULL; /* Must be explicitly loaded */\nstatic PyObject *_numpy_internal=NULL; /* A Python module for callbacks */\n\n\nstatic PyArray_Descr *\n_arraydescr_fromobj(PyObject *obj)\n{\n\tPyObject *dtypedescr;\n\tPyArray_Descr *new;\n\tint ret;\n\t\n\tdtypedescr = PyObject_GetAttrString(obj, \"dtypedescr\");\n\tPyErr_Clear();\n\tif (dtypedescr) {\n\t\tret = PyArray_DescrConverter(dtypedescr, &new);\n\t\tPy_DECREF(dtypedescr);\n\t\tif (ret) return new;\n\t\tPyErr_Clear();\n\t}\n\treturn NULL;\n}\n\n\n/* Including this file is the only way I know how to declare functions\n static in each file, and store the pointers from functions in both\n arrayobject.c and multiarraymodule.c for the C-API \n\n Declarying an external pointer-containing variable in arrayobject.c\n and trying to copy it to PyArray_API, did not work.\n\n Think about two modules with a common api that import each other...\n\n This file would just be the module calls. \n*/\n\n#include \"arrayobject.c\"\n\n\n/* An Error object -- rarely used? */\nstatic PyObject *MultiArrayError;\n\n/*MULTIARRAY_API\n Multiply a List of ints\n*/\nstatic int\nPyArray_MultiplyIntList(register int *l1, register int n) \n{\n\tregister int s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Multiply a List\n*/\nstatic intp \nPyArray_MultiplyList(register intp *l1, register int n) \n{\n\tregister intp s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Produce a pointer into array\n*/\nstatic char *\nPyArray_GetPtr(PyArrayObject *obj, register intp* ind)\n{\n\tregister int n = obj->nd;\n\tregister intp *strides = obj->strides;\n\tregister char *dptr = obj->data;\n\t\n\twhile (n--) dptr += (*strides++) * (*ind++);\n\treturn dptr;\n}\n\n/*MULTIARRAY_API\n Get axis from an object (possibly None) -- a converter function,\n*/\nstatic int \nPyArray_AxisConverter(PyObject *obj, int *axis)\n{\n\tif (obj == Py_None) {\n\t\t*axis = MAX_DIMS;\n\t}\n\telse {\n\t\t*axis = (int) PyInt_AsLong(obj);\n\t\tif (PyErr_Occurred()) {\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Compare Lists\n*/\nstatic int \nPyArray_CompareLists(intp *l1, intp *l2, int n) \n{\n int i;\n for(i=0;iob_type;\n\t\n\tPy_INCREF(self->descr);\n\tnew = PyArray_NewFromDescr(subtype,\n\t\t\t\t self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides,\n\t\t\t\t self->data,\n\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (new==NULL) return NULL;\n\tPy_INCREF(self);\n PyArray_BASE(new) = (PyObject *)self;\n\t\n\tif (type != NULL) {\n\t\tif (PyObject_SetAttrString(new, \"dtypedescr\", \n\t\t\t\t\t (PyObject *)type) < 0) {\n\t\t\tPy_DECREF(new);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tPy_DECREF(type);\n\t}\n\treturn new;\t\n}\n\n/*MULTIARRAY_API\n Ravel\n*/\nstatic PyObject *\nPyArray_Ravel(PyArrayObject *a, int fortran)\n{\n\tPyArray_Dims newdim = {NULL,1};\n\tintp val[1] = {-1};\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tnewdim.ptr = val;\n\tif (!fortran && PyArray_ISCONTIGUOUS(a)) {\n\t\tif (a->nd == 1) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\treturn PyArray_Newshape(a, &newdim);\n\t}\n\telse\n\t return PyArray_Flatten(a, fortran);\n}\n\n/*MULTIARRAY_API\n Flatten\n*/\nstatic PyObject *\nPyArray_Flatten(PyArrayObject *a, int fortran)\n{\n\tPyObject *ret, *new;\n\tintp size;\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tsize = PyArray_SIZE(a);\n\tPy_INCREF(a->descr);\n\tret = PyArray_NewFromDescr(a->ob_type,\n\t\t\t\t a->descr,\n\t\t\t\t 1, &size,\n\t\t\t\t NULL,\n\t\t\t\t NULL,\n\t\t\t\t 0, (PyObject *)a);\n\t\n\tif (ret== NULL) return NULL;\n\tif (fortran) {\n\t\tnew = PyArray_Transpose(a, NULL);\n\t\tif (new == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tPy_INCREF(a);\n\t\tnew = (PyObject *)a;\n\t}\n\tif (PyArray_CopyInto((PyArrayObject *)ret, (PyArrayObject *)new) < 0) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn NULL;\n\t}\n\tPy_DECREF(new);\n\treturn ret;\n}\n\n\n/* For back-ward compatability *\n\n/ * Not recommended */\n\n/*MULTIARRAY_API\n Reshape an array\n*/\nstatic PyObject *\nPyArray_Reshape(PyArrayObject *self, PyObject *shape) \n{\n PyObject *ret;\n PyArray_Dims newdims;\n\n if (!PyArray_IntpConverter(shape, &newdims)) return NULL;\n ret = PyArray_Newshape(self, &newdims);\n PyDimMem_FREE(newdims.ptr);\n return ret;\n}\n\nstatic int\n_check_ones(PyArrayObject *self, int newnd, intp* newdims, intp *strides)\n{\n\tint nd;\n\tintp *dims;\n\tBool done=FALSE;\n\tint j, k;\n\n\tnd = self->nd;\n\tdims = self->dimensions;\n\n\tfor (k=0, j=0; !done && (jstrides[j];\n\t\t\tj++; k++;\n\t\t}\n\t\telse if ((kptr;\n PyArrayObject *ret;\n\tchar msg[] = \"total size of new array must be unchanged\";\n\tint n = newdims->len;\n Bool same;\n\tintp *strides = NULL;\n\tintp newstrides[MAX_DIMS];\n\n /* Quick check to make sure anything needs to be done */\n if (n == self->nd) {\n same = TRUE;\n i=0;\n while(same && i= 0) {\n\t\t\tif ((s_known == 0) || (s_original % s_known != 0)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdimensions[i_unknown] = s_original/s_known;\n\t\t} else {\n\t\t\tif (s_original != s_known) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t}\n \n\tPy_INCREF(self->descr);\n\tret = (PyAO *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t self->descr,\n\t\t\t\t\t n, dimensions,\n\t\t\t\t\t strides,\n\t\t\t\t\t self->data,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (ret== NULL) return NULL;\n\t\n Py_INCREF(self);\n ret->base = (PyObject *)self;\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\n\t\n return (PyObject *)ret;\n}\n\n/* return a new view of the array object with all of its unit-length \n dimensions squeezed out if needed, otherwise\n return the same array.\n */\n\n/*MULTIARRAY_API*/\nstatic PyObject *\nPyArray_Squeeze(PyArrayObject *self)\n{\n\tint nd = self->nd;\n\tint newnd = nd;\n\tintp dimensions[MAX_DIMS];\n\tintp strides[MAX_DIMS];\n\tint i,j;\n\tPyObject *ret;\n\n\tif (nd == 0) {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\tfor (j=0, i=0; idimensions[i] == 1) {\n\t\t\tnewnd -= 1;\n\t\t}\n\t\telse {\n\t\t\tdimensions[j] = self->dimensions[i];\n\t\t\tstrides[j++] = self->strides[i];\n\t\t}\n\t}\n\t\n\tPy_INCREF(self->descr);\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t self->descr,\n\t\t\t\t newnd, dimensions, \n\t\t\t\t strides, self->data, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPyArray_FLAGS(ret) &= ~OWN_DATA;\n\tPyArray_BASE(ret) = (PyObject *)self;\n\tPy_INCREF(self);\n\treturn (PyObject *)ret;\n}\n\n\n/*MULTIARRAY_API\n Mean\n*/\nstatic PyObject *\nPyArray_Mean(PyArrayObject *self, int axis, int rtype)\n{\n\tPyObject *obj1=NULL, *obj2=NULL;\n\tPyObject *new, *ret;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\n\tobj1 = PyArray_GenericReduceFunction((PyAO *)new, n_ops.add, axis,\n\t\t\t\t\t rtype);\n\tobj2 = PyFloat_FromDouble((double) PyArray_DIM(new,axis));\n Py_DECREF(new);\n\tif (obj1 == NULL || obj2 == NULL) {\n\t\tPy_XDECREF(obj1);\n\t\tPy_XDECREF(obj2);\n\t\treturn NULL;\n\t}\n\n\tret = PyNumber_Divide(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n}\n\n/* Set variance to 1 to by-pass square-root calculation and return variance */\n/*MULTIARRAY_API\n Std\n*/\nstatic PyObject *\nPyArray_Std(PyArrayObject *self, int axis, int rtype, int variance)\n{\n\tPyObject *obj1=NULL, *obj2=NULL, *new=NULL;\n\tPyObject *ret=NULL, *newshape=NULL;\n\tint i, n;\n\tintp val;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\t\n\t/* Compute and reshape mean */\n\tobj1 = PyArray_EnsureArray(PyArray_Mean((PyAO *)new, axis, rtype));\n\tif (obj1 == NULL) {Py_DECREF(new); return NULL;} \n\tn = PyArray_NDIM(new);\n\tnewshape = PyTuple_New(n);\n\tif (newshape == NULL) {Py_DECREF(obj1); Py_DECREF(new); return NULL;}\n\tfor (i=0; ind != 1) {\n Py_DECREF(cond);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"condition must be 1-d array\");\n return NULL;\n }\n\n res = PyArray_Nonzero(cond);\n Py_DECREF(cond);\n\tret = PyArray_Take(self, res, axis);\n\tPy_DECREF(res);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Nonzero\n*/\nstatic PyObject *\nPyArray_Nonzero(PyArrayObject *self)\n{\n int n=self->nd, j;\n\tintp count=0, i, size;\n\tPyArrayIterObject *it=NULL;\n\tPyObject *ret=NULL, *item;\n\tintp *dptr[MAX_DIMS];\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (it==NULL) return NULL;\n\n\tsize = it->size;\n\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) count++;\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\n\tPyArray_ITER_RESET(it);\n\tif (n==1) {\n\t\tret = PyArray_New(self->ob_type, 1, &count, PyArray_INTP, \n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)self);\n\t\tif (ret == NULL) goto fail;\n\t\tdptr[0] = (intp *)PyArray_DATA(ret);\n\t\t\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\t*(dptr[0])++ = i;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\t\t\n\t}\n\telse {\n\t\tret = PyTuple_New(n);\n\t\tfor (j=0; job_type, 1, &count, \n\t\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0,\n\t\t\t\t\t (PyObject *)self);\n\t\t\tif (item == NULL) goto fail;\n\t\t\tPyTuple_SET_ITEM(ret, j, item);\n\t\t\tdptr[j] = (intp *)PyArray_DATA(item);\n\t\t}\n\t\t\n\t\t/* reset contiguous so that coordinates gets updated */\n\t\tit->contiguous = 0;\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\tfor (j=0; jcoordinates[j];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\n\n\tPy_DECREF(it);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(ret);\n\tPy_XDECREF(it);\n\treturn NULL;\n \n}\n\n/*MULTIARRAY_API\n Clip\n*/\nstatic PyObject *\nPyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max)\n{\n\tPyObject *selector=NULL, *newtup=NULL, *ret=NULL;\n\tPyObject *res1=NULL, *res2=NULL, *res3=NULL;\n\tPyObject *two;\n\n\ttwo = PyInt_FromLong((long)2);\n\tres1 = PyArray_GenericBinaryFunction(self, max, n_ops.greater);\n\tres2 = PyArray_GenericBinaryFunction(self, min, n_ops.less);\n\tif ((res1 == NULL) || (res2 == NULL)) {\n\t\tPy_DECREF(two);\n\t\tPy_XDECREF(res1);\n\t\tPy_XDECREF(res2);\n\t}\n\tres3 = PyNumber_Multiply(two, res1);\n\tPy_DECREF(two); \n\tPy_DECREF(res1); \n\tif (res3 == NULL) return NULL;\n\n\tselector = PyArray_EnsureArray(PyNumber_Add(res2, res3));\n\tPy_DECREF(res2);\n\tPy_DECREF(res3);\n\tif (selector == NULL) return NULL;\n\n\tnewtup = Py_BuildValue(\"(OOO)\", (PyObject *)self, min, max);\n\tif (newtup == NULL) {Py_DECREF(selector); return NULL;}\n\tret = PyArray_Choose((PyAO *)selector, newtup);\n\tPy_DECREF(selector);\n\tPy_DECREF(newtup);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Conjugate\n*/\nstatic PyObject *\nPyArray_Conjugate(PyArrayObject *self)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyObject *new;\n\t\tintp size, i;\n\t\t/* Make a copy */\n\t\tnew = PyArray_NewCopy(self, -1);\n\t\tif (new==NULL) return NULL;\n\t\tsize = PyArray_SIZE(new);\n\t\tif (self->descr->type_num == PyArray_CFLOAT) {\n\t\t\tcfloat *dptr = (cfloat *) PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CDOUBLE) {\n\t\t\tcdouble *dptr = (cdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CLONGDOUBLE) {\n\t\t\tclongdouble *dptr = (clongdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\t\t\t\n\t\t}\t\t\n\t\treturn new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *) self;\n\t}\n}\n\n/*MULTIARRAY_API\n Trace\n*/\nstatic PyObject *\nPyArray_Trace(PyArrayObject *self, int offset, int axis1, int axis2, \nint rtype)\n{\n\tPyObject *diag=NULL, *ret=NULL;\n\n\tdiag = PyArray_Diagonal(self, offset, axis1, axis2);\n\tif (diag == NULL) return NULL;\n\tret = PyArray_GenericReduceFunction((PyAO *)diag, n_ops.add, -1, rtype);\n\tPy_DECREF(diag);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Diagonal\n*/\nstatic PyObject *\nPyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)\n{\n\tint n = self->nd;\n\tPyObject *new;\n\tPyArray_Dims newaxes;\n\tintp dims[MAX_DIMS];\n\tint i, pos;\t\n\n\tnewaxes.ptr = dims;\n\tif (n < 2) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"array.ndim must be >= 2\");\n\t\treturn NULL;\n\t}\n\tif (axis1 < 0) axis1 += n;\n\tif (axis2 < 0) axis2 += n;\n\tif ((axis1 == axis2) || (axis1 < 0) || (axis1 >= n) ||\t\\\n\t (axis2 < 0) || (axis2 >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \"axis1(=%d) and axis2(=%d) \"\\\n\t\t\t \"must be different and within range (nd=%d)\",\n\t\t\t axis1, axis2, n);\n\t\treturn NULL;\n\t}\n \n\tnewaxes.len = n;\n\t/* insert at the end */\n\tnewaxes.ptr[n-2] = axis1;\n\tnewaxes.ptr[n-1] = axis2;\n\tpos = 0;\n\tfor (i=0; idimensions[0];\n\t\tn2 = self->dimensions[1];\n\t\tstep = n2+1;\n\t\tif (offset < 0) {\n\t\t\tstart = -n2 * offset;\n\t\t\tstop = MIN(n2, n1+offset)*(n2+1) - n2*offset;\n\t\t}\n\t\telse {\n\t\t\tstart = offset;\n\t\t\tstop = MIN(n1, n2-offset)*(n2+1) + offset;\n\t\t}\n\t\t\n\t\t/* count = ceil((stop-start)/step) */\n\t\tcount = ((stop-start) / step) + (((stop-start) % step) != 0);\n\t\t\t\n\t\tindices = PyArray_New(&PyArray_Type, 1, &count, \n\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0, NULL);\n\t\tif (indices == NULL) {\n\t\t\tPy_DECREF(self); return NULL;\n\t\t}\n\t\tdptr = (intp *)PyArray_DATA(indices);\n\t\tfor (n1=start; n1descr;\n\n\t\tmydiagonal = PyList_New(0);\n\t\tif (mydiagonal == NULL) {Py_DECREF(self); return NULL;}\n\t\tn1 = self->dimensions[0];\n\t\tfor (i=0; i 3)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"C arrays of only 1-3 dimensions available\");\n\t\tPy_XDECREF(typedescr);\n\t\treturn -1;\n\t}\n\tif ((ap = (PyArrayObject*)PyArray_FromAny(*op, typedescr, nd, nd,\n\t\t\t\t\t\t CARRAY_FLAGS)) == NULL)\n\t\treturn -1;\n\tswitch(nd) {\n\tcase 1:\n\t\t*((char **)ptr) = ap->data;\n\t\tbreak;\n\tcase 2:\n\t\tn = ap->dimensions[0];\n\t\tptr2 = (char **)_pya_malloc(n * sizeof(char *));\n\t\tif (!ptr2) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0];\n\t\t}\n\t\t*((char ***)ptr) = ptr2;\n\t\tbreak;\t\t\n\tcase 3:\n\t\tn = ap->dimensions[0];\n\t\tm = ap->dimensions[1];\n\t\tptr3 = (char ***)_pya_malloc(n*(m+1) * sizeof(char *));\n\t\tif (!ptr3) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0] + \\\n\t\t\t\t\tj*ap->strides[1];\n\t\t\t}\n\t\t}\n\t\t*((char ****)ptr) = ptr3;\n\t}\n\tmemcpy(dims, ap->dimensions, nd*sizeof(intp));\n\t*op = (PyObject *)ap;\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_MemoryError, \"no memory\");\n\treturn -1;\n}\n\n/* Deprecated --- Use PyArray_AsCArray instead */\n\n/*MULTIARRAY_API\n Convert to a 1D C-array\n*/\nstatic int \nPyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) \n{\n\tintp newd1;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, descr) == -1)\n\t\treturn -1;\t\n\t*d1 = (int) newd1;\n\treturn 0;\n}\n\n/*MULTIARRAY_API\n Convert to a 2D C-array\n*/\nstatic int \nPyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) \n{\n\tintp newdims[2];\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, newdims, 2, descr) == -1)\n\t\treturn -1;\n\n\t*d1 = (int ) newdims[0];\n\t*d2 = (int ) newdims[1];\n return 0;\n}\n\n/* End Deprecated */\n\n/*MULTIARRAY_API\n Free pointers created if As2D is called\n*/\nstatic int \nPyArray_Free(PyObject *op, void *ptr) \n{\n PyArrayObject *ap = (PyArrayObject *)op;\n\t\n if ((ap->nd < 1) || (ap->nd > 3)) \n\t\treturn -1;\n if (ap->nd >= 2) {\n\t\t_pya_free(ptr);\n }\n Py_DECREF(ap);\n return 0;\n}\n\n\nstatic PyObject *\n_swap_and_concat(PyObject *op, int axis, int n)\n{\n\tPyObject *newtup=NULL;\n\tPyObject *otmp, *arr;\n\tint i;\n\n\tnewtup = PyTuple_New(n);\n\tif (newtup==NULL) return NULL;\n\tfor (i=0; i= MAX_DIMS) {\n\t\t\totmp = PyArray_Ravel(mps[i],0);\n\t\t\tPy_DECREF(mps[i]);\n\t\t\tmps[i] = (PyArrayObject *)otmp;\n\t\t}\n\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\tif (prior2 > prior1) {\n\t\t\tprior1 = prior2;\n\t\t\tsubtype = mps[i]->ob_type;\n\t\t\tret = mps[i];\n\t\t}\n\t}\n\t\n\tnew_dim = 0;\n\tfor(i=0; ind;\n\t\telse {\n\t\t\tif (nd != mps[i]->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"arrays must have same \"\\\n\t\t\t\t\t\t\"number of dimensions\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CompareLists(mps[0]->dimensions+1, \n\t\t\t\t\t\t mps[i]->dimensions+1, \n\t\t\t\t\t\t nd-1)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"array dimensions must \"\\\n\t\t\t\t\t\t\"agree except for d_0\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (nd == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"0-d arrays can't be concatenated\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnew_dim += mps[i]->dimensions[0];\n\t}\n\t\n\ttmp = mps[0]->dimensions[0];\n\tmps[0]->dimensions[0] = new_dim;\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(subtype, \n\t\t\t\t\t\t mps[0]->descr, nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ret);\n\tmps[0]->dimensions[0] = tmp;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tdata = ret->data;\n\tfor(i=0; idata, numbytes);\n\t\tdata += numbytes;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; ind;\n\tif (n <= 1) {\n\t\tPy_INCREF(ap);\n\t\treturn (PyObject *)ap;\n\t}\n\n\tif (a1 < 0) a1 += n;\n\tif (a2 < 0) a2 += n;\n\tif ((a1 < 0) || (a1 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis1 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tif ((a2 < 0) || (a2 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis2 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tnew_axes.ptr = dims;\n\tnew_axes.len = n;\n\n\tfor (i=0; ind;\n\t\tfor(i=0; ilen;\n\t\taxes = permute->ptr;\n\t\tif (n > ap->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many axes for this array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tfor(i=0; ind+axis;\n\t\t\tif (axis < 0 || axis >= ap->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"invalid axis for this array\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tpermutation[i] = axis;\n\t\t}\n\t}\n\t\n\t/* this allocates memory for dimensions and strides (but fills them\n\t incorrectly), sets up descr, and points data at ap->data. */\n\tPy_INCREF(ap->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t ap->descr, \n\t\t\t\t n, permutation, \n\t\t\t\t NULL, ap->data, ap->flags,\n\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) return NULL;\n\t\n\t/* point at true owner of memory: */\n\tret->base = (PyObject *)ap;\n\tPy_INCREF(ap);\n\t\n\tfor(i=0; idimensions[i] = ap->dimensions[permutation[i]];\n\t\tret->strides[i] = ap->strides[permutation[i]];\n\t}\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\t\n\n\treturn (PyObject *)ret;\t\n}\n\n/*MULTIARRAY_API\n Repeat the array.\n*/\nstatic PyObject *\nPyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis)\n{\n\tintp *counts;\n\tintp n, n_outer, i, j, k, chunk, total;\n\tintp tmp;\n\tint nd;\n\tPyArrayObject *repeats=NULL;\n\tPyObject *ap=NULL;\n\tPyArrayObject *ret=NULL;\n\tchar *new_data, *old_data;\n\n\trepeats = (PyAO *)PyArray_ContiguousFromAny(op, PyArray_INTP, 0, 1);\n\tif (repeats == NULL) return NULL;\n\tnd = repeats->nd;\n\tcounts = (intp *)repeats->data;\n\n\tif ((ap=_check_axis(aop, &axis, CARRAY_FLAGS))==NULL) {\n\t\tPy_DECREF(repeats);\n\t\treturn NULL;\n\t}\n\n\taop = (PyAO *)ap;\n\n\tif (nd == 1)\n\t\tn = repeats->dimensions[0];\n\telse /* nd == 0 */\n\t\tn = aop->dimensions[axis];\n\n\tif (aop->dimensions[axis] != n) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"a.shape[axis] != len(repeats)\");\n\t\tgoto fail;\n\t}\n\n\t\n\tif (nd == 0) \n\t\ttotal = counts[0]*n;\n\telse {\n\t\t\n\t\ttotal = 0;\n\t\tfor(j=0; jdimensions[axis] = total;\n\tPy_INCREF(aop->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(aop->ob_type, \n\t\t\t\t\t\t aop->descr,\n\t\t\t\t\t\t aop->nd,\n\t\t\t\t\t\t aop->dimensions,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)aop);\n\taop->dimensions[axis] = n;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tnew_data = ret->data;\n\told_data = aop->data;\n\t\n\tchunk = aop->descr->elsize;\n\tfor(i=axis+1; ind; i++) {\n\t\tchunk *= aop->dimensions[i];\n\t}\n\t\n\tn_outer = 1;\n\tfor(i=0; idimensions[i];\n\n\tfor(i=0; ind < mps[i]->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many dimensions\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (!PyArray_CompareLists(ap->dimensions+(ap->nd-mps[i]->nd),\n\t\t\t\t mps[i]->dimensions, mps[i]->nd)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"array dimensions must agree\");\n\t\t\tgoto fail;\n\t\t}\n\t\tsizes[i] = PyArray_NBYTES(mps[i]);\n\t}\n\t\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t\t\t mps[0]->descr,\n\t\t\t\t\t\t ap->nd,\n\t\t\t\t\t\t ap->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\telsize = ret->descr->elsize;\n\tm = PyArray_SIZE(ret);\n\tself_data = (intp *)ap->data;\n\tret_data = ret->data;\n\t\n\tfor (i=0; i= n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid entry in choice array\");\n\t\t\tgoto fail;\n\t\t}\n\t\toffset = i*elsize;\n\t\tif (offset >= sizes[mi]) {offset = offset % sizes[mi]; }\n\t\tmemmove(ret_data, mps[mi]->data+offset, elsize);\n\t\tret_data += elsize; self_data++;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; idescr->f->sort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize);\n\n\tif (needcopy) {\n\t\tchar *buffer;\n\t\tbuffer = PyDataMem_NEW(N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(buffer, (intp) elsize, it->dataptr, \n\t\t\t\t astride, N, elsize);\n\t\t\tif (sort(buffer, N, op) < 0) {\n\t\t\t\tPyDataMem_FREE(buffer); goto fail;\n\t\t\t}\n\t\t\t_strided_copy(it->dataptr, astride, buffer, \n\t\t\t\t (intp) elsize, N, elsize);\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyDataMem_FREE(buffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tif (sort(it->dataptr, N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\t\n\t\n\tEND_THREADS\n\t\n\tPy_DECREF(it);\n\treturn 0;\n\n fail:\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nstatic PyObject*\n_new_argsort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\n\tPyArrayIterObject *it=NULL;\n\tPyArrayIterObject *rit=NULL;\n\tPyObject *ret;\n\tint needcopy=0, i;\n\tintp N, size;\n\tint elsize;\n\tintp astride, rstride, *iptr;\n\tPyArray_ArgSortFunc *argsort;\n\tBEGIN_THREADS_DEF \n\n\tret = PyArray_New(op->ob_type, op->nd,\n\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) return NULL;\n\n\tit = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)op, axis);\n\trit = (PyArrayIterObject *)PyArray_IterAllButAxis(ret, axis);\n\tif (rit == NULL || it == NULL) goto fail;\n\n\tBEGIN_THREADS\n\n\targsort = op->descr->f->argsort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize) || \\\n\t\t(rstride != sizeof(intp));\n\t\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(elsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(valbuffer, (intp) elsize, it->dataptr,\n\t\t\t\t astride, N, elsize);\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idataptr, rstride, indbuffer, \n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idataptr, (intp *)rit->dataptr, \n\t\t\t\t N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\t\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\tPy_DECREF(rit);\n\treturn ret;\n\n fail:\n\n\tEND_THREADS\n\n\tPy_DECREF(ret);\n\tPy_XDECREF(it);\n\tPy_XDECREF(rit);\n\treturn NULL;\n}\n\n\n/* Be sure to save this global_compare when necessary */\n\nstatic PyArrayObject *global_obj;\n\nstatic int \nqsortCompare (const void *a, const void *b) \n{\n\treturn global_obj->descr->f->compare(a,b,global_obj);\n}\n\n/* Consumes reference to ap (op gets it)\n op contains a version of the array with axes swapped if\n local variable axis is not the last dimension.\n orign must be defined locally. \n*/\n\n#define SWAPAXES(op, ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* Consumes reference to ap (op gets it)\n origin must be previously defined locally. \n SWAPAXES must have been called previously. \n op contains the swapped version of the array. \n*/\n#define SWAPBACK(op, ap) {\t \\\n\t\tif (axis != orign) { \\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* These swap axes in-place if necessary */\n#define SWAPINTP(a,b) {intp c; c=(a); (a) = (b); (b) = c;}\n#define SWAPAXES2(ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN); \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define SWAPBACK2(ap) {\t\t \\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n/*MULTIARRAY_API\n Sort an array in-place\n*/\nstatic int\nPyArray_Sort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *store_arr=NULL;\n\tchar *ip;\n\tint i, n, m, elsize, orign;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) return 0;\n\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\treturn -1;\n\t}\n\tif (!PyArray_ISWRITEABLE(op)) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"attempted sort on unwriteable array.\");\n\t\treturn -1;\n\t}\n\n\t/* Determine if we should use type-specific algorithm or not */\n\tif (op->descr->f->sort[which] != NULL) {\n\t\treturn _new_sort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || \\\n\t op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"desired sort not supported for this type\");\n\t\treturn -1;\n\t}\n\n\tSWAPAXES2(op);\n\n ap = (PyArrayObject *)PyArray_FromAny((PyObject *)op, \n\t\t\t\t\t NULL, 1, 0, \n\t\t\t\t\t DEFAULT_FLAGS | UPDATEIFCOPY);\t\n\tif (ap == NULL) goto fail;\n\t\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(ap)/m;\n\n\t/* Store global -- allows re-entry -- restore before leaving*/\n\tstore_arr = global_obj; \n\tglobal_obj = ap;\n\t\n\tfor (ip=ap->data, i=0; idescr->elsize;\n\tconst intp *ipa = ip1;\n\tconst intp *ipb = ip2;\t\n\treturn global_obj->descr->f->compare(global_data + (isize * *ipa),\n global_data + (isize * *ipb), \n\t\t\t\t\t global_obj);\n}\n\n/*MULTIARRAY_API\n ArgSort an array\n*/\nstatic PyObject *\nPyArray_ArgSort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *ret=NULL, *store;\n\tintp *ip;\n\tintp i, j, n, m, orign;\n\tint argsort_elsize;\n\tchar *store_ptr;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t\t op->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, \n\t\t\t\t\t\t (PyObject *)op);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)ret->data) = 0;\n\t\treturn (PyObject *)ret;\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\treturn NULL;\n\t}\n\n\t/* Determine if we should use new algorithm or not */\n\tif (op->descr->f->argsort[which] != NULL) {\n\t\treturn _new_argsort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"requested sort not available for type\");\n\t\tgoto fail;\n\t}\n\n\tSWAPAXES(ap, op);\n\n\top = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ap, \n\t\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t\t 1, 0);\n\n\tif (op == NULL) return NULL;\n\t\n\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) goto fail;\n\t\n\t\n\tip = (intp *)ret->data;\n\targsort_elsize = op->descr->elsize;\n\tm = op->dimensions[op->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(op)/m;\n\tstore_ptr = global_data;\n\tglobal_data = op->data;\n\tstore = global_obj;\n\tglobal_obj = op;\n\tfor (i=0; i 0 in lexsort\");\n\t\treturn NULL;\n\t}\n\tmps = (PyArrayObject **) _pya_malloc(n*sizeof(PyArrayObject));\n\tif (mps==NULL) return PyErr_NoMemory();\n\tits = (PyArrayIterObject **) _pya_malloc(n*sizeof(PyArrayIterObject));\n\tif (its == NULL) {_pya_free(mps); return PyErr_NoMemory();}\n\tfor (i=0; i0) {\n\t\t\tif ((mps[i]->nd != mps[0]->nd) ||\t\\\n\t\t\t (!PyArray_CompareLists(mps[i]->dimensions,\n\t\t\t\t\t\t mps[0]->dimensions,\n\t\t\t\t\t\t mps[0]->nd))) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"all keys need to be the same shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (!mps[i]->descr->f->argsort[PyArray_MERGESORT]) {\n\t\t\tPyErr_Format(PyExc_TypeError, \n\t\t\t\t \"merge sort not available for item %d\", i);\n\t\t\tgoto fail;\n\t\t}\n\t\tits[i] = (PyArrayIterObject *)PyArray_IterAllButAxis\t\\\n\t\t\t((PyObject *)mps[i], axis);\n\t\tif (its[i]==NULL) goto fail;\n\t}\n\n\t/* Now we can check the axis */\n\tnd = mps[0]->nd;\n\tif ((nd==0) || (PyArray_SIZE(mps[0])==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)(ret->data)) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += nd;\n\tif ((axis < 0) || (axis >= nd)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\tgoto fail;\n\t}\n\n\t/* Now do the sorting */\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t mps[0]->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (ret == NULL) goto fail;\n\n\trit = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ret, axis);\n\tif (rit == NULL) goto fail;\n\n\tsize = rit->size;\n\tN = mps[0]->dimensions[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n maxelsize = mps[0]->descr->elsize;\n\tneedcopy = (rstride != sizeof(intp));\n\tfor (j=0; jflags & ALIGNED) || \\\n\t\t\t(mps[j]->strides[axis] != (intp)mps[j]->descr->elsize);\n if (mps[j]->descr->elsize > maxelsize) \n maxelsize = mps[j]->descr->elsize;\n\t}\n\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(maxelsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*maxelsize);\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idescr->elsize;\n\t\t\t\tastride = mps[j]->strides[axis];\t\n\t\t\t\targsort = mps[j]->descr->f->argsort[PyArray_MERGESORT];\n\t\t\t\t_strided_copy(valbuffer, (intp) elsize, its[j]->dataptr,\n\t\t\t\t\t astride, N, elsize);\n\t\t\t\tif (argsort(valbuffer, (intp *)indbuffer, N, mps[j]) < 0) {\n\t\t\t\t\tPyDataMem_FREE(valbuffer); goto fail;\n\t\t\t\t}\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\t_strided_copy(rit->dataptr, rstride, indbuffer,\n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idescr->f->argsort[PyArray_MERGESORT];\n\t\t\t\tif (argsort(its[j]->dataptr, (intp *)rit->dataptr,\n\t\t\t\t\t N, mps[j]) < 0) goto fail;\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\n\tfor (i=0; idescr->f->compare;\n\tintp min_i, max_i, i, j;\n\tint location, elsize = ap1->descr->elsize;\n\tintp elements = ap1->dimensions[ap1->nd-1];\n\tintp n = PyArray_SIZE(ap2);\n\tintp *rp = (intp *)ret->data;\n\tchar *ip = ap2->data;\n\tchar *vp = ap1->data;\n\n\tfor (j=0; j 0) {\n\t\t\t\t\tif (compare(ip, vp+elsize*(--i), ap2) \\\n\t\t\t\t\t != 0) {\n\t\t\t\t\t\ti = i+1; break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmin_i = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (location < 0) {\n\t\t\t\tmax_i = i;\n\t\t\t} else {\n\t\t\t\tmin_i = i+1;\n\t\t\t}\n\t\t}\n\t\t*rp = min_i;\n\t}\n}\n\n/*MULTIARRAY_API\n Numeric.searchsorted(a,v)\n*/\nstatic PyObject *\nPyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n\tint typenum = 0;\n\n\t/* \n PyObject *args;\n args = Py_BuildValue(\"O\",op2);\n\tPy_DELEGATE_ARGS(((PyObject *)op1), searchsorted, args);\n Py_XDECREF(args);\n\t*/\n\n\ttypenum = PyArray_ObjectType((PyObject *)op1, 0);\n\ttypenum = PyArray_ObjectType(op2, typenum);\n\tret = NULL;\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op1, \n\t\t\t\t\t\t\t typenum, \n\t\t\t\t\t\t\t 1, 1);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tret = (PyArrayObject *)PyArray_New(ap2->ob_type, ap2->nd, \n\t\t\t\t\t ap2->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap2);\n\tif (ret == NULL) goto fail;\n\n\tif (ap2->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tgoto fail;\n\t}\n\t\n\tlocal_where(ap1, ap2, ret); \n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n\n\n/* Could perhaps be redone to not make contiguous arrays \n */\n\n/*MULTIARRAY_API\n Numeric.innerproduct(a,v)\n*/\nstatic PyObject *\nPyArray_InnerProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tintp i, j, l, i1, i2, n1, n2;\n\tint typenum;\n\tintp is1, is2, os;\n\tchar *ip1, *ip2, *op;\n\tintp dimensions[MAX_DIMS], nd;\n\tPyArray_DotFunc *dot;\n\tPyTypeObject *subtype;\n double prior1, prior2;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\t\t\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny(op1, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n \n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\tif (ret == NULL) goto fail;\n\n\tdot = (ret->descr->f->dotfunc);\n\t\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\n\t\n\tis1 = ap1->strides[ap1->nd-1]; \n\tis2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t\totherDim = ap2->nd - 1;\n\t}\n\telse {\n\t\tmatchDim = 0;\n\t\totherDim = 0;\n\t}\n\n\tif (ap2->dimensions[matchDim] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"objects are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-2; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\tif(ap2->nd > 1) {\n\t\tdimensions[j++] = ap2->dimensions[ap2->nd-1];\n\t}\n\t/*\n\tfprintf(stderr, \"nd=%d dimensions=\", nd);\n\t for(i=0; i prior1 ? ap2->ob_type : ap1->ob_type);\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\n\n\tif (ret == NULL) goto fail;\n\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\t\t\n\tis1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\tif(ap1->nd > 1)\n\t\tis1r = ap1->strides[ap1->nd-2];\n\telse\n\t\tis1r = ap1->strides[ap1->nd-1];\n\tis2r = ap2->strides[otherDim];\n\n\top = ret->data; os = ret->descr->elsize;\n\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t 2, dims, \n\t\t\t\t NULL, NULL, 0, arr);\n\n\tif (ret == NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn NULL;\n\t}\n\t/* do 2-d loop */\n\toptr = PyArray_DATA(ret);\n\tstr2 = elsize*dims[0];\n\tfor (i=0; idimensions[0];\n\tn2 = ap2->dimensions[0];\n\n\tif (n1 < n2) { \n\t\tret = ap1; ap1 = ap2; ap2 = ret; \n\t\tret = NULL; i = n1;n1=n2;n2=i;\n\t}\n\tlength = n1;\n\tn = n2;\n\tswitch(mode) {\n\tcase 0:\t\n\t\tlength = length-n+1;\n\t\tn_left = n_right = 0;\n\t\tbreak;\n\tcase 1:\n\t\tn_left = (intp)(n/2);\n\t\tn_right = n-n_left-1;\n\t\tbreak;\n\tcase 2:\n\t\tn_right = n-1;\n\t\tn_left = n-1;\n\t\tlength = length+n-1;\n\t\tbreak;\n\tdefault:\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mode must be 0, 1, or 2\");\n\t\tgoto fail;\n\t}\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t\n\tret = (PyArrayObject *)PyArray_New(subtype, 1,\n\t\t\t\t\t &length, typenum, \n\t\t\t\t\t NULL, NULL, 0, 0,\n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\tif (ret == NULL) goto fail;\n\t\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"function not available for this data type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[0]; is2 = ap2->strides[0];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data; ip2 = ap2->data+n_left*is2;\n\tn = n-n_left;\n\tfor(i=0; idescr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Min\n*/\nstatic PyObject *\nPyArray_Min(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tret = PyArray_GenericReduceFunction(arr, n_ops.minimum, axis,\n\t\t\t\t\t arr->descr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Ptp\n*/\nstatic PyObject *\nPyArray_Ptp(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\tPyObject *obj1=NULL, *obj2=NULL;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tobj1 = PyArray_Max(arr, axis);\n\tif (obj1 == NULL) goto fail;\n\tobj2 = PyArray_Min(arr, axis);\n\tif (obj2 == NULL) goto fail;\n\tPy_DECREF(arr);\n\tret = PyNumber_Subtract(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(obj1);\n\tPy_XDECREF(obj2);\n\treturn NULL;\n}\n\n\n/*MULTIARRAY_API\n ArgMax\n*/\nstatic PyObject *\nPyArray_ArgMax(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap=NULL, *rp=NULL;\n\tPyArray_ArgFunc* arg_func;\n\tchar *ip;\n\tintp *rptr;\n\tintp i, n, orign, m;\n\tint elsize;\n\t\n\tif ((ap=(PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny((PyObject *)op, \n\t\t\t\t\t PyArray_NOTYPE, 1, 0);\n\n\tPy_DECREF(op);\n\tif (ap == NULL) return NULL;\n\t\n\targ_func = ap->descr->f->argmax;\n\tif (arg_func == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"data type not ordered\");\n\t\tgoto fail;\n\t}\n\n\trp = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd-1,\n\t\t\t\t\t ap->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)ap);\n\tif (rp == NULL) goto fail;\n\n\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) {\n\t\tPyErr_SetString(MultiArrayError, \n\t\t\t\t\"attempt to get argmax/argmin \"\\\n\t\t\t\t\"of an empty sequence??\");\n\t\tgoto fail;\n\t}\n\tn = PyArray_SIZE(ap)/m;\n\trptr = (intp *)rp->data;\n\tfor (ip = ap->data, i=0; ind + indices->nd - 1;\n for (i=0; i< nd; i++) {\n if (i < axis) {\n shape[i] = self->dimensions[i];\n n *= shape[i];\n } else {\n if (i < axis+indices->nd) {\n shape[i] = indices->dimensions[i-axis];\n m *= shape[i];\n } else {\n shape[i] = self->dimensions[i-indices->nd+1];\n chunk *= shape[i];\n }\n }\n }\n\tPy_INCREF(self->descr);\n ret = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t nd, shape, \n\t\t\t\t\t\t NULL, NULL, 0, \n\t\t\t\t\t\t (PyObject *)self);\n\t\n if (ret == NULL) goto fail;\n\t\n max_item = self->dimensions[axis];\n chunk = chunk * ret->descr->elsize;\n src = self->data;\n dest = ret->data;\n\t\n for(i=0; idata))[j];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\t\"index out of range for \"\\\n\t\t\t\t\t\t\"array\");\n goto fail;\n }\n memmove(dest, src+tmp*chunk, chunk);\n dest += chunk;\n }\n src += chunk*max_item;\n }\n\t\n PyArray_INCREF(ret);\n\n Py_XDECREF(indices);\n Py_XDECREF(self);\n\n return (PyObject *)ret;\n\t\n\t\n fail:\n Py_XDECREF(ret);\n Py_XDECREF(indices);\n Py_XDECREF(self);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array\n*/\nstatic PyObject *\nPyArray_Put(PyArrayObject *self, PyObject* values0, PyObject *indices0) \n{\n PyArrayObject *indices, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype; \n char *src, *dest;\n\n indices = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \"put: first argument must be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \"put: first argument must be contiguous\");\n return NULL;\n }\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0);\n if (indices == NULL) goto fail;\n ni = PyArray_SIZE(indices);\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\n if (thistype == PyArray_OBJECT) { \n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n Py_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+tmp*chunk)));\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n\n }\n\n Py_XDECREF(values);\n Py_XDECREF(indices);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(indices);\n Py_XDECREF(values);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array according to a mask.\n*/\nstatic PyObject *\nPyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) \n{\n PyArrayObject *mask, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype;\n char *src, *dest;\n\n mask = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"putmask: first argument must \"\\\n\t\t\t\t\"be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: first argument must be contiguous\");\n return NULL;\n }\n\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n mask = (PyArrayObject *)\\\n\t\tPyArray_FROM_OTF(mask0, PyArray_BOOL, CARRAY_FLAGS | FORCECAST);\n\tif (mask == NULL) goto fail;\n ni = PyArray_SIZE(mask);\n if (ni != max_item) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: mask and data must be \"\\\n\t\t\t\t\"the same size\");\n goto fail;\n }\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n\tif (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\t /* zero if null array */\n if (nv > 0) {\n if (thistype == PyArray_OBJECT) {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) {\n\t\t\t\t\tPy_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+i*chunk)));\n memmove(dest + i * chunk, src, chunk);\n }\n\t\t\t}\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) memmove(dest + i * chunk, src, chunk);\n\t\t\t}\n\t\t}\n }\n\n Py_XDECREF(values);\n Py_XDECREF(mask);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(mask);\n Py_XDECREF(values);\n return NULL;\n}\n\n\n/* This conversion function can be used with the \"O&\" argument for\n PyArg_ParseTuple. It will immediately return an object of array type\n or will convert to a CARRAY any other object. \n\n If you use PyArray_Converter, you must DECREF the array when finished\n as you get a new reference to it.\n*/\n \n/*MULTIARRAY_API\n Useful to pass as converter function for O& processing in\n PyArgs_ParseTuple.\n*/\nstatic int \nPyArray_Converter(PyObject *object, PyObject **address) \n{\n if (PyArray_Check(object)) {\n *address = object;\n\t\tPy_INCREF(object);\n return PY_SUCCEED;\n }\n else {\n\t\t*address = PyArray_FromAny(object, NULL, 0, 0, CARRAY_FLAGS);\n\t\tif (*address == NULL) return PY_FAIL;\n\t\treturn PY_SUCCEED;\n }\n}\n\n/*MULTIARRAY_API\n Convert an object to true / false\n*/\nstatic int\nPyArray_BoolConverter(PyObject *object, Bool *val)\n{ \n if (PyObject_IsTrue(object))\n *val=TRUE;\n else *val=FALSE;\n if (PyErr_Occurred())\n return PY_FAIL;\n return PY_SUCCEED;\n}\n\n\n/*MULTIARRAY_API\n Typestr converter\n*/\nstatic int\nPyArray_TypestrConvert(int itemsize, int gentype)\n{\n\tregister int newtype = gentype;\n\t\n\tif (gentype == PyArray_GENBOOLLTR) {\n\t\tif (itemsize == 1)\n\t\t\tnewtype = PyArray_BOOL;\n\t\telse \n\t\t\tnewtype = PyArray_NOTYPE;\n\t}\n\telse if (gentype == PyArray_SIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_INT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_INT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_INT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_INT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_INT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\n\t}\n\n\telse if (gentype == PyArray_UNSIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_UINT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_UINT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_UINT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_UINT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_UINT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t\tbreak;\n\t\t}\n\t}\n\telse if (gentype == PyArray_FLOATINGLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 4:\n\t\t\tnewtype = PyArray_FLOAT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_FLOAT64;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 10:\n\t\t\tnewtype = PyArray_FLOAT80;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 12:\n\t\t\tnewtype = PyArray_FLOAT96;\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_FLOAT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\t\n\telse if (gentype == PyArray_COMPLEXLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 8:\n\t\t\tnewtype = PyArray_COMPLEX64;\n\t\t\tbreak;\n\t\tcase 16:\n\t\t\tnewtype = PyArray_COMPLEX128;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 20:\n\t\t\tnewtype = PyArray_COMPLEX160;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 24:\n\t\t\tnewtype = PyArray_COMPLEX192;\t\t\t\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 32:\n\t\t\tnewtype = PyArray_COMPLEX256;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\n\treturn newtype;\n}\n\n\n/* this function takes a Python object which exposes the (single-segment)\n buffer interface and returns a pointer to the data segment\n \n You should increment the reference count by one of buf->base\n if you will hang on to a reference\n\n You only get a borrowed reference to the object. Do not free the\n memory...\n*/\n\n\n/*MULTIARRAY_API\n Get buffer chunk from object\n*/\nstatic int\nPyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)\n{\n int buflen;\n\n buf->ptr = NULL;\n buf->flags = BEHAVED_FLAGS;\n buf->base = NULL;\n\n\tif (obj == Py_None)\n\t\treturn PY_SUCCEED;\n\n if (PyObject_AsWriteBuffer(obj, &(buf->ptr), &buflen) < 0) {\n PyErr_Clear();\n buf->flags &= ~WRITEABLE;\n if (PyObject_AsReadBuffer(obj, (const void **)&(buf->ptr), \n &buflen) < 0)\n return PY_FAIL;\n }\n buf->len = (intp) buflen;\n \n /* Point to the base of the buffer object if present */\n if (PyBuffer_Check(obj)) buf->base = ((PyArray_Chunk *)obj)->base;\n if (buf->base == NULL) buf->base = obj;\n \n return PY_SUCCEED; \n}\n\n\n\n/* This function takes a Python sequence object and allocates and\n fills in an intp array with the converted values.\n\n **Remember to free the pointer seq.ptr when done using\n PyDimMem_FREE(seq.ptr)**\n*/\n\n/*MULTIARRAY_API\n Get intp chunk from sequence\n*/\nstatic int\nPyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)\n{\n int len;\n int nd;\n\n seq->ptr = NULL;\n if (obj == Py_None) return PY_SUCCEED;\n len = PySequence_Size(obj);\n if (len == -1) { /* Check to see if it is a number */\n if (PyNumber_Check(obj)) len = 1;\n }\n if (len < 0) {\n PyErr_SetString(PyExc_TypeError, \n \"expected sequence object with len >= 0\");\n return PY_FAIL;\n }\n if (len > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError, \"sequence too large; \" \\\n \"must be smaller than %d\", MAX_DIMS);\n return PY_FAIL;\n }\n\tif (len > 0) {\n\t\tseq->ptr = PyDimMem_NEW(len);\n\t\tif (seq->ptr == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n seq->len = len;\n nd = PyArray_IntpFromSequence(obj, (intp *)seq->ptr, len);\n if (nd == -1 || nd != len) {\n\t\tPyDimMem_FREE(seq->ptr);\n\t\tseq->ptr=NULL;\n\t\treturn PY_FAIL;\n\t}\n return PY_SUCCEED;\n}\n\n\n/* A tuple type would be either (generic typeobject, typesize) \n or (fixed-length data-type, shape) \n\n or (inheriting data-type, new-data-type)\n The new data-type must have the same itemsize as the inheriting data-type\n unless the latter is 0 \n \n Thus (int32, {'real':(int16,0),'imag',(int16,2)})\n\n is one way to specify a descriptor that will give \n a['real'] and a['imag'] to an int32 array.\n*/\n\n/* leave type reference alone */\nstatic PyArray_Descr *\n_use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) \n{\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n\t\n\t*errflag = 0;\n\tif (!PyArray_DescrConverter(newobj, &conv)) {\n\t\treturn NULL;\n\t}\n\t*errflag = 1;\n\tif (type == &OBJECT_Descr) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"cannot base a new descriptor on an\"\\\n\t\t\t\t\" OBJECT descriptor.\");\n\t\treturn NULL;\n\t}\n\tnew = PyArray_DescrNew(type);\n\tif (new == NULL) return NULL;\n\n\tif (new->elsize && new->elsize != conv->elsize) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mismatch in size of old\"\\\n\t\t\t\t\"and new data-descriptor\");\n\t\treturn NULL;\n\t}\n\tnew->elsize = conv->elsize;\n\tif (conv->fields != Py_None) {\n\t\tnew->fields = conv->fields;\n\t\tPy_XINCREF(new->fields);\n\t}\n\tPy_DECREF(conv);\n\t*errflag = 0;\n\treturn new;\n}\n\nstatic PyArray_Descr *\n_convert_from_tuple(PyObject *obj) \n{\n\tPyArray_Descr *type, *res;\n\tPyObject *val;\n\tint errflag;\n\t\n\tif (PyTuple_GET_SIZE(obj) != 2) return NULL;\n\n\tif (!PyArray_DescrConverter(PyTuple_GET_ITEM(obj,0), &type)) \n\t\treturn NULL;\n\tval = PyTuple_GET_ITEM(obj,1);\n\t/* try to interpret next item as a type */\n\tres = _use_inherit(type, val, &errflag);\n\tif (res || errflag) {\n\t\tPy_DECREF(type);\n\t\tif (res) return res;\n\t\telse return NULL;\n\t}\n\tPyErr_Clear();\n\t/* We get here if res was NULL but errflag wasn't set\n\t --- i.e. the conversion to a data-descr failed in _use_inherit\n\t*/\n\n\tif (type->elsize == 0) { /* interpret next item as a typesize */\n\t\tint itemsize;\n\t\titemsize = PyArray_PyIntAsInt(PyTuple_GET_ITEM(obj,1));\n\t\tif (error_converting(itemsize)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid itemsize in generic type \"\\\n\t\t\t\t\t\"tuple\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(type);\n\t\ttype->elsize = itemsize;\n\t}\n\telse {\n\t\t/* interpret next item as shape (if it's a tuple)\n\t\t and reset the type to PyArray_VOID with \n\t\t anew fields attribute. \n\t */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyArray_Descr *newdescr;\n\t\tif (!(PyArray_IntpConverter(val, &shape)) || \n\t\t (shape.len > MAX_DIMS)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n\t\t\tgoto fail;\n\t\t}\n\t\t/* If (type, 1) was given, it is equivalent to type... */\n\t\tif (shape.len == 1 && shape.ptr[0] == 1 && PyNumber_Check(val)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\treturn type;\n\t\t}\n\t\tnewdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tif (newdescr == NULL) {PyDimMem_FREE(shape.ptr); goto fail;}\n\t\tnewdescr->elsize = type->elsize;\n\t\tnewdescr->elsize *= PyArray_MultiplyList(shape.ptr, \n\t\t\t\t\t\t\t shape.len);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tnewdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tnewdescr->subarray->base = type;\n\t\tPy_INCREF(val);\n\t\tnewdescr->subarray->shape = val;\n\t\tPy_XDECREF(newdescr->fields);\n\t\tnewdescr->fields = NULL;\n\t\ttype = newdescr;\n\t}\n\treturn type;\n\n fail:\n\tPy_XDECREF(type);\n\treturn NULL;\n}\n\n/* obj is a list. Each item is a tuple with\n\n(field-name, data-type (either a list or a string), and an optional \n shape parameter).\n*/\nstatic PyArray_Descr *\n_convert_from_array_descr(PyObject *obj)\n{\n\tint n, i, totalsize;\n\tint ret;\n\tPyObject *fields, *item, *newobj;\n\tPyObject *name, *key, *tup;\n\tPyObject *nameslist;\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n\t\n\tn = PyList_GET_SIZE(obj);\t\n\tnameslist = PyList_New(n);\n\tif (!nameslist) return NULL;\n\ttotalsize = 0;\n\tfields = PyDict_New();\n\tfor (i=0; ielsize;\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(tup);\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n\tnew->elsize = totalsize;\n\treturn new;\n \n fail:\n\tPy_DECREF(fields);\n\tPy_DECREF(nameslist);\n\treturn NULL;\n\n}\n\n/* a list specifying a data-type can just be\n a list of formats. The names for the fields\n will default to f1, f2, f3, and so forth.\n\n or it can be an array_descr format string -- in which case\n align must be 0. \n*/\n\nstatic PyArray_Descr *\n_convert_from_list(PyObject *obj, int align, int try_descr)\n{\n\tint n, i;\n\tint totalsize;\n\tPyObject *fields;\n\tPyArray_Descr *conv=NULL;\n\tPyArray_Descr *new;\n\tPyObject *key, *tup;\n\tPyObject *nameslist=NULL;\n \tint ret;\n\tint maxalign=0;\n\t\n\tn = PyList_GET_SIZE(obj);\n\ttotalsize = 0;\n\tif (n==0) return NULL;\n\tnameslist = PyList_New(n);\n\tif (!nameslist) return NULL;\n\tfields = PyDict_New();\n\tfor (i=0; ialignment;\n\t\t\tif (_align > 1) totalsize =\t\t\t\\\n\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\tmaxalign = MAX(maxalign, _align);\n\t\t}\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\tPyDict_SetItem(fields, key, tup);\n\t\tPy_DECREF(tup);\n\t\tPyList_SET_ITEM(nameslist, i, key);\n\t\tif (ret == PY_FAIL) goto fail;\n\t\ttotalsize += conv->elsize;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n\tif (maxalign > 1) {\n\t\ttotalsize = ((totalsize+maxalign-1)/maxalign)*maxalign;\n\t}\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\treturn new;\n\n fail:\n\tPy_DECREF(nameslist);\n\tPy_DECREF(fields);\n\tif (!try_descr) return NULL;\n\tif (align) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"failed to convert from list of formats \"\\\n\t\t\t\t\"and align cannot be 1 for conversion from \"\\\n\t\t\t\t\"array_descr structure\");\n\t\treturn NULL;\n\t}\n\tPyErr_Clear();\n\treturn _convert_from_array_descr(obj);\n}\n\n\n/* comma-separated string */\n/* this is the format developed by the numarray records module */\n/* and implemented by the format parser in that module */\n/* this is an alternative implementation found in the _internal.py \n file patterned after that one -- the approach is to try to convert \n to a list (with tuples if any repeat information is present) \n and then call the _convert_from_list)\n*/\n\nstatic PyArray_Descr *\n_convert_from_commastring(PyObject *obj, int align)\n{\n\tPyObject *listobj;\n\tPyArray_Descr *res;\n\n\tif (!PyString_Check(obj)) return NULL;\n listobj = PyObject_CallMethod(_numpy_internal, \"_commastring\",\n\t\t\t\t \"O\", obj);\n\tif (!listobj) return NULL;\n\tres = _convert_from_list(listobj, align, 0);\n\tPy_DECREF(listobj);\n\tif (!res && !PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_ValueError, \"invalid data-type\");\n\t\treturn NULL;\n\t}\n\treturn res;\n}\n\n\n\n/* a dictionary specifying a data-type\n must have at least two and up to four\n keys These must all be sequences of the same length.\n\n \"names\" --- field names \n \"formats\" --- the data-type descriptors for the field.\n \n Optional:\n\n \"offsets\" --- integers indicating the offset into the \n record of the start of the field.\n\t\t if not given, then \"consecutive offsets\" \n\t\t will be assumed and placed in the dictionary.\n \n \"titles\" --- Allows the use of an additional key\n for the fields dictionary.\n \nAttribute-lookup-based field names merely has to query the fields \ndictionary of the data-descriptor. Any result present can be used\nto return the correct field.\n\nSo, the notion of what is a name and what is a title is really quite\narbitrary. \n\nWhat does distinguish a title, however, is that if it is not None, \nit will be placed at the end of the tuple inserted into the \nfields dictionary.\n\nIf the dictionary does not have \"names\" and \"formats\" entries,\nthen it will be checked for conformity and used directly. \n*/\n\nstatic PyArray_Descr *\n_use_fields_dict(PyObject *obj, int align)\n{\n return (PyArray_Descr *)PyObject_CallMethod(_numpy_internal, \n\t\t\t\t\t\t \"_usefields\", \n\t\t\t\t\t\t \"Oi\", obj, align);\n}\n\nstatic PyArray_Descr *\n_convert_from_dict(PyObject *obj, int align)\n{\n\tPyArray_Descr *new;\n\tPyObject *fields=NULL;\n\tPyObject *names, *offsets, *descrs, *titles, *key;\n\tint n, i;\n\tint totalsize;\n\tint maxalign=0;\n\t\n\tfields = PyDict_New();\n\tif (fields == NULL) return (PyArray_Descr *)PyErr_NoMemory();\n\t\n\tnames = PyDict_GetItemString(obj, \"names\");\n\tdescrs = PyDict_GetItemString(obj, \"formats\");\n\n\tif (!names || !descrs) {\n\t\tPy_DECREF(fields);\n\t\treturn _use_fields_dict(obj, align);\n\t}\n\tn = PyObject_Length(names);\n\toffsets = PyDict_GetItemString(obj, \"offsets\");\n\ttitles = PyDict_GetItemString(obj, \"titles\");\n\tif ((n > PyObject_Length(descrs)) ||\t\t\t\\\n\t (offsets && (n > PyObject_Length(offsets))) ||\t\\\n\t (titles && (n > PyObject_Length(titles)))) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"all items in the dictionary must have\" \\\n\t\t\t\t\" the same length.\");\n\t\tgoto fail;\n\t}\n\n\ttotalsize = 0;\n\tfor(i=0; i totalsize) totalsize = offset;\n\t\t}\n\t\telse {\n\t\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\n\t\t\tif (align) {\n\t\t\t\tint _align = newdescr->alignment;\n\t\t\t\tif (_align > 1) totalsize =\t\t\\\n\t\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\t\tmaxalign = MAX(maxalign,_align);\n\t\t\t}\n\t\t}\n\t\tif (len == 3) PyTuple_SET_ITEM(tup, 2, item);\n\t\tname = PyObject_GetItem(names, index);\n\t\tPy_DECREF(index);\n\n\t\t/* Insert into dictionary */\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) PyDict_SetItem(fields, item, tup);\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n\t\ttotalsize += newdescr->elsize;\n\t}\n\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tif (new == NULL) goto fail;\n\tif (maxalign > 1)\n\t\ttotalsize = ((totalsize + maxalign - 1)/maxalign)*maxalign;\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, names);\n\tPy_DECREF(key);\n\tnew->fields = fields;\n\treturn new;\n\n fail:\n\tPy_XDECREF(fields);\n\treturn NULL;\n}\n\n/* \n any object with \n the .fields attribute and/or .itemsize attribute \n (if the .fields attribute does not give\n the total size -- i.e. a partial record naming).\n If itemsize is given it must be >= size computed from fields\n \n The .fields attribute must return a convertible dictionary if \n present. Result inherits from PyArray_VOID.\n*/\n\n\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to NULL\n*/\nstatic int\nPyArray_DescrConverter2(PyObject *obj, PyArray_Descr **at)\n{\n\tif (obj == Py_None) {\n\t\t*at = NULL;\n\t\treturn PY_SUCCEED;\n\t}\n\telse return PyArray_DescrConverter(obj, at);\n}\n\n/* This function takes a Python object representing a type and converts it \n to a the correct PyArray_Descr * structure to describe the type.\n \n Many objects can be used to represent a data-type which in NumPy is\n quite a flexible concept. \n\n This is the central code that converts Python objects to \n Type-descriptor objects that are used throughout numpy.\n */\n\n/* new reference in *at */\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to &LONG_descr\n*/\nstatic int\nPyArray_DescrConverter(PyObject *obj, PyArray_Descr **at)\n{\n char *type;\n int check_num=PyArray_NOTYPE+10;\n\tint len;\n\tPyObject *item;\n\tint elsize = 0;\n\tchar endian = '=';\n\n\t*at=NULL;\n\t\n\t/* default */\n if (obj == Py_None) {\n\t\t*at = PyArray_DescrFromType(PyArray_LONG);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n\tif (PyArray_DescrCheck(obj)) {\n\t\t*at = (PyArray_Descr *)obj;\n\t\tPy_INCREF(*at);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n if (PyType_Check(obj)) {\n\t\tif (PyType_IsSubtype((PyTypeObject *)obj, \n\t\t\t\t &PyGenericArrType_Type)) {\n\t\t\t*at = PyArray_DescrFromTypeObject(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t\telse return PY_FAIL;\n\t\t}\n\t\tcheck_num = PyArray_OBJECT;\n\t\tif (obj == (PyObject *)(&PyInt_Type))\n\t\t\tcheck_num = PyArray_LONG;\n\t\telse if (obj == (PyObject *)(&PyLong_Type))\n\t\t\tcheck_num = PyArray_LONGLONG;\n\t\telse if (obj == (PyObject *)(&PyFloat_Type)) \n\t\t\tcheck_num = PyArray_DOUBLE;\n\t\telse if (obj == (PyObject *)(&PyComplex_Type)) \n\t\t\tcheck_num = PyArray_CDOUBLE;\n\t\telse if (obj == (PyObject *)(&PyBool_Type))\n\t\t\tcheck_num = PyArray_BOOL;\n else if (obj == (PyObject *)(&PyString_Type))\n check_num = PyArray_STRING;\n else if (obj == (PyObject *)(&PyUnicode_Type))\n check_num = PyArray_UNICODE;\n\t\telse if (obj == (PyObject *)(&PyBuffer_Type))\n\t\t\tcheck_num = PyArray_VOID;\n\t\telse {\n\t\t\t*at = _arraydescr_fromobj(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* or a typecode string */\n\n\tif (PyString_Check(obj)) {\n\t\t/* Check for a string typecode. */\n\t\ttype = PyString_AS_STRING(obj);\n\t\tlen = PyString_GET_SIZE(obj);\n\t\tif (len <= 0) goto fail;\n\t\tcheck_num = (int) type[0];\n\t\tif ((char) check_num == '>' || (char) check_num == '<' || \\\n\t\t (char) check_num == '|') {\n\t\t\tif (len <= 1) goto fail;\n\t\t\tendian = (char) check_num;\n\t\t\ttype++; len--;\n\t\t\tcheck_num = (int) type[0];\n\t\t\tif (endian == '|') endian = '=';\n\t\t}\n\t\tif (len > 1) {\n\t\t\telsize = atoi(type+1);\n\t\t\tif (len > 2 && elsize < 10) {\n\t\t\t\t/* perhaps commas present */\n\t\t\t\tint i;\n\t\t\t\tfor (i=1;ielsize == 0) && (elsize != 0)) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->elsize = elsize;\n\t}\n\tif (endian != '=' && PyArray_ISNBO(endian)) endian = '='; \n\t\n\tif (endian != '=' && (*at)->byteorder != '|' &&\t\\\n\t (*at)->byteorder != endian) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->byteorder = endian;\n\t}\n\t\n return PY_SUCCEED;\n\n fail:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"data type not understood\");\n\t*at=NULL;\n\treturn PY_FAIL;\n}\t\n\n/*MULTIARRAY_API\n Convert object to endian\n*/\nstatic int\nPyArray_ByteorderConverter(PyObject *obj, char *endian)\n{\n\tchar *str;\n\t*endian = PyArray_SWAP;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Byteorder string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\t*endian = str[0];\n\tif (str[0] != PyArray_BIG && str[0] != PyArray_LITTLE &&\t\\\n\t str[0] != PyArray_NATIVE) {\n\t\tif (str[0] == 'b' || str[0] == 'B')\n\t\t\t*endian = PyArray_BIG;\n\t\telse if (str[0] == 'l' || str[0] == 'L')\n\t\t\t*endian = PyArray_LITTLE;\n\t\telse if (str[0] == 'n' || str[0] == 'N')\n\t\t\t*endian = PyArray_NATIVE;\n\t\telse if (str[0] == 'i' || str[0] == 'I')\n\t\t\t*endian = PyArray_IGNORE;\n\t\telse if (str[0] == 's' || str[0] == 'S')\n\t\t\t*endian = PyArray_SWAP;\n\t\telse {\n\t\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t\t \"%s is an unrecognized byteorder\",\n\t\t\t\t str);\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Convert object to sort kind \n*/\nstatic int\nPyArray_SortkindConverter(PyObject *obj, PyArray_SORTKIND *sortkind)\n{\n\tchar *str;\n\t*sortkind = PyArray_QUICKSORT;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Sort kind string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\tif (str[0] == 'q' || str[0] == 'Q')\n\t\t*sortkind = PyArray_QUICKSORT;\n\telse if (str[0] == 'h' || str[0] == 'H')\n\t\t*sortkind = PyArray_HEAPSORT;\n\telse if (str[0] == 'm' || str[0] == 'M')\n\t\t*sortkind = PyArray_MERGESORT;\n\telse if (str[0] == 't' || str[0] == 'T')\n\t\t*sortkind = PyArray_TIMSORT;\n\telse {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"%s is an unrecognized kind of sort\",\n\t\t\t str);\n\t\treturn PY_FAIL;\n\t}\n\treturn PY_SUCCEED;\n}\n\n\n/* This function returns true if the two typecodes are \n equivalent (same basic kind and same itemsize).\n*/\n\n/*MULTIARRAY_API*/\nstatic Bool\nPyArray_EquivTypes(PyArray_Descr *typ1, PyArray_Descr *typ2)\n{\n\tregister int typenum1=typ1->type_num;\n\tregister int typenum2=typ2->type_num;\n\tregister int size1=typ1->elsize;\n\tregister int size2=typ2->elsize;\n\n\tif (size1 != size2) return FALSE;\n\tif (typ1->fields != typ2->fields) return FALSE;\n\tif (PyArray_ISNBO(typ1->byteorder) != PyArray_ISNBO(typ2->byteorder))\n\t\treturn FALSE;\n\n\tif (typenum1 == PyArray_VOID || \\\n\t typenum2 == PyArray_VOID) {\n\t\treturn ((typenum1 == typenum2) && \n\t\t\t(typ1->typeobj == typ2->typeobj) &&\n\t\t\t(typ1->fields == typ2->fields));\n\t}\n\treturn (typ1->kind == typ2->kind);\n}\n\n/*** END C-API FUNCTIONS **/\n\n\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_fromobject[] = \"array(object, dtype=None, copy=1, fortran=0, \"\\\n \"subok=0)\\n\"\\\n \"will return a new array formed from the given object type given.\\n\"\\\n \"Object can anything with an __array__ method, or any object\\n\"\\\n \"exposing the array interface, or any (nested) sequence.\\n\"\\\n \"If no type is given, then the type will be determined as the\\n\"\\\n \"minimum type required to hold the objects in the sequence.\\n\"\\\n \"If copy is zero and sequence is already an array with the right \\n\"\\\n \"type, a reference will be returned. If the sequence is an array,\\n\"\\\n \"type can be used only to upcast the array. For downcasting \\n\"\\\n \"use .astype(t) method. If subok is true, then subclasses of the\\n\"\\\n \"array may be returned. Otherwise, a base-class ndarray is returned\";\n\nstatic PyObject *\n_array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n{\n\tPyObject *op, *ret=NULL;\n\tstatic char *kwd[]= {\"object\", \"dtype\", \"copy\", \"fortran\", \"subok\", \n NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tPyArray_Descr *type=NULL;\n\tPyArray_Descr *oldtype=NULL;\n\tBool fortran=FALSE;\n\tint flags=0;\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&\", kwd, &op, \n\t\t\t\t\tPyArray_DescrConverter2,\n &type, \n\t\t\t\t\tPyArray_BoolConverter, ©, \n\t\t\t\t\tPyArray_BoolConverter, &fortran,\n PyArray_BoolConverter, &subok)) \n\t\treturn NULL;\n\n\t/* fast exit if simple call */\n\tif ((PyArray_CheckExact(op) || PyBigArray_CheckExact(op))) {\n\t\tif (type==NULL) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\treturn op;\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn PyArray_NewCopy((PyArrayObject*)op, \n\t\t\t\t\t\t fortran);\n\t\t\t}\n\t\t}\n\t\t/* One more chance */\n\t\toldtype = PyArray_DESCR(op);\n\t\tif (PyArray_EquivTypes(oldtype, type)) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\treturn op;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op,\n\t\t\t\t\t\t fortran);\n\t\t\t\tif (oldtype == type) return ret;\n\t\t\t\tPy_INCREF(oldtype);\n\t\t\t\tPy_DECREF(PyArray_DESCR(ret));\n\t\t\t\tPyArray_DESCR(ret) = oldtype;\n\t\t\t\treturn ret;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (copy) {\n\t\tflags = ENSURECOPY;\n\t}\n\tif (fortran) {\n\t\tflags |= FORTRAN;\n\t}\n if (!subok) {\n flags |= ENSUREARRAY;\n }\n\n\tif ((ret = PyArray_FromAny(op, type, 0, 0, flags)) == NULL) \n\t\treturn NULL;\n\n\treturn ret;\n}\n\n/* accepts NULL type */\n/* steals referenct to type */\n/*MULTIARRAY_API\n Empty\n*/\nstatic PyObject *\nPyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n \n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type, nd, dims, \n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n PyArray_FillObjectArray(ret, Py_None);\n\t}\n\treturn (PyObject *)ret;\n}\n\n\nstatic char doc_empty[] = \"empty((d1,...,dn),dtype=int,fortran=0) will return a new array\\n of shape (d1,...,dn) and given type with all its entries uninitialized. This can be faster than zeros.\";\n\nstatic PyObject *\narray_empty(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter, &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Empty(shape.len, shape.ptr, typecode, fortran); \n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_scalar[] = \"scalar(dtypedescr,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtypedescr must be a valid data-type descriptor. If dtypedescr corresponds to an OBJECT descriptor, then obj can be any object, otherwise obj must be a string. If obj is not given it will be interpreted as None for object type and zeros for all other types.\";\n\nstatic PyObject *\narray_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"dtypedescr\",\"obj\", NULL};\n\tPyArray_Descr *typecode;\n\tPyObject *obj=NULL;\n\tint alloc=0;\n\tvoid *dptr;\n\tPyObject *ret;\n\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|O\",\n\t\t\t\t\t kwlist, &PyArrayDescr_Type, \n\t\t\t\t\t &typecode,\n\t\t\t\t\t &obj)) \n\t\treturn NULL;\n\t\t\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\t\t\\\n\t\t\t\t\"itemsize cannot be zero\");\n\t\treturn NULL;\n\t}\n\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (obj == NULL) obj = Py_None;\n\t\tdptr = &obj;\n\t}\n\telse {\n\t\tif (obj == NULL) {\n\t\t\tdptr = _pya_malloc(typecode->elsize);\n\t\t\tif (dptr == NULL) {\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemset(dptr, '\\0', typecode->elsize);\n\t\t\talloc = 1;\n\t\t}\n\t\telse {\n\t\t\tif (!PyString_Check(obj)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"initializing object must \"\\\n\t\t\t\t\t\t\"be a string\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tif (PyString_GET_SIZE(obj) < typecode->elsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"initialization string is too\"\\\n\t\t\t\t\t\t\" small\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdptr = PyString_AS_STRING(obj);\n\t\t}\n\t}\n\n\tret = PyArray_Scalar(dptr, typecode, NULL);\n\t\n\t/* free dptr which contains zeros */\n\tif (alloc) _pya_free(dptr);\n\treturn ret;\n}\n\n\n/* steal a reference */\n/* accepts NULL type */\n/*MULTIARRAY_API\n Zeros\n*/\nstatic PyObject *\nPyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n\tintp n;\n\n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type,\n\t\t\t\t\t\t nd, dims, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n\t\tPyObject *zero = PyInt_FromLong(0);\n PyArray_FillObjectArray(ret, zero);\n Py_DECREF(zero);\n\t}\n\telse {\n\t\tn = PyArray_NBYTES(ret);\n\t\tmemset(ret->data, 0, n);\n\t}\n\treturn (PyObject *)ret;\n\n}\n\nstatic char doc_zeros[] = \"zeros((d1,...,dn),dtype=int,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.\";\n\n\nstatic PyObject *\narray_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Zeros(shape.len, shape.ptr, typecode, (int) fortran);\n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_set_typeDict[] = \"set_typeDict(dict) set the internal \"\\\n\t\"dictionary that can look up an array type using a registered \"\\\n\t\"code\";\n\nstatic PyObject *\narray_set_typeDict(PyObject *ignored, PyObject *args)\n{\n\tPyObject *dict;\n\tif (!PyArg_ParseTuple(args, \"O\", &dict)) return NULL;\n\tPy_XDECREF(typeDict); /* Decrement old reference (if any)*/\n\ttypeDict = dict;\n\tPy_INCREF(dict); /* Create an internal reference to it */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, intp n)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\n\t\n\tif (dtype == &OBJECT_Descr) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Cannot create an object array from a\"\\\n\t\t\t\t\" string.\");\n\t\tPy_DECREF(dtype);\n\t\treturn NULL;\n\t}\n\t\n\titemsize = dtype->elsize;\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"zero-valued itemsize\");\n\t\tPy_DECREF(dtype);\n\t\treturn NULL;\n\t}\n\t\n\tif (n < 0 ) {\n\t\tif (slen % itemsize != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"string size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\t\tn = slen/itemsize;\n\t} else {\n\t\tif (slen < n*itemsize) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"string is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t dtype,\n\t\t\t\t\t\t\t 1, &n, \n\t\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t\t 0, NULL)) == NULL)\n\t\treturn NULL;\n\t\t\n\tmemcpy(ret->data, data, n*dtype->elsize);\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_fromString[] = \"fromstring(string, dtype=int, count=-1) returns a new 1d array initialized from the raw binary data in string. If count is positive, the new array will have count elements, otherwise it's size is determined by the size of string.\";\n\nstatic PyObject *\narray_fromString(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tchar *data;\n\tlonglong nin=-1;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&L\", kwlist, \n\t\t\t\t\t &data, &s, \n\t\t\t\t\t PyArray_DescrConverter, &descr,\n\t\t\t\t\t &nin)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin);\n}\n\n/* This needs an open file object and reads it in directly. \n memory-mapped files handled differently through buffer interface.\n\nfile pointer number in resulting 1d array \n(can easily reshape later, -1 for to end of file)\ntype of array\nsep is a separator string for character-based data (or NULL for binary)\n \" \" means whitespace\n*/\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep)\n{\n\tPyArrayObject *r;\n\tsize_t nread = 0;\n\tPyArray_ScanFunc *scan;\n\tBool binary;\n\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"0-sized elements.\");\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\n\tif (num == -1 && binary) { /* Get size for binary file*/\n\t\tintp start, numbytes;\n\t\tstart = (intp )ftell(fp);\n\t\tfseek(fp, 0, SEEK_END);\n\t\tnumbytes = (intp )ftell(fp) - start;\n\t\trewind(fp);\n\t\tif (numbytes == -1) {\n\t\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\t\"could not seek in file\");\n\t\t\treturn NULL;\n\t\t}\n\t\tnum = numbytes / typecode->elsize;\n\t}\n\t\n\tif (binary) { /* binary data */\n\t\tr = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t 0, NULL);\n\t\tif (r==NULL) return NULL;\n\t\tnread = fread(r->data, typecode->elsize, num, fp);\n\t}\n\telse { /* character reading */\n\t\tintp i;\n\t\tchar *dptr;\n\t\tint done=0;\n\n\t\tscan = typecode->f->scanfunc;\n\t\tif (scan == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character files with that \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (num != -1) { /* number to read is known */\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode, \n\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\tdptr = r->data;\n\t\t\tfor (i=0; i < num; i++) {\n\t\t\t\tif (done) break;\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\t\t\t\tif (done < -2) break;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\telse { /* we have to watch for the end of the file and \n\t\t\t reallocate at the end */\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * typecode->elsize;\n\t\t\tdptr = r->data;\n\t\t\twhile (!done) {\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\n\t\t\t\t/* end of file reached trying to \n\t\t\t\t scan value. done is 1 or 2\n\t\t\t\t if end of file reached trying to\n\t\t\t\t scan separator. Still good value.\n\t\t\t\t*/\n\t\t\t\tif (done < -2) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t\tif (!done && thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tr->data = PyDataMem_RENEW(r->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = r->data + (totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tr->data = PyDataMem_RENEW(r->data, nread*r->descr->elsize);\n\t\t\tPyArray_DIM(r,0) = nread;\n\t\t\tnum = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\tif (nread < num) {\n\t\tfprintf(stderr, \"%ld items requested but only %ld read\\n\", \n\t\t\t(long) num, (long) nread);\n\t\tr->data = PyDataMem_RENEW(r->data, nread * r->descr->elsize);\n\t\tPyArray_DIM(r,0) = nread;\n\t}\n\treturn (PyObject *)r;\n}\n\nstatic char doc_fromfile[] = \\\n\t\"fromfile(file=, dtype=int, count=-1, sep='')\\n\"\t\\\n\t\"\\n\"\\\n\t\" Return an array of the given data type from a \\n\"\\\n\t\" (text or binary) file. The file argument can be an open file\\n\"\\\n\t\" or a string with the name of a file to read from. If\\n\"\\\n\t\" count==-1, then the entire file is read, otherwise count is\\n\"\\\n\t\" the number of items of the given type read in. If sep is ''\\n\"\\\n\t\" then read a binary file, otherwise it gives the separator\\n\"\\\n\t\" between elements in a text file.\\n\"\\\n\t\"\\n\"\\\n\t\" WARNING: This function should be used sparingly, as it is not\\n\"\\\n\t\" a robust method of persistence. But it can be useful to\\n\"\\\n\t\" read in simply-formatted or binary data quickly.\";\n\nstatic PyObject *\narray_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *file=NULL, *ret;\n\tFILE *fp;\n\tchar *sep=\"\";\n\tchar *mode=NULL;\n\tlonglong nin=-1;\n\tstatic char *kwlist[] = {\"file\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *type=NULL;\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Ls\", kwlist, \n\t\t\t\t\t &file,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\tif (type == NULL) type = PyArray_DescrFromType(PyArray_LONG);\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"rb\";\n\t\telse mode=\"r\";\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), mode);\n\t\tif (file==NULL) return NULL;\n\t}\n\telse {\n\t\tPy_INCREF(file);\n\t}\n\tfp = PyFile_AsFile(file);\n\tif (fp == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\"first argument must be an open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_FromFile(fp, type, (intp) nin, sep);\n\tPy_DECREF(file);\n\treturn ret;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, \n\t\t intp count, intp offset) \n{\n\tPyArrayObject *ret;\n\tchar *data;\n\tint ts;\n\tintp s, n;\n\tint itemsize;\n\tint write=1;\n\n\n\tif (type->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot create an OBJECT array from memory\"\\\n\t\t\t\t\" buffer\");\n\t\tPy_DECREF(type);\n\t\treturn NULL;\n\t}\n\tif (type->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"itemsize cannot be zero in type\");\n\t\tPy_DECREF(type);\n\t\treturn NULL; \t\t\n\t}\n\n\tif (buf->ob_type->tp_as_buffer == NULL || \\\n\t (buf->ob_type->tp_as_buffer->bf_getwritebuffer == NULL &&\t\\\n\t buf->ob_type->tp_as_buffer->bf_getreadbuffer == NULL)) {\n\t\tPyObject *newbuf;\n\t\tnewbuf = PyObject_GetAttrString(buf, \"__buffer__\");\n\t\tif (newbuf == NULL) {Py_DECREF(type); return NULL;}\n\t\tbuf = newbuf;\n\t}\n\telse {Py_INCREF(buf);}\n\n\tif (PyObject_AsWriteBuffer(buf, (void *)&data, &ts)==-1) {\n\t\twrite = 0;\n\t\tPyErr_Clear();\n\t\tif (PyObject_AsReadBuffer(buf, (void *)&data, &ts)==-1) {\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((offset < 0) || (offset >= ts)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"offset must be positive and smaller than %\"\n\t\t\t INTP_FMT, (intp)ts);\n\t}\n\n\tdata += offset;\n\ts = (intp)ts - offset;\n\tn = (intp)count;\n\titemsize = type->elsize;\n\t\n\tif (n < 0 ) {\n\t\tif (s % itemsize != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tn = s/itemsize;\n\t} else {\n\t\tif (s < n*itemsize) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t type, \n\t\t\t\t\t\t\t 1, &n, \n\t\t\t\t\t\t\t NULL, data, \n\t\t\t\t\t\t\t DEFAULT_FLAGS,\n\t\t\t\t\t\t\t NULL)) == NULL) {\n\t\tPy_DECREF(buf);\n\t\treturn NULL;\n\t}\n\t\n\tif (!write) ret->flags &= ~WRITEABLE;\n\n\t/* Store a reference for decref on deallocation */\n\tret->base = buf;\n\tPyArray_UpdateFlags(ret, ALIGNED);\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_frombuffer[] = \\\n\t\"frombuffer(buffer=, dtype=int, count=-1, offset=0)\\n\"\\\n\t\"\\n\"\t\t\t\t\t\t\t\t\\\n\t\" Returns a 1-d array of data type dtype from buffer. The buffer\\n\"\\\n\t\" argument must be an object that exposes the buffer interface.\\n\"\\\n\t\" If count is -1 then the entire buffer is used, otherwise, count\\n\"\\\n\t\" is the size of the output. If offset is given then jump that\\n\"\\\n\t\" far into the buffer. If the buffer has data that is out\\n\" \\\n\t\" not in machine byte-order, than use a propert data type\\n\"\\\n\t\" descriptor. The data will not\\n\" \\\n\t\" be byteswapped, but the array will manage it in future\\n\"\\\n\t\" operations.\\n\";\n\nstatic PyObject *\narray_frombuffer(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *obj=NULL;\n\tlonglong nin=-1, offset=0;\n\tstatic char *kwlist[] = {\"buffer\", \"dtype\", \"count\", \"offset\", NULL};\n\tPyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&LL\", kwlist, \n\t\t\t\t\t &obj,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &offset)) {\n\t\treturn NULL;\n\t}\n\tif (type==NULL)\n\t\ttype = PyArray_DescrFromType(PyArray_LONG);\n\t\n\treturn PyArray_FromBuffer(obj, type, (intp)nin, (intp)offset);\n}\n\n\nstatic char doc_concatenate[] = \"concatenate((a1,a2,...),axis=None).\";\n\nstatic PyObject *\narray_concatenate(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *a0;\n\tint axis=0;\n\tstatic char *kwlist[] = {\"seq\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist,\n\t\t\t\t\t &a0,\n\t\t\t\t\t PyArray_AxisConverter, &axis))\n\t\treturn NULL;\n\treturn PyArray_Concatenate(a0, axis);\n}\n\nstatic char doc_innerproduct[] = \\\n\t\"inner(a,b) returns the dot product of two arrays, which has\\n\"\\\n\t\"shape a.shape[:-1] + b.shape[:-1] with elements computed by\\n\" \\\n\t\"the product of the elements from the last dimensions of a and b.\";\n\nstatic PyObject *array_innerproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *b0, *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a0, &b0)) return NULL;\n\t\n\treturn _ARET(PyArray_InnerProduct(a0, b0));\n}\n\nstatic char doc_matrixproduct[] = \\\n\t\"dot(a,v) returns matrix-multiplication between a and b. \\n\"\\\n\t\"The product-sum is over the last dimension of a and the \\n\"\\\n\t\"second-to-last dimension of b.\";\n\nstatic PyObject *array_matrixproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *v, *a;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a, &v)) return NULL;\n\t\n\treturn _ARET(PyArray_MatrixProduct(a, v));\n}\n\nstatic char doc_fastCopyAndTranspose[] = \"_fastCopyAndTranspose(a)\";\n\nstatic PyObject *array_fastCopyAndTranspose(PyObject *dummy, PyObject *args) {\n\tPyObject *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &a0)) return NULL;\n\t\n\treturn _ARET(PyArray_CopyAndTranspose(a0));\n}\n\nstatic char doc_correlate[] = \"cross_correlate(a,v, mode=0)\";\n\nstatic PyObject *array_correlate(PyObject *dummy, PyObject *args, PyObject *kwds) {\n\tPyObject *shape, *a0;\n\tint mode=0;\n\tstatic char *kwlist[] = {\"a\", \"v\", \"mode\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO|i\", kwlist, \n\t\t\t\t\t &a0, &shape, &mode)) return NULL;\n\t\n\treturn PyArray_Correlate(a0, shape, mode);\n}\n\n\n/*MULTIARRAY_API\n Arange, \n*/\nstatic PyObject *\nPyArray_Arange(double start, double stop, double step, int type_num)\n{\n\tintp length;\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *obj;\n\tint ret;\n\n\tlength = (intp ) ceil((stop - start)/step);\n \n\tif (length <= 0) {\n\t\tlength = 0;\n\t\treturn PyArray_New(&PyArray_Type, 1, &length, type_num,\n\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t}\n\n\trange = PyArray_New(&PyArray_Type, 1, &length, type_num, \n\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (range == NULL) return NULL;\n\n\tfuncs = PyArray_DESCR(range)->f; \n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tobj = PyFloat_FromDouble(start);\n\tret = funcs->setitem(obj, PyArray_DATA(range), (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 1) return range;\n\n\tobj = PyFloat_FromDouble(start + step);\n\tret = funcs->setitem(obj, PyArray_DATA(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 2) return range;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\treturn NULL;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\t\n\treturn range;\n\n fail:\n\tPy_DECREF(range);\n\treturn NULL;\n}\n\n/* the formula is \n len = (intp) ceil((start - stop) / step);\n*/\nstatic intp\n_calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, int cmplx)\n{\n\tintp len;\n\tPyObject *val;\n\tdouble value;\n\t\n\t*next = PyNumber_Subtract(stop, start);\n\tif (!(*next)) return -1;\n\tval = PyNumber_TrueDivide(*next, step);\n\tPy_DECREF(*next); *next=NULL;\n\tif (!val) return -1;\n\tif (cmplx && PyComplex_Check(val)) {\n\t\tvalue = PyComplex_RealAsDouble(val);\n\t\tif (error_converting(value)) {Py_DECREF(val); return -1;}\n\t\tlen = (intp) ceil(value);\n\t\tvalue = PyComplex_ImagAsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = MIN(len, (intp) ceil(value));\n\t}\n\telse {\n\t\tvalue = PyFloat_AsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = (intp) ceil(value);\n\t}\n\t\n\tif (len > 0) {\n\t\t*next = PyNumber_Add(start, step);\n\t\tif (!next) return -1;\n\t}\n\treturn len;\n}\n\n/* this doesn't change the references */\n/*MULTIARRAY_API\n ArangeObj,\n*/\nstatic PyObject *\nPyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr *dtype) \n{\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *next;\n\tintp length;\n\n\tif (!dtype) {\n\t\tPyArray_Descr *deftype;\n\t\tPyArray_Descr *newtype;\n\t\tdeftype = PyArray_DescrFromType(PyArray_LONG);\n\t\tnewtype = PyArray_DescrFromObject(start, deftype);\n\t\tPy_DECREF(deftype);\n\t\tdeftype = newtype;\n\t\tif (stop && stop != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(stop, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tif (step && step != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(step, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tdtype = deftype;\n\t}\n\telse Py_INCREF(dtype);\n\n\tif (!step || step == Py_None) {\n\t\tstep = PyInt_FromLong(1);\n\t}\n\telse Py_XINCREF(step);\n\n\tif (!stop || stop == Py_None) {\n\t\tstop = start;\n\t\tstart = PyInt_FromLong(0);\n\t}\n\telse Py_INCREF(start);\n\n\t/* calculate the length and next = start + step*/\n\tlength = _calc_length(start, stop, step, &next, \n\t\t\t PyTypeNum_ISCOMPLEX(dtype->type_num));\n\n\tif (PyErr_Occurred()) {Py_DECREF(dtype); goto fail;}\n\tif (length <= 0) {\n\t\tlength = 0;\n\t\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\t\tPy_DECREF(step); Py_DECREF(start); return range;\n\t}\n\n\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\tif (range == NULL) goto fail;\n\n\tfuncs = PyArray_DESCR(range)->f;\n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tif (funcs->setitem(start, PyArray_DATA(range), (PyArrayObject *)range) < 0)\n\t\tgoto fail;\n\tif (length == 1) goto finish;\n\tif (funcs->setitem(next, PyArray_DATA(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range) < 0) goto fail;\n\tif (length == 2) goto finish;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\tgoto fail;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\n finish:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_DECREF(next);\n\treturn range;\n\t\n fail:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_XDECREF(next);\n\treturn NULL;\n}\n\n\nstatic char doc_arange[] = \"arange(start, stop=None, step=1, dtype=int)\\n\\n Just like range() except it returns an array whose type can be\\n specified by the keyword argument typecode.\";\n\nstatic PyObject *\narray_arange(PyObject *ignored, PyObject *args, PyObject *kws) {\n\tPyObject *o_start=NULL, *o_stop=NULL, *o_step=NULL;\n\tstatic char *kwd[]= {\"start\", \"stop\", \"step\", \"dtype\", NULL};\n\tPyArray_Descr *typecode=NULL;\n\t\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|OOO&\", kwd, &o_start,\n\t\t\t\t\t&o_stop, &o_step, \n\t\t\t\t\tPyArray_DescrConverter, \n\t\t\t\t\t&typecode)) \n\t\treturn NULL;\n\n\treturn PyArray_ArangeObj(o_start, o_stop, o_step, typecode);\n}\n\n\nstatic char \ndoc_set_string_function[] = \"set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.\";\n\nstatic PyObject *\narray_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *op;\n\tint repr=1;\n\tstatic char *kwlist[] = {\"f\", \"repr\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|i\", kwlist, \n\t\t\t\t\t&op, &repr)) return NULL; \n\tif (!PyCallable_Check(op)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"Argument must be callable.\");\n\t\treturn NULL;\n\t}\n\tPyArray_SetStringFunction(op, repr);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char \ndoc_set_ops_function[] = \"set_numeric_ops(op=func, ...) sets some or all of the number methods for all array objects. Don't forget **dict can be used as the argument list. Returns the functions that were replaced -- can be stored and set later.\";\n\nstatic PyObject *\narray_set_ops_function(PyObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *oldops=NULL;\n\t\n\tif ((oldops = PyArray_GetNumericOps())==NULL) return NULL;\n\n\t/* Should probably ensure that objects are at least callable */\n\t/* Leave this to the caller for now --- error will be raised\n\t later when use is attempted \n\t*/\n\tif (kwds && PyArray_SetNumericOps(kwds) == -1) {\n\t\tPy_DECREF(oldops);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"one or more objects not callable\");\n\t\treturn NULL;\n\t}\n\treturn oldops;\n}\n\n\n/*MULTIARRAY_API\n Where\n*/\nstatic PyObject *\nPyArray_Where(PyObject *condition, PyObject *x, PyObject *y)\n{\n\tPyArrayObject *arr;\n\tPyObject *tup=NULL, *obj=NULL;\n\tPyObject *ret=NULL, *zero=NULL;\n\n\n\tarr = (PyArrayObject *)PyArray_FromAny(condition, NULL, 0, 0, 0);\n\tif (arr == NULL) return NULL;\n\n\tif ((x==NULL) && (y==NULL)) {\n\t\tret = PyArray_Nonzero(arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\n\tif ((x==NULL) || (y==NULL)) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \"either both or neither \"\n\t\t\t\t\"of x and y should be given\");\n\t\treturn NULL;\n\t}\n\n\n\tzero = PyInt_FromLong((long) 0);\n\n\tobj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, \n\t\t\t\t\t\t\t\tn_ops.not_equal));\n\tPy_DECREF(zero);\n\tPy_DECREF(arr);\n\tif (obj == NULL) return NULL;\n\n\ttup = Py_BuildValue(\"(OO)\", y, x);\n\tif (tup == NULL) {Py_DECREF(obj); return NULL;}\n\n\tret = PyArray_Choose((PyAO *)obj, tup);\n\n\tPy_DECREF(obj);\n\tPy_DECREF(tup);\n\treturn ret;\n}\n\nstatic char doc_where[] = \"where(condition, | x, y) is shaped like condition\"\\\n\t\" and has elements of x and y where condition is respectively true or\"\\\n\t\" false. If x or y are not given, then it is equivalent to\"\\\n\t\" nonzero(condition).\";\n\nstatic PyObject *\narray_where(PyObject *ignored, PyObject *args)\n{\n\tPyObject *obj=NULL, *x=NULL, *y=NULL;\n\t\n\tif (!PyArg_ParseTuple(args, \"O|OO\", &obj, &x, &y)) return NULL;\n\n\treturn PyArray_Where(obj, x, y);\n\n}\n\nstatic char doc_lexsort[] = \"lexsort(keys=, axis=-1) returns an array of indexes\"\\\n\t\" similar to argsort except the sorting is done using the provided sorting\"\\\n\t\" keys. First the sort is done using key[0], then the resulting list of\"\\\n\t\" indexes is further manipulated by sorting on key[0]. And so forth\"\\\n\t\" The result is a sort on multiple keys. If the keys represented columns\" \\\n\t\" of a spread-sheet, for example, this would sort using multiple columns.\"\\\n\t\" The keys argument must be a tuple of things that can be converted to \"\\\n\t\" arrays of the same shape.\";\n\nstatic PyObject *\narray_lexsort(PyObject *ignored, PyObject *args, PyObject *kwds)\n{\n\tint axis=-1;\n\tPyObject *obj;\n\tstatic char *kwlist[] = {\"keys\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|i\", kwlist, \n\t\t\t\t\t &PyTuple_Type, &obj, &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_LexSort(obj, axis));\n}\n\n#undef _ARET\n\n\nstatic char doc_register_dtype[] = \\\n\t\"register_dtype(a) registers a new type object -- gives it a typenum\";\n\nstatic PyObject *\narray_register_dtype(PyObject *dummy, PyObject *args)\n{\n\tPyObject *dtype;\n\tint ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &dtype)) return NULL;\n\t\n\tret = PyArray_RegisterDataType((PyTypeObject *)dtype);\n\tif (ret < 0)\n\t\treturn NULL;\n\treturn PyInt_FromLong((long) ret);\n}\n\nstatic char doc_can_cast_safely[] = \\\n\t\"can_cast_safely(from=d1, to=d2) returns True if data type d1 \"\\\n\t\"can be cast to data type d2 without losing precision.\";\n\nstatic PyObject *\narray_can_cast_safely(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *d1=NULL;\n\tPyArray_Descr *d2=NULL;\n\tBool ret;\n\tPyObject *retobj;\n\tstatic char *kwlist[] = {\"from\", \"to\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O&O&\", kwlist, \n\t\t\t\t\tPyArray_DescrConverter, &d1,\n\t\t\t\t\tPyArray_DescrConverter, &d2))\n\t\treturn NULL;\n\tif (d1 == NULL || d2 == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"did not understand one of the types; \"\t\\\n\t\t\t\t\"'None' not accepted\");\n\t\treturn NULL;\n\t}\n\t\t\n\tret = PyArray_CanCastTo(d1, d2);\n\tretobj = (ret ? Py_True : Py_False);\n\tPy_INCREF(retobj);\n\treturn retobj;\n}\n\nstatic char doc_new_buffer[] = \\\n\t\"newbuffer(size) return a new uninitialized buffer object of size \"\n\t\"bytes\";\n\nstatic PyObject *\nnew_buffer(PyObject *dummy, PyObject *args)\n{\n\tint size;\n\n\tif(!PyArg_ParseTuple(args, \"i\", &size))\n\t\treturn NULL;\n\t\n\treturn PyBuffer_New(size);\n}\n\nstatic char doc_buffer_buffer[] = \\\n\t\"getbuffer(obj [,offset[, size]]) create a buffer object from the \"\\\n\t\"given object\\n referencing a slice of length size starting at \"\\\n\t\"offset. Default\\n is the entire buffer. A read-write buffer is \"\\\n\t\"attempted followed by a read-only buffer.\";\n\nstatic PyObject *\nbuffer_buffer(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj;\n\tint offset=0, size=Py_END_OF_BUFFER, n;\n\tvoid *unused;\n\tstatic char *kwlist[] = {\"object\", \"offset\", \"size\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ii\", kwlist, \n\t\t\t\t\t &obj, &offset, &size))\n\t\treturn NULL;\n\n\n\tif (PyObject_AsWriteBuffer(obj, &unused, &n) < 0) {\n\t\tPyErr_Clear();\n\t\treturn PyBuffer_FromObject(obj, offset, size);\t\t\n\t}\n\telse\n\t\treturn PyBuffer_FromReadWriteObject(obj, offset, size);\n}\n\n\nstatic struct PyMethodDef array_module_methods[] = {\n\t{\"set_string_function\", (PyCFunction)array_set_string_function, \n\t METH_VARARGS|METH_KEYWORDS, doc_set_string_function},\n\t{\"set_numeric_ops\", (PyCFunction)array_set_ops_function,\n\t METH_VARARGS|METH_KEYWORDS, doc_set_ops_function},\n\t{\"set_typeDict\", (PyCFunction)array_set_typeDict,\n\t METH_VARARGS, doc_set_typeDict},\n\n\t{\"array\",\t(PyCFunction)_array_fromobject, \n\t METH_VARARGS|METH_KEYWORDS, doc_fromobject},\n\t{\"arange\", (PyCFunction)array_arange, \n\t METH_VARARGS|METH_KEYWORDS, doc_arange},\n\t{\"zeros\",\t(PyCFunction)array_zeros, \n\t METH_VARARGS|METH_KEYWORDS, doc_zeros},\n\t{\"empty\",\t(PyCFunction)array_empty, \n\t METH_VARARGS|METH_KEYWORDS, doc_empty},\n\t{\"scalar\", (PyCFunction)array_scalar,\n\t METH_VARARGS|METH_KEYWORDS, doc_scalar},\n\t{\"where\", (PyCFunction)array_where,\n\t METH_VARARGS, doc_where},\n\t{\"lexsort\", (PyCFunction)array_lexsort,\n\t METH_VARARGS | METH_KEYWORDS, doc_lexsort},\n\t{\"fromstring\",(PyCFunction)array_fromString,\n\t METH_VARARGS|METH_KEYWORDS, doc_fromString},\n\t{\"concatenate\", (PyCFunction)array_concatenate, \n\t METH_VARARGS|METH_KEYWORDS, doc_concatenate},\n\t{\"inner\", (PyCFunction)array_innerproduct, \n\t METH_VARARGS, doc_innerproduct}, \n\t{\"dot\", (PyCFunction)array_matrixproduct, \n\t METH_VARARGS, doc_matrixproduct}, \n\t{\"_fastCopyAndTranspose\", (PyCFunction)array_fastCopyAndTranspose, \n\t METH_VARARGS, doc_fastCopyAndTranspose},\n\t{\"correlate\", (PyCFunction)array_correlate, \n\t METH_VARARGS | METH_KEYWORDS, doc_correlate},\n\t{\"frombuffer\", (PyCFunction)array_frombuffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_frombuffer},\n\t{\"fromfile\", (PyCFunction)array_fromfile,\n\t METH_VARARGS | METH_KEYWORDS, doc_fromfile},\n\t{\"register_dtype\", (PyCFunction)array_register_dtype,\n\t METH_VARARGS, doc_register_dtype},\n\t{\"can_cast\", (PyCFunction)array_can_cast_safely,\n\t METH_VARARGS | METH_KEYWORDS, doc_can_cast_safely},\t\t\n\t{\"newbuffer\", (PyCFunction)new_buffer,\n\t METH_VARARGS, doc_new_buffer},\t\n\t{\"getbuffer\", (PyCFunction)buffer_buffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_buffer_buffer},\t\n\t{NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n#include \"__multiarray_api.c\"\n\n/* Establish scalar-type hierarchy */\n\n/* For dual inheritance we need to make sure that the objects being\n inherited from have the tp->mro object initialized. This is\n not necessarily true for the basic type objects of Python (it is \n checked for single inheritance but not dual in PyType_Ready).\n\n Thus, we call PyType_Ready on the standard Python Types, here.\n*/ \nstatic int\nsetup_scalartypes(PyObject *dict)\n{\n\n\tinitialize_numeric_types();\n\n if (PyType_Ready(&PyBool_Type) < 0) return -1;\n if (PyType_Ready(&PyInt_Type) < 0) return -1;\n if (PyType_Ready(&PyFloat_Type) < 0) return -1;\n if (PyType_Ready(&PyComplex_Type) < 0) return -1;\n if (PyType_Ready(&PyString_Type) < 0) return -1;\n if (PyType_Ready(&PyUnicode_Type) < 0) return -1;\n\n#define SINGLE_INHERIT(child, parent) \\\n Py##child##ArrType_Type.tp_base = &Py##parent##ArrType_Type;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) {\t\t\\\n PyErr_Print(); \\\n PyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1;\t\t\t\t\t\t\\\n }\n \n if (PyType_Ready(&PyGenericArrType_Type) < 0)\n return -1;\n\n SINGLE_INHERIT(Number, Generic);\n SINGLE_INHERIT(Integer, Number);\n SINGLE_INHERIT(Inexact, Number);\n SINGLE_INHERIT(SignedInteger, Integer);\n SINGLE_INHERIT(UnsignedInteger, Integer);\n SINGLE_INHERIT(Floating, Inexact);\n SINGLE_INHERIT(ComplexFloating, Inexact);\n SINGLE_INHERIT(Flexible, Generic);\n SINGLE_INHERIT(Character, Flexible);\n\t\n#define DUAL_INHERIT(child, parent1, parent2) \\\n Py##child##ArrType_Type.tp_base = &Py##parent2##ArrType_Type;\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent2##ArrType_Type,\t\\\n\t\t\t &Py##parent1##_Type);\t\t\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\n\n#define DUAL_INHERIT2(child, parent1, parent2)\t\t\t\t\\\n Py##child##ArrType_Type.tp_base = &Py##parent1##_Type;\t\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent1##_Type,\t\t\\\n\t\t\t &Py##parent2##ArrType_Type);\t\t\\\n\tPy##child##ArrType_Type.tp_richcompare =\t\t\t\\\n\t\tPy##parent1##_Type.tp_richcompare;\t\t\t\\\n\tPy##child##ArrType_Type.tp_compare =\t\t\t\t\\\n\t\tPy##parent1##_Type.tp_compare;\t\t\t\t\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\n\n SINGLE_INHERIT(Bool, Generic);\n SINGLE_INHERIT(Byte, SignedInteger);\n SINGLE_INHERIT(Short, SignedInteger);\n#if SIZEOF_INT == SIZEOF_LONG\n DUAL_INHERIT(Int, Int, SignedInteger);\n#else\n SINGLE_INHERIT(Int, SignedInteger);\n#endif\n DUAL_INHERIT(Long, Int, SignedInteger);\n#if SIZEOF_LONGLONG == SIZEOF_LONG\n DUAL_INHERIT(LongLong, Int, SignedInteger);\n#else\n SINGLE_INHERIT(LongLong, SignedInteger);\n#endif\n\n /* fprintf(stderr, \"tp_free = %p, PyObject_Del = %p, int_tp_free = %p, base.tp_free = %p\\n\", PyIntArrType_Type.tp_free, PyObject_Del, PyInt_Type.tp_free, PySignedIntegerArrType_Type.tp_free);\n\t */\n\tSINGLE_INHERIT(UByte, UnsignedInteger);\n SINGLE_INHERIT(UShort, UnsignedInteger);\n SINGLE_INHERIT(UInt, UnsignedInteger);\n SINGLE_INHERIT(ULong, UnsignedInteger);\n SINGLE_INHERIT(ULongLong, UnsignedInteger);\n\n SINGLE_INHERIT(Float, Floating);\n DUAL_INHERIT(Double, Float, Floating);\n SINGLE_INHERIT(LongDouble, Floating);\n\n SINGLE_INHERIT(CFloat, ComplexFloating);\n DUAL_INHERIT(CDouble, Complex, ComplexFloating);\n SINGLE_INHERIT(CLongDouble, ComplexFloating);\n\n DUAL_INHERIT2(String, String, Character);\n DUAL_INHERIT2(Unicode, Unicode, Character);\n\t\n SINGLE_INHERIT(Void, Flexible);\n \n SINGLE_INHERIT(Object, Generic);\n\n return 0;\n\n#undef SINGLE_INHERIT\n#undef DUAL_INHERIT\n\n\t/* Clean up string and unicode array types so they act more like\n\t strings -- get their tables from the standard types.\n\t*/\n}\n\n/* place a flag dictionary in d */\n\nstatic void\nset_flaginfo(PyObject *d)\n{\n PyObject *s;\n PyObject *newd;\n \n newd = PyDict_New();\n\n PyDict_SetItemString(newd, \"OWNDATA\", s=PyInt_FromLong(OWNDATA));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"FORTRAN\", s=PyInt_FromLong(FORTRAN));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"CONTIGUOUS\", s=PyInt_FromLong(CONTIGUOUS));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"ALIGNED\", s=PyInt_FromLong(ALIGNED));\n Py_DECREF(s);\n\n PyDict_SetItemString(newd, \"UPDATEIFCOPY\", s=PyInt_FromLong(UPDATEIFCOPY));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"WRITEABLE\", s=PyInt_FromLong(WRITEABLE));\n Py_DECREF(s);\n \n PyDict_SetItemString(d, \"_flagdict\", newd);\n Py_DECREF(newd);\n return;\n}\n\n\n/* Initialization function for the module */\n\nDL_EXPORT(void) initmultiarray(void) {\n\tPyObject *m, *d, *s;\n\tPyObject *c_api;\n\t\n\t/* Create the module and add the functions */\n\tm = Py_InitModule(\"multiarray\", array_module_methods);\n\tif (!m) goto err;\n\n\t/* Add some symbolic constants to the module */\n\td = PyModule_GetDict(m);\n\tif (!d) goto err; \n\n\t/* Create the module and add the functions */\n\tif (PyType_Ready(&PyBigArray_Type) < 0) \n\t\treturn;\n\n PyArray_Type.tp_base = &PyBigArray_Type;\n\n PyArray_Type.tp_as_mapping = &array_as_mapping;\n\t/* Even though, this would be inherited, it needs to be set now\n\t so that the __getitem__ will map to the as_mapping descriptor\n\t*/\n PyArray_Type.tp_as_number = &array_as_number; \n\t/* For good measure */\n\tPyArray_Type.tp_as_sequence = &array_as_sequence;\n\tPyArray_Type.tp_as_buffer = &array_as_buffer;\t\n PyArray_Type.tp_flags = (Py_TPFLAGS_DEFAULT \n\t\t\t\t | Py_TPFLAGS_BASETYPE\n\t\t\t\t | Py_TPFLAGS_CHECKTYPES);\n PyArray_Type.tp_doc = Arraytype__doc__;\n\n\tif (PyType_Ready(&PyArray_Type) < 0)\n return;\n\n if (setup_scalartypes(d) < 0) goto err;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMultiIter_Type.tp_iter = PyObject_SelfIter;\n\tif (PyType_Ready(&PyArrayIter_Type) < 0)\n\t\treturn; \n \n\tif (PyType_Ready(&PyArrayMapIter_Type) < 0)\n return; \n\n\tif (PyType_Ready(&PyArrayMultiIter_Type) < 0)\n\t\treturn;\n\n\tif (PyType_Ready(&PyArrayDescr_Type) < 0)\n\t\treturn;\n\n\tc_api = PyCObject_FromVoidPtr((void *)PyArray_API, NULL);\n\tif (PyErr_Occurred()) goto err;\n\tPyDict_SetItemString(d, \"_ARRAY_API\", c_api);\n\tPy_DECREF(c_api);\n\tif (PyErr_Occurred()) goto err;\n\n\tMultiArrayError = PyString_FromString (\"multiarray.error\");\n\tPyDict_SetItemString (d, \"error\", MultiArrayError);\n\t\n\ts = PyString_FromString(\"3.0\");\n\tPyDict_SetItemString(d, \"__version__\", s);\n\tPy_DECREF(s);\n Py_INCREF(&PyBigArray_Type);\n\tPyDict_SetItemString(d, \"bigndarray\", (PyObject *)&PyBigArray_Type);\n Py_INCREF(&PyArray_Type);\n\tPyDict_SetItemString(d, \"ndarray\", (PyObject *)&PyArray_Type);\n Py_INCREF(&PyArrayIter_Type);\n\tPyDict_SetItemString(d, \"flatiter\", (PyObject *)&PyArrayIter_Type);\n Py_INCREF(&PyArrayMultiIter_Type);\n\tPyDict_SetItemString(d, \"broadcast\", \n\t\t\t (PyObject *)&PyArrayMultiIter_Type);\n\tPy_INCREF(&PyArrayDescr_Type);\n\tPyDict_SetItemString(d, \"dtypedescr\", (PyObject *)&PyArrayDescr_Type);\n\n\t/* Doesn't need to be exposed to Python \n Py_INCREF(&PyArrayMapIter_Type);\n\tPyDict_SetItemString(d, \"mapiter\", (PyObject *)&PyArrayMapIter_Type);\n\t*/\n set_flaginfo(d);\n\n\tif (set_typeinfo(d) != 0) goto err;\n\n\t_numpy_internal =\t\t\t\t\t\t\\\n\t\tPyImport_ImportModule(\"numpy.core._internal\");\n\tif (_numpy_internal != NULL) return;\n\n err:\t\n\t/* Check for errors */\n\tif (PyErr_Occurred())\n PyErr_Print();\n\t\tPy_FatalError(\"can't initialize module multiarray\");\n\n\treturn;\n}\n\n", + "source_code_before": "/*\n Python Multiarray Module -- A useful collection of functions for creating and\n using ndarrays\n\n Original file \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n Modified for numpy_core in 2005 \n\n Travis E. Oliphant\n Assistant Professor at\n Brigham Young University\n \n*/\n\n/* $Id: multiarraymodule.c,v 1.36 2005/09/14 00:14:00 teoliphant Exp $ */\n\n#include \"Python.h\"\n#include \"structmember.h\"\n/*#include \n#include \n*/\n\n#define _MULTIARRAYMODULE\n#include \"numpy/arrayobject.h\"\n\n#define PyAO PyArrayObject\n\nstatic PyObject *typeDict=NULL; /* Must be explicitly loaded */\nstatic PyObject *_numpy_internal=NULL; /* A Python module for callbacks */\n\n\nstatic PyArray_Descr *\n_arraydescr_fromobj(PyObject *obj)\n{\n\tPyObject *dtypedescr;\n\tPyArray_Descr *new;\n\tint ret;\n\t\n\tdtypedescr = PyObject_GetAttrString(obj, \"dtypedescr\");\n\tPyErr_Clear();\n\tif (dtypedescr) {\n\t\tret = PyArray_DescrConverter(dtypedescr, &new);\n\t\tPy_DECREF(dtypedescr);\n\t\tif (ret) return new;\n\t\tPyErr_Clear();\n\t}\n\treturn NULL;\n}\n\n\n/* Including this file is the only way I know how to declare functions\n static in each file, and store the pointers from functions in both\n arrayobject.c and multiarraymodule.c for the C-API \n\n Declarying an external pointer-containing variable in arrayobject.c\n and trying to copy it to PyArray_API, did not work.\n\n Think about two modules with a common api that import each other...\n\n This file would just be the module calls. \n*/\n\n#include \"arrayobject.c\"\n\n\n/* An Error object -- rarely used? */\nstatic PyObject *MultiArrayError;\n\n/*MULTIARRAY_API\n Multiply a List of ints\n*/\nstatic int\nPyArray_MultiplyIntList(register int *l1, register int n) \n{\n\tregister int s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Multiply a List\n*/\nstatic intp \nPyArray_MultiplyList(register intp *l1, register int n) \n{\n\tregister intp s=1;\n while (n--) s *= (*l1++);\n return s;\n}\n\n/*MULTIARRAY_API\n Produce a pointer into array\n*/\nstatic char *\nPyArray_GetPtr(PyArrayObject *obj, register intp* ind)\n{\n\tregister int n = obj->nd;\n\tregister intp *strides = obj->strides;\n\tregister char *dptr = obj->data;\n\t\n\twhile (n--) dptr += (*strides++) * (*ind++);\n\treturn dptr;\n}\n\n/*MULTIARRAY_API\n Get axis from an object (possibly None) -- a converter function,\n*/\nstatic int \nPyArray_AxisConverter(PyObject *obj, int *axis)\n{\n\tif (obj == Py_None) {\n\t\t*axis = MAX_DIMS;\n\t}\n\telse {\n\t\t*axis = (int) PyInt_AsLong(obj);\n\t\tif (PyErr_Occurred()) {\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Compare Lists\n*/\nstatic int \nPyArray_CompareLists(intp *l1, intp *l2, int n) \n{\n int i;\n for(i=0;iob_type;\n\t\n\tPy_INCREF(self->descr);\n\tnew = PyArray_NewFromDescr(subtype,\n\t\t\t\t self->descr,\n\t\t\t\t self->nd, self->dimensions,\n\t\t\t\t self->strides,\n\t\t\t\t self->data,\n\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (new==NULL) return NULL;\n\tPy_INCREF(self);\n PyArray_BASE(new) = (PyObject *)self;\n\t\n\tif (type != NULL) {\n\t\tif (PyObject_SetAttrString(new, \"dtypedescr\", \n\t\t\t\t\t (PyObject *)type) < 0) {\n\t\t\tPy_DECREF(new);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tPy_DECREF(type);\n\t}\n\treturn new;\t\n}\n\n/*MULTIARRAY_API\n Ravel\n*/\nstatic PyObject *\nPyArray_Ravel(PyArrayObject *a, int fortran)\n{\n\tPyArray_Dims newdim = {NULL,1};\n\tintp val[1] = {-1};\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tnewdim.ptr = val;\n\tif (!fortran && PyArray_ISCONTIGUOUS(a)) {\n\t\tif (a->nd == 1) {\n\t\t\tPy_INCREF(a);\n\t\t\treturn (PyObject *)a;\n\t\t}\n\t\treturn PyArray_Newshape(a, &newdim);\n\t}\n\telse\n\t return PyArray_Flatten(a, fortran);\n}\n\n/*MULTIARRAY_API\n Flatten\n*/\nstatic PyObject *\nPyArray_Flatten(PyArrayObject *a, int fortran)\n{\n\tPyObject *ret, *new;\n\tintp size;\n\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(a);\n\n\tsize = PyArray_SIZE(a);\n\tPy_INCREF(a->descr);\n\tret = PyArray_NewFromDescr(a->ob_type,\n\t\t\t\t a->descr,\n\t\t\t\t 1, &size,\n\t\t\t\t NULL,\n\t\t\t\t NULL,\n\t\t\t\t 0, (PyObject *)a);\n\t\n\tif (ret== NULL) return NULL;\n\tif (fortran) {\n\t\tnew = PyArray_Transpose(a, NULL);\n\t\tif (new == NULL) {\n\t\t\tPy_DECREF(ret);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\telse {\n\t\tPy_INCREF(a);\n\t\tnew = (PyObject *)a;\n\t}\n\tif (PyArray_CopyInto((PyArrayObject *)ret, (PyArrayObject *)new) < 0) {\n\t\tPy_DECREF(ret);\n\t\tPy_DECREF(new);\n\t\treturn NULL;\n\t}\n\tPy_DECREF(new);\n\treturn ret;\n}\n\n\n/* For back-ward compatability *\n\n/ * Not recommended */\n\n/*MULTIARRAY_API\n Reshape an array\n*/\nstatic PyObject *\nPyArray_Reshape(PyArrayObject *self, PyObject *shape) \n{\n PyObject *ret;\n PyArray_Dims newdims;\n\n if (!PyArray_IntpConverter(shape, &newdims)) return NULL;\n ret = PyArray_Newshape(self, &newdims);\n PyDimMem_FREE(newdims.ptr);\n return ret;\n}\n\nstatic int\n_check_ones(PyArrayObject *self, int newnd, intp* newdims, intp *strides)\n{\n\tint nd;\n\tintp *dims;\n\tBool done=FALSE;\n\tint j, k;\n\n\tnd = self->nd;\n\tdims = self->dimensions;\n\n\tfor (k=0, j=0; !done && (jstrides[j];\n\t\t\tj++; k++;\n\t\t}\n\t\telse if ((kptr;\n PyArrayObject *ret;\n\tchar msg[] = \"total size of new array must be unchanged\";\n\tint n = newdims->len;\n Bool same;\n\tintp *strides = NULL;\n\tintp newstrides[MAX_DIMS];\n\n /* Quick check to make sure anything needs to be done */\n if (n == self->nd) {\n same = TRUE;\n i=0;\n while(same && i= 0) {\n\t\t\tif ((s_known == 0) || (s_original % s_known != 0)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdimensions[i_unknown] = s_original/s_known;\n\t\t} else {\n\t\t\tif (s_original != s_known) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, msg);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t}\n \n\tPy_INCREF(self->descr);\n\tret = (PyAO *)PyArray_NewFromDescr(self->ob_type,\n\t\t\t\t\t self->descr,\n\t\t\t\t\t n, dimensions,\n\t\t\t\t\t strides,\n\t\t\t\t\t self->data,\n\t\t\t\t\t self->flags, (PyObject *)self);\n\t\n\tif (ret== NULL) return NULL;\n\t\n Py_INCREF(self);\n ret->base = (PyObject *)self;\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\n\t\n return (PyObject *)ret;\n}\n\n/* return a new view of the array object with all of its unit-length \n dimensions squeezed out if needed, otherwise\n return the same array.\n */\n\n/*MULTIARRAY_API*/\nstatic PyObject *\nPyArray_Squeeze(PyArrayObject *self)\n{\n\tint nd = self->nd;\n\tint newnd = nd;\n\tintp dimensions[MAX_DIMS];\n\tintp strides[MAX_DIMS];\n\tint i,j;\n\tPyObject *ret;\n\n\tif (nd == 0) {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *)self;\n\t}\n\tfor (j=0, i=0; idimensions[i] == 1) {\n\t\t\tnewnd -= 1;\n\t\t}\n\t\telse {\n\t\t\tdimensions[j] = self->dimensions[i];\n\t\t\tstrides[j++] = self->strides[i];\n\t\t}\n\t}\n\t\n\tPy_INCREF(self->descr);\n\tret = PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t self->descr,\n\t\t\t\t newnd, dimensions, \n\t\t\t\t strides, self->data, \n\t\t\t\t self->flags,\n\t\t\t\t (PyObject *)self);\n\tif (ret == NULL) return NULL;\n\tPyArray_FLAGS(ret) &= ~OWN_DATA;\n\tPyArray_BASE(ret) = (PyObject *)self;\n\tPy_INCREF(self);\n\treturn (PyObject *)ret;\n}\n\n\n/*MULTIARRAY_API\n Mean\n*/\nstatic PyObject *\nPyArray_Mean(PyArrayObject *self, int axis, int rtype)\n{\n\tPyObject *obj1=NULL, *obj2=NULL;\n\tPyObject *new, *ret;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\n\tobj1 = PyArray_GenericReduceFunction((PyAO *)new, n_ops.add, axis,\n\t\t\t\t\t rtype);\n\tobj2 = PyFloat_FromDouble((double) PyArray_DIM(new,axis));\n Py_DECREF(new);\n\tif (obj1 == NULL || obj2 == NULL) {\n\t\tPy_XDECREF(obj1);\n\t\tPy_XDECREF(obj2);\n\t\treturn NULL;\n\t}\n\n\tret = PyNumber_Divide(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n}\n\n/* Set variance to 1 to by-pass square-root calculation and return variance */\n/*MULTIARRAY_API\n Std\n*/\nstatic PyObject *\nPyArray_Std(PyArrayObject *self, int axis, int rtype, int variance)\n{\n\tPyObject *obj1=NULL, *obj2=NULL, *new=NULL;\n\tPyObject *ret=NULL, *newshape=NULL;\n\tint i, n;\n\tintp val;\n\n\tif ((new = _check_axis(self, &axis, 0))==NULL) return NULL;\n\t\n\t/* Compute and reshape mean */\n\tobj1 = PyArray_EnsureArray(PyArray_Mean((PyAO *)new, axis, rtype));\n\tif (obj1 == NULL) {Py_DECREF(new); return NULL;} \n\tn = PyArray_NDIM(new);\n\tnewshape = PyTuple_New(n);\n\tif (newshape == NULL) {Py_DECREF(obj1); Py_DECREF(new); return NULL;}\n\tfor (i=0; ind != 1) {\n Py_DECREF(cond);\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"condition must be 1-d array\");\n return NULL;\n }\n\n res = PyArray_Nonzero(cond);\n Py_DECREF(cond);\n\tret = PyArray_Take(self, res, axis);\n\tPy_DECREF(res);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Nonzero\n*/\nstatic PyObject *\nPyArray_Nonzero(PyArrayObject *self)\n{\n int n=self->nd, j;\n\tintp count=0, i, size;\n\tPyArrayIterObject *it=NULL;\n\tPyObject *ret=NULL, *item;\n\tintp *dptr[MAX_DIMS];\n\n\tit = (PyArrayIterObject *)PyArray_IterNew((PyObject *)self);\n\tif (it==NULL) return NULL;\n\n\tsize = it->size;\n\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) count++;\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\n\tPyArray_ITER_RESET(it);\n\tif (n==1) {\n\t\tret = PyArray_New(self->ob_type, 1, &count, PyArray_INTP, \n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)self);\n\t\tif (ret == NULL) goto fail;\n\t\tdptr[0] = (intp *)PyArray_DATA(ret);\n\t\t\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\t*(dptr[0])++ = i;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\t\t\n\t}\n\telse {\n\t\tret = PyTuple_New(n);\n\t\tfor (j=0; job_type, 1, &count, \n\t\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0,\n\t\t\t\t\t (PyObject *)self);\n\t\t\tif (item == NULL) goto fail;\n\t\t\tPyTuple_SET_ITEM(ret, j, item);\n\t\t\tdptr[j] = (intp *)PyArray_DATA(item);\n\t\t}\n\t\t\n\t\t/* reset contiguous so that coordinates gets updated */\n\t\tit->contiguous = 0;\n\t\tfor (i=0; idescr->f->nonzero(it->dataptr, self)) \n\t\t\t\tfor (j=0; jcoordinates[j];\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\n\n\tPy_DECREF(it);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(ret);\n\tPy_XDECREF(it);\n\treturn NULL;\n \n}\n\n/*MULTIARRAY_API\n Clip\n*/\nstatic PyObject *\nPyArray_Clip(PyArrayObject *self, PyObject *min, PyObject *max)\n{\n\tPyObject *selector=NULL, *newtup=NULL, *ret=NULL;\n\tPyObject *res1=NULL, *res2=NULL, *res3=NULL;\n\tPyObject *two;\n\n\ttwo = PyInt_FromLong((long)2);\n\tres1 = PyArray_GenericBinaryFunction(self, max, n_ops.greater);\n\tres2 = PyArray_GenericBinaryFunction(self, min, n_ops.less);\n\tif ((res1 == NULL) || (res2 == NULL)) {\n\t\tPy_DECREF(two);\n\t\tPy_XDECREF(res1);\n\t\tPy_XDECREF(res2);\n\t}\n\tres3 = PyNumber_Multiply(two, res1);\n\tPy_DECREF(two); \n\tPy_DECREF(res1); \n\tif (res3 == NULL) return NULL;\n\n\tselector = PyArray_EnsureArray(PyNumber_Add(res2, res3));\n\tPy_DECREF(res2);\n\tPy_DECREF(res3);\n\tif (selector == NULL) return NULL;\n\n\tnewtup = Py_BuildValue(\"(OOO)\", (PyObject *)self, min, max);\n\tif (newtup == NULL) {Py_DECREF(selector); return NULL;}\n\tret = PyArray_Choose((PyAO *)selector, newtup);\n\tPy_DECREF(selector);\n\tPy_DECREF(newtup);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Conjugate\n*/\nstatic PyObject *\nPyArray_Conjugate(PyArrayObject *self)\n{\n\tif (PyArray_ISCOMPLEX(self)) {\n\t\tPyObject *new;\n\t\tintp size, i;\n\t\t/* Make a copy */\n\t\tnew = PyArray_NewCopy(self, -1);\n\t\tif (new==NULL) return NULL;\n\t\tsize = PyArray_SIZE(new);\n\t\tif (self->descr->type_num == PyArray_CFLOAT) {\n\t\t\tcfloat *dptr = (cfloat *) PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CDOUBLE) {\n\t\t\tcdouble *dptr = (cdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\n\t\t}\n\t\telse if (self->descr->type_num == PyArray_CLONGDOUBLE) {\n\t\t\tclongdouble *dptr = (clongdouble *)PyArray_DATA(new);\n\t\t\tfor (i=0; iimag = -dptr->imag;\n\t\t\t\tdptr++;\n\t\t\t}\t\t\t\n\t\t}\t\t\n\t\treturn new;\n\t}\n\telse {\n\t\tPy_INCREF(self);\n\t\treturn (PyObject *) self;\n\t}\n}\n\n/*MULTIARRAY_API\n Trace\n*/\nstatic PyObject *\nPyArray_Trace(PyArrayObject *self, int offset, int axis1, int axis2, \nint rtype)\n{\n\tPyObject *diag=NULL, *ret=NULL;\n\n\tdiag = PyArray_Diagonal(self, offset, axis1, axis2);\n\tif (diag == NULL) return NULL;\n\tret = PyArray_GenericReduceFunction((PyAO *)diag, n_ops.add, -1, rtype);\n\tPy_DECREF(diag);\n\treturn ret;\n}\n\n/*MULTIARRAY_API\n Diagonal\n*/\nstatic PyObject *\nPyArray_Diagonal(PyArrayObject *self, int offset, int axis1, int axis2)\n{\n\tint n = self->nd;\n\tPyObject *new;\n\tPyArray_Dims newaxes;\n\tintp dims[MAX_DIMS];\n\tint i, pos;\t\n\n\tnewaxes.ptr = dims;\n\tif (n < 2) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"array.ndim must be >= 2\");\n\t\treturn NULL;\n\t}\n\tif (axis1 < 0) axis1 += n;\n\tif (axis2 < 0) axis2 += n;\n\tif ((axis1 == axis2) || (axis1 < 0) || (axis1 >= n) ||\t\\\n\t (axis2 < 0) || (axis2 >= n)) {\n\t\tPyErr_Format(PyExc_ValueError, \"axis1(=%d) and axis2(=%d) \"\\\n\t\t\t \"must be different and within range (nd=%d)\",\n\t\t\t axis1, axis2, n);\n\t\treturn NULL;\n\t}\n \n\tnewaxes.len = n;\n\t/* insert at the end */\n\tnewaxes.ptr[n-2] = axis1;\n\tnewaxes.ptr[n-1] = axis2;\n\tpos = 0;\n\tfor (i=0; idimensions[0];\n\t\tn2 = self->dimensions[1];\n\t\tstep = n2+1;\n\t\tif (offset < 0) {\n\t\t\tstart = -n2 * offset;\n\t\t\tstop = MIN(n2, n1+offset)*(n2+1) - n2*offset;\n\t\t}\n\t\telse {\n\t\t\tstart = offset;\n\t\t\tstop = MIN(n1, n2-offset)*(n2+1) + offset;\n\t\t}\n\t\t\n\t\t/* count = ceil((stop-start)/step) */\n\t\tcount = ((stop-start) / step) + (((stop-start) % step) != 0);\n\t\t\t\n\t\tindices = PyArray_New(&PyArray_Type, 1, &count, \n\t\t\t\t PyArray_INTP, NULL, NULL, 0, 0, NULL);\n\t\tif (indices == NULL) {\n\t\t\tPy_DECREF(self); return NULL;\n\t\t}\n\t\tdptr = (intp *)PyArray_DATA(indices);\n\t\tfor (n1=start; n1descr;\n\n\t\tmydiagonal = PyList_New(0);\n\t\tif (mydiagonal == NULL) {Py_DECREF(self); return NULL;}\n\t\tn1 = self->dimensions[0];\n\t\tfor (i=0; i 3)) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"C arrays of only 1-3 dimensions available\");\n\t\tPy_XDECREF(typedescr);\n\t\treturn -1;\n\t}\n\tif ((ap = (PyArrayObject*)PyArray_FromAny(*op, typedescr, nd, nd,\n\t\t\t\t\t\t CARRAY_FLAGS)) == NULL)\n\t\treturn -1;\n\tswitch(nd) {\n\tcase 1:\n\t\t*((char **)ptr) = ap->data;\n\t\tbreak;\n\tcase 2:\n\t\tn = ap->dimensions[0];\n\t\tptr2 = (char **)_pya_malloc(n * sizeof(char *));\n\t\tif (!ptr2) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0];\n\t\t}\n\t\t*((char ***)ptr) = ptr2;\n\t\tbreak;\t\t\n\tcase 3:\n\t\tn = ap->dimensions[0];\n\t\tm = ap->dimensions[1];\n\t\tptr3 = (char ***)_pya_malloc(n*(m+1) * sizeof(char *));\n\t\tif (!ptr3) goto fail;\n\t\tfor (i=0; idata + i*ap->strides[0] + \\\n\t\t\t\t\tj*ap->strides[1];\n\t\t\t}\n\t\t}\n\t\t*((char ****)ptr) = ptr3;\n\t}\n\tmemcpy(dims, ap->dimensions, nd*sizeof(intp));\n\t*op = (PyObject *)ap;\n\treturn 0;\n\n fail:\n\tPyErr_SetString(PyExc_MemoryError, \"no memory\");\n\treturn -1;\n}\n\n/* Deprecated --- Use PyArray_AsCArray instead */\n\n/*MULTIARRAY_API\n Convert to a 1D C-array\n*/\nstatic int \nPyArray_As1D(PyObject **op, char **ptr, int *d1, int typecode) \n{\n\tintp newd1;\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, &newd1, 1, descr) == -1)\n\t\treturn -1;\t\n\t*d1 = (int) newd1;\n\treturn 0;\n}\n\n/*MULTIARRAY_API\n Convert to a 2D C-array\n*/\nstatic int \nPyArray_As2D(PyObject **op, char ***ptr, int *d1, int *d2, int typecode) \n{\n\tintp newdims[2];\n\tPyArray_Descr *descr;\n\n\tdescr = PyArray_DescrFromType(typecode);\t\n\tif (PyArray_AsCArray(op, (void *)ptr, newdims, 2, descr) == -1)\n\t\treturn -1;\n\n\t*d1 = (int ) newdims[0];\n\t*d2 = (int ) newdims[1];\n return 0;\n}\n\n/* End Deprecated */\n\n/*MULTIARRAY_API\n Free pointers created if As2D is called\n*/\nstatic int \nPyArray_Free(PyObject *op, void *ptr) \n{\n PyArrayObject *ap = (PyArrayObject *)op;\n\t\n if ((ap->nd < 1) || (ap->nd > 3)) \n\t\treturn -1;\n if (ap->nd >= 2) {\n\t\t_pya_free(ptr);\n }\n Py_DECREF(ap);\n return 0;\n}\n\n\nstatic PyObject *\n_swap_and_concat(PyObject *op, int axis, int n)\n{\n\tPyObject *newtup=NULL;\n\tPyObject *otmp, *arr;\n\tint i;\n\n\tnewtup = PyTuple_New(n);\n\tif (newtup==NULL) return NULL;\n\tfor (i=0; i= MAX_DIMS) {\n\t\t\totmp = PyArray_Ravel(mps[i],0);\n\t\t\tPy_DECREF(mps[i]);\n\t\t\tmps[i] = (PyArrayObject *)otmp;\n\t\t}\n\t\tprior2 = PyArray_GetPriority((PyObject *)(mps[i]), 0.0);\n\t\tif (prior2 > prior1) {\n\t\t\tprior1 = prior2;\n\t\t\tsubtype = mps[i]->ob_type;\n\t\t\tret = mps[i];\n\t\t}\n\t}\n\t\n\tnew_dim = 0;\n\tfor(i=0; ind;\n\t\telse {\n\t\t\tif (nd != mps[i]->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"arrays must have same \"\\\n\t\t\t\t\t\t\"number of dimensions\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CompareLists(mps[0]->dimensions+1, \n\t\t\t\t\t\t mps[i]->dimensions+1, \n\t\t\t\t\t\t nd-1)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"array dimensions must \"\\\n\t\t\t\t\t\t\"agree except for d_0\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (nd == 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"0-d arrays can't be concatenated\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnew_dim += mps[i]->dimensions[0];\n\t}\n\t\n\ttmp = mps[0]->dimensions[0];\n\tmps[0]->dimensions[0] = new_dim;\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(subtype, \n\t\t\t\t\t\t mps[0]->descr, nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ret);\n\tmps[0]->dimensions[0] = tmp;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tdata = ret->data;\n\tfor(i=0; idata, numbytes);\n\t\tdata += numbytes;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; ind;\n\tif (n <= 1) {\n\t\tPy_INCREF(ap);\n\t\treturn (PyObject *)ap;\n\t}\n\n\tif (a1 < 0) a1 += n;\n\tif (a2 < 0) a2 += n;\n\tif ((a1 < 0) || (a1 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis1 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tif ((a2 < 0) || (a2 >= n)) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"bad axis2 argument to swapaxes\");\n\t\treturn NULL;\n\t}\n\tnew_axes.ptr = dims;\n\tnew_axes.len = n;\n\n\tfor (i=0; ind;\n\t\tfor(i=0; ilen;\n\t\taxes = permute->ptr;\n\t\tif (n > ap->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many axes for this array\");\n\t\t\treturn NULL;\n\t\t}\n\t\tfor(i=0; ind+axis;\n\t\t\tif (axis < 0 || axis >= ap->nd) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"invalid axis for this array\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tpermutation[i] = axis;\n\t\t}\n\t}\n\t\n\t/* this allocates memory for dimensions and strides (but fills them\n\t incorrectly), sets up descr, and points data at ap->data. */\n\tPy_INCREF(ap->descr);\n\tret = (PyArrayObject *)\\\n\t\tPyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t ap->descr, \n\t\t\t\t n, permutation, \n\t\t\t\t NULL, ap->data, ap->flags,\n\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) return NULL;\n\t\n\t/* point at true owner of memory: */\n\tret->base = (PyObject *)ap;\n\tPy_INCREF(ap);\n\t\n\tfor(i=0; idimensions[i] = ap->dimensions[permutation[i]];\n\t\tret->strides[i] = ap->strides[permutation[i]];\n\t}\n\tPyArray_UpdateFlags(ret, CONTIGUOUS | FORTRAN);\t\n\n\treturn (PyObject *)ret;\t\n}\n\n/*MULTIARRAY_API\n Repeat the array.\n*/\nstatic PyObject *\nPyArray_Repeat(PyArrayObject *aop, PyObject *op, int axis)\n{\n\tintp *counts;\n\tintp n, n_outer, i, j, k, chunk, total;\n\tintp tmp;\n\tint nd;\n\tPyArrayObject *repeats=NULL;\n\tPyObject *ap=NULL;\n\tPyArrayObject *ret=NULL;\n\tchar *new_data, *old_data;\n\n\trepeats = (PyAO *)PyArray_ContiguousFromAny(op, PyArray_INTP, 0, 1);\n\tif (repeats == NULL) return NULL;\n\tnd = repeats->nd;\n\tcounts = (intp *)repeats->data;\n\n\tif ((ap=_check_axis(aop, &axis, CARRAY_FLAGS))==NULL) {\n\t\tPy_DECREF(repeats);\n\t\treturn NULL;\n\t}\n\n\taop = (PyAO *)ap;\n\n\tif (nd == 1)\n\t\tn = repeats->dimensions[0];\n\telse /* nd == 0 */\n\t\tn = aop->dimensions[axis];\n\n\tif (aop->dimensions[axis] != n) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"a.shape[axis] != len(repeats)\");\n\t\tgoto fail;\n\t}\n\n\t\n\tif (nd == 0) \n\t\ttotal = counts[0]*n;\n\telse {\n\t\t\n\t\ttotal = 0;\n\t\tfor(j=0; jdimensions[axis] = total;\n\tPy_INCREF(aop->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(aop->ob_type, \n\t\t\t\t\t\t aop->descr,\n\t\t\t\t\t\t aop->nd,\n\t\t\t\t\t\t aop->dimensions,\n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)aop);\n\taop->dimensions[axis] = n;\n\t\n\tif (ret == NULL) goto fail;\n\t\n\tnew_data = ret->data;\n\told_data = aop->data;\n\t\n\tchunk = aop->descr->elsize;\n\tfor(i=axis+1; ind; i++) {\n\t\tchunk *= aop->dimensions[i];\n\t}\n\t\n\tn_outer = 1;\n\tfor(i=0; idimensions[i];\n\n\tfor(i=0; ind < mps[i]->nd) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"too many dimensions\");\n\t\t\tgoto fail;\n\t\t}\n\t\tif (!PyArray_CompareLists(ap->dimensions+(ap->nd-mps[i]->nd),\n\t\t\t\t mps[i]->dimensions, mps[i]->nd)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"array dimensions must agree\");\n\t\t\tgoto fail;\n\t\t}\n\t\tsizes[i] = PyArray_NBYTES(mps[i]);\n\t}\n\t\n\tPy_INCREF(mps[0]->descr);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(ap->ob_type, \n\t\t\t\t\t\t mps[0]->descr,\n\t\t\t\t\t\t ap->nd,\n\t\t\t\t\t\t ap->dimensions, \n\t\t\t\t\t\t NULL, NULL, 0,\n\t\t\t\t\t\t (PyObject *)ap);\n\tif (ret == NULL) goto fail;\n\t\n\telsize = ret->descr->elsize;\n\tm = PyArray_SIZE(ret);\n\tself_data = (intp *)ap->data;\n\tret_data = ret->data;\n\t\n\tfor (i=0; i= n) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid entry in choice array\");\n\t\t\tgoto fail;\n\t\t}\n\t\toffset = i*elsize;\n\t\tif (offset >= sizes[mi]) {offset = offset % sizes[mi]; }\n\t\tmemmove(ret_data, mps[mi]->data+offset, elsize);\n\t\tret_data += elsize; self_data++;\n\t}\n\t\n\tPyArray_INCREF(ret);\n\tfor(i=0; idescr->f->sort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize);\n\n\tif (needcopy) {\n\t\tchar *buffer;\n\t\tbuffer = PyDataMem_NEW(N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(buffer, (intp) elsize, it->dataptr, \n\t\t\t\t astride, N, elsize);\n\t\t\tif (sort(buffer, N, op) < 0) {\n\t\t\t\tPyDataMem_FREE(buffer); goto fail;\n\t\t\t}\n\t\t\t_strided_copy(it->dataptr, astride, buffer, \n\t\t\t\t (intp) elsize, N, elsize);\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t\tPyDataMem_FREE(buffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tif (sort(it->dataptr, N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t}\n\t}\t\n\t\n\tEND_THREADS\n\t\n\tPy_DECREF(it);\n\treturn 0;\n\n fail:\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\treturn 0;\n}\n\nstatic PyObject*\n_new_argsort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\n\tPyArrayIterObject *it=NULL;\n\tPyArrayIterObject *rit=NULL;\n\tPyObject *ret;\n\tint needcopy=0, i;\n\tintp N, size;\n\tint elsize;\n\tintp astride, rstride, *iptr;\n\tPyArray_ArgSortFunc *argsort;\n\tBEGIN_THREADS_DEF \n\n\tret = PyArray_New(op->ob_type, op->nd,\n\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) return NULL;\n\n\tit = (PyArrayIterObject *)PyArray_IterAllButAxis((PyObject *)op, axis);\n\trit = (PyArrayIterObject *)PyArray_IterAllButAxis(ret, axis);\n\tif (rit == NULL || it == NULL) goto fail;\n\n\tBEGIN_THREADS\n\n\targsort = op->descr->f->argsort[which];\n\tsize = it->size;\n\tN = op->dimensions[axis];\n\telsize = op->descr->elsize;\n\tastride = op->strides[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n\tneedcopy = !(op->flags & ALIGNED) || (astride != (intp) elsize) || \\\n\t\t(rstride != sizeof(intp));\n\t\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(elsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*elsize);\n\t\twhile (size--) {\n\t\t\t_strided_copy(valbuffer, (intp) elsize, it->dataptr,\n\t\t\t\t astride, N, elsize);\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idataptr, rstride, indbuffer, \n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idataptr, (intp *)rit->dataptr, \n\t\t\t\t N, op) < 0) goto fail;\n\t\t\tPyArray_ITER_NEXT(it);\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\t\n\tEND_THREADS\n\n\tPy_DECREF(it);\n\tPy_DECREF(rit);\n\treturn ret;\n\n fail:\n\n\tEND_THREADS\n\n\tPy_DECREF(ret);\n\tPy_XDECREF(it);\n\tPy_XDECREF(rit);\n\treturn NULL;\n}\n\n\n/* Be sure to save this global_compare when necessary */\n\nstatic PyArrayObject *global_obj;\n\nstatic int \nqsortCompare (const void *a, const void *b) \n{\n\treturn global_obj->descr->f->compare(a,b,global_obj);\n}\n\n/* Consumes reference to ap (op gets it)\n op contains a version of the array with axes swapped if\n local variable axis is not the last dimension.\n orign must be defined locally. \n*/\n\n#define SWAPAXES(op, ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* Consumes reference to ap (op gets it)\n origin must be previously defined locally. \n SWAPAXES must have been called previously. \n op contains the swapped version of the array. \n*/\n#define SWAPBACK(op, ap) {\t \\\n\t\tif (axis != orign) { \\\n\t\t\t(op) = (PyAO *)PyArray_SwapAxes((ap), axis, orign); \\\n\t\t\tPy_DECREF((ap));\t\t\t\t\\\n\t\t\tif ((op) == NULL) return NULL;\t\t\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t\telse (op) = (ap);\t\t\t\t\t\\\n\t}\n\n/* These swap axes in-place if necessary */\n#define SWAPINTP(a,b) {intp c; c=(a); (a) = (b); (b) = c;}\n#define SWAPAXES2(ap) {\t\t\t\t\t\t\\\n\t\torign = (ap)->nd-1;\t\t\t\t\t\\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN); \\\n\t\t}\t\t\t\t\t\t \\\n\t}\n\n#define SWAPBACK2(ap) {\t\t \\\n\t\tif (axis != orign) {\t\t\t\t\t\\\n\t\t\tSWAPINTP(ap->dimensions[axis], ap->dimensions[orign]); \\\n\t\t\tSWAPINTP(ap->strides[axis], ap->strides[orign]); \\\n\t\t\tPyArray_UpdateFlags(ap, CONTIGUOUS | FORTRAN);\t\\\n\t\t}\t\t\t\t\t\t\t\\\n\t}\n\n/*MULTIARRAY_API\n Sort an array in-place\n*/\nstatic int\nPyArray_Sort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *store_arr=NULL;\n\tchar *ip;\n\tint i, n, m, elsize, orign;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) return 0;\n\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\treturn -1;\n\t}\n\tif (!PyArray_ISWRITEABLE(op)) {\n\t\tPyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"attempted sort on unwriteable array.\");\n\t\treturn -1;\n\t}\n\n\t/* Determine if we should use type-specific algorithm or not */\n\tif (op->descr->f->sort[which] != NULL) {\n\t\treturn _new_sort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || \\\n\t op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"desired sort not supported for this type\");\n\t\treturn -1;\n\t}\n\n\tSWAPAXES2(op);\n\n ap = (PyArrayObject *)PyArray_FromAny((PyObject *)op, \n\t\t\t\t\t NULL, 1, 0, \n\t\t\t\t\t DEFAULT_FLAGS | UPDATEIFCOPY);\t\n\tif (ap == NULL) goto fail;\n\t\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(ap)/m;\n\n\t/* Store global -- allows re-entry -- restore before leaving*/\n\tstore_arr = global_obj; \n\tglobal_obj = ap;\n\t\n\tfor (ip=ap->data, i=0; idescr->elsize;\n\tconst intp *ipa = ip1;\n\tconst intp *ipb = ip2;\t\n\treturn global_obj->descr->f->compare(global_data + (isize * *ipa),\n global_data + (isize * *ipb), \n\t\t\t\t\t global_obj);\n}\n\n/*MULTIARRAY_API\n ArgSort an array\n*/\nstatic PyObject *\nPyArray_ArgSort(PyArrayObject *op, int axis, PyArray_SORTKIND which) \n{\n\tPyArrayObject *ap=NULL, *ret=NULL, *store;\n\tintp *ip;\n\tintp i, j, n, m, orign;\n\tint argsort_elsize;\n\tchar *store_ptr;\n\n\tn = op->nd;\n\tif ((n==0) || (PyArray_SIZE(op)==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t\t op->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, \n\t\t\t\t\t\t (PyObject *)op);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)ret->data) = 0;\n\t\treturn (PyObject *)ret;\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\treturn NULL;\n\t}\n\n\t/* Determine if we should use new algorithm or not */\n\tif (op->descr->f->argsort[which] != NULL) {\n\t\treturn _new_argsort(op, axis, which);\n\t}\n\n\tif ((which != PyArray_QUICKSORT) || op->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"requested sort not available for type\");\n\t\tgoto fail;\n\t}\n\n\tSWAPAXES(ap, op);\n\n\top = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)ap, \n\t\t\t\t\t\t\t PyArray_NOTYPE,\n\t\t\t\t\t\t\t 1, 0);\n\n\tif (op == NULL) return NULL;\n\t\n\tret = (PyArrayObject *)PyArray_New(op->ob_type, op->nd,\n\t\t\t\t\t op->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)op);\n\tif (ret == NULL) goto fail;\n\t\n\t\n\tip = (intp *)ret->data;\n\targsort_elsize = op->descr->elsize;\n\tm = op->dimensions[op->nd-1];\n\tif (m == 0) goto finish;\n\n\tn = PyArray_SIZE(op)/m;\n\tstore_ptr = global_data;\n\tglobal_data = op->data;\n\tstore = global_obj;\n\tglobal_obj = op;\n\tfor (i=0; i 0 in lexsort\");\n\t\treturn NULL;\n\t}\n\tmps = (PyArrayObject **) _pya_malloc(n*sizeof(PyArrayObject));\n\tif (mps==NULL) return PyErr_NoMemory();\n\tits = (PyArrayIterObject **) _pya_malloc(n*sizeof(PyArrayIterObject));\n\tif (its == NULL) {_pya_free(mps); return PyErr_NoMemory();}\n\tfor (i=0; i0) {\n\t\t\tif ((mps[i]->nd != mps[0]->nd) ||\t\\\n\t\t\t (!PyArray_CompareLists(mps[i]->dimensions,\n\t\t\t\t\t\t mps[0]->dimensions,\n\t\t\t\t\t\t mps[0]->nd))) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"all keys need to be the same shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t}\n\t\tif (!mps[i]->descr->f->argsort[PyArray_MERGESORT]) {\n\t\t\tPyErr_Format(PyExc_TypeError, \n\t\t\t\t \"merge sort not available for item %d\", i);\n\t\t\tgoto fail;\n\t\t}\n\t\tits[i] = (PyArrayIterObject *)PyArray_IterAllButAxis\t\\\n\t\t\t((PyObject *)mps[i], axis);\n\t\tif (its[i]==NULL) goto fail;\n\t}\n\n\t/* Now we can check the axis */\n\tnd = mps[0]->nd;\n\tif ((nd==0) || (PyArray_SIZE(mps[0])==1)) {\n\t\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t\t mps[0]->dimensions, \n\t\t\t\t\t\t PyArray_INTP,\n\t\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t\tif (ret == NULL) return NULL;\n\t\t*((intp *)(ret->data)) = 0;\n\t\treturn (PyObject *)ret;\n\t}\n\tif (axis < 0) axis += nd;\n\tif ((axis < 0) || (axis >= nd)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"axis(=%d) out of bounds\", axis);\n\t\tgoto fail;\n\t}\n\n\t/* Now do the sorting */\n\n\tret = (PyArrayObject *)PyArray_New(&PyArray_Type, mps[0]->nd,\n\t\t\t\t\t mps[0]->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (ret == NULL) goto fail;\n\n\trit = (PyArrayIterObject *)\\\n\t\tPyArray_IterAllButAxis((PyObject *)ret, axis);\n\tif (rit == NULL) goto fail;\n\n\tsize = rit->size;\n\tN = mps[0]->dimensions[axis];\n\trstride = PyArray_STRIDE(ret,axis);\n\n maxelsize = mps[0]->descr->elsize;\n\tneedcopy = (rstride != sizeof(intp));\n\tfor (j=0; jflags & ALIGNED) || \\\n\t\t\t(mps[j]->strides[axis] != (intp)mps[j]->descr->elsize);\n if (mps[j]->descr->elsize > maxelsize) \n maxelsize = mps[j]->descr->elsize;\n\t}\n\n\tif (needcopy) {\n\t\tchar *valbuffer, *indbuffer;\n\t\tvalbuffer = PyDataMem_NEW(N*(maxelsize+sizeof(intp)));\n\t\tindbuffer = valbuffer + (N*maxelsize);\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)indbuffer;\n\t\t\tfor (i=0; idescr->elsize;\n\t\t\t\tastride = mps[j]->strides[axis];\t\n\t\t\t\targsort = mps[j]->descr->f->argsort[PyArray_MERGESORT];\n\t\t\t\t_strided_copy(valbuffer, (intp) elsize, its[j]->dataptr,\n\t\t\t\t\t astride, N, elsize);\n\t\t\t\tif (argsort(valbuffer, (intp *)indbuffer, N, mps[j]) < 0) {\n\t\t\t\t\tPyDataMem_FREE(valbuffer); goto fail;\n\t\t\t\t}\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\t_strided_copy(rit->dataptr, rstride, indbuffer,\n\t\t\t\t sizeof(intp), N, sizeof(intp));\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t\tPyDataMem_FREE(valbuffer);\n\t}\n\telse {\n\t\twhile (size--) {\n\t\t\tiptr = (intp *)rit->dataptr;\n\t\t\tfor (i=0; idescr->f->argsort[PyArray_MERGESORT];\n\t\t\t\tif (argsort(its[j]->dataptr, (intp *)rit->dataptr,\n\t\t\t\t\t N, mps[j]) < 0) goto fail;\n\t\t\t\tPyArray_ITER_NEXT(its[j]);\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(rit);\n\t\t}\n\t}\n\n\tfor (i=0; idescr->f->compare;\n\tintp min_i, max_i, i, j;\n\tint location, elsize = ap1->descr->elsize;\n\tintp elements = ap1->dimensions[ap1->nd-1];\n\tintp n = PyArray_SIZE(ap2);\n\tintp *rp = (intp *)ret->data;\n\tchar *ip = ap2->data;\n\tchar *vp = ap1->data;\n\n\tfor (j=0; j 0) {\n\t\t\t\t\tif (compare(ip, vp+elsize*(--i), ap2) \\\n\t\t\t\t\t != 0) {\n\t\t\t\t\t\ti = i+1; break;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tmin_i = i;\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\telse if (location < 0) {\n\t\t\t\tmax_i = i;\n\t\t\t} else {\n\t\t\t\tmin_i = i+1;\n\t\t\t}\n\t\t}\n\t\t*rp = min_i;\n\t}\n}\n\n/*MULTIARRAY_API\n Numeric.searchsorted(a,v)\n*/\nstatic PyObject *\nPyArray_SearchSorted(PyArrayObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1=NULL, *ap2=NULL, *ret=NULL;\n\tint typenum = 0;\n\n\t/* \n PyObject *args;\n args = Py_BuildValue(\"O\",op2);\n\tPy_DELEGATE_ARGS(((PyObject *)op1), searchsorted, args);\n Py_XDECREF(args);\n\t*/\n\n\ttypenum = PyArray_ObjectType((PyObject *)op1, 0);\n\ttypenum = PyArray_ObjectType(op2, typenum);\n\tret = NULL;\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny((PyObject *)op1, \n\t\t\t\t\t\t\t typenum, \n\t\t\t\t\t\t\t 1, 1);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tret = (PyArrayObject *)PyArray_New(ap2->ob_type, ap2->nd, \n\t\t\t\t\t ap2->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, (PyObject *)ap2);\n\tif (ret == NULL) goto fail;\n\n\tif (ap2->descr->f->compare == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"compare not supported for type\");\n\t\tgoto fail;\n\t}\n\t\n\tlocal_where(ap1, ap2, ret); \n\t\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\treturn (PyObject *)ret;\n\t\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ret);\n\treturn NULL;\n}\n\n\n\n/* Could perhaps be redone to not make contiguous arrays \n */\n\n/*MULTIARRAY_API\n Numeric.innerproduct(a,v)\n*/\nstatic PyObject *\nPyArray_InnerProduct(PyObject *op1, PyObject *op2) \n{\n\tPyArrayObject *ap1, *ap2, *ret=NULL;\n\tintp i, j, l, i1, i2, n1, n2;\n\tint typenum;\n\tintp is1, is2, os;\n\tchar *ip1, *ip2, *op;\n\tintp dimensions[MAX_DIMS], nd;\n\tPyArray_DotFunc *dot;\n\tPyTypeObject *subtype;\n double prior1, prior2;\n\t\n\ttypenum = PyArray_ObjectType(op1, 0); \n\ttypenum = PyArray_ObjectType(op2, typenum);\n\t\t\n\tap1 = (PyArrayObject *)PyArray_ContiguousFromAny(op1, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap1 == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_ContiguousFromAny(op2, typenum, \n\t\t\t\t\t\t\t 0, 0);\n\tif (ap2 == NULL) goto fail;\n\t\n\tif (ap1->nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\t\n\tif (ap2->dimensions[ap2->nd-1] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"matrices are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n \n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\tif (ret == NULL) goto fail;\n\n\tdot = (ret->descr->f->dotfunc);\n\t\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\n\t\n\tis1 = ap1->strides[ap1->nd-1]; \n\tis2 = ap2->strides[ap2->nd-1];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2nd == 0 || ap2->nd == 0) {\n\t\tret = (ap1->nd == 0 ? ap1 : ap2);\n\t\tret = (PyArrayObject *)ret->ob_type->tp_as_number->\\\n\t\t\tnb_multiply((PyObject *)ap1, (PyObject *)ap2);\n\t\tPy_DECREF(ap1);\n\t\tPy_DECREF(ap2);\n\t\treturn (PyObject *)ret;\n\t}\n\t\n\tl = ap1->dimensions[ap1->nd-1];\n\tif (ap2->nd > 1) {\n\t\tmatchDim = ap2->nd - 2;\n\t\totherDim = ap2->nd - 1;\n\t}\n\telse {\n\t\tmatchDim = 0;\n\t\totherDim = 0;\n\t}\n\n\tif (ap2->dimensions[matchDim] != l) {\n\t\tPyErr_SetString(PyExc_ValueError, \"objects are not aligned\");\n\t\tgoto fail;\n\t}\n\t\n\tif (l == 0) n1 = n2 = 0;\n\telse {\n\t\tn1 = PyArray_SIZE(ap1)/l;\n\t\tn2 = PyArray_SIZE(ap2)/l;\n\t}\n\n\tnd = ap1->nd+ap2->nd-2;\n\tj = 0;\n\tfor(i=0; ind-1; i++) {\n\t\tdimensions[j++] = ap1->dimensions[i];\n\t}\n\tfor(i=0; ind-2; i++) {\n\t\tdimensions[j++] = ap2->dimensions[i];\n\t}\n\tif(ap2->nd > 1) {\n\t\tdimensions[j++] = ap2->dimensions[ap2->nd-1];\n\t}\n\t/*\n\tfprintf(stderr, \"nd=%d dimensions=\", nd);\n\t for(i=0; i prior1 ? ap2->ob_type : ap1->ob_type);\n\n\tret = (PyArrayObject *)PyArray_New(subtype, nd, dimensions, \n\t\t\t\t\t typenum, NULL, NULL, 0, 0, \n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\n\t/* Ensure that multiarray.dot([],[]) -> 0 */\n\tmemset(PyArray_DATA(ret), 0, PyArray_ITEMSIZE(ret));\n\n\tif (ret == NULL) goto fail;\n\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"dot not available for this type\");\n\t\tgoto fail;\n\t}\n\t\t\n\tis1 = ap1->strides[ap1->nd-1]; is2 = ap2->strides[matchDim];\n\tif(ap1->nd > 1)\n\t\tis1r = ap1->strides[ap1->nd-2];\n\telse\n\t\tis1r = ap1->strides[ap1->nd-1];\n\tis2r = ap2->strides[otherDim];\n\n\top = ret->data; os = ret->descr->elsize;\n\n\tip1 = ap1->data;\n\tfor(i1=0; i1data;\n\t\tfor(i2=0; i2ob_type, \n\t\t\t\t PyArray_DESCR(arr),\n\t\t\t\t 2, dims, \n\t\t\t\t NULL, NULL, 0, arr);\n\n\tif (ret == NULL) {\n\t\tPy_DECREF(arr);\n\t\treturn NULL;\n\t}\n\t/* do 2-d loop */\n\toptr = PyArray_DATA(ret);\n\tstr2 = elsize*dims[0];\n\tfor (i=0; idimensions[0];\n\tn2 = ap2->dimensions[0];\n\n\tif (n1 < n2) { \n\t\tret = ap1; ap1 = ap2; ap2 = ret; \n\t\tret = NULL; i = n1;n1=n2;n2=i;\n\t}\n\tlength = n1;\n\tn = n2;\n\tswitch(mode) {\n\tcase 0:\t\n\t\tlength = length-n+1;\n\t\tn_left = n_right = 0;\n\t\tbreak;\n\tcase 1:\n\t\tn_left = (intp)(n/2);\n\t\tn_right = n-n_left-1;\n\t\tbreak;\n\tcase 2:\n\t\tn_right = n-1;\n\t\tn_left = n-1;\n\t\tlength = length+n-1;\n\t\tbreak;\n\tdefault:\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mode must be 0, 1, or 2\");\n\t\tgoto fail;\n\t}\n\n\t/* Need to choose an output array that can hold a sum \n\t -- use priority to determine which subtype.\n\t */\n prior2 = PyArray_GetPriority((PyObject *)ap2, 0.0);\n prior1 = PyArray_GetPriority((PyObject *)ap1, 0.0);\n subtype = (prior2 > prior1 ? ap2->ob_type : ap1->ob_type);\n\t\n\tret = (PyArrayObject *)PyArray_New(subtype, 1,\n\t\t\t\t\t &length, typenum, \n\t\t\t\t\t NULL, NULL, 0, 0,\n (PyObject *)\n\t\t\t\t\t (prior2 > prior1 ? ap2 : ap1));\n\tif (ret == NULL) goto fail;\n\t\n\tdot = ret->descr->f->dotfunc;\n\tif (dot == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"function not available for this data type\");\n\t\tgoto fail;\n\t}\n\t\n\tis1 = ap1->strides[0]; is2 = ap2->strides[0];\n\top = ret->data; os = ret->descr->elsize;\n\t\n\tip1 = ap1->data; ip2 = ap2->data+n_left*is2;\n\tn = n-n_left;\n\tfor(i=0; idescr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Min\n*/\nstatic PyObject *\nPyArray_Min(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tret = PyArray_GenericReduceFunction(arr, n_ops.minimum, axis,\n\t\t\t\t\t arr->descr->type_num);\n\tPy_DECREF(arr);\n\treturn ret;\t \n}\n\n/*MULTIARRAY_API\n Ptp\n*/\nstatic PyObject *\nPyArray_Ptp(PyArrayObject *ap, int axis)\n{\n\tPyArrayObject *arr;\n\tPyObject *ret;\n\tPyObject *obj1=NULL, *obj2=NULL;\n\n\tif ((arr=(PyArrayObject *)_check_axis(ap, &axis, 0))==NULL)\n\t\treturn NULL;\n\tobj1 = PyArray_Max(arr, axis);\n\tif (obj1 == NULL) goto fail;\n\tobj2 = PyArray_Min(arr, axis);\n\tif (obj2 == NULL) goto fail;\n\tPy_DECREF(arr);\n\tret = PyNumber_Subtract(obj1, obj2);\n\tPy_DECREF(obj1);\n\tPy_DECREF(obj2);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(arr);\n\tPy_XDECREF(obj1);\n\tPy_XDECREF(obj2);\n\treturn NULL;\n}\n\n\n/*MULTIARRAY_API\n ArgMax\n*/\nstatic PyObject *\nPyArray_ArgMax(PyArrayObject *op, int axis) \n{\n\tPyArrayObject *ap=NULL, *rp=NULL;\n\tPyArray_ArgFunc* arg_func;\n\tchar *ip;\n\tintp *rptr;\n\tintp i, n, orign, m;\n\tint elsize;\n\t\n\tif ((ap=(PyAO *)_check_axis(op, &axis, 0))==NULL) return NULL;\n\n\tSWAPAXES(op, ap);\n\n\tap = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny((PyObject *)op, \n\t\t\t\t\t PyArray_NOTYPE, 1, 0);\n\n\tPy_DECREF(op);\n\tif (ap == NULL) return NULL;\n\t\n\targ_func = ap->descr->f->argmax;\n\tif (arg_func == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \"data type not ordered\");\n\t\tgoto fail;\n\t}\n\n\trp = (PyArrayObject *)PyArray_New(ap->ob_type, ap->nd-1,\n\t\t\t\t\t ap->dimensions, PyArray_INTP,\n\t\t\t\t\t NULL, NULL, 0, 0, \n (PyObject *)ap);\n\tif (rp == NULL) goto fail;\n\n\n\telsize = ap->descr->elsize;\n\tm = ap->dimensions[ap->nd-1];\n\tif (m == 0) {\n\t\tPyErr_SetString(MultiArrayError, \n\t\t\t\t\"attempt to get argmax/argmin \"\\\n\t\t\t\t\"of an empty sequence??\");\n\t\tgoto fail;\n\t}\n\tn = PyArray_SIZE(ap)/m;\n\trptr = (intp *)rp->data;\n\tfor (ip = ap->data, i=0; ind + indices->nd - 1;\n for (i=0; i< nd; i++) {\n if (i < axis) {\n shape[i] = self->dimensions[i];\n n *= shape[i];\n } else {\n if (i < axis+indices->nd) {\n shape[i] = indices->dimensions[i-axis];\n m *= shape[i];\n } else {\n shape[i] = self->dimensions[i-indices->nd+1];\n chunk *= shape[i];\n }\n }\n }\n\tPy_INCREF(self->descr);\n ret = (PyArrayObject *)PyArray_NewFromDescr(self->ob_type, \n\t\t\t\t\t\t self->descr,\n\t\t\t\t\t\t nd, shape, \n\t\t\t\t\t\t NULL, NULL, 0, \n\t\t\t\t\t\t (PyObject *)self);\n\t\n if (ret == NULL) goto fail;\n\t\n max_item = self->dimensions[axis];\n chunk = chunk * ret->descr->elsize;\n src = self->data;\n dest = ret->data;\n\t\n for(i=0; idata))[j];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \n\t\t\t\t\t\t\"index out of range for \"\\\n\t\t\t\t\t\t\"array\");\n goto fail;\n }\n memmove(dest, src+tmp*chunk, chunk);\n dest += chunk;\n }\n src += chunk*max_item;\n }\n\t\n PyArray_INCREF(ret);\n\n Py_XDECREF(indices);\n Py_XDECREF(self);\n\n return (PyObject *)ret;\n\t\n\t\n fail:\n Py_XDECREF(ret);\n Py_XDECREF(indices);\n Py_XDECREF(self);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array\n*/\nstatic PyObject *\nPyArray_Put(PyArrayObject *self, PyObject* values0, PyObject *indices0) \n{\n PyArrayObject *indices, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype; \n char *src, *dest;\n\n indices = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \"put: first argument must be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \"put: first argument must be contiguous\");\n return NULL;\n }\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n indices = (PyArrayObject *)PyArray_ContiguousFromAny(indices0, PyArray_INTP, 0, 0);\n if (indices == NULL) goto fail;\n ni = PyArray_SIZE(indices);\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n if (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\n if (nv > 0) { /* nv == 0 for a null array */\n if (thistype == PyArray_OBJECT) { \n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n Py_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+tmp*chunk)));\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((intp *)(indices->data))[i];\n if (tmp < 0) tmp = tmp+max_item;\n if ((tmp < 0) || (tmp >= max_item)) {\n PyErr_SetString(PyExc_IndexError, \"index out of range for array\");\n goto fail;\n }\n memmove(dest + tmp * chunk, src, chunk);\n }\n }\n\n }\n\n Py_XDECREF(values);\n Py_XDECREF(indices);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(indices);\n Py_XDECREF(values);\n return NULL;\n}\n\n/*MULTIARRAY_API\n Put values into an array according to a mask.\n*/\nstatic PyObject *\nPyArray_PutMask(PyArrayObject *self, PyObject* values0, PyObject* mask0) \n{\n PyArrayObject *mask, *values;\n int i, chunk, ni, max_item, nv, tmp, thistype;\n char *src, *dest;\n\n mask = NULL;\n values = NULL;\n\n if (!PyArray_Check(self)) {\n PyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"putmask: first argument must \"\\\n\t\t\t\t\"be an array\");\n return NULL;\n }\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: first argument must be contiguous\");\n return NULL;\n }\n\n max_item = PyArray_SIZE(self);\n dest = self->data;\n chunk = self->descr->elsize;\n\n mask = (PyArrayObject *)\\\n\t\tPyArray_FROM_OTF(mask0, PyArray_BOOL, CARRAY_FLAGS | FORCECAST);\n\tif (mask == NULL) goto fail;\n ni = PyArray_SIZE(mask);\n if (ni != max_item) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"putmask: mask and data must be \"\\\n\t\t\t\t\"the same size\");\n goto fail;\n }\n\n\tthistype = self->descr->type_num;\n values = (PyArrayObject *)\\\n\t\tPyArray_ContiguousFromAny(values0, thistype, 0, 0);\n\tif (values == NULL) goto fail;\n nv = PyArray_SIZE(values);\t /* zero if null array */\n if (nv > 0) {\n if (thistype == PyArray_OBJECT) {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) {\n\t\t\t\t\tPy_INCREF(*((PyObject **)src));\n Py_XDECREF(*((PyObject **)(dest+i*chunk)));\n memmove(dest + i * chunk, src, chunk);\n }\n\t\t\t}\n }\n else {\n for(i=0; idata + chunk * (i % nv);\n tmp = ((Bool *)(mask->data))[i];\n if (tmp) memmove(dest + i * chunk, src, chunk);\n\t\t\t}\n\t\t}\n }\n\n Py_XDECREF(values);\n Py_XDECREF(mask);\n Py_INCREF(Py_None);\n return Py_None;\n\t\n fail:\n Py_XDECREF(mask);\n Py_XDECREF(values);\n return NULL;\n}\n\n\n/* This conversion function can be used with the \"O&\" argument for\n PyArg_ParseTuple. It will immediately return an object of array type\n or will convert to a CARRAY any other object. \n\n If you use PyArray_Converter, you must DECREF the array when finished\n as you get a new reference to it.\n*/\n \n/*MULTIARRAY_API\n Useful to pass as converter function for O& processing in\n PyArgs_ParseTuple.\n*/\nstatic int \nPyArray_Converter(PyObject *object, PyObject **address) \n{\n if (PyArray_Check(object)) {\n *address = object;\n\t\tPy_INCREF(object);\n return PY_SUCCEED;\n }\n else {\n\t\t*address = PyArray_FromAny(object, NULL, 0, 0, CARRAY_FLAGS);\n\t\tif (*address == NULL) return PY_FAIL;\n\t\treturn PY_SUCCEED;\n }\n}\n\n/*MULTIARRAY_API\n Convert an object to true / false\n*/\nstatic int\nPyArray_BoolConverter(PyObject *object, Bool *val)\n{ \n if (PyObject_IsTrue(object))\n *val=TRUE;\n else *val=FALSE;\n if (PyErr_Occurred())\n return PY_FAIL;\n return PY_SUCCEED;\n}\n\n\n/*MULTIARRAY_API\n Typestr converter\n*/\nstatic int\nPyArray_TypestrConvert(int itemsize, int gentype)\n{\n\tregister int newtype = gentype;\n\t\n\tif (gentype == PyArray_GENBOOLLTR) {\n\t\tif (itemsize == 1)\n\t\t\tnewtype = PyArray_BOOL;\n\t\telse \n\t\t\tnewtype = PyArray_NOTYPE;\n\t}\n\telse if (gentype == PyArray_SIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_INT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_INT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_INT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_INT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_INT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\n\t}\n\n\telse if (gentype == PyArray_UNSIGNEDLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 1:\n\t\t\tnewtype = PyArray_UINT8;\n\t\t\tbreak;\n\t\tcase 2:\n\t\t\tnewtype = PyArray_UINT16;\n\t\t\tbreak;\n\t\tcase 4:\n\t\t\tnewtype = PyArray_UINT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_UINT64;\n\t\t\tbreak;\n#ifdef PyArray_INT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_UINT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t\tbreak;\n\t\t}\n\t}\n\telse if (gentype == PyArray_FLOATINGLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 4:\n\t\t\tnewtype = PyArray_FLOAT32;\n\t\t\tbreak;\n\t\tcase 8:\n\t\t\tnewtype = PyArray_FLOAT64;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 10:\n\t\t\tnewtype = PyArray_FLOAT80;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 12:\n\t\t\tnewtype = PyArray_FLOAT96;\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 16:\n\t\t\tnewtype = PyArray_FLOAT128;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\t\n\telse if (gentype == PyArray_COMPLEXLTR) {\n\t\tswitch(itemsize) {\n\t\tcase 8:\n\t\t\tnewtype = PyArray_COMPLEX64;\n\t\t\tbreak;\n\t\tcase 16:\n\t\t\tnewtype = PyArray_COMPLEX128;\n\t\t\tbreak;\n#ifdef PyArray_FLOAT80\n case 20:\n\t\t\tnewtype = PyArray_COMPLEX160;\n\t\t\tbreak;\n#endif\n#ifdef PyArray_FLOAT96\n\t\tcase 24:\n\t\t\tnewtype = PyArray_COMPLEX192;\t\t\t\n\t\t\tbreak;\n#endif\t\t \n#ifdef PyArray_FLOAT128\n\t\tcase 32:\n\t\t\tnewtype = PyArray_COMPLEX256;\n\t\t\tbreak;\n#endif\n\t\tdefault:\n\t\t\tnewtype = PyArray_NOTYPE;\n\t\t}\t\t\n\t}\n\n\treturn newtype;\n}\n\n\n/* this function takes a Python object which exposes the (single-segment)\n buffer interface and returns a pointer to the data segment\n \n You should increment the reference count by one of buf->base\n if you will hang on to a reference\n\n You only get a borrowed reference to the object. Do not free the\n memory...\n*/\n\n\n/*MULTIARRAY_API\n Get buffer chunk from object\n*/\nstatic int\nPyArray_BufferConverter(PyObject *obj, PyArray_Chunk *buf)\n{\n int buflen;\n\n buf->ptr = NULL;\n buf->flags = BEHAVED_FLAGS;\n buf->base = NULL;\n\n\tif (obj == Py_None)\n\t\treturn PY_SUCCEED;\n\n if (PyObject_AsWriteBuffer(obj, &(buf->ptr), &buflen) < 0) {\n PyErr_Clear();\n buf->flags &= ~WRITEABLE;\n if (PyObject_AsReadBuffer(obj, (const void **)&(buf->ptr), \n &buflen) < 0)\n return PY_FAIL;\n }\n buf->len = (intp) buflen;\n \n /* Point to the base of the buffer object if present */\n if (PyBuffer_Check(obj)) buf->base = ((PyArray_Chunk *)obj)->base;\n if (buf->base == NULL) buf->base = obj;\n \n return PY_SUCCEED; \n}\n\n\n\n/* This function takes a Python sequence object and allocates and\n fills in an intp array with the converted values.\n\n **Remember to free the pointer seq.ptr when done using\n PyDimMem_FREE(seq.ptr)**\n*/\n\n/*MULTIARRAY_API\n Get intp chunk from sequence\n*/\nstatic int\nPyArray_IntpConverter(PyObject *obj, PyArray_Dims *seq)\n{\n int len;\n int nd;\n\n seq->ptr = NULL;\n if (obj == Py_None) return PY_SUCCEED;\n len = PySequence_Size(obj);\n if (len == -1) { /* Check to see if it is a number */\n if (PyNumber_Check(obj)) len = 1;\n }\n if (len < 0) {\n PyErr_SetString(PyExc_TypeError, \n \"expected sequence object with len >= 0\");\n return PY_FAIL;\n }\n if (len > MAX_DIMS) {\n PyErr_Format(PyExc_ValueError, \"sequence too large; \" \\\n \"must be smaller than %d\", MAX_DIMS);\n return PY_FAIL;\n }\n\tif (len > 0) {\n\t\tseq->ptr = PyDimMem_NEW(len);\n\t\tif (seq->ptr == NULL) {\n\t\t\tPyErr_NoMemory();\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n seq->len = len;\n nd = PyArray_IntpFromSequence(obj, (intp *)seq->ptr, len);\n if (nd == -1 || nd != len) {\n\t\tPyDimMem_FREE(seq->ptr);\n\t\tseq->ptr=NULL;\n\t\treturn PY_FAIL;\n\t}\n return PY_SUCCEED;\n}\n\n\n/* A tuple type would be either (generic typeobject, typesize) \n or (fixed-length data-type, shape) \n\n or (inheriting data-type, new-data-type)\n The new data-type must have the same itemsize as the inheriting data-type\n unless the latter is 0 \n \n Thus (int32, {'real':(int16,0),'imag',(int16,2)})\n\n is one way to specify a descriptor that will give \n a['real'] and a['imag'] to an int32 array.\n*/\n\n/* leave type reference alone */\nstatic PyArray_Descr *\n_use_inherit(PyArray_Descr *type, PyObject *newobj, int *errflag) \n{\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n\t\n\t*errflag = 0;\n\tif (!PyArray_DescrConverter(newobj, &conv)) {\n\t\treturn NULL;\n\t}\n\t*errflag = 1;\n\tif (type == &OBJECT_Descr) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"cannot base a new descriptor on an\"\\\n\t\t\t\t\" OBJECT descriptor.\");\n\t\treturn NULL;\n\t}\n\tnew = PyArray_DescrNew(type);\n\tif (new == NULL) return NULL;\n\n\tif (new->elsize && new->elsize != conv->elsize) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"mismatch in size of old\"\\\n\t\t\t\t\"and new data-descriptor\");\n\t\treturn NULL;\n\t}\n\tnew->elsize = conv->elsize;\n\tif (conv->fields != Py_None) {\n\t\tnew->fields = conv->fields;\n\t\tPy_XINCREF(new->fields);\n\t}\n\tPy_DECREF(conv);\n\t*errflag = 0;\n\treturn new;\n}\n\nstatic PyArray_Descr *\n_convert_from_tuple(PyObject *obj) \n{\n\tPyArray_Descr *type, *res;\n\tPyObject *val;\n\tint errflag;\n\t\n\tif (PyTuple_GET_SIZE(obj) != 2) return NULL;\n\n\tif (!PyArray_DescrConverter(PyTuple_GET_ITEM(obj,0), &type)) \n\t\treturn NULL;\n\tval = PyTuple_GET_ITEM(obj,1);\n\t/* try to interpret next item as a type */\n\tres = _use_inherit(type, val, &errflag);\n\tif (res || errflag) {\n\t\tPy_DECREF(type);\n\t\tif (res) return res;\n\t\telse return NULL;\n\t}\n\tPyErr_Clear();\n\t/* We get here if res was NULL but errflag wasn't set\n\t --- i.e. the conversion to a data-descr failed in _use_inherit\n\t*/\n\n\tif (type->elsize == 0) { /* interpret next item as a typesize */\n\t\tint itemsize;\n\t\titemsize = PyArray_PyIntAsInt(PyTuple_GET_ITEM(obj,1));\n\t\tif (error_converting(itemsize)) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid itemsize in generic type \"\\\n\t\t\t\t\t\"tuple\");\n\t\t\tgoto fail;\n\t\t}\n\t\tPyArray_DESCR_REPLACE(type);\n\t\ttype->elsize = itemsize;\n\t}\n\telse {\n\t\t/* interpret next item as shape (if it's a tuple)\n\t\t and reset the type to PyArray_VOID with \n\t\t anew fields attribute. \n\t */\n\t\tPyArray_Dims shape={NULL,-1};\n\t\tPyArray_Descr *newdescr;\n\t\tif (!(PyArray_IntpConverter(val, &shape)) || \n\t\t (shape.len > MAX_DIMS)) {\n\t\t\tPyDimMem_FREE(shape.ptr);\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"invalid shape in fixed-type tuple.\");\n\t\t\tgoto fail;\n\t\t}\n\t\tnewdescr = PyArray_DescrNewFromType(PyArray_VOID);\n\t\tif (newdescr == NULL) {PyDimMem_FREE(shape.ptr); goto fail;}\n\t\tnewdescr->elsize = type->elsize;\n\t\tnewdescr->elsize *= PyArray_MultiplyList(shape.ptr, \n\t\t\t\t\t\t\t shape.len);\n\t\tPyDimMem_FREE(shape.ptr);\n\t\tnewdescr->subarray = _pya_malloc(sizeof(PyArray_ArrayDescr));\n\t\tnewdescr->subarray->base = type;\n\t\tPy_INCREF(val);\n\t\tnewdescr->subarray->shape = val;\n\t\tPy_XDECREF(newdescr->fields);\n\t\tnewdescr->fields = NULL;\n\t\ttype = newdescr;\n\t}\n\treturn type;\n\n fail:\n\tPy_XDECREF(type);\n\treturn NULL;\n}\n\n/* obj is a list. Each item is a tuple with\n\n(field-name, data-type (either a list or a string), and an optional \n shape parameter).\n*/\nstatic PyArray_Descr *\n_convert_from_array_descr(PyObject *obj)\n{\n\tint n, i, totalsize;\n\tint ret;\n\tPyObject *fields, *item, *newobj;\n\tPyObject *name, *key, *tup;\n\tPyObject *nameslist;\n\tPyArray_Descr *new;\n\tPyArray_Descr *conv;\n\t\n\tn = PyList_GET_SIZE(obj);\t\n\tnameslist = PyList_New(n);\n\tif (!nameslist) return NULL;\n\ttotalsize = 0;\n\tfields = PyDict_New();\n\tfor (i=0; ielsize;\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(tup);\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n\tnew->elsize = totalsize;\n\treturn new;\n \n fail:\n\tPy_DECREF(fields);\n\tPy_DECREF(nameslist);\n\treturn NULL;\n\n}\n\n/* a list specifying a data-type can just be\n a list of formats. The names for the fields\n will default to f1, f2, f3, and so forth.\n\n or it can be an array_descr format string -- in which case\n align must be 0. \n*/\n\nstatic PyArray_Descr *\n_convert_from_list(PyObject *obj, int align, int try_descr)\n{\n\tint n, i;\n\tint totalsize;\n\tPyObject *fields;\n\tPyArray_Descr *conv=NULL;\n\tPyArray_Descr *new;\n\tPyObject *key, *tup;\n\tPyObject *nameslist=NULL;\n \tint ret;\n\tint maxalign=0;\n\t\n\tn = PyList_GET_SIZE(obj);\n\ttotalsize = 0;\n\tif (n==0) return NULL;\n\tnameslist = PyList_New(n);\n\tif (!nameslist) return NULL;\n\tfields = PyDict_New();\n\tfor (i=0; ialignment;\n\t\t\tif (_align > 1) totalsize =\t\t\t\\\n\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\tmaxalign = MAX(maxalign, _align);\n\t\t}\n\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong((long) totalsize));\n\t\tPyDict_SetItem(fields, key, tup);\n\t\tPy_DECREF(tup);\n\t\tPyList_SET_ITEM(nameslist, i, key);\n\t\tif (ret == PY_FAIL) goto fail;\n\t\ttotalsize += conv->elsize;\n\t}\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, nameslist);\n\tPy_DECREF(key);\n\tPy_DECREF(nameslist);\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tnew->fields = fields;\n\tif (maxalign > 1) {\n\t\ttotalsize = ((totalsize+maxalign-1)/maxalign)*maxalign;\n\t}\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\treturn new;\n\n fail:\n\tPy_DECREF(nameslist);\n\tPy_DECREF(fields);\n\tif (!try_descr) return NULL;\n\tif (align) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"failed to convert from list of formats \"\\\n\t\t\t\t\"and align cannot be 1 for conversion from \"\\\n\t\t\t\t\"array_descr structure\");\n\t\treturn NULL;\n\t}\n\tPyErr_Clear();\n\treturn _convert_from_array_descr(obj);\n}\n\n\n/* comma-separated string */\n/* this is the format developed by the numarray records module */\n/* and implemented by the format parser in that module */\n/* this is an alternative implementation found in the _internal.py \n file patterned after that one -- the approach is to try to convert \n to a list (with tuples if any repeat information is present) \n and then call the _convert_from_list)\n*/\n\nstatic PyArray_Descr *\n_convert_from_commastring(PyObject *obj, int align)\n{\n\tPyObject *listobj;\n\tPyArray_Descr *res;\n\n\tif (!PyString_Check(obj)) return NULL;\n listobj = PyObject_CallMethod(_numpy_internal, \"_commastring\",\n\t\t\t\t \"O\", obj);\n\tif (!listobj) return NULL;\n\tres = _convert_from_list(listobj, align, 0);\n\tPy_DECREF(listobj);\n\tif (!res && !PyErr_Occurred()) {\n\t\tPyErr_SetString(PyExc_ValueError, \"invalid data-type\");\n\t\treturn NULL;\n\t}\n\treturn res;\n}\n\n\n\n/* a dictionary specifying a data-type\n must have at least two and up to four\n keys These must all be sequences of the same length.\n\n \"names\" --- field names \n \"formats\" --- the data-type descriptors for the field.\n \n Optional:\n\n \"offsets\" --- integers indicating the offset into the \n record of the start of the field.\n\t\t if not given, then \"consecutive offsets\" \n\t\t will be assumed and placed in the dictionary.\n \n \"titles\" --- Allows the use of an additional key\n for the fields dictionary.\n \nAttribute-lookup-based field names merely has to query the fields \ndictionary of the data-descriptor. Any result present can be used\nto return the correct field.\n\nSo, the notion of what is a name and what is a title is really quite\narbitrary. \n\nWhat does distinguish a title, however, is that if it is not None, \nit will be placed at the end of the tuple inserted into the \nfields dictionary.\n\nIf the dictionary does not have \"names\" and \"formats\" entries,\nthen it will be checked for conformity and used directly. \n*/\n\nstatic PyArray_Descr *\n_use_fields_dict(PyObject *obj, int align)\n{\n return (PyArray_Descr *)PyObject_CallMethod(_numpy_internal, \n\t\t\t\t\t\t \"_usefields\", \n\t\t\t\t\t\t \"Oi\", obj, align);\n}\n\nstatic PyArray_Descr *\n_convert_from_dict(PyObject *obj, int align)\n{\n\tPyArray_Descr *new;\n\tPyObject *fields=NULL;\n\tPyObject *names, *offsets, *descrs, *titles, *key;\n\tint n, i;\n\tint totalsize;\n\tint maxalign=0;\n\t\n\tfields = PyDict_New();\n\tif (fields == NULL) return (PyArray_Descr *)PyErr_NoMemory();\n\t\n\tnames = PyDict_GetItemString(obj, \"names\");\n\tdescrs = PyDict_GetItemString(obj, \"formats\");\n\n\tif (!names || !descrs) {\n\t\tPy_DECREF(fields);\n\t\treturn _use_fields_dict(obj, align);\n\t}\n\tn = PyObject_Length(names);\n\toffsets = PyDict_GetItemString(obj, \"offsets\");\n\ttitles = PyDict_GetItemString(obj, \"titles\");\n\tif ((n > PyObject_Length(descrs)) ||\t\t\t\\\n\t (offsets && (n > PyObject_Length(offsets))) ||\t\\\n\t (titles && (n > PyObject_Length(titles)))) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"all items in the dictionary must have\" \\\n\t\t\t\t\" the same length.\");\n\t\tgoto fail;\n\t}\n\n\ttotalsize = 0;\n\tfor(i=0; i totalsize) totalsize = offset;\n\t\t}\n\t\telse {\n\t\t\tPyTuple_SET_ITEM(tup, 1, PyInt_FromLong(totalsize));\n\t\t\tif (align) {\n\t\t\t\tint _align = newdescr->alignment;\n\t\t\t\tif (_align > 1) totalsize =\t\t\\\n\t\t\t\t\t((totalsize + _align - 1)/_align)*_align;\n\t\t\t\tmaxalign = MAX(maxalign,_align);\n\t\t\t}\n\t\t}\n\t\tif (len == 3) PyTuple_SET_ITEM(tup, 2, item);\n\t\tname = PyObject_GetItem(names, index);\n\t\tPy_DECREF(index);\n\n\t\t/* Insert into dictionary */\n\t\tPyDict_SetItem(fields, name, tup);\n\t\tPy_DECREF(name);\n\t\tif (len == 3) PyDict_SetItem(fields, item, tup);\n\t\tPy_DECREF(tup);\n\t\tif ((ret == PY_FAIL) || (newdescr->elsize == 0)) goto fail;\n\t\ttotalsize += newdescr->elsize;\n\t}\n\n\tnew = PyArray_DescrNewFromType(PyArray_VOID);\n\tif (new == NULL) goto fail;\n\tif (maxalign > 1)\n\t\ttotalsize = ((totalsize + maxalign - 1)/maxalign)*maxalign;\n\tif (align) new->alignment = maxalign;\n\tnew->elsize = totalsize;\n\tkey = PyInt_FromLong(-1);\n\tPyDict_SetItem(fields, key, names);\n\tPy_DECREF(key);\n\tnew->fields = fields;\n\treturn new;\n\n fail:\n\tPy_XDECREF(fields);\n\treturn NULL;\n}\n\n/* \n any object with \n the .fields attribute and/or .itemsize attribute \n (if the .fields attribute does not give\n the total size -- i.e. a partial record naming).\n If itemsize is given it must be >= size computed from fields\n \n The .fields attribute must return a convertible dictionary if \n present. Result inherits from PyArray_VOID.\n*/\n\n\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to NULL\n*/\nstatic int\nPyArray_DescrConverter2(PyObject *obj, PyArray_Descr **at)\n{\n\tif (obj == Py_None) {\n\t\t*at = NULL;\n\t\treturn PY_SUCCEED;\n\t}\n\telse return PyArray_DescrConverter(obj, at);\n}\n\n/* This function takes a Python object representing a type and converts it \n to a the correct PyArray_Descr * structure to describe the type.\n \n Many objects can be used to represent a data-type which in NumPy is\n quite a flexible concept. \n\n This is the central code that converts Python objects to \n Type-descriptor objects that are used throughout numpy.\n */\n\n/* new reference in *at */\n/*MULTIARRAY_API\n Get typenum from an object -- None goes to &LONG_descr\n*/\nstatic int\nPyArray_DescrConverter(PyObject *obj, PyArray_Descr **at)\n{\n char *type;\n int check_num=PyArray_NOTYPE+10;\n\tint len;\n\tPyObject *item;\n\tint elsize = 0;\n\tchar endian = '=';\n\n\t*at=NULL;\n\t\n\t/* default */\n if (obj == Py_None) {\n\t\t*at = PyArray_DescrFromType(PyArray_LONG);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n\tif (PyArray_DescrCheck(obj)) {\n\t\t*at = (PyArray_Descr *)obj;\n\t\tPy_INCREF(*at);\n\t\treturn PY_SUCCEED;\n\t}\n\t\n if (PyType_Check(obj)) {\n\t\tif (PyType_IsSubtype((PyTypeObject *)obj, \n\t\t\t\t &PyGenericArrType_Type)) {\n\t\t\t*at = PyArray_DescrFromTypeObject(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t\telse return PY_FAIL;\n\t\t}\n\t\tcheck_num = PyArray_OBJECT;\n\t\tif (obj == (PyObject *)(&PyInt_Type))\n\t\t\tcheck_num = PyArray_LONG;\n\t\telse if (obj == (PyObject *)(&PyLong_Type))\n\t\t\tcheck_num = PyArray_LONGLONG;\n\t\telse if (obj == (PyObject *)(&PyFloat_Type)) \n\t\t\tcheck_num = PyArray_DOUBLE;\n\t\telse if (obj == (PyObject *)(&PyComplex_Type)) \n\t\t\tcheck_num = PyArray_CDOUBLE;\n\t\telse if (obj == (PyObject *)(&PyBool_Type))\n\t\t\tcheck_num = PyArray_BOOL;\n else if (obj == (PyObject *)(&PyString_Type))\n check_num = PyArray_STRING;\n else if (obj == (PyObject *)(&PyUnicode_Type))\n check_num = PyArray_UNICODE;\n\t\telse if (obj == (PyObject *)(&PyBuffer_Type))\n\t\t\tcheck_num = PyArray_VOID;\n\t\telse {\n\t\t\t*at = _arraydescr_fromobj(obj);\n\t\t\tif (*at) return PY_SUCCEED;\n\t\t}\n\t\tgoto finish;\n\t}\n\n\t/* or a typecode string */\n\n\tif (PyString_Check(obj)) {\n\t\t/* Check for a string typecode. */\n\t\ttype = PyString_AS_STRING(obj);\n\t\tlen = PyString_GET_SIZE(obj);\n\t\tif (len <= 0) goto fail;\n\t\tcheck_num = (int) type[0];\n\t\tif ((char) check_num == '>' || (char) check_num == '<' || \\\n\t\t (char) check_num == '|') {\n\t\t\tif (len <= 1) goto fail;\n\t\t\tendian = (char) check_num;\n\t\t\ttype++; len--;\n\t\t\tcheck_num = (int) type[0];\n\t\t\tif (endian == '|') endian = '=';\n\t\t}\n\t\tif (len > 1) {\n\t\t\telsize = atoi(type+1);\n\t\t\tif (len > 2 && elsize < 10) {\n\t\t\t\t/* perhaps commas present */\n\t\t\t\tint i;\n\t\t\t\tfor (i=1;ielsize == 0) && (elsize != 0)) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->elsize = elsize;\n\t}\n\tif (endian != '=' && PyArray_ISNBO(endian)) endian = '='; \n\t\n\tif (endian != '=' && (*at)->byteorder != '|' &&\t\\\n\t (*at)->byteorder != endian) {\n\t\tPyArray_DESCR_REPLACE(*at);\n\t\t(*at)->byteorder = endian;\n\t}\n\t\n return PY_SUCCEED;\n\n fail:\n\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\"data type not understood\");\n\t*at=NULL;\n\treturn PY_FAIL;\n}\t\n\n/*MULTIARRAY_API\n Convert object to endian\n*/\nstatic int\nPyArray_ByteorderConverter(PyObject *obj, char *endian)\n{\n\tchar *str;\n\t*endian = PyArray_SWAP;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Byteorder string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\t*endian = str[0];\n\tif (str[0] != PyArray_BIG && str[0] != PyArray_LITTLE &&\t\\\n\t str[0] != PyArray_NATIVE) {\n\t\tif (str[0] == 'b' || str[0] == 'B')\n\t\t\t*endian = PyArray_BIG;\n\t\telse if (str[0] == 'l' || str[0] == 'L')\n\t\t\t*endian = PyArray_LITTLE;\n\t\telse if (str[0] == 'n' || str[0] == 'N')\n\t\t\t*endian = PyArray_NATIVE;\n\t\telse if (str[0] == 'i' || str[0] == 'I')\n\t\t\t*endian = PyArray_IGNORE;\n\t\telse if (str[0] == 's' || str[0] == 'S')\n\t\t\t*endian = PyArray_SWAP;\n\t\telse {\n\t\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t\t \"%s is an unrecognized byteorder\",\n\t\t\t\t str);\n\t\t\treturn PY_FAIL;\n\t\t}\n\t}\n\treturn PY_SUCCEED;\n}\n\n/*MULTIARRAY_API\n Convert object to sort kind \n*/\nstatic int\nPyArray_SortkindConverter(PyObject *obj, PyArray_SORTKIND *sortkind)\n{\n\tchar *str;\n\t*sortkind = PyArray_QUICKSORT;\n\tstr = PyString_AsString(obj);\n\tif (!str) return PY_FAIL;\n\tif (strlen(str) < 1) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Sort kind string must be at least length 1\");\n\t\treturn PY_FAIL;\n\t}\n\tif (str[0] == 'q' || str[0] == 'Q')\n\t\t*sortkind = PyArray_QUICKSORT;\n\telse if (str[0] == 'h' || str[0] == 'H')\n\t\t*sortkind = PyArray_HEAPSORT;\n\telse if (str[0] == 'm' || str[0] == 'M')\n\t\t*sortkind = PyArray_MERGESORT;\n\telse if (str[0] == 't' || str[0] == 'T')\n\t\t*sortkind = PyArray_TIMSORT;\n\telse {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"%s is an unrecognized kind of sort\",\n\t\t\t str);\n\t\treturn PY_FAIL;\n\t}\n\treturn PY_SUCCEED;\n}\n\n\n/* This function returns true if the two typecodes are \n equivalent (same basic kind and same itemsize).\n*/\n\n/*MULTIARRAY_API*/\nstatic Bool\nPyArray_EquivTypes(PyArray_Descr *typ1, PyArray_Descr *typ2)\n{\n\tregister int typenum1=typ1->type_num;\n\tregister int typenum2=typ2->type_num;\n\tregister int size1=typ1->elsize;\n\tregister int size2=typ2->elsize;\n\n\tif (size1 != size2) return FALSE;\n\tif (typ1->fields != typ2->fields) return FALSE;\n\tif (PyArray_ISNBO(typ1->byteorder) != PyArray_ISNBO(typ2->byteorder))\n\t\treturn FALSE;\n\n\tif (typenum1 == PyArray_VOID || \\\n\t typenum2 == PyArray_VOID) {\n\t\treturn ((typenum1 == typenum2) && \n\t\t\t(typ1->typeobj == typ2->typeobj) &&\n\t\t\t(typ1->fields == typ2->fields));\n\t}\n\treturn (typ1->kind == typ2->kind);\n}\n\n/*** END C-API FUNCTIONS **/\n\n\n#define _ARET(x) PyArray_Return((PyArrayObject *)(x))\n\nstatic char doc_fromobject[] = \"array(object, dtype=None, copy=1, fortran=0, \"\\\n \"subok=0)\\n\"\\\n \"will return a new array formed from the given object type given.\\n\"\\\n \"Object can anything with an __array__ method, or any object\\n\"\\\n \"exposing the array interface, or any (nested) sequence.\\n\"\\\n \"If no type is given, then the type will be determined as the\\n\"\\\n \"minimum type required to hold the objects in the sequence.\\n\"\\\n \"If copy is zero and sequence is already an array with the right \\n\"\\\n \"type, a reference will be returned. If the sequence is an array,\\n\"\\\n \"type can be used only to upcast the array. For downcasting \\n\"\\\n \"use .astype(t) method. If subok is true, then subclasses of the\\n\"\\\n \"array may be returned. Otherwise, a base-class ndarray is returned\";\n\nstatic PyObject *\n_array_fromobject(PyObject *ignored, PyObject *args, PyObject *kws)\n{\n\tPyObject *op, *ret=NULL;\n\tstatic char *kwd[]= {\"object\", \"dtype\", \"copy\", \"fortran\", \"subok\", \n NULL};\n Bool subok=FALSE;\n\tBool copy=TRUE;\n\tPyArray_Descr *type=NULL;\n\tPyArray_Descr *oldtype=NULL;\n\tBool fortran=FALSE;\n\tint flags=0;\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|O&O&O&O&\", kwd, &op, \n\t\t\t\t\tPyArray_DescrConverter2,\n &type, \n\t\t\t\t\tPyArray_BoolConverter, ©, \n\t\t\t\t\tPyArray_BoolConverter, &fortran,\n PyArray_BoolConverter, &subok)) \n\t\treturn NULL;\n\n\t/* fast exit if simple call */\n\tif ((PyArray_CheckExact(op) || PyBigArray_CheckExact(op))) {\n\t\tif (type==NULL) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\treturn op;\n\t\t\t}\n\t\t\telse {\n\t\t\t\treturn PyArray_NewCopy((PyArrayObject*)op, \n\t\t\t\t\t\t fortran);\n\t\t\t}\n\t\t}\n\t\t/* One more chance */\n\t\toldtype = PyArray_DESCR(op);\n\t\tif (PyArray_EquivTypes(oldtype, type)) {\n\t\t\tif (!copy && fortran==PyArray_ISFORTRAN(op)) {\n\t\t\t\tPy_INCREF(op);\n\t\t\t\treturn op;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tret = PyArray_NewCopy((PyArrayObject*)op,\n\t\t\t\t\t\t fortran);\n\t\t\t\tif (oldtype == type) return ret;\n\t\t\t\tPy_INCREF(oldtype);\n\t\t\t\tPy_DECREF(PyArray_DESCR(ret));\n\t\t\t\tPyArray_DESCR(ret) = oldtype;\n\t\t\t\treturn ret;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (copy) {\n\t\tflags = ENSURECOPY;\n\t}\n\tif (fortran) {\n\t\tflags |= FORTRAN;\n\t}\n if (!subok) {\n flags |= ENSUREARRAY;\n }\n\n\tif ((ret = PyArray_FromAny(op, type, 0, 0, flags)) == NULL) \n\t\treturn NULL;\n\n\treturn ret;\n}\n\n/* accepts NULL type */\n/* steals referenct to type */\n/*MULTIARRAY_API\n Empty\n*/\nstatic PyObject *\nPyArray_Empty(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n \n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type, nd, dims, \n\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n PyArray_FillObjectArray(ret, Py_None);\n\t}\n\treturn (PyObject *)ret;\n}\n\n\nstatic char doc_empty[] = \"empty((d1,...,dn),dtype=int,fortran=0) will return a new array\\n of shape (d1,...,dn) and given type with all its entries uninitialized. This can be faster than zeros.\";\n\nstatic PyObject *\narray_empty(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter, &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Empty(shape.len, shape.ptr, typecode, fortran); \n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_scalar[] = \"scalar(dtypedescr,obj) will return a new scalar array of the given type initialized with obj. Mainly for pickle support. The dtypedescr must be a valid data-type descriptor. If dtypedescr corresponds to an OBJECT descriptor, then obj can be any object, otherwise obj must be a string. If obj is not given it will be interpreted as None for object type and zeros for all other types.\";\n\nstatic PyObject *\narray_scalar(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n \n\tstatic char *kwlist[] = {\"dtypedescr\",\"obj\", NULL};\n\tPyArray_Descr *typecode;\n\tPyObject *obj=NULL;\n\tint alloc=0;\n\tvoid *dptr;\n\tPyObject *ret;\n\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|O\",\n\t\t\t\t\t kwlist, &PyArrayDescr_Type, \n\t\t\t\t\t &typecode,\n\t\t\t\t\t &obj)) \n\t\treturn NULL;\n\t\t\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError,\t\t\\\n\t\t\t\t\"itemsize cannot be zero\");\n\t\treturn NULL;\n\t}\n\n\tif (typecode->type_num == PyArray_OBJECT) {\n\t\tif (obj == NULL) obj = Py_None;\n\t\tdptr = &obj;\n\t}\n\telse {\n\t\tif (obj == NULL) {\n\t\t\tdptr = _pya_malloc(typecode->elsize);\n\t\t\tif (dptr == NULL) {\n\t\t\t\treturn PyErr_NoMemory();\n\t\t\t}\n\t\t\tmemset(dptr, '\\0', typecode->elsize);\n\t\t\talloc = 1;\n\t\t}\n\t\telse {\n\t\t\tif (!PyString_Check(obj)) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\t\"initializing object must \"\\\n\t\t\t\t\t\t\"be a string\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tif (PyString_GET_SIZE(obj) < typecode->elsize) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\t\t\"initialization string is too\"\\\n\t\t\t\t\t\t\" small\");\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tdptr = PyString_AS_STRING(obj);\n\t\t}\n\t}\n\n\tret = PyArray_Scalar(dptr, typecode, NULL);\n\t\n\t/* free dptr which contains zeros */\n\tif (alloc) _pya_free(dptr);\n\treturn ret;\n}\n\n\n/* steal a reference */\n/* accepts NULL type */\n/*MULTIARRAY_API\n Zeros\n*/\nstatic PyObject *\nPyArray_Zeros(int nd, intp *dims, PyArray_Descr *type, int fortran)\n{\n\tPyArrayObject *ret;\n\tintp n;\n\n\tif (!type) type = PyArray_DescrFromType(PyArray_LONG);\n\tret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t type,\n\t\t\t\t\t\t nd, dims, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t fortran, NULL);\n\tif (ret == NULL) return NULL;\n \n\tif ((PyArray_TYPE(ret) == PyArray_OBJECT)) {\n\t\tPyObject *zero = PyInt_FromLong(0);\n PyArray_FillObjectArray(ret, zero);\n Py_DECREF(zero);\n\t}\n\telse {\n\t\tn = PyArray_NBYTES(ret);\n\t\tmemset(ret->data, 0, n);\n\t}\n\treturn (PyObject *)ret;\n\n}\n\nstatic char doc_zeros[] = \"zeros((d1,...,dn),dtype=int,fortran=0) will return a new array of shape (d1,...,dn) and type typecode with all it's entries initialized to zero.\";\n\n\nstatic PyObject *\narray_zeros(PyObject *ignored, PyObject *args, PyObject *kwds) \n{\n\tstatic char *kwlist[] = {\"shape\",\"dtype\",\"fortran\",NULL};\n\tPyArray_Descr *typecode=NULL;\n PyArray_Dims shape = {NULL, 0};\n\tBool fortran = FALSE;\t\n PyObject *ret=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&\",\n\t\t\t\t\t kwlist, PyArray_IntpConverter,\n &shape, \n PyArray_DescrConverter,\n\t\t\t\t\t &typecode, \n\t\t\t\t\t PyArray_BoolConverter,\n\t\t\t\t\t &fortran)) \n\t\tgoto fail;\n\n\tret = PyArray_Zeros(shape.len, shape.ptr, typecode, (int) fortran);\n PyDimMem_FREE(shape.ptr);\n return ret;\n\n fail:\n\tPyDimMem_FREE(shape.ptr);\n\treturn ret;\n}\n\nstatic char doc_set_typeDict[] = \"set_typeDict(dict) set the internal \"\\\n\t\"dictionary that can look up an array type using a registered \"\\\n\t\"code\";\n\nstatic PyObject *\narray_set_typeDict(PyObject *ignored, PyObject *args)\n{\n\tPyObject *dict;\n\tif (!PyArg_ParseTuple(args, \"O\", &dict)) return NULL;\n\tPy_XDECREF(typeDict); /* Decrement old reference (if any)*/\n\ttypeDict = dict;\n\tPy_INCREF(dict); /* Create an internal reference to it */\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\n/* steals a reference to dtype -- accepts NULL */\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromString(char *data, intp slen, PyArray_Descr *dtype, intp n)\n{\n\tint itemsize;\n\tPyArrayObject *ret;\n\n\tif (dtype == NULL)\n\t\tdtype=PyArray_DescrFromType(PyArray_LONG);\n\t\n\tif (dtype == &OBJECT_Descr) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"Cannot create an object array from a\"\\\n\t\t\t\t\" string.\");\n\t\tPy_DECREF(dtype);\n\t\treturn NULL;\n\t}\n\t\n\titemsize = dtype->elsize;\n\tif (itemsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"zero-valued itemsize\");\n\t\tPy_DECREF(dtype);\n\t\treturn NULL;\n\t}\n\t\n\tif (n < 0 ) {\n\t\tif (slen % itemsize != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"string size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\t\tn = slen/itemsize;\n\t} else {\n\t\tif (slen < n*itemsize) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"string is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\tPy_DECREF(dtype);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t dtype,\n\t\t\t\t\t\t\t 1, &n, \n\t\t\t\t\t\t\t NULL, NULL,\n\t\t\t\t\t\t\t 0, NULL)) == NULL)\n\t\treturn NULL;\n\t\t\n\tmemcpy(ret->data, data, n*dtype->elsize);\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_fromString[] = \"fromstring(string, dtype=int, count=-1) returns a new 1d array initialized from the raw binary data in string. If count is positive, the new array will have count elements, otherwise it's size is determined by the size of string.\";\n\nstatic PyObject *\narray_fromString(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tchar *data;\n\tlonglong nin=-1;\n\tint s;\n\tstatic char *kwlist[] = {\"string\", \"dtype\", \"count\", NULL};\n\tPyArray_Descr *descr=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"s#|O&L\", kwlist, \n\t\t\t\t\t &data, &s, \n\t\t\t\t\t PyArray_DescrConverter, &descr,\n\t\t\t\t\t &nin)) {\n\t\treturn NULL;\n\t}\n\n\treturn PyArray_FromString(data, (intp)s, descr, (intp)nin);\n}\n\n/* This needs an open file object and reads it in directly. \n memory-mapped files handled differently through buffer interface.\n\nfile pointer number in resulting 1d array \n(can easily reshape later, -1 for to end of file)\ntype of array\nsep is a separator string for character-based data (or NULL for binary)\n \" \" means whitespace\n*/\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromFile(FILE *fp, PyArray_Descr *typecode, intp num, char *sep)\n{\n\tPyArrayObject *r;\n\tsize_t nread = 0;\n\tPyArray_ScanFunc *scan;\n\tBool binary;\n\n\tif (typecode->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \"0-sized elements.\");\n\t\treturn NULL;\n\t}\n\n\tbinary = ((sep == NULL) || (strlen(sep) == 0));\n\tif (num == -1 && binary) { /* Get size for binary file*/\n\t\tintp start, numbytes;\n\t\tstart = (intp )ftell(fp);\n\t\tfseek(fp, 0, SEEK_END);\n\t\tnumbytes = (intp )ftell(fp) - start;\n\t\trewind(fp);\n\t\tif (numbytes == -1) {\n\t\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\t\"could not seek in file\");\n\t\t\treturn NULL;\n\t\t}\n\t\tnum = numbytes / typecode->elsize;\n\t}\n\t\n\tif (binary) { /* binary data */\n\t\tr = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t\t 0, NULL);\n\t\tif (r==NULL) return NULL;\n\t\tnread = fread(r->data, typecode->elsize, num, fp);\n\t}\n\telse { /* character reading */\n\t\tintp i;\n\t\tchar *dptr;\n\t\tint done=0;\n\n\t\tscan = typecode->f->scanfunc;\n\t\tif (scan == NULL) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"don't know how to read \"\t\\\n\t\t\t\t\t\"character files with that \"\t\\\n\t\t\t\t\t\"array type\");\n\t\t\treturn NULL;\n\t\t}\n\n\t\tif (num != -1) { /* number to read is known */\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode, \n\t\t\t\t\t\t 1, &num, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\tdptr = r->data;\n\t\t\tfor (i=0; i < num; i++) {\n\t\t\t\tif (done) break;\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\t\t\t\tif (done < -2) break;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t}\n\t\telse { /* we have to watch for the end of the file and \n\t\t\t reallocate at the end */\n#define _FILEBUFNUM 4096\n\t\t\tintp thisbuf=0;\n\t\t\tintp size = _FILEBUFNUM;\n\t\t\tintp bytes;\n\t\t\tintp totalbytes;\n\n\t\t\tr = (PyArrayObject *)\\\n\t\t\t\tPyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t typecode,\n\t\t\t\t\t\t 1, &size, \n\t\t\t\t\t\t NULL, NULL, \n\t\t\t\t\t\t 0, NULL);\n\t\t\tif (r==NULL) return NULL;\n\t\t\ttotalbytes = bytes = size * typecode->elsize;\n\t\t\tdptr = r->data;\n\t\t\twhile (!done) {\n\t\t\t\tdone = scan(fp, dptr, sep, NULL);\n\n\t\t\t\t/* end of file reached trying to \n\t\t\t\t scan value. done is 1 or 2\n\t\t\t\t if end of file reached trying to\n\t\t\t\t scan separator. Still good value.\n\t\t\t\t*/\n\t\t\t\tif (done < -2) break;\n\t\t\t\tthisbuf += 1;\n\t\t\t\tnread += 1;\n\t\t\t\tdptr += r->descr->elsize;\n\t\t\t\tif (!done && thisbuf == size) {\n\t\t\t\t\ttotalbytes += bytes;\n\t\t\t\t\tr->data = PyDataMem_RENEW(r->data, \n\t\t\t\t\t\t\t\t totalbytes);\n\t\t\t\t\tdptr = r->data + (totalbytes - bytes);\n\t\t\t\t\tthisbuf = 0;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (PyErr_Occurred()) {\n\t\t\t\tPy_DECREF(r);\n\t\t\t\treturn NULL;\n\t\t\t}\n\t\t\tr->data = PyDataMem_RENEW(r->data, nread*r->descr->elsize);\n\t\t\tPyArray_DIM(r,0) = nread;\n\t\t\tnum = nread;\n#undef _FILEBUFNUM\n\t\t}\n\t}\n\tif (nread < num) {\n\t\tfprintf(stderr, \"%ld items requested but only %ld read\\n\", \n\t\t\t(long) num, (long) nread);\n\t\tr->data = PyDataMem_RENEW(r->data, nread * r->descr->elsize);\n\t\tPyArray_DIM(r,0) = nread;\n\t}\n\treturn (PyObject *)r;\n}\n\nstatic char doc_fromfile[] = \\\n\t\"fromfile(file=, dtype=int, count=-1, sep='')\\n\"\t\\\n\t\"\\n\"\\\n\t\" Return an array of the given data type from a \\n\"\\\n\t\" (text or binary) file. The file argument can be an open file\\n\"\\\n\t\" or a string with the name of a file to read from. If\\n\"\\\n\t\" count==-1, then the entire file is read, otherwise count is\\n\"\\\n\t\" the number of items of the given type read in. If sep is ''\\n\"\\\n\t\" then read a binary file, otherwise it gives the separator\\n\"\\\n\t\" between elements in a text file.\\n\"\\\n\t\"\\n\"\\\n\t\" WARNING: This function should be used sparingly, as it is not\\n\"\\\n\t\" a robust method of persistence. But it can be useful to\\n\"\\\n\t\" read in simply-formatted or binary data quickly.\";\n\nstatic PyObject *\narray_fromfile(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *file=NULL, *ret;\n\tFILE *fp;\n\tchar *sep=\"\";\n\tchar *mode=NULL;\n\tlonglong nin=-1;\n\tstatic char *kwlist[] = {\"file\", \"dtype\", \"count\", \"sep\", NULL};\n\tPyArray_Descr *type=NULL;\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&Ls\", kwlist, \n\t\t\t\t\t &file,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &sep)) {\n\t\treturn NULL;\n\t}\n\n\tif (type == NULL) type = PyArray_DescrFromType(PyArray_LONG);\n\n\tif (PyString_Check(file)) {\n\t\tif (sep == \"\") mode=\"rb\";\n\t\telse mode=\"r\";\n\t\tfile = PyFile_FromString(PyString_AS_STRING(file), mode);\n\t\tif (file==NULL) return NULL;\n\t}\n\telse {\n\t\tPy_INCREF(file);\n\t}\n\tfp = PyFile_AsFile(file);\n\tif (fp == NULL) {\n\t\tPyErr_SetString(PyExc_IOError, \n\t\t\t\t\"first argument must be an open file\");\n\t\tPy_DECREF(file);\n\t\treturn NULL;\n\t}\n\tret = PyArray_FromFile(fp, type, (intp) nin, sep);\n\tPy_DECREF(file);\n\treturn ret;\n}\n\n/*OBJECT_API*/\nstatic PyObject *\nPyArray_FromBuffer(PyObject *buf, PyArray_Descr *type, \n\t\t intp count, intp offset) \n{\n\tPyArrayObject *ret;\n\tchar *data;\n\tint ts;\n\tintp s, n;\n\tint itemsize;\n\tint write=1;\n\n\n\tif (type->type_num == PyArray_OBJECT) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"cannot create an OBJECT array from memory\"\\\n\t\t\t\t\" buffer\");\n\t\tPy_DECREF(type);\n\t\treturn NULL;\n\t}\n\tif (type->elsize == 0) {\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"itemsize cannot be zero in type\");\n\t\tPy_DECREF(type);\n\t\treturn NULL; \t\t\n\t}\n\n\tif (buf->ob_type->tp_as_buffer == NULL || \\\n\t (buf->ob_type->tp_as_buffer->bf_getwritebuffer == NULL &&\t\\\n\t buf->ob_type->tp_as_buffer->bf_getreadbuffer == NULL)) {\n\t\tPyObject *newbuf;\n\t\tnewbuf = PyObject_GetAttrString(buf, \"__buffer__\");\n\t\tif (newbuf == NULL) {Py_DECREF(type); return NULL;}\n\t\tbuf = newbuf;\n\t}\n\telse {Py_INCREF(buf);}\n\n\tif (PyObject_AsWriteBuffer(buf, (void *)&data, &ts)==-1) {\n\t\twrite = 0;\n\t\tPyErr_Clear();\n\t\tif (PyObject_AsReadBuffer(buf, (void *)&data, &ts)==-1) {\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((offset < 0) || (offset >= ts)) {\n\t\tPyErr_Format(PyExc_ValueError,\n\t\t\t \"offset must be positive and smaller than %\"\n\t\t\t INTP_FMT, (intp)ts);\n\t}\n\n\tdata += offset;\n\ts = (intp)ts - offset;\n\tn = (intp)count;\n\titemsize = type->elsize;\n\t\n\tif (n < 0 ) {\n\t\tif (s % itemsize != 0) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer size must be a multiple\"\\\n\t\t\t\t\t\" of element size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t\tn = s/itemsize;\n\t} else {\n\t\tif (s < n*itemsize) {\n\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\"buffer is smaller than requested\"\\\n\t\t\t\t\t\" size\");\n\t\t\tPy_DECREF(buf);\n\t\t\tPy_DECREF(type);\n\t\t\treturn NULL;\n\t\t}\n\t}\n\t\n\tif ((ret = (PyArrayObject *)PyArray_NewFromDescr(&PyArray_Type, \n\t\t\t\t\t\t\t type, \n\t\t\t\t\t\t\t 1, &n, \n\t\t\t\t\t\t\t NULL, data, \n\t\t\t\t\t\t\t DEFAULT_FLAGS,\n\t\t\t\t\t\t\t NULL)) == NULL) {\n\t\tPy_DECREF(buf);\n\t\treturn NULL;\n\t}\n\t\n\tif (!write) ret->flags &= ~WRITEABLE;\n\n\t/* Store a reference for decref on deallocation */\n\tret->base = buf;\n\tPyArray_UpdateFlags(ret, ALIGNED);\n\treturn (PyObject *)ret;\n}\n\nstatic char doc_frombuffer[] = \\\n\t\"frombuffer(buffer=, dtype=int, count=-1, offset=0)\\n\"\\\n\t\"\\n\"\t\t\t\t\t\t\t\t\\\n\t\" Returns a 1-d array of data type dtype from buffer. The buffer\\n\"\\\n\t\" argument must be an object that exposes the buffer interface.\\n\"\\\n\t\" If count is -1 then the entire buffer is used, otherwise, count\\n\"\\\n\t\" is the size of the output. If offset is given then jump that\\n\"\\\n\t\" far into the buffer. If the buffer has data that is out\\n\" \\\n\t\" not in machine byte-order, than use a propert data type\\n\"\\\n\t\" descriptor. The data will not\\n\" \\\n\t\" be byteswapped, but the array will manage it in future\\n\"\\\n\t\" operations.\\n\";\n\nstatic PyObject *\narray_frombuffer(PyObject *ignored, PyObject *args, PyObject *keywds)\n{\n\tPyObject *obj=NULL;\n\tlonglong nin=-1, offset=0;\n\tstatic char *kwlist[] = {\"buffer\", \"dtype\", \"count\", \"offset\", NULL};\n\tPyArray_Descr *type=NULL;\n\n\tif (!PyArg_ParseTupleAndKeywords(args, keywds, \"O|O&LL\", kwlist, \n\t\t\t\t\t &obj,\n\t\t\t\t\t PyArray_DescrConverter, &type,\n\t\t\t\t\t &nin, &offset)) {\n\t\treturn NULL;\n\t}\n\tif (type==NULL)\n\t\ttype = PyArray_DescrFromType(PyArray_LONG);\n\t\n\treturn PyArray_FromBuffer(obj, type, (intp)nin, (intp)offset);\n}\n\n\nstatic char doc_concatenate[] = \"concatenate((a1,a2,...),axis=None).\";\n\nstatic PyObject *\narray_concatenate(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *a0;\n\tint axis=0;\n\tstatic char *kwlist[] = {\"seq\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|O&\", kwlist,\n\t\t\t\t\t &a0,\n\t\t\t\t\t PyArray_AxisConverter, &axis))\n\t\treturn NULL;\n\treturn PyArray_Concatenate(a0, axis);\n}\n\nstatic char doc_innerproduct[] = \\\n\t\"inner(a,b) returns the dot product of two arrays, which has\\n\"\\\n\t\"shape a.shape[:-1] + b.shape[:-1] with elements computed by\\n\" \\\n\t\"the product of the elements from the last dimensions of a and b.\";\n\nstatic PyObject *array_innerproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *b0, *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a0, &b0)) return NULL;\n\t\n\treturn _ARET(PyArray_InnerProduct(a0, b0));\n}\n\nstatic char doc_matrixproduct[] = \\\n\t\"dot(a,v) returns matrix-multiplication between a and b. \\n\"\\\n\t\"The product-sum is over the last dimension of a and the \\n\"\\\n\t\"second-to-last dimension of b.\";\n\nstatic PyObject *array_matrixproduct(PyObject *dummy, PyObject *args) {\n\tPyObject *v, *a;\n\t\n\tif (!PyArg_ParseTuple(args, \"OO\", &a, &v)) return NULL;\n\t\n\treturn _ARET(PyArray_MatrixProduct(a, v));\n}\n\nstatic char doc_fastCopyAndTranspose[] = \"_fastCopyAndTranspose(a)\";\n\nstatic PyObject *array_fastCopyAndTranspose(PyObject *dummy, PyObject *args) {\n\tPyObject *a0;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &a0)) return NULL;\n\t\n\treturn _ARET(PyArray_CopyAndTranspose(a0));\n}\n\nstatic char doc_correlate[] = \"cross_correlate(a,v, mode=0)\";\n\nstatic PyObject *array_correlate(PyObject *dummy, PyObject *args, PyObject *kwds) {\n\tPyObject *shape, *a0;\n\tint mode=0;\n\tstatic char *kwlist[] = {\"a\", \"v\", \"mode\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"OO|i\", kwlist, \n\t\t\t\t\t &a0, &shape, &mode)) return NULL;\n\t\n\treturn PyArray_Correlate(a0, shape, mode);\n}\n\n\n/*MULTIARRAY_API\n Arange, \n*/\nstatic PyObject *\nPyArray_Arange(double start, double stop, double step, int type_num)\n{\n\tintp length;\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *obj;\n\tint ret;\n\n\tlength = (intp ) ceil((stop - start)/step);\n \n\tif (length <= 0) {\n\t\tlength = 0;\n\t\treturn PyArray_New(&PyArray_Type, 1, &length, type_num,\n\t\t\t\t NULL, NULL, 0, 0, NULL);\n\t}\n\n\trange = PyArray_New(&PyArray_Type, 1, &length, type_num, \n\t\t\t NULL, NULL, 0, 0, NULL);\n\tif (range == NULL) return NULL;\n\n\tfuncs = PyArray_DESCR(range)->f; \n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tobj = PyFloat_FromDouble(start);\n\tret = funcs->setitem(obj, PyArray_DATA(range), (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 1) return range;\n\n\tobj = PyFloat_FromDouble(start + step);\n\tret = funcs->setitem(obj, PyArray_DATA(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range);\n\tPy_DECREF(obj);\n\tif (ret < 0) goto fail;\n\tif (length == 2) return range;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\treturn NULL;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\t\n\treturn range;\n\n fail:\n\tPy_DECREF(range);\n\treturn NULL;\n}\n\n/* the formula is \n len = (intp) ceil((start - stop) / step);\n*/\nstatic intp\n_calc_length(PyObject *start, PyObject *stop, PyObject *step, PyObject **next, int cmplx)\n{\n\tintp len;\n\tPyObject *val;\n\tdouble value;\n\t\n\t*next = PyNumber_Subtract(stop, start);\n\tif (!(*next)) return -1;\n\tval = PyNumber_TrueDivide(*next, step);\n\tPy_DECREF(*next); *next=NULL;\n\tif (!val) return -1;\n\tif (cmplx && PyComplex_Check(val)) {\n\t\tvalue = PyComplex_RealAsDouble(val);\n\t\tif (error_converting(value)) {Py_DECREF(val); return -1;}\n\t\tlen = (intp) ceil(value);\n\t\tvalue = PyComplex_ImagAsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = MIN(len, (intp) ceil(value));\n\t}\n\telse {\n\t\tvalue = PyFloat_AsDouble(val);\n\t\tPy_DECREF(val);\n\t\tif (error_converting(value)) return -1;\n\t\tlen = (intp) ceil(value);\n\t}\n\t\n\tif (len > 0) {\n\t\t*next = PyNumber_Add(start, step);\n\t\tif (!next) return -1;\n\t}\n\treturn len;\n}\n\n/* this doesn't change the references */\n/*MULTIARRAY_API\n ArangeObj,\n*/\nstatic PyObject *\nPyArray_ArangeObj(PyObject *start, PyObject *stop, PyObject *step, PyArray_Descr *dtype) \n{\n\tPyObject *range;\n\tPyArray_ArrFuncs *funcs;\n\tPyObject *next;\n\tintp length;\n\n\tif (!dtype) {\n\t\tPyArray_Descr *deftype;\n\t\tPyArray_Descr *newtype;\n\t\tdeftype = PyArray_DescrFromType(PyArray_LONG);\n\t\tnewtype = PyArray_DescrFromObject(start, deftype);\n\t\tPy_DECREF(deftype);\n\t\tdeftype = newtype;\n\t\tif (stop && stop != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(stop, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tif (step && step != Py_None) {\n\t\t\tnewtype = PyArray_DescrFromObject(step, deftype);\n\t\t\tPy_DECREF(deftype);\n\t\t\tdeftype = newtype;\n\t\t}\n\t\tdtype = deftype;\n\t}\n\telse Py_INCREF(dtype);\n\n\tif (!step || step == Py_None) {\n\t\tstep = PyInt_FromLong(1);\n\t}\n\telse Py_XINCREF(step);\n\n\tif (!stop || stop == Py_None) {\n\t\tstop = start;\n\t\tstart = PyInt_FromLong(0);\n\t}\n\telse Py_INCREF(start);\n\n\t/* calculate the length and next = start + step*/\n\tlength = _calc_length(start, stop, step, &next, \n\t\t\t PyTypeNum_ISCOMPLEX(dtype->type_num));\n\n\tif (PyErr_Occurred()) {Py_DECREF(dtype); goto fail;}\n\tif (length <= 0) {\n\t\tlength = 0;\n\t\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\t\tPy_DECREF(step); Py_DECREF(start); return range;\n\t}\n\n\trange = PyArray_SimpleNewFromDescr(1, &length, dtype);\n\tif (range == NULL) goto fail;\n\n\tfuncs = PyArray_DESCR(range)->f;\n\n\t/* place start in the buffer and the next value in the second position */\n\t/* if length > 2, then call the inner loop, otherwise stop */\n\n\tif (funcs->setitem(start, PyArray_DATA(range), (PyArrayObject *)range) < 0)\n\t\tgoto fail;\n\tif (length == 1) goto finish;\n\tif (funcs->setitem(next, PyArray_DATA(range)+PyArray_ITEMSIZE(range), \n\t\t\t (PyArrayObject *)range) < 0) goto fail;\n\tif (length == 2) goto finish;\n\n\tif (!funcs->fill) {\n\t\tPyErr_SetString(PyExc_ValueError, \"no fill-function for data-type.\");\n\t\tPy_DECREF(range);\n\t\tgoto fail;\n\t}\n\tfuncs->fill(PyArray_DATA(range), length, (PyArrayObject *)range);\n\tif (PyErr_Occurred()) goto fail;\n\n finish:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_DECREF(next);\n\treturn range;\n\t\n fail:\n\tPy_DECREF(start);\n\tPy_DECREF(step);\n\tPy_XDECREF(next);\n\treturn NULL;\n}\n\n\nstatic char doc_arange[] = \"arange(start, stop=None, step=1, dtype=int)\\n\\n Just like range() except it returns an array whose type can be\\n specified by the keyword argument typecode.\";\n\nstatic PyObject *\narray_arange(PyObject *ignored, PyObject *args, PyObject *kws) {\n\tPyObject *o_start=NULL, *o_stop=NULL, *o_step=NULL;\n\tstatic char *kwd[]= {\"start\", \"stop\", \"step\", \"dtype\", NULL};\n\tPyArray_Descr *typecode=NULL;\n\t\n\tif(!PyArg_ParseTupleAndKeywords(args, kws, \"O|OOO&\", kwd, &o_start,\n\t\t\t\t\t&o_stop, &o_step, \n\t\t\t\t\tPyArray_DescrConverter, \n\t\t\t\t\t&typecode)) \n\t\treturn NULL;\n\n\treturn PyArray_ArangeObj(o_start, o_stop, o_step, typecode);\n}\n\n\nstatic char \ndoc_set_string_function[] = \"set_string_function(f, repr=1) sets the python function f to be the function used to obtain a pretty printable string version of a array whenever a array is printed. f(M) should expect a array argument M, and should return a string consisting of the desired representation of M for printing.\";\n\nstatic PyObject *\narray_set_string_function(PyObject *dummy, PyObject *args, PyObject *kwds) \n{\n\tPyObject *op;\n\tint repr=1;\n\tstatic char *kwlist[] = {\"f\", \"repr\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|i\", kwlist, \n\t\t\t\t\t&op, &repr)) return NULL; \n\tif (!PyCallable_Check(op)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"Argument must be callable.\");\n\t\treturn NULL;\n\t}\n\tPyArray_SetStringFunction(op, repr);\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic char \ndoc_set_ops_function[] = \"set_numeric_ops(op=func, ...) sets some or all of the number methods for all array objects. Don't forget **dict can be used as the argument list. Returns the functions that were replaced -- can be stored and set later.\";\n\nstatic PyObject *\narray_set_ops_function(PyObject *self, PyObject *args, PyObject *kwds) \n{\n\tPyObject *oldops=NULL;\n\t\n\tif ((oldops = PyArray_GetNumericOps())==NULL) return NULL;\n\n\t/* Should probably ensure that objects are at least callable */\n\t/* Leave this to the caller for now --- error will be raised\n\t later when use is attempted \n\t*/\n\tif (kwds && PyArray_SetNumericOps(kwds) == -1) {\n\t\tPy_DECREF(oldops);\n\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"one or more objects not callable\");\n\t\treturn NULL;\n\t}\n\treturn oldops;\n}\n\n\n/*MULTIARRAY_API\n Where\n*/\nstatic PyObject *\nPyArray_Where(PyObject *condition, PyObject *x, PyObject *y)\n{\n\tPyArrayObject *arr;\n\tPyObject *tup=NULL, *obj=NULL;\n\tPyObject *ret=NULL, *zero=NULL;\n\n\n\tarr = (PyArrayObject *)PyArray_FromAny(condition, NULL, 0, 0, 0);\n\tif (arr == NULL) return NULL;\n\n\tif ((x==NULL) && (y==NULL)) {\n\t\tret = PyArray_Nonzero(arr);\n\t\tPy_DECREF(arr);\n\t\treturn ret;\n\t}\n\n\tif ((x==NULL) || (y==NULL)) {\n\t\tPy_DECREF(arr);\n\t\tPyErr_SetString(PyExc_ValueError, \"either both or neither \"\n\t\t\t\t\"of x and y should be given\");\n\t\treturn NULL;\n\t}\n\n\n\tzero = PyInt_FromLong((long) 0);\n\n\tobj = PyArray_EnsureArray(PyArray_GenericBinaryFunction(arr, zero, \n\t\t\t\t\t\t\t\tn_ops.not_equal));\n\tPy_DECREF(zero);\n\tPy_DECREF(arr);\n\tif (obj == NULL) return NULL;\n\n\ttup = Py_BuildValue(\"(OO)\", y, x);\n\tif (tup == NULL) {Py_DECREF(obj); return NULL;}\n\n\tret = PyArray_Choose((PyAO *)obj, tup);\n\n\tPy_DECREF(obj);\n\tPy_DECREF(tup);\n\treturn ret;\n}\n\nstatic char doc_where[] = \"where(condition, | x, y) is shaped like condition\"\\\n\t\" and has elements of x and y where condition is respectively true or\"\\\n\t\" false. If x or y are not given, then it is equivalent to\"\\\n\t\" nonzero(condition).\";\n\nstatic PyObject *\narray_where(PyObject *ignored, PyObject *args)\n{\n\tPyObject *obj=NULL, *x=NULL, *y=NULL;\n\t\n\tif (!PyArg_ParseTuple(args, \"O|OO\", &obj, &x, &y)) return NULL;\n\n\treturn PyArray_Where(obj, x, y);\n\n}\n\nstatic char doc_lexsort[] = \"lexsort(keys=, axis=-1) returns an array of indexes\"\\\n\t\" similar to argsort except the sorting is done using the provided sorting\"\\\n\t\" keys. First the sort is done using key[0], then the resulting list of\"\\\n\t\" indexes is further manipulated by sorting on key[0]. And so forth\"\\\n\t\" The result is a sort on multiple keys. If the keys represented columns\" \\\n\t\" of a spread-sheet, for example, this would sort using multiple columns.\"\\\n\t\" The keys argument must be a tuple of things that can be converted to \"\\\n\t\" arrays of the same shape.\";\n\nstatic PyObject *\narray_lexsort(PyObject *ignored, PyObject *args, PyObject *kwds)\n{\n\tint axis=-1;\n\tPyObject *obj;\n\tstatic char *kwlist[] = {\"keys\", \"axis\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O!|i\", kwlist, \n\t\t\t\t\t &PyTuple_Type, &obj, &axis)) return NULL;\n\t\n\treturn _ARET(PyArray_LexSort(obj, axis));\n}\n\n#undef _ARET\n\n\nstatic char doc_register_dtype[] = \\\n\t\"register_dtype(a) registers a new type object -- gives it a typenum\";\n\nstatic PyObject *\narray_register_dtype(PyObject *dummy, PyObject *args)\n{\n\tPyObject *dtype;\n\tint ret;\n\t\n\tif (!PyArg_ParseTuple(args, \"O\", &dtype)) return NULL;\n\t\n\tret = PyArray_RegisterDataType((PyTypeObject *)dtype);\n\tif (ret < 0)\n\t\treturn NULL;\n\treturn PyInt_FromLong((long) ret);\n}\n\nstatic char doc_can_cast_safely[] = \\\n\t\"can_cast_safely(from=d1, to=d2) returns True if data type d1 \"\\\n\t\"can be cast to data type d2 without losing precision.\";\n\nstatic PyObject *\narray_can_cast_safely(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyArray_Descr *d1=NULL;\n\tPyArray_Descr *d2=NULL;\n\tBool ret;\n\tPyObject *retobj;\n\tstatic char *kwlist[] = {\"from\", \"to\", NULL};\n\n\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O&O&\", kwlist, \n\t\t\t\t\tPyArray_DescrConverter, &d1,\n\t\t\t\t\tPyArray_DescrConverter, &d2))\n\t\treturn NULL;\n\tif (d1 == NULL || d2 == NULL) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"did not understand one of the types; \"\t\\\n\t\t\t\t\"'None' not accepted\");\n\t\treturn NULL;\n\t}\n\t\t\n\tret = PyArray_CanCastTo(d1, d2);\n\tretobj = (ret ? Py_True : Py_False);\n\tPy_INCREF(retobj);\n\treturn retobj;\n}\n\nstatic char doc_new_buffer[] = \\\n\t\"newbuffer(size) return a new uninitialized buffer object of size \"\n\t\"bytes\";\n\nstatic PyObject *\nnew_buffer(PyObject *dummy, PyObject *args)\n{\n\tint size;\n\n\tif(!PyArg_ParseTuple(args, \"i\", &size))\n\t\treturn NULL;\n\t\n\treturn PyBuffer_New(size);\n}\n\nstatic char doc_buffer_buffer[] = \\\n\t\"getbuffer(obj [,offset[, size]]) create a buffer object from the \"\\\n\t\"given object\\n referencing a slice of length size starting at \"\\\n\t\"offset. Default\\n is the entire buffer. A read-write buffer is \"\\\n\t\"attempted followed by a read-only buffer.\";\n\nstatic PyObject *\nbuffer_buffer(PyObject *dummy, PyObject *args, PyObject *kwds)\n{\n\tPyObject *obj;\n\tint offset=0, size=Py_END_OF_BUFFER, n;\n\tvoid *unused;\n\tstatic char *kwlist[] = {\"object\", \"offset\", \"size\", NULL};\n\t\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O|ii\", kwlist, \n\t\t\t\t\t &obj, &offset, &size))\n\t\treturn NULL;\n\n\n\tif (PyObject_AsWriteBuffer(obj, &unused, &n) < 0) {\n\t\tPyErr_Clear();\n\t\treturn PyBuffer_FromObject(obj, offset, size);\t\t\n\t}\n\telse\n\t\treturn PyBuffer_FromReadWriteObject(obj, offset, size);\n}\n\n\nstatic struct PyMethodDef array_module_methods[] = {\n\t{\"set_string_function\", (PyCFunction)array_set_string_function, \n\t METH_VARARGS|METH_KEYWORDS, doc_set_string_function},\n\t{\"set_numeric_ops\", (PyCFunction)array_set_ops_function,\n\t METH_VARARGS|METH_KEYWORDS, doc_set_ops_function},\n\t{\"set_typeDict\", (PyCFunction)array_set_typeDict,\n\t METH_VARARGS, doc_set_typeDict},\n\n\t{\"array\",\t(PyCFunction)_array_fromobject, \n\t METH_VARARGS|METH_KEYWORDS, doc_fromobject},\n\t{\"arange\", (PyCFunction)array_arange, \n\t METH_VARARGS|METH_KEYWORDS, doc_arange},\n\t{\"zeros\",\t(PyCFunction)array_zeros, \n\t METH_VARARGS|METH_KEYWORDS, doc_zeros},\n\t{\"empty\",\t(PyCFunction)array_empty, \n\t METH_VARARGS|METH_KEYWORDS, doc_empty},\n\t{\"scalar\", (PyCFunction)array_scalar,\n\t METH_VARARGS|METH_KEYWORDS, doc_scalar},\n\t{\"where\", (PyCFunction)array_where,\n\t METH_VARARGS, doc_where},\n\t{\"lexsort\", (PyCFunction)array_lexsort,\n\t METH_VARARGS | METH_KEYWORDS, doc_lexsort},\n\t{\"fromstring\",(PyCFunction)array_fromString,\n\t METH_VARARGS|METH_KEYWORDS, doc_fromString},\n\t{\"concatenate\", (PyCFunction)array_concatenate, \n\t METH_VARARGS|METH_KEYWORDS, doc_concatenate},\n\t{\"inner\", (PyCFunction)array_innerproduct, \n\t METH_VARARGS, doc_innerproduct}, \n\t{\"dot\", (PyCFunction)array_matrixproduct, \n\t METH_VARARGS, doc_matrixproduct}, \n\t{\"_fastCopyAndTranspose\", (PyCFunction)array_fastCopyAndTranspose, \n\t METH_VARARGS, doc_fastCopyAndTranspose},\n\t{\"correlate\", (PyCFunction)array_correlate, \n\t METH_VARARGS | METH_KEYWORDS, doc_correlate},\n\t{\"frombuffer\", (PyCFunction)array_frombuffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_frombuffer},\n\t{\"fromfile\", (PyCFunction)array_fromfile,\n\t METH_VARARGS | METH_KEYWORDS, doc_fromfile},\n\t{\"register_dtype\", (PyCFunction)array_register_dtype,\n\t METH_VARARGS, doc_register_dtype},\n\t{\"can_cast\", (PyCFunction)array_can_cast_safely,\n\t METH_VARARGS | METH_KEYWORDS, doc_can_cast_safely},\t\t\n\t{\"newbuffer\", (PyCFunction)new_buffer,\n\t METH_VARARGS, doc_new_buffer},\t\n\t{\"getbuffer\", (PyCFunction)buffer_buffer,\n\t METH_VARARGS | METH_KEYWORDS, doc_buffer_buffer},\t\n\t{NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\n#include \"__multiarray_api.c\"\n\n/* Establish scalar-type hierarchy */\n\n/* For dual inheritance we need to make sure that the objects being\n inherited from have the tp->mro object initialized. This is\n not necessarily true for the basic type objects of Python (it is \n checked for single inheritance but not dual in PyType_Ready).\n\n Thus, we call PyType_Ready on the standard Python Types, here.\n*/ \nstatic int\nsetup_scalartypes(PyObject *dict)\n{\n\n\tinitialize_numeric_types();\n\n if (PyType_Ready(&PyBool_Type) < 0) return -1;\n if (PyType_Ready(&PyInt_Type) < 0) return -1;\n if (PyType_Ready(&PyFloat_Type) < 0) return -1;\n if (PyType_Ready(&PyComplex_Type) < 0) return -1;\n if (PyType_Ready(&PyString_Type) < 0) return -1;\n if (PyType_Ready(&PyUnicode_Type) < 0) return -1;\n\n#define SINGLE_INHERIT(child, parent) \\\n Py##child##ArrType_Type.tp_base = &Py##parent##ArrType_Type;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) {\t\t\\\n PyErr_Print(); \\\n PyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1;\t\t\t\t\t\t\\\n }\n \n if (PyType_Ready(&PyGenericArrType_Type) < 0)\n return -1;\n\n SINGLE_INHERIT(Number, Generic);\n SINGLE_INHERIT(Integer, Number);\n SINGLE_INHERIT(Inexact, Number);\n SINGLE_INHERIT(SignedInteger, Integer);\n SINGLE_INHERIT(UnsignedInteger, Integer);\n SINGLE_INHERIT(Floating, Inexact);\n SINGLE_INHERIT(ComplexFloating, Inexact);\n SINGLE_INHERIT(Flexible, Generic);\n SINGLE_INHERIT(Character, Flexible);\n\t\n#define DUAL_INHERIT(child, parent1, parent2) \\\n Py##child##ArrType_Type.tp_base = &Py##parent2##ArrType_Type;\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent2##ArrType_Type,\t\\\n\t\t\t &Py##parent1##_Type);\t\t\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\n\n#define DUAL_INHERIT2(child, parent1, parent2)\t\t\t\t\\\n Py##child##ArrType_Type.tp_base = &Py##parent1##_Type;\t\t\\\n Py##child##ArrType_Type.tp_bases = \\\n Py_BuildValue(\"(OO)\", &Py##parent1##_Type,\t\t\\\n\t\t\t &Py##parent2##ArrType_Type);\t\t\\\n\tPy##child##ArrType_Type.tp_richcompare =\t\t\t\\\n\t\tPy##parent1##_Type.tp_richcompare;\t\t\t\\\n\tPy##child##ArrType_Type.tp_compare =\t\t\t\t\\\n\t\tPy##parent1##_Type.tp_compare;\t\t\t\t\\\n Py##child##ArrType_Type.tp_hash = Py##parent1##_Type.tp_hash;\t\\\n if (PyType_Ready(&Py##child##ArrType_Type) < 0) { \\\n PyErr_Print(); \\\n\t\tPyErr_Format(PyExc_SystemError, \\\n\t\t\t \"could not initialize Py%sArrType_Type\", \\\n #child); \\\n return -1; \\\n }\n\n SINGLE_INHERIT(Bool, Generic);\n SINGLE_INHERIT(Byte, SignedInteger);\n SINGLE_INHERIT(Short, SignedInteger);\n#if SIZEOF_INT == SIZEOF_LONG\n DUAL_INHERIT(Int, Int, SignedInteger);\n#else\n SINGLE_INHERIT(Int, SignedInteger);\n#endif\n DUAL_INHERIT(Long, Int, SignedInteger);\n#if SIZEOF_LONGLONG == SIZEOF_LONG\n DUAL_INHERIT(LongLong, Int, SignedInteger);\n#else\n SINGLE_INHERIT(LongLong, SignedInteger);\n#endif\n\n /* fprintf(stderr, \"tp_free = %p, PyObject_Del = %p, int_tp_free = %p, base.tp_free = %p\\n\", PyIntArrType_Type.tp_free, PyObject_Del, PyInt_Type.tp_free, PySignedIntegerArrType_Type.tp_free);\n\t */\n\tSINGLE_INHERIT(UByte, UnsignedInteger);\n SINGLE_INHERIT(UShort, UnsignedInteger);\n SINGLE_INHERIT(UInt, UnsignedInteger);\n SINGLE_INHERIT(ULong, UnsignedInteger);\n SINGLE_INHERIT(ULongLong, UnsignedInteger);\n\n SINGLE_INHERIT(Float, Floating);\n DUAL_INHERIT(Double, Float, Floating);\n SINGLE_INHERIT(LongDouble, Floating);\n\n SINGLE_INHERIT(CFloat, ComplexFloating);\n DUAL_INHERIT(CDouble, Complex, ComplexFloating);\n SINGLE_INHERIT(CLongDouble, ComplexFloating);\n\n DUAL_INHERIT2(String, String, Character);\n DUAL_INHERIT2(Unicode, Unicode, Character);\n\t\n SINGLE_INHERIT(Void, Flexible);\n \n SINGLE_INHERIT(Object, Generic);\n\n return 0;\n\n#undef SINGLE_INHERIT\n#undef DUAL_INHERIT\n\n\t/* Clean up string and unicode array types so they act more like\n\t strings -- get their tables from the standard types.\n\t*/\n}\n\n/* place a flag dictionary in d */\n\nstatic void\nset_flaginfo(PyObject *d)\n{\n PyObject *s;\n PyObject *newd;\n \n newd = PyDict_New();\n\n PyDict_SetItemString(newd, \"OWNDATA\", s=PyInt_FromLong(OWNDATA));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"FORTRAN\", s=PyInt_FromLong(FORTRAN));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"CONTIGUOUS\", s=PyInt_FromLong(CONTIGUOUS));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"ALIGNED\", s=PyInt_FromLong(ALIGNED));\n Py_DECREF(s);\n\n PyDict_SetItemString(newd, \"UPDATEIFCOPY\", s=PyInt_FromLong(UPDATEIFCOPY));\n Py_DECREF(s);\n PyDict_SetItemString(newd, \"WRITEABLE\", s=PyInt_FromLong(WRITEABLE));\n Py_DECREF(s);\n \n PyDict_SetItemString(d, \"_flagdict\", newd);\n Py_DECREF(newd);\n return;\n}\n\n\n/* Initialization function for the module */\n\nDL_EXPORT(void) initmultiarray(void) {\n\tPyObject *m, *d, *s;\n\tPyObject *c_api;\n\t\n\t/* Create the module and add the functions */\n\tm = Py_InitModule(\"multiarray\", array_module_methods);\n\tif (!m) goto err;\n\n\t/* Add some symbolic constants to the module */\n\td = PyModule_GetDict(m);\n\tif (!d) goto err; \n\n\t/* Create the module and add the functions */\n\tif (PyType_Ready(&PyBigArray_Type) < 0) \n\t\treturn;\n\n PyArray_Type.tp_base = &PyBigArray_Type;\n\n PyArray_Type.tp_as_mapping = &array_as_mapping;\n\t/* Even though, this would be inherited, it needs to be set now\n\t so that the __getitem__ will map to the as_mapping descriptor\n\t*/\n PyArray_Type.tp_as_number = &array_as_number; \n\t/* For good measure */\n\tPyArray_Type.tp_as_sequence = &array_as_sequence;\n\tPyArray_Type.tp_as_buffer = &array_as_buffer;\t\n PyArray_Type.tp_flags = (Py_TPFLAGS_DEFAULT \n\t\t\t\t | Py_TPFLAGS_BASETYPE\n\t\t\t\t | Py_TPFLAGS_CHECKTYPES);\n PyArray_Type.tp_doc = Arraytype__doc__;\n\n\tif (PyType_Ready(&PyArray_Type) < 0)\n return;\n\n if (setup_scalartypes(d) < 0) goto err;\n\n\tPyArrayIter_Type.tp_iter = PyObject_SelfIter;\n\tPyArrayMultiIter_Type.tp_iter = PyObject_SelfIter;\n\tif (PyType_Ready(&PyArrayIter_Type) < 0)\n\t\treturn; \n \n\tif (PyType_Ready(&PyArrayMapIter_Type) < 0)\n return; \n\n\tif (PyType_Ready(&PyArrayMultiIter_Type) < 0)\n\t\treturn;\n\n\tif (PyType_Ready(&PyArrayDescr_Type) < 0)\n\t\treturn;\n\n\tc_api = PyCObject_FromVoidPtr((void *)PyArray_API, NULL);\n\tif (PyErr_Occurred()) goto err;\n\tPyDict_SetItemString(d, \"_ARRAY_API\", c_api);\n\tPy_DECREF(c_api);\n\tif (PyErr_Occurred()) goto err;\n\n\tMultiArrayError = PyString_FromString (\"multiarray.error\");\n\tPyDict_SetItemString (d, \"error\", MultiArrayError);\n\t\n\ts = PyString_FromString(\"3.0\");\n\tPyDict_SetItemString(d, \"__version__\", s);\n\tPy_DECREF(s);\n Py_INCREF(&PyBigArray_Type);\n\tPyDict_SetItemString(d, \"bigndarray\", (PyObject *)&PyBigArray_Type);\n Py_INCREF(&PyArray_Type);\n\tPyDict_SetItemString(d, \"ndarray\", (PyObject *)&PyArray_Type);\n Py_INCREF(&PyArrayIter_Type);\n\tPyDict_SetItemString(d, \"flatiter\", (PyObject *)&PyArrayIter_Type);\n Py_INCREF(&PyArrayMultiIter_Type);\n\tPyDict_SetItemString(d, \"broadcast\", \n\t\t\t (PyObject *)&PyArrayMultiIter_Type);\n\tPy_INCREF(&PyArrayDescr_Type);\n\tPyDict_SetItemString(d, \"dtypedescr\", (PyObject *)&PyArrayDescr_Type);\n\n\t/* Doesn't need to be exposed to Python \n Py_INCREF(&PyArrayMapIter_Type);\n\tPyDict_SetItemString(d, \"mapiter\", (PyObject *)&PyArrayMapIter_Type);\n\t*/\n set_flaginfo(d);\n\n\tif (set_typeinfo(d) != 0) goto err;\n\n\t_numpy_internal =\t\t\t\t\t\t\\\n\t\tPyImport_ImportModule(\"numpy.core._internal\");\n\tif (_numpy_internal != NULL) return;\n\n err:\t\n\t/* Check for errors */\n\tif (PyErr_Occurred())\n PyErr_Print();\n\t\tPy_FatalError(\"can't initialize module multiarray\");\n\n\treturn;\n}\n\n", + "methods": [ + { + "name": "_arraydescr_fromobj", + "long_name": "_arraydescr_fromobj( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 15, + "complexity": 3, + "token_count": 67, + "parameters": [ + "obj" + ], + "start_line": 34, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyIntList", + "long_name": "PyArray_MultiplyIntList( register int * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 74, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyList", + "long_name": "PyArray_MultiplyList( register intp * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 85, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPtr", + "long_name": "PyArray_GetPtr( PyArrayObject * obj , register intp * ind)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 61, + "parameters": [ + "obj", + "ind" + ], + "start_line": 96, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AxisConverter", + "long_name": "PyArray_AxisConverter( PyObject * obj , int * axis)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 53, + "parameters": [ + "obj", + "axis" + ], + "start_line": 110, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CompareLists", + "long_name": "PyArray_CompareLists( intp * l1 , intp * l2 , int n)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 3, + "token_count": 51, + "parameters": [ + "l1", + "l2", + "n" + ], + "start_line": 128, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_View", + "long_name": "PyArray_View( PyArrayObject * self , PyArray_Descr * type , PyTypeObject * pytype)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self", + "type", + "pytype" + ], + "start_line": 142, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ravel", + "long_name": "PyArray_Ravel( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 102, + "parameters": [ + "a", + "fortran" + ], + "start_line": 178, + "end_line": 195, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Flatten", + "long_name": "PyArray_Flatten( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 6, + "token_count": 176, + "parameters": [ + "a", + "fortran" + ], + "start_line": 201, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Reshape", + "long_name": "PyArray_Reshape( PyArrayObject * self , PyObject * shape)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "shape" + ], + "start_line": 247, + "end_line": 256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_check_ones", + "long_name": "_check_ones( PyArrayObject * self , int newnd , intp * newdims , intp * strides)", + "filename": "multiarraymodule.c", + "nloc": 25, + "complexity": 12, + "token_count": 189, + "parameters": [ + "self", + "newnd", + "newdims", + "strides" + ], + "start_line": 259, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Newshape", + "long_name": "PyArray_Newshape( PyArrayObject * self , PyArray_Dims * newdims)", + "filename": "multiarraymodule.c", + "nloc": 72, + "complexity": 17, + "token_count": 409, + "parameters": [ + "self", + "newdims" + ], + "start_line": 296, + "end_line": 383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Squeeze", + "long_name": "PyArray_Squeeze( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 34, + "complexity": 5, + "token_count": 204, + "parameters": [ + "self" + ], + "start_line": 392, + "end_line": 427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Mean", + "long_name": "PyArray_Mean( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 19, + "complexity": 4, + "token_count": 139, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 434, + "end_line": 455, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Std", + "long_name": "PyArray_Std( PyArrayObject * self , int axis , int rtype , int variance)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 13, + "token_count": 450, + "parameters": [ + "self", + "axis", + "rtype", + "variance" + ], + "start_line": 462, + "end_line": 521, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sum", + "long_name": "PyArray_Sum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 528, + "end_line": 538, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Prod", + "long_name": "PyArray_Prod( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 544, + "end_line": 554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CumSum", + "long_name": "PyArray_CumSum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 560, + "end_line": 570, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CumProd", + "long_name": "PyArray_CumProd( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 576, + "end_line": 587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Any", + "long_name": "PyArray_Any( PyArrayObject * self , int axis)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "axis" + ], + "start_line": 593, + "end_line": 604, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_All", + "long_name": "PyArray_All( PyArrayObject * self , int axis)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "axis" + ], + "start_line": 610, + "end_line": 621, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Compress", + "long_name": "PyArray_Compress( PyArrayObject * self , PyObject * condition , int axis)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 3, + "token_count": 110, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 628, + "end_line": 648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Nonzero", + "long_name": "PyArray_Nonzero( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 13, + "token_count": 414, + "parameters": [ + "self" + ], + "start_line": 654, + "end_line": 713, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Clip", + "long_name": "PyArray_Clip( PyArrayObject * self , PyObject * min , PyObject * max)", + "filename": "multiarraymodule.c", + "nloc": 28, + "complexity": 6, + "token_count": 237, + "parameters": [ + "self", + "min", + "max" + ], + "start_line": 719, + "end_line": 749, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Conjugate", + "long_name": "PyArray_Conjugate( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 9, + "token_count": 228, + "parameters": [ + "self" + ], + "start_line": 755, + "end_line": 791, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Trace", + "long_name": "PyArray_Trace( PyArrayObject * self , int offset , int axis1 , int axis2 , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 81, + "parameters": [ + "self", + "offset", + "axis1", + "axis2", + "rtype" + ], + "start_line": 797, + "end_line": 807, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Diagonal", + "long_name": "PyArray_Diagonal( PyArrayObject * self , int offset , int axis1 , int axis2)", + "filename": "multiarraymodule.c", + "nloc": 104, + "complexity": 23, + "token_count": 774, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 813, + "end_line": 932, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AsCArray", + "long_name": "PyArray_AsCArray( PyObject ** op , * ptr , intp * dims , int nd , PyArray_Descr * typedescr)", + "filename": "multiarraymodule.c", + "nloc": 50, + "complexity": 12, + "token_count": 400, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 948, + "end_line": 999, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As1D", + "long_name": "PyArray_As1D( PyObject ** op , char ** ptr , int * d1 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 71, + "parameters": [ + "op", + "ptr", + "d1", + "typecode" + ], + "start_line": 1007, + "end_line": 1017, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As2D", + "long_name": "PyArray_As2D( PyObject ** op , char ** * ptr , int * d1 , int * d2 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 92, + "parameters": [ + "op", + "ptr", + "d1", + "d2", + "typecode" + ], + "start_line": 1023, + "end_line": 1035, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Free", + "long_name": "PyArray_Free( PyObject * op , * ptr)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 4, + "token_count": 67, + "parameters": [ + "op", + "ptr" + ], + "start_line": 1043, + "end_line": 1054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "_swap_and_concat", + "long_name": "_swap_and_concat( PyObject * op , int axis , int n)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 6, + "token_count": 185, + "parameters": [ + "op", + "axis", + "n" + ], + "start_line": 1058, + "end_line": 1086, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Concatenate", + "long_name": "PyArray_Concatenate( PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 92, + "complexity": 20, + "token_count": 617, + "parameters": [ + "op", + "axis" + ], + "start_line": 1098, + "end_line": 1202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 105, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SwapAxes", + "long_name": "PyArray_SwapAxes( PyArrayObject * ap , int a1 , int a2)", + "filename": "multiarraymodule.c", + "nloc": 38, + "complexity": 12, + "token_count": 227, + "parameters": [ + "ap", + "a1", + "a2" + ], + "start_line": 1208, + "end_line": 1249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Transpose", + "long_name": "PyArray_Transpose( PyArrayObject * ap , PyArray_Dims * permute)", + "filename": "multiarraymodule.c", + "nloc": 46, + "complexity": 10, + "token_count": 309, + "parameters": [ + "ap", + "permute" + ], + "start_line": 1255, + "end_line": 1308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Repeat", + "long_name": "PyArray_Repeat( PyArrayObject * aop , PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 78, + "complexity": 15, + "token_count": 523, + "parameters": [ + "aop", + "op", + "axis" + ], + "start_line": 1314, + "end_line": 1409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 63, + "complexity": 13, + "token_count": 427, + "parameters": [ + "op", + "retn" + ], + "start_line": 1413, + "end_line": 1482, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Choose", + "long_name": "PyArray_Choose( PyArrayObject * ip , PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 15, + "token_count": 518, + "parameters": [ + "ip", + "op" + ], + "start_line": 1489, + "end_line": 1570, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 82, + "top_nesting_level": 0 + }, + { + "name": "_strided_copy", + "long_name": "_strided_copy( char * dst , intp dststride , char * src , intp srcstride , intp num , int elsize)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 48, + "parameters": [ + "dst", + "dststride", + "src", + "srcstride", + "num", + "elsize" + ], + "start_line": 1573, + "end_line": 1580, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "_new_sort", + "long_name": "_new_sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 8, + "token_count": 284, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1591, + "end_line": 1645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "_new_argsort", + "long_name": "_new_argsort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 67, + "complexity": 13, + "token_count": 498, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1648, + "end_line": 1726, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "qsortCompare", + "long_name": "qsortCompare( const * a , const * b)", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "a", + "b" + ], + "start_line": 1734, + "end_line": 1737, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sort", + "long_name": "PyArray_Sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 52, + "complexity": 14, + "token_count": 353, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1792, + "end_line": 1858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "argsort_static_compare", + "long_name": "argsort_static_compare( const * ip1 , const * ip2)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 1, + "token_count": 67, + "parameters": [ + "ip1", + "ip2" + ], + "start_line": 1864, + "end_line": 1872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgSort", + "long_name": "PyArray_ArgSort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 15, + "token_count": 493, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1878, + "end_line": 1958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_LexSort", + "long_name": "PyArray_LexSort( PyObject * sort_keys , int axis)", + "filename": "multiarraymodule.c", + "nloc": 132, + "complexity": 36, + "token_count": 1162, + "parameters": [ + "sort_keys", + "axis" + ], + "start_line": 1970, + "end_line": 2114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 145, + "top_nesting_level": 0 + }, + { + "name": "local_where", + "long_name": "local_where( PyArrayObject * ap1 , PyArrayObject * ap2 , PyArrayObject * ret)", + "filename": "multiarraymodule.c", + "nloc": 35, + "complexity": 7, + "token_count": 243, + "parameters": [ + "ap1", + "ap2", + "ret" + ], + "start_line": 2118, + "end_line": 2153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SearchSorted", + "long_name": "PyArray_SearchSorted( PyArrayObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 5, + "token_count": 231, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2159, + "end_line": 2204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 82, + "complexity": 17, + "token_count": 659, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2215, + "end_line": 2317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 102, + "complexity": 20, + "token_count": 804, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2325, + "end_line": 2452, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 128, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 284, + "parameters": [ + "op" + ], + "start_line": 2458, + "end_line": 2512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Correlate", + "long_name": "PyArray_Correlate( PyObject * op1 , PyObject * op2 , int mode)", + "filename": "multiarraymodule.c", + "nloc": 95, + "complexity": 15, + "token_count": 674, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2518, + "end_line": 2625, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgMin", + "long_name": "PyArray_ArgMin( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 5, + "token_count": 141, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2632, + "end_line": 2656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Max", + "long_name": "PyArray_Max( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 71, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2662, + "end_line": 2673, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Min", + "long_name": "PyArray_Min( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 71, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2679, + "end_line": 2690, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ptp", + "long_name": "PyArray_Ptp( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 4, + "token_count": 138, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2696, + "end_line": 2719, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgMax", + "long_name": "PyArray_ArgMax( PyArrayObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 7, + "token_count": 326, + "parameters": [ + "op", + "axis" + ], + "start_line": 2726, + "end_line": 2783, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Take", + "long_name": "PyArray_Take( PyArrayObject * self0 , PyObject * indices0 , int axis)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 473, + "parameters": [ + "self0", + "indices0", + "axis" + ], + "start_line": 2790, + "end_line": 2865, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Put", + "long_name": "PyArray_Put( PyArrayObject * self , PyObject * values0 , PyObject * indices0)", + "filename": "multiarraymodule.c", + "nloc": 63, + "complexity": 15, + "token_count": 465, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 2871, + "end_line": 2940, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PutMask", + "long_name": "PyArray_PutMask( PyArrayObject * self , PyObject * values0 , PyObject * mask0)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 422, + "parameters": [ + "self", + "values0", + "mask0" + ], + "start_line": 2946, + "end_line": 3017, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Converter", + "long_name": "PyArray_Converter( PyObject * object , PyObject ** address)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 66, + "parameters": [ + "object", + "address" + ], + "start_line": 3033, + "end_line": 3045, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BoolConverter", + "long_name": "PyArray_BoolConverter( PyObject * object , Bool * val)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "object", + "val" + ], + "start_line": 3051, + "end_line": 3059, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_TypestrConvert", + "long_name": "PyArray_TypestrConvert( int itemsize , int gentype)", + "filename": "multiarraymodule.c", + "nloc": 96, + "complexity": 35, + "token_count": 308, + "parameters": [ + "itemsize", + "gentype" + ], + "start_line": 3066, + "end_line": 3181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BufferConverter", + "long_name": "PyArray_BufferConverter( PyObject * obj , PyArray_Chunk * buf)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 6, + "token_count": 147, + "parameters": [ + "obj", + "buf" + ], + "start_line": 3199, + "end_line": 3224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpConverter", + "long_name": "PyArray_IntpConverter( PyObject * obj , PyArray_Dims * seq)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 10, + "token_count": 189, + "parameters": [ + "obj", + "seq" + ], + "start_line": 3239, + "end_line": 3275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "_use_inherit", + "long_name": "_use_inherit( PyArray_Descr * type , PyObject * newobj , int * errflag)", + "filename": "multiarraymodule.c", + "nloc": 32, + "complexity": 7, + "token_count": 161, + "parameters": [ + "type", + "newobj", + "errflag" + ], + "start_line": 3293, + "end_line": 3326, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_tuple", + "long_name": "_convert_from_tuple( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 61, + "complexity": 14, + "token_count": 369, + "parameters": [ + "obj" + ], + "start_line": 3329, + "end_line": 3402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 60, + "complexity": 11, + "token_count": 395, + "parameters": [ + "obj" + ], + "start_line": 3410, + "end_line": 3472, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 62, + "complexity": 11, + "token_count": 392, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3483, + "end_line": 3546, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_commastring", + "long_name": "_convert_from_commastring( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 92, + "parameters": [ + "obj", + "align" + ], + "start_line": 3559, + "end_line": 3575, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_use_fields_dict", + "long_name": "_use_fields_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 1, + "token_count": 29, + "parameters": [ + "obj", + "align" + ], + "start_line": 3612, + "end_line": 3617, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_dict", + "long_name": "_convert_from_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 93, + "complexity": 25, + "token_count": 641, + "parameters": [ + "obj", + "align" + ], + "start_line": 3620, + "end_line": 3722, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter2", + "long_name": "PyArray_DescrConverter2( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 37, + "parameters": [ + "obj", + "at" + ], + "start_line": 3740, + "end_line": 3747, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter", + "long_name": "PyArray_DescrConverter( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 148, + "complexity": 58, + "token_count": 921, + "parameters": [ + "obj", + "at" + ], + "start_line": 3764, + "end_line": 3946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 183, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ByteorderConverter", + "long_name": "PyArray_ByteorderConverter( PyObject * obj , char * endian)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 16, + "token_count": 218, + "parameters": [ + "obj", + "endian" + ], + "start_line": 3952, + "end_line": 3984, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SortkindConverter", + "long_name": "PyArray_SortkindConverter( PyObject * obj , PyArray_SORTKIND * sortkind)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 11, + "token_count": 162, + "parameters": [ + "obj", + "sortkind" + ], + "start_line": 3990, + "end_line": 4016, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EquivTypes", + "long_name": "PyArray_EquivTypes( PyArray_Descr * typ1 , PyArray_Descr * typ2)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 8, + "token_count": 138, + "parameters": [ + "typ1", + "typ2" + ], + "start_line": 4025, + "end_line": 4044, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 59, + "complexity": 15, + "token_count": 325, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4065, + "end_line": 4130, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Empty", + "long_name": "PyArray_Empty( int nd , intp * dims , PyArray_Descr * type , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 14, + "complexity": 4, + "token_count": 96, + "parameters": [ + "nd", + "dims", + "type", + "fortran" + ], + "start_line": 4138, + "end_line": 4153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_empty", + "long_name": "array_empty( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 2, + "token_count": 130, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4159, + "end_line": 4183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_scalar", + "long_name": "array_scalar( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 10, + "token_count": 254, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4188, + "end_line": 4246, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zeros", + "long_name": "PyArray_Zeros( int nd , intp * dims , PyArray_Descr * type , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 4, + "token_count": 134, + "parameters": [ + "nd", + "dims", + "type", + "fortran" + ], + "start_line": 4255, + "end_line": 4279, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_zeros", + "long_name": "array_zeros( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 2, + "token_count": 133, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4285, + "end_line": 4309, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_set_typeDict", + "long_name": "array_set_typeDict( PyObject * ignored , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "ignored", + "args" + ], + "start_line": 4316, + "end_line": 4325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n)", + "filename": "multiarraymodule.c", + "nloc": 46, + "complexity": 8, + "token_count": 222, + "parameters": [ + "data", + "slen", + "dtype", + "n" + ], + "start_line": 4330, + "end_line": 4381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 15, + "complexity": 2, + "token_count": 103, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4386, + "end_line": 4402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 111, + "complexity": 22, + "token_count": 649, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4416, + "end_line": 4541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_fromfile", + "long_name": "array_fromfile( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 7, + "token_count": 225, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4559, + "end_line": 4597, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromBuffer", + "long_name": "PyArray_FromBuffer( PyObject * buf , PyArray_Descr * type , intp count , intp offset)", + "filename": "multiarraymodule.c", + "nloc": 83, + "complexity": 16, + "token_count": 446, + "parameters": [ + "buf", + "type", + "count", + "offset" + ], + "start_line": 4601, + "end_line": 4694, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "array_frombuffer", + "long_name": "array_frombuffer( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 121, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4710, + "end_line": 4727, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_concatenate", + "long_name": "array_concatenate( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 73, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 4733, + "end_line": 4744, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_innerproduct", + "long_name": "array_innerproduct( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 5, + "complexity": 2, + "token_count": 49, + "parameters": [ + "dummy", + "args" + ], + "start_line": 4751, + "end_line": 4757, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_matrixproduct", + "long_name": "array_matrixproduct( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 5, + "complexity": 2, + "token_count": 49, + "parameters": [ + "dummy", + "args" + ], + "start_line": 4764, + "end_line": 4770, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_fastCopyAndTranspose", + "long_name": "array_fastCopyAndTranspose( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 5, + "complexity": 2, + "token_count": 41, + "parameters": [ + "dummy", + "args" + ], + "start_line": 4774, + "end_line": 4780, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_correlate", + "long_name": "array_correlate( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 4784, + "end_line": 4793, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Arange", + "long_name": "PyArray_Arange( double start , double stop , double step , int type_num)", + "filename": "multiarraymodule.c", + "nloc": 40, + "complexity": 9, + "token_count": 300, + "parameters": [ + "start", + "stop", + "step", + "type_num" + ], + "start_line": 4800, + "end_line": 4851, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "_calc_length", + "long_name": "_calc_length( PyObject * start , PyObject * stop , PyObject * step , PyObject ** next , int cmplx)", + "filename": "multiarraymodule.c", + "nloc": 31, + "complexity": 10, + "token_count": 235, + "parameters": [ + "start", + "stop", + "step", + "next", + "cmplx" + ], + "start_line": 4857, + "end_line": 4889, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArangeObj", + "long_name": "PyArray_ArangeObj( PyObject * start , PyObject * stop , PyObject * step , PyArray_Descr * dtype)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 19, + "token_count": 461, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 4896, + "end_line": 4980, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "array_arange", + "long_name": "array_arange( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 100, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4986, + "end_line": 4998, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_set_string_function", + "long_name": "array_set_string_function( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 98, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5005, + "end_line": 5021, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "array_set_ops_function", + "long_name": "array_set_ops_function( PyObject * self , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 5027, + "end_line": 5044, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Where", + "long_name": "PyArray_Where( PyObject * condition , PyObject * x , PyObject * y)", + "filename": "multiarraymodule.c", + "nloc": 31, + "complexity": 8, + "token_count": 231, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5051, + "end_line": 5091, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_where", + "long_name": "array_where( PyObject * ignored , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 60, + "parameters": [ + "ignored", + "args" + ], + "start_line": 5099, + "end_line": 5107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_lexsort", + "long_name": "array_lexsort( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 5119, + "end_line": 5129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_register_dtype", + "long_name": "array_register_dtype( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 3, + "token_count": 64, + "parameters": [ + "dummy", + "args" + ], + "start_line": 5138, + "end_line": 5149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_can_cast_safely", + "long_name": "array_can_cast_safely( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 5, + "token_count": 128, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5156, + "end_line": 5179, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "new_buffer", + "long_name": "new_buffer( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 7, + "complexity": 2, + "token_count": 37, + "parameters": [ + "dummy", + "args" + ], + "start_line": 5186, + "end_line": 5194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "buffer_buffer", + "long_name": "buffer_buffer( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 120, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5203, + "end_line": 5221, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "setup_scalartypes", + "long_name": "setup_scalartypes( PyObject * dict)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 10, + "token_count": 351, + "parameters": [ + "dict" + ], + "start_line": 5285, + "end_line": 5398, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 114, + "top_nesting_level": 0 + }, + { + "name": "set_flaginfo", + "long_name": "set_flaginfo( PyObject * d)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 1, + "token_count": 152, + "parameters": [ + "d" + ], + "start_line": 5403, + "end_line": 5427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "initmultiarray", + "long_name": "initmultiarray()", + "filename": "multiarraymodule.c", + "nloc": 63, + "complexity": 15, + "token_count": 434, + "parameters": [], + "start_line": 5432, + "end_line": 5525, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "_arraydescr_fromobj", + "long_name": "_arraydescr_fromobj( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 15, + "complexity": 3, + "token_count": 67, + "parameters": [ + "obj" + ], + "start_line": 34, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyIntList", + "long_name": "PyArray_MultiplyIntList( register int * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 74, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MultiplyList", + "long_name": "PyArray_MultiplyList( register intp * l1 , register int n)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 36, + "parameters": [ + "l1", + "n" + ], + "start_line": 85, + "end_line": 90, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPtr", + "long_name": "PyArray_GetPtr( PyArrayObject * obj , register intp * ind)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 61, + "parameters": [ + "obj", + "ind" + ], + "start_line": 96, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AxisConverter", + "long_name": "PyArray_AxisConverter( PyObject * obj , int * axis)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 53, + "parameters": [ + "obj", + "axis" + ], + "start_line": 110, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CompareLists", + "long_name": "PyArray_CompareLists( intp * l1 , intp * l2 , int n)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 3, + "token_count": 51, + "parameters": [ + "l1", + "l2", + "n" + ], + "start_line": 128, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_View", + "long_name": "PyArray_View( PyArrayObject * self , PyArray_Descr * type , PyTypeObject * pytype)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 5, + "token_count": 158, + "parameters": [ + "self", + "type", + "pytype" + ], + "start_line": 142, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ravel", + "long_name": "PyArray_Ravel( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 102, + "parameters": [ + "a", + "fortran" + ], + "start_line": 178, + "end_line": 195, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Flatten", + "long_name": "PyArray_Flatten( PyArrayObject * a , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 6, + "token_count": 176, + "parameters": [ + "a", + "fortran" + ], + "start_line": 201, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Reshape", + "long_name": "PyArray_Reshape( PyArrayObject * self , PyObject * shape)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "shape" + ], + "start_line": 247, + "end_line": 256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "_check_ones", + "long_name": "_check_ones( PyArrayObject * self , int newnd , intp * newdims , intp * strides)", + "filename": "multiarraymodule.c", + "nloc": 25, + "complexity": 12, + "token_count": 189, + "parameters": [ + "self", + "newnd", + "newdims", + "strides" + ], + "start_line": 259, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Newshape", + "long_name": "PyArray_Newshape( PyArrayObject * self , PyArray_Dims * newdims)", + "filename": "multiarraymodule.c", + "nloc": 72, + "complexity": 17, + "token_count": 409, + "parameters": [ + "self", + "newdims" + ], + "start_line": 296, + "end_line": 383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Squeeze", + "long_name": "PyArray_Squeeze( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 34, + "complexity": 5, + "token_count": 204, + "parameters": [ + "self" + ], + "start_line": 392, + "end_line": 427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Mean", + "long_name": "PyArray_Mean( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 19, + "complexity": 4, + "token_count": 139, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 434, + "end_line": 455, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Std", + "long_name": "PyArray_Std( PyArrayObject * self , int axis , int rtype , int variance)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 13, + "token_count": 450, + "parameters": [ + "self", + "axis", + "rtype", + "variance" + ], + "start_line": 462, + "end_line": 521, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sum", + "long_name": "PyArray_Sum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 528, + "end_line": 538, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Prod", + "long_name": "PyArray_Prod( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 544, + "end_line": 554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CumSum", + "long_name": "PyArray_CumSum( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 560, + "end_line": 570, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CumProd", + "long_name": "PyArray_CumProd( PyArrayObject * self , int axis , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 69, + "parameters": [ + "self", + "axis", + "rtype" + ], + "start_line": 576, + "end_line": 587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Any", + "long_name": "PyArray_Any( PyArrayObject * self , int axis)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "axis" + ], + "start_line": 593, + "end_line": 604, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_All", + "long_name": "PyArray_All( PyArrayObject * self , int axis)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "axis" + ], + "start_line": 610, + "end_line": 621, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Compress", + "long_name": "PyArray_Compress( PyArrayObject * self , PyObject * condition , int axis)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 3, + "token_count": 110, + "parameters": [ + "self", + "condition", + "axis" + ], + "start_line": 628, + "end_line": 648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Nonzero", + "long_name": "PyArray_Nonzero( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 13, + "token_count": 414, + "parameters": [ + "self" + ], + "start_line": 654, + "end_line": 713, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 60, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Clip", + "long_name": "PyArray_Clip( PyArrayObject * self , PyObject * min , PyObject * max)", + "filename": "multiarraymodule.c", + "nloc": 28, + "complexity": 6, + "token_count": 237, + "parameters": [ + "self", + "min", + "max" + ], + "start_line": 719, + "end_line": 749, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Conjugate", + "long_name": "PyArray_Conjugate( PyArrayObject * self)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 9, + "token_count": 228, + "parameters": [ + "self" + ], + "start_line": 755, + "end_line": 791, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Trace", + "long_name": "PyArray_Trace( PyArrayObject * self , int offset , int axis1 , int axis2 , int rtype)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 81, + "parameters": [ + "self", + "offset", + "axis1", + "axis2", + "rtype" + ], + "start_line": 797, + "end_line": 807, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Diagonal", + "long_name": "PyArray_Diagonal( PyArrayObject * self , int offset , int axis1 , int axis2)", + "filename": "multiarraymodule.c", + "nloc": 104, + "complexity": 23, + "token_count": 774, + "parameters": [ + "self", + "offset", + "axis1", + "axis2" + ], + "start_line": 813, + "end_line": 932, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "top_nesting_level": 0 + }, + { + "name": "PyArray_AsCArray", + "long_name": "PyArray_AsCArray( PyObject ** op , * ptr , intp * dims , int nd , PyArray_Descr * typedescr)", + "filename": "multiarraymodule.c", + "nloc": 50, + "complexity": 12, + "token_count": 400, + "parameters": [ + "op", + "ptr", + "dims", + "nd", + "typedescr" + ], + "start_line": 948, + "end_line": 999, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As1D", + "long_name": "PyArray_As1D( PyObject ** op , char ** ptr , int * d1 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 71, + "parameters": [ + "op", + "ptr", + "d1", + "typecode" + ], + "start_line": 1007, + "end_line": 1017, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyArray_As2D", + "long_name": "PyArray_As2D( PyObject ** op , char ** * ptr , int * d1 , int * d2 , int typecode)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 92, + "parameters": [ + "op", + "ptr", + "d1", + "d2", + "typecode" + ], + "start_line": 1023, + "end_line": 1035, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Free", + "long_name": "PyArray_Free( PyObject * op , * ptr)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 4, + "token_count": 67, + "parameters": [ + "op", + "ptr" + ], + "start_line": 1043, + "end_line": 1054, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "_swap_and_concat", + "long_name": "_swap_and_concat( PyObject * op , int axis , int n)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 6, + "token_count": 185, + "parameters": [ + "op", + "axis", + "n" + ], + "start_line": 1058, + "end_line": 1086, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Concatenate", + "long_name": "PyArray_Concatenate( PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 92, + "complexity": 20, + "token_count": 617, + "parameters": [ + "op", + "axis" + ], + "start_line": 1098, + "end_line": 1202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 105, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SwapAxes", + "long_name": "PyArray_SwapAxes( PyArrayObject * ap , int a1 , int a2)", + "filename": "multiarraymodule.c", + "nloc": 38, + "complexity": 12, + "token_count": 227, + "parameters": [ + "ap", + "a1", + "a2" + ], + "start_line": 1208, + "end_line": 1249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Transpose", + "long_name": "PyArray_Transpose( PyArrayObject * ap , PyArray_Dims * permute)", + "filename": "multiarraymodule.c", + "nloc": 46, + "complexity": 10, + "token_count": 309, + "parameters": [ + "ap", + "permute" + ], + "start_line": 1255, + "end_line": 1308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Repeat", + "long_name": "PyArray_Repeat( PyArrayObject * aop , PyObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 78, + "complexity": 15, + "token_count": 523, + "parameters": [ + "aop", + "op", + "axis" + ], + "start_line": 1314, + "end_line": 1409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 96, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ConvertToCommonType", + "long_name": "PyArray_ConvertToCommonType( PyObject * op , int * retn)", + "filename": "multiarraymodule.c", + "nloc": 63, + "complexity": 13, + "token_count": 427, + "parameters": [ + "op", + "retn" + ], + "start_line": 1413, + "end_line": 1482, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Choose", + "long_name": "PyArray_Choose( PyArrayObject * ip , PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 15, + "token_count": 518, + "parameters": [ + "ip", + "op" + ], + "start_line": 1489, + "end_line": 1570, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 82, + "top_nesting_level": 0 + }, + { + "name": "_strided_copy", + "long_name": "_strided_copy( char * dst , intp dststride , char * src , intp srcstride , intp num , int elsize)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 48, + "parameters": [ + "dst", + "dststride", + "src", + "srcstride", + "num", + "elsize" + ], + "start_line": 1573, + "end_line": 1580, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "_new_sort", + "long_name": "_new_sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 8, + "token_count": 284, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1591, + "end_line": 1645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "_new_argsort", + "long_name": "_new_argsort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 67, + "complexity": 13, + "token_count": 498, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1648, + "end_line": 1726, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 0 + }, + { + "name": "qsortCompare", + "long_name": "qsortCompare( const * a , const * b)", + "filename": "multiarraymodule.c", + "nloc": 4, + "complexity": 1, + "token_count": 30, + "parameters": [ + "a", + "b" + ], + "start_line": 1734, + "end_line": 1737, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Sort", + "long_name": "PyArray_Sort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 52, + "complexity": 14, + "token_count": 353, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1792, + "end_line": 1858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 67, + "top_nesting_level": 0 + }, + { + "name": "argsort_static_compare", + "long_name": "argsort_static_compare( const * ip1 , const * ip2)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 1, + "token_count": 67, + "parameters": [ + "ip1", + "ip2" + ], + "start_line": 1864, + "end_line": 1872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgSort", + "long_name": "PyArray_ArgSort( PyArrayObject * op , int axis , PyArray_SORTKIND which)", + "filename": "multiarraymodule.c", + "nloc": 66, + "complexity": 15, + "token_count": 493, + "parameters": [ + "op", + "axis", + "which" + ], + "start_line": 1878, + "end_line": 1958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "top_nesting_level": 0 + }, + { + "name": "PyArray_LexSort", + "long_name": "PyArray_LexSort( PyObject * sort_keys , int axis)", + "filename": "multiarraymodule.c", + "nloc": 132, + "complexity": 36, + "token_count": 1162, + "parameters": [ + "sort_keys", + "axis" + ], + "start_line": 1970, + "end_line": 2114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 145, + "top_nesting_level": 0 + }, + { + "name": "local_where", + "long_name": "local_where( PyArrayObject * ap1 , PyArrayObject * ap2 , PyArrayObject * ret)", + "filename": "multiarraymodule.c", + "nloc": 35, + "complexity": 7, + "token_count": 243, + "parameters": [ + "ap1", + "ap2", + "ret" + ], + "start_line": 2118, + "end_line": 2153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SearchSorted", + "long_name": "PyArray_SearchSorted( PyArrayObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 5, + "token_count": 231, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2159, + "end_line": 2204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 0 + }, + { + "name": "PyArray_InnerProduct", + "long_name": "PyArray_InnerProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 82, + "complexity": 17, + "token_count": 659, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2215, + "end_line": 2317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MatrixProduct", + "long_name": "PyArray_MatrixProduct( PyObject * op1 , PyObject * op2)", + "filename": "multiarraymodule.c", + "nloc": 102, + "complexity": 20, + "token_count": 804, + "parameters": [ + "op1", + "op2" + ], + "start_line": 2325, + "end_line": 2452, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 128, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyAndTranspose", + "long_name": "PyArray_CopyAndTranspose( PyObject * op)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 6, + "token_count": 284, + "parameters": [ + "op" + ], + "start_line": 2458, + "end_line": 2512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 55, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Correlate", + "long_name": "PyArray_Correlate( PyObject * op1 , PyObject * op2 , int mode)", + "filename": "multiarraymodule.c", + "nloc": 95, + "complexity": 15, + "token_count": 674, + "parameters": [ + "op1", + "op2", + "mode" + ], + "start_line": 2518, + "end_line": 2625, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgMin", + "long_name": "PyArray_ArgMin( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 5, + "token_count": 141, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2632, + "end_line": 2656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Max", + "long_name": "PyArray_Max( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 71, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2662, + "end_line": 2673, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Min", + "long_name": "PyArray_Min( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 71, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2679, + "end_line": 2690, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Ptp", + "long_name": "PyArray_Ptp( PyArrayObject * ap , int axis)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 4, + "token_count": 138, + "parameters": [ + "ap", + "axis" + ], + "start_line": 2696, + "end_line": 2719, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArgMax", + "long_name": "PyArray_ArgMax( PyArrayObject * op , int axis)", + "filename": "multiarraymodule.c", + "nloc": 47, + "complexity": 7, + "token_count": 326, + "parameters": [ + "op", + "axis" + ], + "start_line": 2726, + "end_line": 2783, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Take", + "long_name": "PyArray_Take( PyArrayObject * self0 , PyObject * indices0 , int axis)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 473, + "parameters": [ + "self0", + "indices0", + "axis" + ], + "start_line": 2790, + "end_line": 2865, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 76, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Put", + "long_name": "PyArray_Put( PyArrayObject * self , PyObject * values0 , PyObject * indices0)", + "filename": "multiarraymodule.c", + "nloc": 63, + "complexity": 15, + "token_count": 465, + "parameters": [ + "self", + "values0", + "indices0" + ], + "start_line": 2871, + "end_line": 2940, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PutMask", + "long_name": "PyArray_PutMask( PyArrayObject * self , PyObject * values0 , PyObject * mask0)", + "filename": "multiarraymodule.c", + "nloc": 65, + "complexity": 12, + "token_count": 422, + "parameters": [ + "self", + "values0", + "mask0" + ], + "start_line": 2946, + "end_line": 3017, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 72, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Converter", + "long_name": "PyArray_Converter( PyObject * object , PyObject ** address)", + "filename": "multiarraymodule.c", + "nloc": 13, + "complexity": 3, + "token_count": 66, + "parameters": [ + "object", + "address" + ], + "start_line": 3033, + "end_line": 3045, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BoolConverter", + "long_name": "PyArray_BoolConverter( PyObject * object , Bool * val)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "object", + "val" + ], + "start_line": 3051, + "end_line": 3059, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_TypestrConvert", + "long_name": "PyArray_TypestrConvert( int itemsize , int gentype)", + "filename": "multiarraymodule.c", + "nloc": 96, + "complexity": 35, + "token_count": 308, + "parameters": [ + "itemsize", + "gentype" + ], + "start_line": 3066, + "end_line": 3181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "PyArray_BufferConverter", + "long_name": "PyArray_BufferConverter( PyObject * obj , PyArray_Chunk * buf)", + "filename": "multiarraymodule.c", + "nloc": 20, + "complexity": 6, + "token_count": 147, + "parameters": [ + "obj", + "buf" + ], + "start_line": 3199, + "end_line": 3224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "PyArray_IntpConverter", + "long_name": "PyArray_IntpConverter( PyObject * obj , PyArray_Dims * seq)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 10, + "token_count": 189, + "parameters": [ + "obj", + "seq" + ], + "start_line": 3239, + "end_line": 3275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 0 + }, + { + "name": "_use_inherit", + "long_name": "_use_inherit( PyArray_Descr * type , PyObject * newobj , int * errflag)", + "filename": "multiarraymodule.c", + "nloc": 32, + "complexity": 7, + "token_count": 161, + "parameters": [ + "type", + "newobj", + "errflag" + ], + "start_line": 3293, + "end_line": 3326, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_tuple", + "long_name": "_convert_from_tuple( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 57, + "complexity": 11, + "token_count": 335, + "parameters": [ + "obj" + ], + "start_line": 3329, + "end_line": 3397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 69, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_array_descr", + "long_name": "_convert_from_array_descr( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 60, + "complexity": 11, + "token_count": 395, + "parameters": [ + "obj" + ], + "start_line": 3405, + "end_line": 3467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_list", + "long_name": "_convert_from_list( PyObject * obj , int align , int try_descr)", + "filename": "multiarraymodule.c", + "nloc": 62, + "complexity": 11, + "token_count": 392, + "parameters": [ + "obj", + "align", + "try_descr" + ], + "start_line": 3478, + "end_line": 3541, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_commastring", + "long_name": "_convert_from_commastring( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 5, + "token_count": 92, + "parameters": [ + "obj", + "align" + ], + "start_line": 3554, + "end_line": 3570, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_use_fields_dict", + "long_name": "_use_fields_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 1, + "token_count": 29, + "parameters": [ + "obj", + "align" + ], + "start_line": 3607, + "end_line": 3612, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_convert_from_dict", + "long_name": "_convert_from_dict( PyObject * obj , int align)", + "filename": "multiarraymodule.c", + "nloc": 93, + "complexity": 25, + "token_count": 641, + "parameters": [ + "obj", + "align" + ], + "start_line": 3615, + "end_line": 3717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter2", + "long_name": "PyArray_DescrConverter2( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 37, + "parameters": [ + "obj", + "at" + ], + "start_line": 3735, + "end_line": 3742, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyArray_DescrConverter", + "long_name": "PyArray_DescrConverter( PyObject * obj , PyArray_Descr ** at)", + "filename": "multiarraymodule.c", + "nloc": 148, + "complexity": 58, + "token_count": 921, + "parameters": [ + "obj", + "at" + ], + "start_line": 3759, + "end_line": 3941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 183, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ByteorderConverter", + "long_name": "PyArray_ByteorderConverter( PyObject * obj , char * endian)", + "filename": "multiarraymodule.c", + "nloc": 33, + "complexity": 16, + "token_count": 218, + "parameters": [ + "obj", + "endian" + ], + "start_line": 3947, + "end_line": 3979, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_SortkindConverter", + "long_name": "PyArray_SortkindConverter( PyObject * obj , PyArray_SORTKIND * sortkind)", + "filename": "multiarraymodule.c", + "nloc": 27, + "complexity": 11, + "token_count": 162, + "parameters": [ + "obj", + "sortkind" + ], + "start_line": 3985, + "end_line": 4011, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EquivTypes", + "long_name": "PyArray_EquivTypes( PyArray_Descr * typ1 , PyArray_Descr * typ2)", + "filename": "multiarraymodule.c", + "nloc": 18, + "complexity": 8, + "token_count": 138, + "parameters": [ + "typ1", + "typ2" + ], + "start_line": 4020, + "end_line": 4039, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_array_fromobject", + "long_name": "_array_fromobject( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 59, + "complexity": 15, + "token_count": 325, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4060, + "end_line": 4125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Empty", + "long_name": "PyArray_Empty( int nd , intp * dims , PyArray_Descr * type , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 14, + "complexity": 4, + "token_count": 96, + "parameters": [ + "nd", + "dims", + "type", + "fortran" + ], + "start_line": 4133, + "end_line": 4148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "array_empty", + "long_name": "array_empty( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 2, + "token_count": 130, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4154, + "end_line": 4178, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_scalar", + "long_name": "array_scalar( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 51, + "complexity": 10, + "token_count": 254, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4183, + "end_line": 4241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 59, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Zeros", + "long_name": "PyArray_Zeros( int nd , intp * dims , PyArray_Descr * type , int fortran)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 4, + "token_count": 134, + "parameters": [ + "nd", + "dims", + "type", + "fortran" + ], + "start_line": 4250, + "end_line": 4274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_zeros", + "long_name": "array_zeros( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 2, + "token_count": 133, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 4280, + "end_line": 4304, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "array_set_typeDict", + "long_name": "array_set_typeDict( PyObject * ignored , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "ignored", + "args" + ], + "start_line": 4311, + "end_line": 4320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromString", + "long_name": "PyArray_FromString( char * data , intp slen , PyArray_Descr * dtype , intp n)", + "filename": "multiarraymodule.c", + "nloc": 46, + "complexity": 8, + "token_count": 222, + "parameters": [ + "data", + "slen", + "dtype", + "n" + ], + "start_line": 4325, + "end_line": 4376, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "array_fromString", + "long_name": "array_fromString( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 15, + "complexity": 2, + "token_count": 103, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4381, + "end_line": 4397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromFile", + "long_name": "PyArray_FromFile( FILE * fp , PyArray_Descr * typecode , intp num , char * sep)", + "filename": "multiarraymodule.c", + "nloc": 111, + "complexity": 22, + "token_count": 649, + "parameters": [ + "fp", + "typecode", + "num", + "sep" + ], + "start_line": 4411, + "end_line": 4536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 126, + "top_nesting_level": 0 + }, + { + "name": "array_fromfile", + "long_name": "array_fromfile( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 36, + "complexity": 7, + "token_count": 225, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4554, + "end_line": 4592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromBuffer", + "long_name": "PyArray_FromBuffer( PyObject * buf , PyArray_Descr * type , intp count , intp offset)", + "filename": "multiarraymodule.c", + "nloc": 83, + "complexity": 16, + "token_count": 446, + "parameters": [ + "buf", + "type", + "count", + "offset" + ], + "start_line": 4596, + "end_line": 4689, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + }, + { + "name": "array_frombuffer", + "long_name": "array_frombuffer( PyObject * ignored , PyObject * args , PyObject * keywds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 121, + "parameters": [ + "ignored", + "args", + "keywds" + ], + "start_line": 4705, + "end_line": 4722, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "array_concatenate", + "long_name": "array_concatenate( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 73, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 4728, + "end_line": 4739, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_innerproduct", + "long_name": "array_innerproduct( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 5, + "complexity": 2, + "token_count": 49, + "parameters": [ + "dummy", + "args" + ], + "start_line": 4746, + "end_line": 4752, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_matrixproduct", + "long_name": "array_matrixproduct( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 5, + "complexity": 2, + "token_count": 49, + "parameters": [ + "dummy", + "args" + ], + "start_line": 4759, + "end_line": 4765, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_fastCopyAndTranspose", + "long_name": "array_fastCopyAndTranspose( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 5, + "complexity": 2, + "token_count": 41, + "parameters": [ + "dummy", + "args" + ], + "start_line": 4769, + "end_line": 4775, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "array_correlate", + "long_name": "array_correlate( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 8, + "complexity": 2, + "token_count": 81, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 4779, + "end_line": 4788, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Arange", + "long_name": "PyArray_Arange( double start , double stop , double step , int type_num)", + "filename": "multiarraymodule.c", + "nloc": 40, + "complexity": 9, + "token_count": 300, + "parameters": [ + "start", + "stop", + "step", + "type_num" + ], + "start_line": 4795, + "end_line": 4846, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 52, + "top_nesting_level": 0 + }, + { + "name": "_calc_length", + "long_name": "_calc_length( PyObject * start , PyObject * stop , PyObject * step , PyObject ** next , int cmplx)", + "filename": "multiarraymodule.c", + "nloc": 31, + "complexity": 10, + "token_count": 235, + "parameters": [ + "start", + "stop", + "step", + "next", + "cmplx" + ], + "start_line": 4852, + "end_line": 4884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ArangeObj", + "long_name": "PyArray_ArangeObj( PyObject * start , PyObject * stop , PyObject * step , PyArray_Descr * dtype)", + "filename": "multiarraymodule.c", + "nloc": 70, + "complexity": 19, + "token_count": 461, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 4891, + "end_line": 4975, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 85, + "top_nesting_level": 0 + }, + { + "name": "array_arange", + "long_name": "array_arange( PyObject * ignored , PyObject * args , PyObject * kws)", + "filename": "multiarraymodule.c", + "nloc": 11, + "complexity": 2, + "token_count": 100, + "parameters": [ + "ignored", + "args", + "kws" + ], + "start_line": 4981, + "end_line": 4993, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_set_string_function", + "long_name": "array_set_string_function( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 98, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5000, + "end_line": 5016, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "array_set_ops_function", + "long_name": "array_set_ops_function( PyObject * self , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 12, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 5022, + "end_line": 5039, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Where", + "long_name": "PyArray_Where( PyObject * condition , PyObject * x , PyObject * y)", + "filename": "multiarraymodule.c", + "nloc": 31, + "complexity": 8, + "token_count": 231, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 5046, + "end_line": 5086, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_where", + "long_name": "array_where( PyObject * ignored , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 6, + "complexity": 2, + "token_count": 60, + "parameters": [ + "ignored", + "args" + ], + "start_line": 5094, + "end_line": 5102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "array_lexsort", + "long_name": "array_lexsort( PyObject * ignored , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "ignored", + "args", + "kwds" + ], + "start_line": 5114, + "end_line": 5124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "array_register_dtype", + "long_name": "array_register_dtype( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 10, + "complexity": 3, + "token_count": 64, + "parameters": [ + "dummy", + "args" + ], + "start_line": 5133, + "end_line": 5144, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_can_cast_safely", + "long_name": "array_can_cast_safely( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 22, + "complexity": 5, + "token_count": 128, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5151, + "end_line": 5174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "new_buffer", + "long_name": "new_buffer( PyObject * dummy , PyObject * args)", + "filename": "multiarraymodule.c", + "nloc": 7, + "complexity": 2, + "token_count": 37, + "parameters": [ + "dummy", + "args" + ], + "start_line": 5181, + "end_line": 5189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "buffer_buffer", + "long_name": "buffer_buffer( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "multiarraymodule.c", + "nloc": 16, + "complexity": 3, + "token_count": 120, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 5198, + "end_line": 5216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "setup_scalartypes", + "long_name": "setup_scalartypes( PyObject * dict)", + "filename": "multiarraymodule.c", + "nloc": 45, + "complexity": 10, + "token_count": 351, + "parameters": [ + "dict" + ], + "start_line": 5280, + "end_line": 5393, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 114, + "top_nesting_level": 0 + }, + { + "name": "set_flaginfo", + "long_name": "set_flaginfo( PyObject * d)", + "filename": "multiarraymodule.c", + "nloc": 21, + "complexity": 1, + "token_count": 152, + "parameters": [ + "d" + ], + "start_line": 5398, + "end_line": 5422, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "initmultiarray", + "long_name": "initmultiarray()", + "filename": "multiarraymodule.c", + "nloc": 63, + "complexity": 15, + "token_count": 434, + "parameters": [], + "start_line": 5427, + "end_line": 5520, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 94, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "_convert_from_tuple", + "long_name": "_convert_from_tuple( PyObject * obj)", + "filename": "multiarraymodule.c", + "nloc": 61, + "complexity": 14, + "token_count": 369, + "parameters": [ + "obj" + ], + "start_line": 3329, + "end_line": 3402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + } + ], + "nloc": 4157, + "complexity": 913, + "token_count": 27189, + "diff_parsed": { + "added": [ + "\t\t/* If (type, 1) was given, it is equivalent to type... */", + "\t\tif (shape.len == 1 && shape.ptr[0] == 1 && PyNumber_Check(val)) {", + "\t\t\tPyDimMem_FREE(shape.ptr);", + "\t\t\treturn type;", + "\t\t}" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "0a407f99008973cead33d672c44006fbfa285a34", + "msg": "made 'masked' rank-0", + "author": { + "name": "sasha", + "email": "sasha@localhost" + }, + "committer": { + "name": "sasha", + "email": "sasha@localhost" + }, + "author_date": "2006-01-12T21:56:07+00:00", + "author_timezone": 0, + "committer_date": "2006-01-12T21:56:07+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "071f111e8c14ac2286722fb147254aebd8ff98d3" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 2, + "insertions": 9, + "lines": 11, + "files": 2, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "numpy/core/ma.py", + "new_path": "numpy/core/ma.py", + "filename": "ma.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -2148,5 +2148,4 @@ def _compress(self, cond, axis=None):\n del _m, MethodType, not_implemented\n \n \n-masked = MaskedArray([0], int, mask=[1])[0:0]\n-masked = masked[0:0]\n+masked = MaskedArray(0, int, mask=1)\n", + "added_lines": 1, + "deleted_lines": 2, + "source_code": "\"\"\"MA: a facility for dealing with missing observations\nMA is generally used as a numpy.array look-alike.\nby Paul F. Dubois.\n\nCopyright 1999, 2000, 2001 Regents of the University of California.\nReleased for unlimited redistribution.\nAdapted for numpy_core 2005 by Travis Oliphant and\n(mainly) Paul Dubois.\n\"\"\"\nimport string, types, sys\n\nimport umath\nimport oldnumeric\nfrom numeric import e, pi, newaxis, ndarray, inf\nfrom oldnumeric import typecodes, amax, amin\nfrom numerictypes import *\nimport numeric\n\n \nMaskType=bool_\ndivide_tolerance = 1.e-35\n\nclass MAError (Exception):\n def __init__ (self, args=None):\n \"Create an exception\"\n self.args = args\n def __str__(self):\n \"Calculate the string representation\"\n return str(self.args)\n __repr__ = __str__\n\nclass _MaskedPrintOption:\n \"One instance of this class, masked_print_option, is created.\"\n def __init__ (self, display):\n \"Create the masked print option object.\"\n self.set_display(display)\n self._enabled = 1\n\n def display (self):\n \"Show what prints for masked values.\"\n return self._display\n\n def set_display (self, s):\n \"set_display(s) sets what prints for masked values.\"\n self._display = s\n\n def enabled (self):\n \"Is the use of the display value enabled?\"\n return self._enabled\n\n def enable(self, flag=1):\n \"Set the enabling flag to flag.\"\n self._enabled = flag\n\n def __str__ (self):\n return str(self._display)\n\n __repr__ = __str__\n \n#if you single index into a masked location you get this object.\nmasked_print_option = _MaskedPrintOption('--')\n\n# Use single element arrays or scalars.\ndefault_real_fill_value = 1.e20\ndefault_complex_fill_value = 1.e20 + 0.0j\ndefault_character_fill_value = '-'\ndefault_integer_fill_value = 999999\ndefault_object_fill_value = '?'\n\ndef default_fill_value (obj):\n \"Function to calculate default fill value for an object.\"\n if isinstance(obj, types.FloatType):\n return default_real_fill_value\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return default_integer_fill_value\n elif isinstance(obj, types.StringType):\n return default_character_fill_value\n elif isinstance(obj, types.ComplexType):\n return default_complex_fill_value\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return default_real_fill_value\n if x in typecodes['Integer']:\n return default_integer_fill_value\n if x in typecodes['Complex']:\n return default_complex_fill_value\n if x in typecodes['Character']:\n return default_character_fill_value\n if x in typecodes['UnsignedInteger']:\n return umath.absolute(default_integer_fill_value)\n return default_object_fill_value\n else:\n return default_object_fill_value\n\ndef minimum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking minima.\"\n if isinstance(obj, types.FloatType):\n return numeric.inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return numeric.inf\n if x in typecodes['Integer']:\n return sys.maxint\n if x in typecodes['UnsignedInteger']:\n return sys.maxint\n else:\n raise TypeError, 'Unsuitable type for calculating minimum.'\n\ndef maximum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking maxima.\"\n if isinstance(obj, types.FloatType):\n return -inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return -sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return -inf\n if x in typecodes['Integer']:\n return -sys.maxint\n if x in typecodes['UnsignedInteger']:\n return 0\n else:\n raise TypeError, 'Unsuitable type for calculating maximum.'\n\ndef set_fill_value (a, fill_value):\n \"Set fill value of a if it is a masked array.\"\n if isMaskedArray(a):\n a.set_fill_value (fill_value)\n\ndef getmask (a):\n \"\"\"Mask of values in a; could be None.\n Returns None if a is not a masked array.\n To get an array for sure use getmaskarray.\"\"\"\n if isinstance(a, MaskedArray):\n return a.raw_mask()\n else:\n return None\n\ndef getmaskarray (a):\n \"\"\"Mask of values in a; an array of zeros if mask is None\n or not a masked array, and is a byte-sized integer.\n Do not try to add up entries, for example.\n \"\"\"\n m = getmask(a)\n if m is None:\n return make_mask_none(shape(a))\n else:\n return m\n\ndef is_mask (m):\n \"\"\"Is m a legal mask? Does not check contents, only type.\n \"\"\"\n if m is None or (isinstance(m, ndarray) and \\\n m.dtype is MaskType):\n return 1\n else:\n return 0\n\ndef make_mask (m, copy=0, flag=0):\n \"\"\"make_mask(m, copy=0, flag=0)\n return m as a mask, creating a copy if necessary or requested.\n Can accept any sequence of integers or None. Does not check\n that contents must be 0s and 1s.\n if flag, return None if m contains no true elements.\n \"\"\"\n if m is None:\n return None\n elif isinstance(m, ndarray):\n if m.dtype is MaskType:\n if copy:\n result = numeric.array(m, dtype=MaskType, copy=copy)\n else:\n result = m\n else:\n result = m.astype(MaskType)\n else:\n result = filled(m,True).astype(MaskType)\n\n if flag and not oldnumeric.sometrue(oldnumeric.ravel(result)):\n return None\n else:\n return result\n\ndef make_mask_none (s):\n \"Return a mask of all zeros of shape s.\"\n result = numeric.zeros(s, dtype=MaskType)\n result.shape = s\n return result\n\ndef mask_or (m1, m2):\n \"\"\"Logical or of the mask candidates m1 and m2, treating None as false.\n Result may equal m1 or m2 if the other is None.\n \"\"\"\n if m1 is None: return make_mask(m2)\n if m2 is None: return make_mask(m1)\n if m1 is m2 and is_mask(m1): return m1\n return make_mask(umath.logical_or(m1, m2))\n\ndef filled (a, value = None):\n \"\"\"a as a contiguous numeric array with any masked areas replaced by value\n if value is None or the special element \"masked\", get_fill_value(a)\n is used instead.\n\n If a is already a contiguous numeric array, a itself is returned.\n\n filled(a) can be used to be sure that the result is numeric when\n passing an object a to other software ignorant of MA, in particular to\n numeric itself.\n \"\"\"\n if isinstance(a, MaskedArray):\n return a.filled(value)\n elif isinstance(a, ndarray) and a.flags['CONTIGUOUS']:\n return a\n elif isinstance(a, types.DictType):\n return numeric.array(a, 'O')\n else:\n return numeric.array(a)\n\ndef get_fill_value (a):\n \"\"\"\n The fill value of a, if it has one; otherwise, the default fill value\n for that type.\n \"\"\"\n if isMaskedArray(a):\n result = a.fill_value()\n else:\n result = default_fill_value(a)\n return result\n\ndef common_fill_value (a, b):\n \"The common fill_value of a and b, if there is one, or None\"\n t1 = get_fill_value(a)\n t2 = get_fill_value(b)\n if t1 == t2: return t1\n return None\n\n# Domain functions return 1 where the argument(s) are not in the domain.\nclass domain_check_interval:\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n def __init__(self, y1, y2):\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n self.y1 = y1\n self.y2 = y2\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.logical_or(umath.greater (x, self.y2),\n umath.less(x, self.y1)\n )\n\nclass domain_tan:\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n def __init__(self, eps):\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n self.eps = eps\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less(umath.absolute(umath.cos(x)), self.eps)\n\nclass domain_greater:\n \"domain_greater(v)(x) = true where x <= v\"\n def __init__(self, critical_value):\n \"domain_greater(v)(x) = true where x <= v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less_equal (x, self.critical_value)\n\nclass domain_greater_equal:\n \"domain_greater_equal(v)(x) = true where x < v\"\n def __init__(self, critical_value):\n \"domain_greater_equal(v)(x) = true where x < v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less (x, self.critical_value)\n\nclass masked_unary_operation:\n def __init__ (self, aufunc, fill=0, domain=None):\n \"\"\" masked_unary_operation(aufunc, fill=0, domain=None)\n aufunc(fill) must be defined\n self(x) returns aufunc(x)\n with masked values where domain(x) is true or getmask(x) is true.\n \"\"\"\n self.f = aufunc\n self.fill = fill\n self.domain = domain\n self.__doc__ = getattr(aufunc, \"__doc__\", str(aufunc))\n\n def __call__ (self, a, *args, **kwargs):\n \"Execute the call behavior.\"\n# numeric tries to return scalars rather than arrays when given scalars.\n m = getmask(a)\n d1 = filled(a, self.fill)\n if self.domain is not None:\n m = mask_or(m, self.domain(d1))\n result = self.f(d1, *args, **kwargs)\n if m is not None:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\n\nclass domain_safe_divide:\n def __init__ (self, tolerance=divide_tolerance):\n self.tolerance = tolerance\n def __call__ (self, a, b):\n return umath.absolute(a) * self.tolerance >= umath.absolute(b)\n\nclass domained_binary_operation:\n \"\"\"Binary operations that have a domain, like divide. These are complicated so they\n are a separate class. They have no reduce, outer or accumulate.\n \"\"\"\n def __init__ (self, abfunc, domain, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.domain = domain\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__(self, a, b):\n \"Execute the call behavior.\"\n ma = getmask(a)\n mb = getmask(b)\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n t = self.domain(d1, d2)\n\n if oldnumeric.sometrue(t, None):\n d2 = where(t, self.filly, d2)\n mb = mask_or(mb, t)\n m = mask_or(ma, mb)\n result = self.f(d1, d2)\n if m is not None:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n \n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nclass masked_binary_operation:\n def __init__ (self, abfunc, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__ (self, a, b, *args, **kwargs):\n \"Execute the call behavior.\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n result = self.f(d1, d2, *args, **kwargs)\n if m is not None:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis with this function.\"\"\"\n m = getmask(target)\n t = filled(target, self.filly)\n if t.shape == ():\n t = t.reshape(1)\n if m is not None:\n m = make_mask(m, copy=1)\n m.shape = (1,)\n if m is None:\n return masked_array (self.f.reduce (t, axis))\n else:\n t = masked_array (t, m)\n t = self.f.reduce(filled(t, self.filly), axis)\n m = umath.logical_and.reduce(m, axis)\n if isinstance(t, ndarray):\n return masked_array(t, m, get_fill_value(target))\n elif m:\n return masked\n else:\n return t\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n m = None\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = self.f.outer(filled(a, self.fillx), filled(b, self.filly))\n return masked_array(d, m)\n\n def accumulate (self, target, axis=0):\n \"\"\"Accumulate target along axis after filling with y fill value.\"\"\"\n t = filled(target, self.filly)\n return masked_array (self.f.accumulate (t, axis))\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nsqrt = masked_unary_operation(umath.sqrt, 0.0, domain_greater_equal(0.0))\nlog = masked_unary_operation(umath.log, 1.0, domain_greater(0.0))\nlog10 = masked_unary_operation(umath.log10, 1.0, domain_greater(0.0))\nexp = masked_unary_operation(umath.exp)\nconjugate = masked_unary_operation(umath.conjugate)\nsin = masked_unary_operation(umath.sin)\ncos = masked_unary_operation(umath.cos)\ntan = masked_unary_operation(umath.tan, 0.0, domain_tan(1.e-35))\narcsin = masked_unary_operation(umath.arcsin, 0.0, domain_check_interval(-1.0, 1.0))\narccos = masked_unary_operation(umath.arccos, 0.0, domain_check_interval(-1.0, 1.0))\narctan = masked_unary_operation(umath.arctan)\n# Missing from numeric\narcsinh = masked_unary_operation(umath.arcsinh)\narccosh = masked_unary_operation(umath.arccosh)\narctanh = masked_unary_operation(umath.arctanh)\nsinh = masked_unary_operation(umath.sinh)\ncosh = masked_unary_operation(umath.cosh)\ntanh = masked_unary_operation(umath.tanh)\nabsolute = masked_unary_operation(umath.absolute)\nfabs = masked_unary_operation(umath.fabs)\nnegative = masked_unary_operation(umath.negative)\nnonzero = masked_unary_operation(oldnumeric.nonzero)\naround = masked_unary_operation(oldnumeric.round_)\nfloor = masked_unary_operation(umath.floor)\nceil = masked_unary_operation(umath.ceil)\nsometrue = masked_unary_operation(oldnumeric.sometrue)\nalltrue = masked_unary_operation(oldnumeric.alltrue, 1)\nlogical_not = masked_unary_operation(umath.logical_not)\n\nadd = masked_binary_operation(umath.add)\nsubtract = masked_binary_operation(umath.subtract)\nsubtract.reduce = None\nmultiply = masked_binary_operation(umath.multiply, 1, 1)\ndivide = domained_binary_operation(umath.divide, domain_safe_divide(), 0, 1)\ntrue_divide = domained_binary_operation(umath.true_divide, domain_safe_divide(), 0, 1)\nfloor_divide = domained_binary_operation(umath.floor_divide, domain_safe_divide(), 0, 1)\nremainder = domained_binary_operation(umath.remainder, domain_safe_divide(), 0, 1)\nfmod = domained_binary_operation(umath.fmod, domain_safe_divide(), 0, 1)\nhypot = masked_binary_operation(umath.hypot)\narctan2 = masked_binary_operation(umath.arctan2, 0.0, 1.0)\narctan2.reduce = None\nequal = masked_binary_operation(umath.equal)\nequal.reduce = None\nnot_equal = masked_binary_operation(umath.not_equal)\nnot_equal.reduce = None\nless_equal = masked_binary_operation(umath.less_equal)\nless_equal.reduce = None\ngreater_equal = masked_binary_operation(umath.greater_equal)\ngreater_equal.reduce = None\nless = masked_binary_operation(umath.less)\nless.reduce = None\ngreater = masked_binary_operation(umath.greater)\ngreater.reduce = None\nlogical_and = masked_binary_operation(umath.logical_and)\nlogical_or = masked_binary_operation(umath.logical_or)\nlogical_xor = masked_binary_operation(umath.logical_xor)\nbitwise_and = masked_binary_operation(umath.bitwise_and)\nbitwise_or = masked_binary_operation(umath.bitwise_or)\nbitwise_xor = masked_binary_operation(umath.bitwise_xor)\n\ndef rank (object):\n return oldnumeric.rank(filled(object))\n\ndef shape (object):\n return oldnumeric.shape(filled(object))\n\ndef size (object, axis=None):\n return oldnumeric.size(filled(object), axis)\n\nclass MaskedArray (object):\n \"\"\"Arrays with possibly masked values.\n Masked values of 1 exclude the corresponding element from \n any computation.\n\n Construction:\n x = array(data, dtype=None, copy=True, fortran=False,\n mask = None, fill_value=None)\n\n If copy=False, every effort is made not to copy the data:\n If data is a MaskedArray, and argument mask=None,\n then the candidate data is data.data and the\n mask used is data.mask. If data is a numeric array,\n it is used as the candidate raw data.\n If dtypechar is not None and\n is != data.dtypechar then a data copy is required.\n Otherwise, the candidate is used.\n\n If a data copy is required, raw data stored is the result of:\n numeric.array(data, dtype=dtypechar, copy=copy)\n\n If mask is None there are no masked values. Otherwise mask must\n be convertible to an array of booleans with the same shape as x.\n\n fill_value is used to fill in masked values when necessary,\n such as when printing and in method/function filled().\n The fill_value is not used for computation within this module.\n \"\"\"\n __array_priority__ = 10.1\n def __init__(self, data, dtype=None, copy=True, fortran=False, \n mask=None, fill_value=None):\n \"\"\"array(data, dtype=None, copy=True, fortran=False, mask=None, fill_value=None)\n If data already a numeric array, its dtype becomes the default value of dtype.\n \"\"\"\n tc = dtype\n need_data_copied = copy\n if isinstance(data, MaskedArray):\n c = data.data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n if mask is None:\n mask = data.mask\n elif mask is not None: #attempting to change the mask\n need_data_copied = True\n\n elif isinstance(data, ndarray):\n c = data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n else:\n need_data_copied = False #because I'll do it now\n c = numeric.array(data, dtype=tc, copy=True, fortran=fortran)\n\n if need_data_copied:\n if tc == ctc:\n self._data = numeric.array(c, dtype=tc, copy=True, fortran=fortran)\n else:\n self._data = c.astype(tc)\n else:\n self._data = c\n\n if mask is None:\n self._mask = None\n self._shared_mask = 0\n else:\n self._mask = make_mask (mask)\n if self._mask is None:\n self._shared_mask = 0\n else:\n self._shared_mask = (self._mask is mask)\n nm = size(self._mask)\n nd = size(self._data)\n if nm != nd:\n if nm == 1:\n self._mask = oldnumeric.resize(self._mask, self._data.shape)\n self._shared_mask = 0\n elif nd == 1:\n self._data = oldnumeric.resize(self._data, self._mask.shape)\n self._data.shape = self._mask.shape\n else:\n raise MAError, \"Mask and data not compatible.\"\n elif nm == 1 and shape(self._mask) != shape(self._data):\n self.unshare_mask()\n self._mask.shape = self._data.shape\n\n self.set_fill_value(fill_value)\n\n def __array__ (self, t = None):\n \"Special hook for numeric. Converts to numeric if possible.\"\n if self._mask is not None:\n if oldnumeric.ravel(self._mask).any():\n raise MAError, \\\n \"\"\"Cannot automatically convert masked array to numeric because data\n is masked in one or more locations.\n \"\"\"\n else: # Mask is all false\n # Optimize to avoid future invocations of this section.\n self._mask = None\n self._shared_mask = 0\n if t:\n return self._data.astype(t)\n else:\n return self._data\n\n def __array_wrap__ (self, array):\n \"\"\"Special hook for ufuncs. Converts to Masked array with\n the same mask as self.\"\"\"\n return MaskedArray(array, copy=False, mask=self._mask,\n fill_value = self._fill_value)\n \n def _get_shape(self):\n \"Return the current shape.\"\n return self._data.shape\n\n def _set_shape (self, newshape):\n \"Set the array's shape.\"\n self._data.shape = newshape\n if self._mask is not None:\n self._mask = self._mask.copy()\n self._mask.shape = newshape\n\n def _get_flat(self):\n \"\"\"Calculate the flat value.\n \"\"\"\n if self._mask is None:\n return masked_array(self._data.ravel(), mask=None,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.ravel(),\n mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_flat (self, value):\n \"x.flat = value\"\n y = self.ravel()\n y[:] = value\n\n def _get_real(self):\n \"Get the real part of a complex array.\"\n if self._mask is None:\n return masked_array(self._data.real, mask=None,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.real, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_real (self, value):\n \"x.real = value\"\n y = self.real\n y[...] = value\n\n def _get_imaginary(self):\n \"Get the imaginary part of a complex array.\"\n if self._mask is None:\n return masked_array(self._data.imag, mask=None,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.imag, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_imaginary (self, value):\n \"x.imaginary = value\"\n y = self.imaginary\n y[...] = value\n\n def __str__(self):\n \"\"\"Calculate the str representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n if masked_print_option.enabled():\n f = masked_print_option\n # XXX: Without the following special case masked\n # XXX: would print as \"[--]\", not \"--\". Can we avoid\n # XXX: checks for masked by choosing a different value\n # XXX: for the masked singleton? 2005-01-05 -- sasha\n if self is masked:\n return str(f)\n # convert to object array to make filled work\n self = self.astype(object)\n else:\n f = self.fill_value()\n res = self.filled(f)\n return str(res)\n\n def __repr__(self):\n \"\"\"Calculate the repr representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n with_mask = \"\"\"\\\narray(data =\n %(data)s,\n mask =\n %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n with_mask1 = \"\"\"\\\narray(data = %(data)s,\n mask = %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n without_mask = \"\"\"array(\n %(data)s)\"\"\"\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n\n n = len(self.shape)\n if self._mask is None:\n if n <=1:\n return without_mask1 % {'data':str(self.filled())}\n return without_mask % {'data':str(self.filled())}\n else:\n if n <=1:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n if self._mask is None:\n return without_mask % {'data':str(self.filled())}\n else:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n\n def __float__(self):\n \"Convert self to float.\"\n self.unmask()\n if self._mask is not None:\n raise MAError, 'Cannot convert masked element to a Python float.'\n return float(self.data.item())\n\n def __int__(self):\n \"Convert self to int.\"\n self.unmask()\n if self._mask is not None:\n raise MAError, 'Cannot convert masked element to a Python int.'\n return int(self.data.item())\n\n def __getitem__(self, i):\n \"Get item described by i. Not a copy as in previous versions.\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i]\n if m is None:\n return dout\n mi = m[i]\n if mi.size == 1:\n if mi: \n return masked\n else:\n return dout\n else:\n return masked_array(dout, mi, fill_value=self._fill_value)\n\n def __getslice__(self, i, j):\n \"Get slice described by i, j\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i:j]\n if m is None:\n return masked_array(dout, fill_value=self._fill_value)\n else:\n return masked_array(dout, mask = m[i:j], fill_value=self._fill_value)\n\n# --------\n# setitem and setslice notes\n# note that if value is masked, it means to mask those locations.\n# setting a value changes the mask to match the value in those locations.\n\n def __setitem__(self, index, value):\n \"Set item described by index. If value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, 'Cannot alter the masked element.'\n if value is masked:\n if self._mask is None:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n else:\n self.unshare_mask()\n self._mask[index] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[index] = value\n if m is None:\n if self._mask is not None:\n self.unshare_mask()\n self._mask[index] = False\n else:\n if self._mask is None:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = True\n else:\n self.unshare_mask()\n self._mask[index] = m\n\n def __setslice__(self, i, j, value):\n \"Set slice i:j; if value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, \"Cannot alter the 'masked' object.\"\n if value is masked:\n if self._mask is None:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n self._mask[i:j] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[i:j] = value\n if m is None:\n if self._mask is not None:\n self.unshare_mask()\n self._mask[i:j] = False\n else:\n if self._mask is None:\n self._mask = make_mask_none(self._data.shape)\n self._shared_mask = False\n self._mask[i:j] = m\n\n def __nonzero__(self):\n \"\"\"returns true if any element is non-zero or masked\n\n \"\"\"\n # XXX: This changes bool conversion logic from MA.\n # XXX: In MA bool(a) == len(a) != 0, but in numpy\n # XXX: scalars do not have len \n m = self._mask\n d = self._data\n return bool(m is not None and m.any()\n or d is not None and d.any())\n \n def __len__ (self):\n \"\"\"Return length of first dimension. This is weird but Python's\n slicing behavior depends on it.\"\"\"\n return len(self._data)\n\n def __and__(self, other):\n \"Return bitwise_and\"\n return bitwise_and(self, other)\n\n def __or__(self, other):\n \"Return bitwise_or\"\n return bitwise_or(self, other)\n\n def __xor__(self, other):\n \"Return bitwise_xor\"\n return bitwise_xor(self, other)\n\n __rand__ = __and__\n __ror__ = __or__\n __rxor__ = __xor__\n\n def __abs__(self):\n \"Return absolute(self)\"\n return absolute(self)\n\n def __neg__(self):\n \"Return negative(self)\"\n return negative(self)\n\n def __pos__(self):\n \"Return array(self)\"\n return array(self)\n\n def __add__(self, other):\n \"Return add(self, other)\"\n return add(self, other)\n\n __radd__ = __add__\n\n def __mod__ (self, other):\n \"Return remainder(self, other)\"\n return remainder(self, other)\n\n def __rmod__ (self, other):\n \"Return remainder(other, self)\"\n return remainder(other, self)\n\n def __lshift__ (self, n):\n return left_shift(self, n)\n\n def __rshift__ (self, n):\n return right_shift(self, n)\n\n def __sub__(self, other):\n \"Return subtract(self, other)\"\n return subtract(self, other)\n\n def __rsub__(self, other):\n \"Return subtract(other, self)\"\n return subtract(other, self)\n\n def __mul__(self, other):\n \"Return multiply(self, other)\"\n return multiply(self, other)\n\n __rmul__ = __mul__\n\n def __div__(self, other):\n \"Return divide(self, other)\"\n return divide(self, other)\n\n def __rdiv__(self, other):\n \"Return divide(other, self)\"\n return divide(other, self)\n\n def __truediv__(self, other):\n \"Return divide(self, other)\"\n return true_divide(self, other)\n\n def __rtruediv__(self, other):\n \"Return divide(other, self)\"\n return true_divide(other, self)\n\n def __floordiv__(self, other):\n \"Return divide(self, other)\"\n return floor_divide(self, other)\n\n def __rfloordiv__(self, other):\n \"Return divide(other, self)\"\n return floor_divide(other, self)\n\n def __pow__(self,other, third=None):\n \"Return power(self, other, third)\"\n return power(self, other, third)\n\n def __sqrt__(self):\n \"Return sqrt(self)\"\n return sqrt(self)\n\n def __iadd__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is None:\n self._data += f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not None\n else:\n result = add(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __imul__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is None:\n self._data *= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not None\n else:\n result = multiply(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __isub__(self, other):\n \"Subtract other from self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is None:\n self._data -= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not None\n else:\n result = subtract(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n\n\n def __idiv__(self, other):\n \"Divide self by other in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n mo = getmask(other)\n result = divide(self, masked_array(f, mask=mo))\n self._data = result.data\n dm = result.raw_mask()\n if dm is not self._mask:\n self._mask = dm\n self._shared_mask = 1\n return self\n\n def __eq__(self,other):\n return equal(self,other)\n\n def __ne__(self,other):\n return not_equal(self,other)\n\n def __lt__(self,other):\n return less(self,other)\n\n def __le__(self,other):\n return less_equal(self,other)\n\n def __gt__(self,other):\n return greater(self,other)\n\n def __ge__(self,other):\n return greater_equal(self,other)\n\n def astype (self, tc):\n \"return self as array of given type.\"\n d = self._data.astype(tc)\n return array(d, mask=self._mask)\n\n def byte_swapped(self):\n \"\"\"Returns the raw data field, byte_swapped. Included for consistency\n with numeric but doesn't make sense in this context.\n \"\"\"\n return self._data.byte_swapped()\n\n def compressed (self):\n \"A 1-D array of all the non-masked data.\"\n d = oldnumeric.ravel(self._data)\n if self._mask is None:\n return array(d)\n else:\n m = 1 - oldnumeric.ravel(self._mask)\n c = oldnumeric.compress(m, d)\n return array(c, copy=0)\n\n def count (self, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n m = self._mask\n s = self._data.shape\n ls = len(s)\n if m is None:\n if ls == 0:\n return 1\n if ls == 1:\n return s[0]\n if axis is None:\n return reduce(lambda x,y:x*y, s)\n else:\n n = s[axis]\n t = list(s)\n del t[axis]\n return ones(t) * n\n if axis is None:\n w = oldnumeric.ravel(m).astype(int) \n n1 = size(w)\n if n1 == 1:\n n2 = w[0]\n else:\n n2 = umath.add.reduce(w)\n return n1 - n2\n else:\n n1 = size(m, axis)\n n2 = sum(m.astype(int), axis)\n return n1 - n2\n\n def dot (self, other):\n \"s.dot(other) = innerproduct(s, other)\"\n return innerproduct(self, other)\n\n def fill_value(self):\n \"Get the current fill value.\"\n return self._fill_value\n\n def filled (self, fill_value=None):\n \"\"\"A numeric array with masked values filled. If fill_value is None,\n use self.fill_value().\n\n If mask is None, copy data only if not contiguous.\n Result is always a contiguous, numeric array.\n# Is contiguous really necessary now?\n \"\"\"\n d = self._data\n m = self._mask\n if m is None:\n if d.flags['CONTIGUOUS']:\n return d\n else:\n return d.copy()\n else:\n if fill_value is None:\n value = self._fill_value\n else:\n value = fill_value\n\n if self is masked:\n result = numeric.array(value).reshape(*d.shape)\n else:\n try:\n result = numeric.array(d, dtype=d.dtype, copy=1)\n result[m] = value\n except (TypeError, AttributeError):\n #ok, can't put that value in here\n value = numeric.array(value, dtype=object)\n d = d.astype(object)\n result = oldnumeric.choose(m, (d, value))\n except IndexError:\n #ok, if scalar\n if d.shape:\n raise\n elif m:\n result = numeric.array(value, dtype=d.dtype)\n else:\n result = d\n return result\n\n def ids (self):\n \"\"\"Return the ids of the data and mask areas\"\"\"\n return (id(self._data), id(self._mask))\n\n def iscontiguous (self):\n \"Is the data contiguous?\"\n return self._data.flags['CONTIGUOUS']\n\n def itemsize(self):\n \"Item size of each data item.\"\n return self._data.itemsize\n\n\n def outer(self, other):\n \"s.outer(other) = outerproduct(s, other)\"\n return outerproduct(self, other)\n\n def put (self, values):\n \"\"\"Set the non-masked entries of self to filled(values).\n No change to mask\n \"\"\"\n iota = numeric.arange(self.size)\n d = self._data\n if self._mask is None:\n ind = iota\n else:\n ind = oldnumeric.compress(1 - self._mask, iota)\n d[ind] = filled(values).astype(d.dtype)\n\n def putmask (self, values):\n \"\"\"Set the masked entries of self to filled(values).\n Mask changed to None.\n \"\"\"\n d = self._data\n if self._mask is not None:\n d[self._mask] = filled(values).astype(d.dtype)\n self._shared_mask = 0\n self._mask = None\n\n def ravel (self):\n \"\"\"Return a 1-D view of self.\"\"\"\n if self._mask is None:\n return masked_array(self._data.ravel())\n else:\n return masked_array(self._data.ravel(), self._mask.ravel())\n\n def raw_data (self):\n \"\"\" Obsolete; use data property instead.\n The raw data; portions may be meaningless.\n May be noncontiguous. Expert use only.\"\"\"\n return self._data\n data = property(fget=raw_data, \n doc=\"The data, but values at masked locations are meaningless.\")\n\n def raw_mask (self):\n \"\"\" Obsolete; use mask property instead.\n May be noncontiguous. Expert use only.\n \"\"\"\n return self._mask\n mask = property(fget=raw_mask, \n doc=\"The mask, may be None. Values where mask true are meaningless.\")\n\n def reshape (self, *s):\n \"\"\"This array reshaped to shape s\"\"\"\n d = self._data.reshape(*s)\n if self._mask is None:\n return masked_array(d)\n else:\n m = self._mask.reshape(*s)\n return masked_array(d, m)\n\n def set_fill_value (self, v=None):\n \"Set the fill value to v. Omit v to restore default.\"\n if v is None:\n v = default_fill_value (self.raw_data())\n self._fill_value = v\n\n def _get_size (self):\n return self._data.size\n size = property(fget=_get_size, doc=\"Number of elements in the array.\")\n## CHECK THIS: signature of numeric.array.size?\n \n def _get_dtypechar(self):\n return self._data.dtypechar\n dtypechar = property(fget=_get_dtypechar, doc=\"type character of the array.\")\n\n def _get_dtype(self):\n return self._data.dtype\n dtype = property(fget=_get_dtype, doc=\"type of the array elements.\")\n\n def item(self):\n \"Return Python scalar if possible.\"\n if self._mask is not None:\n m = oldnumeric.ravel(self._mask)\n try:\n if m[0]:\n return masked\n except IndexError:\n return masked\n return self._data.item()\n\n def tolist(self, fill_value=None):\n \"Convert to list\"\n return self.filled(fill_value).tolist()\n\n def tostring(self, fill_value=None):\n \"Convert to string\"\n return self.filled(fill_value).tostring()\n\n def unmask (self):\n \"Replace the mask by None if possible.\"\n if self._mask is None: return\n m = make_mask(self._mask, flag=1)\n if m is None:\n self._mask = None\n self._shared_mask = 0\n\n def unshare_mask (self):\n \"If currently sharing mask, make a copy.\"\n if self._shared_mask:\n self._mask = make_mask (self._mask, copy=1, flag=0)\n self._shared_mask = 0\n\n shape = property(_get_shape, _set_shape,\n doc = 'tuple giving the shape of the array')\n\n flat = property(_get_flat, _set_flat,\n doc = 'Access array in flat form.')\n\n real = property(_get_real, _set_real,\n doc = 'Access the real part of the array')\n\n imaginary = property(_get_imaginary, _set_imaginary,\n doc = 'Access the imaginary part of the array')\n\n imag = imaginary\n\n#end class MaskedArray\n\narray = MaskedArray\n\ndef isMaskedArray (x):\n \"Is x a masked array, that is, an instance of MaskedArray?\"\n return isinstance(x, MaskedArray)\n\nisarray = isMaskedArray\nisMA = isMaskedArray #backward compatibility\n\ndef allclose (a, b, fill_value=1, rtol=1.e-5, atol=1.e-8):\n \"\"\" Returns true if all components of a and b are equal\n subject to given tolerances.\n If fill_value is 1, masked values considered equal.\n If fill_value is 0, masked values considered unequal.\n The relative error rtol should be positive and << 1.0\n The absolute error atol comes into play for those elements\n of b that are very small or zero; it says how small a must be also.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a)\n d2 = filled(b)\n x = filled(array(d1, copy=0, mask=m), fill_value).astype(float)\n y = filled(array(d2, copy=0, mask=m), 1).astype(float)\n d = umath.less_equal(umath.absolute(x-y), atol + rtol * umath.absolute(y))\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n\ndef allequal (a, b, fill_value=1):\n \"\"\"\n True if all entries of a and b are equal, using\n fill_value as a truth value where either or both are masked.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n if m is None:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n elif fill_value:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n dm = array(d, mask=m, copy=0)\n return oldnumeric.alltrue(oldnumeric.ravel(filled(dm, 1)))\n else:\n return 0\n\ndef masked_values (data, value, rtol=1.e-5, atol=1.e-8, copy=1):\n \"\"\"\n masked_values(data, value, rtol=1.e-5, atol=1.e-8)\n Create a masked array; mask is None if possible.\n If copy==0, and otherwise possible, result\n may share data values with original array.\n Let d = filled(data, value). Returns d\n masked where abs(data-value)<= atol + rtol * abs(value)\n if d is of a floating point type. Otherwise returns\n masked_object(d, value, copy)\n \"\"\"\n abs = umath.absolute\n d = filled(data, value)\n if issubclass(d.dtype, numeric.floating):\n m = umath.less_equal(abs(d-value), atol+rtol*abs(value))\n m = make_mask(m, flag=1)\n return array(d, mask = m, copy=copy,\n fill_value=value)\n else:\n return masked_object(d, value, copy=copy)\n\ndef masked_object (data, value, copy=1):\n \"Create array masked where exactly data equal to value\"\n d = filled(data, value)\n dm = make_mask(umath.equal(d, value), flag=1)\n return array(d, mask=dm, copy=copy, fill_value=value)\n\ndef arrayrange(start, stop=None, step=1, dtype=None):\n \"\"\"Just like range() except it returns a array whose type can be specified\n by the keyword argument dtypechar.\n \"\"\"\n return array(numeric.arrayrange(start, stop, step, dtype))\n\narange = arrayrange\n\ndef fromstring (s, t):\n \"Construct a masked array from a string. Result will have no mask.\"\n return masked_array(numeric.fromstring(s, t))\n\ndef left_shift (a, n):\n \"Left shift n bits\"\n m = getmask(a)\n if m is None:\n d = umath.left_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.left_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef right_shift (a, n):\n \"Right shift n bits\"\n m = getmask(a)\n if m is None:\n d = umath.right_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.right_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef resize (a, new_shape):\n \"\"\"resize(a, new_shape) returns a new array with the specified shape.\n The original array's total size can be any size.\"\"\"\n m = getmask(a)\n if m is not None:\n m = oldnumeric.resize(m, new_shape)\n result = array(oldnumeric.resize(filled(a), new_shape), mask=m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n \"\"\"\n af = filled(a)\n if isinstance(repeats, types.IntType):\n repeats = tuple([repeats]*(shape(af)[axis]))\n\n m = getmask(a)\n if m is not None:\n m = oldnumeric.repeat(m, repeats, axis)\n d = oldnumeric.repeat(af, repeats, axis)\n result = masked_array(d, m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef identity(n):\n \"\"\"identity(n) returns the identity matrix of shape n x n.\n \"\"\"\n return array(numeric.identity(n))\n\ndef indices (dimensions, dtype=None):\n \"\"\"indices(dimensions,dtype=None) returns an array representing a grid\n of indices with row-only, and column-only variation.\n \"\"\"\n return array(numeric.indices(dimensions, dtype))\n\ndef zeros (shape, dtype=int):\n \"\"\"zeros(n, dtype=int) =\n an array of all zeros of the given length or shape.\"\"\"\n return array(numeric.zeros(shape, dtype))\n\ndef ones (shape, dtype=int):\n \"\"\"ones(n, dtype=int) =\n an array of all ones of the given length or shape.\"\"\"\n return array(numeric.ones(shape, dtype))\n\n\ndef count (a, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n a = masked_array(a)\n return a.count(axis)\n\ndef power (a, b, third=None):\n \"a**b\"\n if third is not None:\n raise MAError, \"3-argument power not supported.\"\n ma = getmask(a)\n mb = getmask(b)\n m = mask_or(ma, mb)\n fa = filled(a, 1)\n fb = filled(b, 1)\n if fb.dtypechar in typecodes[\"Integer\"]:\n return masked_array(umath.power(fa, fb), m)\n md = make_mask(umath.less_equal (fa, 0), flag=1)\n m = mask_or(m, md)\n if m is None:\n return masked_array(umath.power(fa, fb))\n else:\n fa = numeric.where(m, 1, fa)\n return masked_array(umath.power(fa, fb), m)\n\ndef masked_array (a, mask=None, fill_value=None):\n \"\"\"masked_array(a, mask=None) =\n array(a, mask=mask, copy=0, fill_value=fill_value)\n \"\"\"\n return array(a, mask=mask, copy=0, fill_value=fill_value)\n\nsum = add.reduce\nproduct = multiply.reduce\n\ndef average (a, axis=0, weights=None, returned = 0):\n \"\"\"average(a, axis=0, weights=None)\n Computes average along indicated axis.\n If axis is None, average over the entire array\n Inputs can be integer or floating types; result is of type float.\n\n If weights are given, result is sum(a*weights)/(sum(weights)*1.0)\n weights must have a's shape or be the 1-d with length the size\n of a in the given axis.\n\n If returned, return a tuple: the result and the sum of the weights\n or count of values. Results will have the same shape.\n\n masked values in the weights will be set to 0.0\n \"\"\"\n a = masked_array(a)\n mask = a.mask\n ash = a.shape\n if ash == ():\n ash = (1,)\n if axis is None:\n if mask is None:\n if weights is None:\n n = add.reduce(a.raw_data().ravel())\n d = reduce(lambda x, y: x * y, ash, 1.0)\n else:\n w = filled(weights, 0.0).ravel()\n n = umath.add.reduce(a.raw_data().ravel() * w)\n d = umath.add.reduce(w)\n del w\n else:\n if weights is None:\n n = add.reduce(a.ravel())\n w = oldnumeric.choose(mask, (1.0,0.0)).ravel()\n d = umath.add.reduce(w)\n del w\n else:\n w = array(filled(weights, 0.0), float, mask=mask).ravel()\n n = add.reduce(a.ravel() * w)\n d = add.reduce(w)\n del w\n else:\n if mask is None:\n if weights is None:\n d = ash[axis] * 1.0\n n = umath.add.reduce(a.raw_data(), axis)\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = numeric.array(w, float, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * ones(ash, float)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w, r\n else:\n raise ValueError, 'average: weights wrong shape.'\n else:\n if weights is None:\n n = add.reduce(a, axis)\n w = numeric.choose(mask, (1.0, 0.0))\n d = umath.add.reduce(w, axis)\n del w\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = array(w, float, mask=mask, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * masked_array(ones(ash, float), mask)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n else:\n raise ValueError, 'average: weights wrong shape.'\n del w\n #print n, d, repr(mask), repr(weights)\n if n is masked or d is masked: return masked\n result = divide (n, d)\n del n\n\n if isinstance(result, MaskedArray):\n result.unmask()\n if returned:\n if not isinstance(d, MaskedArray):\n d = masked_array(d)\n if not d.shape == result.shape:\n d = ones(result.shape, float) * d\n d.unmask()\n if returned:\n return result, d\n else:\n return result\n\ndef where (condition, x, y):\n \"\"\"where(condition, x, y) is x where condition is nonzero, y otherwise.\n condition must be convertible to an integer array.\n Answer is always the shape of condition.\n The type depends on x and y. It is integer if both x and y are\n the value masked.\n \"\"\"\n fc = filled(not_equal(condition,0), 0)\n if x is masked:\n xv = 0\n xm = 1\n else:\n xv = filled(x)\n xm = getmask(x)\n if xm is None: xm = 0\n if y is masked:\n yv = 0\n ym = 1\n else:\n yv = filled(y)\n ym = getmask(y)\n if ym is None: ym = 0\n d = numeric.choose(fc, (yv, xv))\n md = numeric.choose(fc, (ym, xm))\n m = getmask(condition)\n m = make_mask(mask_or(m, md), copy=0, flag=1)\n return masked_array(d, m)\n\ndef choose (indices, t):\n \"Returns array shaped like indices with elements chosen from t\"\n def fmask (x):\n if x is masked: return 1\n return filled(x)\n def nmask (x):\n if x is masked: return 1\n m = getmask(x)\n if m is None: return 0\n return m\n c = filled(indices,0)\n masks = [nmask(x) for x in t]\n a = [fmask(x) for x in t]\n d = numeric.choose(c, a)\n m = numeric.choose(c, masks)\n m = make_mask(mask_or(m, getmask(indices)), copy=0, flag=1)\n return masked_array(d, m)\n\ndef masked_where(condition, x, copy=1):\n \"\"\"Return x as an array masked where condition is true.\n Also masked where x or condition masked.\n \"\"\"\n cm = filled(condition,1)\n m = mask_or(getmask(x), cm)\n return array(filled(x), copy=copy, mask=m)\n\ndef masked_greater(x, value, copy=1):\n \"masked_greater(x, value) = x masked where x > value\"\n return masked_where(greater(x, value), x, copy)\n\ndef masked_greater_equal(x, value, copy=1):\n \"masked_greater_equal(x, value) = x masked where x >= value\"\n return masked_where(greater_equal(x, value), x, copy)\n\ndef masked_less(x, value, copy=1):\n \"masked_less(x, value) = x masked where x < value\"\n return masked_where(less(x, value), x, copy)\n\ndef masked_less_equal(x, value, copy=1):\n \"masked_less_equal(x, value) = x masked where x <= value\"\n return masked_where(less_equal(x, value), x, copy)\n\ndef masked_not_equal(x, value, copy=1):\n \"masked_not_equal(x, value) = x masked where x != value\"\n d = filled(x,0)\n c = umath.not_equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_equal(x, value, copy=1):\n \"\"\"masked_equal(x, value) = x masked where x == value\n For floating point consider masked_values(x, value) instead.\n \"\"\"\n d = filled(x,0)\n c = umath.equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_inside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are inside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d=filled(x, 0)\n c = umath.logical_and(umath.less_equal(d, v2), umath.greater_equal(d, v1))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef masked_outside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are outside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d = filled(x,0)\n c = umath.logical_or(umath.less(d, v1), umath.greater(d, v2))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef reshape (a, *newshape):\n \"Copy of a with a new shape.\"\n m = getmask(a)\n d = filled(a).reshape(*newshape)\n if m is None:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.reshape(m, *newshape))\n\ndef ravel (a):\n \"a as one-dimensional, may share data and mask\"\n m = getmask(a)\n d = oldnumeric.ravel(filled(a))\n if m is None:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.ravel(m))\n\ndef concatenate (arrays, axis=0):\n \"Concatenate the arrays along the given axis\"\n d = []\n for x in arrays:\n d.append(filled(x))\n d = numeric.concatenate(d, axis)\n for x in arrays:\n if getmask(x) is not None: break\n else:\n return masked_array(d)\n dm = []\n for x in arrays:\n dm.append(getmaskarray(x))\n dm = numeric.concatenate(dm, axis)\n return masked_array(d, mask=dm)\n\ndef take (a, indices, axis=0):\n \"take(a, indices, axis=0) returns selection of items from a.\"\n m = getmask(a)\n d = masked_array(a).raw_data()\n if m is None:\n return masked_array(numeric.take(d, indices, axis))\n else:\n return masked_array(numeric.take(d, indices, axis),\n mask = numeric.take(m, indices, axis))\n\ndef transpose(a, axes=None):\n \"transpose(a, axes=None) reorder dimensions per tuple axes\"\n m = getmask(a)\n d = filled(a)\n if m is None:\n return masked_array(numeric.transpose(d, axes))\n else:\n return masked_array(numeric.transpose(d, axes),\n mask = numeric.transpose(m, axes))\n\n\ndef put(a, indices, values):\n \"\"\"put(a, indices, values) sets storage-indexed locations to corresponding values.\n\n Values and indices are filled if necessary.\n\n \"\"\"\n d = a.raw_data()\n ind = filled(indices)\n v = filled(values)\n numeric.put (d, ind, v)\n m = getmask(a)\n if m is not None:\n a.unshare_mask()\n numeric.put(a.raw_mask(), ind, 0)\n\ndef putmask(a, mask, values):\n \"putmask(a, mask, values) sets a where mask is true.\"\n if mask is None:\n return\n numeric.putmask(a.raw_data(), mask, values)\n m = getmask(a)\n if m is None: return\n a.unshare_mask()\n numeric.putmask(a.raw_mask(), mask, 0)\n\ndef innerproduct(a,b):\n \"\"\"innerproduct(a,b) returns the dot product of two arrays, which has\n shape a.shape[:-1] + b.shape[:-1] with elements computed by summing the\n product of the elements from the last dimensions of a and b.\n Masked elements are replace by zeros.\n \"\"\"\n fa = filled(a, 0)\n fb = filled(b, 0)\n if len(fa.shape) == 0: fa.shape = (1,)\n if len(fb.shape) == 0: fb.shape = (1,)\n return masked_array(numeric.innerproduct(fa, fb))\n\ndef outerproduct(a, b):\n \"\"\"outerproduct(a,b) = {a[i]*b[j]}, has shape (len(a),len(b))\"\"\"\n fa = filled(a,0).ravel()\n fb = filled(b,0).ravel()\n d = numeric.outerproduct(fa, fb)\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n return masked_array(d)\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = make_mask(1-numeric.outerproduct(1-ma,1-mb), copy=0)\n return masked_array(d, m)\n\ndef dot(a, b):\n \"\"\"dot(a,b) returns matrix-multiplication between a and b. The product-sum\n is over the last dimension of a and the second-to-last dimension of b.\n Masked values are replaced by zeros. See also innerproduct.\n \"\"\"\n return innerproduct(filled(a,0), numeric.swapaxes(filled(b,0), -1, -2))\n\ndef compress(condition, x, dimension=-1):\n \"\"\"Select those parts of x for which condition is true.\n Masked values in condition are considered false.\n \"\"\"\n c = filled(condition, 0)\n m = getmask(x)\n if m is not None:\n m=numeric.compress(c, m, dimension)\n d = numeric.compress(c, filled(x), dimension)\n return masked_array(d, m)\n\nclass _minimum_operation:\n \"Object to calculate minima\"\n def __init__ (self):\n \"\"\"minimum(a, b) or minimum(a)\n In one argument case returns the scalar minimum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is None:\n d = amin(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amin(ac.raw_data())\n else:\n return where(less(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is None:\n t = filled(target)\n return masked_array (umath.minimum.reduce (t, axis))\n else:\n t = umath.minimum.reduce(filled(target, minimum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n m = None\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.minimum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nminimum = _minimum_operation ()\n\nclass _maximum_operation:\n \"Object to calculate maxima\"\n def __init__ (self):\n \"\"\"maximum(a, b) or maximum(a)\n In one argument case returns the scalar maximum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is None:\n d = amax(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amax(ac.raw_data())\n else:\n return where(greater(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is None:\n t = filled(target)\n return masked_array (umath.maximum.reduce (t, axis))\n else:\n t = umath.maximum.reduce(filled(target, maximum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n m = None\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.maximum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nmaximum = _maximum_operation ()\n\ndef sort (x, axis = -1, fill_value=None):\n \"\"\"If x does not have a mask, return a masked array formed from the\n result of numeric.sort(x, axis).\n Otherwise, fill x with fill_value. Sort it.\n Set a mask where the result is equal to fill_value.\n Note that this may have unintended consequences if the data contains the\n fill value at a non-masked site.\n\n If fill_value is not given the default fill value for x's type will be\n used.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n d = filled(x, fill_value)\n s = oldnumeric.sort(d, axis)\n if getmask(x) is None:\n return masked_array(s)\n return masked_values(s, fill_value, copy=0)\n\ndef diagonal(a, k = 0, axis1=0, axis2=1):\n \"\"\"diagonal(a,k=0,axis1=0, axis2=1) = the k'th diagonal of a\"\"\"\n d = oldnumeric.diagonal(filled(a), k, axis1, axis2)\n m = getmask(a)\n if m is None:\n return masked_array(d, m)\n else:\n return masked_array(d, oldnumeric.diagonal(m, k, axis1, axis2))\n\ndef argsort (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for sorting along given axis.\n if fill_value is None, use get_fill_value(x)\n Returns a numpy array.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argsort(d, axis)\n\ndef argmin (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return indices for minimum values along given axis.\n if fill_value is None, use get_fill_value(x).\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argmin(d, axis)\n\ndef argmax (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for maximum along given axis.\n if fill_value is None, use -get_fill_value(x) if it exists.\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n try:\n fill_value = - fill_value\n except:\n pass\n d = filled(x, fill_value)\n return oldnumeric.argmax(d, axis)\n\ndef fromfunction (f, s):\n \"\"\"apply f to s to create array as in umath.\"\"\"\n return masked_array(numeric.fromfunction(f,s))\n\ndef asarray(data, dtype=None):\n \"\"\"asarray(data, dtype) = array(data, dtype, copy=0)\n \"\"\"\n if isinstance(data, MaskedArray) and \\\n (dtype is None or dtype == data.dtype):\n return data\n return array(data, dtype=dtype, copy=0)\n\n# Add methods to support ndarray interface\n# XXX: I is better to to change the masked_*_operation adaptors\n# XXX: to wrap ndarray methods directly to create ma.array methods.\nfrom types import MethodType\ndef _m(f):\n return MethodType(f, None, array)\ndef not_implemented(*args, **kwds):\n raise NotImplementedError, \"not yet implemented for numpy.ma arrays\"\narray.all = _m(alltrue)\narray.any = _m(sometrue)\narray.argmax = _m(argmax)\narray.argmin = _m(argmin)\narray.argsort = _m(argsort)\narray.base = property(_m(not_implemented))\narray.byteswap = _m(not_implemented)\n\ndef _choose(self, *args):\n return choose(self, args)\narray.choose = _m(_choose)\ndel _choose\n\narray.clip = _m(not_implemented)\n\ndef _compress(self, cond, axis=None):\n return compress(cond, self, axis)\narray.compress = _m(_compress)\ndel _compress\n\narray.conj = array.conjugate = _m(conjugate)\narray.copy = _m(not_implemented)\narray.cumprod = _m(not_implemented)\narray.cumsum = _m(not_implemented)\narray.diagonal = _m(diagonal)\narray.dtypedescr = property(_m(not_implemented))\narray.dtypestr = property(_m(not_implemented))\narray.dump = _m(not_implemented)\narray.dumps = _m(not_implemented)\narray.fill = _m(not_implemented)\narray.flags = property(_m(not_implemented))\narray.flatten = _m(ravel)\narray.getfield = _m(not_implemented)\narray.max = _m(maximum)\narray.mean = _m(average)\narray.min = _m(minimum)\narray.nbytes = property(_m(not_implemented))\narray.ndim = _m(not_implemented)\narray.newbyteorder = _m(not_implemented)\narray.nonzero = _m(nonzero)\narray.prod = _m(product)\narray.ptp = _m(not_implemented)\narray.repeat = _m(repeat)\narray.resize = _m(resize)\narray.searchsorted = _m(not_implemented)\narray.setfield = _m(not_implemented)\narray.setflags = _m(not_implemented)\narray.sort = _m(not_implemented) # NB: ndarray.sort is inplace\narray.squeeze = _m(not_implemented)\narray.std = _m(not_implemented)\narray.strides = property(_m(not_implemented))\narray.sum = _m(sum)\narray.swapaxes = _m(not_implemented)\narray.take = _m(take)\narray.tofile = _m(not_implemented)\narray.trace = _m(not_implemented)\narray.transpose = _m(transpose)\narray.var = _m(not_implemented)\narray.view = _m(not_implemented)\ndel _m, MethodType, not_implemented\n\n\nmasked = MaskedArray(0, int, mask=1)\n", + "source_code_before": "\"\"\"MA: a facility for dealing with missing observations\nMA is generally used as a numpy.array look-alike.\nby Paul F. Dubois.\n\nCopyright 1999, 2000, 2001 Regents of the University of California.\nReleased for unlimited redistribution.\nAdapted for numpy_core 2005 by Travis Oliphant and\n(mainly) Paul Dubois.\n\"\"\"\nimport string, types, sys\n\nimport umath\nimport oldnumeric\nfrom numeric import e, pi, newaxis, ndarray, inf\nfrom oldnumeric import typecodes, amax, amin\nfrom numerictypes import *\nimport numeric\n\n \nMaskType=bool_\ndivide_tolerance = 1.e-35\n\nclass MAError (Exception):\n def __init__ (self, args=None):\n \"Create an exception\"\n self.args = args\n def __str__(self):\n \"Calculate the string representation\"\n return str(self.args)\n __repr__ = __str__\n\nclass _MaskedPrintOption:\n \"One instance of this class, masked_print_option, is created.\"\n def __init__ (self, display):\n \"Create the masked print option object.\"\n self.set_display(display)\n self._enabled = 1\n\n def display (self):\n \"Show what prints for masked values.\"\n return self._display\n\n def set_display (self, s):\n \"set_display(s) sets what prints for masked values.\"\n self._display = s\n\n def enabled (self):\n \"Is the use of the display value enabled?\"\n return self._enabled\n\n def enable(self, flag=1):\n \"Set the enabling flag to flag.\"\n self._enabled = flag\n\n def __str__ (self):\n return str(self._display)\n\n __repr__ = __str__\n \n#if you single index into a masked location you get this object.\nmasked_print_option = _MaskedPrintOption('--')\n\n# Use single element arrays or scalars.\ndefault_real_fill_value = 1.e20\ndefault_complex_fill_value = 1.e20 + 0.0j\ndefault_character_fill_value = '-'\ndefault_integer_fill_value = 999999\ndefault_object_fill_value = '?'\n\ndef default_fill_value (obj):\n \"Function to calculate default fill value for an object.\"\n if isinstance(obj, types.FloatType):\n return default_real_fill_value\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return default_integer_fill_value\n elif isinstance(obj, types.StringType):\n return default_character_fill_value\n elif isinstance(obj, types.ComplexType):\n return default_complex_fill_value\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return default_real_fill_value\n if x in typecodes['Integer']:\n return default_integer_fill_value\n if x in typecodes['Complex']:\n return default_complex_fill_value\n if x in typecodes['Character']:\n return default_character_fill_value\n if x in typecodes['UnsignedInteger']:\n return umath.absolute(default_integer_fill_value)\n return default_object_fill_value\n else:\n return default_object_fill_value\n\ndef minimum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking minima.\"\n if isinstance(obj, types.FloatType):\n return numeric.inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return numeric.inf\n if x in typecodes['Integer']:\n return sys.maxint\n if x in typecodes['UnsignedInteger']:\n return sys.maxint\n else:\n raise TypeError, 'Unsuitable type for calculating minimum.'\n\ndef maximum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking maxima.\"\n if isinstance(obj, types.FloatType):\n return -inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return -sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return -inf\n if x in typecodes['Integer']:\n return -sys.maxint\n if x in typecodes['UnsignedInteger']:\n return 0\n else:\n raise TypeError, 'Unsuitable type for calculating maximum.'\n\ndef set_fill_value (a, fill_value):\n \"Set fill value of a if it is a masked array.\"\n if isMaskedArray(a):\n a.set_fill_value (fill_value)\n\ndef getmask (a):\n \"\"\"Mask of values in a; could be None.\n Returns None if a is not a masked array.\n To get an array for sure use getmaskarray.\"\"\"\n if isinstance(a, MaskedArray):\n return a.raw_mask()\n else:\n return None\n\ndef getmaskarray (a):\n \"\"\"Mask of values in a; an array of zeros if mask is None\n or not a masked array, and is a byte-sized integer.\n Do not try to add up entries, for example.\n \"\"\"\n m = getmask(a)\n if m is None:\n return make_mask_none(shape(a))\n else:\n return m\n\ndef is_mask (m):\n \"\"\"Is m a legal mask? Does not check contents, only type.\n \"\"\"\n if m is None or (isinstance(m, ndarray) and \\\n m.dtype is MaskType):\n return 1\n else:\n return 0\n\ndef make_mask (m, copy=0, flag=0):\n \"\"\"make_mask(m, copy=0, flag=0)\n return m as a mask, creating a copy if necessary or requested.\n Can accept any sequence of integers or None. Does not check\n that contents must be 0s and 1s.\n if flag, return None if m contains no true elements.\n \"\"\"\n if m is None:\n return None\n elif isinstance(m, ndarray):\n if m.dtype is MaskType:\n if copy:\n result = numeric.array(m, dtype=MaskType, copy=copy)\n else:\n result = m\n else:\n result = m.astype(MaskType)\n else:\n result = filled(m,True).astype(MaskType)\n\n if flag and not oldnumeric.sometrue(oldnumeric.ravel(result)):\n return None\n else:\n return result\n\ndef make_mask_none (s):\n \"Return a mask of all zeros of shape s.\"\n result = numeric.zeros(s, dtype=MaskType)\n result.shape = s\n return result\n\ndef mask_or (m1, m2):\n \"\"\"Logical or of the mask candidates m1 and m2, treating None as false.\n Result may equal m1 or m2 if the other is None.\n \"\"\"\n if m1 is None: return make_mask(m2)\n if m2 is None: return make_mask(m1)\n if m1 is m2 and is_mask(m1): return m1\n return make_mask(umath.logical_or(m1, m2))\n\ndef filled (a, value = None):\n \"\"\"a as a contiguous numeric array with any masked areas replaced by value\n if value is None or the special element \"masked\", get_fill_value(a)\n is used instead.\n\n If a is already a contiguous numeric array, a itself is returned.\n\n filled(a) can be used to be sure that the result is numeric when\n passing an object a to other software ignorant of MA, in particular to\n numeric itself.\n \"\"\"\n if isinstance(a, MaskedArray):\n return a.filled(value)\n elif isinstance(a, ndarray) and a.flags['CONTIGUOUS']:\n return a\n elif isinstance(a, types.DictType):\n return numeric.array(a, 'O')\n else:\n return numeric.array(a)\n\ndef get_fill_value (a):\n \"\"\"\n The fill value of a, if it has one; otherwise, the default fill value\n for that type.\n \"\"\"\n if isMaskedArray(a):\n result = a.fill_value()\n else:\n result = default_fill_value(a)\n return result\n\ndef common_fill_value (a, b):\n \"The common fill_value of a and b, if there is one, or None\"\n t1 = get_fill_value(a)\n t2 = get_fill_value(b)\n if t1 == t2: return t1\n return None\n\n# Domain functions return 1 where the argument(s) are not in the domain.\nclass domain_check_interval:\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n def __init__(self, y1, y2):\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n self.y1 = y1\n self.y2 = y2\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.logical_or(umath.greater (x, self.y2),\n umath.less(x, self.y1)\n )\n\nclass domain_tan:\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n def __init__(self, eps):\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n self.eps = eps\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less(umath.absolute(umath.cos(x)), self.eps)\n\nclass domain_greater:\n \"domain_greater(v)(x) = true where x <= v\"\n def __init__(self, critical_value):\n \"domain_greater(v)(x) = true where x <= v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less_equal (x, self.critical_value)\n\nclass domain_greater_equal:\n \"domain_greater_equal(v)(x) = true where x < v\"\n def __init__(self, critical_value):\n \"domain_greater_equal(v)(x) = true where x < v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less (x, self.critical_value)\n\nclass masked_unary_operation:\n def __init__ (self, aufunc, fill=0, domain=None):\n \"\"\" masked_unary_operation(aufunc, fill=0, domain=None)\n aufunc(fill) must be defined\n self(x) returns aufunc(x)\n with masked values where domain(x) is true or getmask(x) is true.\n \"\"\"\n self.f = aufunc\n self.fill = fill\n self.domain = domain\n self.__doc__ = getattr(aufunc, \"__doc__\", str(aufunc))\n\n def __call__ (self, a, *args, **kwargs):\n \"Execute the call behavior.\"\n# numeric tries to return scalars rather than arrays when given scalars.\n m = getmask(a)\n d1 = filled(a, self.fill)\n if self.domain is not None:\n m = mask_or(m, self.domain(d1))\n result = self.f(d1, *args, **kwargs)\n if m is not None:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\n\nclass domain_safe_divide:\n def __init__ (self, tolerance=divide_tolerance):\n self.tolerance = tolerance\n def __call__ (self, a, b):\n return umath.absolute(a) * self.tolerance >= umath.absolute(b)\n\nclass domained_binary_operation:\n \"\"\"Binary operations that have a domain, like divide. These are complicated so they\n are a separate class. They have no reduce, outer or accumulate.\n \"\"\"\n def __init__ (self, abfunc, domain, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.domain = domain\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__(self, a, b):\n \"Execute the call behavior.\"\n ma = getmask(a)\n mb = getmask(b)\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n t = self.domain(d1, d2)\n\n if oldnumeric.sometrue(t, None):\n d2 = where(t, self.filly, d2)\n mb = mask_or(mb, t)\n m = mask_or(ma, mb)\n result = self.f(d1, d2)\n if m is not None:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n \n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nclass masked_binary_operation:\n def __init__ (self, abfunc, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__ (self, a, b, *args, **kwargs):\n \"Execute the call behavior.\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n result = self.f(d1, d2, *args, **kwargs)\n if m is not None:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis with this function.\"\"\"\n m = getmask(target)\n t = filled(target, self.filly)\n if t.shape == ():\n t = t.reshape(1)\n if m is not None:\n m = make_mask(m, copy=1)\n m.shape = (1,)\n if m is None:\n return masked_array (self.f.reduce (t, axis))\n else:\n t = masked_array (t, m)\n t = self.f.reduce(filled(t, self.filly), axis)\n m = umath.logical_and.reduce(m, axis)\n if isinstance(t, ndarray):\n return masked_array(t, m, get_fill_value(target))\n elif m:\n return masked\n else:\n return t\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n m = None\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = self.f.outer(filled(a, self.fillx), filled(b, self.filly))\n return masked_array(d, m)\n\n def accumulate (self, target, axis=0):\n \"\"\"Accumulate target along axis after filling with y fill value.\"\"\"\n t = filled(target, self.filly)\n return masked_array (self.f.accumulate (t, axis))\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nsqrt = masked_unary_operation(umath.sqrt, 0.0, domain_greater_equal(0.0))\nlog = masked_unary_operation(umath.log, 1.0, domain_greater(0.0))\nlog10 = masked_unary_operation(umath.log10, 1.0, domain_greater(0.0))\nexp = masked_unary_operation(umath.exp)\nconjugate = masked_unary_operation(umath.conjugate)\nsin = masked_unary_operation(umath.sin)\ncos = masked_unary_operation(umath.cos)\ntan = masked_unary_operation(umath.tan, 0.0, domain_tan(1.e-35))\narcsin = masked_unary_operation(umath.arcsin, 0.0, domain_check_interval(-1.0, 1.0))\narccos = masked_unary_operation(umath.arccos, 0.0, domain_check_interval(-1.0, 1.0))\narctan = masked_unary_operation(umath.arctan)\n# Missing from numeric\narcsinh = masked_unary_operation(umath.arcsinh)\narccosh = masked_unary_operation(umath.arccosh)\narctanh = masked_unary_operation(umath.arctanh)\nsinh = masked_unary_operation(umath.sinh)\ncosh = masked_unary_operation(umath.cosh)\ntanh = masked_unary_operation(umath.tanh)\nabsolute = masked_unary_operation(umath.absolute)\nfabs = masked_unary_operation(umath.fabs)\nnegative = masked_unary_operation(umath.negative)\nnonzero = masked_unary_operation(oldnumeric.nonzero)\naround = masked_unary_operation(oldnumeric.round_)\nfloor = masked_unary_operation(umath.floor)\nceil = masked_unary_operation(umath.ceil)\nsometrue = masked_unary_operation(oldnumeric.sometrue)\nalltrue = masked_unary_operation(oldnumeric.alltrue, 1)\nlogical_not = masked_unary_operation(umath.logical_not)\n\nadd = masked_binary_operation(umath.add)\nsubtract = masked_binary_operation(umath.subtract)\nsubtract.reduce = None\nmultiply = masked_binary_operation(umath.multiply, 1, 1)\ndivide = domained_binary_operation(umath.divide, domain_safe_divide(), 0, 1)\ntrue_divide = domained_binary_operation(umath.true_divide, domain_safe_divide(), 0, 1)\nfloor_divide = domained_binary_operation(umath.floor_divide, domain_safe_divide(), 0, 1)\nremainder = domained_binary_operation(umath.remainder, domain_safe_divide(), 0, 1)\nfmod = domained_binary_operation(umath.fmod, domain_safe_divide(), 0, 1)\nhypot = masked_binary_operation(umath.hypot)\narctan2 = masked_binary_operation(umath.arctan2, 0.0, 1.0)\narctan2.reduce = None\nequal = masked_binary_operation(umath.equal)\nequal.reduce = None\nnot_equal = masked_binary_operation(umath.not_equal)\nnot_equal.reduce = None\nless_equal = masked_binary_operation(umath.less_equal)\nless_equal.reduce = None\ngreater_equal = masked_binary_operation(umath.greater_equal)\ngreater_equal.reduce = None\nless = masked_binary_operation(umath.less)\nless.reduce = None\ngreater = masked_binary_operation(umath.greater)\ngreater.reduce = None\nlogical_and = masked_binary_operation(umath.logical_and)\nlogical_or = masked_binary_operation(umath.logical_or)\nlogical_xor = masked_binary_operation(umath.logical_xor)\nbitwise_and = masked_binary_operation(umath.bitwise_and)\nbitwise_or = masked_binary_operation(umath.bitwise_or)\nbitwise_xor = masked_binary_operation(umath.bitwise_xor)\n\ndef rank (object):\n return oldnumeric.rank(filled(object))\n\ndef shape (object):\n return oldnumeric.shape(filled(object))\n\ndef size (object, axis=None):\n return oldnumeric.size(filled(object), axis)\n\nclass MaskedArray (object):\n \"\"\"Arrays with possibly masked values.\n Masked values of 1 exclude the corresponding element from \n any computation.\n\n Construction:\n x = array(data, dtype=None, copy=True, fortran=False,\n mask = None, fill_value=None)\n\n If copy=False, every effort is made not to copy the data:\n If data is a MaskedArray, and argument mask=None,\n then the candidate data is data.data and the\n mask used is data.mask. If data is a numeric array,\n it is used as the candidate raw data.\n If dtypechar is not None and\n is != data.dtypechar then a data copy is required.\n Otherwise, the candidate is used.\n\n If a data copy is required, raw data stored is the result of:\n numeric.array(data, dtype=dtypechar, copy=copy)\n\n If mask is None there are no masked values. Otherwise mask must\n be convertible to an array of booleans with the same shape as x.\n\n fill_value is used to fill in masked values when necessary,\n such as when printing and in method/function filled().\n The fill_value is not used for computation within this module.\n \"\"\"\n __array_priority__ = 10.1\n def __init__(self, data, dtype=None, copy=True, fortran=False, \n mask=None, fill_value=None):\n \"\"\"array(data, dtype=None, copy=True, fortran=False, mask=None, fill_value=None)\n If data already a numeric array, its dtype becomes the default value of dtype.\n \"\"\"\n tc = dtype\n need_data_copied = copy\n if isinstance(data, MaskedArray):\n c = data.data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n if mask is None:\n mask = data.mask\n elif mask is not None: #attempting to change the mask\n need_data_copied = True\n\n elif isinstance(data, ndarray):\n c = data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n else:\n need_data_copied = False #because I'll do it now\n c = numeric.array(data, dtype=tc, copy=True, fortran=fortran)\n\n if need_data_copied:\n if tc == ctc:\n self._data = numeric.array(c, dtype=tc, copy=True, fortran=fortran)\n else:\n self._data = c.astype(tc)\n else:\n self._data = c\n\n if mask is None:\n self._mask = None\n self._shared_mask = 0\n else:\n self._mask = make_mask (mask)\n if self._mask is None:\n self._shared_mask = 0\n else:\n self._shared_mask = (self._mask is mask)\n nm = size(self._mask)\n nd = size(self._data)\n if nm != nd:\n if nm == 1:\n self._mask = oldnumeric.resize(self._mask, self._data.shape)\n self._shared_mask = 0\n elif nd == 1:\n self._data = oldnumeric.resize(self._data, self._mask.shape)\n self._data.shape = self._mask.shape\n else:\n raise MAError, \"Mask and data not compatible.\"\n elif nm == 1 and shape(self._mask) != shape(self._data):\n self.unshare_mask()\n self._mask.shape = self._data.shape\n\n self.set_fill_value(fill_value)\n\n def __array__ (self, t = None):\n \"Special hook for numeric. Converts to numeric if possible.\"\n if self._mask is not None:\n if oldnumeric.ravel(self._mask).any():\n raise MAError, \\\n \"\"\"Cannot automatically convert masked array to numeric because data\n is masked in one or more locations.\n \"\"\"\n else: # Mask is all false\n # Optimize to avoid future invocations of this section.\n self._mask = None\n self._shared_mask = 0\n if t:\n return self._data.astype(t)\n else:\n return self._data\n\n def __array_wrap__ (self, array):\n \"\"\"Special hook for ufuncs. Converts to Masked array with\n the same mask as self.\"\"\"\n return MaskedArray(array, copy=False, mask=self._mask,\n fill_value = self._fill_value)\n \n def _get_shape(self):\n \"Return the current shape.\"\n return self._data.shape\n\n def _set_shape (self, newshape):\n \"Set the array's shape.\"\n self._data.shape = newshape\n if self._mask is not None:\n self._mask = self._mask.copy()\n self._mask.shape = newshape\n\n def _get_flat(self):\n \"\"\"Calculate the flat value.\n \"\"\"\n if self._mask is None:\n return masked_array(self._data.ravel(), mask=None,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.ravel(),\n mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_flat (self, value):\n \"x.flat = value\"\n y = self.ravel()\n y[:] = value\n\n def _get_real(self):\n \"Get the real part of a complex array.\"\n if self._mask is None:\n return masked_array(self._data.real, mask=None,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.real, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_real (self, value):\n \"x.real = value\"\n y = self.real\n y[...] = value\n\n def _get_imaginary(self):\n \"Get the imaginary part of a complex array.\"\n if self._mask is None:\n return masked_array(self._data.imag, mask=None,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.imag, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_imaginary (self, value):\n \"x.imaginary = value\"\n y = self.imaginary\n y[...] = value\n\n def __str__(self):\n \"\"\"Calculate the str representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n if masked_print_option.enabled():\n f = masked_print_option\n # XXX: Without the following special case masked\n # XXX: would print as \"[--]\", not \"--\". Can we avoid\n # XXX: checks for masked by choosing a different value\n # XXX: for the masked singleton? 2005-01-05 -- sasha\n if self is masked:\n return str(f)\n # convert to object array to make filled work\n self = self.astype(object)\n else:\n f = self.fill_value()\n res = self.filled(f)\n return str(res)\n\n def __repr__(self):\n \"\"\"Calculate the repr representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n with_mask = \"\"\"\\\narray(data =\n %(data)s,\n mask =\n %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n with_mask1 = \"\"\"\\\narray(data = %(data)s,\n mask = %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n without_mask = \"\"\"array(\n %(data)s)\"\"\"\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n\n n = len(self.shape)\n if self._mask is None:\n if n <=1:\n return without_mask1 % {'data':str(self.filled())}\n return without_mask % {'data':str(self.filled())}\n else:\n if n <=1:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n if self._mask is None:\n return without_mask % {'data':str(self.filled())}\n else:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n\n def __float__(self):\n \"Convert self to float.\"\n self.unmask()\n if self._mask is not None:\n raise MAError, 'Cannot convert masked element to a Python float.'\n return float(self.data.item())\n\n def __int__(self):\n \"Convert self to int.\"\n self.unmask()\n if self._mask is not None:\n raise MAError, 'Cannot convert masked element to a Python int.'\n return int(self.data.item())\n\n def __getitem__(self, i):\n \"Get item described by i. Not a copy as in previous versions.\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i]\n if m is None:\n return dout\n mi = m[i]\n if mi.size == 1:\n if mi: \n return masked\n else:\n return dout\n else:\n return masked_array(dout, mi, fill_value=self._fill_value)\n\n def __getslice__(self, i, j):\n \"Get slice described by i, j\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i:j]\n if m is None:\n return masked_array(dout, fill_value=self._fill_value)\n else:\n return masked_array(dout, mask = m[i:j], fill_value=self._fill_value)\n\n# --------\n# setitem and setslice notes\n# note that if value is masked, it means to mask those locations.\n# setting a value changes the mask to match the value in those locations.\n\n def __setitem__(self, index, value):\n \"Set item described by index. If value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, 'Cannot alter the masked element.'\n if value is masked:\n if self._mask is None:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n else:\n self.unshare_mask()\n self._mask[index] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[index] = value\n if m is None:\n if self._mask is not None:\n self.unshare_mask()\n self._mask[index] = False\n else:\n if self._mask is None:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = True\n else:\n self.unshare_mask()\n self._mask[index] = m\n\n def __setslice__(self, i, j, value):\n \"Set slice i:j; if value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, \"Cannot alter the 'masked' object.\"\n if value is masked:\n if self._mask is None:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n self._mask[i:j] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[i:j] = value\n if m is None:\n if self._mask is not None:\n self.unshare_mask()\n self._mask[i:j] = False\n else:\n if self._mask is None:\n self._mask = make_mask_none(self._data.shape)\n self._shared_mask = False\n self._mask[i:j] = m\n\n def __nonzero__(self):\n \"\"\"returns true if any element is non-zero or masked\n\n \"\"\"\n # XXX: This changes bool conversion logic from MA.\n # XXX: In MA bool(a) == len(a) != 0, but in numpy\n # XXX: scalars do not have len \n m = self._mask\n d = self._data\n return bool(m is not None and m.any()\n or d is not None and d.any())\n \n def __len__ (self):\n \"\"\"Return length of first dimension. This is weird but Python's\n slicing behavior depends on it.\"\"\"\n return len(self._data)\n\n def __and__(self, other):\n \"Return bitwise_and\"\n return bitwise_and(self, other)\n\n def __or__(self, other):\n \"Return bitwise_or\"\n return bitwise_or(self, other)\n\n def __xor__(self, other):\n \"Return bitwise_xor\"\n return bitwise_xor(self, other)\n\n __rand__ = __and__\n __ror__ = __or__\n __rxor__ = __xor__\n\n def __abs__(self):\n \"Return absolute(self)\"\n return absolute(self)\n\n def __neg__(self):\n \"Return negative(self)\"\n return negative(self)\n\n def __pos__(self):\n \"Return array(self)\"\n return array(self)\n\n def __add__(self, other):\n \"Return add(self, other)\"\n return add(self, other)\n\n __radd__ = __add__\n\n def __mod__ (self, other):\n \"Return remainder(self, other)\"\n return remainder(self, other)\n\n def __rmod__ (self, other):\n \"Return remainder(other, self)\"\n return remainder(other, self)\n\n def __lshift__ (self, n):\n return left_shift(self, n)\n\n def __rshift__ (self, n):\n return right_shift(self, n)\n\n def __sub__(self, other):\n \"Return subtract(self, other)\"\n return subtract(self, other)\n\n def __rsub__(self, other):\n \"Return subtract(other, self)\"\n return subtract(other, self)\n\n def __mul__(self, other):\n \"Return multiply(self, other)\"\n return multiply(self, other)\n\n __rmul__ = __mul__\n\n def __div__(self, other):\n \"Return divide(self, other)\"\n return divide(self, other)\n\n def __rdiv__(self, other):\n \"Return divide(other, self)\"\n return divide(other, self)\n\n def __truediv__(self, other):\n \"Return divide(self, other)\"\n return true_divide(self, other)\n\n def __rtruediv__(self, other):\n \"Return divide(other, self)\"\n return true_divide(other, self)\n\n def __floordiv__(self, other):\n \"Return divide(self, other)\"\n return floor_divide(self, other)\n\n def __rfloordiv__(self, other):\n \"Return divide(other, self)\"\n return floor_divide(other, self)\n\n def __pow__(self,other, third=None):\n \"Return power(self, other, third)\"\n return power(self, other, third)\n\n def __sqrt__(self):\n \"Return sqrt(self)\"\n return sqrt(self)\n\n def __iadd__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is None:\n self._data += f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not None\n else:\n result = add(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __imul__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is None:\n self._data *= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not None\n else:\n result = multiply(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __isub__(self, other):\n \"Subtract other from self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is None:\n self._data -= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not None\n else:\n result = subtract(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n\n\n def __idiv__(self, other):\n \"Divide self by other in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n mo = getmask(other)\n result = divide(self, masked_array(f, mask=mo))\n self._data = result.data\n dm = result.raw_mask()\n if dm is not self._mask:\n self._mask = dm\n self._shared_mask = 1\n return self\n\n def __eq__(self,other):\n return equal(self,other)\n\n def __ne__(self,other):\n return not_equal(self,other)\n\n def __lt__(self,other):\n return less(self,other)\n\n def __le__(self,other):\n return less_equal(self,other)\n\n def __gt__(self,other):\n return greater(self,other)\n\n def __ge__(self,other):\n return greater_equal(self,other)\n\n def astype (self, tc):\n \"return self as array of given type.\"\n d = self._data.astype(tc)\n return array(d, mask=self._mask)\n\n def byte_swapped(self):\n \"\"\"Returns the raw data field, byte_swapped. Included for consistency\n with numeric but doesn't make sense in this context.\n \"\"\"\n return self._data.byte_swapped()\n\n def compressed (self):\n \"A 1-D array of all the non-masked data.\"\n d = oldnumeric.ravel(self._data)\n if self._mask is None:\n return array(d)\n else:\n m = 1 - oldnumeric.ravel(self._mask)\n c = oldnumeric.compress(m, d)\n return array(c, copy=0)\n\n def count (self, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n m = self._mask\n s = self._data.shape\n ls = len(s)\n if m is None:\n if ls == 0:\n return 1\n if ls == 1:\n return s[0]\n if axis is None:\n return reduce(lambda x,y:x*y, s)\n else:\n n = s[axis]\n t = list(s)\n del t[axis]\n return ones(t) * n\n if axis is None:\n w = oldnumeric.ravel(m).astype(int) \n n1 = size(w)\n if n1 == 1:\n n2 = w[0]\n else:\n n2 = umath.add.reduce(w)\n return n1 - n2\n else:\n n1 = size(m, axis)\n n2 = sum(m.astype(int), axis)\n return n1 - n2\n\n def dot (self, other):\n \"s.dot(other) = innerproduct(s, other)\"\n return innerproduct(self, other)\n\n def fill_value(self):\n \"Get the current fill value.\"\n return self._fill_value\n\n def filled (self, fill_value=None):\n \"\"\"A numeric array with masked values filled. If fill_value is None,\n use self.fill_value().\n\n If mask is None, copy data only if not contiguous.\n Result is always a contiguous, numeric array.\n# Is contiguous really necessary now?\n \"\"\"\n d = self._data\n m = self._mask\n if m is None:\n if d.flags['CONTIGUOUS']:\n return d\n else:\n return d.copy()\n else:\n if fill_value is None:\n value = self._fill_value\n else:\n value = fill_value\n\n if self is masked:\n result = numeric.array(value).reshape(*d.shape)\n else:\n try:\n result = numeric.array(d, dtype=d.dtype, copy=1)\n result[m] = value\n except (TypeError, AttributeError):\n #ok, can't put that value in here\n value = numeric.array(value, dtype=object)\n d = d.astype(object)\n result = oldnumeric.choose(m, (d, value))\n except IndexError:\n #ok, if scalar\n if d.shape:\n raise\n elif m:\n result = numeric.array(value, dtype=d.dtype)\n else:\n result = d\n return result\n\n def ids (self):\n \"\"\"Return the ids of the data and mask areas\"\"\"\n return (id(self._data), id(self._mask))\n\n def iscontiguous (self):\n \"Is the data contiguous?\"\n return self._data.flags['CONTIGUOUS']\n\n def itemsize(self):\n \"Item size of each data item.\"\n return self._data.itemsize\n\n\n def outer(self, other):\n \"s.outer(other) = outerproduct(s, other)\"\n return outerproduct(self, other)\n\n def put (self, values):\n \"\"\"Set the non-masked entries of self to filled(values).\n No change to mask\n \"\"\"\n iota = numeric.arange(self.size)\n d = self._data\n if self._mask is None:\n ind = iota\n else:\n ind = oldnumeric.compress(1 - self._mask, iota)\n d[ind] = filled(values).astype(d.dtype)\n\n def putmask (self, values):\n \"\"\"Set the masked entries of self to filled(values).\n Mask changed to None.\n \"\"\"\n d = self._data\n if self._mask is not None:\n d[self._mask] = filled(values).astype(d.dtype)\n self._shared_mask = 0\n self._mask = None\n\n def ravel (self):\n \"\"\"Return a 1-D view of self.\"\"\"\n if self._mask is None:\n return masked_array(self._data.ravel())\n else:\n return masked_array(self._data.ravel(), self._mask.ravel())\n\n def raw_data (self):\n \"\"\" Obsolete; use data property instead.\n The raw data; portions may be meaningless.\n May be noncontiguous. Expert use only.\"\"\"\n return self._data\n data = property(fget=raw_data, \n doc=\"The data, but values at masked locations are meaningless.\")\n\n def raw_mask (self):\n \"\"\" Obsolete; use mask property instead.\n May be noncontiguous. Expert use only.\n \"\"\"\n return self._mask\n mask = property(fget=raw_mask, \n doc=\"The mask, may be None. Values where mask true are meaningless.\")\n\n def reshape (self, *s):\n \"\"\"This array reshaped to shape s\"\"\"\n d = self._data.reshape(*s)\n if self._mask is None:\n return masked_array(d)\n else:\n m = self._mask.reshape(*s)\n return masked_array(d, m)\n\n def set_fill_value (self, v=None):\n \"Set the fill value to v. Omit v to restore default.\"\n if v is None:\n v = default_fill_value (self.raw_data())\n self._fill_value = v\n\n def _get_size (self):\n return self._data.size\n size = property(fget=_get_size, doc=\"Number of elements in the array.\")\n## CHECK THIS: signature of numeric.array.size?\n \n def _get_dtypechar(self):\n return self._data.dtypechar\n dtypechar = property(fget=_get_dtypechar, doc=\"type character of the array.\")\n\n def _get_dtype(self):\n return self._data.dtype\n dtype = property(fget=_get_dtype, doc=\"type of the array elements.\")\n\n def item(self):\n \"Return Python scalar if possible.\"\n if self._mask is not None:\n m = oldnumeric.ravel(self._mask)\n try:\n if m[0]:\n return masked\n except IndexError:\n return masked\n return self._data.item()\n\n def tolist(self, fill_value=None):\n \"Convert to list\"\n return self.filled(fill_value).tolist()\n\n def tostring(self, fill_value=None):\n \"Convert to string\"\n return self.filled(fill_value).tostring()\n\n def unmask (self):\n \"Replace the mask by None if possible.\"\n if self._mask is None: return\n m = make_mask(self._mask, flag=1)\n if m is None:\n self._mask = None\n self._shared_mask = 0\n\n def unshare_mask (self):\n \"If currently sharing mask, make a copy.\"\n if self._shared_mask:\n self._mask = make_mask (self._mask, copy=1, flag=0)\n self._shared_mask = 0\n\n shape = property(_get_shape, _set_shape,\n doc = 'tuple giving the shape of the array')\n\n flat = property(_get_flat, _set_flat,\n doc = 'Access array in flat form.')\n\n real = property(_get_real, _set_real,\n doc = 'Access the real part of the array')\n\n imaginary = property(_get_imaginary, _set_imaginary,\n doc = 'Access the imaginary part of the array')\n\n imag = imaginary\n\n#end class MaskedArray\n\narray = MaskedArray\n\ndef isMaskedArray (x):\n \"Is x a masked array, that is, an instance of MaskedArray?\"\n return isinstance(x, MaskedArray)\n\nisarray = isMaskedArray\nisMA = isMaskedArray #backward compatibility\n\ndef allclose (a, b, fill_value=1, rtol=1.e-5, atol=1.e-8):\n \"\"\" Returns true if all components of a and b are equal\n subject to given tolerances.\n If fill_value is 1, masked values considered equal.\n If fill_value is 0, masked values considered unequal.\n The relative error rtol should be positive and << 1.0\n The absolute error atol comes into play for those elements\n of b that are very small or zero; it says how small a must be also.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a)\n d2 = filled(b)\n x = filled(array(d1, copy=0, mask=m), fill_value).astype(float)\n y = filled(array(d2, copy=0, mask=m), 1).astype(float)\n d = umath.less_equal(umath.absolute(x-y), atol + rtol * umath.absolute(y))\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n\ndef allequal (a, b, fill_value=1):\n \"\"\"\n True if all entries of a and b are equal, using\n fill_value as a truth value where either or both are masked.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n if m is None:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n elif fill_value:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n dm = array(d, mask=m, copy=0)\n return oldnumeric.alltrue(oldnumeric.ravel(filled(dm, 1)))\n else:\n return 0\n\ndef masked_values (data, value, rtol=1.e-5, atol=1.e-8, copy=1):\n \"\"\"\n masked_values(data, value, rtol=1.e-5, atol=1.e-8)\n Create a masked array; mask is None if possible.\n If copy==0, and otherwise possible, result\n may share data values with original array.\n Let d = filled(data, value). Returns d\n masked where abs(data-value)<= atol + rtol * abs(value)\n if d is of a floating point type. Otherwise returns\n masked_object(d, value, copy)\n \"\"\"\n abs = umath.absolute\n d = filled(data, value)\n if issubclass(d.dtype, numeric.floating):\n m = umath.less_equal(abs(d-value), atol+rtol*abs(value))\n m = make_mask(m, flag=1)\n return array(d, mask = m, copy=copy,\n fill_value=value)\n else:\n return masked_object(d, value, copy=copy)\n\ndef masked_object (data, value, copy=1):\n \"Create array masked where exactly data equal to value\"\n d = filled(data, value)\n dm = make_mask(umath.equal(d, value), flag=1)\n return array(d, mask=dm, copy=copy, fill_value=value)\n\ndef arrayrange(start, stop=None, step=1, dtype=None):\n \"\"\"Just like range() except it returns a array whose type can be specified\n by the keyword argument dtypechar.\n \"\"\"\n return array(numeric.arrayrange(start, stop, step, dtype))\n\narange = arrayrange\n\ndef fromstring (s, t):\n \"Construct a masked array from a string. Result will have no mask.\"\n return masked_array(numeric.fromstring(s, t))\n\ndef left_shift (a, n):\n \"Left shift n bits\"\n m = getmask(a)\n if m is None:\n d = umath.left_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.left_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef right_shift (a, n):\n \"Right shift n bits\"\n m = getmask(a)\n if m is None:\n d = umath.right_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.right_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef resize (a, new_shape):\n \"\"\"resize(a, new_shape) returns a new array with the specified shape.\n The original array's total size can be any size.\"\"\"\n m = getmask(a)\n if m is not None:\n m = oldnumeric.resize(m, new_shape)\n result = array(oldnumeric.resize(filled(a), new_shape), mask=m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n \"\"\"\n af = filled(a)\n if isinstance(repeats, types.IntType):\n repeats = tuple([repeats]*(shape(af)[axis]))\n\n m = getmask(a)\n if m is not None:\n m = oldnumeric.repeat(m, repeats, axis)\n d = oldnumeric.repeat(af, repeats, axis)\n result = masked_array(d, m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef identity(n):\n \"\"\"identity(n) returns the identity matrix of shape n x n.\n \"\"\"\n return array(numeric.identity(n))\n\ndef indices (dimensions, dtype=None):\n \"\"\"indices(dimensions,dtype=None) returns an array representing a grid\n of indices with row-only, and column-only variation.\n \"\"\"\n return array(numeric.indices(dimensions, dtype))\n\ndef zeros (shape, dtype=int):\n \"\"\"zeros(n, dtype=int) =\n an array of all zeros of the given length or shape.\"\"\"\n return array(numeric.zeros(shape, dtype))\n\ndef ones (shape, dtype=int):\n \"\"\"ones(n, dtype=int) =\n an array of all ones of the given length or shape.\"\"\"\n return array(numeric.ones(shape, dtype))\n\n\ndef count (a, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n a = masked_array(a)\n return a.count(axis)\n\ndef power (a, b, third=None):\n \"a**b\"\n if third is not None:\n raise MAError, \"3-argument power not supported.\"\n ma = getmask(a)\n mb = getmask(b)\n m = mask_or(ma, mb)\n fa = filled(a, 1)\n fb = filled(b, 1)\n if fb.dtypechar in typecodes[\"Integer\"]:\n return masked_array(umath.power(fa, fb), m)\n md = make_mask(umath.less_equal (fa, 0), flag=1)\n m = mask_or(m, md)\n if m is None:\n return masked_array(umath.power(fa, fb))\n else:\n fa = numeric.where(m, 1, fa)\n return masked_array(umath.power(fa, fb), m)\n\ndef masked_array (a, mask=None, fill_value=None):\n \"\"\"masked_array(a, mask=None) =\n array(a, mask=mask, copy=0, fill_value=fill_value)\n \"\"\"\n return array(a, mask=mask, copy=0, fill_value=fill_value)\n\nsum = add.reduce\nproduct = multiply.reduce\n\ndef average (a, axis=0, weights=None, returned = 0):\n \"\"\"average(a, axis=0, weights=None)\n Computes average along indicated axis.\n If axis is None, average over the entire array\n Inputs can be integer or floating types; result is of type float.\n\n If weights are given, result is sum(a*weights)/(sum(weights)*1.0)\n weights must have a's shape or be the 1-d with length the size\n of a in the given axis.\n\n If returned, return a tuple: the result and the sum of the weights\n or count of values. Results will have the same shape.\n\n masked values in the weights will be set to 0.0\n \"\"\"\n a = masked_array(a)\n mask = a.mask\n ash = a.shape\n if ash == ():\n ash = (1,)\n if axis is None:\n if mask is None:\n if weights is None:\n n = add.reduce(a.raw_data().ravel())\n d = reduce(lambda x, y: x * y, ash, 1.0)\n else:\n w = filled(weights, 0.0).ravel()\n n = umath.add.reduce(a.raw_data().ravel() * w)\n d = umath.add.reduce(w)\n del w\n else:\n if weights is None:\n n = add.reduce(a.ravel())\n w = oldnumeric.choose(mask, (1.0,0.0)).ravel()\n d = umath.add.reduce(w)\n del w\n else:\n w = array(filled(weights, 0.0), float, mask=mask).ravel()\n n = add.reduce(a.ravel() * w)\n d = add.reduce(w)\n del w\n else:\n if mask is None:\n if weights is None:\n d = ash[axis] * 1.0\n n = umath.add.reduce(a.raw_data(), axis)\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = numeric.array(w, float, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * ones(ash, float)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w, r\n else:\n raise ValueError, 'average: weights wrong shape.'\n else:\n if weights is None:\n n = add.reduce(a, axis)\n w = numeric.choose(mask, (1.0, 0.0))\n d = umath.add.reduce(w, axis)\n del w\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = array(w, float, mask=mask, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * masked_array(ones(ash, float), mask)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n else:\n raise ValueError, 'average: weights wrong shape.'\n del w\n #print n, d, repr(mask), repr(weights)\n if n is masked or d is masked: return masked\n result = divide (n, d)\n del n\n\n if isinstance(result, MaskedArray):\n result.unmask()\n if returned:\n if not isinstance(d, MaskedArray):\n d = masked_array(d)\n if not d.shape == result.shape:\n d = ones(result.shape, float) * d\n d.unmask()\n if returned:\n return result, d\n else:\n return result\n\ndef where (condition, x, y):\n \"\"\"where(condition, x, y) is x where condition is nonzero, y otherwise.\n condition must be convertible to an integer array.\n Answer is always the shape of condition.\n The type depends on x and y. It is integer if both x and y are\n the value masked.\n \"\"\"\n fc = filled(not_equal(condition,0), 0)\n if x is masked:\n xv = 0\n xm = 1\n else:\n xv = filled(x)\n xm = getmask(x)\n if xm is None: xm = 0\n if y is masked:\n yv = 0\n ym = 1\n else:\n yv = filled(y)\n ym = getmask(y)\n if ym is None: ym = 0\n d = numeric.choose(fc, (yv, xv))\n md = numeric.choose(fc, (ym, xm))\n m = getmask(condition)\n m = make_mask(mask_or(m, md), copy=0, flag=1)\n return masked_array(d, m)\n\ndef choose (indices, t):\n \"Returns array shaped like indices with elements chosen from t\"\n def fmask (x):\n if x is masked: return 1\n return filled(x)\n def nmask (x):\n if x is masked: return 1\n m = getmask(x)\n if m is None: return 0\n return m\n c = filled(indices,0)\n masks = [nmask(x) for x in t]\n a = [fmask(x) for x in t]\n d = numeric.choose(c, a)\n m = numeric.choose(c, masks)\n m = make_mask(mask_or(m, getmask(indices)), copy=0, flag=1)\n return masked_array(d, m)\n\ndef masked_where(condition, x, copy=1):\n \"\"\"Return x as an array masked where condition is true.\n Also masked where x or condition masked.\n \"\"\"\n cm = filled(condition,1)\n m = mask_or(getmask(x), cm)\n return array(filled(x), copy=copy, mask=m)\n\ndef masked_greater(x, value, copy=1):\n \"masked_greater(x, value) = x masked where x > value\"\n return masked_where(greater(x, value), x, copy)\n\ndef masked_greater_equal(x, value, copy=1):\n \"masked_greater_equal(x, value) = x masked where x >= value\"\n return masked_where(greater_equal(x, value), x, copy)\n\ndef masked_less(x, value, copy=1):\n \"masked_less(x, value) = x masked where x < value\"\n return masked_where(less(x, value), x, copy)\n\ndef masked_less_equal(x, value, copy=1):\n \"masked_less_equal(x, value) = x masked where x <= value\"\n return masked_where(less_equal(x, value), x, copy)\n\ndef masked_not_equal(x, value, copy=1):\n \"masked_not_equal(x, value) = x masked where x != value\"\n d = filled(x,0)\n c = umath.not_equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_equal(x, value, copy=1):\n \"\"\"masked_equal(x, value) = x masked where x == value\n For floating point consider masked_values(x, value) instead.\n \"\"\"\n d = filled(x,0)\n c = umath.equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_inside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are inside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d=filled(x, 0)\n c = umath.logical_and(umath.less_equal(d, v2), umath.greater_equal(d, v1))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef masked_outside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are outside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d = filled(x,0)\n c = umath.logical_or(umath.less(d, v1), umath.greater(d, v2))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef reshape (a, *newshape):\n \"Copy of a with a new shape.\"\n m = getmask(a)\n d = filled(a).reshape(*newshape)\n if m is None:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.reshape(m, *newshape))\n\ndef ravel (a):\n \"a as one-dimensional, may share data and mask\"\n m = getmask(a)\n d = oldnumeric.ravel(filled(a))\n if m is None:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.ravel(m))\n\ndef concatenate (arrays, axis=0):\n \"Concatenate the arrays along the given axis\"\n d = []\n for x in arrays:\n d.append(filled(x))\n d = numeric.concatenate(d, axis)\n for x in arrays:\n if getmask(x) is not None: break\n else:\n return masked_array(d)\n dm = []\n for x in arrays:\n dm.append(getmaskarray(x))\n dm = numeric.concatenate(dm, axis)\n return masked_array(d, mask=dm)\n\ndef take (a, indices, axis=0):\n \"take(a, indices, axis=0) returns selection of items from a.\"\n m = getmask(a)\n d = masked_array(a).raw_data()\n if m is None:\n return masked_array(numeric.take(d, indices, axis))\n else:\n return masked_array(numeric.take(d, indices, axis),\n mask = numeric.take(m, indices, axis))\n\ndef transpose(a, axes=None):\n \"transpose(a, axes=None) reorder dimensions per tuple axes\"\n m = getmask(a)\n d = filled(a)\n if m is None:\n return masked_array(numeric.transpose(d, axes))\n else:\n return masked_array(numeric.transpose(d, axes),\n mask = numeric.transpose(m, axes))\n\n\ndef put(a, indices, values):\n \"\"\"put(a, indices, values) sets storage-indexed locations to corresponding values.\n\n Values and indices are filled if necessary.\n\n \"\"\"\n d = a.raw_data()\n ind = filled(indices)\n v = filled(values)\n numeric.put (d, ind, v)\n m = getmask(a)\n if m is not None:\n a.unshare_mask()\n numeric.put(a.raw_mask(), ind, 0)\n\ndef putmask(a, mask, values):\n \"putmask(a, mask, values) sets a where mask is true.\"\n if mask is None:\n return\n numeric.putmask(a.raw_data(), mask, values)\n m = getmask(a)\n if m is None: return\n a.unshare_mask()\n numeric.putmask(a.raw_mask(), mask, 0)\n\ndef innerproduct(a,b):\n \"\"\"innerproduct(a,b) returns the dot product of two arrays, which has\n shape a.shape[:-1] + b.shape[:-1] with elements computed by summing the\n product of the elements from the last dimensions of a and b.\n Masked elements are replace by zeros.\n \"\"\"\n fa = filled(a, 0)\n fb = filled(b, 0)\n if len(fa.shape) == 0: fa.shape = (1,)\n if len(fb.shape) == 0: fb.shape = (1,)\n return masked_array(numeric.innerproduct(fa, fb))\n\ndef outerproduct(a, b):\n \"\"\"outerproduct(a,b) = {a[i]*b[j]}, has shape (len(a),len(b))\"\"\"\n fa = filled(a,0).ravel()\n fb = filled(b,0).ravel()\n d = numeric.outerproduct(fa, fb)\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n return masked_array(d)\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = make_mask(1-numeric.outerproduct(1-ma,1-mb), copy=0)\n return masked_array(d, m)\n\ndef dot(a, b):\n \"\"\"dot(a,b) returns matrix-multiplication between a and b. The product-sum\n is over the last dimension of a and the second-to-last dimension of b.\n Masked values are replaced by zeros. See also innerproduct.\n \"\"\"\n return innerproduct(filled(a,0), numeric.swapaxes(filled(b,0), -1, -2))\n\ndef compress(condition, x, dimension=-1):\n \"\"\"Select those parts of x for which condition is true.\n Masked values in condition are considered false.\n \"\"\"\n c = filled(condition, 0)\n m = getmask(x)\n if m is not None:\n m=numeric.compress(c, m, dimension)\n d = numeric.compress(c, filled(x), dimension)\n return masked_array(d, m)\n\nclass _minimum_operation:\n \"Object to calculate minima\"\n def __init__ (self):\n \"\"\"minimum(a, b) or minimum(a)\n In one argument case returns the scalar minimum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is None:\n d = amin(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amin(ac.raw_data())\n else:\n return where(less(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is None:\n t = filled(target)\n return masked_array (umath.minimum.reduce (t, axis))\n else:\n t = umath.minimum.reduce(filled(target, minimum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n m = None\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.minimum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nminimum = _minimum_operation ()\n\nclass _maximum_operation:\n \"Object to calculate maxima\"\n def __init__ (self):\n \"\"\"maximum(a, b) or maximum(a)\n In one argument case returns the scalar maximum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is None:\n d = amax(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amax(ac.raw_data())\n else:\n return where(greater(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is None:\n t = filled(target)\n return masked_array (umath.maximum.reduce (t, axis))\n else:\n t = umath.maximum.reduce(filled(target, maximum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n m = None\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.maximum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nmaximum = _maximum_operation ()\n\ndef sort (x, axis = -1, fill_value=None):\n \"\"\"If x does not have a mask, return a masked array formed from the\n result of numeric.sort(x, axis).\n Otherwise, fill x with fill_value. Sort it.\n Set a mask where the result is equal to fill_value.\n Note that this may have unintended consequences if the data contains the\n fill value at a non-masked site.\n\n If fill_value is not given the default fill value for x's type will be\n used.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n d = filled(x, fill_value)\n s = oldnumeric.sort(d, axis)\n if getmask(x) is None:\n return masked_array(s)\n return masked_values(s, fill_value, copy=0)\n\ndef diagonal(a, k = 0, axis1=0, axis2=1):\n \"\"\"diagonal(a,k=0,axis1=0, axis2=1) = the k'th diagonal of a\"\"\"\n d = oldnumeric.diagonal(filled(a), k, axis1, axis2)\n m = getmask(a)\n if m is None:\n return masked_array(d, m)\n else:\n return masked_array(d, oldnumeric.diagonal(m, k, axis1, axis2))\n\ndef argsort (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for sorting along given axis.\n if fill_value is None, use get_fill_value(x)\n Returns a numpy array.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argsort(d, axis)\n\ndef argmin (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return indices for minimum values along given axis.\n if fill_value is None, use get_fill_value(x).\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argmin(d, axis)\n\ndef argmax (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for maximum along given axis.\n if fill_value is None, use -get_fill_value(x) if it exists.\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n try:\n fill_value = - fill_value\n except:\n pass\n d = filled(x, fill_value)\n return oldnumeric.argmax(d, axis)\n\ndef fromfunction (f, s):\n \"\"\"apply f to s to create array as in umath.\"\"\"\n return masked_array(numeric.fromfunction(f,s))\n\ndef asarray(data, dtype=None):\n \"\"\"asarray(data, dtype) = array(data, dtype, copy=0)\n \"\"\"\n if isinstance(data, MaskedArray) and \\\n (dtype is None or dtype == data.dtype):\n return data\n return array(data, dtype=dtype, copy=0)\n\n# Add methods to support ndarray interface\n# XXX: I is better to to change the masked_*_operation adaptors\n# XXX: to wrap ndarray methods directly to create ma.array methods.\nfrom types import MethodType\ndef _m(f):\n return MethodType(f, None, array)\ndef not_implemented(*args, **kwds):\n raise NotImplementedError, \"not yet implemented for numpy.ma arrays\"\narray.all = _m(alltrue)\narray.any = _m(sometrue)\narray.argmax = _m(argmax)\narray.argmin = _m(argmin)\narray.argsort = _m(argsort)\narray.base = property(_m(not_implemented))\narray.byteswap = _m(not_implemented)\n\ndef _choose(self, *args):\n return choose(self, args)\narray.choose = _m(_choose)\ndel _choose\n\narray.clip = _m(not_implemented)\n\ndef _compress(self, cond, axis=None):\n return compress(cond, self, axis)\narray.compress = _m(_compress)\ndel _compress\n\narray.conj = array.conjugate = _m(conjugate)\narray.copy = _m(not_implemented)\narray.cumprod = _m(not_implemented)\narray.cumsum = _m(not_implemented)\narray.diagonal = _m(diagonal)\narray.dtypedescr = property(_m(not_implemented))\narray.dtypestr = property(_m(not_implemented))\narray.dump = _m(not_implemented)\narray.dumps = _m(not_implemented)\narray.fill = _m(not_implemented)\narray.flags = property(_m(not_implemented))\narray.flatten = _m(ravel)\narray.getfield = _m(not_implemented)\narray.max = _m(maximum)\narray.mean = _m(average)\narray.min = _m(minimum)\narray.nbytes = property(_m(not_implemented))\narray.ndim = _m(not_implemented)\narray.newbyteorder = _m(not_implemented)\narray.nonzero = _m(nonzero)\narray.prod = _m(product)\narray.ptp = _m(not_implemented)\narray.repeat = _m(repeat)\narray.resize = _m(resize)\narray.searchsorted = _m(not_implemented)\narray.setfield = _m(not_implemented)\narray.setflags = _m(not_implemented)\narray.sort = _m(not_implemented) # NB: ndarray.sort is inplace\narray.squeeze = _m(not_implemented)\narray.std = _m(not_implemented)\narray.strides = property(_m(not_implemented))\narray.sum = _m(sum)\narray.swapaxes = _m(not_implemented)\narray.take = _m(take)\narray.tofile = _m(not_implemented)\narray.trace = _m(not_implemented)\narray.transpose = _m(transpose)\narray.var = _m(not_implemented)\narray.view = _m(not_implemented)\ndel _m, MethodType, not_implemented\n\n\nmasked = MaskedArray([0], int, mask=[1])[0:0]\nmasked = masked[0:0]\n", + "methods": [ + { + "name": "__init__", + "long_name": "__init__( self , args = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 24, + "end_line": 26, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 27, + "end_line": 29, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , display )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "display" + ], + "start_line": 34, + "end_line": 37, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "display", + "long_name": "display( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 39, + "end_line": 41, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "set_display", + "long_name": "set_display( self , s )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "s" + ], + "start_line": 43, + "end_line": 45, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enabled", + "long_name": "enabled( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 47, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enable", + "long_name": "enable( self , flag = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "flag" + ], + "start_line": 51, + "end_line": 53, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 55, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "default_fill_value", + "long_name": "default_fill_value( obj )", + "filename": "ma.py", + "nloc": 25, + "complexity": 13, + "token_count": 144, + "parameters": [ + "obj" + ], + "start_line": 70, + "end_line": 94, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "minimum_fill_value", + "long_name": "minimum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 105, + "parameters": [ + "obj" + ], + "start_line": 96, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "maximum_fill_value", + "long_name": "maximum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 103, + "parameters": [ + "obj" + ], + "start_line": 113, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( a , fill_value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 2, + "token_count": 20, + "parameters": [ + "a", + "fill_value" + ], + "start_line": 130, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "getmask", + "long_name": "getmask( a )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "a" + ], + "start_line": 135, + "end_line": 142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "getmaskarray", + "long_name": "getmaskarray( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 144, + "end_line": 153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "is_mask", + "long_name": "is_mask( m )", + "filename": "ma.py", + "nloc": 6, + "complexity": 4, + "token_count": 33, + "parameters": [ + "m" + ], + "start_line": 155, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "make_mask", + "long_name": "make_mask( m , copy = 0 , flag = 0 )", + "filename": "ma.py", + "nloc": 17, + "complexity": 7, + "token_count": 107, + "parameters": [ + "m", + "copy", + "flag" + ], + "start_line": 164, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "make_mask_none", + "long_name": "make_mask_none( s )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 25, + "parameters": [ + "s" + ], + "start_line": 189, + "end_line": 193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "mask_or", + "long_name": "mask_or( m1 , m2 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 5, + "token_count": 52, + "parameters": [ + "m1", + "m2" + ], + "start_line": 195, + "end_line": 202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "filled", + "long_name": "filled( a , value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 5, + "token_count": 70, + "parameters": [ + "a", + "value" + ], + "start_line": 204, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "get_fill_value", + "long_name": "get_fill_value( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 224, + "end_line": 233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "common_fill_value", + "long_name": "common_fill_value( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a", + "b" + ], + "start_line": 235, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , y1 , y2 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "y1", + "y2" + ], + "start_line": 245, + "end_line": 248, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 35, + "parameters": [ + "self", + "x" + ], + "start_line": 250, + "end_line": 254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , eps )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "eps" + ], + "start_line": 258, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "x" + ], + "start_line": 262, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 268, + "end_line": 270, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 272, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 278, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 282, + "end_line": 284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , aufunc , fill = 0 , domain = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "aufunc", + "fill", + "domain" + ], + "start_line": 287, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 16, + "complexity": 5, + "token_count": 112, + "parameters": [ + "self", + "a", + "args", + "kwargs" + ], + "start_line": 298, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 316, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , tolerance = divide_tolerance )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "tolerance" + ], + "start_line": 321, + "end_line": 322, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 323, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , domain , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 53, + "parameters": [ + "self", + "abfunc", + "domain", + "fillx", + "filly" + ], + "start_line": 330, + "end_line": 338, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 147, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 340, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 363, + "end_line": 364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "abfunc", + "fillx", + "filly" + ], + "start_line": 367, + "end_line": 374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 113, + "parameters": [ + "self", + "a", + "b", + "args", + "kwargs" + ], + "start_line": 376, + "end_line": 390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 20, + "complexity": 6, + "token_count": 157, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 392, + "end_line": 412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 414, + "end_line": 425, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "accumulate", + "long_name": "accumulate( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 427, + "end_line": 430, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 431, + "end_line": 432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "rank", + "long_name": "rank( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 494, + "end_line": 495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 497, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( object , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 21, + "parameters": [ + "object", + "axis" + ], + "start_line": 500, + "end_line": 501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , data , dtype = None , copy = True , fortran = False , mask = None , fill_value = None )", + "filename": "ma.py", + "nloc": 56, + "complexity": 18, + "token_count": 379, + "parameters": [ + "self", + "data", + "dtype", + "copy", + "fortran", + "mask", + "fill_value" + ], + "start_line": 532, + "end_line": 594, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "__array__", + "long_name": "__array__( self , t = None )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 67, + "parameters": [ + "self", + "t" + ], + "start_line": 596, + "end_line": 611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__array_wrap__", + "long_name": "__array_wrap__( self , array )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "array" + ], + "start_line": 613, + "end_line": 617, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_shape", + "long_name": "_get_shape( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 619, + "end_line": 621, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_set_shape", + "long_name": "_set_shape( self , newshape )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "newshape" + ], + "start_line": 623, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_get_flat", + "long_name": "_get_flat( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 630, + "end_line": 639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "_set_flat", + "long_name": "_set_flat( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "value" + ], + "start_line": 641, + "end_line": 644, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_real", + "long_name": "_get_real( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 646, + "end_line": 653, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_real", + "long_name": "_set_real( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 655, + "end_line": 658, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_imaginary", + "long_name": "_get_imaginary( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 660, + "end_line": 667, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_imaginary", + "long_name": "_set_imaginary( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 669, + "end_line": 672, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 674, + "end_line": 691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "ma.py", + "nloc": 42, + "complexity": 5, + "token_count": 207, + "parameters": [ + "self" + ], + "start_line": 693, + "end_line": 738, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 1 + }, + { + "name": "__float__", + "long_name": "__float__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 740, + "end_line": 745, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__int__", + "long_name": "__int__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 747, + "end_line": 752, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , i )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 70, + "parameters": [ + "self", + "i" + ], + "start_line": 754, + "end_line": 768, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 770, + "end_line": 778, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__setitem__", + "long_name": "__setitem__( self , index , value )", + "filename": "ma.py", + "nloc": 27, + "complexity": 7, + "token_count": 157, + "parameters": [ + "self", + "index", + "value" + ], + "start_line": 785, + "end_line": 811, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "__setslice__", + "long_name": "__setslice__( self , i , j , value )", + "filename": "ma.py", + "nloc": 23, + "complexity": 7, + "token_count": 155, + "parameters": [ + "self", + "i", + "j", + "value" + ], + "start_line": 813, + "end_line": 835, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "__nonzero__", + "long_name": "__nonzero__( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 837, + "end_line": 847, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 849, + "end_line": 852, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__and__", + "long_name": "__and__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 854, + "end_line": 856, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__or__", + "long_name": "__or__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 858, + "end_line": 860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__xor__", + "long_name": "__xor__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 862, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__abs__", + "long_name": "__abs__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 870, + "end_line": 872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__neg__", + "long_name": "__neg__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 874, + "end_line": 876, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pos__", + "long_name": "__pos__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 878, + "end_line": 880, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__add__", + "long_name": "__add__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 882, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mod__", + "long_name": "__mod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 888, + "end_line": 890, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rmod__", + "long_name": "__rmod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 892, + "end_line": 894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__lshift__", + "long_name": "__lshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 896, + "end_line": 897, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__rshift__", + "long_name": "__rshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 899, + "end_line": 900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__sub__", + "long_name": "__sub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 902, + "end_line": 904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rsub__", + "long_name": "__rsub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 906, + "end_line": 908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mul__", + "long_name": "__mul__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 910, + "end_line": 912, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__div__", + "long_name": "__div__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 916, + "end_line": 918, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rdiv__", + "long_name": "__rdiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 920, + "end_line": 922, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__truediv__", + "long_name": "__truediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 924, + "end_line": 926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rtruediv__", + "long_name": "__rtruediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 928, + "end_line": 930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__floordiv__", + "long_name": "__floordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 932, + "end_line": 934, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rfloordiv__", + "long_name": "__rfloordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 936, + "end_line": 938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pow__", + "long_name": "__pow__( self , other , third = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "other", + "third" + ], + "start_line": 940, + "end_line": 942, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__sqrt__", + "long_name": "__sqrt__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 944, + "end_line": 946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__iadd__", + "long_name": "__iadd__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 948, + "end_line": 989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__imul__", + "long_name": "__imul__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 251, + "parameters": [ + "self", + "other" + ], + "start_line": 991, + "end_line": 1032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__isub__", + "long_name": "__isub__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 1034, + "end_line": 1075, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__idiv__", + "long_name": "__idiv__( self , other )", + "filename": "ma.py", + "nloc": 38, + "complexity": 12, + "token_count": 233, + "parameters": [ + "self", + "other" + ], + "start_line": 1079, + "end_line": 1116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 1 + }, + { + "name": "__eq__", + "long_name": "__eq__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1118, + "end_line": 1119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ne__", + "long_name": "__ne__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1121, + "end_line": 1122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__lt__", + "long_name": "__lt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1124, + "end_line": 1125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__le__", + "long_name": "__le__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1127, + "end_line": 1128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__gt__", + "long_name": "__gt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1130, + "end_line": 1131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ge__", + "long_name": "__ge__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1133, + "end_line": 1134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "astype", + "long_name": "astype( self , tc )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "tc" + ], + "start_line": 1136, + "end_line": 1139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "byte_swapped", + "long_name": "byte_swapped( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 1141, + "end_line": 1145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "compressed", + "long_name": "compressed( self )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 1147, + "end_line": 1155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "count", + "long_name": "count( self , axis = None )", + "filename": "ma.py", + "nloc": 29, + "complexity": 7, + "token_count": 173, + "parameters": [ + "self", + "axis" + ], + "start_line": 1157, + "end_line": 1185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "dot", + "long_name": "dot( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1187, + "end_line": 1189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "fill_value", + "long_name": "fill_value( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1191, + "end_line": 1193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "filled", + "long_name": "filled( self , fill_value = None )", + "filename": "ma.py", + "nloc": 31, + "complexity": 9, + "token_count": 183, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1195, + "end_line": 1235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + }, + { + "name": "ids", + "long_name": "ids( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 1237, + "end_line": 1239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "iscontiguous", + "long_name": "iscontiguous( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 1241, + "end_line": 1243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "itemsize", + "long_name": "itemsize( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 1245, + "end_line": 1247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1250, + "end_line": 1252, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "put", + "long_name": "put( self , values )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "values" + ], + "start_line": 1254, + "end_line": 1264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "putmask", + "long_name": "putmask( self , values )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "values" + ], + "start_line": 1266, + "end_line": 1274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "ravel", + "long_name": "ravel( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 1276, + "end_line": 1281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "raw_data", + "long_name": "raw_data( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1283, + "end_line": 1287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "raw_mask", + "long_name": "raw_mask( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1291, + "end_line": 1295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "reshape", + "long_name": "reshape( self , * s )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self", + "s" + ], + "start_line": 1299, + "end_line": 1306, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( self , v = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self", + "v" + ], + "start_line": 1308, + "end_line": 1312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_size", + "long_name": "_get_size( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1314, + "end_line": 1315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtypechar", + "long_name": "_get_dtypechar( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1319, + "end_line": 1320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtype", + "long_name": "_get_dtype( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1323, + "end_line": 1324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "item", + "long_name": "item( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 4, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 1327, + "end_line": 1336, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "tolist", + "long_name": "tolist( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1338, + "end_line": 1340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "tostring", + "long_name": "tostring( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1342, + "end_line": 1344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "unmask", + "long_name": "unmask( self )", + "filename": "ma.py", + "nloc": 7, + "complexity": 3, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 1346, + "end_line": 1352, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "unshare_mask", + "long_name": "unshare_mask( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 1354, + "end_line": 1358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "isMaskedArray", + "long_name": "isMaskedArray( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "x" + ], + "start_line": 1378, + "end_line": 1380, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "allclose", + "long_name": "allclose( a , b , fill_value = 1 , rtol = 1 . e - 5 , atol = 1 . e - 8 )", + "filename": "ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 140, + "parameters": [ + "a", + "b", + "fill_value", + "rtol", + "atol" + ], + "start_line": 1385, + "end_line": 1400, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "allequal", + "long_name": "allequal( a , b , fill_value = 1 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 3, + "token_count": 125, + "parameters": [ + "a", + "b", + "fill_value" + ], + "start_line": 1402, + "end_line": 1420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "masked_values", + "long_name": "masked_values( data , value , rtol = 1 . e - 5 , atol = 1 . e - 8 , copy = 1 )", + "filename": "ma.py", + "nloc": 10, + "complexity": 2, + "token_count": 115, + "parameters": [ + "data", + "value", + "rtol", + "atol", + "copy" + ], + "start_line": 1422, + "end_line": 1441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "masked_object", + "long_name": "masked_object( data , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "data", + "value", + "copy" + ], + "start_line": 1443, + "end_line": 1447, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayrange", + "long_name": "arrayrange( start , stop = None , step = 1 , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 34, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 1449, + "end_line": 1453, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "fromstring", + "long_name": "fromstring( s , t )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "s", + "t" + ], + "start_line": 1457, + "end_line": 1459, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "left_shift", + "long_name": "left_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1461, + "end_line": 1469, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "right_shift", + "long_name": "right_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1471, + "end_line": 1479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 1481, + "end_line": 1489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 101, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 1491, + "end_line": 1506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "identity", + "long_name": "identity( n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "n" + ], + "start_line": 1508, + "end_line": 1511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "indices", + "long_name": "indices( dimensions , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "dimensions", + "dtype" + ], + "start_line": 1513, + "end_line": 1517, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "zeros", + "long_name": "zeros( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1519, + "end_line": 1522, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ones", + "long_name": "ones( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1524, + "end_line": 1527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "count", + "long_name": "count( a , axis = None )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a", + "axis" + ], + "start_line": 1530, + "end_line": 1533, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "power", + "long_name": "power( a , b , third = None )", + "filename": "ma.py", + "nloc": 18, + "complexity": 4, + "token_count": 152, + "parameters": [ + "a", + "b", + "third" + ], + "start_line": 1535, + "end_line": 1552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "masked_array", + "long_name": "masked_array( a , mask = None , fill_value = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "mask", + "fill_value" + ], + "start_line": 1554, + "end_line": 1558, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "average", + "long_name": "average( a , axis = 0 , weights = None , returned = 0 )", + "filename": "ma.py", + "nloc": 92, + "complexity": 22, + "token_count": 741, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 1563, + "end_line": 1670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "where", + "long_name": "where( condition , x , y )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 149, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 1672, + "end_line": 1698, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "choose.fmask", + "long_name": "choose.fmask( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 2, + "token_count": 17, + "parameters": [ + "x" + ], + "start_line": 1702, + "end_line": 1704, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "choose.nmask", + "long_name": "choose.nmask( x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 3, + "token_count": 27, + "parameters": [ + "x" + ], + "start_line": 1705, + "end_line": 1709, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "choose", + "long_name": "choose( indices , t )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 93, + "parameters": [ + "indices", + "t" + ], + "start_line": 1700, + "end_line": 1716, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "masked_where", + "long_name": "masked_where( condition , x , copy = 1 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 47, + "parameters": [ + "condition", + "x", + "copy" + ], + "start_line": 1718, + "end_line": 1724, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "masked_greater", + "long_name": "masked_greater( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1726, + "end_line": 1728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_greater_equal", + "long_name": "masked_greater_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1730, + "end_line": 1732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less", + "long_name": "masked_less( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1734, + "end_line": 1736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less_equal", + "long_name": "masked_less_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1738, + "end_line": 1740, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_not_equal", + "long_name": "masked_not_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1742, + "end_line": 1747, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "masked_equal", + "long_name": "masked_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1749, + "end_line": 1756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "masked_inside", + "long_name": "masked_inside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1758, + "end_line": 1769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "masked_outside", + "long_name": "masked_outside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1771, + "end_line": 1782, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , * newshape )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 56, + "parameters": [ + "a", + "newshape" + ], + "start_line": 1784, + "end_line": 1791, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( a )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "a" + ], + "start_line": 1793, + "end_line": 1800, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "concatenate", + "long_name": "concatenate( arrays , axis = 0 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 5, + "token_count": 97, + "parameters": [ + "arrays", + "axis" + ], + "start_line": 1802, + "end_line": 1816, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 76, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 1818, + "end_line": 1826, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "a", + "axes" + ], + "start_line": 1828, + "end_line": 1836, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , indices , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 70, + "parameters": [ + "a", + "indices", + "values" + ], + "start_line": 1839, + "end_line": 1852, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 61, + "parameters": [ + "a", + "mask", + "values" + ], + "start_line": 1854, + "end_line": 1862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "innerproduct", + "long_name": "innerproduct( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 3, + "token_count": 72, + "parameters": [ + "a", + "b" + ], + "start_line": 1864, + "end_line": 1874, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "outerproduct", + "long_name": "outerproduct( a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 110, + "parameters": [ + "a", + "b" + ], + "start_line": 1876, + "end_line": 1888, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dot", + "long_name": "dot( a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 36, + "parameters": [ + "a", + "b" + ], + "start_line": 1890, + "end_line": 1895, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , x , dimension = - 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 67, + "parameters": [ + "condition", + "x", + "dimension" + ], + "start_line": 1897, + "end_line": 1906, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1910, + "end_line": 1914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1916, + "end_line": 1929, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1931, + "end_line": 1940, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1942, + "end_line": 1953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1959, + "end_line": 1963, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1965, + "end_line": 1978, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1980, + "end_line": 1989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1991, + "end_line": 2002, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "sort", + "long_name": "sort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 8, + "complexity": 3, + "token_count": 68, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2006, + "end_line": 2023, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , k = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 73, + "parameters": [ + "a", + "k", + "axis1", + "axis2" + ], + "start_line": 2025, + "end_line": 2032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2034, + "end_line": 2041, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2043, + "end_line": 2051, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 52, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2053, + "end_line": 2067, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "fromfunction", + "long_name": "fromfunction( f , s )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "f", + "s" + ], + "start_line": 2069, + "end_line": 2071, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( data , dtype = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 46, + "parameters": [ + "data", + "dtype" + ], + "start_line": 2073, + "end_line": 2079, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_m", + "long_name": "_m( f )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "f" + ], + "start_line": 2085, + "end_line": 2086, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "not_implemented", + "long_name": "not_implemented( * args , ** kwds )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "args", + "kwds" + ], + "start_line": 2087, + "end_line": 2088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_choose", + "long_name": "_choose( self , * args )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 2097, + "end_line": 2098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_compress", + "long_name": "_compress( self , cond , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "cond", + "axis" + ], + "start_line": 2104, + "end_line": 2105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "__init__", + "long_name": "__init__( self , args = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 24, + "end_line": 26, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 27, + "end_line": 29, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , display )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "display" + ], + "start_line": 34, + "end_line": 37, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "display", + "long_name": "display( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 39, + "end_line": 41, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "set_display", + "long_name": "set_display( self , s )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "s" + ], + "start_line": 43, + "end_line": 45, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enabled", + "long_name": "enabled( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 47, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enable", + "long_name": "enable( self , flag = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "flag" + ], + "start_line": 51, + "end_line": 53, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 55, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "default_fill_value", + "long_name": "default_fill_value( obj )", + "filename": "ma.py", + "nloc": 25, + "complexity": 13, + "token_count": 144, + "parameters": [ + "obj" + ], + "start_line": 70, + "end_line": 94, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "minimum_fill_value", + "long_name": "minimum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 105, + "parameters": [ + "obj" + ], + "start_line": 96, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "maximum_fill_value", + "long_name": "maximum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 103, + "parameters": [ + "obj" + ], + "start_line": 113, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( a , fill_value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 2, + "token_count": 20, + "parameters": [ + "a", + "fill_value" + ], + "start_line": 130, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "getmask", + "long_name": "getmask( a )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "a" + ], + "start_line": 135, + "end_line": 142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "getmaskarray", + "long_name": "getmaskarray( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 144, + "end_line": 153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "is_mask", + "long_name": "is_mask( m )", + "filename": "ma.py", + "nloc": 6, + "complexity": 4, + "token_count": 33, + "parameters": [ + "m" + ], + "start_line": 155, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "make_mask", + "long_name": "make_mask( m , copy = 0 , flag = 0 )", + "filename": "ma.py", + "nloc": 17, + "complexity": 7, + "token_count": 107, + "parameters": [ + "m", + "copy", + "flag" + ], + "start_line": 164, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "make_mask_none", + "long_name": "make_mask_none( s )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 25, + "parameters": [ + "s" + ], + "start_line": 189, + "end_line": 193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "mask_or", + "long_name": "mask_or( m1 , m2 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 5, + "token_count": 52, + "parameters": [ + "m1", + "m2" + ], + "start_line": 195, + "end_line": 202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "filled", + "long_name": "filled( a , value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 5, + "token_count": 70, + "parameters": [ + "a", + "value" + ], + "start_line": 204, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "get_fill_value", + "long_name": "get_fill_value( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 224, + "end_line": 233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "common_fill_value", + "long_name": "common_fill_value( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a", + "b" + ], + "start_line": 235, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , y1 , y2 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "y1", + "y2" + ], + "start_line": 245, + "end_line": 248, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 35, + "parameters": [ + "self", + "x" + ], + "start_line": 250, + "end_line": 254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , eps )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "eps" + ], + "start_line": 258, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "x" + ], + "start_line": 262, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 268, + "end_line": 270, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 272, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 278, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 282, + "end_line": 284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , aufunc , fill = 0 , domain = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "aufunc", + "fill", + "domain" + ], + "start_line": 287, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 16, + "complexity": 5, + "token_count": 112, + "parameters": [ + "self", + "a", + "args", + "kwargs" + ], + "start_line": 298, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 316, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , tolerance = divide_tolerance )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "tolerance" + ], + "start_line": 321, + "end_line": 322, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 323, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , domain , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 53, + "parameters": [ + "self", + "abfunc", + "domain", + "fillx", + "filly" + ], + "start_line": 330, + "end_line": 338, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 147, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 340, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 363, + "end_line": 364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "abfunc", + "fillx", + "filly" + ], + "start_line": 367, + "end_line": 374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 113, + "parameters": [ + "self", + "a", + "b", + "args", + "kwargs" + ], + "start_line": 376, + "end_line": 390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 20, + "complexity": 6, + "token_count": 157, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 392, + "end_line": 412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 414, + "end_line": 425, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "accumulate", + "long_name": "accumulate( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 427, + "end_line": 430, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 431, + "end_line": 432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "rank", + "long_name": "rank( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 494, + "end_line": 495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 497, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( object , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 21, + "parameters": [ + "object", + "axis" + ], + "start_line": 500, + "end_line": 501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , data , dtype = None , copy = True , fortran = False , mask = None , fill_value = None )", + "filename": "ma.py", + "nloc": 56, + "complexity": 18, + "token_count": 379, + "parameters": [ + "self", + "data", + "dtype", + "copy", + "fortran", + "mask", + "fill_value" + ], + "start_line": 532, + "end_line": 594, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "__array__", + "long_name": "__array__( self , t = None )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 67, + "parameters": [ + "self", + "t" + ], + "start_line": 596, + "end_line": 611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__array_wrap__", + "long_name": "__array_wrap__( self , array )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "array" + ], + "start_line": 613, + "end_line": 617, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_shape", + "long_name": "_get_shape( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 619, + "end_line": 621, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_set_shape", + "long_name": "_set_shape( self , newshape )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "newshape" + ], + "start_line": 623, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_get_flat", + "long_name": "_get_flat( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 630, + "end_line": 639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "_set_flat", + "long_name": "_set_flat( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "value" + ], + "start_line": 641, + "end_line": 644, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_real", + "long_name": "_get_real( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 646, + "end_line": 653, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_real", + "long_name": "_set_real( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 655, + "end_line": 658, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_imaginary", + "long_name": "_get_imaginary( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 660, + "end_line": 667, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_imaginary", + "long_name": "_set_imaginary( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 669, + "end_line": 672, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 674, + "end_line": 691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "ma.py", + "nloc": 42, + "complexity": 5, + "token_count": 207, + "parameters": [ + "self" + ], + "start_line": 693, + "end_line": 738, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 1 + }, + { + "name": "__float__", + "long_name": "__float__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 740, + "end_line": 745, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__int__", + "long_name": "__int__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 747, + "end_line": 752, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , i )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 70, + "parameters": [ + "self", + "i" + ], + "start_line": 754, + "end_line": 768, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 770, + "end_line": 778, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__setitem__", + "long_name": "__setitem__( self , index , value )", + "filename": "ma.py", + "nloc": 27, + "complexity": 7, + "token_count": 157, + "parameters": [ + "self", + "index", + "value" + ], + "start_line": 785, + "end_line": 811, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "__setslice__", + "long_name": "__setslice__( self , i , j , value )", + "filename": "ma.py", + "nloc": 23, + "complexity": 7, + "token_count": 155, + "parameters": [ + "self", + "i", + "j", + "value" + ], + "start_line": 813, + "end_line": 835, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "__nonzero__", + "long_name": "__nonzero__( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 837, + "end_line": 847, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 849, + "end_line": 852, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__and__", + "long_name": "__and__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 854, + "end_line": 856, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__or__", + "long_name": "__or__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 858, + "end_line": 860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__xor__", + "long_name": "__xor__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 862, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__abs__", + "long_name": "__abs__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 870, + "end_line": 872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__neg__", + "long_name": "__neg__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 874, + "end_line": 876, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pos__", + "long_name": "__pos__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 878, + "end_line": 880, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__add__", + "long_name": "__add__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 882, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mod__", + "long_name": "__mod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 888, + "end_line": 890, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rmod__", + "long_name": "__rmod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 892, + "end_line": 894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__lshift__", + "long_name": "__lshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 896, + "end_line": 897, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__rshift__", + "long_name": "__rshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 899, + "end_line": 900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__sub__", + "long_name": "__sub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 902, + "end_line": 904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rsub__", + "long_name": "__rsub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 906, + "end_line": 908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mul__", + "long_name": "__mul__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 910, + "end_line": 912, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__div__", + "long_name": "__div__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 916, + "end_line": 918, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rdiv__", + "long_name": "__rdiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 920, + "end_line": 922, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__truediv__", + "long_name": "__truediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 924, + "end_line": 926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rtruediv__", + "long_name": "__rtruediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 928, + "end_line": 930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__floordiv__", + "long_name": "__floordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 932, + "end_line": 934, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rfloordiv__", + "long_name": "__rfloordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 936, + "end_line": 938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pow__", + "long_name": "__pow__( self , other , third = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "other", + "third" + ], + "start_line": 940, + "end_line": 942, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__sqrt__", + "long_name": "__sqrt__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 944, + "end_line": 946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__iadd__", + "long_name": "__iadd__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 948, + "end_line": 989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__imul__", + "long_name": "__imul__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 251, + "parameters": [ + "self", + "other" + ], + "start_line": 991, + "end_line": 1032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__isub__", + "long_name": "__isub__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 1034, + "end_line": 1075, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__idiv__", + "long_name": "__idiv__( self , other )", + "filename": "ma.py", + "nloc": 38, + "complexity": 12, + "token_count": 233, + "parameters": [ + "self", + "other" + ], + "start_line": 1079, + "end_line": 1116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 1 + }, + { + "name": "__eq__", + "long_name": "__eq__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1118, + "end_line": 1119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ne__", + "long_name": "__ne__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1121, + "end_line": 1122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__lt__", + "long_name": "__lt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1124, + "end_line": 1125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__le__", + "long_name": "__le__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1127, + "end_line": 1128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__gt__", + "long_name": "__gt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1130, + "end_line": 1131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ge__", + "long_name": "__ge__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1133, + "end_line": 1134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "astype", + "long_name": "astype( self , tc )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "tc" + ], + "start_line": 1136, + "end_line": 1139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "byte_swapped", + "long_name": "byte_swapped( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 1141, + "end_line": 1145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "compressed", + "long_name": "compressed( self )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 1147, + "end_line": 1155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "count", + "long_name": "count( self , axis = None )", + "filename": "ma.py", + "nloc": 29, + "complexity": 7, + "token_count": 173, + "parameters": [ + "self", + "axis" + ], + "start_line": 1157, + "end_line": 1185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "dot", + "long_name": "dot( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1187, + "end_line": 1189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "fill_value", + "long_name": "fill_value( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1191, + "end_line": 1193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "filled", + "long_name": "filled( self , fill_value = None )", + "filename": "ma.py", + "nloc": 31, + "complexity": 9, + "token_count": 183, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1195, + "end_line": 1235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + }, + { + "name": "ids", + "long_name": "ids( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 1237, + "end_line": 1239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "iscontiguous", + "long_name": "iscontiguous( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 1241, + "end_line": 1243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "itemsize", + "long_name": "itemsize( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 1245, + "end_line": 1247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1250, + "end_line": 1252, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "put", + "long_name": "put( self , values )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "values" + ], + "start_line": 1254, + "end_line": 1264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "putmask", + "long_name": "putmask( self , values )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "values" + ], + "start_line": 1266, + "end_line": 1274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "ravel", + "long_name": "ravel( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 1276, + "end_line": 1281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "raw_data", + "long_name": "raw_data( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1283, + "end_line": 1287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "raw_mask", + "long_name": "raw_mask( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1291, + "end_line": 1295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "reshape", + "long_name": "reshape( self , * s )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self", + "s" + ], + "start_line": 1299, + "end_line": 1306, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( self , v = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self", + "v" + ], + "start_line": 1308, + "end_line": 1312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_size", + "long_name": "_get_size( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1314, + "end_line": 1315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtypechar", + "long_name": "_get_dtypechar( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1319, + "end_line": 1320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtype", + "long_name": "_get_dtype( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1323, + "end_line": 1324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "item", + "long_name": "item( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 4, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 1327, + "end_line": 1336, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "tolist", + "long_name": "tolist( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1338, + "end_line": 1340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "tostring", + "long_name": "tostring( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1342, + "end_line": 1344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "unmask", + "long_name": "unmask( self )", + "filename": "ma.py", + "nloc": 7, + "complexity": 3, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 1346, + "end_line": 1352, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "unshare_mask", + "long_name": "unshare_mask( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 1354, + "end_line": 1358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "isMaskedArray", + "long_name": "isMaskedArray( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "x" + ], + "start_line": 1378, + "end_line": 1380, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "allclose", + "long_name": "allclose( a , b , fill_value = 1 , rtol = 1 . e - 5 , atol = 1 . e - 8 )", + "filename": "ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 140, + "parameters": [ + "a", + "b", + "fill_value", + "rtol", + "atol" + ], + "start_line": 1385, + "end_line": 1400, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "allequal", + "long_name": "allequal( a , b , fill_value = 1 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 3, + "token_count": 125, + "parameters": [ + "a", + "b", + "fill_value" + ], + "start_line": 1402, + "end_line": 1420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "masked_values", + "long_name": "masked_values( data , value , rtol = 1 . e - 5 , atol = 1 . e - 8 , copy = 1 )", + "filename": "ma.py", + "nloc": 10, + "complexity": 2, + "token_count": 115, + "parameters": [ + "data", + "value", + "rtol", + "atol", + "copy" + ], + "start_line": 1422, + "end_line": 1441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "masked_object", + "long_name": "masked_object( data , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "data", + "value", + "copy" + ], + "start_line": 1443, + "end_line": 1447, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayrange", + "long_name": "arrayrange( start , stop = None , step = 1 , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 34, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 1449, + "end_line": 1453, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "fromstring", + "long_name": "fromstring( s , t )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "s", + "t" + ], + "start_line": 1457, + "end_line": 1459, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "left_shift", + "long_name": "left_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1461, + "end_line": 1469, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "right_shift", + "long_name": "right_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1471, + "end_line": 1479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 1481, + "end_line": 1489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 101, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 1491, + "end_line": 1506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "identity", + "long_name": "identity( n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "n" + ], + "start_line": 1508, + "end_line": 1511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "indices", + "long_name": "indices( dimensions , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "dimensions", + "dtype" + ], + "start_line": 1513, + "end_line": 1517, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "zeros", + "long_name": "zeros( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1519, + "end_line": 1522, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ones", + "long_name": "ones( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1524, + "end_line": 1527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "count", + "long_name": "count( a , axis = None )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a", + "axis" + ], + "start_line": 1530, + "end_line": 1533, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "power", + "long_name": "power( a , b , third = None )", + "filename": "ma.py", + "nloc": 18, + "complexity": 4, + "token_count": 152, + "parameters": [ + "a", + "b", + "third" + ], + "start_line": 1535, + "end_line": 1552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "masked_array", + "long_name": "masked_array( a , mask = None , fill_value = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "mask", + "fill_value" + ], + "start_line": 1554, + "end_line": 1558, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "average", + "long_name": "average( a , axis = 0 , weights = None , returned = 0 )", + "filename": "ma.py", + "nloc": 92, + "complexity": 22, + "token_count": 741, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 1563, + "end_line": 1670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "where", + "long_name": "where( condition , x , y )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 149, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 1672, + "end_line": 1698, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "choose.fmask", + "long_name": "choose.fmask( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 2, + "token_count": 17, + "parameters": [ + "x" + ], + "start_line": 1702, + "end_line": 1704, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "choose.nmask", + "long_name": "choose.nmask( x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 3, + "token_count": 27, + "parameters": [ + "x" + ], + "start_line": 1705, + "end_line": 1709, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "choose", + "long_name": "choose( indices , t )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 93, + "parameters": [ + "indices", + "t" + ], + "start_line": 1700, + "end_line": 1716, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "masked_where", + "long_name": "masked_where( condition , x , copy = 1 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 47, + "parameters": [ + "condition", + "x", + "copy" + ], + "start_line": 1718, + "end_line": 1724, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "masked_greater", + "long_name": "masked_greater( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1726, + "end_line": 1728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_greater_equal", + "long_name": "masked_greater_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1730, + "end_line": 1732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less", + "long_name": "masked_less( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1734, + "end_line": 1736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less_equal", + "long_name": "masked_less_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1738, + "end_line": 1740, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_not_equal", + "long_name": "masked_not_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1742, + "end_line": 1747, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "masked_equal", + "long_name": "masked_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1749, + "end_line": 1756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "masked_inside", + "long_name": "masked_inside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1758, + "end_line": 1769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "masked_outside", + "long_name": "masked_outside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1771, + "end_line": 1782, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , * newshape )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 56, + "parameters": [ + "a", + "newshape" + ], + "start_line": 1784, + "end_line": 1791, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( a )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "a" + ], + "start_line": 1793, + "end_line": 1800, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "concatenate", + "long_name": "concatenate( arrays , axis = 0 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 5, + "token_count": 97, + "parameters": [ + "arrays", + "axis" + ], + "start_line": 1802, + "end_line": 1816, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 76, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 1818, + "end_line": 1826, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "a", + "axes" + ], + "start_line": 1828, + "end_line": 1836, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , indices , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 70, + "parameters": [ + "a", + "indices", + "values" + ], + "start_line": 1839, + "end_line": 1852, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 61, + "parameters": [ + "a", + "mask", + "values" + ], + "start_line": 1854, + "end_line": 1862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "innerproduct", + "long_name": "innerproduct( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 3, + "token_count": 72, + "parameters": [ + "a", + "b" + ], + "start_line": 1864, + "end_line": 1874, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "outerproduct", + "long_name": "outerproduct( a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 110, + "parameters": [ + "a", + "b" + ], + "start_line": 1876, + "end_line": 1888, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dot", + "long_name": "dot( a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 36, + "parameters": [ + "a", + "b" + ], + "start_line": 1890, + "end_line": 1895, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , x , dimension = - 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 67, + "parameters": [ + "condition", + "x", + "dimension" + ], + "start_line": 1897, + "end_line": 1906, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1910, + "end_line": 1914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1916, + "end_line": 1929, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1931, + "end_line": 1940, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1942, + "end_line": 1953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1959, + "end_line": 1963, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1965, + "end_line": 1978, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1980, + "end_line": 1989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1991, + "end_line": 2002, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "sort", + "long_name": "sort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 8, + "complexity": 3, + "token_count": 68, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2006, + "end_line": 2023, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , k = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 73, + "parameters": [ + "a", + "k", + "axis1", + "axis2" + ], + "start_line": 2025, + "end_line": 2032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2034, + "end_line": 2041, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2043, + "end_line": 2051, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 52, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2053, + "end_line": 2067, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "fromfunction", + "long_name": "fromfunction( f , s )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "f", + "s" + ], + "start_line": 2069, + "end_line": 2071, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( data , dtype = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 46, + "parameters": [ + "data", + "dtype" + ], + "start_line": 2073, + "end_line": 2079, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_m", + "long_name": "_m( f )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "f" + ], + "start_line": 2085, + "end_line": 2086, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "not_implemented", + "long_name": "not_implemented( * args , ** kwds )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "args", + "kwds" + ], + "start_line": 2087, + "end_line": 2088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_choose", + "long_name": "_choose( self , * args )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 2097, + "end_line": 2098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_compress", + "long_name": "_compress( self , cond , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "cond", + "axis" + ], + "start_line": 2104, + "end_line": 2105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 1677, + "complexity": 455, + "token_count": 11669, + "diff_parsed": { + "added": [ + "masked = MaskedArray(0, int, mask=1)" + ], + "deleted": [ + "masked = MaskedArray([0], int, mask=[1])[0:0]", + "masked = masked[0:0]" + ] + } + }, + { + "old_path": "numpy/core/tests/test_ma.py", + "new_path": "numpy/core/tests/test_ma.py", + "filename": "test_ma.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -626,6 +626,14 @@ def check_testArrayMethods(self):\n def check_testAPI(self):\n self.failIf([m for m in dir(numpy.ndarray)\n if m not in dir(array) and not m.startswith('_')])\n+\n+ def check_testSingleElementSubscript(self):\n+ a = array([1,3,2])\n+ b = array([1,3,2], mask=[1,0,1])\n+ self.failUnlessEqual(a[0].shape, ())\n+ self.failUnlessEqual(b[0].shape, ())\n+ self.failUnlessEqual(b[1].shape, ())\n+\n \n def timingTest():\n for f in [testf, testinplace]:\n", + "added_lines": 8, + "deleted_lines": 0, + "source_code": "import numpy \nimport types, time\nfrom numpy.core.ma import *\nfrom numpy.testing import ScipyTestCase, ScipyTest\ndef eq(v,w):\n result = allclose(v,w)\n if not result:\n print \"\"\"Not eq:\n%s\n----\n%s\"\"\"% (str(v), str(w))\n return result\n\nclass test_ma(ScipyTestCase):\n def __init__(self, *args, **kwds):\n ScipyTestCase.__init__(self, *args, **kwds)\n self.setUp()\n \n def setUp (self):\n x=numpy.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])\n y=numpy.array([5.,0.,3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])\n a10 = 10.\n m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]\n m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0 ,0, 1]\n xm = array(x, mask=m1)\n ym = array(y, mask=m2)\n z = numpy.array([-.5, 0., .5, .8])\n zm = array(z, mask=[0,1,0,0])\n xf = numpy.where(m1, 1.e+20, x)\n s = x.shape\n xm.set_fill_value(1.e+20)\n self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf, s)\n\n def check_testBasic1d(self):\n \"Test of basic array creation and properties in 1 dimension.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual(xm.dtype, x.dtype)\n self.assertEqual(xm.dtypechar, x.dtypechar)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual(count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n\n def check_testBasic2d(self):\n \"Test of basic array creation and properties in 2 dimensions.\"\n for s in [(4,3), (6,2)]: \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n x.shape = s\n y.shape = s\n xm.shape = s\n ym.shape = s\n xf.shape = s\n \n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual( count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n self.setUp()\n\n def check_testArithmetic (self):\n \"Test of basic arithmetic.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n a2d = array([[1,2],[0,4]])\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n self.failUnless(eq (a2d * a2d, a2d * a2dm))\n self.failUnless(eq (a2d + a2d, a2d + a2dm))\n self.failUnless(eq (a2d - a2d, a2d - a2dm))\n for s in [(12,), (4,3), (2,6)]: \n x = x.reshape(s)\n y = y.reshape(s)\n xm = xm.reshape(s)\n ym = ym.reshape(s)\n xf = xf.reshape(s)\n self.failUnless(eq(-x, -xm))\n self.failUnless(eq(x + y, xm + ym))\n self.failUnless(eq(x - y, xm - ym))\n self.failUnless(eq(x * y, xm * ym))\n self.failUnless(eq(x / y, xm / ym))\n self.failUnless(eq(a10 + y, a10 + ym))\n self.failUnless(eq(a10 - y, a10 - ym))\n self.failUnless(eq(a10 * y, a10 * ym))\n self.failUnless(eq(a10 / y, a10 / ym))\n self.failUnless(eq(x + a10, xm + a10))\n self.failUnless(eq(x - a10, xm - a10))\n self.failUnless(eq(x * a10, xm * a10))\n self.failUnless(eq(x / a10, xm / a10))\n self.failUnless(eq(x**2, xm**2))\n self.failUnless(eq(abs(x)**2.5, abs(xm) **2.5))\n self.failUnless(eq(x**y, xm**ym))\n self.failUnless(eq(numpy.add(x,y), add(xm, ym)))\n self.failUnless(eq(numpy.subtract(x,y), subtract(xm, ym)))\n self.failUnless(eq(numpy.multiply(x,y), multiply(xm, ym)))\n self.failUnless(eq(numpy.divide(x,y), divide(xm, ym)))\n\n\n def check_testMixedArithmetic(self):\n na = numpy.array([1])\n ma = array([1])\n self.failUnless(isinstance(na + ma, MaskedArray))\n self.failUnless(isinstance(ma + na, MaskedArray))\n \n def check_testUfuncs1 (self):\n \"Test various functions such as sin, cos.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.cos(x), cos(xm)))\n self.failUnless (eq(numpy.cosh(x), cosh(xm)))\n self.failUnless (eq(numpy.sin(x), sin(xm)))\n self.failUnless (eq(numpy.sinh(x), sinh(xm)))\n self.failUnless (eq(numpy.tan(x), tan(xm)))\n self.failUnless (eq(numpy.tanh(x), tanh(xm)))\n self.failUnless (eq(numpy.sqrt(abs(x)), sqrt(xm)))\n self.failUnless (eq(numpy.log(abs(x)), log(xm)))\n self.failUnless (eq(numpy.log10(abs(x)), log10(xm)))\n self.failUnless (eq(numpy.exp(x), exp(xm)))\n self.failUnless (eq(numpy.arcsin(z), arcsin(zm)))\n self.failUnless (eq(numpy.arccos(z), arccos(zm)))\n self.failUnless (eq(numpy.arctan(z), arctan(zm)))\n self.failUnless (eq(numpy.arctan2(x, y), arctan2(xm, ym)))\n self.failUnless (eq(numpy.absolute(x), absolute(xm)))\n self.failUnless (eq(numpy.equal(x,y), equal(xm, ym)))\n self.failUnless (eq(numpy.not_equal(x,y), not_equal(xm, ym)))\n self.failUnless (eq(numpy.less(x,y), less(xm, ym)))\n self.failUnless (eq(numpy.greater(x,y), greater(xm, ym)))\n self.failUnless (eq(numpy.less_equal(x,y), less_equal(xm, ym)))\n self.failUnless (eq(numpy.greater_equal(x,y), greater_equal(xm, ym)))\n self.failUnless (eq(numpy.conjugate(x), conjugate(xm)))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,ym))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((x,y))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,y))))\n self.failUnless (eq(numpy.concatenate((x,y,x)), concatenate((x,ym,x))))\n \n def check_xtestCount (self):\n \"Test count\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless( isinstance(count(ott), types.IntType))\n self.assertEqual(3, count(ott))\n self.assertEqual(1, count(1))\n self.failUnless (eq(0, array(1,mask=[1])))\n ott=ott.reshape((2,2))\n assert isMaskedArray(count(ott,0))\n assert isinstance(count(ott), types.IntType)\n self.failUnless (eq(3, count(ott)))\n assert getmask(count(ott,0)) is None\n self.failUnless (eq([1,2],count(ott,0)))\n \n def check_testMinMax (self):\n \"Test minimum and maximum.\" \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n xr = numpy.ravel(x) #max doesn't work if shaped\n xmr = ravel(xm)\n self.failUnless (eq(max(xr), maximum(xmr))) #true because of careful selection of data\n self.failUnless (eq(min(xr), minimum(xmr))) #true because of careful selection of data\n\n def check_testAddSumProd (self):\n \"Test add, sum, product.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.add.reduce(x), add.reduce(x)))\n self.failUnless (eq(numpy.add.accumulate(x), add.accumulate(x)))\n self.failUnless (eq(4, sum(array(4))))\n self.failUnless (eq(4, sum(array(4), axis=0)))\n self.failUnless (eq(numpy.sum(x), sum(x)))\n self.failUnless (eq(numpy.sum(filled(xm,0)), sum(xm)))\n self.failUnless (eq(numpy.sum(x,0), sum(x,0)))\n self.failUnless (eq(numpy.product(x), product(x)))\n self.failUnless (eq(numpy.product(x,0), product(x,0)))\n self.failUnless (eq(numpy.product(filled(xm,1)), product(xm)))\n if len(s) > 1:\n self.failUnless (eq(numpy.concatenate((x,y),1), concatenate((xm,ym),1)))\n self.failUnless (eq(numpy.add.reduce(x,1), add.reduce(x,1)))\n self.failUnless (eq(numpy.sum(x,1), sum(x,1)))\n self.failUnless (eq(numpy.product(x,1), product(x,1)))\n \n \n def check_testCI(self):\n \"Test of conversions and indexing\"\n x1 = numpy.array([1,2,4,3])\n x2 = array(x1, mask = [1,0,0,0])\n x3 = array(x1, mask = [0,1,0,1])\n x4 = array(x1)\n # test conversion to strings\n junk, garbage = str(x2), repr(x2)\n assert eq(numpy.sort(x1),sort(x2, fill_value=0))\n # tests of indexing\n assert type(x2[1]) is type(x1[1])\n assert x1[1] == x2[1]\n assert x2[0] is masked\n assert eq(x1[2],x2[2])\n assert eq(x1[2:5],x2[2:5])\n assert eq(x1[:],x2[:])\n assert eq(x1[1:], x3[1:])\n x1[2]=9\n x2[2]=9\n assert eq(x1,x2)\n x1[1:3] = 99\n x2[1:3] = 99\n assert eq(x1,x2)\n x2[1] = masked\n assert eq(x1,x2)\n x2[1:3]=masked\n assert eq(x1,x2)\n x2[:] = x1\n x2[1] = masked\n assert allequal(getmask(x2),array([0,1,0,0]))\n x3[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x3), array([0,1,1,0]))\n x4[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x4), array([0,1,1,0]))\n assert allequal(x4, array([1,2,3,4]))\n x1 = numpy.arange(5)*1.0\n x2 = masked_values(x1, 3.0)\n assert eq(x1,x2)\n assert allequal(array([0,0,0,1,0],MaskType), x2.mask)\n assert eq(3.0, x2.fill_value())\n x1 = array([1,'hello',2,3],object)\n x2 = numpy.array([1,'hello',2,3],object)\n s1 = x1[1]\n s2 = x2[1]\n self.assertEqual(type(s2), str)\n self.assertEqual(type(s1), str)\n self.assertEqual(s1, s2)\n assert x1[1:1].shape == (0,)\n \n def check_testCopySize(self):\n \"Tests of some subtle points of copying and sizing.\"\n n = [0,0,1,0,0]\n m = make_mask(n)\n m2 = make_mask(m)\n self.failUnless(m is m2)\n m3 = make_mask(m, copy=1)\n self.failUnless(m is not m3)\n \n x1 = numpy.arange(5)\n y1 = array(x1, mask=m)\n self.failUnless( y1.raw_data() is not x1)\n self.failUnless( allequal(x1,y1.raw_data()))\n self.failUnless( y1.mask is m)\n \n y1a = array(y1, copy=0)\n self.failUnless( y1a.raw_data() is y1.raw_data())\n self.failUnless( y1a.mask is y1.mask)\n \n y2 = array(x1, mask=m, copy=0)\n self.failUnless( y2.raw_data() is x1)\n self.failUnless( y2.mask is m)\n self.failUnless( y2[2] is masked)\n y2[2]=9\n self.failUnless( y2[2] is not masked)\n self.failUnless( y2.mask is not m)\n self.failUnless( allequal(y2.mask, 0))\n \n y3 = array(x1*1.0, mask=m)\n self.failUnless(filled(y3).dtype is (x1*1.0).dtype)\n \n x4 = arange(4)\n x4[2] = masked\n y4 = resize(x4, (8,))\n self.failUnless( eq(concatenate([x4,x4]), y4))\n self.failUnless( eq(getmask(y4),[0,0,1,0,0,0,1,0]))\n y5 = repeat(x4, (2,2,2,2))\n self.failUnless( eq(y5, [0,0,1,1,2,2,3,3]))\n y6 = repeat(x4, 2)\n self.failUnless( eq(y5, y6))\n \n def check_testPut(self):\n \"Test of put\"\n d = arange(5)\n n = [0,0,0,1,1]\n m = make_mask(n)\n x = array(d, mask = m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n x[[1,4]] = [10,40]\n self.failUnless( x.mask is not m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is not masked)\n self.failUnless( eq(x, [0,10,2,-1,40]))\n \n x = array(d, mask = m) \n x.put([-1,100,200])\n self.failUnless( eq(x, [-1,100,200,0,0]))\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n \n x = array(d, mask = m) \n x.putmask([30,40])\n self.failUnless( eq(x, [0,1,2,30,40]))\n self.failUnless( x.mask is None)\n \n x = array(d, mask = m) \n y = x.compressed()\n z = array(x, mask = m)\n z.put(y)\n assert eq (x, z)\n \n def check_testMaPut(self):\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]\n i = numpy.nonzero(m)\n putmask(xm, m, z)\n assert take(xm, i) == z\n put(ym, i, zm)\n assert take(ym, i) == zm\n \n def check_testOddFeatures(self):\n \"Test of other odd features\"\n x = arange(20); x=x.reshape(4,5)\n x.flat[5] = 12\n assert x[1,0] == 12\n z = x + 10j * x\n assert eq(z.real, x)\n assert eq(z.imag, 10*x)\n assert eq((z*conjugate(z)).real, 101*x*x)\n z.imag[...] = 0.0\n \n x = arange(10)\n x[3] = masked\n assert str(x[3]) == str(masked)\n c = x >= 8\n assert count(where(c,masked,masked)) == 0\n assert shape(where(c,masked,masked)) == c.shape\n z = where(c , x, masked)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is masked\n assert z[7] is masked\n assert z[8] is not masked\n assert z[9] is not masked\n assert eq(x,z)\n z = where(c , masked, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n z = masked_where(c, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n assert eq(x,z)\n x = array([1.,2.,3.,4.,5.])\n c = array([1,1,1,0,0])\n x[2] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n c[0] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n assert eq(masked_where(greater(x, 2), x), masked_greater(x,2))\n assert eq(masked_where(greater_equal(x, 2), x), masked_greater_equal(x,2))\n assert eq(masked_where(less(x, 2), x), masked_less(x,2))\n assert eq(masked_where(less_equal(x, 2), x), masked_less_equal(x,2))\n assert eq(masked_where(not_equal(x, 2), x), masked_not_equal(x,2))\n assert eq(masked_where(equal(x, 2), x), masked_equal(x,2))\n assert eq(masked_where(not_equal(x,2), x), masked_not_equal(x,2))\n assert eq(masked_inside(range(5), 1, 3), [0, 199, 199, 199, 4])\n assert eq(masked_outside(range(5), 1, 3),[199,1,2,3,199])\n assert eq(masked_inside(array(range(5), mask=[1,0,0,0,0]), 1, 3).mask, [1,1,1,1,0])\n assert eq(masked_outside(array(range(5), mask=[0,1,0,0,0]), 1, 3).mask, [1,1,0,0,1])\n assert eq(masked_equal(array(range(5), mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,0])\n assert eq(masked_not_equal(array([2,2,1,2,1], mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,1])\n assert eq(masked_where([1,1,0,0,0], [1,2,3,4,5]), [99,99,3,4,5])\n atest = ones((10,10,10), dtype=float32)\n btest = zeros(atest.shape, MaskType)\n ctest = masked_where(btest,atest)\n assert eq(atest,ctest)\n z = choose(c, (-x, x))\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n x = arange(6)\n x[5] = masked\n y = arange(6)*10\n y[2]= masked\n c = array([1,1,1,0,0,0], mask=[1,0,0,0,0,0])\n cm = c.filled(1)\n z = where(c,x,y)\n zm = where(cm,x,y)\n assert eq(z, zm)\n assert getmask(zm) is None\n assert eq(zm, [0,1,2,30,40,50])\n z = where(c, masked, 1)\n assert eq(z, [99,99,99,1,1,1])\n z = where(c, 1, masked)\n assert eq(z, [99, 1, 1, 99, 99, 99])\n \n def check_testMinMax(self):\n \"Test of minumum, maximum.\" \n assert eq(minimum([1,2,3],[4,0,9]), [1,0,3])\n assert eq(maximum([1,2,3],[4,0,9]), [4,2,9])\n x = arange(5)\n y = arange(5) - 2\n x[3] = masked\n y[0] = masked\n assert eq(minimum(x,y), where(less(x,y), x, y))\n assert eq(maximum(x,y), where(greater(x,y), x, y))\n assert minimum(x) == 0\n assert maximum(x) == 4\n \n def check_testTakeTransposeInnerOuter(self):\n \"Test of take, transpose, inner, outer products\"\n x = arange(24)\n y = numpy.arange(24)\n x[5:6] = masked\n x=x.reshape(2,3,4)\n y=y.reshape(2,3,4)\n assert eq(numpy.transpose(y,(2,0,1)), transpose(x,(2,0,1)))\n assert eq(numpy.take(y, (2,0,1), 1), take(x, (2,0,1), 1))\n assert eq(numpy.innerproduct(filled(x,0),filled(y,0)),\n innerproduct(x, y))\n assert eq(numpy.outerproduct(filled(x,0),filled(y,0)),\n outerproduct(x, y))\n y = array(['abc', 1, 'def', 2, 3], object)\n y[2] = masked\n t = take(y,[0,3,4])\n assert t[0] == 'abc'\n assert t[1] == 2\n assert t[2] == 3\n \n def check_testInplace(self):\n \"\"\"Test of inplace operations and rich comparisons\"\"\"\n y = arange(10)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x += 1\n assert eq(x, y+1)\n xm += 1\n assert eq(x, y+1)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x -= 1\n assert eq(x, y-1)\n xm -= 1\n assert eq(xm, y-1)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x *= 2.0\n assert eq(x, y*2)\n xm *= 2.0\n assert eq(xm, y*2)\n \n x = arange(10)*2\n xm = arange(10)\n xm[2] = masked\n x /= 2\n assert eq(x, y)\n xm /= 2\n assert eq(x, y)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x /= 2.0\n assert eq(x, y/2.0)\n xm /= arange(10)\n assert eq(xm, ones((10,)))\n \n x = arange(10).astype(float32)\n xm = arange(10)\n xm[2] = masked\n id1 = id(x.raw_data())\n x += 1.\n assert id1 == id(x.raw_data())\n assert eq(x, y+1.)\n \n def check_testPickle(self):\n \"Test of pickling\"\n x = arange(12)\n x[4:10:2] = masked\n x=x.reshape(4,3)\n f = open('test9.pik','wb')\n import pickle\n pickle.dump(x, f)\n f.close()\n f = open('test9.pik', 'rb')\n y = pickle.load(f)\n assert eq(x,y) \n \n def check_testMasked(self):\n \"Test of masked element\"\n xx=arange(6)\n xx[1] = masked\n self.failUnless(str(masked) == '--')\n self.failUnless(xx[1] is masked)\n # don't know why these should raise an exception...\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, masked)\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, 2)\n self.failUnlessRaises(Exception, lambda x,y: x+y, masked, xx)\n self.failUnlessRaises(Exception, lambda x,y: x+y, xx, masked)\n \n def check_testAverage1(self):\n \"Test of average.\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless(eq(2.0, average(ott)))\n self.failUnless(eq(2.0, average(ott, weights=[1., 1., 2., 1.])))\n result, wts = average(ott, weights=[1.,1.,2.,1.], returned=1)\n self.failUnless(eq(2.0, result))\n self.failUnless(wts == 4.0)\n ott[:] = masked\n self.failUnless(average(ott) is masked)\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n ott=ott.reshape(2,2)\n ott[:,1] = masked\n self.failUnless(eq(average(ott), [2.0, 0.0]))\n self.failUnless(average(ott,axis=1)[0] is masked)\n self.failUnless(eq([2.,0.], average(ott)))\n result, wts = average(ott, returned=1)\n self.failUnless(eq(wts, [1., 0.]))\n\n def check_testAverage2(self):\n \"More tests of average.\"\n w1 = [0,1,1,1,1,0]\n w2 = [[0,1,1,1,1,0],[1,0,0,0,0,1]]\n x=arange(6)\n self.failUnless(allclose(average(x), 2.5))\n self.failUnless(allclose(average(x, weights=w1), 2.5))\n y=array([arange(6), 2.0*arange(6)])\n self.failUnless(allclose(average(y, None), numpy.add.reduce(numpy.arange(6))*3./12.))\n self.failUnless(allclose(average(y, axis=0), numpy.arange(6) * 3./2.))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n self.failUnless(allclose(average(y, None, weights=w2), 20./6.))\n self.failUnless(allclose(average(y, axis=0, weights=w2), [0.,1.,2.,3.,4.,10.]))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n m1 = zeros(6)\n m2 = [0,0,1,1,0,0]\n m3 = [[0,0,1,1,0,0],[0,1,1,1,1,0]]\n m4 = ones(6)\n m5 = [0, 1, 1, 1, 1, 1]\n self.failUnless(allclose(average(masked_array(x, m1)), 2.5))\n self.failUnless(allclose(average(masked_array(x, m2)), 2.5))\n self.failUnless(average(masked_array(x, m4)) is masked)\n self.assertEqual(average(masked_array(x, m5)), 0.0)\n self.assertEqual(count(average(masked_array(x, m4))), 0)\n z = masked_array(y, m3)\n self.failUnless(allclose(average(z, None), 20./6.))\n self.failUnless(allclose(average(z, axis=0), [0.,1.,99.,99.,4.0, 7.5]))\n self.failUnless(allclose(average(z, axis=1), [2.5, 5.0]))\n self.failUnless(allclose( average(z,weights=w2), [0.,1., 99., 99., 4.0, 10.0]))\n \n a = arange(6)\n b = arange(6) * 3\n r1, w1 = average([[a,b],[b,a]], axis=1, returned=1)\n self.assertEqual(shape(r1) , shape(w1))\n self.assertEqual(r1.shape , w1.shape)\n r2, w2 = average(ones((2,2,3)), axis=0, weights=[3,1], returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), weights=ones((2,2,3)), returned=1)\n self.failUnless(shape(w2) == shape(r2))\n a2d = array([[1,2],[0,4]], float)\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n a2da = average(a2d)\n self.failUnless(eq (a2da, [0.5, 3.0]))\n a2dma = average(a2dm)\n self.failUnless(eq( a2dma, [1.0, 3.0]))\n a2dma = average(a2dm, axis=None)\n self.failUnless(eq(a2dma, 7./3.))\n a2dma = average(a2dm, axis=1)\n self.failUnless(eq(a2dma, [1.5, 4.0]))\n\n def check_testToPython(self):\n self.assertEqual(1, int(array(1)))\n self.assertEqual(1.0, float(array(1)))\n self.assertEqual(1, int(array([[[1]]])))\n self.assertEqual(1.0, float(array([[1]])))\n self.failUnlessRaises(ValueError, float, array([1,1]))\n self.failUnlessRaises(MAError, float, array([1],mask=[1]))\n self.failUnless(bool(array([0,1])))\n self.failUnless(bool(array([0,0],mask=[0,1])))\n self.failIf(bool(array([0,0])))\n self.failIf(bool(array([0,0],mask=[0,0])))\n\n def check_testScalarArithmetic(self):\n xm = array(0, mask=1)\n self.failUnless((1/array(0)).mask)\n self.failUnless((1 + xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless(maximum(xm, xm).mask)\n self.failUnless(minimum(xm, xm).mask)\n self.failUnless(xm.filled().dtype is xm.data.dtype)\n x = array(0, mask=0)\n self.failUnless(x.filled() is x.data)\n\n def check_testArrayMethods(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnless(eq(a.any(), a.data.any()))\n self.failUnless(eq(a.all(), a.data.all()))\n self.failUnless(eq(a.argmax(), a.data.argmax()))\n self.failUnless(eq(a.argmin(), a.data.argmin()))\n self.failUnless(eq(a.choose(0,1,2,3,4), a.data.choose(0,1,2,3,4)))\n self.failUnless(eq(a.compress([1,0,1]), a.data.compress([1,0,1])))\n self.failUnless(eq(a.conj(), a.data.conj()))\n self.failUnless(eq(a.conjugate(), a.data.conjugate()))\n m = array([[1,2],[3,4]])\n self.failUnless(eq(m.diagonal(), m.data.diagonal()))\n self.failUnless(eq(a.sum(), a.data.sum()))\n self.failUnless(eq(a.take([1,2]), a.data.take([1,2])))\n self.failUnless(eq(m.transpose(), m.data.transpose()))\n \n def check_testAPI(self):\n self.failIf([m for m in dir(numpy.ndarray)\n if m not in dir(array) and not m.startswith('_')])\n\n def check_testSingleElementSubscript(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnlessEqual(a[0].shape, ())\n self.failUnlessEqual(b[0].shape, ())\n self.failUnlessEqual(b[1].shape, ())\n\n \ndef timingTest():\n for f in [testf, testinplace]:\n for n in [1000,10000,50000]:\n t = testta(n, f)\n t1 = testtb(n, f)\n t2 = testtc(n, f)\n print f.test_name\n print \"\"\"\\\nn = %7d \nnumpy time (ms) %6.1f \nMA maskless ratio %6.1f\nMA masked ratio %6.1f\n\"\"\" % (n, t*1000.0, t1/t, t2/t)\n\ndef testta(n, f):\n x=numpy.arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtb(n, f):\n x=arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtc(n, f):\n x=arange(n) + 1.0\n x[0] = masked\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testf(x):\n for i in range(25):\n y = x **2 + 2.0 * x - 1.0\n w = x **2 + 1.0\n z = (y / w) ** 2\n return z\ntestf.test_name = 'Simple arithmetic'\n\ndef testinplace(x):\n for i in range(25):\n y = x**2\n y += 2.0*x\n y -= 1.0\n y /= x\n return y\ntestinplace.test_name = 'Inplace operations'\n\nif __name__ == \"__main__\":\n ScipyTest('numpy.core.ma').run() \n #timingTest()\n", + "source_code_before": "import numpy \nimport types, time\nfrom numpy.core.ma import *\nfrom numpy.testing import ScipyTestCase, ScipyTest\ndef eq(v,w):\n result = allclose(v,w)\n if not result:\n print \"\"\"Not eq:\n%s\n----\n%s\"\"\"% (str(v), str(w))\n return result\n\nclass test_ma(ScipyTestCase):\n def __init__(self, *args, **kwds):\n ScipyTestCase.__init__(self, *args, **kwds)\n self.setUp()\n \n def setUp (self):\n x=numpy.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])\n y=numpy.array([5.,0.,3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])\n a10 = 10.\n m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]\n m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0 ,0, 1]\n xm = array(x, mask=m1)\n ym = array(y, mask=m2)\n z = numpy.array([-.5, 0., .5, .8])\n zm = array(z, mask=[0,1,0,0])\n xf = numpy.where(m1, 1.e+20, x)\n s = x.shape\n xm.set_fill_value(1.e+20)\n self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf, s)\n\n def check_testBasic1d(self):\n \"Test of basic array creation and properties in 1 dimension.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual(xm.dtype, x.dtype)\n self.assertEqual(xm.dtypechar, x.dtypechar)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual(count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n\n def check_testBasic2d(self):\n \"Test of basic array creation and properties in 2 dimensions.\"\n for s in [(4,3), (6,2)]: \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n x.shape = s\n y.shape = s\n xm.shape = s\n ym.shape = s\n xf.shape = s\n \n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual( count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n self.setUp()\n\n def check_testArithmetic (self):\n \"Test of basic arithmetic.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n a2d = array([[1,2],[0,4]])\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n self.failUnless(eq (a2d * a2d, a2d * a2dm))\n self.failUnless(eq (a2d + a2d, a2d + a2dm))\n self.failUnless(eq (a2d - a2d, a2d - a2dm))\n for s in [(12,), (4,3), (2,6)]: \n x = x.reshape(s)\n y = y.reshape(s)\n xm = xm.reshape(s)\n ym = ym.reshape(s)\n xf = xf.reshape(s)\n self.failUnless(eq(-x, -xm))\n self.failUnless(eq(x + y, xm + ym))\n self.failUnless(eq(x - y, xm - ym))\n self.failUnless(eq(x * y, xm * ym))\n self.failUnless(eq(x / y, xm / ym))\n self.failUnless(eq(a10 + y, a10 + ym))\n self.failUnless(eq(a10 - y, a10 - ym))\n self.failUnless(eq(a10 * y, a10 * ym))\n self.failUnless(eq(a10 / y, a10 / ym))\n self.failUnless(eq(x + a10, xm + a10))\n self.failUnless(eq(x - a10, xm - a10))\n self.failUnless(eq(x * a10, xm * a10))\n self.failUnless(eq(x / a10, xm / a10))\n self.failUnless(eq(x**2, xm**2))\n self.failUnless(eq(abs(x)**2.5, abs(xm) **2.5))\n self.failUnless(eq(x**y, xm**ym))\n self.failUnless(eq(numpy.add(x,y), add(xm, ym)))\n self.failUnless(eq(numpy.subtract(x,y), subtract(xm, ym)))\n self.failUnless(eq(numpy.multiply(x,y), multiply(xm, ym)))\n self.failUnless(eq(numpy.divide(x,y), divide(xm, ym)))\n\n\n def check_testMixedArithmetic(self):\n na = numpy.array([1])\n ma = array([1])\n self.failUnless(isinstance(na + ma, MaskedArray))\n self.failUnless(isinstance(ma + na, MaskedArray))\n \n def check_testUfuncs1 (self):\n \"Test various functions such as sin, cos.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.cos(x), cos(xm)))\n self.failUnless (eq(numpy.cosh(x), cosh(xm)))\n self.failUnless (eq(numpy.sin(x), sin(xm)))\n self.failUnless (eq(numpy.sinh(x), sinh(xm)))\n self.failUnless (eq(numpy.tan(x), tan(xm)))\n self.failUnless (eq(numpy.tanh(x), tanh(xm)))\n self.failUnless (eq(numpy.sqrt(abs(x)), sqrt(xm)))\n self.failUnless (eq(numpy.log(abs(x)), log(xm)))\n self.failUnless (eq(numpy.log10(abs(x)), log10(xm)))\n self.failUnless (eq(numpy.exp(x), exp(xm)))\n self.failUnless (eq(numpy.arcsin(z), arcsin(zm)))\n self.failUnless (eq(numpy.arccos(z), arccos(zm)))\n self.failUnless (eq(numpy.arctan(z), arctan(zm)))\n self.failUnless (eq(numpy.arctan2(x, y), arctan2(xm, ym)))\n self.failUnless (eq(numpy.absolute(x), absolute(xm)))\n self.failUnless (eq(numpy.equal(x,y), equal(xm, ym)))\n self.failUnless (eq(numpy.not_equal(x,y), not_equal(xm, ym)))\n self.failUnless (eq(numpy.less(x,y), less(xm, ym)))\n self.failUnless (eq(numpy.greater(x,y), greater(xm, ym)))\n self.failUnless (eq(numpy.less_equal(x,y), less_equal(xm, ym)))\n self.failUnless (eq(numpy.greater_equal(x,y), greater_equal(xm, ym)))\n self.failUnless (eq(numpy.conjugate(x), conjugate(xm)))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,ym))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((x,y))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,y))))\n self.failUnless (eq(numpy.concatenate((x,y,x)), concatenate((x,ym,x))))\n \n def check_xtestCount (self):\n \"Test count\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless( isinstance(count(ott), types.IntType))\n self.assertEqual(3, count(ott))\n self.assertEqual(1, count(1))\n self.failUnless (eq(0, array(1,mask=[1])))\n ott=ott.reshape((2,2))\n assert isMaskedArray(count(ott,0))\n assert isinstance(count(ott), types.IntType)\n self.failUnless (eq(3, count(ott)))\n assert getmask(count(ott,0)) is None\n self.failUnless (eq([1,2],count(ott,0)))\n \n def check_testMinMax (self):\n \"Test minimum and maximum.\" \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n xr = numpy.ravel(x) #max doesn't work if shaped\n xmr = ravel(xm)\n self.failUnless (eq(max(xr), maximum(xmr))) #true because of careful selection of data\n self.failUnless (eq(min(xr), minimum(xmr))) #true because of careful selection of data\n\n def check_testAddSumProd (self):\n \"Test add, sum, product.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.add.reduce(x), add.reduce(x)))\n self.failUnless (eq(numpy.add.accumulate(x), add.accumulate(x)))\n self.failUnless (eq(4, sum(array(4))))\n self.failUnless (eq(4, sum(array(4), axis=0)))\n self.failUnless (eq(numpy.sum(x), sum(x)))\n self.failUnless (eq(numpy.sum(filled(xm,0)), sum(xm)))\n self.failUnless (eq(numpy.sum(x,0), sum(x,0)))\n self.failUnless (eq(numpy.product(x), product(x)))\n self.failUnless (eq(numpy.product(x,0), product(x,0)))\n self.failUnless (eq(numpy.product(filled(xm,1)), product(xm)))\n if len(s) > 1:\n self.failUnless (eq(numpy.concatenate((x,y),1), concatenate((xm,ym),1)))\n self.failUnless (eq(numpy.add.reduce(x,1), add.reduce(x,1)))\n self.failUnless (eq(numpy.sum(x,1), sum(x,1)))\n self.failUnless (eq(numpy.product(x,1), product(x,1)))\n \n \n def check_testCI(self):\n \"Test of conversions and indexing\"\n x1 = numpy.array([1,2,4,3])\n x2 = array(x1, mask = [1,0,0,0])\n x3 = array(x1, mask = [0,1,0,1])\n x4 = array(x1)\n # test conversion to strings\n junk, garbage = str(x2), repr(x2)\n assert eq(numpy.sort(x1),sort(x2, fill_value=0))\n # tests of indexing\n assert type(x2[1]) is type(x1[1])\n assert x1[1] == x2[1]\n assert x2[0] is masked\n assert eq(x1[2],x2[2])\n assert eq(x1[2:5],x2[2:5])\n assert eq(x1[:],x2[:])\n assert eq(x1[1:], x3[1:])\n x1[2]=9\n x2[2]=9\n assert eq(x1,x2)\n x1[1:3] = 99\n x2[1:3] = 99\n assert eq(x1,x2)\n x2[1] = masked\n assert eq(x1,x2)\n x2[1:3]=masked\n assert eq(x1,x2)\n x2[:] = x1\n x2[1] = masked\n assert allequal(getmask(x2),array([0,1,0,0]))\n x3[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x3), array([0,1,1,0]))\n x4[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x4), array([0,1,1,0]))\n assert allequal(x4, array([1,2,3,4]))\n x1 = numpy.arange(5)*1.0\n x2 = masked_values(x1, 3.0)\n assert eq(x1,x2)\n assert allequal(array([0,0,0,1,0],MaskType), x2.mask)\n assert eq(3.0, x2.fill_value())\n x1 = array([1,'hello',2,3],object)\n x2 = numpy.array([1,'hello',2,3],object)\n s1 = x1[1]\n s2 = x2[1]\n self.assertEqual(type(s2), str)\n self.assertEqual(type(s1), str)\n self.assertEqual(s1, s2)\n assert x1[1:1].shape == (0,)\n \n def check_testCopySize(self):\n \"Tests of some subtle points of copying and sizing.\"\n n = [0,0,1,0,0]\n m = make_mask(n)\n m2 = make_mask(m)\n self.failUnless(m is m2)\n m3 = make_mask(m, copy=1)\n self.failUnless(m is not m3)\n \n x1 = numpy.arange(5)\n y1 = array(x1, mask=m)\n self.failUnless( y1.raw_data() is not x1)\n self.failUnless( allequal(x1,y1.raw_data()))\n self.failUnless( y1.mask is m)\n \n y1a = array(y1, copy=0)\n self.failUnless( y1a.raw_data() is y1.raw_data())\n self.failUnless( y1a.mask is y1.mask)\n \n y2 = array(x1, mask=m, copy=0)\n self.failUnless( y2.raw_data() is x1)\n self.failUnless( y2.mask is m)\n self.failUnless( y2[2] is masked)\n y2[2]=9\n self.failUnless( y2[2] is not masked)\n self.failUnless( y2.mask is not m)\n self.failUnless( allequal(y2.mask, 0))\n \n y3 = array(x1*1.0, mask=m)\n self.failUnless(filled(y3).dtype is (x1*1.0).dtype)\n \n x4 = arange(4)\n x4[2] = masked\n y4 = resize(x4, (8,))\n self.failUnless( eq(concatenate([x4,x4]), y4))\n self.failUnless( eq(getmask(y4),[0,0,1,0,0,0,1,0]))\n y5 = repeat(x4, (2,2,2,2))\n self.failUnless( eq(y5, [0,0,1,1,2,2,3,3]))\n y6 = repeat(x4, 2)\n self.failUnless( eq(y5, y6))\n \n def check_testPut(self):\n \"Test of put\"\n d = arange(5)\n n = [0,0,0,1,1]\n m = make_mask(n)\n x = array(d, mask = m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n x[[1,4]] = [10,40]\n self.failUnless( x.mask is not m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is not masked)\n self.failUnless( eq(x, [0,10,2,-1,40]))\n \n x = array(d, mask = m) \n x.put([-1,100,200])\n self.failUnless( eq(x, [-1,100,200,0,0]))\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n \n x = array(d, mask = m) \n x.putmask([30,40])\n self.failUnless( eq(x, [0,1,2,30,40]))\n self.failUnless( x.mask is None)\n \n x = array(d, mask = m) \n y = x.compressed()\n z = array(x, mask = m)\n z.put(y)\n assert eq (x, z)\n \n def check_testMaPut(self):\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]\n i = numpy.nonzero(m)\n putmask(xm, m, z)\n assert take(xm, i) == z\n put(ym, i, zm)\n assert take(ym, i) == zm\n \n def check_testOddFeatures(self):\n \"Test of other odd features\"\n x = arange(20); x=x.reshape(4,5)\n x.flat[5] = 12\n assert x[1,0] == 12\n z = x + 10j * x\n assert eq(z.real, x)\n assert eq(z.imag, 10*x)\n assert eq((z*conjugate(z)).real, 101*x*x)\n z.imag[...] = 0.0\n \n x = arange(10)\n x[3] = masked\n assert str(x[3]) == str(masked)\n c = x >= 8\n assert count(where(c,masked,masked)) == 0\n assert shape(where(c,masked,masked)) == c.shape\n z = where(c , x, masked)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is masked\n assert z[7] is masked\n assert z[8] is not masked\n assert z[9] is not masked\n assert eq(x,z)\n z = where(c , masked, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n z = masked_where(c, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n assert eq(x,z)\n x = array([1.,2.,3.,4.,5.])\n c = array([1,1,1,0,0])\n x[2] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n c[0] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n assert eq(masked_where(greater(x, 2), x), masked_greater(x,2))\n assert eq(masked_where(greater_equal(x, 2), x), masked_greater_equal(x,2))\n assert eq(masked_where(less(x, 2), x), masked_less(x,2))\n assert eq(masked_where(less_equal(x, 2), x), masked_less_equal(x,2))\n assert eq(masked_where(not_equal(x, 2), x), masked_not_equal(x,2))\n assert eq(masked_where(equal(x, 2), x), masked_equal(x,2))\n assert eq(masked_where(not_equal(x,2), x), masked_not_equal(x,2))\n assert eq(masked_inside(range(5), 1, 3), [0, 199, 199, 199, 4])\n assert eq(masked_outside(range(5), 1, 3),[199,1,2,3,199])\n assert eq(masked_inside(array(range(5), mask=[1,0,0,0,0]), 1, 3).mask, [1,1,1,1,0])\n assert eq(masked_outside(array(range(5), mask=[0,1,0,0,0]), 1, 3).mask, [1,1,0,0,1])\n assert eq(masked_equal(array(range(5), mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,0])\n assert eq(masked_not_equal(array([2,2,1,2,1], mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,1])\n assert eq(masked_where([1,1,0,0,0], [1,2,3,4,5]), [99,99,3,4,5])\n atest = ones((10,10,10), dtype=float32)\n btest = zeros(atest.shape, MaskType)\n ctest = masked_where(btest,atest)\n assert eq(atest,ctest)\n z = choose(c, (-x, x))\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n x = arange(6)\n x[5] = masked\n y = arange(6)*10\n y[2]= masked\n c = array([1,1,1,0,0,0], mask=[1,0,0,0,0,0])\n cm = c.filled(1)\n z = where(c,x,y)\n zm = where(cm,x,y)\n assert eq(z, zm)\n assert getmask(zm) is None\n assert eq(zm, [0,1,2,30,40,50])\n z = where(c, masked, 1)\n assert eq(z, [99,99,99,1,1,1])\n z = where(c, 1, masked)\n assert eq(z, [99, 1, 1, 99, 99, 99])\n \n def check_testMinMax(self):\n \"Test of minumum, maximum.\" \n assert eq(minimum([1,2,3],[4,0,9]), [1,0,3])\n assert eq(maximum([1,2,3],[4,0,9]), [4,2,9])\n x = arange(5)\n y = arange(5) - 2\n x[3] = masked\n y[0] = masked\n assert eq(minimum(x,y), where(less(x,y), x, y))\n assert eq(maximum(x,y), where(greater(x,y), x, y))\n assert minimum(x) == 0\n assert maximum(x) == 4\n \n def check_testTakeTransposeInnerOuter(self):\n \"Test of take, transpose, inner, outer products\"\n x = arange(24)\n y = numpy.arange(24)\n x[5:6] = masked\n x=x.reshape(2,3,4)\n y=y.reshape(2,3,4)\n assert eq(numpy.transpose(y,(2,0,1)), transpose(x,(2,0,1)))\n assert eq(numpy.take(y, (2,0,1), 1), take(x, (2,0,1), 1))\n assert eq(numpy.innerproduct(filled(x,0),filled(y,0)),\n innerproduct(x, y))\n assert eq(numpy.outerproduct(filled(x,0),filled(y,0)),\n outerproduct(x, y))\n y = array(['abc', 1, 'def', 2, 3], object)\n y[2] = masked\n t = take(y,[0,3,4])\n assert t[0] == 'abc'\n assert t[1] == 2\n assert t[2] == 3\n \n def check_testInplace(self):\n \"\"\"Test of inplace operations and rich comparisons\"\"\"\n y = arange(10)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x += 1\n assert eq(x, y+1)\n xm += 1\n assert eq(x, y+1)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x -= 1\n assert eq(x, y-1)\n xm -= 1\n assert eq(xm, y-1)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x *= 2.0\n assert eq(x, y*2)\n xm *= 2.0\n assert eq(xm, y*2)\n \n x = arange(10)*2\n xm = arange(10)\n xm[2] = masked\n x /= 2\n assert eq(x, y)\n xm /= 2\n assert eq(x, y)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x /= 2.0\n assert eq(x, y/2.0)\n xm /= arange(10)\n assert eq(xm, ones((10,)))\n \n x = arange(10).astype(float32)\n xm = arange(10)\n xm[2] = masked\n id1 = id(x.raw_data())\n x += 1.\n assert id1 == id(x.raw_data())\n assert eq(x, y+1.)\n \n def check_testPickle(self):\n \"Test of pickling\"\n x = arange(12)\n x[4:10:2] = masked\n x=x.reshape(4,3)\n f = open('test9.pik','wb')\n import pickle\n pickle.dump(x, f)\n f.close()\n f = open('test9.pik', 'rb')\n y = pickle.load(f)\n assert eq(x,y) \n \n def check_testMasked(self):\n \"Test of masked element\"\n xx=arange(6)\n xx[1] = masked\n self.failUnless(str(masked) == '--')\n self.failUnless(xx[1] is masked)\n # don't know why these should raise an exception...\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, masked)\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, 2)\n self.failUnlessRaises(Exception, lambda x,y: x+y, masked, xx)\n self.failUnlessRaises(Exception, lambda x,y: x+y, xx, masked)\n \n def check_testAverage1(self):\n \"Test of average.\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless(eq(2.0, average(ott)))\n self.failUnless(eq(2.0, average(ott, weights=[1., 1., 2., 1.])))\n result, wts = average(ott, weights=[1.,1.,2.,1.], returned=1)\n self.failUnless(eq(2.0, result))\n self.failUnless(wts == 4.0)\n ott[:] = masked\n self.failUnless(average(ott) is masked)\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n ott=ott.reshape(2,2)\n ott[:,1] = masked\n self.failUnless(eq(average(ott), [2.0, 0.0]))\n self.failUnless(average(ott,axis=1)[0] is masked)\n self.failUnless(eq([2.,0.], average(ott)))\n result, wts = average(ott, returned=1)\n self.failUnless(eq(wts, [1., 0.]))\n\n def check_testAverage2(self):\n \"More tests of average.\"\n w1 = [0,1,1,1,1,0]\n w2 = [[0,1,1,1,1,0],[1,0,0,0,0,1]]\n x=arange(6)\n self.failUnless(allclose(average(x), 2.5))\n self.failUnless(allclose(average(x, weights=w1), 2.5))\n y=array([arange(6), 2.0*arange(6)])\n self.failUnless(allclose(average(y, None), numpy.add.reduce(numpy.arange(6))*3./12.))\n self.failUnless(allclose(average(y, axis=0), numpy.arange(6) * 3./2.))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n self.failUnless(allclose(average(y, None, weights=w2), 20./6.))\n self.failUnless(allclose(average(y, axis=0, weights=w2), [0.,1.,2.,3.,4.,10.]))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n m1 = zeros(6)\n m2 = [0,0,1,1,0,0]\n m3 = [[0,0,1,1,0,0],[0,1,1,1,1,0]]\n m4 = ones(6)\n m5 = [0, 1, 1, 1, 1, 1]\n self.failUnless(allclose(average(masked_array(x, m1)), 2.5))\n self.failUnless(allclose(average(masked_array(x, m2)), 2.5))\n self.failUnless(average(masked_array(x, m4)) is masked)\n self.assertEqual(average(masked_array(x, m5)), 0.0)\n self.assertEqual(count(average(masked_array(x, m4))), 0)\n z = masked_array(y, m3)\n self.failUnless(allclose(average(z, None), 20./6.))\n self.failUnless(allclose(average(z, axis=0), [0.,1.,99.,99.,4.0, 7.5]))\n self.failUnless(allclose(average(z, axis=1), [2.5, 5.0]))\n self.failUnless(allclose( average(z,weights=w2), [0.,1., 99., 99., 4.0, 10.0]))\n \n a = arange(6)\n b = arange(6) * 3\n r1, w1 = average([[a,b],[b,a]], axis=1, returned=1)\n self.assertEqual(shape(r1) , shape(w1))\n self.assertEqual(r1.shape , w1.shape)\n r2, w2 = average(ones((2,2,3)), axis=0, weights=[3,1], returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), weights=ones((2,2,3)), returned=1)\n self.failUnless(shape(w2) == shape(r2))\n a2d = array([[1,2],[0,4]], float)\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n a2da = average(a2d)\n self.failUnless(eq (a2da, [0.5, 3.0]))\n a2dma = average(a2dm)\n self.failUnless(eq( a2dma, [1.0, 3.0]))\n a2dma = average(a2dm, axis=None)\n self.failUnless(eq(a2dma, 7./3.))\n a2dma = average(a2dm, axis=1)\n self.failUnless(eq(a2dma, [1.5, 4.0]))\n\n def check_testToPython(self):\n self.assertEqual(1, int(array(1)))\n self.assertEqual(1.0, float(array(1)))\n self.assertEqual(1, int(array([[[1]]])))\n self.assertEqual(1.0, float(array([[1]])))\n self.failUnlessRaises(ValueError, float, array([1,1]))\n self.failUnlessRaises(MAError, float, array([1],mask=[1]))\n self.failUnless(bool(array([0,1])))\n self.failUnless(bool(array([0,0],mask=[0,1])))\n self.failIf(bool(array([0,0])))\n self.failIf(bool(array([0,0],mask=[0,0])))\n\n def check_testScalarArithmetic(self):\n xm = array(0, mask=1)\n self.failUnless((1/array(0)).mask)\n self.failUnless((1 + xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless(maximum(xm, xm).mask)\n self.failUnless(minimum(xm, xm).mask)\n self.failUnless(xm.filled().dtype is xm.data.dtype)\n x = array(0, mask=0)\n self.failUnless(x.filled() is x.data)\n\n def check_testArrayMethods(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnless(eq(a.any(), a.data.any()))\n self.failUnless(eq(a.all(), a.data.all()))\n self.failUnless(eq(a.argmax(), a.data.argmax()))\n self.failUnless(eq(a.argmin(), a.data.argmin()))\n self.failUnless(eq(a.choose(0,1,2,3,4), a.data.choose(0,1,2,3,4)))\n self.failUnless(eq(a.compress([1,0,1]), a.data.compress([1,0,1])))\n self.failUnless(eq(a.conj(), a.data.conj()))\n self.failUnless(eq(a.conjugate(), a.data.conjugate()))\n m = array([[1,2],[3,4]])\n self.failUnless(eq(m.diagonal(), m.data.diagonal()))\n self.failUnless(eq(a.sum(), a.data.sum()))\n self.failUnless(eq(a.take([1,2]), a.data.take([1,2])))\n self.failUnless(eq(m.transpose(), m.data.transpose()))\n \n def check_testAPI(self):\n self.failIf([m for m in dir(numpy.ndarray)\n if m not in dir(array) and not m.startswith('_')])\n \ndef timingTest():\n for f in [testf, testinplace]:\n for n in [1000,10000,50000]:\n t = testta(n, f)\n t1 = testtb(n, f)\n t2 = testtc(n, f)\n print f.test_name\n print \"\"\"\\\nn = %7d \nnumpy time (ms) %6.1f \nMA maskless ratio %6.1f\nMA masked ratio %6.1f\n\"\"\" % (n, t*1000.0, t1/t, t2/t)\n\ndef testta(n, f):\n x=numpy.arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtb(n, f):\n x=arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtc(n, f):\n x=arange(n) + 1.0\n x[0] = masked\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testf(x):\n for i in range(25):\n y = x **2 + 2.0 * x - 1.0\n w = x **2 + 1.0\n z = (y / w) ** 2\n return z\ntestf.test_name = 'Simple arithmetic'\n\ndef testinplace(x):\n for i in range(25):\n y = x**2\n y += 2.0*x\n y -= 1.0\n y /= x\n return y\ntestinplace.test_name = 'Inplace operations'\n\nif __name__ == \"__main__\":\n ScipyTest('numpy.core.ma').run() \n #timingTest()\n", + "methods": [ + { + "name": "eq", + "long_name": "eq( v , w )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "v", + "w" + ], + "start_line": 5, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , * args , ** kwds )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 15, + "end_line": 17, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 276, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 32, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic1d", + "long_name": "check_testBasic1d( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 186, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 47, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic2d", + "long_name": "check_testBasic2d( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 2, + "token_count": 209, + "parameters": [ + "self" + ], + "start_line": 49, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "check_testArithmetic", + "long_name": "check_testArithmetic( self )", + "filename": "test_ma.py", + "nloc": 34, + "complexity": 2, + "token_count": 518, + "parameters": [ + "self" + ], + "start_line": 70, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "check_testMixedArithmetic", + "long_name": "check_testMixedArithmetic( self )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 106, + "end_line": 110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_testUfuncs1", + "long_name": "check_testUfuncs1( self )", + "filename": "test_ma.py", + "nloc": 29, + "complexity": 1, + "token_count": 600, + "parameters": [ + "self" + ], + "start_line": 112, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "check_xtestCount", + "long_name": "check_xtestCount( self )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 1, + "token_count": 174, + "parameters": [ + "self" + ], + "start_line": 142, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 156, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_testAddSumProd", + "long_name": "check_testAddSumProd( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 2, + "token_count": 361, + "parameters": [ + "self" + ], + "start_line": 164, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testCI", + "long_name": "check_testCI( self )", + "filename": "test_ma.py", + "nloc": 46, + "complexity": 1, + "token_count": 560, + "parameters": [ + "self" + ], + "start_line": 184, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 1 + }, + { + "name": "check_testCopySize", + "long_name": "check_testCopySize( self )", + "filename": "test_ma.py", + "nloc": 35, + "complexity": 1, + "token_count": 409, + "parameters": [ + "self" + ], + "start_line": 233, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 1 + }, + { + "name": "check_testPut", + "long_name": "check_testPut( self )", + "filename": "test_ma.py", + "nloc": 27, + "complexity": 1, + "token_count": 291, + "parameters": [ + "self" + ], + "start_line": 274, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "check_testMaPut", + "long_name": "check_testMaPut( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 101, + "parameters": [ + "self" + ], + "start_line": 305, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_testOddFeatures", + "long_name": "check_testOddFeatures( self )", + "filename": "test_ma.py", + "nloc": 88, + "complexity": 1, + "token_count": 1188, + "parameters": [ + "self" + ], + "start_line": 314, + "end_line": 402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 154, + "parameters": [ + "self" + ], + "start_line": 404, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testTakeTransposeInnerOuter", + "long_name": "check_testTakeTransposeInnerOuter( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 1, + "token_count": 235, + "parameters": [ + "self" + ], + "start_line": 417, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "check_testInplace", + "long_name": "check_testInplace( self )", + "filename": "test_ma.py", + "nloc": 44, + "complexity": 1, + "token_count": 315, + "parameters": [ + "self" + ], + "start_line": 437, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testPickle", + "long_name": "check_testPickle( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 489, + "end_line": 500, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testMasked", + "long_name": "check_testMasked( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 502, + "end_line": 512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage1", + "long_name": "check_testAverage1( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 1, + "token_count": 289, + "parameters": [ + "self" + ], + "start_line": 514, + "end_line": 531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage2", + "long_name": "check_testAverage2( self )", + "filename": "test_ma.py", + "nloc": 50, + "complexity": 1, + "token_count": 945, + "parameters": [ + "self" + ], + "start_line": 533, + "end_line": 583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testToPython", + "long_name": "check_testToPython( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 193, + "parameters": [ + "self" + ], + "start_line": 585, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testScalarArithmetic", + "long_name": "check_testScalarArithmetic( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 597, + "end_line": 607, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testArrayMethods", + "long_name": "check_testArrayMethods( self )", + "filename": "test_ma.py", + "nloc": 16, + "complexity": 1, + "token_count": 351, + "parameters": [ + "self" + ], + "start_line": 609, + "end_line": 624, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "check_testAPI", + "long_name": "check_testAPI( self )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 4, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 626, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_testSingleElementSubscript", + "long_name": "check_testSingleElementSubscript( self )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 630, + "end_line": 635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "timingTest", + "long_name": "timingTest( )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 3, + "token_count": 72, + "parameters": [], + "start_line": 638, + "end_line": 650, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "testta", + "long_name": "testta( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 40, + "parameters": [ + "n", + "f" + ], + "start_line": 652, + "end_line": 656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtb", + "long_name": "testtb( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 38, + "parameters": [ + "n", + "f" + ], + "start_line": 658, + "end_line": 662, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtc", + "long_name": "testtc( n , f )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 44, + "parameters": [ + "n", + "f" + ], + "start_line": 664, + "end_line": 669, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testf", + "long_name": "testf( x )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 48, + "parameters": [ + "x" + ], + "start_line": 671, + "end_line": 676, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testinplace", + "long_name": "testinplace( x )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 36, + "parameters": [ + "x" + ], + "start_line": 679, + "end_line": 685, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "eq", + "long_name": "eq( v , w )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "v", + "w" + ], + "start_line": 5, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , * args , ** kwds )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 15, + "end_line": 17, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 276, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 32, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic1d", + "long_name": "check_testBasic1d( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 186, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 47, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic2d", + "long_name": "check_testBasic2d( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 2, + "token_count": 209, + "parameters": [ + "self" + ], + "start_line": 49, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "check_testArithmetic", + "long_name": "check_testArithmetic( self )", + "filename": "test_ma.py", + "nloc": 34, + "complexity": 2, + "token_count": 518, + "parameters": [ + "self" + ], + "start_line": 70, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "check_testMixedArithmetic", + "long_name": "check_testMixedArithmetic( self )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 106, + "end_line": 110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_testUfuncs1", + "long_name": "check_testUfuncs1( self )", + "filename": "test_ma.py", + "nloc": 29, + "complexity": 1, + "token_count": 600, + "parameters": [ + "self" + ], + "start_line": 112, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "check_xtestCount", + "long_name": "check_xtestCount( self )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 1, + "token_count": 174, + "parameters": [ + "self" + ], + "start_line": 142, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 156, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_testAddSumProd", + "long_name": "check_testAddSumProd( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 2, + "token_count": 361, + "parameters": [ + "self" + ], + "start_line": 164, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testCI", + "long_name": "check_testCI( self )", + "filename": "test_ma.py", + "nloc": 46, + "complexity": 1, + "token_count": 560, + "parameters": [ + "self" + ], + "start_line": 184, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 1 + }, + { + "name": "check_testCopySize", + "long_name": "check_testCopySize( self )", + "filename": "test_ma.py", + "nloc": 35, + "complexity": 1, + "token_count": 409, + "parameters": [ + "self" + ], + "start_line": 233, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 1 + }, + { + "name": "check_testPut", + "long_name": "check_testPut( self )", + "filename": "test_ma.py", + "nloc": 27, + "complexity": 1, + "token_count": 291, + "parameters": [ + "self" + ], + "start_line": 274, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "check_testMaPut", + "long_name": "check_testMaPut( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 101, + "parameters": [ + "self" + ], + "start_line": 305, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_testOddFeatures", + "long_name": "check_testOddFeatures( self )", + "filename": "test_ma.py", + "nloc": 88, + "complexity": 1, + "token_count": 1188, + "parameters": [ + "self" + ], + "start_line": 314, + "end_line": 402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 154, + "parameters": [ + "self" + ], + "start_line": 404, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testTakeTransposeInnerOuter", + "long_name": "check_testTakeTransposeInnerOuter( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 1, + "token_count": 235, + "parameters": [ + "self" + ], + "start_line": 417, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "check_testInplace", + "long_name": "check_testInplace( self )", + "filename": "test_ma.py", + "nloc": 44, + "complexity": 1, + "token_count": 315, + "parameters": [ + "self" + ], + "start_line": 437, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testPickle", + "long_name": "check_testPickle( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 489, + "end_line": 500, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testMasked", + "long_name": "check_testMasked( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 502, + "end_line": 512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage1", + "long_name": "check_testAverage1( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 1, + "token_count": 289, + "parameters": [ + "self" + ], + "start_line": 514, + "end_line": 531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage2", + "long_name": "check_testAverage2( self )", + "filename": "test_ma.py", + "nloc": 50, + "complexity": 1, + "token_count": 945, + "parameters": [ + "self" + ], + "start_line": 533, + "end_line": 583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testToPython", + "long_name": "check_testToPython( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 193, + "parameters": [ + "self" + ], + "start_line": 585, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testScalarArithmetic", + "long_name": "check_testScalarArithmetic( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 597, + "end_line": 607, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testArrayMethods", + "long_name": "check_testArrayMethods( self )", + "filename": "test_ma.py", + "nloc": 16, + "complexity": 1, + "token_count": 351, + "parameters": [ + "self" + ], + "start_line": 609, + "end_line": 624, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "check_testAPI", + "long_name": "check_testAPI( self )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 4, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 626, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "timingTest", + "long_name": "timingTest( )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 3, + "token_count": 72, + "parameters": [], + "start_line": 630, + "end_line": 642, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "testta", + "long_name": "testta( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 40, + "parameters": [ + "n", + "f" + ], + "start_line": 644, + "end_line": 648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtb", + "long_name": "testtb( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 38, + "parameters": [ + "n", + "f" + ], + "start_line": 650, + "end_line": 654, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtc", + "long_name": "testtc( n , f )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 44, + "parameters": [ + "n", + "f" + ], + "start_line": 656, + "end_line": 661, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testf", + "long_name": "testf( x )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 48, + "parameters": [ + "x" + ], + "start_line": 663, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testinplace", + "long_name": "testinplace( x )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 36, + "parameters": [ + "x" + ], + "start_line": 671, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "check_testSingleElementSubscript", + "long_name": "check_testSingleElementSubscript( self )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 630, + "end_line": 635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + } + ], + "nloc": 629, + "complexity": 45, + "token_count": 8318, + "diff_parsed": { + "added": [ + "", + " def check_testSingleElementSubscript(self):", + " a = array([1,3,2])", + " b = array([1,3,2], mask=[1,0,1])", + " self.failUnlessEqual(a[0].shape, ())", + " self.failUnlessEqual(b[0].shape, ())", + " self.failUnlessEqual(b[1].shape, ())", + "" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "42779fea3ed52eac633f4d12ca4f9d355ffb5535", + "msg": "introduced nomask = None constant", + "author": { + "name": "sasha", + "email": "sasha@localhost" + }, + "committer": { + "name": "sasha", + "email": "sasha@localhost" + }, + "author_date": "2006-01-12T22:27:17+00:00", + "author_timezone": 0, + "committer_date": "2006-01-12T22:27:17+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "0a407f99008973cead33d672c44006fbfa285a34" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 113, + "insertions": 114, + "lines": 227, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/ma.py", + "new_path": "numpy/core/ma.py", + "filename": "ma.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -18,6 +18,7 @@\n \n \n MaskType=bool_\n+nomask = None # To be changed to MaskType(0)\n divide_tolerance = 1.e-35\n \n class MAError (Exception):\n@@ -133,21 +134,21 @@ def set_fill_value (a, fill_value):\n a.set_fill_value (fill_value)\n \n def getmask (a):\n- \"\"\"Mask of values in a; could be None.\n- Returns None if a is not a masked array.\n+ \"\"\"Mask of values in a; could be nomask.\n+ Returns nomask if a is not a masked array.\n To get an array for sure use getmaskarray.\"\"\"\n if isinstance(a, MaskedArray):\n return a.raw_mask()\n else:\n- return None\n+ return nomask\n \n def getmaskarray (a):\n- \"\"\"Mask of values in a; an array of zeros if mask is None\n+ \"\"\"Mask of values in a; an array of zeros if mask is nomask\n or not a masked array, and is a byte-sized integer.\n Do not try to add up entries, for example.\n \"\"\"\n m = getmask(a)\n- if m is None:\n+ if m is nomask:\n return make_mask_none(shape(a))\n else:\n return m\n@@ -155,7 +156,7 @@ def getmaskarray (a):\n def is_mask (m):\n \"\"\"Is m a legal mask? Does not check contents, only type.\n \"\"\"\n- if m is None or (isinstance(m, ndarray) and \\\n+ if m is nomask or (isinstance(m, ndarray) and \\\n m.dtype is MaskType):\n return 1\n else:\n@@ -164,12 +165,12 @@ def is_mask (m):\n def make_mask (m, copy=0, flag=0):\n \"\"\"make_mask(m, copy=0, flag=0)\n return m as a mask, creating a copy if necessary or requested.\n- Can accept any sequence of integers or None. Does not check\n+ Can accept any sequence of integers or nomask. Does not check\n that contents must be 0s and 1s.\n- if flag, return None if m contains no true elements.\n+ if flag, return nomask if m contains no true elements.\n \"\"\"\n- if m is None:\n- return None\n+ if m is nomask:\n+ return nomask\n elif isinstance(m, ndarray):\n if m.dtype is MaskType:\n if copy:\n@@ -182,7 +183,7 @@ def make_mask (m, copy=0, flag=0):\n result = filled(m,True).astype(MaskType)\n \n if flag and not oldnumeric.sometrue(oldnumeric.ravel(result)):\n- return None\n+ return nomask\n else:\n return result\n \n@@ -193,11 +194,11 @@ def make_mask_none (s):\n return result\n \n def mask_or (m1, m2):\n- \"\"\"Logical or of the mask candidates m1 and m2, treating None as false.\n- Result may equal m1 or m2 if the other is None.\n+ \"\"\"Logical or of the mask candidates m1 and m2, treating nomask as false.\n+ Result may equal m1 or m2 if the other is nomask.\n \"\"\"\n- if m1 is None: return make_mask(m2)\n- if m2 is None: return make_mask(m1)\n+ if m1 is nomask: return make_mask(m2)\n+ if m2 is nomask: return make_mask(m1)\n if m1 is m2 and is_mask(m1): return m1\n return make_mask(umath.logical_or(m1, m2))\n \n@@ -303,7 +304,7 @@ def __call__ (self, a, *args, **kwargs):\n if self.domain is not None:\n m = mask_or(m, self.domain(d1))\n result = self.f(d1, *args, **kwargs)\n- if m is not None:\n+ if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n@@ -350,7 +351,7 @@ def __call__(self, a, b):\n mb = mask_or(mb, t)\n m = mask_or(ma, mb)\n result = self.f(d1, d2)\n- if m is not None:\n+ if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n@@ -379,7 +380,7 @@ def __call__ (self, a, b, *args, **kwargs):\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n result = self.f(d1, d2, *args, **kwargs)\n- if m is not None:\n+ if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n@@ -395,10 +396,10 @@ def reduce (self, target, axis=0):\n t = filled(target, self.filly)\n if t.shape == ():\n t = t.reshape(1)\n- if m is not None:\n+ if m is not nomask:\n m = make_mask(m, copy=1)\n m.shape = (1,)\n- if m is None:\n+ if m is nomask:\n return masked_array (self.f.reduce (t, axis))\n else:\n t = masked_array (t, m)\n@@ -415,8 +416,8 @@ def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n- if ma is None and mb is None:\n- m = None\n+ if ma is nomask and mb is nomask:\n+ m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n@@ -507,10 +508,10 @@ class MaskedArray (object):\n \n Construction:\n x = array(data, dtype=None, copy=True, fortran=False,\n- mask = None, fill_value=None)\n+ mask = nomask, fill_value=None)\n \n If copy=False, every effort is made not to copy the data:\n- If data is a MaskedArray, and argument mask=None,\n+ If data is a MaskedArray, and argument mask=nomask,\n then the candidate data is data.data and the\n mask used is data.mask. If data is a numeric array,\n it is used as the candidate raw data.\n@@ -521,7 +522,7 @@ class MaskedArray (object):\n If a data copy is required, raw data stored is the result of:\n numeric.array(data, dtype=dtypechar, copy=copy)\n \n- If mask is None there are no masked values. Otherwise mask must\n+ If mask is nomask there are no masked values. Otherwise mask must\n be convertible to an array of booleans with the same shape as x.\n \n fill_value is used to fill in masked values when necessary,\n@@ -530,8 +531,8 @@ class MaskedArray (object):\n \"\"\"\n __array_priority__ = 10.1\n def __init__(self, data, dtype=None, copy=True, fortran=False, \n- mask=None, fill_value=None):\n- \"\"\"array(data, dtype=None, copy=True, fortran=False, mask=None, fill_value=None)\n+ mask=nomask, fill_value=None):\n+ \"\"\"array(data, dtype=None, copy=True, fortran=False, mask=nomask, fill_value=None)\n If data already a numeric array, its dtype becomes the default value of dtype.\n \"\"\"\n tc = dtype\n@@ -543,9 +544,9 @@ def __init__(self, data, dtype=None, copy=True, fortran=False,\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n- if mask is None:\n+ if mask is nomask:\n mask = data.mask\n- elif mask is not None: #attempting to change the mask\n+ elif mask is not nomask: #attempting to change the mask\n need_data_copied = True\n \n elif isinstance(data, ndarray):\n@@ -567,12 +568,12 @@ def __init__(self, data, dtype=None, copy=True, fortran=False,\n else:\n self._data = c\n \n- if mask is None:\n- self._mask = None\n+ if mask is nomask:\n+ self._mask = nomask\n self._shared_mask = 0\n else:\n self._mask = make_mask (mask)\n- if self._mask is None:\n+ if self._mask is nomask:\n self._shared_mask = 0\n else:\n self._shared_mask = (self._mask is mask)\n@@ -595,7 +596,7 @@ def __init__(self, data, dtype=None, copy=True, fortran=False,\n \n def __array__ (self, t = None):\n \"Special hook for numeric. Converts to numeric if possible.\"\n- if self._mask is not None:\n+ if self._mask is not nomask:\n if oldnumeric.ravel(self._mask).any():\n raise MAError, \\\n \"\"\"Cannot automatically convert masked array to numeric because data\n@@ -603,7 +604,7 @@ def __array__ (self, t = None):\n \"\"\"\n else: # Mask is all false\n # Optimize to avoid future invocations of this section.\n- self._mask = None\n+ self._mask = nomask\n self._shared_mask = 0\n if t:\n return self._data.astype(t)\n@@ -623,15 +624,15 @@ def _get_shape(self):\n def _set_shape (self, newshape):\n \"Set the array's shape.\"\n self._data.shape = newshape\n- if self._mask is not None:\n+ if self._mask is not nomask:\n self._mask = self._mask.copy()\n self._mask.shape = newshape\n \n def _get_flat(self):\n \"\"\"Calculate the flat value.\n \"\"\"\n- if self._mask is None:\n- return masked_array(self._data.ravel(), mask=None,\n+ if self._mask is nomask:\n+ return masked_array(self._data.ravel(), mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.ravel(),\n@@ -645,8 +646,8 @@ def _set_flat (self, value):\n \n def _get_real(self):\n \"Get the real part of a complex array.\"\n- if self._mask is None:\n- return masked_array(self._data.real, mask=None,\n+ if self._mask is nomask:\n+ return masked_array(self._data.real, mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.real, mask=self._mask.ravel(),\n@@ -659,8 +660,8 @@ def _set_real (self, value):\n \n def _get_imaginary(self):\n \"Get the imaginary part of a complex array.\"\n- if self._mask is None:\n- return masked_array(self._data.imag, mask=None,\n+ if self._mask is nomask:\n+ return masked_array(self._data.imag, mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.imag, mask=self._mask.ravel(),\n@@ -711,7 +712,7 @@ def __repr__(self):\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n \n n = len(self.shape)\n- if self._mask is None:\n+ if self._mask is nomask:\n if n <=1:\n return without_mask1 % {'data':str(self.filled())}\n return without_mask % {'data':str(self.filled())}\n@@ -728,7 +729,7 @@ def __repr__(self):\n 'fill': str(self.fill_value())\n }\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n- if self._mask is None:\n+ if self._mask is nomask:\n return without_mask % {'data':str(self.filled())}\n else:\n return with_mask % {\n@@ -740,14 +741,14 @@ def __repr__(self):\n def __float__(self):\n \"Convert self to float.\"\n self.unmask()\n- if self._mask is not None:\n+ if self._mask is not nomask:\n raise MAError, 'Cannot convert masked element to a Python float.'\n return float(self.data.item())\n \n def __int__(self):\n \"Convert self to int.\"\n self.unmask()\n- if self._mask is not None:\n+ if self._mask is not nomask:\n raise MAError, 'Cannot convert masked element to a Python int.'\n return int(self.data.item())\n \n@@ -756,7 +757,7 @@ def __getitem__(self, i):\n self.unshare_mask()\n m = self._mask\n dout = self._data[i]\n- if m is None:\n+ if m is nomask:\n return dout\n mi = m[i]\n if mi.size == 1:\n@@ -772,7 +773,7 @@ def __getslice__(self, i, j):\n self.unshare_mask()\n m = self._mask\n dout = self._data[i:j]\n- if m is None:\n+ if m is nomask:\n return masked_array(dout, fill_value=self._fill_value)\n else:\n return masked_array(dout, mask = m[i:j], fill_value=self._fill_value)\n@@ -788,7 +789,7 @@ def __setitem__(self, index, value):\n if self is masked:\n raise MAError, 'Cannot alter the masked element.'\n if value is masked:\n- if self._mask is None:\n+ if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n else:\n@@ -798,12 +799,12 @@ def __setitem__(self, index, value):\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[index] = value\n- if m is None:\n- if self._mask is not None:\n+ if m is nomask:\n+ if self._mask is not nomask:\n self.unshare_mask()\n self._mask[index] = False\n else:\n- if self._mask is None:\n+ if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = True\n else:\n@@ -816,7 +817,7 @@ def __setslice__(self, i, j, value):\n if self is masked:\n raise MAError, \"Cannot alter the 'masked' object.\"\n if value is masked:\n- if self._mask is None:\n+ if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n self._mask[i:j] = True\n@@ -824,12 +825,12 @@ def __setslice__(self, i, j, value):\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[i:j] = value\n- if m is None:\n- if self._mask is not None:\n+ if m is nomask:\n+ if self._mask is not nomask:\n self.unshare_mask()\n self._mask[i:j] = False\n else:\n- if self._mask is None:\n+ if self._mask is nomask:\n self._mask = make_mask_none(self._data.shape)\n self._shared_mask = False\n self._mask[i:j] = m\n@@ -843,8 +844,8 @@ def __nonzero__(self):\n # XXX: scalars do not have len \n m = self._mask\n d = self._data\n- return bool(m is not None and m.any()\n- or d is not None and d.any())\n+ return bool(m is not nomask and m.any()\n+ or d is not nomask and d.any())\n \n def __len__ (self):\n \"\"\"Return length of first dimension. This is weird but Python's\n@@ -976,11 +977,11 @@ def __iadd__(self, other):\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n \n- if self._mask is None:\n+ if self._mask is nomask:\n self._data += f\n m = getmask(other)\n self._mask = m\n- self._shared_mask = m is not None\n+ self._shared_mask = m is not nomask\n else:\n result = add(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n@@ -1019,11 +1020,11 @@ def __imul__(self, other):\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n \n- if self._mask is None:\n+ if self._mask is nomask:\n self._data *= f\n m = getmask(other)\n self._mask = m\n- self._shared_mask = m is not None\n+ self._shared_mask = m is not nomask\n else:\n result = multiply(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n@@ -1062,11 +1063,11 @@ def __isub__(self, other):\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n \n- if self._mask is None:\n+ if self._mask is nomask:\n self._data -= f\n m = getmask(other)\n self._mask = m\n- self._shared_mask = m is not None\n+ self._shared_mask = m is not nomask\n else:\n result = subtract(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n@@ -1147,7 +1148,7 @@ def byte_swapped(self):\n def compressed (self):\n \"A 1-D array of all the non-masked data.\"\n d = oldnumeric.ravel(self._data)\n- if self._mask is None:\n+ if self._mask is nomask:\n return array(d)\n else:\n m = 1 - oldnumeric.ravel(self._mask)\n@@ -1159,7 +1160,7 @@ def count (self, axis = None):\n m = self._mask\n s = self._data.shape\n ls = len(s)\n- if m is None:\n+ if m is nomask:\n if ls == 0:\n return 1\n if ls == 1:\n@@ -1196,13 +1197,13 @@ def filled (self, fill_value=None):\n \"\"\"A numeric array with masked values filled. If fill_value is None,\n use self.fill_value().\n \n- If mask is None, copy data only if not contiguous.\n+ If mask is nomask, copy data only if not contiguous.\n Result is always a contiguous, numeric array.\n # Is contiguous really necessary now?\n \"\"\"\n d = self._data\n m = self._mask\n- if m is None:\n+ if m is nomask:\n if d.flags['CONTIGUOUS']:\n return d\n else:\n@@ -1257,7 +1258,7 @@ def put (self, values):\n \"\"\"\n iota = numeric.arange(self.size)\n d = self._data\n- if self._mask is None:\n+ if self._mask is nomask:\n ind = iota\n else:\n ind = oldnumeric.compress(1 - self._mask, iota)\n@@ -1265,17 +1266,17 @@ def put (self, values):\n \n def putmask (self, values):\n \"\"\"Set the masked entries of self to filled(values).\n- Mask changed to None.\n+ Mask changed to nomask.\n \"\"\"\n d = self._data\n- if self._mask is not None:\n+ if self._mask is not nomask:\n d[self._mask] = filled(values).astype(d.dtype)\n self._shared_mask = 0\n- self._mask = None\n+ self._mask = nomask\n \n def ravel (self):\n \"\"\"Return a 1-D view of self.\"\"\"\n- if self._mask is None:\n+ if self._mask is nomask:\n return masked_array(self._data.ravel())\n else:\n return masked_array(self._data.ravel(), self._mask.ravel())\n@@ -1294,12 +1295,12 @@ def raw_mask (self):\n \"\"\"\n return self._mask\n mask = property(fget=raw_mask, \n- doc=\"The mask, may be None. Values where mask true are meaningless.\")\n+ doc=\"The mask, may be nomask. Values where mask true are meaningless.\")\n \n def reshape (self, *s):\n \"\"\"This array reshaped to shape s\"\"\"\n d = self._data.reshape(*s)\n- if self._mask is None:\n+ if self._mask is nomask:\n return masked_array(d)\n else:\n m = self._mask.reshape(*s)\n@@ -1326,7 +1327,7 @@ def _get_dtype(self):\n \n def item(self):\n \"Return Python scalar if possible.\"\n- if self._mask is not None:\n+ if self._mask is not nomask:\n m = oldnumeric.ravel(self._mask)\n try:\n if m[0]:\n@@ -1344,11 +1345,11 @@ def tostring(self, fill_value=None):\n return self.filled(fill_value).tostring()\n \n def unmask (self):\n- \"Replace the mask by None if possible.\"\n- if self._mask is None: return\n+ \"Replace the mask by nomask if possible.\"\n+ if self._mask is nomask: return\n m = make_mask(self._mask, flag=1)\n- if m is None:\n- self._mask = None\n+ if m is nomask:\n+ self._mask = nomask\n self._shared_mask = 0\n \n def unshare_mask (self):\n@@ -1405,7 +1406,7 @@ def allequal (a, b, fill_value=1):\n fill_value as a truth value where either or both are masked.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n- if m is None:\n+ if m is nomask:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n@@ -1422,7 +1423,7 @@ def allequal (a, b, fill_value=1):\n def masked_values (data, value, rtol=1.e-5, atol=1.e-8, copy=1):\n \"\"\"\n masked_values(data, value, rtol=1.e-5, atol=1.e-8)\n- Create a masked array; mask is None if possible.\n+ Create a masked array; mask is nomask if possible.\n If copy==0, and otherwise possible, result\n may share data values with original array.\n Let d = filled(data, value). Returns d\n@@ -1461,7 +1462,7 @@ def fromstring (s, t):\n def left_shift (a, n):\n \"Left shift n bits\"\n m = getmask(a)\n- if m is None:\n+ if m is nomask:\n d = umath.left_shift(filled(a), n)\n return masked_array(d)\n else:\n@@ -1471,7 +1472,7 @@ def left_shift (a, n):\n def right_shift (a, n):\n \"Right shift n bits\"\n m = getmask(a)\n- if m is None:\n+ if m is nomask:\n d = umath.right_shift(filled(a), n)\n return masked_array(d)\n else:\n@@ -1482,7 +1483,7 @@ def resize (a, new_shape):\n \"\"\"resize(a, new_shape) returns a new array with the specified shape.\n The original array's total size can be any size.\"\"\"\n m = getmask(a)\n- if m is not None:\n+ if m is not nomask:\n m = oldnumeric.resize(m, new_shape)\n result = array(oldnumeric.resize(filled(a), new_shape), mask=m)\n result.set_fill_value(get_fill_value(a))\n@@ -1498,7 +1499,7 @@ def repeat(a, repeats, axis=0):\n repeats = tuple([repeats]*(shape(af)[axis]))\n \n m = getmask(a)\n- if m is not None:\n+ if m is not nomask:\n m = oldnumeric.repeat(m, repeats, axis)\n d = oldnumeric.repeat(af, repeats, axis)\n result = masked_array(d, m)\n@@ -1545,14 +1546,14 @@ def power (a, b, third=None):\n return masked_array(umath.power(fa, fb), m)\n md = make_mask(umath.less_equal (fa, 0), flag=1)\n m = mask_or(m, md)\n- if m is None:\n+ if m is nomask:\n return masked_array(umath.power(fa, fb))\n else:\n fa = numeric.where(m, 1, fa)\n return masked_array(umath.power(fa, fb), m)\n \n-def masked_array (a, mask=None, fill_value=None):\n- \"\"\"masked_array(a, mask=None) =\n+def masked_array (a, mask=nomask, fill_value=None):\n+ \"\"\"masked_array(a, mask=nomask) =\n array(a, mask=mask, copy=0, fill_value=fill_value)\n \"\"\"\n return array(a, mask=mask, copy=0, fill_value=fill_value)\n@@ -1581,7 +1582,7 @@ def average (a, axis=0, weights=None, returned = 0):\n if ash == ():\n ash = (1,)\n if axis is None:\n- if mask is None:\n+ if mask is nomask:\n if weights is None:\n n = add.reduce(a.raw_data().ravel())\n d = reduce(lambda x, y: x * y, ash, 1.0)\n@@ -1602,7 +1603,7 @@ def average (a, axis=0, weights=None, returned = 0):\n d = add.reduce(w)\n del w\n else:\n- if mask is None:\n+ if mask is nomask:\n if weights is None:\n d = ash[axis] * 1.0\n n = umath.add.reduce(a.raw_data(), axis)\n@@ -1683,14 +1684,14 @@ def where (condition, x, y):\n else:\n xv = filled(x)\n xm = getmask(x)\n- if xm is None: xm = 0\n+ if xm is nomask: xm = 0\n if y is masked:\n yv = 0\n ym = 1\n else:\n yv = filled(y)\n ym = getmask(y)\n- if ym is None: ym = 0\n+ if ym is nomask: ym = 0\n d = numeric.choose(fc, (yv, xv))\n md = numeric.choose(fc, (ym, xm))\n m = getmask(condition)\n@@ -1705,7 +1706,7 @@ def fmask (x):\n def nmask (x):\n if x is masked: return 1\n m = getmask(x)\n- if m is None: return 0\n+ if m is nomask: return 0\n return m\n c = filled(indices,0)\n masks = [nmask(x) for x in t]\n@@ -1785,7 +1786,7 @@ def reshape (a, *newshape):\n \"Copy of a with a new shape.\"\n m = getmask(a)\n d = filled(a).reshape(*newshape)\n- if m is None:\n+ if m is nomask:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.reshape(m, *newshape))\n@@ -1794,7 +1795,7 @@ def ravel (a):\n \"a as one-dimensional, may share data and mask\"\n m = getmask(a)\n d = oldnumeric.ravel(filled(a))\n- if m is None:\n+ if m is nomask:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.ravel(m))\n@@ -1806,7 +1807,7 @@ def concatenate (arrays, axis=0):\n d.append(filled(x))\n d = numeric.concatenate(d, axis)\n for x in arrays:\n- if getmask(x) is not None: break\n+ if getmask(x) is not nomask: break\n else:\n return masked_array(d)\n dm = []\n@@ -1819,7 +1820,7 @@ def take (a, indices, axis=0):\n \"take(a, indices, axis=0) returns selection of items from a.\"\n m = getmask(a)\n d = masked_array(a).raw_data()\n- if m is None:\n+ if m is nomask:\n return masked_array(numeric.take(d, indices, axis))\n else:\n return masked_array(numeric.take(d, indices, axis),\n@@ -1829,7 +1830,7 @@ def transpose(a, axes=None):\n \"transpose(a, axes=None) reorder dimensions per tuple axes\"\n m = getmask(a)\n d = filled(a)\n- if m is None:\n+ if m is nomask:\n return masked_array(numeric.transpose(d, axes))\n else:\n return masked_array(numeric.transpose(d, axes),\n@@ -1847,17 +1848,17 @@ def put(a, indices, values):\n v = filled(values)\n numeric.put (d, ind, v)\n m = getmask(a)\n- if m is not None:\n+ if m is not nomask:\n a.unshare_mask()\n numeric.put(a.raw_mask(), ind, 0)\n \n def putmask(a, mask, values):\n \"putmask(a, mask, values) sets a where mask is true.\"\n- if mask is None:\n+ if mask is nomask:\n return\n numeric.putmask(a.raw_data(), mask, values)\n m = getmask(a)\n- if m is None: return\n+ if m is nomask: return\n a.unshare_mask()\n numeric.putmask(a.raw_mask(), mask, 0)\n \n@@ -1880,7 +1881,7 @@ def outerproduct(a, b):\n d = numeric.outerproduct(fa, fb)\n ma = getmask(a)\n mb = getmask(b)\n- if ma is None and mb is None:\n+ if ma is nomask and mb is nomask:\n return masked_array(d)\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n@@ -1900,7 +1901,7 @@ def compress(condition, x, dimension=-1):\n \"\"\"\n c = filled(condition, 0)\n m = getmask(x)\n- if m is not None:\n+ if m is not nomask:\n m=numeric.compress(c, m, dimension)\n d = numeric.compress(c, filled(x), dimension)\n return masked_array(d, m)\n@@ -1917,7 +1918,7 @@ def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n- if m is None:\n+ if m is nomask:\n d = amin(filled(a).ravel())\n return d\n ac = a.compressed()\n@@ -1931,7 +1932,7 @@ def __call__ (self, a, b=None):\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n- if m is None:\n+ if m is nomask:\n t = filled(target)\n return masked_array (umath.minimum.reduce (t, axis))\n else:\n@@ -1943,8 +1944,8 @@ def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n- if ma is None and mb is None:\n- m = None\n+ if ma is nomask and mb is nomask:\n+ m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n@@ -1966,7 +1967,7 @@ def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n- if m is None:\n+ if m is nomask:\n d = amax(filled(a).ravel())\n return d\n ac = a.compressed()\n@@ -1980,7 +1981,7 @@ def __call__ (self, a, b=None):\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n- if m is None:\n+ if m is nomask:\n t = filled(target)\n return masked_array (umath.maximum.reduce (t, axis))\n else:\n@@ -1992,8 +1993,8 @@ def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n- if ma is None and mb is None:\n- m = None\n+ if ma is nomask and mb is nomask:\n+ m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n@@ -2018,7 +2019,7 @@ def sort (x, axis = -1, fill_value=None):\n fill_value = default_fill_value (x)\n d = filled(x, fill_value)\n s = oldnumeric.sort(d, axis)\n- if getmask(x) is None:\n+ if getmask(x) is nomask:\n return masked_array(s)\n return masked_values(s, fill_value, copy=0)\n \n@@ -2026,7 +2027,7 @@ def diagonal(a, k = 0, axis1=0, axis2=1):\n \"\"\"diagonal(a,k=0,axis1=0, axis2=1) = the k'th diagonal of a\"\"\"\n d = oldnumeric.diagonal(filled(a), k, axis1, axis2)\n m = getmask(a)\n- if m is None:\n+ if m is nomask:\n return masked_array(d, m)\n else:\n return masked_array(d, oldnumeric.diagonal(m, k, axis1, axis2))\n", + "added_lines": 114, + "deleted_lines": 113, + "source_code": "\"\"\"MA: a facility for dealing with missing observations\nMA is generally used as a numpy.array look-alike.\nby Paul F. Dubois.\n\nCopyright 1999, 2000, 2001 Regents of the University of California.\nReleased for unlimited redistribution.\nAdapted for numpy_core 2005 by Travis Oliphant and\n(mainly) Paul Dubois.\n\"\"\"\nimport string, types, sys\n\nimport umath\nimport oldnumeric\nfrom numeric import e, pi, newaxis, ndarray, inf\nfrom oldnumeric import typecodes, amax, amin\nfrom numerictypes import *\nimport numeric\n\n \nMaskType=bool_\nnomask = None # To be changed to MaskType(0)\ndivide_tolerance = 1.e-35\n\nclass MAError (Exception):\n def __init__ (self, args=None):\n \"Create an exception\"\n self.args = args\n def __str__(self):\n \"Calculate the string representation\"\n return str(self.args)\n __repr__ = __str__\n\nclass _MaskedPrintOption:\n \"One instance of this class, masked_print_option, is created.\"\n def __init__ (self, display):\n \"Create the masked print option object.\"\n self.set_display(display)\n self._enabled = 1\n\n def display (self):\n \"Show what prints for masked values.\"\n return self._display\n\n def set_display (self, s):\n \"set_display(s) sets what prints for masked values.\"\n self._display = s\n\n def enabled (self):\n \"Is the use of the display value enabled?\"\n return self._enabled\n\n def enable(self, flag=1):\n \"Set the enabling flag to flag.\"\n self._enabled = flag\n\n def __str__ (self):\n return str(self._display)\n\n __repr__ = __str__\n \n#if you single index into a masked location you get this object.\nmasked_print_option = _MaskedPrintOption('--')\n\n# Use single element arrays or scalars.\ndefault_real_fill_value = 1.e20\ndefault_complex_fill_value = 1.e20 + 0.0j\ndefault_character_fill_value = '-'\ndefault_integer_fill_value = 999999\ndefault_object_fill_value = '?'\n\ndef default_fill_value (obj):\n \"Function to calculate default fill value for an object.\"\n if isinstance(obj, types.FloatType):\n return default_real_fill_value\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return default_integer_fill_value\n elif isinstance(obj, types.StringType):\n return default_character_fill_value\n elif isinstance(obj, types.ComplexType):\n return default_complex_fill_value\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return default_real_fill_value\n if x in typecodes['Integer']:\n return default_integer_fill_value\n if x in typecodes['Complex']:\n return default_complex_fill_value\n if x in typecodes['Character']:\n return default_character_fill_value\n if x in typecodes['UnsignedInteger']:\n return umath.absolute(default_integer_fill_value)\n return default_object_fill_value\n else:\n return default_object_fill_value\n\ndef minimum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking minima.\"\n if isinstance(obj, types.FloatType):\n return numeric.inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return numeric.inf\n if x in typecodes['Integer']:\n return sys.maxint\n if x in typecodes['UnsignedInteger']:\n return sys.maxint\n else:\n raise TypeError, 'Unsuitable type for calculating minimum.'\n\ndef maximum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking maxima.\"\n if isinstance(obj, types.FloatType):\n return -inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return -sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return -inf\n if x in typecodes['Integer']:\n return -sys.maxint\n if x in typecodes['UnsignedInteger']:\n return 0\n else:\n raise TypeError, 'Unsuitable type for calculating maximum.'\n\ndef set_fill_value (a, fill_value):\n \"Set fill value of a if it is a masked array.\"\n if isMaskedArray(a):\n a.set_fill_value (fill_value)\n\ndef getmask (a):\n \"\"\"Mask of values in a; could be nomask.\n Returns nomask if a is not a masked array.\n To get an array for sure use getmaskarray.\"\"\"\n if isinstance(a, MaskedArray):\n return a.raw_mask()\n else:\n return nomask\n\ndef getmaskarray (a):\n \"\"\"Mask of values in a; an array of zeros if mask is nomask\n or not a masked array, and is a byte-sized integer.\n Do not try to add up entries, for example.\n \"\"\"\n m = getmask(a)\n if m is nomask:\n return make_mask_none(shape(a))\n else:\n return m\n\ndef is_mask (m):\n \"\"\"Is m a legal mask? Does not check contents, only type.\n \"\"\"\n if m is nomask or (isinstance(m, ndarray) and \\\n m.dtype is MaskType):\n return 1\n else:\n return 0\n\ndef make_mask (m, copy=0, flag=0):\n \"\"\"make_mask(m, copy=0, flag=0)\n return m as a mask, creating a copy if necessary or requested.\n Can accept any sequence of integers or nomask. Does not check\n that contents must be 0s and 1s.\n if flag, return nomask if m contains no true elements.\n \"\"\"\n if m is nomask:\n return nomask\n elif isinstance(m, ndarray):\n if m.dtype is MaskType:\n if copy:\n result = numeric.array(m, dtype=MaskType, copy=copy)\n else:\n result = m\n else:\n result = m.astype(MaskType)\n else:\n result = filled(m,True).astype(MaskType)\n\n if flag and not oldnumeric.sometrue(oldnumeric.ravel(result)):\n return nomask\n else:\n return result\n\ndef make_mask_none (s):\n \"Return a mask of all zeros of shape s.\"\n result = numeric.zeros(s, dtype=MaskType)\n result.shape = s\n return result\n\ndef mask_or (m1, m2):\n \"\"\"Logical or of the mask candidates m1 and m2, treating nomask as false.\n Result may equal m1 or m2 if the other is nomask.\n \"\"\"\n if m1 is nomask: return make_mask(m2)\n if m2 is nomask: return make_mask(m1)\n if m1 is m2 and is_mask(m1): return m1\n return make_mask(umath.logical_or(m1, m2))\n\ndef filled (a, value = None):\n \"\"\"a as a contiguous numeric array with any masked areas replaced by value\n if value is None or the special element \"masked\", get_fill_value(a)\n is used instead.\n\n If a is already a contiguous numeric array, a itself is returned.\n\n filled(a) can be used to be sure that the result is numeric when\n passing an object a to other software ignorant of MA, in particular to\n numeric itself.\n \"\"\"\n if isinstance(a, MaskedArray):\n return a.filled(value)\n elif isinstance(a, ndarray) and a.flags['CONTIGUOUS']:\n return a\n elif isinstance(a, types.DictType):\n return numeric.array(a, 'O')\n else:\n return numeric.array(a)\n\ndef get_fill_value (a):\n \"\"\"\n The fill value of a, if it has one; otherwise, the default fill value\n for that type.\n \"\"\"\n if isMaskedArray(a):\n result = a.fill_value()\n else:\n result = default_fill_value(a)\n return result\n\ndef common_fill_value (a, b):\n \"The common fill_value of a and b, if there is one, or None\"\n t1 = get_fill_value(a)\n t2 = get_fill_value(b)\n if t1 == t2: return t1\n return None\n\n# Domain functions return 1 where the argument(s) are not in the domain.\nclass domain_check_interval:\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n def __init__(self, y1, y2):\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n self.y1 = y1\n self.y2 = y2\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.logical_or(umath.greater (x, self.y2),\n umath.less(x, self.y1)\n )\n\nclass domain_tan:\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n def __init__(self, eps):\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n self.eps = eps\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less(umath.absolute(umath.cos(x)), self.eps)\n\nclass domain_greater:\n \"domain_greater(v)(x) = true where x <= v\"\n def __init__(self, critical_value):\n \"domain_greater(v)(x) = true where x <= v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less_equal (x, self.critical_value)\n\nclass domain_greater_equal:\n \"domain_greater_equal(v)(x) = true where x < v\"\n def __init__(self, critical_value):\n \"domain_greater_equal(v)(x) = true where x < v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less (x, self.critical_value)\n\nclass masked_unary_operation:\n def __init__ (self, aufunc, fill=0, domain=None):\n \"\"\" masked_unary_operation(aufunc, fill=0, domain=None)\n aufunc(fill) must be defined\n self(x) returns aufunc(x)\n with masked values where domain(x) is true or getmask(x) is true.\n \"\"\"\n self.f = aufunc\n self.fill = fill\n self.domain = domain\n self.__doc__ = getattr(aufunc, \"__doc__\", str(aufunc))\n\n def __call__ (self, a, *args, **kwargs):\n \"Execute the call behavior.\"\n# numeric tries to return scalars rather than arrays when given scalars.\n m = getmask(a)\n d1 = filled(a, self.fill)\n if self.domain is not None:\n m = mask_or(m, self.domain(d1))\n result = self.f(d1, *args, **kwargs)\n if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\n\nclass domain_safe_divide:\n def __init__ (self, tolerance=divide_tolerance):\n self.tolerance = tolerance\n def __call__ (self, a, b):\n return umath.absolute(a) * self.tolerance >= umath.absolute(b)\n\nclass domained_binary_operation:\n \"\"\"Binary operations that have a domain, like divide. These are complicated so they\n are a separate class. They have no reduce, outer or accumulate.\n \"\"\"\n def __init__ (self, abfunc, domain, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.domain = domain\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__(self, a, b):\n \"Execute the call behavior.\"\n ma = getmask(a)\n mb = getmask(b)\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n t = self.domain(d1, d2)\n\n if oldnumeric.sometrue(t, None):\n d2 = where(t, self.filly, d2)\n mb = mask_or(mb, t)\n m = mask_or(ma, mb)\n result = self.f(d1, d2)\n if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n \n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nclass masked_binary_operation:\n def __init__ (self, abfunc, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__ (self, a, b, *args, **kwargs):\n \"Execute the call behavior.\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n result = self.f(d1, d2, *args, **kwargs)\n if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis with this function.\"\"\"\n m = getmask(target)\n t = filled(target, self.filly)\n if t.shape == ():\n t = t.reshape(1)\n if m is not nomask:\n m = make_mask(m, copy=1)\n m.shape = (1,)\n if m is nomask:\n return masked_array (self.f.reduce (t, axis))\n else:\n t = masked_array (t, m)\n t = self.f.reduce(filled(t, self.filly), axis)\n m = umath.logical_and.reduce(m, axis)\n if isinstance(t, ndarray):\n return masked_array(t, m, get_fill_value(target))\n elif m:\n return masked\n else:\n return t\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = self.f.outer(filled(a, self.fillx), filled(b, self.filly))\n return masked_array(d, m)\n\n def accumulate (self, target, axis=0):\n \"\"\"Accumulate target along axis after filling with y fill value.\"\"\"\n t = filled(target, self.filly)\n return masked_array (self.f.accumulate (t, axis))\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nsqrt = masked_unary_operation(umath.sqrt, 0.0, domain_greater_equal(0.0))\nlog = masked_unary_operation(umath.log, 1.0, domain_greater(0.0))\nlog10 = masked_unary_operation(umath.log10, 1.0, domain_greater(0.0))\nexp = masked_unary_operation(umath.exp)\nconjugate = masked_unary_operation(umath.conjugate)\nsin = masked_unary_operation(umath.sin)\ncos = masked_unary_operation(umath.cos)\ntan = masked_unary_operation(umath.tan, 0.0, domain_tan(1.e-35))\narcsin = masked_unary_operation(umath.arcsin, 0.0, domain_check_interval(-1.0, 1.0))\narccos = masked_unary_operation(umath.arccos, 0.0, domain_check_interval(-1.0, 1.0))\narctan = masked_unary_operation(umath.arctan)\n# Missing from numeric\narcsinh = masked_unary_operation(umath.arcsinh)\narccosh = masked_unary_operation(umath.arccosh)\narctanh = masked_unary_operation(umath.arctanh)\nsinh = masked_unary_operation(umath.sinh)\ncosh = masked_unary_operation(umath.cosh)\ntanh = masked_unary_operation(umath.tanh)\nabsolute = masked_unary_operation(umath.absolute)\nfabs = masked_unary_operation(umath.fabs)\nnegative = masked_unary_operation(umath.negative)\nnonzero = masked_unary_operation(oldnumeric.nonzero)\naround = masked_unary_operation(oldnumeric.round_)\nfloor = masked_unary_operation(umath.floor)\nceil = masked_unary_operation(umath.ceil)\nsometrue = masked_unary_operation(oldnumeric.sometrue)\nalltrue = masked_unary_operation(oldnumeric.alltrue, 1)\nlogical_not = masked_unary_operation(umath.logical_not)\n\nadd = masked_binary_operation(umath.add)\nsubtract = masked_binary_operation(umath.subtract)\nsubtract.reduce = None\nmultiply = masked_binary_operation(umath.multiply, 1, 1)\ndivide = domained_binary_operation(umath.divide, domain_safe_divide(), 0, 1)\ntrue_divide = domained_binary_operation(umath.true_divide, domain_safe_divide(), 0, 1)\nfloor_divide = domained_binary_operation(umath.floor_divide, domain_safe_divide(), 0, 1)\nremainder = domained_binary_operation(umath.remainder, domain_safe_divide(), 0, 1)\nfmod = domained_binary_operation(umath.fmod, domain_safe_divide(), 0, 1)\nhypot = masked_binary_operation(umath.hypot)\narctan2 = masked_binary_operation(umath.arctan2, 0.0, 1.0)\narctan2.reduce = None\nequal = masked_binary_operation(umath.equal)\nequal.reduce = None\nnot_equal = masked_binary_operation(umath.not_equal)\nnot_equal.reduce = None\nless_equal = masked_binary_operation(umath.less_equal)\nless_equal.reduce = None\ngreater_equal = masked_binary_operation(umath.greater_equal)\ngreater_equal.reduce = None\nless = masked_binary_operation(umath.less)\nless.reduce = None\ngreater = masked_binary_operation(umath.greater)\ngreater.reduce = None\nlogical_and = masked_binary_operation(umath.logical_and)\nlogical_or = masked_binary_operation(umath.logical_or)\nlogical_xor = masked_binary_operation(umath.logical_xor)\nbitwise_and = masked_binary_operation(umath.bitwise_and)\nbitwise_or = masked_binary_operation(umath.bitwise_or)\nbitwise_xor = masked_binary_operation(umath.bitwise_xor)\n\ndef rank (object):\n return oldnumeric.rank(filled(object))\n\ndef shape (object):\n return oldnumeric.shape(filled(object))\n\ndef size (object, axis=None):\n return oldnumeric.size(filled(object), axis)\n\nclass MaskedArray (object):\n \"\"\"Arrays with possibly masked values.\n Masked values of 1 exclude the corresponding element from \n any computation.\n\n Construction:\n x = array(data, dtype=None, copy=True, fortran=False,\n mask = nomask, fill_value=None)\n\n If copy=False, every effort is made not to copy the data:\n If data is a MaskedArray, and argument mask=nomask,\n then the candidate data is data.data and the\n mask used is data.mask. If data is a numeric array,\n it is used as the candidate raw data.\n If dtypechar is not None and\n is != data.dtypechar then a data copy is required.\n Otherwise, the candidate is used.\n\n If a data copy is required, raw data stored is the result of:\n numeric.array(data, dtype=dtypechar, copy=copy)\n\n If mask is nomask there are no masked values. Otherwise mask must\n be convertible to an array of booleans with the same shape as x.\n\n fill_value is used to fill in masked values when necessary,\n such as when printing and in method/function filled().\n The fill_value is not used for computation within this module.\n \"\"\"\n __array_priority__ = 10.1\n def __init__(self, data, dtype=None, copy=True, fortran=False, \n mask=nomask, fill_value=None):\n \"\"\"array(data, dtype=None, copy=True, fortran=False, mask=nomask, fill_value=None)\n If data already a numeric array, its dtype becomes the default value of dtype.\n \"\"\"\n tc = dtype\n need_data_copied = copy\n if isinstance(data, MaskedArray):\n c = data.data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n if mask is nomask:\n mask = data.mask\n elif mask is not nomask: #attempting to change the mask\n need_data_copied = True\n\n elif isinstance(data, ndarray):\n c = data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n else:\n need_data_copied = False #because I'll do it now\n c = numeric.array(data, dtype=tc, copy=True, fortran=fortran)\n\n if need_data_copied:\n if tc == ctc:\n self._data = numeric.array(c, dtype=tc, copy=True, fortran=fortran)\n else:\n self._data = c.astype(tc)\n else:\n self._data = c\n\n if mask is nomask:\n self._mask = nomask\n self._shared_mask = 0\n else:\n self._mask = make_mask (mask)\n if self._mask is nomask:\n self._shared_mask = 0\n else:\n self._shared_mask = (self._mask is mask)\n nm = size(self._mask)\n nd = size(self._data)\n if nm != nd:\n if nm == 1:\n self._mask = oldnumeric.resize(self._mask, self._data.shape)\n self._shared_mask = 0\n elif nd == 1:\n self._data = oldnumeric.resize(self._data, self._mask.shape)\n self._data.shape = self._mask.shape\n else:\n raise MAError, \"Mask and data not compatible.\"\n elif nm == 1 and shape(self._mask) != shape(self._data):\n self.unshare_mask()\n self._mask.shape = self._data.shape\n\n self.set_fill_value(fill_value)\n\n def __array__ (self, t = None):\n \"Special hook for numeric. Converts to numeric if possible.\"\n if self._mask is not nomask:\n if oldnumeric.ravel(self._mask).any():\n raise MAError, \\\n \"\"\"Cannot automatically convert masked array to numeric because data\n is masked in one or more locations.\n \"\"\"\n else: # Mask is all false\n # Optimize to avoid future invocations of this section.\n self._mask = nomask\n self._shared_mask = 0\n if t:\n return self._data.astype(t)\n else:\n return self._data\n\n def __array_wrap__ (self, array):\n \"\"\"Special hook for ufuncs. Converts to Masked array with\n the same mask as self.\"\"\"\n return MaskedArray(array, copy=False, mask=self._mask,\n fill_value = self._fill_value)\n \n def _get_shape(self):\n \"Return the current shape.\"\n return self._data.shape\n\n def _set_shape (self, newshape):\n \"Set the array's shape.\"\n self._data.shape = newshape\n if self._mask is not nomask:\n self._mask = self._mask.copy()\n self._mask.shape = newshape\n\n def _get_flat(self):\n \"\"\"Calculate the flat value.\n \"\"\"\n if self._mask is nomask:\n return masked_array(self._data.ravel(), mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.ravel(),\n mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_flat (self, value):\n \"x.flat = value\"\n y = self.ravel()\n y[:] = value\n\n def _get_real(self):\n \"Get the real part of a complex array.\"\n if self._mask is nomask:\n return masked_array(self._data.real, mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.real, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_real (self, value):\n \"x.real = value\"\n y = self.real\n y[...] = value\n\n def _get_imaginary(self):\n \"Get the imaginary part of a complex array.\"\n if self._mask is nomask:\n return masked_array(self._data.imag, mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.imag, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_imaginary (self, value):\n \"x.imaginary = value\"\n y = self.imaginary\n y[...] = value\n\n def __str__(self):\n \"\"\"Calculate the str representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n if masked_print_option.enabled():\n f = masked_print_option\n # XXX: Without the following special case masked\n # XXX: would print as \"[--]\", not \"--\". Can we avoid\n # XXX: checks for masked by choosing a different value\n # XXX: for the masked singleton? 2005-01-05 -- sasha\n if self is masked:\n return str(f)\n # convert to object array to make filled work\n self = self.astype(object)\n else:\n f = self.fill_value()\n res = self.filled(f)\n return str(res)\n\n def __repr__(self):\n \"\"\"Calculate the repr representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n with_mask = \"\"\"\\\narray(data =\n %(data)s,\n mask =\n %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n with_mask1 = \"\"\"\\\narray(data = %(data)s,\n mask = %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n without_mask = \"\"\"array(\n %(data)s)\"\"\"\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n\n n = len(self.shape)\n if self._mask is nomask:\n if n <=1:\n return without_mask1 % {'data':str(self.filled())}\n return without_mask % {'data':str(self.filled())}\n else:\n if n <=1:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n if self._mask is nomask:\n return without_mask % {'data':str(self.filled())}\n else:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n\n def __float__(self):\n \"Convert self to float.\"\n self.unmask()\n if self._mask is not nomask:\n raise MAError, 'Cannot convert masked element to a Python float.'\n return float(self.data.item())\n\n def __int__(self):\n \"Convert self to int.\"\n self.unmask()\n if self._mask is not nomask:\n raise MAError, 'Cannot convert masked element to a Python int.'\n return int(self.data.item())\n\n def __getitem__(self, i):\n \"Get item described by i. Not a copy as in previous versions.\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i]\n if m is nomask:\n return dout\n mi = m[i]\n if mi.size == 1:\n if mi: \n return masked\n else:\n return dout\n else:\n return masked_array(dout, mi, fill_value=self._fill_value)\n\n def __getslice__(self, i, j):\n \"Get slice described by i, j\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i:j]\n if m is nomask:\n return masked_array(dout, fill_value=self._fill_value)\n else:\n return masked_array(dout, mask = m[i:j], fill_value=self._fill_value)\n\n# --------\n# setitem and setslice notes\n# note that if value is masked, it means to mask those locations.\n# setting a value changes the mask to match the value in those locations.\n\n def __setitem__(self, index, value):\n \"Set item described by index. If value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, 'Cannot alter the masked element.'\n if value is masked:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n else:\n self.unshare_mask()\n self._mask[index] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[index] = value\n if m is nomask:\n if self._mask is not nomask:\n self.unshare_mask()\n self._mask[index] = False\n else:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = True\n else:\n self.unshare_mask()\n self._mask[index] = m\n\n def __setslice__(self, i, j, value):\n \"Set slice i:j; if value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, \"Cannot alter the 'masked' object.\"\n if value is masked:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n self._mask[i:j] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[i:j] = value\n if m is nomask:\n if self._mask is not nomask:\n self.unshare_mask()\n self._mask[i:j] = False\n else:\n if self._mask is nomask:\n self._mask = make_mask_none(self._data.shape)\n self._shared_mask = False\n self._mask[i:j] = m\n\n def __nonzero__(self):\n \"\"\"returns true if any element is non-zero or masked\n\n \"\"\"\n # XXX: This changes bool conversion logic from MA.\n # XXX: In MA bool(a) == len(a) != 0, but in numpy\n # XXX: scalars do not have len \n m = self._mask\n d = self._data\n return bool(m is not nomask and m.any()\n or d is not nomask and d.any())\n \n def __len__ (self):\n \"\"\"Return length of first dimension. This is weird but Python's\n slicing behavior depends on it.\"\"\"\n return len(self._data)\n\n def __and__(self, other):\n \"Return bitwise_and\"\n return bitwise_and(self, other)\n\n def __or__(self, other):\n \"Return bitwise_or\"\n return bitwise_or(self, other)\n\n def __xor__(self, other):\n \"Return bitwise_xor\"\n return bitwise_xor(self, other)\n\n __rand__ = __and__\n __ror__ = __or__\n __rxor__ = __xor__\n\n def __abs__(self):\n \"Return absolute(self)\"\n return absolute(self)\n\n def __neg__(self):\n \"Return negative(self)\"\n return negative(self)\n\n def __pos__(self):\n \"Return array(self)\"\n return array(self)\n\n def __add__(self, other):\n \"Return add(self, other)\"\n return add(self, other)\n\n __radd__ = __add__\n\n def __mod__ (self, other):\n \"Return remainder(self, other)\"\n return remainder(self, other)\n\n def __rmod__ (self, other):\n \"Return remainder(other, self)\"\n return remainder(other, self)\n\n def __lshift__ (self, n):\n return left_shift(self, n)\n\n def __rshift__ (self, n):\n return right_shift(self, n)\n\n def __sub__(self, other):\n \"Return subtract(self, other)\"\n return subtract(self, other)\n\n def __rsub__(self, other):\n \"Return subtract(other, self)\"\n return subtract(other, self)\n\n def __mul__(self, other):\n \"Return multiply(self, other)\"\n return multiply(self, other)\n\n __rmul__ = __mul__\n\n def __div__(self, other):\n \"Return divide(self, other)\"\n return divide(self, other)\n\n def __rdiv__(self, other):\n \"Return divide(other, self)\"\n return divide(other, self)\n\n def __truediv__(self, other):\n \"Return divide(self, other)\"\n return true_divide(self, other)\n\n def __rtruediv__(self, other):\n \"Return divide(other, self)\"\n return true_divide(other, self)\n\n def __floordiv__(self, other):\n \"Return divide(self, other)\"\n return floor_divide(self, other)\n\n def __rfloordiv__(self, other):\n \"Return divide(other, self)\"\n return floor_divide(other, self)\n\n def __pow__(self,other, third=None):\n \"Return power(self, other, third)\"\n return power(self, other, third)\n\n def __sqrt__(self):\n \"Return sqrt(self)\"\n return sqrt(self)\n\n def __iadd__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data += f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = add(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __imul__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data *= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = multiply(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __isub__(self, other):\n \"Subtract other from self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data -= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = subtract(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n\n\n def __idiv__(self, other):\n \"Divide self by other in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n mo = getmask(other)\n result = divide(self, masked_array(f, mask=mo))\n self._data = result.data\n dm = result.raw_mask()\n if dm is not self._mask:\n self._mask = dm\n self._shared_mask = 1\n return self\n\n def __eq__(self,other):\n return equal(self,other)\n\n def __ne__(self,other):\n return not_equal(self,other)\n\n def __lt__(self,other):\n return less(self,other)\n\n def __le__(self,other):\n return less_equal(self,other)\n\n def __gt__(self,other):\n return greater(self,other)\n\n def __ge__(self,other):\n return greater_equal(self,other)\n\n def astype (self, tc):\n \"return self as array of given type.\"\n d = self._data.astype(tc)\n return array(d, mask=self._mask)\n\n def byte_swapped(self):\n \"\"\"Returns the raw data field, byte_swapped. Included for consistency\n with numeric but doesn't make sense in this context.\n \"\"\"\n return self._data.byte_swapped()\n\n def compressed (self):\n \"A 1-D array of all the non-masked data.\"\n d = oldnumeric.ravel(self._data)\n if self._mask is nomask:\n return array(d)\n else:\n m = 1 - oldnumeric.ravel(self._mask)\n c = oldnumeric.compress(m, d)\n return array(c, copy=0)\n\n def count (self, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n m = self._mask\n s = self._data.shape\n ls = len(s)\n if m is nomask:\n if ls == 0:\n return 1\n if ls == 1:\n return s[0]\n if axis is None:\n return reduce(lambda x,y:x*y, s)\n else:\n n = s[axis]\n t = list(s)\n del t[axis]\n return ones(t) * n\n if axis is None:\n w = oldnumeric.ravel(m).astype(int) \n n1 = size(w)\n if n1 == 1:\n n2 = w[0]\n else:\n n2 = umath.add.reduce(w)\n return n1 - n2\n else:\n n1 = size(m, axis)\n n2 = sum(m.astype(int), axis)\n return n1 - n2\n\n def dot (self, other):\n \"s.dot(other) = innerproduct(s, other)\"\n return innerproduct(self, other)\n\n def fill_value(self):\n \"Get the current fill value.\"\n return self._fill_value\n\n def filled (self, fill_value=None):\n \"\"\"A numeric array with masked values filled. If fill_value is None,\n use self.fill_value().\n\n If mask is nomask, copy data only if not contiguous.\n Result is always a contiguous, numeric array.\n# Is contiguous really necessary now?\n \"\"\"\n d = self._data\n m = self._mask\n if m is nomask:\n if d.flags['CONTIGUOUS']:\n return d\n else:\n return d.copy()\n else:\n if fill_value is None:\n value = self._fill_value\n else:\n value = fill_value\n\n if self is masked:\n result = numeric.array(value).reshape(*d.shape)\n else:\n try:\n result = numeric.array(d, dtype=d.dtype, copy=1)\n result[m] = value\n except (TypeError, AttributeError):\n #ok, can't put that value in here\n value = numeric.array(value, dtype=object)\n d = d.astype(object)\n result = oldnumeric.choose(m, (d, value))\n except IndexError:\n #ok, if scalar\n if d.shape:\n raise\n elif m:\n result = numeric.array(value, dtype=d.dtype)\n else:\n result = d\n return result\n\n def ids (self):\n \"\"\"Return the ids of the data and mask areas\"\"\"\n return (id(self._data), id(self._mask))\n\n def iscontiguous (self):\n \"Is the data contiguous?\"\n return self._data.flags['CONTIGUOUS']\n\n def itemsize(self):\n \"Item size of each data item.\"\n return self._data.itemsize\n\n\n def outer(self, other):\n \"s.outer(other) = outerproduct(s, other)\"\n return outerproduct(self, other)\n\n def put (self, values):\n \"\"\"Set the non-masked entries of self to filled(values).\n No change to mask\n \"\"\"\n iota = numeric.arange(self.size)\n d = self._data\n if self._mask is nomask:\n ind = iota\n else:\n ind = oldnumeric.compress(1 - self._mask, iota)\n d[ind] = filled(values).astype(d.dtype)\n\n def putmask (self, values):\n \"\"\"Set the masked entries of self to filled(values).\n Mask changed to nomask.\n \"\"\"\n d = self._data\n if self._mask is not nomask:\n d[self._mask] = filled(values).astype(d.dtype)\n self._shared_mask = 0\n self._mask = nomask\n\n def ravel (self):\n \"\"\"Return a 1-D view of self.\"\"\"\n if self._mask is nomask:\n return masked_array(self._data.ravel())\n else:\n return masked_array(self._data.ravel(), self._mask.ravel())\n\n def raw_data (self):\n \"\"\" Obsolete; use data property instead.\n The raw data; portions may be meaningless.\n May be noncontiguous. Expert use only.\"\"\"\n return self._data\n data = property(fget=raw_data, \n doc=\"The data, but values at masked locations are meaningless.\")\n\n def raw_mask (self):\n \"\"\" Obsolete; use mask property instead.\n May be noncontiguous. Expert use only.\n \"\"\"\n return self._mask\n mask = property(fget=raw_mask, \n doc=\"The mask, may be nomask. Values where mask true are meaningless.\")\n\n def reshape (self, *s):\n \"\"\"This array reshaped to shape s\"\"\"\n d = self._data.reshape(*s)\n if self._mask is nomask:\n return masked_array(d)\n else:\n m = self._mask.reshape(*s)\n return masked_array(d, m)\n\n def set_fill_value (self, v=None):\n \"Set the fill value to v. Omit v to restore default.\"\n if v is None:\n v = default_fill_value (self.raw_data())\n self._fill_value = v\n\n def _get_size (self):\n return self._data.size\n size = property(fget=_get_size, doc=\"Number of elements in the array.\")\n## CHECK THIS: signature of numeric.array.size?\n \n def _get_dtypechar(self):\n return self._data.dtypechar\n dtypechar = property(fget=_get_dtypechar, doc=\"type character of the array.\")\n\n def _get_dtype(self):\n return self._data.dtype\n dtype = property(fget=_get_dtype, doc=\"type of the array elements.\")\n\n def item(self):\n \"Return Python scalar if possible.\"\n if self._mask is not nomask:\n m = oldnumeric.ravel(self._mask)\n try:\n if m[0]:\n return masked\n except IndexError:\n return masked\n return self._data.item()\n\n def tolist(self, fill_value=None):\n \"Convert to list\"\n return self.filled(fill_value).tolist()\n\n def tostring(self, fill_value=None):\n \"Convert to string\"\n return self.filled(fill_value).tostring()\n\n def unmask (self):\n \"Replace the mask by nomask if possible.\"\n if self._mask is nomask: return\n m = make_mask(self._mask, flag=1)\n if m is nomask:\n self._mask = nomask\n self._shared_mask = 0\n\n def unshare_mask (self):\n \"If currently sharing mask, make a copy.\"\n if self._shared_mask:\n self._mask = make_mask (self._mask, copy=1, flag=0)\n self._shared_mask = 0\n\n shape = property(_get_shape, _set_shape,\n doc = 'tuple giving the shape of the array')\n\n flat = property(_get_flat, _set_flat,\n doc = 'Access array in flat form.')\n\n real = property(_get_real, _set_real,\n doc = 'Access the real part of the array')\n\n imaginary = property(_get_imaginary, _set_imaginary,\n doc = 'Access the imaginary part of the array')\n\n imag = imaginary\n\n#end class MaskedArray\n\narray = MaskedArray\n\ndef isMaskedArray (x):\n \"Is x a masked array, that is, an instance of MaskedArray?\"\n return isinstance(x, MaskedArray)\n\nisarray = isMaskedArray\nisMA = isMaskedArray #backward compatibility\n\ndef allclose (a, b, fill_value=1, rtol=1.e-5, atol=1.e-8):\n \"\"\" Returns true if all components of a and b are equal\n subject to given tolerances.\n If fill_value is 1, masked values considered equal.\n If fill_value is 0, masked values considered unequal.\n The relative error rtol should be positive and << 1.0\n The absolute error atol comes into play for those elements\n of b that are very small or zero; it says how small a must be also.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a)\n d2 = filled(b)\n x = filled(array(d1, copy=0, mask=m), fill_value).astype(float)\n y = filled(array(d2, copy=0, mask=m), 1).astype(float)\n d = umath.less_equal(umath.absolute(x-y), atol + rtol * umath.absolute(y))\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n\ndef allequal (a, b, fill_value=1):\n \"\"\"\n True if all entries of a and b are equal, using\n fill_value as a truth value where either or both are masked.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n if m is nomask:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n elif fill_value:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n dm = array(d, mask=m, copy=0)\n return oldnumeric.alltrue(oldnumeric.ravel(filled(dm, 1)))\n else:\n return 0\n\ndef masked_values (data, value, rtol=1.e-5, atol=1.e-8, copy=1):\n \"\"\"\n masked_values(data, value, rtol=1.e-5, atol=1.e-8)\n Create a masked array; mask is nomask if possible.\n If copy==0, and otherwise possible, result\n may share data values with original array.\n Let d = filled(data, value). Returns d\n masked where abs(data-value)<= atol + rtol * abs(value)\n if d is of a floating point type. Otherwise returns\n masked_object(d, value, copy)\n \"\"\"\n abs = umath.absolute\n d = filled(data, value)\n if issubclass(d.dtype, numeric.floating):\n m = umath.less_equal(abs(d-value), atol+rtol*abs(value))\n m = make_mask(m, flag=1)\n return array(d, mask = m, copy=copy,\n fill_value=value)\n else:\n return masked_object(d, value, copy=copy)\n\ndef masked_object (data, value, copy=1):\n \"Create array masked where exactly data equal to value\"\n d = filled(data, value)\n dm = make_mask(umath.equal(d, value), flag=1)\n return array(d, mask=dm, copy=copy, fill_value=value)\n\ndef arrayrange(start, stop=None, step=1, dtype=None):\n \"\"\"Just like range() except it returns a array whose type can be specified\n by the keyword argument dtypechar.\n \"\"\"\n return array(numeric.arrayrange(start, stop, step, dtype))\n\narange = arrayrange\n\ndef fromstring (s, t):\n \"Construct a masked array from a string. Result will have no mask.\"\n return masked_array(numeric.fromstring(s, t))\n\ndef left_shift (a, n):\n \"Left shift n bits\"\n m = getmask(a)\n if m is nomask:\n d = umath.left_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.left_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef right_shift (a, n):\n \"Right shift n bits\"\n m = getmask(a)\n if m is nomask:\n d = umath.right_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.right_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef resize (a, new_shape):\n \"\"\"resize(a, new_shape) returns a new array with the specified shape.\n The original array's total size can be any size.\"\"\"\n m = getmask(a)\n if m is not nomask:\n m = oldnumeric.resize(m, new_shape)\n result = array(oldnumeric.resize(filled(a), new_shape), mask=m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n \"\"\"\n af = filled(a)\n if isinstance(repeats, types.IntType):\n repeats = tuple([repeats]*(shape(af)[axis]))\n\n m = getmask(a)\n if m is not nomask:\n m = oldnumeric.repeat(m, repeats, axis)\n d = oldnumeric.repeat(af, repeats, axis)\n result = masked_array(d, m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef identity(n):\n \"\"\"identity(n) returns the identity matrix of shape n x n.\n \"\"\"\n return array(numeric.identity(n))\n\ndef indices (dimensions, dtype=None):\n \"\"\"indices(dimensions,dtype=None) returns an array representing a grid\n of indices with row-only, and column-only variation.\n \"\"\"\n return array(numeric.indices(dimensions, dtype))\n\ndef zeros (shape, dtype=int):\n \"\"\"zeros(n, dtype=int) =\n an array of all zeros of the given length or shape.\"\"\"\n return array(numeric.zeros(shape, dtype))\n\ndef ones (shape, dtype=int):\n \"\"\"ones(n, dtype=int) =\n an array of all ones of the given length or shape.\"\"\"\n return array(numeric.ones(shape, dtype))\n\n\ndef count (a, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n a = masked_array(a)\n return a.count(axis)\n\ndef power (a, b, third=None):\n \"a**b\"\n if third is not None:\n raise MAError, \"3-argument power not supported.\"\n ma = getmask(a)\n mb = getmask(b)\n m = mask_or(ma, mb)\n fa = filled(a, 1)\n fb = filled(b, 1)\n if fb.dtypechar in typecodes[\"Integer\"]:\n return masked_array(umath.power(fa, fb), m)\n md = make_mask(umath.less_equal (fa, 0), flag=1)\n m = mask_or(m, md)\n if m is nomask:\n return masked_array(umath.power(fa, fb))\n else:\n fa = numeric.where(m, 1, fa)\n return masked_array(umath.power(fa, fb), m)\n\ndef masked_array (a, mask=nomask, fill_value=None):\n \"\"\"masked_array(a, mask=nomask) =\n array(a, mask=mask, copy=0, fill_value=fill_value)\n \"\"\"\n return array(a, mask=mask, copy=0, fill_value=fill_value)\n\nsum = add.reduce\nproduct = multiply.reduce\n\ndef average (a, axis=0, weights=None, returned = 0):\n \"\"\"average(a, axis=0, weights=None)\n Computes average along indicated axis.\n If axis is None, average over the entire array\n Inputs can be integer or floating types; result is of type float.\n\n If weights are given, result is sum(a*weights)/(sum(weights)*1.0)\n weights must have a's shape or be the 1-d with length the size\n of a in the given axis.\n\n If returned, return a tuple: the result and the sum of the weights\n or count of values. Results will have the same shape.\n\n masked values in the weights will be set to 0.0\n \"\"\"\n a = masked_array(a)\n mask = a.mask\n ash = a.shape\n if ash == ():\n ash = (1,)\n if axis is None:\n if mask is nomask:\n if weights is None:\n n = add.reduce(a.raw_data().ravel())\n d = reduce(lambda x, y: x * y, ash, 1.0)\n else:\n w = filled(weights, 0.0).ravel()\n n = umath.add.reduce(a.raw_data().ravel() * w)\n d = umath.add.reduce(w)\n del w\n else:\n if weights is None:\n n = add.reduce(a.ravel())\n w = oldnumeric.choose(mask, (1.0,0.0)).ravel()\n d = umath.add.reduce(w)\n del w\n else:\n w = array(filled(weights, 0.0), float, mask=mask).ravel()\n n = add.reduce(a.ravel() * w)\n d = add.reduce(w)\n del w\n else:\n if mask is nomask:\n if weights is None:\n d = ash[axis] * 1.0\n n = umath.add.reduce(a.raw_data(), axis)\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = numeric.array(w, float, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * ones(ash, float)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w, r\n else:\n raise ValueError, 'average: weights wrong shape.'\n else:\n if weights is None:\n n = add.reduce(a, axis)\n w = numeric.choose(mask, (1.0, 0.0))\n d = umath.add.reduce(w, axis)\n del w\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = array(w, float, mask=mask, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * masked_array(ones(ash, float), mask)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n else:\n raise ValueError, 'average: weights wrong shape.'\n del w\n #print n, d, repr(mask), repr(weights)\n if n is masked or d is masked: return masked\n result = divide (n, d)\n del n\n\n if isinstance(result, MaskedArray):\n result.unmask()\n if returned:\n if not isinstance(d, MaskedArray):\n d = masked_array(d)\n if not d.shape == result.shape:\n d = ones(result.shape, float) * d\n d.unmask()\n if returned:\n return result, d\n else:\n return result\n\ndef where (condition, x, y):\n \"\"\"where(condition, x, y) is x where condition is nonzero, y otherwise.\n condition must be convertible to an integer array.\n Answer is always the shape of condition.\n The type depends on x and y. It is integer if both x and y are\n the value masked.\n \"\"\"\n fc = filled(not_equal(condition,0), 0)\n if x is masked:\n xv = 0\n xm = 1\n else:\n xv = filled(x)\n xm = getmask(x)\n if xm is nomask: xm = 0\n if y is masked:\n yv = 0\n ym = 1\n else:\n yv = filled(y)\n ym = getmask(y)\n if ym is nomask: ym = 0\n d = numeric.choose(fc, (yv, xv))\n md = numeric.choose(fc, (ym, xm))\n m = getmask(condition)\n m = make_mask(mask_or(m, md), copy=0, flag=1)\n return masked_array(d, m)\n\ndef choose (indices, t):\n \"Returns array shaped like indices with elements chosen from t\"\n def fmask (x):\n if x is masked: return 1\n return filled(x)\n def nmask (x):\n if x is masked: return 1\n m = getmask(x)\n if m is nomask: return 0\n return m\n c = filled(indices,0)\n masks = [nmask(x) for x in t]\n a = [fmask(x) for x in t]\n d = numeric.choose(c, a)\n m = numeric.choose(c, masks)\n m = make_mask(mask_or(m, getmask(indices)), copy=0, flag=1)\n return masked_array(d, m)\n\ndef masked_where(condition, x, copy=1):\n \"\"\"Return x as an array masked where condition is true.\n Also masked where x or condition masked.\n \"\"\"\n cm = filled(condition,1)\n m = mask_or(getmask(x), cm)\n return array(filled(x), copy=copy, mask=m)\n\ndef masked_greater(x, value, copy=1):\n \"masked_greater(x, value) = x masked where x > value\"\n return masked_where(greater(x, value), x, copy)\n\ndef masked_greater_equal(x, value, copy=1):\n \"masked_greater_equal(x, value) = x masked where x >= value\"\n return masked_where(greater_equal(x, value), x, copy)\n\ndef masked_less(x, value, copy=1):\n \"masked_less(x, value) = x masked where x < value\"\n return masked_where(less(x, value), x, copy)\n\ndef masked_less_equal(x, value, copy=1):\n \"masked_less_equal(x, value) = x masked where x <= value\"\n return masked_where(less_equal(x, value), x, copy)\n\ndef masked_not_equal(x, value, copy=1):\n \"masked_not_equal(x, value) = x masked where x != value\"\n d = filled(x,0)\n c = umath.not_equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_equal(x, value, copy=1):\n \"\"\"masked_equal(x, value) = x masked where x == value\n For floating point consider masked_values(x, value) instead.\n \"\"\"\n d = filled(x,0)\n c = umath.equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_inside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are inside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d=filled(x, 0)\n c = umath.logical_and(umath.less_equal(d, v2), umath.greater_equal(d, v1))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef masked_outside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are outside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d = filled(x,0)\n c = umath.logical_or(umath.less(d, v1), umath.greater(d, v2))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef reshape (a, *newshape):\n \"Copy of a with a new shape.\"\n m = getmask(a)\n d = filled(a).reshape(*newshape)\n if m is nomask:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.reshape(m, *newshape))\n\ndef ravel (a):\n \"a as one-dimensional, may share data and mask\"\n m = getmask(a)\n d = oldnumeric.ravel(filled(a))\n if m is nomask:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.ravel(m))\n\ndef concatenate (arrays, axis=0):\n \"Concatenate the arrays along the given axis\"\n d = []\n for x in arrays:\n d.append(filled(x))\n d = numeric.concatenate(d, axis)\n for x in arrays:\n if getmask(x) is not nomask: break\n else:\n return masked_array(d)\n dm = []\n for x in arrays:\n dm.append(getmaskarray(x))\n dm = numeric.concatenate(dm, axis)\n return masked_array(d, mask=dm)\n\ndef take (a, indices, axis=0):\n \"take(a, indices, axis=0) returns selection of items from a.\"\n m = getmask(a)\n d = masked_array(a).raw_data()\n if m is nomask:\n return masked_array(numeric.take(d, indices, axis))\n else:\n return masked_array(numeric.take(d, indices, axis),\n mask = numeric.take(m, indices, axis))\n\ndef transpose(a, axes=None):\n \"transpose(a, axes=None) reorder dimensions per tuple axes\"\n m = getmask(a)\n d = filled(a)\n if m is nomask:\n return masked_array(numeric.transpose(d, axes))\n else:\n return masked_array(numeric.transpose(d, axes),\n mask = numeric.transpose(m, axes))\n\n\ndef put(a, indices, values):\n \"\"\"put(a, indices, values) sets storage-indexed locations to corresponding values.\n\n Values and indices are filled if necessary.\n\n \"\"\"\n d = a.raw_data()\n ind = filled(indices)\n v = filled(values)\n numeric.put (d, ind, v)\n m = getmask(a)\n if m is not nomask:\n a.unshare_mask()\n numeric.put(a.raw_mask(), ind, 0)\n\ndef putmask(a, mask, values):\n \"putmask(a, mask, values) sets a where mask is true.\"\n if mask is nomask:\n return\n numeric.putmask(a.raw_data(), mask, values)\n m = getmask(a)\n if m is nomask: return\n a.unshare_mask()\n numeric.putmask(a.raw_mask(), mask, 0)\n\ndef innerproduct(a,b):\n \"\"\"innerproduct(a,b) returns the dot product of two arrays, which has\n shape a.shape[:-1] + b.shape[:-1] with elements computed by summing the\n product of the elements from the last dimensions of a and b.\n Masked elements are replace by zeros.\n \"\"\"\n fa = filled(a, 0)\n fb = filled(b, 0)\n if len(fa.shape) == 0: fa.shape = (1,)\n if len(fb.shape) == 0: fb.shape = (1,)\n return masked_array(numeric.innerproduct(fa, fb))\n\ndef outerproduct(a, b):\n \"\"\"outerproduct(a,b) = {a[i]*b[j]}, has shape (len(a),len(b))\"\"\"\n fa = filled(a,0).ravel()\n fb = filled(b,0).ravel()\n d = numeric.outerproduct(fa, fb)\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n return masked_array(d)\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = make_mask(1-numeric.outerproduct(1-ma,1-mb), copy=0)\n return masked_array(d, m)\n\ndef dot(a, b):\n \"\"\"dot(a,b) returns matrix-multiplication between a and b. The product-sum\n is over the last dimension of a and the second-to-last dimension of b.\n Masked values are replaced by zeros. See also innerproduct.\n \"\"\"\n return innerproduct(filled(a,0), numeric.swapaxes(filled(b,0), -1, -2))\n\ndef compress(condition, x, dimension=-1):\n \"\"\"Select those parts of x for which condition is true.\n Masked values in condition are considered false.\n \"\"\"\n c = filled(condition, 0)\n m = getmask(x)\n if m is not nomask:\n m=numeric.compress(c, m, dimension)\n d = numeric.compress(c, filled(x), dimension)\n return masked_array(d, m)\n\nclass _minimum_operation:\n \"Object to calculate minima\"\n def __init__ (self):\n \"\"\"minimum(a, b) or minimum(a)\n In one argument case returns the scalar minimum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is nomask:\n d = amin(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amin(ac.raw_data())\n else:\n return where(less(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is nomask:\n t = filled(target)\n return masked_array (umath.minimum.reduce (t, axis))\n else:\n t = umath.minimum.reduce(filled(target, minimum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.minimum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nminimum = _minimum_operation ()\n\nclass _maximum_operation:\n \"Object to calculate maxima\"\n def __init__ (self):\n \"\"\"maximum(a, b) or maximum(a)\n In one argument case returns the scalar maximum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is nomask:\n d = amax(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amax(ac.raw_data())\n else:\n return where(greater(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is nomask:\n t = filled(target)\n return masked_array (umath.maximum.reduce (t, axis))\n else:\n t = umath.maximum.reduce(filled(target, maximum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.maximum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nmaximum = _maximum_operation ()\n\ndef sort (x, axis = -1, fill_value=None):\n \"\"\"If x does not have a mask, return a masked array formed from the\n result of numeric.sort(x, axis).\n Otherwise, fill x with fill_value. Sort it.\n Set a mask where the result is equal to fill_value.\n Note that this may have unintended consequences if the data contains the\n fill value at a non-masked site.\n\n If fill_value is not given the default fill value for x's type will be\n used.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n d = filled(x, fill_value)\n s = oldnumeric.sort(d, axis)\n if getmask(x) is nomask:\n return masked_array(s)\n return masked_values(s, fill_value, copy=0)\n\ndef diagonal(a, k = 0, axis1=0, axis2=1):\n \"\"\"diagonal(a,k=0,axis1=0, axis2=1) = the k'th diagonal of a\"\"\"\n d = oldnumeric.diagonal(filled(a), k, axis1, axis2)\n m = getmask(a)\n if m is nomask:\n return masked_array(d, m)\n else:\n return masked_array(d, oldnumeric.diagonal(m, k, axis1, axis2))\n\ndef argsort (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for sorting along given axis.\n if fill_value is None, use get_fill_value(x)\n Returns a numpy array.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argsort(d, axis)\n\ndef argmin (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return indices for minimum values along given axis.\n if fill_value is None, use get_fill_value(x).\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argmin(d, axis)\n\ndef argmax (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for maximum along given axis.\n if fill_value is None, use -get_fill_value(x) if it exists.\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n try:\n fill_value = - fill_value\n except:\n pass\n d = filled(x, fill_value)\n return oldnumeric.argmax(d, axis)\n\ndef fromfunction (f, s):\n \"\"\"apply f to s to create array as in umath.\"\"\"\n return masked_array(numeric.fromfunction(f,s))\n\ndef asarray(data, dtype=None):\n \"\"\"asarray(data, dtype) = array(data, dtype, copy=0)\n \"\"\"\n if isinstance(data, MaskedArray) and \\\n (dtype is None or dtype == data.dtype):\n return data\n return array(data, dtype=dtype, copy=0)\n\n# Add methods to support ndarray interface\n# XXX: I is better to to change the masked_*_operation adaptors\n# XXX: to wrap ndarray methods directly to create ma.array methods.\nfrom types import MethodType\ndef _m(f):\n return MethodType(f, None, array)\ndef not_implemented(*args, **kwds):\n raise NotImplementedError, \"not yet implemented for numpy.ma arrays\"\narray.all = _m(alltrue)\narray.any = _m(sometrue)\narray.argmax = _m(argmax)\narray.argmin = _m(argmin)\narray.argsort = _m(argsort)\narray.base = property(_m(not_implemented))\narray.byteswap = _m(not_implemented)\n\ndef _choose(self, *args):\n return choose(self, args)\narray.choose = _m(_choose)\ndel _choose\n\narray.clip = _m(not_implemented)\n\ndef _compress(self, cond, axis=None):\n return compress(cond, self, axis)\narray.compress = _m(_compress)\ndel _compress\n\narray.conj = array.conjugate = _m(conjugate)\narray.copy = _m(not_implemented)\narray.cumprod = _m(not_implemented)\narray.cumsum = _m(not_implemented)\narray.diagonal = _m(diagonal)\narray.dtypedescr = property(_m(not_implemented))\narray.dtypestr = property(_m(not_implemented))\narray.dump = _m(not_implemented)\narray.dumps = _m(not_implemented)\narray.fill = _m(not_implemented)\narray.flags = property(_m(not_implemented))\narray.flatten = _m(ravel)\narray.getfield = _m(not_implemented)\narray.max = _m(maximum)\narray.mean = _m(average)\narray.min = _m(minimum)\narray.nbytes = property(_m(not_implemented))\narray.ndim = _m(not_implemented)\narray.newbyteorder = _m(not_implemented)\narray.nonzero = _m(nonzero)\narray.prod = _m(product)\narray.ptp = _m(not_implemented)\narray.repeat = _m(repeat)\narray.resize = _m(resize)\narray.searchsorted = _m(not_implemented)\narray.setfield = _m(not_implemented)\narray.setflags = _m(not_implemented)\narray.sort = _m(not_implemented) # NB: ndarray.sort is inplace\narray.squeeze = _m(not_implemented)\narray.std = _m(not_implemented)\narray.strides = property(_m(not_implemented))\narray.sum = _m(sum)\narray.swapaxes = _m(not_implemented)\narray.take = _m(take)\narray.tofile = _m(not_implemented)\narray.trace = _m(not_implemented)\narray.transpose = _m(transpose)\narray.var = _m(not_implemented)\narray.view = _m(not_implemented)\ndel _m, MethodType, not_implemented\n\n\nmasked = MaskedArray(0, int, mask=1)\n", + "source_code_before": "\"\"\"MA: a facility for dealing with missing observations\nMA is generally used as a numpy.array look-alike.\nby Paul F. Dubois.\n\nCopyright 1999, 2000, 2001 Regents of the University of California.\nReleased for unlimited redistribution.\nAdapted for numpy_core 2005 by Travis Oliphant and\n(mainly) Paul Dubois.\n\"\"\"\nimport string, types, sys\n\nimport umath\nimport oldnumeric\nfrom numeric import e, pi, newaxis, ndarray, inf\nfrom oldnumeric import typecodes, amax, amin\nfrom numerictypes import *\nimport numeric\n\n \nMaskType=bool_\ndivide_tolerance = 1.e-35\n\nclass MAError (Exception):\n def __init__ (self, args=None):\n \"Create an exception\"\n self.args = args\n def __str__(self):\n \"Calculate the string representation\"\n return str(self.args)\n __repr__ = __str__\n\nclass _MaskedPrintOption:\n \"One instance of this class, masked_print_option, is created.\"\n def __init__ (self, display):\n \"Create the masked print option object.\"\n self.set_display(display)\n self._enabled = 1\n\n def display (self):\n \"Show what prints for masked values.\"\n return self._display\n\n def set_display (self, s):\n \"set_display(s) sets what prints for masked values.\"\n self._display = s\n\n def enabled (self):\n \"Is the use of the display value enabled?\"\n return self._enabled\n\n def enable(self, flag=1):\n \"Set the enabling flag to flag.\"\n self._enabled = flag\n\n def __str__ (self):\n return str(self._display)\n\n __repr__ = __str__\n \n#if you single index into a masked location you get this object.\nmasked_print_option = _MaskedPrintOption('--')\n\n# Use single element arrays or scalars.\ndefault_real_fill_value = 1.e20\ndefault_complex_fill_value = 1.e20 + 0.0j\ndefault_character_fill_value = '-'\ndefault_integer_fill_value = 999999\ndefault_object_fill_value = '?'\n\ndef default_fill_value (obj):\n \"Function to calculate default fill value for an object.\"\n if isinstance(obj, types.FloatType):\n return default_real_fill_value\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return default_integer_fill_value\n elif isinstance(obj, types.StringType):\n return default_character_fill_value\n elif isinstance(obj, types.ComplexType):\n return default_complex_fill_value\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return default_real_fill_value\n if x in typecodes['Integer']:\n return default_integer_fill_value\n if x in typecodes['Complex']:\n return default_complex_fill_value\n if x in typecodes['Character']:\n return default_character_fill_value\n if x in typecodes['UnsignedInteger']:\n return umath.absolute(default_integer_fill_value)\n return default_object_fill_value\n else:\n return default_object_fill_value\n\ndef minimum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking minima.\"\n if isinstance(obj, types.FloatType):\n return numeric.inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return numeric.inf\n if x in typecodes['Integer']:\n return sys.maxint\n if x in typecodes['UnsignedInteger']:\n return sys.maxint\n else:\n raise TypeError, 'Unsuitable type for calculating minimum.'\n\ndef maximum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking maxima.\"\n if isinstance(obj, types.FloatType):\n return -inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return -sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return -inf\n if x in typecodes['Integer']:\n return -sys.maxint\n if x in typecodes['UnsignedInteger']:\n return 0\n else:\n raise TypeError, 'Unsuitable type for calculating maximum.'\n\ndef set_fill_value (a, fill_value):\n \"Set fill value of a if it is a masked array.\"\n if isMaskedArray(a):\n a.set_fill_value (fill_value)\n\ndef getmask (a):\n \"\"\"Mask of values in a; could be None.\n Returns None if a is not a masked array.\n To get an array for sure use getmaskarray.\"\"\"\n if isinstance(a, MaskedArray):\n return a.raw_mask()\n else:\n return None\n\ndef getmaskarray (a):\n \"\"\"Mask of values in a; an array of zeros if mask is None\n or not a masked array, and is a byte-sized integer.\n Do not try to add up entries, for example.\n \"\"\"\n m = getmask(a)\n if m is None:\n return make_mask_none(shape(a))\n else:\n return m\n\ndef is_mask (m):\n \"\"\"Is m a legal mask? Does not check contents, only type.\n \"\"\"\n if m is None or (isinstance(m, ndarray) and \\\n m.dtype is MaskType):\n return 1\n else:\n return 0\n\ndef make_mask (m, copy=0, flag=0):\n \"\"\"make_mask(m, copy=0, flag=0)\n return m as a mask, creating a copy if necessary or requested.\n Can accept any sequence of integers or None. Does not check\n that contents must be 0s and 1s.\n if flag, return None if m contains no true elements.\n \"\"\"\n if m is None:\n return None\n elif isinstance(m, ndarray):\n if m.dtype is MaskType:\n if copy:\n result = numeric.array(m, dtype=MaskType, copy=copy)\n else:\n result = m\n else:\n result = m.astype(MaskType)\n else:\n result = filled(m,True).astype(MaskType)\n\n if flag and not oldnumeric.sometrue(oldnumeric.ravel(result)):\n return None\n else:\n return result\n\ndef make_mask_none (s):\n \"Return a mask of all zeros of shape s.\"\n result = numeric.zeros(s, dtype=MaskType)\n result.shape = s\n return result\n\ndef mask_or (m1, m2):\n \"\"\"Logical or of the mask candidates m1 and m2, treating None as false.\n Result may equal m1 or m2 if the other is None.\n \"\"\"\n if m1 is None: return make_mask(m2)\n if m2 is None: return make_mask(m1)\n if m1 is m2 and is_mask(m1): return m1\n return make_mask(umath.logical_or(m1, m2))\n\ndef filled (a, value = None):\n \"\"\"a as a contiguous numeric array with any masked areas replaced by value\n if value is None or the special element \"masked\", get_fill_value(a)\n is used instead.\n\n If a is already a contiguous numeric array, a itself is returned.\n\n filled(a) can be used to be sure that the result is numeric when\n passing an object a to other software ignorant of MA, in particular to\n numeric itself.\n \"\"\"\n if isinstance(a, MaskedArray):\n return a.filled(value)\n elif isinstance(a, ndarray) and a.flags['CONTIGUOUS']:\n return a\n elif isinstance(a, types.DictType):\n return numeric.array(a, 'O')\n else:\n return numeric.array(a)\n\ndef get_fill_value (a):\n \"\"\"\n The fill value of a, if it has one; otherwise, the default fill value\n for that type.\n \"\"\"\n if isMaskedArray(a):\n result = a.fill_value()\n else:\n result = default_fill_value(a)\n return result\n\ndef common_fill_value (a, b):\n \"The common fill_value of a and b, if there is one, or None\"\n t1 = get_fill_value(a)\n t2 = get_fill_value(b)\n if t1 == t2: return t1\n return None\n\n# Domain functions return 1 where the argument(s) are not in the domain.\nclass domain_check_interval:\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n def __init__(self, y1, y2):\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n self.y1 = y1\n self.y2 = y2\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.logical_or(umath.greater (x, self.y2),\n umath.less(x, self.y1)\n )\n\nclass domain_tan:\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n def __init__(self, eps):\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n self.eps = eps\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less(umath.absolute(umath.cos(x)), self.eps)\n\nclass domain_greater:\n \"domain_greater(v)(x) = true where x <= v\"\n def __init__(self, critical_value):\n \"domain_greater(v)(x) = true where x <= v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less_equal (x, self.critical_value)\n\nclass domain_greater_equal:\n \"domain_greater_equal(v)(x) = true where x < v\"\n def __init__(self, critical_value):\n \"domain_greater_equal(v)(x) = true where x < v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less (x, self.critical_value)\n\nclass masked_unary_operation:\n def __init__ (self, aufunc, fill=0, domain=None):\n \"\"\" masked_unary_operation(aufunc, fill=0, domain=None)\n aufunc(fill) must be defined\n self(x) returns aufunc(x)\n with masked values where domain(x) is true or getmask(x) is true.\n \"\"\"\n self.f = aufunc\n self.fill = fill\n self.domain = domain\n self.__doc__ = getattr(aufunc, \"__doc__\", str(aufunc))\n\n def __call__ (self, a, *args, **kwargs):\n \"Execute the call behavior.\"\n# numeric tries to return scalars rather than arrays when given scalars.\n m = getmask(a)\n d1 = filled(a, self.fill)\n if self.domain is not None:\n m = mask_or(m, self.domain(d1))\n result = self.f(d1, *args, **kwargs)\n if m is not None:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\n\nclass domain_safe_divide:\n def __init__ (self, tolerance=divide_tolerance):\n self.tolerance = tolerance\n def __call__ (self, a, b):\n return umath.absolute(a) * self.tolerance >= umath.absolute(b)\n\nclass domained_binary_operation:\n \"\"\"Binary operations that have a domain, like divide. These are complicated so they\n are a separate class. They have no reduce, outer or accumulate.\n \"\"\"\n def __init__ (self, abfunc, domain, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.domain = domain\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__(self, a, b):\n \"Execute the call behavior.\"\n ma = getmask(a)\n mb = getmask(b)\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n t = self.domain(d1, d2)\n\n if oldnumeric.sometrue(t, None):\n d2 = where(t, self.filly, d2)\n mb = mask_or(mb, t)\n m = mask_or(ma, mb)\n result = self.f(d1, d2)\n if m is not None:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n \n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nclass masked_binary_operation:\n def __init__ (self, abfunc, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__ (self, a, b, *args, **kwargs):\n \"Execute the call behavior.\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n result = self.f(d1, d2, *args, **kwargs)\n if m is not None:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis with this function.\"\"\"\n m = getmask(target)\n t = filled(target, self.filly)\n if t.shape == ():\n t = t.reshape(1)\n if m is not None:\n m = make_mask(m, copy=1)\n m.shape = (1,)\n if m is None:\n return masked_array (self.f.reduce (t, axis))\n else:\n t = masked_array (t, m)\n t = self.f.reduce(filled(t, self.filly), axis)\n m = umath.logical_and.reduce(m, axis)\n if isinstance(t, ndarray):\n return masked_array(t, m, get_fill_value(target))\n elif m:\n return masked\n else:\n return t\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n m = None\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = self.f.outer(filled(a, self.fillx), filled(b, self.filly))\n return masked_array(d, m)\n\n def accumulate (self, target, axis=0):\n \"\"\"Accumulate target along axis after filling with y fill value.\"\"\"\n t = filled(target, self.filly)\n return masked_array (self.f.accumulate (t, axis))\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nsqrt = masked_unary_operation(umath.sqrt, 0.0, domain_greater_equal(0.0))\nlog = masked_unary_operation(umath.log, 1.0, domain_greater(0.0))\nlog10 = masked_unary_operation(umath.log10, 1.0, domain_greater(0.0))\nexp = masked_unary_operation(umath.exp)\nconjugate = masked_unary_operation(umath.conjugate)\nsin = masked_unary_operation(umath.sin)\ncos = masked_unary_operation(umath.cos)\ntan = masked_unary_operation(umath.tan, 0.0, domain_tan(1.e-35))\narcsin = masked_unary_operation(umath.arcsin, 0.0, domain_check_interval(-1.0, 1.0))\narccos = masked_unary_operation(umath.arccos, 0.0, domain_check_interval(-1.0, 1.0))\narctan = masked_unary_operation(umath.arctan)\n# Missing from numeric\narcsinh = masked_unary_operation(umath.arcsinh)\narccosh = masked_unary_operation(umath.arccosh)\narctanh = masked_unary_operation(umath.arctanh)\nsinh = masked_unary_operation(umath.sinh)\ncosh = masked_unary_operation(umath.cosh)\ntanh = masked_unary_operation(umath.tanh)\nabsolute = masked_unary_operation(umath.absolute)\nfabs = masked_unary_operation(umath.fabs)\nnegative = masked_unary_operation(umath.negative)\nnonzero = masked_unary_operation(oldnumeric.nonzero)\naround = masked_unary_operation(oldnumeric.round_)\nfloor = masked_unary_operation(umath.floor)\nceil = masked_unary_operation(umath.ceil)\nsometrue = masked_unary_operation(oldnumeric.sometrue)\nalltrue = masked_unary_operation(oldnumeric.alltrue, 1)\nlogical_not = masked_unary_operation(umath.logical_not)\n\nadd = masked_binary_operation(umath.add)\nsubtract = masked_binary_operation(umath.subtract)\nsubtract.reduce = None\nmultiply = masked_binary_operation(umath.multiply, 1, 1)\ndivide = domained_binary_operation(umath.divide, domain_safe_divide(), 0, 1)\ntrue_divide = domained_binary_operation(umath.true_divide, domain_safe_divide(), 0, 1)\nfloor_divide = domained_binary_operation(umath.floor_divide, domain_safe_divide(), 0, 1)\nremainder = domained_binary_operation(umath.remainder, domain_safe_divide(), 0, 1)\nfmod = domained_binary_operation(umath.fmod, domain_safe_divide(), 0, 1)\nhypot = masked_binary_operation(umath.hypot)\narctan2 = masked_binary_operation(umath.arctan2, 0.0, 1.0)\narctan2.reduce = None\nequal = masked_binary_operation(umath.equal)\nequal.reduce = None\nnot_equal = masked_binary_operation(umath.not_equal)\nnot_equal.reduce = None\nless_equal = masked_binary_operation(umath.less_equal)\nless_equal.reduce = None\ngreater_equal = masked_binary_operation(umath.greater_equal)\ngreater_equal.reduce = None\nless = masked_binary_operation(umath.less)\nless.reduce = None\ngreater = masked_binary_operation(umath.greater)\ngreater.reduce = None\nlogical_and = masked_binary_operation(umath.logical_and)\nlogical_or = masked_binary_operation(umath.logical_or)\nlogical_xor = masked_binary_operation(umath.logical_xor)\nbitwise_and = masked_binary_operation(umath.bitwise_and)\nbitwise_or = masked_binary_operation(umath.bitwise_or)\nbitwise_xor = masked_binary_operation(umath.bitwise_xor)\n\ndef rank (object):\n return oldnumeric.rank(filled(object))\n\ndef shape (object):\n return oldnumeric.shape(filled(object))\n\ndef size (object, axis=None):\n return oldnumeric.size(filled(object), axis)\n\nclass MaskedArray (object):\n \"\"\"Arrays with possibly masked values.\n Masked values of 1 exclude the corresponding element from \n any computation.\n\n Construction:\n x = array(data, dtype=None, copy=True, fortran=False,\n mask = None, fill_value=None)\n\n If copy=False, every effort is made not to copy the data:\n If data is a MaskedArray, and argument mask=None,\n then the candidate data is data.data and the\n mask used is data.mask. If data is a numeric array,\n it is used as the candidate raw data.\n If dtypechar is not None and\n is != data.dtypechar then a data copy is required.\n Otherwise, the candidate is used.\n\n If a data copy is required, raw data stored is the result of:\n numeric.array(data, dtype=dtypechar, copy=copy)\n\n If mask is None there are no masked values. Otherwise mask must\n be convertible to an array of booleans with the same shape as x.\n\n fill_value is used to fill in masked values when necessary,\n such as when printing and in method/function filled().\n The fill_value is not used for computation within this module.\n \"\"\"\n __array_priority__ = 10.1\n def __init__(self, data, dtype=None, copy=True, fortran=False, \n mask=None, fill_value=None):\n \"\"\"array(data, dtype=None, copy=True, fortran=False, mask=None, fill_value=None)\n If data already a numeric array, its dtype becomes the default value of dtype.\n \"\"\"\n tc = dtype\n need_data_copied = copy\n if isinstance(data, MaskedArray):\n c = data.data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n if mask is None:\n mask = data.mask\n elif mask is not None: #attempting to change the mask\n need_data_copied = True\n\n elif isinstance(data, ndarray):\n c = data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n else:\n need_data_copied = False #because I'll do it now\n c = numeric.array(data, dtype=tc, copy=True, fortran=fortran)\n\n if need_data_copied:\n if tc == ctc:\n self._data = numeric.array(c, dtype=tc, copy=True, fortran=fortran)\n else:\n self._data = c.astype(tc)\n else:\n self._data = c\n\n if mask is None:\n self._mask = None\n self._shared_mask = 0\n else:\n self._mask = make_mask (mask)\n if self._mask is None:\n self._shared_mask = 0\n else:\n self._shared_mask = (self._mask is mask)\n nm = size(self._mask)\n nd = size(self._data)\n if nm != nd:\n if nm == 1:\n self._mask = oldnumeric.resize(self._mask, self._data.shape)\n self._shared_mask = 0\n elif nd == 1:\n self._data = oldnumeric.resize(self._data, self._mask.shape)\n self._data.shape = self._mask.shape\n else:\n raise MAError, \"Mask and data not compatible.\"\n elif nm == 1 and shape(self._mask) != shape(self._data):\n self.unshare_mask()\n self._mask.shape = self._data.shape\n\n self.set_fill_value(fill_value)\n\n def __array__ (self, t = None):\n \"Special hook for numeric. Converts to numeric if possible.\"\n if self._mask is not None:\n if oldnumeric.ravel(self._mask).any():\n raise MAError, \\\n \"\"\"Cannot automatically convert masked array to numeric because data\n is masked in one or more locations.\n \"\"\"\n else: # Mask is all false\n # Optimize to avoid future invocations of this section.\n self._mask = None\n self._shared_mask = 0\n if t:\n return self._data.astype(t)\n else:\n return self._data\n\n def __array_wrap__ (self, array):\n \"\"\"Special hook for ufuncs. Converts to Masked array with\n the same mask as self.\"\"\"\n return MaskedArray(array, copy=False, mask=self._mask,\n fill_value = self._fill_value)\n \n def _get_shape(self):\n \"Return the current shape.\"\n return self._data.shape\n\n def _set_shape (self, newshape):\n \"Set the array's shape.\"\n self._data.shape = newshape\n if self._mask is not None:\n self._mask = self._mask.copy()\n self._mask.shape = newshape\n\n def _get_flat(self):\n \"\"\"Calculate the flat value.\n \"\"\"\n if self._mask is None:\n return masked_array(self._data.ravel(), mask=None,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.ravel(),\n mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_flat (self, value):\n \"x.flat = value\"\n y = self.ravel()\n y[:] = value\n\n def _get_real(self):\n \"Get the real part of a complex array.\"\n if self._mask is None:\n return masked_array(self._data.real, mask=None,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.real, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_real (self, value):\n \"x.real = value\"\n y = self.real\n y[...] = value\n\n def _get_imaginary(self):\n \"Get the imaginary part of a complex array.\"\n if self._mask is None:\n return masked_array(self._data.imag, mask=None,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.imag, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_imaginary (self, value):\n \"x.imaginary = value\"\n y = self.imaginary\n y[...] = value\n\n def __str__(self):\n \"\"\"Calculate the str representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n if masked_print_option.enabled():\n f = masked_print_option\n # XXX: Without the following special case masked\n # XXX: would print as \"[--]\", not \"--\". Can we avoid\n # XXX: checks for masked by choosing a different value\n # XXX: for the masked singleton? 2005-01-05 -- sasha\n if self is masked:\n return str(f)\n # convert to object array to make filled work\n self = self.astype(object)\n else:\n f = self.fill_value()\n res = self.filled(f)\n return str(res)\n\n def __repr__(self):\n \"\"\"Calculate the repr representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n with_mask = \"\"\"\\\narray(data =\n %(data)s,\n mask =\n %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n with_mask1 = \"\"\"\\\narray(data = %(data)s,\n mask = %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n without_mask = \"\"\"array(\n %(data)s)\"\"\"\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n\n n = len(self.shape)\n if self._mask is None:\n if n <=1:\n return without_mask1 % {'data':str(self.filled())}\n return without_mask % {'data':str(self.filled())}\n else:\n if n <=1:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n if self._mask is None:\n return without_mask % {'data':str(self.filled())}\n else:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n\n def __float__(self):\n \"Convert self to float.\"\n self.unmask()\n if self._mask is not None:\n raise MAError, 'Cannot convert masked element to a Python float.'\n return float(self.data.item())\n\n def __int__(self):\n \"Convert self to int.\"\n self.unmask()\n if self._mask is not None:\n raise MAError, 'Cannot convert masked element to a Python int.'\n return int(self.data.item())\n\n def __getitem__(self, i):\n \"Get item described by i. Not a copy as in previous versions.\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i]\n if m is None:\n return dout\n mi = m[i]\n if mi.size == 1:\n if mi: \n return masked\n else:\n return dout\n else:\n return masked_array(dout, mi, fill_value=self._fill_value)\n\n def __getslice__(self, i, j):\n \"Get slice described by i, j\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i:j]\n if m is None:\n return masked_array(dout, fill_value=self._fill_value)\n else:\n return masked_array(dout, mask = m[i:j], fill_value=self._fill_value)\n\n# --------\n# setitem and setslice notes\n# note that if value is masked, it means to mask those locations.\n# setting a value changes the mask to match the value in those locations.\n\n def __setitem__(self, index, value):\n \"Set item described by index. If value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, 'Cannot alter the masked element.'\n if value is masked:\n if self._mask is None:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n else:\n self.unshare_mask()\n self._mask[index] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[index] = value\n if m is None:\n if self._mask is not None:\n self.unshare_mask()\n self._mask[index] = False\n else:\n if self._mask is None:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = True\n else:\n self.unshare_mask()\n self._mask[index] = m\n\n def __setslice__(self, i, j, value):\n \"Set slice i:j; if value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, \"Cannot alter the 'masked' object.\"\n if value is masked:\n if self._mask is None:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n self._mask[i:j] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[i:j] = value\n if m is None:\n if self._mask is not None:\n self.unshare_mask()\n self._mask[i:j] = False\n else:\n if self._mask is None:\n self._mask = make_mask_none(self._data.shape)\n self._shared_mask = False\n self._mask[i:j] = m\n\n def __nonzero__(self):\n \"\"\"returns true if any element is non-zero or masked\n\n \"\"\"\n # XXX: This changes bool conversion logic from MA.\n # XXX: In MA bool(a) == len(a) != 0, but in numpy\n # XXX: scalars do not have len \n m = self._mask\n d = self._data\n return bool(m is not None and m.any()\n or d is not None and d.any())\n \n def __len__ (self):\n \"\"\"Return length of first dimension. This is weird but Python's\n slicing behavior depends on it.\"\"\"\n return len(self._data)\n\n def __and__(self, other):\n \"Return bitwise_and\"\n return bitwise_and(self, other)\n\n def __or__(self, other):\n \"Return bitwise_or\"\n return bitwise_or(self, other)\n\n def __xor__(self, other):\n \"Return bitwise_xor\"\n return bitwise_xor(self, other)\n\n __rand__ = __and__\n __ror__ = __or__\n __rxor__ = __xor__\n\n def __abs__(self):\n \"Return absolute(self)\"\n return absolute(self)\n\n def __neg__(self):\n \"Return negative(self)\"\n return negative(self)\n\n def __pos__(self):\n \"Return array(self)\"\n return array(self)\n\n def __add__(self, other):\n \"Return add(self, other)\"\n return add(self, other)\n\n __radd__ = __add__\n\n def __mod__ (self, other):\n \"Return remainder(self, other)\"\n return remainder(self, other)\n\n def __rmod__ (self, other):\n \"Return remainder(other, self)\"\n return remainder(other, self)\n\n def __lshift__ (self, n):\n return left_shift(self, n)\n\n def __rshift__ (self, n):\n return right_shift(self, n)\n\n def __sub__(self, other):\n \"Return subtract(self, other)\"\n return subtract(self, other)\n\n def __rsub__(self, other):\n \"Return subtract(other, self)\"\n return subtract(other, self)\n\n def __mul__(self, other):\n \"Return multiply(self, other)\"\n return multiply(self, other)\n\n __rmul__ = __mul__\n\n def __div__(self, other):\n \"Return divide(self, other)\"\n return divide(self, other)\n\n def __rdiv__(self, other):\n \"Return divide(other, self)\"\n return divide(other, self)\n\n def __truediv__(self, other):\n \"Return divide(self, other)\"\n return true_divide(self, other)\n\n def __rtruediv__(self, other):\n \"Return divide(other, self)\"\n return true_divide(other, self)\n\n def __floordiv__(self, other):\n \"Return divide(self, other)\"\n return floor_divide(self, other)\n\n def __rfloordiv__(self, other):\n \"Return divide(other, self)\"\n return floor_divide(other, self)\n\n def __pow__(self,other, third=None):\n \"Return power(self, other, third)\"\n return power(self, other, third)\n\n def __sqrt__(self):\n \"Return sqrt(self)\"\n return sqrt(self)\n\n def __iadd__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is None:\n self._data += f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not None\n else:\n result = add(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __imul__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is None:\n self._data *= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not None\n else:\n result = multiply(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __isub__(self, other):\n \"Subtract other from self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is None:\n self._data -= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not None\n else:\n result = subtract(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n\n\n def __idiv__(self, other):\n \"Divide self by other in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n mo = getmask(other)\n result = divide(self, masked_array(f, mask=mo))\n self._data = result.data\n dm = result.raw_mask()\n if dm is not self._mask:\n self._mask = dm\n self._shared_mask = 1\n return self\n\n def __eq__(self,other):\n return equal(self,other)\n\n def __ne__(self,other):\n return not_equal(self,other)\n\n def __lt__(self,other):\n return less(self,other)\n\n def __le__(self,other):\n return less_equal(self,other)\n\n def __gt__(self,other):\n return greater(self,other)\n\n def __ge__(self,other):\n return greater_equal(self,other)\n\n def astype (self, tc):\n \"return self as array of given type.\"\n d = self._data.astype(tc)\n return array(d, mask=self._mask)\n\n def byte_swapped(self):\n \"\"\"Returns the raw data field, byte_swapped. Included for consistency\n with numeric but doesn't make sense in this context.\n \"\"\"\n return self._data.byte_swapped()\n\n def compressed (self):\n \"A 1-D array of all the non-masked data.\"\n d = oldnumeric.ravel(self._data)\n if self._mask is None:\n return array(d)\n else:\n m = 1 - oldnumeric.ravel(self._mask)\n c = oldnumeric.compress(m, d)\n return array(c, copy=0)\n\n def count (self, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n m = self._mask\n s = self._data.shape\n ls = len(s)\n if m is None:\n if ls == 0:\n return 1\n if ls == 1:\n return s[0]\n if axis is None:\n return reduce(lambda x,y:x*y, s)\n else:\n n = s[axis]\n t = list(s)\n del t[axis]\n return ones(t) * n\n if axis is None:\n w = oldnumeric.ravel(m).astype(int) \n n1 = size(w)\n if n1 == 1:\n n2 = w[0]\n else:\n n2 = umath.add.reduce(w)\n return n1 - n2\n else:\n n1 = size(m, axis)\n n2 = sum(m.astype(int), axis)\n return n1 - n2\n\n def dot (self, other):\n \"s.dot(other) = innerproduct(s, other)\"\n return innerproduct(self, other)\n\n def fill_value(self):\n \"Get the current fill value.\"\n return self._fill_value\n\n def filled (self, fill_value=None):\n \"\"\"A numeric array with masked values filled. If fill_value is None,\n use self.fill_value().\n\n If mask is None, copy data only if not contiguous.\n Result is always a contiguous, numeric array.\n# Is contiguous really necessary now?\n \"\"\"\n d = self._data\n m = self._mask\n if m is None:\n if d.flags['CONTIGUOUS']:\n return d\n else:\n return d.copy()\n else:\n if fill_value is None:\n value = self._fill_value\n else:\n value = fill_value\n\n if self is masked:\n result = numeric.array(value).reshape(*d.shape)\n else:\n try:\n result = numeric.array(d, dtype=d.dtype, copy=1)\n result[m] = value\n except (TypeError, AttributeError):\n #ok, can't put that value in here\n value = numeric.array(value, dtype=object)\n d = d.astype(object)\n result = oldnumeric.choose(m, (d, value))\n except IndexError:\n #ok, if scalar\n if d.shape:\n raise\n elif m:\n result = numeric.array(value, dtype=d.dtype)\n else:\n result = d\n return result\n\n def ids (self):\n \"\"\"Return the ids of the data and mask areas\"\"\"\n return (id(self._data), id(self._mask))\n\n def iscontiguous (self):\n \"Is the data contiguous?\"\n return self._data.flags['CONTIGUOUS']\n\n def itemsize(self):\n \"Item size of each data item.\"\n return self._data.itemsize\n\n\n def outer(self, other):\n \"s.outer(other) = outerproduct(s, other)\"\n return outerproduct(self, other)\n\n def put (self, values):\n \"\"\"Set the non-masked entries of self to filled(values).\n No change to mask\n \"\"\"\n iota = numeric.arange(self.size)\n d = self._data\n if self._mask is None:\n ind = iota\n else:\n ind = oldnumeric.compress(1 - self._mask, iota)\n d[ind] = filled(values).astype(d.dtype)\n\n def putmask (self, values):\n \"\"\"Set the masked entries of self to filled(values).\n Mask changed to None.\n \"\"\"\n d = self._data\n if self._mask is not None:\n d[self._mask] = filled(values).astype(d.dtype)\n self._shared_mask = 0\n self._mask = None\n\n def ravel (self):\n \"\"\"Return a 1-D view of self.\"\"\"\n if self._mask is None:\n return masked_array(self._data.ravel())\n else:\n return masked_array(self._data.ravel(), self._mask.ravel())\n\n def raw_data (self):\n \"\"\" Obsolete; use data property instead.\n The raw data; portions may be meaningless.\n May be noncontiguous. Expert use only.\"\"\"\n return self._data\n data = property(fget=raw_data, \n doc=\"The data, but values at masked locations are meaningless.\")\n\n def raw_mask (self):\n \"\"\" Obsolete; use mask property instead.\n May be noncontiguous. Expert use only.\n \"\"\"\n return self._mask\n mask = property(fget=raw_mask, \n doc=\"The mask, may be None. Values where mask true are meaningless.\")\n\n def reshape (self, *s):\n \"\"\"This array reshaped to shape s\"\"\"\n d = self._data.reshape(*s)\n if self._mask is None:\n return masked_array(d)\n else:\n m = self._mask.reshape(*s)\n return masked_array(d, m)\n\n def set_fill_value (self, v=None):\n \"Set the fill value to v. Omit v to restore default.\"\n if v is None:\n v = default_fill_value (self.raw_data())\n self._fill_value = v\n\n def _get_size (self):\n return self._data.size\n size = property(fget=_get_size, doc=\"Number of elements in the array.\")\n## CHECK THIS: signature of numeric.array.size?\n \n def _get_dtypechar(self):\n return self._data.dtypechar\n dtypechar = property(fget=_get_dtypechar, doc=\"type character of the array.\")\n\n def _get_dtype(self):\n return self._data.dtype\n dtype = property(fget=_get_dtype, doc=\"type of the array elements.\")\n\n def item(self):\n \"Return Python scalar if possible.\"\n if self._mask is not None:\n m = oldnumeric.ravel(self._mask)\n try:\n if m[0]:\n return masked\n except IndexError:\n return masked\n return self._data.item()\n\n def tolist(self, fill_value=None):\n \"Convert to list\"\n return self.filled(fill_value).tolist()\n\n def tostring(self, fill_value=None):\n \"Convert to string\"\n return self.filled(fill_value).tostring()\n\n def unmask (self):\n \"Replace the mask by None if possible.\"\n if self._mask is None: return\n m = make_mask(self._mask, flag=1)\n if m is None:\n self._mask = None\n self._shared_mask = 0\n\n def unshare_mask (self):\n \"If currently sharing mask, make a copy.\"\n if self._shared_mask:\n self._mask = make_mask (self._mask, copy=1, flag=0)\n self._shared_mask = 0\n\n shape = property(_get_shape, _set_shape,\n doc = 'tuple giving the shape of the array')\n\n flat = property(_get_flat, _set_flat,\n doc = 'Access array in flat form.')\n\n real = property(_get_real, _set_real,\n doc = 'Access the real part of the array')\n\n imaginary = property(_get_imaginary, _set_imaginary,\n doc = 'Access the imaginary part of the array')\n\n imag = imaginary\n\n#end class MaskedArray\n\narray = MaskedArray\n\ndef isMaskedArray (x):\n \"Is x a masked array, that is, an instance of MaskedArray?\"\n return isinstance(x, MaskedArray)\n\nisarray = isMaskedArray\nisMA = isMaskedArray #backward compatibility\n\ndef allclose (a, b, fill_value=1, rtol=1.e-5, atol=1.e-8):\n \"\"\" Returns true if all components of a and b are equal\n subject to given tolerances.\n If fill_value is 1, masked values considered equal.\n If fill_value is 0, masked values considered unequal.\n The relative error rtol should be positive and << 1.0\n The absolute error atol comes into play for those elements\n of b that are very small or zero; it says how small a must be also.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a)\n d2 = filled(b)\n x = filled(array(d1, copy=0, mask=m), fill_value).astype(float)\n y = filled(array(d2, copy=0, mask=m), 1).astype(float)\n d = umath.less_equal(umath.absolute(x-y), atol + rtol * umath.absolute(y))\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n\ndef allequal (a, b, fill_value=1):\n \"\"\"\n True if all entries of a and b are equal, using\n fill_value as a truth value where either or both are masked.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n if m is None:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n elif fill_value:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n dm = array(d, mask=m, copy=0)\n return oldnumeric.alltrue(oldnumeric.ravel(filled(dm, 1)))\n else:\n return 0\n\ndef masked_values (data, value, rtol=1.e-5, atol=1.e-8, copy=1):\n \"\"\"\n masked_values(data, value, rtol=1.e-5, atol=1.e-8)\n Create a masked array; mask is None if possible.\n If copy==0, and otherwise possible, result\n may share data values with original array.\n Let d = filled(data, value). Returns d\n masked where abs(data-value)<= atol + rtol * abs(value)\n if d is of a floating point type. Otherwise returns\n masked_object(d, value, copy)\n \"\"\"\n abs = umath.absolute\n d = filled(data, value)\n if issubclass(d.dtype, numeric.floating):\n m = umath.less_equal(abs(d-value), atol+rtol*abs(value))\n m = make_mask(m, flag=1)\n return array(d, mask = m, copy=copy,\n fill_value=value)\n else:\n return masked_object(d, value, copy=copy)\n\ndef masked_object (data, value, copy=1):\n \"Create array masked where exactly data equal to value\"\n d = filled(data, value)\n dm = make_mask(umath.equal(d, value), flag=1)\n return array(d, mask=dm, copy=copy, fill_value=value)\n\ndef arrayrange(start, stop=None, step=1, dtype=None):\n \"\"\"Just like range() except it returns a array whose type can be specified\n by the keyword argument dtypechar.\n \"\"\"\n return array(numeric.arrayrange(start, stop, step, dtype))\n\narange = arrayrange\n\ndef fromstring (s, t):\n \"Construct a masked array from a string. Result will have no mask.\"\n return masked_array(numeric.fromstring(s, t))\n\ndef left_shift (a, n):\n \"Left shift n bits\"\n m = getmask(a)\n if m is None:\n d = umath.left_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.left_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef right_shift (a, n):\n \"Right shift n bits\"\n m = getmask(a)\n if m is None:\n d = umath.right_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.right_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef resize (a, new_shape):\n \"\"\"resize(a, new_shape) returns a new array with the specified shape.\n The original array's total size can be any size.\"\"\"\n m = getmask(a)\n if m is not None:\n m = oldnumeric.resize(m, new_shape)\n result = array(oldnumeric.resize(filled(a), new_shape), mask=m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n \"\"\"\n af = filled(a)\n if isinstance(repeats, types.IntType):\n repeats = tuple([repeats]*(shape(af)[axis]))\n\n m = getmask(a)\n if m is not None:\n m = oldnumeric.repeat(m, repeats, axis)\n d = oldnumeric.repeat(af, repeats, axis)\n result = masked_array(d, m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef identity(n):\n \"\"\"identity(n) returns the identity matrix of shape n x n.\n \"\"\"\n return array(numeric.identity(n))\n\ndef indices (dimensions, dtype=None):\n \"\"\"indices(dimensions,dtype=None) returns an array representing a grid\n of indices with row-only, and column-only variation.\n \"\"\"\n return array(numeric.indices(dimensions, dtype))\n\ndef zeros (shape, dtype=int):\n \"\"\"zeros(n, dtype=int) =\n an array of all zeros of the given length or shape.\"\"\"\n return array(numeric.zeros(shape, dtype))\n\ndef ones (shape, dtype=int):\n \"\"\"ones(n, dtype=int) =\n an array of all ones of the given length or shape.\"\"\"\n return array(numeric.ones(shape, dtype))\n\n\ndef count (a, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n a = masked_array(a)\n return a.count(axis)\n\ndef power (a, b, third=None):\n \"a**b\"\n if third is not None:\n raise MAError, \"3-argument power not supported.\"\n ma = getmask(a)\n mb = getmask(b)\n m = mask_or(ma, mb)\n fa = filled(a, 1)\n fb = filled(b, 1)\n if fb.dtypechar in typecodes[\"Integer\"]:\n return masked_array(umath.power(fa, fb), m)\n md = make_mask(umath.less_equal (fa, 0), flag=1)\n m = mask_or(m, md)\n if m is None:\n return masked_array(umath.power(fa, fb))\n else:\n fa = numeric.where(m, 1, fa)\n return masked_array(umath.power(fa, fb), m)\n\ndef masked_array (a, mask=None, fill_value=None):\n \"\"\"masked_array(a, mask=None) =\n array(a, mask=mask, copy=0, fill_value=fill_value)\n \"\"\"\n return array(a, mask=mask, copy=0, fill_value=fill_value)\n\nsum = add.reduce\nproduct = multiply.reduce\n\ndef average (a, axis=0, weights=None, returned = 0):\n \"\"\"average(a, axis=0, weights=None)\n Computes average along indicated axis.\n If axis is None, average over the entire array\n Inputs can be integer or floating types; result is of type float.\n\n If weights are given, result is sum(a*weights)/(sum(weights)*1.0)\n weights must have a's shape or be the 1-d with length the size\n of a in the given axis.\n\n If returned, return a tuple: the result and the sum of the weights\n or count of values. Results will have the same shape.\n\n masked values in the weights will be set to 0.0\n \"\"\"\n a = masked_array(a)\n mask = a.mask\n ash = a.shape\n if ash == ():\n ash = (1,)\n if axis is None:\n if mask is None:\n if weights is None:\n n = add.reduce(a.raw_data().ravel())\n d = reduce(lambda x, y: x * y, ash, 1.0)\n else:\n w = filled(weights, 0.0).ravel()\n n = umath.add.reduce(a.raw_data().ravel() * w)\n d = umath.add.reduce(w)\n del w\n else:\n if weights is None:\n n = add.reduce(a.ravel())\n w = oldnumeric.choose(mask, (1.0,0.0)).ravel()\n d = umath.add.reduce(w)\n del w\n else:\n w = array(filled(weights, 0.0), float, mask=mask).ravel()\n n = add.reduce(a.ravel() * w)\n d = add.reduce(w)\n del w\n else:\n if mask is None:\n if weights is None:\n d = ash[axis] * 1.0\n n = umath.add.reduce(a.raw_data(), axis)\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = numeric.array(w, float, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * ones(ash, float)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w, r\n else:\n raise ValueError, 'average: weights wrong shape.'\n else:\n if weights is None:\n n = add.reduce(a, axis)\n w = numeric.choose(mask, (1.0, 0.0))\n d = umath.add.reduce(w, axis)\n del w\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = array(w, float, mask=mask, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * masked_array(ones(ash, float), mask)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n else:\n raise ValueError, 'average: weights wrong shape.'\n del w\n #print n, d, repr(mask), repr(weights)\n if n is masked or d is masked: return masked\n result = divide (n, d)\n del n\n\n if isinstance(result, MaskedArray):\n result.unmask()\n if returned:\n if not isinstance(d, MaskedArray):\n d = masked_array(d)\n if not d.shape == result.shape:\n d = ones(result.shape, float) * d\n d.unmask()\n if returned:\n return result, d\n else:\n return result\n\ndef where (condition, x, y):\n \"\"\"where(condition, x, y) is x where condition is nonzero, y otherwise.\n condition must be convertible to an integer array.\n Answer is always the shape of condition.\n The type depends on x and y. It is integer if both x and y are\n the value masked.\n \"\"\"\n fc = filled(not_equal(condition,0), 0)\n if x is masked:\n xv = 0\n xm = 1\n else:\n xv = filled(x)\n xm = getmask(x)\n if xm is None: xm = 0\n if y is masked:\n yv = 0\n ym = 1\n else:\n yv = filled(y)\n ym = getmask(y)\n if ym is None: ym = 0\n d = numeric.choose(fc, (yv, xv))\n md = numeric.choose(fc, (ym, xm))\n m = getmask(condition)\n m = make_mask(mask_or(m, md), copy=0, flag=1)\n return masked_array(d, m)\n\ndef choose (indices, t):\n \"Returns array shaped like indices with elements chosen from t\"\n def fmask (x):\n if x is masked: return 1\n return filled(x)\n def nmask (x):\n if x is masked: return 1\n m = getmask(x)\n if m is None: return 0\n return m\n c = filled(indices,0)\n masks = [nmask(x) for x in t]\n a = [fmask(x) for x in t]\n d = numeric.choose(c, a)\n m = numeric.choose(c, masks)\n m = make_mask(mask_or(m, getmask(indices)), copy=0, flag=1)\n return masked_array(d, m)\n\ndef masked_where(condition, x, copy=1):\n \"\"\"Return x as an array masked where condition is true.\n Also masked where x or condition masked.\n \"\"\"\n cm = filled(condition,1)\n m = mask_or(getmask(x), cm)\n return array(filled(x), copy=copy, mask=m)\n\ndef masked_greater(x, value, copy=1):\n \"masked_greater(x, value) = x masked where x > value\"\n return masked_where(greater(x, value), x, copy)\n\ndef masked_greater_equal(x, value, copy=1):\n \"masked_greater_equal(x, value) = x masked where x >= value\"\n return masked_where(greater_equal(x, value), x, copy)\n\ndef masked_less(x, value, copy=1):\n \"masked_less(x, value) = x masked where x < value\"\n return masked_where(less(x, value), x, copy)\n\ndef masked_less_equal(x, value, copy=1):\n \"masked_less_equal(x, value) = x masked where x <= value\"\n return masked_where(less_equal(x, value), x, copy)\n\ndef masked_not_equal(x, value, copy=1):\n \"masked_not_equal(x, value) = x masked where x != value\"\n d = filled(x,0)\n c = umath.not_equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_equal(x, value, copy=1):\n \"\"\"masked_equal(x, value) = x masked where x == value\n For floating point consider masked_values(x, value) instead.\n \"\"\"\n d = filled(x,0)\n c = umath.equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_inside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are inside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d=filled(x, 0)\n c = umath.logical_and(umath.less_equal(d, v2), umath.greater_equal(d, v1))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef masked_outside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are outside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d = filled(x,0)\n c = umath.logical_or(umath.less(d, v1), umath.greater(d, v2))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef reshape (a, *newshape):\n \"Copy of a with a new shape.\"\n m = getmask(a)\n d = filled(a).reshape(*newshape)\n if m is None:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.reshape(m, *newshape))\n\ndef ravel (a):\n \"a as one-dimensional, may share data and mask\"\n m = getmask(a)\n d = oldnumeric.ravel(filled(a))\n if m is None:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.ravel(m))\n\ndef concatenate (arrays, axis=0):\n \"Concatenate the arrays along the given axis\"\n d = []\n for x in arrays:\n d.append(filled(x))\n d = numeric.concatenate(d, axis)\n for x in arrays:\n if getmask(x) is not None: break\n else:\n return masked_array(d)\n dm = []\n for x in arrays:\n dm.append(getmaskarray(x))\n dm = numeric.concatenate(dm, axis)\n return masked_array(d, mask=dm)\n\ndef take (a, indices, axis=0):\n \"take(a, indices, axis=0) returns selection of items from a.\"\n m = getmask(a)\n d = masked_array(a).raw_data()\n if m is None:\n return masked_array(numeric.take(d, indices, axis))\n else:\n return masked_array(numeric.take(d, indices, axis),\n mask = numeric.take(m, indices, axis))\n\ndef transpose(a, axes=None):\n \"transpose(a, axes=None) reorder dimensions per tuple axes\"\n m = getmask(a)\n d = filled(a)\n if m is None:\n return masked_array(numeric.transpose(d, axes))\n else:\n return masked_array(numeric.transpose(d, axes),\n mask = numeric.transpose(m, axes))\n\n\ndef put(a, indices, values):\n \"\"\"put(a, indices, values) sets storage-indexed locations to corresponding values.\n\n Values and indices are filled if necessary.\n\n \"\"\"\n d = a.raw_data()\n ind = filled(indices)\n v = filled(values)\n numeric.put (d, ind, v)\n m = getmask(a)\n if m is not None:\n a.unshare_mask()\n numeric.put(a.raw_mask(), ind, 0)\n\ndef putmask(a, mask, values):\n \"putmask(a, mask, values) sets a where mask is true.\"\n if mask is None:\n return\n numeric.putmask(a.raw_data(), mask, values)\n m = getmask(a)\n if m is None: return\n a.unshare_mask()\n numeric.putmask(a.raw_mask(), mask, 0)\n\ndef innerproduct(a,b):\n \"\"\"innerproduct(a,b) returns the dot product of two arrays, which has\n shape a.shape[:-1] + b.shape[:-1] with elements computed by summing the\n product of the elements from the last dimensions of a and b.\n Masked elements are replace by zeros.\n \"\"\"\n fa = filled(a, 0)\n fb = filled(b, 0)\n if len(fa.shape) == 0: fa.shape = (1,)\n if len(fb.shape) == 0: fb.shape = (1,)\n return masked_array(numeric.innerproduct(fa, fb))\n\ndef outerproduct(a, b):\n \"\"\"outerproduct(a,b) = {a[i]*b[j]}, has shape (len(a),len(b))\"\"\"\n fa = filled(a,0).ravel()\n fb = filled(b,0).ravel()\n d = numeric.outerproduct(fa, fb)\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n return masked_array(d)\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = make_mask(1-numeric.outerproduct(1-ma,1-mb), copy=0)\n return masked_array(d, m)\n\ndef dot(a, b):\n \"\"\"dot(a,b) returns matrix-multiplication between a and b. The product-sum\n is over the last dimension of a and the second-to-last dimension of b.\n Masked values are replaced by zeros. See also innerproduct.\n \"\"\"\n return innerproduct(filled(a,0), numeric.swapaxes(filled(b,0), -1, -2))\n\ndef compress(condition, x, dimension=-1):\n \"\"\"Select those parts of x for which condition is true.\n Masked values in condition are considered false.\n \"\"\"\n c = filled(condition, 0)\n m = getmask(x)\n if m is not None:\n m=numeric.compress(c, m, dimension)\n d = numeric.compress(c, filled(x), dimension)\n return masked_array(d, m)\n\nclass _minimum_operation:\n \"Object to calculate minima\"\n def __init__ (self):\n \"\"\"minimum(a, b) or minimum(a)\n In one argument case returns the scalar minimum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is None:\n d = amin(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amin(ac.raw_data())\n else:\n return where(less(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is None:\n t = filled(target)\n return masked_array (umath.minimum.reduce (t, axis))\n else:\n t = umath.minimum.reduce(filled(target, minimum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n m = None\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.minimum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nminimum = _minimum_operation ()\n\nclass _maximum_operation:\n \"Object to calculate maxima\"\n def __init__ (self):\n \"\"\"maximum(a, b) or maximum(a)\n In one argument case returns the scalar maximum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is None:\n d = amax(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amax(ac.raw_data())\n else:\n return where(greater(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is None:\n t = filled(target)\n return masked_array (umath.maximum.reduce (t, axis))\n else:\n t = umath.maximum.reduce(filled(target, maximum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is None and mb is None:\n m = None\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.maximum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nmaximum = _maximum_operation ()\n\ndef sort (x, axis = -1, fill_value=None):\n \"\"\"If x does not have a mask, return a masked array formed from the\n result of numeric.sort(x, axis).\n Otherwise, fill x with fill_value. Sort it.\n Set a mask where the result is equal to fill_value.\n Note that this may have unintended consequences if the data contains the\n fill value at a non-masked site.\n\n If fill_value is not given the default fill value for x's type will be\n used.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n d = filled(x, fill_value)\n s = oldnumeric.sort(d, axis)\n if getmask(x) is None:\n return masked_array(s)\n return masked_values(s, fill_value, copy=0)\n\ndef diagonal(a, k = 0, axis1=0, axis2=1):\n \"\"\"diagonal(a,k=0,axis1=0, axis2=1) = the k'th diagonal of a\"\"\"\n d = oldnumeric.diagonal(filled(a), k, axis1, axis2)\n m = getmask(a)\n if m is None:\n return masked_array(d, m)\n else:\n return masked_array(d, oldnumeric.diagonal(m, k, axis1, axis2))\n\ndef argsort (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for sorting along given axis.\n if fill_value is None, use get_fill_value(x)\n Returns a numpy array.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argsort(d, axis)\n\ndef argmin (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return indices for minimum values along given axis.\n if fill_value is None, use get_fill_value(x).\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argmin(d, axis)\n\ndef argmax (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for maximum along given axis.\n if fill_value is None, use -get_fill_value(x) if it exists.\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n try:\n fill_value = - fill_value\n except:\n pass\n d = filled(x, fill_value)\n return oldnumeric.argmax(d, axis)\n\ndef fromfunction (f, s):\n \"\"\"apply f to s to create array as in umath.\"\"\"\n return masked_array(numeric.fromfunction(f,s))\n\ndef asarray(data, dtype=None):\n \"\"\"asarray(data, dtype) = array(data, dtype, copy=0)\n \"\"\"\n if isinstance(data, MaskedArray) and \\\n (dtype is None or dtype == data.dtype):\n return data\n return array(data, dtype=dtype, copy=0)\n\n# Add methods to support ndarray interface\n# XXX: I is better to to change the masked_*_operation adaptors\n# XXX: to wrap ndarray methods directly to create ma.array methods.\nfrom types import MethodType\ndef _m(f):\n return MethodType(f, None, array)\ndef not_implemented(*args, **kwds):\n raise NotImplementedError, \"not yet implemented for numpy.ma arrays\"\narray.all = _m(alltrue)\narray.any = _m(sometrue)\narray.argmax = _m(argmax)\narray.argmin = _m(argmin)\narray.argsort = _m(argsort)\narray.base = property(_m(not_implemented))\narray.byteswap = _m(not_implemented)\n\ndef _choose(self, *args):\n return choose(self, args)\narray.choose = _m(_choose)\ndel _choose\n\narray.clip = _m(not_implemented)\n\ndef _compress(self, cond, axis=None):\n return compress(cond, self, axis)\narray.compress = _m(_compress)\ndel _compress\n\narray.conj = array.conjugate = _m(conjugate)\narray.copy = _m(not_implemented)\narray.cumprod = _m(not_implemented)\narray.cumsum = _m(not_implemented)\narray.diagonal = _m(diagonal)\narray.dtypedescr = property(_m(not_implemented))\narray.dtypestr = property(_m(not_implemented))\narray.dump = _m(not_implemented)\narray.dumps = _m(not_implemented)\narray.fill = _m(not_implemented)\narray.flags = property(_m(not_implemented))\narray.flatten = _m(ravel)\narray.getfield = _m(not_implemented)\narray.max = _m(maximum)\narray.mean = _m(average)\narray.min = _m(minimum)\narray.nbytes = property(_m(not_implemented))\narray.ndim = _m(not_implemented)\narray.newbyteorder = _m(not_implemented)\narray.nonzero = _m(nonzero)\narray.prod = _m(product)\narray.ptp = _m(not_implemented)\narray.repeat = _m(repeat)\narray.resize = _m(resize)\narray.searchsorted = _m(not_implemented)\narray.setfield = _m(not_implemented)\narray.setflags = _m(not_implemented)\narray.sort = _m(not_implemented) # NB: ndarray.sort is inplace\narray.squeeze = _m(not_implemented)\narray.std = _m(not_implemented)\narray.strides = property(_m(not_implemented))\narray.sum = _m(sum)\narray.swapaxes = _m(not_implemented)\narray.take = _m(take)\narray.tofile = _m(not_implemented)\narray.trace = _m(not_implemented)\narray.transpose = _m(transpose)\narray.var = _m(not_implemented)\narray.view = _m(not_implemented)\ndel _m, MethodType, not_implemented\n\n\nmasked = MaskedArray(0, int, mask=1)\n", + "methods": [ + { + "name": "__init__", + "long_name": "__init__( self , args = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 25, + "end_line": 27, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 28, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , display )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "display" + ], + "start_line": 35, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "display", + "long_name": "display( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 40, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "set_display", + "long_name": "set_display( self , s )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "s" + ], + "start_line": 44, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enabled", + "long_name": "enabled( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 48, + "end_line": 50, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enable", + "long_name": "enable( self , flag = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "flag" + ], + "start_line": 52, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 56, + "end_line": 57, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "default_fill_value", + "long_name": "default_fill_value( obj )", + "filename": "ma.py", + "nloc": 25, + "complexity": 13, + "token_count": 144, + "parameters": [ + "obj" + ], + "start_line": 71, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "minimum_fill_value", + "long_name": "minimum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 105, + "parameters": [ + "obj" + ], + "start_line": 97, + "end_line": 112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "maximum_fill_value", + "long_name": "maximum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 103, + "parameters": [ + "obj" + ], + "start_line": 114, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( a , fill_value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 2, + "token_count": 20, + "parameters": [ + "a", + "fill_value" + ], + "start_line": 131, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "getmask", + "long_name": "getmask( a )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "a" + ], + "start_line": 136, + "end_line": 143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "getmaskarray", + "long_name": "getmaskarray( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 145, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "is_mask", + "long_name": "is_mask( m )", + "filename": "ma.py", + "nloc": 6, + "complexity": 4, + "token_count": 33, + "parameters": [ + "m" + ], + "start_line": 156, + "end_line": 163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "make_mask", + "long_name": "make_mask( m , copy = 0 , flag = 0 )", + "filename": "ma.py", + "nloc": 17, + "complexity": 7, + "token_count": 107, + "parameters": [ + "m", + "copy", + "flag" + ], + "start_line": 165, + "end_line": 188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "make_mask_none", + "long_name": "make_mask_none( s )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 25, + "parameters": [ + "s" + ], + "start_line": 190, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "mask_or", + "long_name": "mask_or( m1 , m2 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 5, + "token_count": 52, + "parameters": [ + "m1", + "m2" + ], + "start_line": 196, + "end_line": 203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "filled", + "long_name": "filled( a , value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 5, + "token_count": 70, + "parameters": [ + "a", + "value" + ], + "start_line": 205, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "get_fill_value", + "long_name": "get_fill_value( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 225, + "end_line": 234, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "common_fill_value", + "long_name": "common_fill_value( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a", + "b" + ], + "start_line": 236, + "end_line": 241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , y1 , y2 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "y1", + "y2" + ], + "start_line": 246, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 35, + "parameters": [ + "self", + "x" + ], + "start_line": 251, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , eps )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "eps" + ], + "start_line": 259, + "end_line": 261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "x" + ], + "start_line": 263, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 269, + "end_line": 271, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 273, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 279, + "end_line": 281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 283, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , aufunc , fill = 0 , domain = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "aufunc", + "fill", + "domain" + ], + "start_line": 288, + "end_line": 297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 16, + "complexity": 5, + "token_count": 112, + "parameters": [ + "self", + "a", + "args", + "kwargs" + ], + "start_line": 299, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 317, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , tolerance = divide_tolerance )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "tolerance" + ], + "start_line": 322, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 324, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , domain , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 53, + "parameters": [ + "self", + "abfunc", + "domain", + "fillx", + "filly" + ], + "start_line": 331, + "end_line": 339, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 147, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 341, + "end_line": 362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 364, + "end_line": 365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "abfunc", + "fillx", + "filly" + ], + "start_line": 368, + "end_line": 375, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 113, + "parameters": [ + "self", + "a", + "b", + "args", + "kwargs" + ], + "start_line": 377, + "end_line": 391, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 20, + "complexity": 6, + "token_count": 157, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 393, + "end_line": 413, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 415, + "end_line": 426, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "accumulate", + "long_name": "accumulate( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 428, + "end_line": 431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 432, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "rank", + "long_name": "rank( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 495, + "end_line": 496, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 498, + "end_line": 499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( object , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 21, + "parameters": [ + "object", + "axis" + ], + "start_line": 501, + "end_line": 502, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , data , dtype = None , copy = True , fortran = False , mask = nomask , fill_value = None )", + "filename": "ma.py", + "nloc": 56, + "complexity": 18, + "token_count": 379, + "parameters": [ + "self", + "data", + "dtype", + "copy", + "fortran", + "mask", + "fill_value" + ], + "start_line": 533, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "__array__", + "long_name": "__array__( self , t = None )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 67, + "parameters": [ + "self", + "t" + ], + "start_line": 597, + "end_line": 612, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__array_wrap__", + "long_name": "__array_wrap__( self , array )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "array" + ], + "start_line": 614, + "end_line": 618, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_shape", + "long_name": "_get_shape( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 620, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_set_shape", + "long_name": "_set_shape( self , newshape )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "newshape" + ], + "start_line": 624, + "end_line": 629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_get_flat", + "long_name": "_get_flat( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 631, + "end_line": 640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "_set_flat", + "long_name": "_set_flat( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "value" + ], + "start_line": 642, + "end_line": 645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_real", + "long_name": "_get_real( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 647, + "end_line": 654, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_real", + "long_name": "_set_real( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 656, + "end_line": 659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_imaginary", + "long_name": "_get_imaginary( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 661, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_imaginary", + "long_name": "_set_imaginary( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 670, + "end_line": 673, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 675, + "end_line": 692, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "ma.py", + "nloc": 42, + "complexity": 5, + "token_count": 207, + "parameters": [ + "self" + ], + "start_line": 694, + "end_line": 739, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 1 + }, + { + "name": "__float__", + "long_name": "__float__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 741, + "end_line": 746, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__int__", + "long_name": "__int__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 748, + "end_line": 753, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , i )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 70, + "parameters": [ + "self", + "i" + ], + "start_line": 755, + "end_line": 769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 771, + "end_line": 779, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__setitem__", + "long_name": "__setitem__( self , index , value )", + "filename": "ma.py", + "nloc": 27, + "complexity": 7, + "token_count": 157, + "parameters": [ + "self", + "index", + "value" + ], + "start_line": 786, + "end_line": 812, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "__setslice__", + "long_name": "__setslice__( self , i , j , value )", + "filename": "ma.py", + "nloc": 23, + "complexity": 7, + "token_count": 155, + "parameters": [ + "self", + "i", + "j", + "value" + ], + "start_line": 814, + "end_line": 836, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "__nonzero__", + "long_name": "__nonzero__( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 838, + "end_line": 848, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 850, + "end_line": 853, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__and__", + "long_name": "__and__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 855, + "end_line": 857, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__or__", + "long_name": "__or__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 859, + "end_line": 861, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__xor__", + "long_name": "__xor__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 863, + "end_line": 865, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__abs__", + "long_name": "__abs__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 871, + "end_line": 873, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__neg__", + "long_name": "__neg__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 875, + "end_line": 877, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pos__", + "long_name": "__pos__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 879, + "end_line": 881, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__add__", + "long_name": "__add__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 883, + "end_line": 885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mod__", + "long_name": "__mod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 889, + "end_line": 891, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rmod__", + "long_name": "__rmod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 893, + "end_line": 895, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__lshift__", + "long_name": "__lshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 897, + "end_line": 898, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__rshift__", + "long_name": "__rshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 900, + "end_line": 901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__sub__", + "long_name": "__sub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 903, + "end_line": 905, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rsub__", + "long_name": "__rsub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 907, + "end_line": 909, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mul__", + "long_name": "__mul__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 911, + "end_line": 913, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__div__", + "long_name": "__div__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 917, + "end_line": 919, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rdiv__", + "long_name": "__rdiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 921, + "end_line": 923, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__truediv__", + "long_name": "__truediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 925, + "end_line": 927, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rtruediv__", + "long_name": "__rtruediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 929, + "end_line": 931, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__floordiv__", + "long_name": "__floordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 933, + "end_line": 935, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rfloordiv__", + "long_name": "__rfloordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 937, + "end_line": 939, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pow__", + "long_name": "__pow__( self , other , third = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "other", + "third" + ], + "start_line": 941, + "end_line": 943, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__sqrt__", + "long_name": "__sqrt__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 945, + "end_line": 947, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__iadd__", + "long_name": "__iadd__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 949, + "end_line": 990, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__imul__", + "long_name": "__imul__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 251, + "parameters": [ + "self", + "other" + ], + "start_line": 992, + "end_line": 1033, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__isub__", + "long_name": "__isub__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 1035, + "end_line": 1076, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__idiv__", + "long_name": "__idiv__( self , other )", + "filename": "ma.py", + "nloc": 38, + "complexity": 12, + "token_count": 233, + "parameters": [ + "self", + "other" + ], + "start_line": 1080, + "end_line": 1117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 1 + }, + { + "name": "__eq__", + "long_name": "__eq__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1119, + "end_line": 1120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ne__", + "long_name": "__ne__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1122, + "end_line": 1123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__lt__", + "long_name": "__lt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1125, + "end_line": 1126, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__le__", + "long_name": "__le__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1128, + "end_line": 1129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__gt__", + "long_name": "__gt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1131, + "end_line": 1132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ge__", + "long_name": "__ge__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1134, + "end_line": 1135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "astype", + "long_name": "astype( self , tc )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "tc" + ], + "start_line": 1137, + "end_line": 1140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "byte_swapped", + "long_name": "byte_swapped( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 1142, + "end_line": 1146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "compressed", + "long_name": "compressed( self )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 1148, + "end_line": 1156, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "count", + "long_name": "count( self , axis = None )", + "filename": "ma.py", + "nloc": 29, + "complexity": 7, + "token_count": 173, + "parameters": [ + "self", + "axis" + ], + "start_line": 1158, + "end_line": 1186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "dot", + "long_name": "dot( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1188, + "end_line": 1190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "fill_value", + "long_name": "fill_value( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1192, + "end_line": 1194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "filled", + "long_name": "filled( self , fill_value = None )", + "filename": "ma.py", + "nloc": 31, + "complexity": 9, + "token_count": 183, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1196, + "end_line": 1236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + }, + { + "name": "ids", + "long_name": "ids( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 1238, + "end_line": 1240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "iscontiguous", + "long_name": "iscontiguous( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 1242, + "end_line": 1244, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "itemsize", + "long_name": "itemsize( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 1246, + "end_line": 1248, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1251, + "end_line": 1253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "put", + "long_name": "put( self , values )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "values" + ], + "start_line": 1255, + "end_line": 1265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "putmask", + "long_name": "putmask( self , values )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "values" + ], + "start_line": 1267, + "end_line": 1275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "ravel", + "long_name": "ravel( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 1277, + "end_line": 1282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "raw_data", + "long_name": "raw_data( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1284, + "end_line": 1288, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "raw_mask", + "long_name": "raw_mask( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1292, + "end_line": 1296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "reshape", + "long_name": "reshape( self , * s )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self", + "s" + ], + "start_line": 1300, + "end_line": 1307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( self , v = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self", + "v" + ], + "start_line": 1309, + "end_line": 1313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_size", + "long_name": "_get_size( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1315, + "end_line": 1316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtypechar", + "long_name": "_get_dtypechar( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1320, + "end_line": 1321, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtype", + "long_name": "_get_dtype( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1324, + "end_line": 1325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "item", + "long_name": "item( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 4, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 1328, + "end_line": 1337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "tolist", + "long_name": "tolist( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1339, + "end_line": 1341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "tostring", + "long_name": "tostring( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1343, + "end_line": 1345, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "unmask", + "long_name": "unmask( self )", + "filename": "ma.py", + "nloc": 7, + "complexity": 3, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 1347, + "end_line": 1353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "unshare_mask", + "long_name": "unshare_mask( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 1355, + "end_line": 1359, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "isMaskedArray", + "long_name": "isMaskedArray( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "x" + ], + "start_line": 1379, + "end_line": 1381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "allclose", + "long_name": "allclose( a , b , fill_value = 1 , rtol = 1 . e - 5 , atol = 1 . e - 8 )", + "filename": "ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 140, + "parameters": [ + "a", + "b", + "fill_value", + "rtol", + "atol" + ], + "start_line": 1386, + "end_line": 1401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "allequal", + "long_name": "allequal( a , b , fill_value = 1 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 3, + "token_count": 125, + "parameters": [ + "a", + "b", + "fill_value" + ], + "start_line": 1403, + "end_line": 1421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "masked_values", + "long_name": "masked_values( data , value , rtol = 1 . e - 5 , atol = 1 . e - 8 , copy = 1 )", + "filename": "ma.py", + "nloc": 10, + "complexity": 2, + "token_count": 115, + "parameters": [ + "data", + "value", + "rtol", + "atol", + "copy" + ], + "start_line": 1423, + "end_line": 1442, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "masked_object", + "long_name": "masked_object( data , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "data", + "value", + "copy" + ], + "start_line": 1444, + "end_line": 1448, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayrange", + "long_name": "arrayrange( start , stop = None , step = 1 , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 34, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 1450, + "end_line": 1454, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "fromstring", + "long_name": "fromstring( s , t )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "s", + "t" + ], + "start_line": 1458, + "end_line": 1460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "left_shift", + "long_name": "left_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1462, + "end_line": 1470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "right_shift", + "long_name": "right_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1472, + "end_line": 1480, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 1482, + "end_line": 1490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 101, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 1492, + "end_line": 1507, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "identity", + "long_name": "identity( n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "n" + ], + "start_line": 1509, + "end_line": 1512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "indices", + "long_name": "indices( dimensions , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "dimensions", + "dtype" + ], + "start_line": 1514, + "end_line": 1518, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "zeros", + "long_name": "zeros( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1520, + "end_line": 1523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ones", + "long_name": "ones( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1525, + "end_line": 1528, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "count", + "long_name": "count( a , axis = None )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a", + "axis" + ], + "start_line": 1531, + "end_line": 1534, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "power", + "long_name": "power( a , b , third = None )", + "filename": "ma.py", + "nloc": 18, + "complexity": 4, + "token_count": 152, + "parameters": [ + "a", + "b", + "third" + ], + "start_line": 1536, + "end_line": 1553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "masked_array", + "long_name": "masked_array( a , mask = nomask , fill_value = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "mask", + "fill_value" + ], + "start_line": 1555, + "end_line": 1559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "average", + "long_name": "average( a , axis = 0 , weights = None , returned = 0 )", + "filename": "ma.py", + "nloc": 92, + "complexity": 22, + "token_count": 741, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 1564, + "end_line": 1671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "where", + "long_name": "where( condition , x , y )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 149, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 1673, + "end_line": 1699, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "choose.fmask", + "long_name": "choose.fmask( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 2, + "token_count": 17, + "parameters": [ + "x" + ], + "start_line": 1703, + "end_line": 1705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "choose.nmask", + "long_name": "choose.nmask( x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 3, + "token_count": 27, + "parameters": [ + "x" + ], + "start_line": 1706, + "end_line": 1710, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "choose", + "long_name": "choose( indices , t )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 93, + "parameters": [ + "indices", + "t" + ], + "start_line": 1701, + "end_line": 1717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "masked_where", + "long_name": "masked_where( condition , x , copy = 1 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 47, + "parameters": [ + "condition", + "x", + "copy" + ], + "start_line": 1719, + "end_line": 1725, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "masked_greater", + "long_name": "masked_greater( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1727, + "end_line": 1729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_greater_equal", + "long_name": "masked_greater_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1731, + "end_line": 1733, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less", + "long_name": "masked_less( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1735, + "end_line": 1737, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less_equal", + "long_name": "masked_less_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1739, + "end_line": 1741, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_not_equal", + "long_name": "masked_not_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1743, + "end_line": 1748, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "masked_equal", + "long_name": "masked_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1750, + "end_line": 1757, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "masked_inside", + "long_name": "masked_inside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1759, + "end_line": 1770, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "masked_outside", + "long_name": "masked_outside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1772, + "end_line": 1783, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , * newshape )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 56, + "parameters": [ + "a", + "newshape" + ], + "start_line": 1785, + "end_line": 1792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( a )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "a" + ], + "start_line": 1794, + "end_line": 1801, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "concatenate", + "long_name": "concatenate( arrays , axis = 0 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 5, + "token_count": 97, + "parameters": [ + "arrays", + "axis" + ], + "start_line": 1803, + "end_line": 1817, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 76, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 1819, + "end_line": 1827, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "a", + "axes" + ], + "start_line": 1829, + "end_line": 1837, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , indices , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 70, + "parameters": [ + "a", + "indices", + "values" + ], + "start_line": 1840, + "end_line": 1853, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 61, + "parameters": [ + "a", + "mask", + "values" + ], + "start_line": 1855, + "end_line": 1863, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "innerproduct", + "long_name": "innerproduct( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 3, + "token_count": 72, + "parameters": [ + "a", + "b" + ], + "start_line": 1865, + "end_line": 1875, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "outerproduct", + "long_name": "outerproduct( a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 110, + "parameters": [ + "a", + "b" + ], + "start_line": 1877, + "end_line": 1889, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dot", + "long_name": "dot( a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 36, + "parameters": [ + "a", + "b" + ], + "start_line": 1891, + "end_line": 1896, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , x , dimension = - 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 67, + "parameters": [ + "condition", + "x", + "dimension" + ], + "start_line": 1898, + "end_line": 1907, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1911, + "end_line": 1915, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1917, + "end_line": 1930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1932, + "end_line": 1941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1943, + "end_line": 1954, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1960, + "end_line": 1964, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1966, + "end_line": 1979, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1981, + "end_line": 1990, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1992, + "end_line": 2003, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "sort", + "long_name": "sort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 8, + "complexity": 3, + "token_count": 68, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2007, + "end_line": 2024, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , k = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 73, + "parameters": [ + "a", + "k", + "axis1", + "axis2" + ], + "start_line": 2026, + "end_line": 2033, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2035, + "end_line": 2042, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2044, + "end_line": 2052, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 52, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2054, + "end_line": 2068, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "fromfunction", + "long_name": "fromfunction( f , s )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "f", + "s" + ], + "start_line": 2070, + "end_line": 2072, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( data , dtype = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 46, + "parameters": [ + "data", + "dtype" + ], + "start_line": 2074, + "end_line": 2080, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_m", + "long_name": "_m( f )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "f" + ], + "start_line": 2086, + "end_line": 2087, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "not_implemented", + "long_name": "not_implemented( * args , ** kwds )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "args", + "kwds" + ], + "start_line": 2088, + "end_line": 2089, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_choose", + "long_name": "_choose( self , * args )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 2098, + "end_line": 2099, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_compress", + "long_name": "_compress( self , cond , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "cond", + "axis" + ], + "start_line": 2105, + "end_line": 2106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "__init__", + "long_name": "__init__( self , args = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 24, + "end_line": 26, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 27, + "end_line": 29, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , display )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "display" + ], + "start_line": 34, + "end_line": 37, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "display", + "long_name": "display( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 39, + "end_line": 41, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "set_display", + "long_name": "set_display( self , s )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "s" + ], + "start_line": 43, + "end_line": 45, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enabled", + "long_name": "enabled( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 47, + "end_line": 49, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enable", + "long_name": "enable( self , flag = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "flag" + ], + "start_line": 51, + "end_line": 53, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 55, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "default_fill_value", + "long_name": "default_fill_value( obj )", + "filename": "ma.py", + "nloc": 25, + "complexity": 13, + "token_count": 144, + "parameters": [ + "obj" + ], + "start_line": 70, + "end_line": 94, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "minimum_fill_value", + "long_name": "minimum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 105, + "parameters": [ + "obj" + ], + "start_line": 96, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "maximum_fill_value", + "long_name": "maximum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 103, + "parameters": [ + "obj" + ], + "start_line": 113, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( a , fill_value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 2, + "token_count": 20, + "parameters": [ + "a", + "fill_value" + ], + "start_line": 130, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "getmask", + "long_name": "getmask( a )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "a" + ], + "start_line": 135, + "end_line": 142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "getmaskarray", + "long_name": "getmaskarray( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 144, + "end_line": 153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "is_mask", + "long_name": "is_mask( m )", + "filename": "ma.py", + "nloc": 6, + "complexity": 4, + "token_count": 33, + "parameters": [ + "m" + ], + "start_line": 155, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "make_mask", + "long_name": "make_mask( m , copy = 0 , flag = 0 )", + "filename": "ma.py", + "nloc": 17, + "complexity": 7, + "token_count": 107, + "parameters": [ + "m", + "copy", + "flag" + ], + "start_line": 164, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "make_mask_none", + "long_name": "make_mask_none( s )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 25, + "parameters": [ + "s" + ], + "start_line": 189, + "end_line": 193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "mask_or", + "long_name": "mask_or( m1 , m2 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 5, + "token_count": 52, + "parameters": [ + "m1", + "m2" + ], + "start_line": 195, + "end_line": 202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "filled", + "long_name": "filled( a , value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 5, + "token_count": 70, + "parameters": [ + "a", + "value" + ], + "start_line": 204, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "get_fill_value", + "long_name": "get_fill_value( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 224, + "end_line": 233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "common_fill_value", + "long_name": "common_fill_value( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a", + "b" + ], + "start_line": 235, + "end_line": 240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , y1 , y2 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "y1", + "y2" + ], + "start_line": 245, + "end_line": 248, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 35, + "parameters": [ + "self", + "x" + ], + "start_line": 250, + "end_line": 254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , eps )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "eps" + ], + "start_line": 258, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "x" + ], + "start_line": 262, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 268, + "end_line": 270, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 272, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 278, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 282, + "end_line": 284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , aufunc , fill = 0 , domain = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "aufunc", + "fill", + "domain" + ], + "start_line": 287, + "end_line": 296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 16, + "complexity": 5, + "token_count": 112, + "parameters": [ + "self", + "a", + "args", + "kwargs" + ], + "start_line": 298, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 316, + "end_line": 317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , tolerance = divide_tolerance )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "tolerance" + ], + "start_line": 321, + "end_line": 322, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 323, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , domain , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 53, + "parameters": [ + "self", + "abfunc", + "domain", + "fillx", + "filly" + ], + "start_line": 330, + "end_line": 338, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 147, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 340, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 363, + "end_line": 364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "abfunc", + "fillx", + "filly" + ], + "start_line": 367, + "end_line": 374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 113, + "parameters": [ + "self", + "a", + "b", + "args", + "kwargs" + ], + "start_line": 376, + "end_line": 390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 20, + "complexity": 6, + "token_count": 157, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 392, + "end_line": 412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 414, + "end_line": 425, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "accumulate", + "long_name": "accumulate( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 427, + "end_line": 430, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 431, + "end_line": 432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "rank", + "long_name": "rank( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 494, + "end_line": 495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 497, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( object , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 21, + "parameters": [ + "object", + "axis" + ], + "start_line": 500, + "end_line": 501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , data , dtype = None , copy = True , fortran = False , mask = None , fill_value = None )", + "filename": "ma.py", + "nloc": 56, + "complexity": 18, + "token_count": 379, + "parameters": [ + "self", + "data", + "dtype", + "copy", + "fortran", + "mask", + "fill_value" + ], + "start_line": 532, + "end_line": 594, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "__array__", + "long_name": "__array__( self , t = None )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 67, + "parameters": [ + "self", + "t" + ], + "start_line": 596, + "end_line": 611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__array_wrap__", + "long_name": "__array_wrap__( self , array )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "array" + ], + "start_line": 613, + "end_line": 617, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_shape", + "long_name": "_get_shape( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 619, + "end_line": 621, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_set_shape", + "long_name": "_set_shape( self , newshape )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "newshape" + ], + "start_line": 623, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_get_flat", + "long_name": "_get_flat( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 630, + "end_line": 639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "_set_flat", + "long_name": "_set_flat( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "value" + ], + "start_line": 641, + "end_line": 644, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_real", + "long_name": "_get_real( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 646, + "end_line": 653, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_real", + "long_name": "_set_real( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 655, + "end_line": 658, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_imaginary", + "long_name": "_get_imaginary( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 660, + "end_line": 667, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_imaginary", + "long_name": "_set_imaginary( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 669, + "end_line": 672, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 674, + "end_line": 691, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "ma.py", + "nloc": 42, + "complexity": 5, + "token_count": 207, + "parameters": [ + "self" + ], + "start_line": 693, + "end_line": 738, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 1 + }, + { + "name": "__float__", + "long_name": "__float__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 740, + "end_line": 745, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__int__", + "long_name": "__int__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 747, + "end_line": 752, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , i )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 70, + "parameters": [ + "self", + "i" + ], + "start_line": 754, + "end_line": 768, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 770, + "end_line": 778, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__setitem__", + "long_name": "__setitem__( self , index , value )", + "filename": "ma.py", + "nloc": 27, + "complexity": 7, + "token_count": 157, + "parameters": [ + "self", + "index", + "value" + ], + "start_line": 785, + "end_line": 811, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "__setslice__", + "long_name": "__setslice__( self , i , j , value )", + "filename": "ma.py", + "nloc": 23, + "complexity": 7, + "token_count": 155, + "parameters": [ + "self", + "i", + "j", + "value" + ], + "start_line": 813, + "end_line": 835, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "__nonzero__", + "long_name": "__nonzero__( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 837, + "end_line": 847, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 849, + "end_line": 852, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__and__", + "long_name": "__and__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 854, + "end_line": 856, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__or__", + "long_name": "__or__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 858, + "end_line": 860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__xor__", + "long_name": "__xor__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 862, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__abs__", + "long_name": "__abs__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 870, + "end_line": 872, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__neg__", + "long_name": "__neg__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 874, + "end_line": 876, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pos__", + "long_name": "__pos__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 878, + "end_line": 880, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__add__", + "long_name": "__add__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 882, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mod__", + "long_name": "__mod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 888, + "end_line": 890, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rmod__", + "long_name": "__rmod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 892, + "end_line": 894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__lshift__", + "long_name": "__lshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 896, + "end_line": 897, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__rshift__", + "long_name": "__rshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 899, + "end_line": 900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__sub__", + "long_name": "__sub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 902, + "end_line": 904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rsub__", + "long_name": "__rsub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 906, + "end_line": 908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mul__", + "long_name": "__mul__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 910, + "end_line": 912, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__div__", + "long_name": "__div__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 916, + "end_line": 918, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rdiv__", + "long_name": "__rdiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 920, + "end_line": 922, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__truediv__", + "long_name": "__truediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 924, + "end_line": 926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rtruediv__", + "long_name": "__rtruediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 928, + "end_line": 930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__floordiv__", + "long_name": "__floordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 932, + "end_line": 934, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rfloordiv__", + "long_name": "__rfloordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 936, + "end_line": 938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pow__", + "long_name": "__pow__( self , other , third = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "other", + "third" + ], + "start_line": 940, + "end_line": 942, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__sqrt__", + "long_name": "__sqrt__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 944, + "end_line": 946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__iadd__", + "long_name": "__iadd__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 948, + "end_line": 989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__imul__", + "long_name": "__imul__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 251, + "parameters": [ + "self", + "other" + ], + "start_line": 991, + "end_line": 1032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__isub__", + "long_name": "__isub__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 1034, + "end_line": 1075, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__idiv__", + "long_name": "__idiv__( self , other )", + "filename": "ma.py", + "nloc": 38, + "complexity": 12, + "token_count": 233, + "parameters": [ + "self", + "other" + ], + "start_line": 1079, + "end_line": 1116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 1 + }, + { + "name": "__eq__", + "long_name": "__eq__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1118, + "end_line": 1119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ne__", + "long_name": "__ne__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1121, + "end_line": 1122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__lt__", + "long_name": "__lt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1124, + "end_line": 1125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__le__", + "long_name": "__le__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1127, + "end_line": 1128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__gt__", + "long_name": "__gt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1130, + "end_line": 1131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ge__", + "long_name": "__ge__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1133, + "end_line": 1134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "astype", + "long_name": "astype( self , tc )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "tc" + ], + "start_line": 1136, + "end_line": 1139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "byte_swapped", + "long_name": "byte_swapped( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 1141, + "end_line": 1145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "compressed", + "long_name": "compressed( self )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 1147, + "end_line": 1155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "count", + "long_name": "count( self , axis = None )", + "filename": "ma.py", + "nloc": 29, + "complexity": 7, + "token_count": 173, + "parameters": [ + "self", + "axis" + ], + "start_line": 1157, + "end_line": 1185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "dot", + "long_name": "dot( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1187, + "end_line": 1189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "fill_value", + "long_name": "fill_value( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1191, + "end_line": 1193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "filled", + "long_name": "filled( self , fill_value = None )", + "filename": "ma.py", + "nloc": 31, + "complexity": 9, + "token_count": 183, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1195, + "end_line": 1235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + }, + { + "name": "ids", + "long_name": "ids( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 1237, + "end_line": 1239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "iscontiguous", + "long_name": "iscontiguous( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 1241, + "end_line": 1243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "itemsize", + "long_name": "itemsize( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 1245, + "end_line": 1247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1250, + "end_line": 1252, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "put", + "long_name": "put( self , values )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "values" + ], + "start_line": 1254, + "end_line": 1264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "putmask", + "long_name": "putmask( self , values )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "values" + ], + "start_line": 1266, + "end_line": 1274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "ravel", + "long_name": "ravel( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 1276, + "end_line": 1281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "raw_data", + "long_name": "raw_data( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1283, + "end_line": 1287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "raw_mask", + "long_name": "raw_mask( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1291, + "end_line": 1295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "reshape", + "long_name": "reshape( self , * s )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self", + "s" + ], + "start_line": 1299, + "end_line": 1306, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( self , v = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self", + "v" + ], + "start_line": 1308, + "end_line": 1312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_size", + "long_name": "_get_size( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1314, + "end_line": 1315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtypechar", + "long_name": "_get_dtypechar( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1319, + "end_line": 1320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtype", + "long_name": "_get_dtype( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1323, + "end_line": 1324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "item", + "long_name": "item( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 4, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 1327, + "end_line": 1336, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "tolist", + "long_name": "tolist( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1338, + "end_line": 1340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "tostring", + "long_name": "tostring( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1342, + "end_line": 1344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "unmask", + "long_name": "unmask( self )", + "filename": "ma.py", + "nloc": 7, + "complexity": 3, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 1346, + "end_line": 1352, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "unshare_mask", + "long_name": "unshare_mask( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 1354, + "end_line": 1358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "isMaskedArray", + "long_name": "isMaskedArray( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "x" + ], + "start_line": 1378, + "end_line": 1380, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "allclose", + "long_name": "allclose( a , b , fill_value = 1 , rtol = 1 . e - 5 , atol = 1 . e - 8 )", + "filename": "ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 140, + "parameters": [ + "a", + "b", + "fill_value", + "rtol", + "atol" + ], + "start_line": 1385, + "end_line": 1400, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "allequal", + "long_name": "allequal( a , b , fill_value = 1 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 3, + "token_count": 125, + "parameters": [ + "a", + "b", + "fill_value" + ], + "start_line": 1402, + "end_line": 1420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "masked_values", + "long_name": "masked_values( data , value , rtol = 1 . e - 5 , atol = 1 . e - 8 , copy = 1 )", + "filename": "ma.py", + "nloc": 10, + "complexity": 2, + "token_count": 115, + "parameters": [ + "data", + "value", + "rtol", + "atol", + "copy" + ], + "start_line": 1422, + "end_line": 1441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "masked_object", + "long_name": "masked_object( data , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "data", + "value", + "copy" + ], + "start_line": 1443, + "end_line": 1447, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayrange", + "long_name": "arrayrange( start , stop = None , step = 1 , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 34, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 1449, + "end_line": 1453, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "fromstring", + "long_name": "fromstring( s , t )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "s", + "t" + ], + "start_line": 1457, + "end_line": 1459, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "left_shift", + "long_name": "left_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1461, + "end_line": 1469, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "right_shift", + "long_name": "right_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1471, + "end_line": 1479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 1481, + "end_line": 1489, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 101, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 1491, + "end_line": 1506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "identity", + "long_name": "identity( n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "n" + ], + "start_line": 1508, + "end_line": 1511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "indices", + "long_name": "indices( dimensions , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "dimensions", + "dtype" + ], + "start_line": 1513, + "end_line": 1517, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "zeros", + "long_name": "zeros( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1519, + "end_line": 1522, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ones", + "long_name": "ones( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1524, + "end_line": 1527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "count", + "long_name": "count( a , axis = None )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a", + "axis" + ], + "start_line": 1530, + "end_line": 1533, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "power", + "long_name": "power( a , b , third = None )", + "filename": "ma.py", + "nloc": 18, + "complexity": 4, + "token_count": 152, + "parameters": [ + "a", + "b", + "third" + ], + "start_line": 1535, + "end_line": 1552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "masked_array", + "long_name": "masked_array( a , mask = None , fill_value = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "mask", + "fill_value" + ], + "start_line": 1554, + "end_line": 1558, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "average", + "long_name": "average( a , axis = 0 , weights = None , returned = 0 )", + "filename": "ma.py", + "nloc": 92, + "complexity": 22, + "token_count": 741, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 1563, + "end_line": 1670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "where", + "long_name": "where( condition , x , y )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 149, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 1672, + "end_line": 1698, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "choose.fmask", + "long_name": "choose.fmask( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 2, + "token_count": 17, + "parameters": [ + "x" + ], + "start_line": 1702, + "end_line": 1704, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "choose.nmask", + "long_name": "choose.nmask( x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 3, + "token_count": 27, + "parameters": [ + "x" + ], + "start_line": 1705, + "end_line": 1709, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "choose", + "long_name": "choose( indices , t )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 93, + "parameters": [ + "indices", + "t" + ], + "start_line": 1700, + "end_line": 1716, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "masked_where", + "long_name": "masked_where( condition , x , copy = 1 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 47, + "parameters": [ + "condition", + "x", + "copy" + ], + "start_line": 1718, + "end_line": 1724, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "masked_greater", + "long_name": "masked_greater( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1726, + "end_line": 1728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_greater_equal", + "long_name": "masked_greater_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1730, + "end_line": 1732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less", + "long_name": "masked_less( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1734, + "end_line": 1736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less_equal", + "long_name": "masked_less_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1738, + "end_line": 1740, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_not_equal", + "long_name": "masked_not_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1742, + "end_line": 1747, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "masked_equal", + "long_name": "masked_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1749, + "end_line": 1756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "masked_inside", + "long_name": "masked_inside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1758, + "end_line": 1769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "masked_outside", + "long_name": "masked_outside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1771, + "end_line": 1782, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , * newshape )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 56, + "parameters": [ + "a", + "newshape" + ], + "start_line": 1784, + "end_line": 1791, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( a )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "a" + ], + "start_line": 1793, + "end_line": 1800, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "concatenate", + "long_name": "concatenate( arrays , axis = 0 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 5, + "token_count": 97, + "parameters": [ + "arrays", + "axis" + ], + "start_line": 1802, + "end_line": 1816, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 76, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 1818, + "end_line": 1826, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "a", + "axes" + ], + "start_line": 1828, + "end_line": 1836, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , indices , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 70, + "parameters": [ + "a", + "indices", + "values" + ], + "start_line": 1839, + "end_line": 1852, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 61, + "parameters": [ + "a", + "mask", + "values" + ], + "start_line": 1854, + "end_line": 1862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "innerproduct", + "long_name": "innerproduct( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 3, + "token_count": 72, + "parameters": [ + "a", + "b" + ], + "start_line": 1864, + "end_line": 1874, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "outerproduct", + "long_name": "outerproduct( a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 110, + "parameters": [ + "a", + "b" + ], + "start_line": 1876, + "end_line": 1888, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dot", + "long_name": "dot( a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 36, + "parameters": [ + "a", + "b" + ], + "start_line": 1890, + "end_line": 1895, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , x , dimension = - 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 67, + "parameters": [ + "condition", + "x", + "dimension" + ], + "start_line": 1897, + "end_line": 1906, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1910, + "end_line": 1914, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1916, + "end_line": 1929, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1931, + "end_line": 1940, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1942, + "end_line": 1953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1959, + "end_line": 1963, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1965, + "end_line": 1978, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1980, + "end_line": 1989, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1991, + "end_line": 2002, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "sort", + "long_name": "sort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 8, + "complexity": 3, + "token_count": 68, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2006, + "end_line": 2023, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , k = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 73, + "parameters": [ + "a", + "k", + "axis1", + "axis2" + ], + "start_line": 2025, + "end_line": 2032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2034, + "end_line": 2041, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2043, + "end_line": 2051, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 52, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2053, + "end_line": 2067, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "fromfunction", + "long_name": "fromfunction( f , s )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "f", + "s" + ], + "start_line": 2069, + "end_line": 2071, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( data , dtype = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 46, + "parameters": [ + "data", + "dtype" + ], + "start_line": 2073, + "end_line": 2079, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_m", + "long_name": "_m( f )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "f" + ], + "start_line": 2085, + "end_line": 2086, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "not_implemented", + "long_name": "not_implemented( * args , ** kwds )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "args", + "kwds" + ], + "start_line": 2087, + "end_line": 2088, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_choose", + "long_name": "_choose( self , * args )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 2097, + "end_line": 2098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_compress", + "long_name": "_compress( self , cond , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "cond", + "axis" + ], + "start_line": 2104, + "end_line": 2105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 771, + "end_line": 779, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 61, + "parameters": [ + "a", + "mask", + "values" + ], + "start_line": 1855, + "end_line": 1863, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , indices , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 70, + "parameters": [ + "a", + "indices", + "values" + ], + "start_line": 1840, + "end_line": 1853, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( a )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "a" + ], + "start_line": 1794, + "end_line": 1801, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "ma.py", + "nloc": 42, + "complexity": 5, + "token_count": 207, + "parameters": [ + "self" + ], + "start_line": 694, + "end_line": 739, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , data , dtype = None , copy = True , fortran = False , mask = None , fill_value = None )", + "filename": "ma.py", + "nloc": 56, + "complexity": 18, + "token_count": 379, + "parameters": [ + "self", + "data", + "dtype", + "copy", + "fortran", + "mask", + "fill_value" + ], + "start_line": 532, + "end_line": 594, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 415, + "end_line": 426, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__setslice__", + "long_name": "__setslice__( self , i , j , value )", + "filename": "ma.py", + "nloc": 23, + "complexity": 7, + "token_count": 155, + "parameters": [ + "self", + "i", + "j", + "value" + ], + "start_line": 814, + "end_line": 836, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "filled", + "long_name": "filled( self , fill_value = None )", + "filename": "ma.py", + "nloc": 31, + "complexity": 9, + "token_count": 183, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1196, + "end_line": 1236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 101, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 1492, + "end_line": 1507, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "__float__", + "long_name": "__float__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 741, + "end_line": 746, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "right_shift", + "long_name": "right_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1472, + "end_line": 1480, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "masked_values", + "long_name": "masked_values( data , value , rtol = 1 . e - 5 , atol = 1 . e - 8 , copy = 1 )", + "filename": "ma.py", + "nloc": 10, + "complexity": 2, + "token_count": 115, + "parameters": [ + "data", + "value", + "rtol", + "atol", + "copy" + ], + "start_line": 1423, + "end_line": 1442, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "_get_real", + "long_name": "_get_real( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 647, + "end_line": 654, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "item", + "long_name": "item( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 4, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 1328, + "end_line": 1337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "where", + "long_name": "where( condition , x , y )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 149, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 1673, + "end_line": 1699, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "choose.nmask", + "long_name": "choose.nmask( x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 3, + "token_count": 27, + "parameters": [ + "x" + ], + "start_line": 1706, + "end_line": 1710, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "a", + "axes" + ], + "start_line": 1829, + "end_line": 1837, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "masked_array", + "long_name": "masked_array( a , mask = None , fill_value = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "mask", + "fill_value" + ], + "start_line": 1554, + "end_line": 1558, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "_get_imaginary", + "long_name": "_get_imaginary( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 661, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "is_mask", + "long_name": "is_mask( m )", + "filename": "ma.py", + "nloc": 6, + "complexity": 4, + "token_count": 33, + "parameters": [ + "m" + ], + "start_line": 156, + "end_line": 163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "getmask", + "long_name": "getmask( a )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "a" + ], + "start_line": 136, + "end_line": 143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "unmask", + "long_name": "unmask( self )", + "filename": "ma.py", + "nloc": 7, + "complexity": 3, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 1347, + "end_line": 1353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "compressed", + "long_name": "compressed( self )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 1148, + "end_line": 1156, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "left_shift", + "long_name": "left_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1462, + "end_line": 1470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 147, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 341, + "end_line": 362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "put", + "long_name": "put( self , values )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "values" + ], + "start_line": 1255, + "end_line": 1265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "concatenate", + "long_name": "concatenate( arrays , axis = 0 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 5, + "token_count": 97, + "parameters": [ + "arrays", + "axis" + ], + "start_line": 1803, + "end_line": 1817, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 113, + "parameters": [ + "self", + "a", + "b", + "args", + "kwargs" + ], + "start_line": 377, + "end_line": 391, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "putmask", + "long_name": "putmask( self , values )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "values" + ], + "start_line": 1267, + "end_line": 1275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__setitem__", + "long_name": "__setitem__( self , index , value )", + "filename": "ma.py", + "nloc": 27, + "complexity": 7, + "token_count": 157, + "parameters": [ + "self", + "index", + "value" + ], + "start_line": 786, + "end_line": 812, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 1482, + "end_line": 1490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "__iadd__", + "long_name": "__iadd__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 949, + "end_line": 990, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , i )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 70, + "parameters": [ + "self", + "i" + ], + "start_line": 755, + "end_line": 769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "allequal", + "long_name": "allequal( a , b , fill_value = 1 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 3, + "token_count": 125, + "parameters": [ + "a", + "b", + "fill_value" + ], + "start_line": 1403, + "end_line": 1421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 1277, + "end_line": 1282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 20, + "complexity": 6, + "token_count": 157, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 393, + "end_line": 413, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1917, + "end_line": 1930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reshape", + "long_name": "reshape( a , * newshape )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 56, + "parameters": [ + "a", + "newshape" + ], + "start_line": 1785, + "end_line": 1792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__nonzero__", + "long_name": "__nonzero__( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 838, + "end_line": 848, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "getmaskarray", + "long_name": "getmaskarray( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 145, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 76, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 1819, + "end_line": 1827, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "outerproduct", + "long_name": "outerproduct( a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 110, + "parameters": [ + "a", + "b" + ], + "start_line": 1877, + "end_line": 1889, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "_set_shape", + "long_name": "_set_shape( self , newshape )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "newshape" + ], + "start_line": 624, + "end_line": 629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "choose", + "long_name": "choose( indices , t )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 93, + "parameters": [ + "indices", + "t" + ], + "start_line": 1701, + "end_line": 1717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "__isub__", + "long_name": "__isub__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 1035, + "end_line": 1076, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "masked_array", + "long_name": "masked_array( a , mask = nomask , fill_value = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "mask", + "fill_value" + ], + "start_line": 1555, + "end_line": 1559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( self , * s )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self", + "s" + ], + "start_line": 1300, + "end_line": 1307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , data , dtype = None , copy = True , fortran = False , mask = nomask , fill_value = None )", + "filename": "ma.py", + "nloc": 56, + "complexity": 18, + "token_count": 379, + "parameters": [ + "self", + "data", + "dtype", + "copy", + "fortran", + "mask", + "fill_value" + ], + "start_line": 533, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "count", + "long_name": "count( self , axis = None )", + "filename": "ma.py", + "nloc": 29, + "complexity": 7, + "token_count": 173, + "parameters": [ + "self", + "axis" + ], + "start_line": 1158, + "end_line": 1186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "sort", + "long_name": "sort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 8, + "complexity": 3, + "token_count": 68, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2007, + "end_line": 2024, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "average", + "long_name": "average( a , axis = 0 , weights = None , returned = 0 )", + "filename": "ma.py", + "nloc": 92, + "complexity": 22, + "token_count": 741, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 1564, + "end_line": 1671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "__int__", + "long_name": "__int__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 748, + "end_line": 753, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "compress", + "long_name": "compress( condition , x , dimension = - 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 67, + "parameters": [ + "condition", + "x", + "dimension" + ], + "start_line": 1898, + "end_line": 1907, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "make_mask", + "long_name": "make_mask( m , copy = 0 , flag = 0 )", + "filename": "ma.py", + "nloc": 17, + "complexity": 7, + "token_count": 107, + "parameters": [ + "m", + "copy", + "flag" + ], + "start_line": 165, + "end_line": 188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "__imul__", + "long_name": "__imul__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 251, + "parameters": [ + "self", + "other" + ], + "start_line": 992, + "end_line": 1033, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "_get_flat", + "long_name": "_get_flat( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 631, + "end_line": 640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__array__", + "long_name": "__array__( self , t = None )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 67, + "parameters": [ + "self", + "t" + ], + "start_line": 597, + "end_line": 612, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , k = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 73, + "parameters": [ + "a", + "k", + "axis1", + "axis2" + ], + "start_line": 2026, + "end_line": 2033, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 16, + "complexity": 5, + "token_count": 112, + "parameters": [ + "self", + "a", + "args", + "kwargs" + ], + "start_line": 299, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "mask_or", + "long_name": "mask_or( m1 , m2 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 5, + "token_count": 52, + "parameters": [ + "m1", + "m2" + ], + "start_line": 196, + "end_line": 203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "power", + "long_name": "power( a , b , third = None )", + "filename": "ma.py", + "nloc": 18, + "complexity": 4, + "token_count": 152, + "parameters": [ + "a", + "b", + "third" + ], + "start_line": 1536, + "end_line": 1553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + } + ], + "nloc": 1678, + "complexity": 455, + "token_count": 11672, + "diff_parsed": { + "added": [ + "nomask = None # To be changed to MaskType(0)", + " \"\"\"Mask of values in a; could be nomask.", + " Returns nomask if a is not a masked array.", + " return nomask", + " \"\"\"Mask of values in a; an array of zeros if mask is nomask", + " if m is nomask:", + " if m is nomask or (isinstance(m, ndarray) and \\", + " Can accept any sequence of integers or nomask. Does not check", + " if flag, return nomask if m contains no true elements.", + " if m is nomask:", + " return nomask", + " return nomask", + " \"\"\"Logical or of the mask candidates m1 and m2, treating nomask as false.", + " Result may equal m1 or m2 if the other is nomask.", + " if m1 is nomask: return make_mask(m2)", + " if m2 is nomask: return make_mask(m1)", + " if m is not nomask:", + " if m is not nomask:", + " if m is not nomask:", + " if m is not nomask:", + " if m is nomask:", + " if ma is nomask and mb is nomask:", + " m = nomask", + " mask = nomask, fill_value=None)", + " If data is a MaskedArray, and argument mask=nomask,", + " If mask is nomask there are no masked values. Otherwise mask must", + " mask=nomask, fill_value=None):", + " \"\"\"array(data, dtype=None, copy=True, fortran=False, mask=nomask, fill_value=None)", + " if mask is nomask:", + " elif mask is not nomask: #attempting to change the mask", + " if mask is nomask:", + " self._mask = nomask", + " if self._mask is nomask:", + " if self._mask is not nomask:", + " self._mask = nomask", + " if self._mask is not nomask:", + " if self._mask is nomask:", + " return masked_array(self._data.ravel(), mask=nomask,", + " if self._mask is nomask:", + " return masked_array(self._data.real, mask=nomask,", + " if self._mask is nomask:", + " return masked_array(self._data.imag, mask=nomask,", + " if self._mask is nomask:", + " if self._mask is nomask:", + " if self._mask is not nomask:", + " if self._mask is not nomask:", + " if m is nomask:", + " if m is nomask:", + " if self._mask is nomask:", + " if m is nomask:", + " if self._mask is not nomask:", + " if self._mask is nomask:", + " if self._mask is nomask:", + " if m is nomask:", + " if self._mask is not nomask:", + " if self._mask is nomask:", + " return bool(m is not nomask and m.any()", + " or d is not nomask and d.any())", + " if self._mask is nomask:", + " self._shared_mask = m is not nomask", + " if self._mask is nomask:", + " self._shared_mask = m is not nomask", + " if self._mask is nomask:", + " self._shared_mask = m is not nomask", + " if self._mask is nomask:", + " if m is nomask:", + " If mask is nomask, copy data only if not contiguous.", + " if m is nomask:", + " if self._mask is nomask:", + " Mask changed to nomask.", + " if self._mask is not nomask:", + " self._mask = nomask", + " if self._mask is nomask:", + " doc=\"The mask, may be nomask. Values where mask true are meaningless.\")", + " if self._mask is nomask:", + " if self._mask is not nomask:", + " \"Replace the mask by nomask if possible.\"", + " if self._mask is nomask: return", + " if m is nomask:", + " self._mask = nomask", + " if m is nomask:", + " Create a masked array; mask is nomask if possible.", + " if m is nomask:", + " if m is nomask:", + " if m is not nomask:", + " if m is not nomask:", + " if m is nomask:", + "def masked_array (a, mask=nomask, fill_value=None):", + " \"\"\"masked_array(a, mask=nomask) =", + " if mask is nomask:", + " if mask is nomask:", + " if xm is nomask: xm = 0", + " if ym is nomask: ym = 0", + " if m is nomask: return 0", + " if m is nomask:", + " if m is nomask:", + " if getmask(x) is not nomask: break", + " if m is nomask:", + " if m is nomask:", + " if m is not nomask:", + " if mask is nomask:", + " if m is nomask: return", + " if ma is nomask and mb is nomask:", + " if m is not nomask:", + " if m is nomask:", + " if m is nomask:", + " if ma is nomask and mb is nomask:", + " m = nomask", + " if m is nomask:", + " if m is nomask:", + " if ma is nomask and mb is nomask:", + " m = nomask", + " if getmask(x) is nomask:", + " if m is nomask:" + ], + "deleted": [ + " \"\"\"Mask of values in a; could be None.", + " Returns None if a is not a masked array.", + " return None", + " \"\"\"Mask of values in a; an array of zeros if mask is None", + " if m is None:", + " if m is None or (isinstance(m, ndarray) and \\", + " Can accept any sequence of integers or None. Does not check", + " if flag, return None if m contains no true elements.", + " if m is None:", + " return None", + " return None", + " \"\"\"Logical or of the mask candidates m1 and m2, treating None as false.", + " Result may equal m1 or m2 if the other is None.", + " if m1 is None: return make_mask(m2)", + " if m2 is None: return make_mask(m1)", + " if m is not None:", + " if m is not None:", + " if m is not None:", + " if m is not None:", + " if m is None:", + " if ma is None and mb is None:", + " m = None", + " mask = None, fill_value=None)", + " If data is a MaskedArray, and argument mask=None,", + " If mask is None there are no masked values. Otherwise mask must", + " mask=None, fill_value=None):", + " \"\"\"array(data, dtype=None, copy=True, fortran=False, mask=None, fill_value=None)", + " if mask is None:", + " elif mask is not None: #attempting to change the mask", + " if mask is None:", + " self._mask = None", + " if self._mask is None:", + " if self._mask is not None:", + " self._mask = None", + " if self._mask is not None:", + " if self._mask is None:", + " return masked_array(self._data.ravel(), mask=None,", + " if self._mask is None:", + " return masked_array(self._data.real, mask=None,", + " if self._mask is None:", + " return masked_array(self._data.imag, mask=None,", + " if self._mask is None:", + " if self._mask is None:", + " if self._mask is not None:", + " if self._mask is not None:", + " if m is None:", + " if m is None:", + " if self._mask is None:", + " if m is None:", + " if self._mask is not None:", + " if self._mask is None:", + " if self._mask is None:", + " if m is None:", + " if self._mask is not None:", + " if self._mask is None:", + " return bool(m is not None and m.any()", + " or d is not None and d.any())", + " if self._mask is None:", + " self._shared_mask = m is not None", + " if self._mask is None:", + " self._shared_mask = m is not None", + " if self._mask is None:", + " self._shared_mask = m is not None", + " if self._mask is None:", + " if m is None:", + " If mask is None, copy data only if not contiguous.", + " if m is None:", + " if self._mask is None:", + " Mask changed to None.", + " if self._mask is not None:", + " self._mask = None", + " if self._mask is None:", + " doc=\"The mask, may be None. Values where mask true are meaningless.\")", + " if self._mask is None:", + " if self._mask is not None:", + " \"Replace the mask by None if possible.\"", + " if self._mask is None: return", + " if m is None:", + " self._mask = None", + " if m is None:", + " Create a masked array; mask is None if possible.", + " if m is None:", + " if m is None:", + " if m is not None:", + " if m is not None:", + " if m is None:", + "def masked_array (a, mask=None, fill_value=None):", + " \"\"\"masked_array(a, mask=None) =", + " if mask is None:", + " if mask is None:", + " if xm is None: xm = 0", + " if ym is None: ym = 0", + " if m is None: return 0", + " if m is None:", + " if m is None:", + " if getmask(x) is not None: break", + " if m is None:", + " if m is None:", + " if m is not None:", + " if mask is None:", + " if m is None: return", + " if ma is None and mb is None:", + " if m is not None:", + " if m is None:", + " if m is None:", + " if ma is None and mb is None:", + " m = None", + " if m is None:", + " if m is None:", + " if ma is None and mb is None:", + " m = None", + " if getmask(x) is None:", + " if m is None:" + ] + } + } + ] + }, + { + "hash": "8aee1fe94c2d0c0d83d28f7cac7db4832e0e7026", + "msg": "Fix AIX portion of code", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-12T22:46:53+00:00", + "author_timezone": 0, + "committer_date": "2006-01-12T22:46:53+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "42779fea3ed52eac633f4d12ca4f9d355ffb5535" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/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/include/numpy/ufuncobject.h", + "new_path": "numpy/core/include/numpy/ufuncobject.h", + "filename": "ufuncobject.h", + "extension": "h", + "change_type": "MODIFY", + "diff": "@@ -280,7 +280,7 @@ typedef struct {\n #define generate_divbyzero_error() feraiseexcept(FE_DIVBYZERO)\n #define generate_overflow_error() feraiseexcept(FE_OVERFLOW)\n \t\n-#elif defined(AIX)\n+#elif defined(_AIX)\n \n #include \n #include \n@@ -288,11 +288,11 @@ typedef struct {\n #define UFUNC_CHECK_STATUS(ret) { \\\n \tfpflag_t fpstatus; \\\n \\\n-\tfpstatus = fp_read_flag();\n+\tfpstatus = fp_read_flag(); \\\n \tret = ((FP_DIV_BY_ZERO & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \\\n \t\t| ((FP_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n \t\t| ((FP_UNDERFLOW & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \\\n-\t\t| ((FP_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0);\n+\t\t| ((FP_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0); \\\n \tfp_clr_flag( FP_DIV_BY_ZERO | FP_OVERFLOW | FP_UNDERFLOW | FP_INVALID); \\\n }\n \n", + "added_lines": 3, + "deleted_lines": 3, + "source_code": "#ifndef Py_UFUNCOBJECT_H\n#define Py_UFUNCOBJECT_H\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#define MAX_ARGS 40\n\ntypedef void (*PyUFuncGenericFunction) (char **, intp *, intp *, void *);\n\ntypedef struct {\n\tPyObject_HEAD\n\tint nin, nout, nargs;\n\tint identity;\n\tPyUFuncGenericFunction *functions;\n\tvoid **data;\n\tint ntypes;\n\tint check_return;\n\tchar *name, *types;\n\tchar *doc;\n void *ptr;\n PyObject *obj;\n\tPyObject *userloops;\n} PyUFuncObject;\n\n#include \"arrayobject.h\"\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# define CAT2(x,y) x ## y\n# define CAT(x,y) CAT2(x,y)\n# define NS(name) CAT(PY_ARRAY_TYPES_PREFIX, name)\n# define intp NS(intp)\n#endif\n\n#define UFUNC_ERR_IGNORE 0\n#define UFUNC_ERR_WARN 1\n#define UFUNC_ERR_RAISE 2\n#define UFUNC_ERR_CALL 3\n\n\t/* Python side integer mask */\n\n#define UFUNC_MASK_DIVIDEBYZERO 0x03\n#define UFUNC_MASK_OVERFLOW 0x0c\n#define UFUNC_MASK_UNDERFLOW 0x30\n#define UFUNC_MASK_INVALID 0xc0\n\n#define UFUNC_SHIFT_DIVIDEBYZERO 0\n#define UFUNC_SHIFT_OVERFLOW 2\n#define UFUNC_SHIFT_UNDERFLOW 4\n#define UFUNC_SHIFT_INVALID 6 \n\n\n/* platform-dependent code translates floating point\n status to an integer sum of these values\n*/\n#define UFUNC_FPE_DIVIDEBYZERO 1\n#define UFUNC_FPE_OVERFLOW 2\n#define UFUNC_FPE_UNDERFLOW 4\n#define UFUNC_FPE_INVALID 8\n\t\n#define UFUNC_ERR_DEFAULT 0 /* Default error mode */\n\n\t/* Only internal -- not exported, yet*/\ntypedef struct {\n\t/* Multi-iterator portion --- needs to be present in this order \n\t to work with PyArray_Broadcast */\n\tPyObject_HEAD\n\tint numiter;\n\tintp size;\n\tintp index;\n\tint nd;\n\tintp dimensions[MAX_DIMS];\t\n\tPyArrayIterObject *iters[MAX_ARGS];\n /* End of Multi-iterator portion */\n\n\t/* The ufunc */\n\tPyUFuncObject *ufunc;\n\t\n\t/* The error handling */\n\tint errormask; /* Integer showing desired error handling */\n\tPyObject *errobj; /* currently a tuple with \n\t\t\t\t (string, func or None)\n\t\t\t */\n\n\t/* Specific function and data to use */\n\tPyUFuncGenericFunction function;\n\tvoid *funcdata;\n\n\t/* Loop method */\n\tint meth;\n\n\t/* Whether we need to copy to a buffer or not.*/\n\tint needbuffer[MAX_ARGS];\n\tint leftover;\n\tint ninnerloops;\n\tint lastdim;\n\t\n\t/* Whether or not to swap */\n\tint swap[MAX_ARGS];\n\n\t/* Buffers for the loop */\n\tvoid *buffer[MAX_ARGS];\n\tint bufsize;\n\tintp bufcnt;\n\tvoid *dptr[MAX_ARGS];\n\n\t/* For casting */\n\tvoid *castbuf[MAX_ARGS];\n\tPyArray_VectorUnaryFunc *cast[MAX_ARGS];\n\n\t/* usually points to buffer but when a cast is to be\n\t done it switches for that argument to castbuf.\n\t*/\n\tvoid *bufptr[MAX_ARGS]; \n\n\t/* Steps filled in from iters or sizeof(item)\n\t depending on loop method. \n\t*/\n\tintp steps[MAX_ARGS];\n\n int obj; /* This loop calls object functions */\n int notimplemented; /* The loop caused notimplemented */\n\t\n} PyUFuncLoopObject;\n\n/* Could make this more clever someday */\n#define UFUNC_MAXIDENTITY 32\n\ntypedef struct {\n PyObject_HEAD\n PyArrayIterObject *it;\n PyArrayObject *ret;\n\tPyArrayIterObject *rit; /* Needed for Accumulate */\n int outsize;\n\tintp index;\n\tintp size;\n char idptr[UFUNC_MAXIDENTITY];\n\n\t/* The ufunc */\n\tPyUFuncObject *ufunc;\n\n\t/* The error handling */\n\tint errormask;\n\tPyObject *errobj;\n\n PyUFuncGenericFunction function;\n void *funcdata;\n int meth;\n int swap;\n\n void *buffer;\n int bufsize;\n\n void *castbuf;\n PyArray_VectorUnaryFunc *cast;\n\n void *bufptr[3];\n intp steps[3];\n\n intp N;\n int instrides;\n int insize;\n char *inptr;\n\n /* For copying small arrays */\n PyObject *decref;\n\n int obj;\n\n} PyUFuncReduceObject;\n\n\n#if defined(ALLOW_THREADS)\n#define LOOP_BEGIN_THREADS if (!(loop->obj)) {_save = PyEval_SaveThread();}\n#define LOOP_END_THREADS if (!(loop->obj)) {PyEval_RestoreThread(_save);}\n#else\n#define LOOP_BEGIN_THREADS\n#define LOOP_END_THREADS\n#endif\n\n#define PyUFunc_One 1\n#define PyUFunc_Zero 0\n#define PyUFunc_None -1\n\n#define UFUNC_REDUCE 0\n#define UFUNC_ACCUMULATE 1\n#define UFUNC_REDUCEAT 2\n#define UFUNC_OUTER 3\n\n\ntypedef struct {\n int nin;\n int nout;\n PyObject *callable;\n} PyUFunc_PyFuncData;\n\n\n#include \"__ufunc_api.h\"\n\n#define UFUNC_PYVALS_NAME \"UFUNC_PYVALS\"\n\n#define UFUNC_CHECK_ERROR(arg) \\\n\tif (((arg)->obj && PyErr_Occurred()) || \\\n ((arg)->errormask && \\\n PyUFunc_checkfperr((arg)->errormask, \\\n (arg)->errobj))) \\\n\t\tgoto fail\n\n/* This code checks the IEEE status flags in a platform-dependent way */\n/* Adapted from Numarray */\n\n/* OSF/Alpha (Tru64) ---------------------------------------------*/\n#if defined(__osf__) && defined(__alpha)\n\n#include \n\n#define UFUNC_CHECK_STATUS(ret) {\t\t\\\n\tunsigned long fpstatus;\t\t \\\n\t\t\t\t\t\t\\\n\tfpstatus = ieee_get_fp_control();\t\t\t\t\\\n\t/* clear status bits as well as disable exception mode if on */ \\\n\tieee_set_fp_control( 0 );\t\t\t\t\t\\\n\tret = ((IEEE_STATUS_DZE & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \\\n\t\t| ((IEEE_STATUS_OVF & fpstatus) ? UFUNC_FPE_OVERFLOW : 0) \\\n\t\t| ((IEEE_STATUS_UNF & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \\\n\t\t| ((IEEE_STATUS_INV & fpstatus) ? UFUNC_FPE_INVALID : 0); \\\n\t}\n\t\n/* MS Windows -----------------------------------------------------*/\n#elif defined(_MSC_VER) \n\n#include \n\n#define UFUNC_CHECK_STATUS(ret) {\t\t \\\n\tint fpstatus = (int) _clear87();\t\t\t\\\n\t\t\t\t\t\t\t\t\t\\\n\tret = ((SW_ZERODIVIDE & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0)\t\\\n\t\t| ((SW_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n\t\t| ((SW_UNDERFLOW & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0)\t\\\n\t\t| ((SW_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0);\t\\\n\t}\n\t\n\n/* Solaris --------------------------------------------------------*/\n/* --------ignoring SunOS ieee_flags approach, someone else can\n** deal with that! */\n#elif defined(sun) || defined(__OpenBSD__) || defined(__FreeBSD__)\n#include \n\n#define UFUNC_CHECK_STATUS(ret) {\t\t\t\t\\\n\tint fpstatus;\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\\\n\tfpstatus = (int) fpgetsticky();\t\t\t\t\t\\\n\tret = ((FP_X_DZ & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0)\t\\\n\t\t| ((FP_X_OFL & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n\t\t| ((FP_X_UFL & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0)\t\\\n\t\t| ((FP_X_INV & fpstatus) ? UFUNC_FPE_INVALID : 0);\t\\\n\t(void) fpsetsticky(0);\t\t\t\t\t\t\\\n\t}\n\t\n#elif defined(linux) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__MINGW32__)\n\n#if defined(__GLIBC__) || defined(__APPLE__) || defined(__MINGW32__)\n#include \n#elif defined(__CYGWIN__)\n#include \n#endif\n\n#define UFUNC_CHECK_STATUS(ret) { \\\n\tint fpstatus = (int) fetestexcept(FE_DIVBYZERO | FE_OVERFLOW |\t\\\n\t\t\t\t\t FE_UNDERFLOW | FE_INVALID);\t\\\n\tret = ((FE_DIVBYZERO & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \\\n\t\t| ((FE_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n\t\t| ((FE_UNDERFLOW & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \\\n\t\t| ((FE_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0);\t\\\n\t(void) feclearexcept(FE_DIVBYZERO | FE_OVERFLOW |\t\t\\\n\t\t\t FE_UNDERFLOW | FE_INVALID);\t\t\\\n}\n\n#define generate_divbyzero_error() feraiseexcept(FE_DIVBYZERO)\n#define generate_overflow_error() feraiseexcept(FE_OVERFLOW)\n\t\n#elif defined(_AIX)\n\n#include \n#include \n\n#define UFUNC_CHECK_STATUS(ret) { \\\n\tfpflag_t fpstatus; \\\n \\\n\tfpstatus = fp_read_flag(); \\\n\tret = ((FP_DIV_BY_ZERO & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \\\n\t\t| ((FP_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n\t\t| ((FP_UNDERFLOW & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \\\n\t\t| ((FP_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0); \\\n\tfp_clr_flag( FP_DIV_BY_ZERO | FP_OVERFLOW | FP_UNDERFLOW | FP_INVALID); \\\n}\n\n#else\n\n#define NO_FLOATING_POINT_SUPPORT \n#define UFUNC_CHECK_STATUS(ret) { \\\n ret = 0;\t\t\t\t\t\t\t \\\n }\n\n#endif\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# undef CAT\n# undef CAT2\n# undef NS\n# undef inpt\n#endif\n\n\n#ifdef __cplusplus\n}\n#endif\n#endif /* !Py_UFUNCOBJECT_H */\n", + "source_code_before": "#ifndef Py_UFUNCOBJECT_H\n#define Py_UFUNCOBJECT_H\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#define MAX_ARGS 40\n\ntypedef void (*PyUFuncGenericFunction) (char **, intp *, intp *, void *);\n\ntypedef struct {\n\tPyObject_HEAD\n\tint nin, nout, nargs;\n\tint identity;\n\tPyUFuncGenericFunction *functions;\n\tvoid **data;\n\tint ntypes;\n\tint check_return;\n\tchar *name, *types;\n\tchar *doc;\n void *ptr;\n PyObject *obj;\n\tPyObject *userloops;\n} PyUFuncObject;\n\n#include \"arrayobject.h\"\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# define CAT2(x,y) x ## y\n# define CAT(x,y) CAT2(x,y)\n# define NS(name) CAT(PY_ARRAY_TYPES_PREFIX, name)\n# define intp NS(intp)\n#endif\n\n#define UFUNC_ERR_IGNORE 0\n#define UFUNC_ERR_WARN 1\n#define UFUNC_ERR_RAISE 2\n#define UFUNC_ERR_CALL 3\n\n\t/* Python side integer mask */\n\n#define UFUNC_MASK_DIVIDEBYZERO 0x03\n#define UFUNC_MASK_OVERFLOW 0x0c\n#define UFUNC_MASK_UNDERFLOW 0x30\n#define UFUNC_MASK_INVALID 0xc0\n\n#define UFUNC_SHIFT_DIVIDEBYZERO 0\n#define UFUNC_SHIFT_OVERFLOW 2\n#define UFUNC_SHIFT_UNDERFLOW 4\n#define UFUNC_SHIFT_INVALID 6 \n\n\n/* platform-dependent code translates floating point\n status to an integer sum of these values\n*/\n#define UFUNC_FPE_DIVIDEBYZERO 1\n#define UFUNC_FPE_OVERFLOW 2\n#define UFUNC_FPE_UNDERFLOW 4\n#define UFUNC_FPE_INVALID 8\n\t\n#define UFUNC_ERR_DEFAULT 0 /* Default error mode */\n\n\t/* Only internal -- not exported, yet*/\ntypedef struct {\n\t/* Multi-iterator portion --- needs to be present in this order \n\t to work with PyArray_Broadcast */\n\tPyObject_HEAD\n\tint numiter;\n\tintp size;\n\tintp index;\n\tint nd;\n\tintp dimensions[MAX_DIMS];\t\n\tPyArrayIterObject *iters[MAX_ARGS];\n /* End of Multi-iterator portion */\n\n\t/* The ufunc */\n\tPyUFuncObject *ufunc;\n\t\n\t/* The error handling */\n\tint errormask; /* Integer showing desired error handling */\n\tPyObject *errobj; /* currently a tuple with \n\t\t\t\t (string, func or None)\n\t\t\t */\n\n\t/* Specific function and data to use */\n\tPyUFuncGenericFunction function;\n\tvoid *funcdata;\n\n\t/* Loop method */\n\tint meth;\n\n\t/* Whether we need to copy to a buffer or not.*/\n\tint needbuffer[MAX_ARGS];\n\tint leftover;\n\tint ninnerloops;\n\tint lastdim;\n\t\n\t/* Whether or not to swap */\n\tint swap[MAX_ARGS];\n\n\t/* Buffers for the loop */\n\tvoid *buffer[MAX_ARGS];\n\tint bufsize;\n\tintp bufcnt;\n\tvoid *dptr[MAX_ARGS];\n\n\t/* For casting */\n\tvoid *castbuf[MAX_ARGS];\n\tPyArray_VectorUnaryFunc *cast[MAX_ARGS];\n\n\t/* usually points to buffer but when a cast is to be\n\t done it switches for that argument to castbuf.\n\t*/\n\tvoid *bufptr[MAX_ARGS]; \n\n\t/* Steps filled in from iters or sizeof(item)\n\t depending on loop method. \n\t*/\n\tintp steps[MAX_ARGS];\n\n int obj; /* This loop calls object functions */\n int notimplemented; /* The loop caused notimplemented */\n\t\n} PyUFuncLoopObject;\n\n/* Could make this more clever someday */\n#define UFUNC_MAXIDENTITY 32\n\ntypedef struct {\n PyObject_HEAD\n PyArrayIterObject *it;\n PyArrayObject *ret;\n\tPyArrayIterObject *rit; /* Needed for Accumulate */\n int outsize;\n\tintp index;\n\tintp size;\n char idptr[UFUNC_MAXIDENTITY];\n\n\t/* The ufunc */\n\tPyUFuncObject *ufunc;\n\n\t/* The error handling */\n\tint errormask;\n\tPyObject *errobj;\n\n PyUFuncGenericFunction function;\n void *funcdata;\n int meth;\n int swap;\n\n void *buffer;\n int bufsize;\n\n void *castbuf;\n PyArray_VectorUnaryFunc *cast;\n\n void *bufptr[3];\n intp steps[3];\n\n intp N;\n int instrides;\n int insize;\n char *inptr;\n\n /* For copying small arrays */\n PyObject *decref;\n\n int obj;\n\n} PyUFuncReduceObject;\n\n\n#if defined(ALLOW_THREADS)\n#define LOOP_BEGIN_THREADS if (!(loop->obj)) {_save = PyEval_SaveThread();}\n#define LOOP_END_THREADS if (!(loop->obj)) {PyEval_RestoreThread(_save);}\n#else\n#define LOOP_BEGIN_THREADS\n#define LOOP_END_THREADS\n#endif\n\n#define PyUFunc_One 1\n#define PyUFunc_Zero 0\n#define PyUFunc_None -1\n\n#define UFUNC_REDUCE 0\n#define UFUNC_ACCUMULATE 1\n#define UFUNC_REDUCEAT 2\n#define UFUNC_OUTER 3\n\n\ntypedef struct {\n int nin;\n int nout;\n PyObject *callable;\n} PyUFunc_PyFuncData;\n\n\n#include \"__ufunc_api.h\"\n\n#define UFUNC_PYVALS_NAME \"UFUNC_PYVALS\"\n\n#define UFUNC_CHECK_ERROR(arg) \\\n\tif (((arg)->obj && PyErr_Occurred()) || \\\n ((arg)->errormask && \\\n PyUFunc_checkfperr((arg)->errormask, \\\n (arg)->errobj))) \\\n\t\tgoto fail\n\n/* This code checks the IEEE status flags in a platform-dependent way */\n/* Adapted from Numarray */\n\n/* OSF/Alpha (Tru64) ---------------------------------------------*/\n#if defined(__osf__) && defined(__alpha)\n\n#include \n\n#define UFUNC_CHECK_STATUS(ret) {\t\t\\\n\tunsigned long fpstatus;\t\t \\\n\t\t\t\t\t\t\\\n\tfpstatus = ieee_get_fp_control();\t\t\t\t\\\n\t/* clear status bits as well as disable exception mode if on */ \\\n\tieee_set_fp_control( 0 );\t\t\t\t\t\\\n\tret = ((IEEE_STATUS_DZE & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \\\n\t\t| ((IEEE_STATUS_OVF & fpstatus) ? UFUNC_FPE_OVERFLOW : 0) \\\n\t\t| ((IEEE_STATUS_UNF & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \\\n\t\t| ((IEEE_STATUS_INV & fpstatus) ? UFUNC_FPE_INVALID : 0); \\\n\t}\n\t\n/* MS Windows -----------------------------------------------------*/\n#elif defined(_MSC_VER) \n\n#include \n\n#define UFUNC_CHECK_STATUS(ret) {\t\t \\\n\tint fpstatus = (int) _clear87();\t\t\t\\\n\t\t\t\t\t\t\t\t\t\\\n\tret = ((SW_ZERODIVIDE & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0)\t\\\n\t\t| ((SW_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n\t\t| ((SW_UNDERFLOW & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0)\t\\\n\t\t| ((SW_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0);\t\\\n\t}\n\t\n\n/* Solaris --------------------------------------------------------*/\n/* --------ignoring SunOS ieee_flags approach, someone else can\n** deal with that! */\n#elif defined(sun) || defined(__OpenBSD__) || defined(__FreeBSD__)\n#include \n\n#define UFUNC_CHECK_STATUS(ret) {\t\t\t\t\\\n\tint fpstatus;\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\\\n\tfpstatus = (int) fpgetsticky();\t\t\t\t\t\\\n\tret = ((FP_X_DZ & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0)\t\\\n\t\t| ((FP_X_OFL & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n\t\t| ((FP_X_UFL & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0)\t\\\n\t\t| ((FP_X_INV & fpstatus) ? UFUNC_FPE_INVALID : 0);\t\\\n\t(void) fpsetsticky(0);\t\t\t\t\t\t\\\n\t}\n\t\n#elif defined(linux) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__MINGW32__)\n\n#if defined(__GLIBC__) || defined(__APPLE__) || defined(__MINGW32__)\n#include \n#elif defined(__CYGWIN__)\n#include \n#endif\n\n#define UFUNC_CHECK_STATUS(ret) { \\\n\tint fpstatus = (int) fetestexcept(FE_DIVBYZERO | FE_OVERFLOW |\t\\\n\t\t\t\t\t FE_UNDERFLOW | FE_INVALID);\t\\\n\tret = ((FE_DIVBYZERO & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \\\n\t\t| ((FE_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n\t\t| ((FE_UNDERFLOW & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \\\n\t\t| ((FE_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0);\t\\\n\t(void) feclearexcept(FE_DIVBYZERO | FE_OVERFLOW |\t\t\\\n\t\t\t FE_UNDERFLOW | FE_INVALID);\t\t\\\n}\n\n#define generate_divbyzero_error() feraiseexcept(FE_DIVBYZERO)\n#define generate_overflow_error() feraiseexcept(FE_OVERFLOW)\n\t\n#elif defined(AIX)\n\n#include \n#include \n\n#define UFUNC_CHECK_STATUS(ret) { \\\n\tfpflag_t fpstatus; \\\n \\\n\tfpstatus = fp_read_flag();\n\tret = ((FP_DIV_BY_ZERO & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \\\n\t\t| ((FP_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n\t\t| ((FP_UNDERFLOW & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \\\n\t\t| ((FP_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0);\n\tfp_clr_flag( FP_DIV_BY_ZERO | FP_OVERFLOW | FP_UNDERFLOW | FP_INVALID); \\\n}\n\n#else\n\n#define NO_FLOATING_POINT_SUPPORT \n#define UFUNC_CHECK_STATUS(ret) { \\\n ret = 0;\t\t\t\t\t\t\t \\\n }\n\n#endif\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# undef CAT\n# undef CAT2\n# undef NS\n# undef inpt\n#endif\n\n\n#ifdef __cplusplus\n}\n#endif\n#endif /* !Py_UFUNCOBJECT_H */\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": 90, + "complexity": 0, + "token_count": 345, + "diff_parsed": { + "added": [ + "#elif defined(_AIX)", + "\tfpstatus = fp_read_flag(); \\", + "\t\t| ((FP_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0); \\" + ], + "deleted": [ + "#elif defined(AIX)", + "\tfpstatus = fp_read_flag();", + "\t\t| ((FP_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0);" + ] + } + } + ] + }, + { + "hash": "3883205632b3569a8741176b3888ea48485cf188", + "msg": "Add generate_div_by_zero", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-12T22:54:22+00:00", + "author_timezone": 0, + "committer_date": "2006-01-12T22:54:22+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "8aee1fe94c2d0c0d83d28f7cac7db4832e0e7026" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 0, + "insertions": 3, + "lines": 3, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "numpy/core/include/numpy/ufuncobject.h", + "new_path": "numpy/core/include/numpy/ufuncobject.h", + "filename": "ufuncobject.h", + "extension": "h", + "change_type": "MODIFY", + "diff": "@@ -296,6 +296,9 @@ typedef struct {\n \tfp_clr_flag( FP_DIV_BY_ZERO | FP_OVERFLOW | FP_UNDERFLOW | FP_INVALID); \\\n }\n \n+#define generate_divbyzero_error() fp_raise_xcp(FP_DIV_BY_ZERO)\n+#define generate_overflow_error() fp_raise_xcp(FE_OVERFLOW)\n+\n #else\n \n #define NO_FLOATING_POINT_SUPPORT \n", + "added_lines": 3, + "deleted_lines": 0, + "source_code": "#ifndef Py_UFUNCOBJECT_H\n#define Py_UFUNCOBJECT_H\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#define MAX_ARGS 40\n\ntypedef void (*PyUFuncGenericFunction) (char **, intp *, intp *, void *);\n\ntypedef struct {\n\tPyObject_HEAD\n\tint nin, nout, nargs;\n\tint identity;\n\tPyUFuncGenericFunction *functions;\n\tvoid **data;\n\tint ntypes;\n\tint check_return;\n\tchar *name, *types;\n\tchar *doc;\n void *ptr;\n PyObject *obj;\n\tPyObject *userloops;\n} PyUFuncObject;\n\n#include \"arrayobject.h\"\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# define CAT2(x,y) x ## y\n# define CAT(x,y) CAT2(x,y)\n# define NS(name) CAT(PY_ARRAY_TYPES_PREFIX, name)\n# define intp NS(intp)\n#endif\n\n#define UFUNC_ERR_IGNORE 0\n#define UFUNC_ERR_WARN 1\n#define UFUNC_ERR_RAISE 2\n#define UFUNC_ERR_CALL 3\n\n\t/* Python side integer mask */\n\n#define UFUNC_MASK_DIVIDEBYZERO 0x03\n#define UFUNC_MASK_OVERFLOW 0x0c\n#define UFUNC_MASK_UNDERFLOW 0x30\n#define UFUNC_MASK_INVALID 0xc0\n\n#define UFUNC_SHIFT_DIVIDEBYZERO 0\n#define UFUNC_SHIFT_OVERFLOW 2\n#define UFUNC_SHIFT_UNDERFLOW 4\n#define UFUNC_SHIFT_INVALID 6 \n\n\n/* platform-dependent code translates floating point\n status to an integer sum of these values\n*/\n#define UFUNC_FPE_DIVIDEBYZERO 1\n#define UFUNC_FPE_OVERFLOW 2\n#define UFUNC_FPE_UNDERFLOW 4\n#define UFUNC_FPE_INVALID 8\n\t\n#define UFUNC_ERR_DEFAULT 0 /* Default error mode */\n\n\t/* Only internal -- not exported, yet*/\ntypedef struct {\n\t/* Multi-iterator portion --- needs to be present in this order \n\t to work with PyArray_Broadcast */\n\tPyObject_HEAD\n\tint numiter;\n\tintp size;\n\tintp index;\n\tint nd;\n\tintp dimensions[MAX_DIMS];\t\n\tPyArrayIterObject *iters[MAX_ARGS];\n /* End of Multi-iterator portion */\n\n\t/* The ufunc */\n\tPyUFuncObject *ufunc;\n\t\n\t/* The error handling */\n\tint errormask; /* Integer showing desired error handling */\n\tPyObject *errobj; /* currently a tuple with \n\t\t\t\t (string, func or None)\n\t\t\t */\n\n\t/* Specific function and data to use */\n\tPyUFuncGenericFunction function;\n\tvoid *funcdata;\n\n\t/* Loop method */\n\tint meth;\n\n\t/* Whether we need to copy to a buffer or not.*/\n\tint needbuffer[MAX_ARGS];\n\tint leftover;\n\tint ninnerloops;\n\tint lastdim;\n\t\n\t/* Whether or not to swap */\n\tint swap[MAX_ARGS];\n\n\t/* Buffers for the loop */\n\tvoid *buffer[MAX_ARGS];\n\tint bufsize;\n\tintp bufcnt;\n\tvoid *dptr[MAX_ARGS];\n\n\t/* For casting */\n\tvoid *castbuf[MAX_ARGS];\n\tPyArray_VectorUnaryFunc *cast[MAX_ARGS];\n\n\t/* usually points to buffer but when a cast is to be\n\t done it switches for that argument to castbuf.\n\t*/\n\tvoid *bufptr[MAX_ARGS]; \n\n\t/* Steps filled in from iters or sizeof(item)\n\t depending on loop method. \n\t*/\n\tintp steps[MAX_ARGS];\n\n int obj; /* This loop calls object functions */\n int notimplemented; /* The loop caused notimplemented */\n\t\n} PyUFuncLoopObject;\n\n/* Could make this more clever someday */\n#define UFUNC_MAXIDENTITY 32\n\ntypedef struct {\n PyObject_HEAD\n PyArrayIterObject *it;\n PyArrayObject *ret;\n\tPyArrayIterObject *rit; /* Needed for Accumulate */\n int outsize;\n\tintp index;\n\tintp size;\n char idptr[UFUNC_MAXIDENTITY];\n\n\t/* The ufunc */\n\tPyUFuncObject *ufunc;\n\n\t/* The error handling */\n\tint errormask;\n\tPyObject *errobj;\n\n PyUFuncGenericFunction function;\n void *funcdata;\n int meth;\n int swap;\n\n void *buffer;\n int bufsize;\n\n void *castbuf;\n PyArray_VectorUnaryFunc *cast;\n\n void *bufptr[3];\n intp steps[3];\n\n intp N;\n int instrides;\n int insize;\n char *inptr;\n\n /* For copying small arrays */\n PyObject *decref;\n\n int obj;\n\n} PyUFuncReduceObject;\n\n\n#if defined(ALLOW_THREADS)\n#define LOOP_BEGIN_THREADS if (!(loop->obj)) {_save = PyEval_SaveThread();}\n#define LOOP_END_THREADS if (!(loop->obj)) {PyEval_RestoreThread(_save);}\n#else\n#define LOOP_BEGIN_THREADS\n#define LOOP_END_THREADS\n#endif\n\n#define PyUFunc_One 1\n#define PyUFunc_Zero 0\n#define PyUFunc_None -1\n\n#define UFUNC_REDUCE 0\n#define UFUNC_ACCUMULATE 1\n#define UFUNC_REDUCEAT 2\n#define UFUNC_OUTER 3\n\n\ntypedef struct {\n int nin;\n int nout;\n PyObject *callable;\n} PyUFunc_PyFuncData;\n\n\n#include \"__ufunc_api.h\"\n\n#define UFUNC_PYVALS_NAME \"UFUNC_PYVALS\"\n\n#define UFUNC_CHECK_ERROR(arg) \\\n\tif (((arg)->obj && PyErr_Occurred()) || \\\n ((arg)->errormask && \\\n PyUFunc_checkfperr((arg)->errormask, \\\n (arg)->errobj))) \\\n\t\tgoto fail\n\n/* This code checks the IEEE status flags in a platform-dependent way */\n/* Adapted from Numarray */\n\n/* OSF/Alpha (Tru64) ---------------------------------------------*/\n#if defined(__osf__) && defined(__alpha)\n\n#include \n\n#define UFUNC_CHECK_STATUS(ret) {\t\t\\\n\tunsigned long fpstatus;\t\t \\\n\t\t\t\t\t\t\\\n\tfpstatus = ieee_get_fp_control();\t\t\t\t\\\n\t/* clear status bits as well as disable exception mode if on */ \\\n\tieee_set_fp_control( 0 );\t\t\t\t\t\\\n\tret = ((IEEE_STATUS_DZE & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \\\n\t\t| ((IEEE_STATUS_OVF & fpstatus) ? UFUNC_FPE_OVERFLOW : 0) \\\n\t\t| ((IEEE_STATUS_UNF & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \\\n\t\t| ((IEEE_STATUS_INV & fpstatus) ? UFUNC_FPE_INVALID : 0); \\\n\t}\n\t\n/* MS Windows -----------------------------------------------------*/\n#elif defined(_MSC_VER) \n\n#include \n\n#define UFUNC_CHECK_STATUS(ret) {\t\t \\\n\tint fpstatus = (int) _clear87();\t\t\t\\\n\t\t\t\t\t\t\t\t\t\\\n\tret = ((SW_ZERODIVIDE & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0)\t\\\n\t\t| ((SW_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n\t\t| ((SW_UNDERFLOW & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0)\t\\\n\t\t| ((SW_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0);\t\\\n\t}\n\t\n\n/* Solaris --------------------------------------------------------*/\n/* --------ignoring SunOS ieee_flags approach, someone else can\n** deal with that! */\n#elif defined(sun) || defined(__OpenBSD__) || defined(__FreeBSD__)\n#include \n\n#define UFUNC_CHECK_STATUS(ret) {\t\t\t\t\\\n\tint fpstatus;\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\\\n\tfpstatus = (int) fpgetsticky();\t\t\t\t\t\\\n\tret = ((FP_X_DZ & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0)\t\\\n\t\t| ((FP_X_OFL & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n\t\t| ((FP_X_UFL & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0)\t\\\n\t\t| ((FP_X_INV & fpstatus) ? UFUNC_FPE_INVALID : 0);\t\\\n\t(void) fpsetsticky(0);\t\t\t\t\t\t\\\n\t}\n\t\n#elif defined(linux) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__MINGW32__)\n\n#if defined(__GLIBC__) || defined(__APPLE__) || defined(__MINGW32__)\n#include \n#elif defined(__CYGWIN__)\n#include \n#endif\n\n#define UFUNC_CHECK_STATUS(ret) { \\\n\tint fpstatus = (int) fetestexcept(FE_DIVBYZERO | FE_OVERFLOW |\t\\\n\t\t\t\t\t FE_UNDERFLOW | FE_INVALID);\t\\\n\tret = ((FE_DIVBYZERO & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \\\n\t\t| ((FE_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n\t\t| ((FE_UNDERFLOW & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \\\n\t\t| ((FE_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0);\t\\\n\t(void) feclearexcept(FE_DIVBYZERO | FE_OVERFLOW |\t\t\\\n\t\t\t FE_UNDERFLOW | FE_INVALID);\t\t\\\n}\n\n#define generate_divbyzero_error() feraiseexcept(FE_DIVBYZERO)\n#define generate_overflow_error() feraiseexcept(FE_OVERFLOW)\n\t\n#elif defined(_AIX)\n\n#include \n#include \n\n#define UFUNC_CHECK_STATUS(ret) { \\\n\tfpflag_t fpstatus; \\\n \\\n\tfpstatus = fp_read_flag(); \\\n\tret = ((FP_DIV_BY_ZERO & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \\\n\t\t| ((FP_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n\t\t| ((FP_UNDERFLOW & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \\\n\t\t| ((FP_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0); \\\n\tfp_clr_flag( FP_DIV_BY_ZERO | FP_OVERFLOW | FP_UNDERFLOW | FP_INVALID); \\\n}\n\n#define generate_divbyzero_error() fp_raise_xcp(FP_DIV_BY_ZERO)\n#define generate_overflow_error() fp_raise_xcp(FE_OVERFLOW)\n\n#else\n\n#define NO_FLOATING_POINT_SUPPORT \n#define UFUNC_CHECK_STATUS(ret) { \\\n ret = 0;\t\t\t\t\t\t\t \\\n }\n\n#endif\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# undef CAT\n# undef CAT2\n# undef NS\n# undef inpt\n#endif\n\n\n#ifdef __cplusplus\n}\n#endif\n#endif /* !Py_UFUNCOBJECT_H */\n", + "source_code_before": "#ifndef Py_UFUNCOBJECT_H\n#define Py_UFUNCOBJECT_H\n#ifdef __cplusplus\nextern \"C\" {\n#endif\n\n#define MAX_ARGS 40\n\ntypedef void (*PyUFuncGenericFunction) (char **, intp *, intp *, void *);\n\ntypedef struct {\n\tPyObject_HEAD\n\tint nin, nout, nargs;\n\tint identity;\n\tPyUFuncGenericFunction *functions;\n\tvoid **data;\n\tint ntypes;\n\tint check_return;\n\tchar *name, *types;\n\tchar *doc;\n void *ptr;\n PyObject *obj;\n\tPyObject *userloops;\n} PyUFuncObject;\n\n#include \"arrayobject.h\"\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# define CAT2(x,y) x ## y\n# define CAT(x,y) CAT2(x,y)\n# define NS(name) CAT(PY_ARRAY_TYPES_PREFIX, name)\n# define intp NS(intp)\n#endif\n\n#define UFUNC_ERR_IGNORE 0\n#define UFUNC_ERR_WARN 1\n#define UFUNC_ERR_RAISE 2\n#define UFUNC_ERR_CALL 3\n\n\t/* Python side integer mask */\n\n#define UFUNC_MASK_DIVIDEBYZERO 0x03\n#define UFUNC_MASK_OVERFLOW 0x0c\n#define UFUNC_MASK_UNDERFLOW 0x30\n#define UFUNC_MASK_INVALID 0xc0\n\n#define UFUNC_SHIFT_DIVIDEBYZERO 0\n#define UFUNC_SHIFT_OVERFLOW 2\n#define UFUNC_SHIFT_UNDERFLOW 4\n#define UFUNC_SHIFT_INVALID 6 \n\n\n/* platform-dependent code translates floating point\n status to an integer sum of these values\n*/\n#define UFUNC_FPE_DIVIDEBYZERO 1\n#define UFUNC_FPE_OVERFLOW 2\n#define UFUNC_FPE_UNDERFLOW 4\n#define UFUNC_FPE_INVALID 8\n\t\n#define UFUNC_ERR_DEFAULT 0 /* Default error mode */\n\n\t/* Only internal -- not exported, yet*/\ntypedef struct {\n\t/* Multi-iterator portion --- needs to be present in this order \n\t to work with PyArray_Broadcast */\n\tPyObject_HEAD\n\tint numiter;\n\tintp size;\n\tintp index;\n\tint nd;\n\tintp dimensions[MAX_DIMS];\t\n\tPyArrayIterObject *iters[MAX_ARGS];\n /* End of Multi-iterator portion */\n\n\t/* The ufunc */\n\tPyUFuncObject *ufunc;\n\t\n\t/* The error handling */\n\tint errormask; /* Integer showing desired error handling */\n\tPyObject *errobj; /* currently a tuple with \n\t\t\t\t (string, func or None)\n\t\t\t */\n\n\t/* Specific function and data to use */\n\tPyUFuncGenericFunction function;\n\tvoid *funcdata;\n\n\t/* Loop method */\n\tint meth;\n\n\t/* Whether we need to copy to a buffer or not.*/\n\tint needbuffer[MAX_ARGS];\n\tint leftover;\n\tint ninnerloops;\n\tint lastdim;\n\t\n\t/* Whether or not to swap */\n\tint swap[MAX_ARGS];\n\n\t/* Buffers for the loop */\n\tvoid *buffer[MAX_ARGS];\n\tint bufsize;\n\tintp bufcnt;\n\tvoid *dptr[MAX_ARGS];\n\n\t/* For casting */\n\tvoid *castbuf[MAX_ARGS];\n\tPyArray_VectorUnaryFunc *cast[MAX_ARGS];\n\n\t/* usually points to buffer but when a cast is to be\n\t done it switches for that argument to castbuf.\n\t*/\n\tvoid *bufptr[MAX_ARGS]; \n\n\t/* Steps filled in from iters or sizeof(item)\n\t depending on loop method. \n\t*/\n\tintp steps[MAX_ARGS];\n\n int obj; /* This loop calls object functions */\n int notimplemented; /* The loop caused notimplemented */\n\t\n} PyUFuncLoopObject;\n\n/* Could make this more clever someday */\n#define UFUNC_MAXIDENTITY 32\n\ntypedef struct {\n PyObject_HEAD\n PyArrayIterObject *it;\n PyArrayObject *ret;\n\tPyArrayIterObject *rit; /* Needed for Accumulate */\n int outsize;\n\tintp index;\n\tintp size;\n char idptr[UFUNC_MAXIDENTITY];\n\n\t/* The ufunc */\n\tPyUFuncObject *ufunc;\n\n\t/* The error handling */\n\tint errormask;\n\tPyObject *errobj;\n\n PyUFuncGenericFunction function;\n void *funcdata;\n int meth;\n int swap;\n\n void *buffer;\n int bufsize;\n\n void *castbuf;\n PyArray_VectorUnaryFunc *cast;\n\n void *bufptr[3];\n intp steps[3];\n\n intp N;\n int instrides;\n int insize;\n char *inptr;\n\n /* For copying small arrays */\n PyObject *decref;\n\n int obj;\n\n} PyUFuncReduceObject;\n\n\n#if defined(ALLOW_THREADS)\n#define LOOP_BEGIN_THREADS if (!(loop->obj)) {_save = PyEval_SaveThread();}\n#define LOOP_END_THREADS if (!(loop->obj)) {PyEval_RestoreThread(_save);}\n#else\n#define LOOP_BEGIN_THREADS\n#define LOOP_END_THREADS\n#endif\n\n#define PyUFunc_One 1\n#define PyUFunc_Zero 0\n#define PyUFunc_None -1\n\n#define UFUNC_REDUCE 0\n#define UFUNC_ACCUMULATE 1\n#define UFUNC_REDUCEAT 2\n#define UFUNC_OUTER 3\n\n\ntypedef struct {\n int nin;\n int nout;\n PyObject *callable;\n} PyUFunc_PyFuncData;\n\n\n#include \"__ufunc_api.h\"\n\n#define UFUNC_PYVALS_NAME \"UFUNC_PYVALS\"\n\n#define UFUNC_CHECK_ERROR(arg) \\\n\tif (((arg)->obj && PyErr_Occurred()) || \\\n ((arg)->errormask && \\\n PyUFunc_checkfperr((arg)->errormask, \\\n (arg)->errobj))) \\\n\t\tgoto fail\n\n/* This code checks the IEEE status flags in a platform-dependent way */\n/* Adapted from Numarray */\n\n/* OSF/Alpha (Tru64) ---------------------------------------------*/\n#if defined(__osf__) && defined(__alpha)\n\n#include \n\n#define UFUNC_CHECK_STATUS(ret) {\t\t\\\n\tunsigned long fpstatus;\t\t \\\n\t\t\t\t\t\t\\\n\tfpstatus = ieee_get_fp_control();\t\t\t\t\\\n\t/* clear status bits as well as disable exception mode if on */ \\\n\tieee_set_fp_control( 0 );\t\t\t\t\t\\\n\tret = ((IEEE_STATUS_DZE & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \\\n\t\t| ((IEEE_STATUS_OVF & fpstatus) ? UFUNC_FPE_OVERFLOW : 0) \\\n\t\t| ((IEEE_STATUS_UNF & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \\\n\t\t| ((IEEE_STATUS_INV & fpstatus) ? UFUNC_FPE_INVALID : 0); \\\n\t}\n\t\n/* MS Windows -----------------------------------------------------*/\n#elif defined(_MSC_VER) \n\n#include \n\n#define UFUNC_CHECK_STATUS(ret) {\t\t \\\n\tint fpstatus = (int) _clear87();\t\t\t\\\n\t\t\t\t\t\t\t\t\t\\\n\tret = ((SW_ZERODIVIDE & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0)\t\\\n\t\t| ((SW_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n\t\t| ((SW_UNDERFLOW & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0)\t\\\n\t\t| ((SW_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0);\t\\\n\t}\n\t\n\n/* Solaris --------------------------------------------------------*/\n/* --------ignoring SunOS ieee_flags approach, someone else can\n** deal with that! */\n#elif defined(sun) || defined(__OpenBSD__) || defined(__FreeBSD__)\n#include \n\n#define UFUNC_CHECK_STATUS(ret) {\t\t\t\t\\\n\tint fpstatus;\t\t\t\t\t\t\\\n\t\t\t\t\t\t\t\t\\\n\tfpstatus = (int) fpgetsticky();\t\t\t\t\t\\\n\tret = ((FP_X_DZ & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0)\t\\\n\t\t| ((FP_X_OFL & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n\t\t| ((FP_X_UFL & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0)\t\\\n\t\t| ((FP_X_INV & fpstatus) ? UFUNC_FPE_INVALID : 0);\t\\\n\t(void) fpsetsticky(0);\t\t\t\t\t\t\\\n\t}\n\t\n#elif defined(linux) || defined(__APPLE__) || defined(__CYGWIN__) || defined(__MINGW32__)\n\n#if defined(__GLIBC__) || defined(__APPLE__) || defined(__MINGW32__)\n#include \n#elif defined(__CYGWIN__)\n#include \n#endif\n\n#define UFUNC_CHECK_STATUS(ret) { \\\n\tint fpstatus = (int) fetestexcept(FE_DIVBYZERO | FE_OVERFLOW |\t\\\n\t\t\t\t\t FE_UNDERFLOW | FE_INVALID);\t\\\n\tret = ((FE_DIVBYZERO & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \\\n\t\t| ((FE_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n\t\t| ((FE_UNDERFLOW & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \\\n\t\t| ((FE_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0);\t\\\n\t(void) feclearexcept(FE_DIVBYZERO | FE_OVERFLOW |\t\t\\\n\t\t\t FE_UNDERFLOW | FE_INVALID);\t\t\\\n}\n\n#define generate_divbyzero_error() feraiseexcept(FE_DIVBYZERO)\n#define generate_overflow_error() feraiseexcept(FE_OVERFLOW)\n\t\n#elif defined(_AIX)\n\n#include \n#include \n\n#define UFUNC_CHECK_STATUS(ret) { \\\n\tfpflag_t fpstatus; \\\n \\\n\tfpstatus = fp_read_flag(); \\\n\tret = ((FP_DIV_BY_ZERO & fpstatus) ? UFUNC_FPE_DIVIDEBYZERO : 0) \\\n\t\t| ((FP_OVERFLOW & fpstatus) ? UFUNC_FPE_OVERFLOW : 0)\t\\\n\t\t| ((FP_UNDERFLOW & fpstatus) ? UFUNC_FPE_UNDERFLOW : 0) \\\n\t\t| ((FP_INVALID & fpstatus) ? UFUNC_FPE_INVALID : 0); \\\n\tfp_clr_flag( FP_DIV_BY_ZERO | FP_OVERFLOW | FP_UNDERFLOW | FP_INVALID); \\\n}\n\n#else\n\n#define NO_FLOATING_POINT_SUPPORT \n#define UFUNC_CHECK_STATUS(ret) { \\\n ret = 0;\t\t\t\t\t\t\t \\\n }\n\n#endif\n\n#ifdef PY_ARRAY_TYPES_PREFIX\n# undef CAT\n# undef CAT2\n# undef NS\n# undef inpt\n#endif\n\n\n#ifdef __cplusplus\n}\n#endif\n#endif /* !Py_UFUNCOBJECT_H */\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": 90, + "complexity": 0, + "token_count": 345, + "diff_parsed": { + "added": [ + "#define generate_divbyzero_error() fp_raise_xcp(FP_DIV_BY_ZERO)", + "#define generate_overflow_error() fp_raise_xcp(FE_OVERFLOW)", + "" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "968dd66df41a74bc3aea2c806705fdf4c52e61ee", + "msg": "fix up the expm1 and log1p additions.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-13T02:29:56+00:00", + "author_timezone": 0, + "committer_date": "2006-01-13T02:29:56+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "3883205632b3569a8741176b3888ea48485cf188" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/repo_copy", + "deletions": 28, + "insertions": 81, + "lines": 109, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "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": "@@ -8,7 +8,8 @@\n #include \n \n \n-/* A whole slew of basic math functions are provided originally by Konrad Hinsen. */\n+/* A whole slew of basic math functions are provided originally \n+ by Konrad Hinsen. */\n \n #if !defined(__STDC__) && !defined(_MSC_VER)\n extern double fmod (double, double);\n@@ -20,31 +21,6 @@ extern double modf (double, double *);\n #define M_PI 3.14159265358979323846264338328\n #endif\n \n-#ifndef HAVE_LOG1P\n-static double 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-#ifndef HAVE_EXPM1\n-static 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 #ifndef HAVE_INVERSE_HYPERBOLIC\n static double acosh(double x)\n@@ -314,8 +290,6 @@ double hypot(double x, double y)\n asinh, acosh, atanh\n \n hypot, atan2, pow\n-\n- log1p, expm1\n */\n \n /**begin repeat\n@@ -365,6 +339,85 @@ double hypot(double x, double y)\n \n \n \n+#ifndef HAVE_LOG1P\n+static double 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+static longdouble 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+static float 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\n+static 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+static 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+static 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", + "added_lines": 81, + "deleted_lines": 28, + "source_code": "/* -*- c -*- */\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#define _UMATHMODULE\n#include \"numpy/ufuncobject.h\"\n#include \"abstract.h\"\n#include \n\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\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\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\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\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\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\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\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\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n#else\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\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\ndouble 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\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\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,log1p,expm1)*2#\n#typ=longdouble*18, float*18#\n#c=l*18,f*18#\n#TYPE=LONGDOUBLE*18, FLOAT*18#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\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@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@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\nstatic double 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)\nstatic longdouble 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)\nstatic float 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)\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)\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\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@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\t}\n\telse if (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n\t}\n\telse {\n\t\tnc_log@c@(a, r);\n\t\tnc_prod@c@(r, b, r);\n\t\tnc_exp@c@(r, r);\n\t}\n\treturn;\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; i> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n\t/* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>32) || (y>>32) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>64) || (y>>64) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n\treturn 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n\tulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n\tif (a0 < 0) { a = -a0; } else { a = a0; }\n\tif (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n\tah = (a >> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n /*\n\t ulonglong c = ((x + y)<<32) + w;\n\t if ((a0 < 0) ^ (b0 < 0))\n\t *c = -c;\n\t else\n\t *c = c\n\t */\n\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>31) || (y>>31) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>63) || (y>>63) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n\treturn 0;\n#endif\n}\n\n/** end direct numarray code **/\n\nstatic void\nBOOL_multiply(char **args, intp *dimensions, intp *steps, void *func) {\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 MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nULONGLONG_multiply(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\tulonglong temp;\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\telse if (temp < MIN_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nLONGLONG_multiply(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\tlonglong temp;\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=fmod*10, 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\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\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 memcpy(op, i1, sizeof(@typ@));\n else\n memcpy(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\n/* A whole slew of basic math functions are provided originally 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#ifndef HAVE_LOG1P\nstatic double 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#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#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\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\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\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\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\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\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\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\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n#else\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\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\ndouble 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\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\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 log1p, expm1\n*/\n\n/**begin repeat\n\n#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan,log1p,expm1)*2#\n#typ=longdouble*18, float*18#\n#c=l*18,f*18#\n#TYPE=LONGDOUBLE*18, FLOAT*18#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\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@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@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\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\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@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\t}\n\telse if (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n\t}\n\telse {\n\t\tnc_log@c@(a, r);\n\t\tnc_prod@c@(r, b, r);\n\t\tnc_exp@c@(r, r);\n\t}\n\treturn;\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; i> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n\t/* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>32) || (y>>32) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>64) || (y>>64) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n\treturn 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n\tulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n\tif (a0 < 0) { a = -a0; } else { a = a0; }\n\tif (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n\tah = (a >> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n /*\n\t ulonglong c = ((x + y)<<32) + w;\n\t if ((a0 < 0) ^ (b0 < 0))\n\t *c = -c;\n\t else\n\t *c = c\n\t */\n\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>31) || (y>>31) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>63) || (y>>63) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n\treturn 0;\n#endif\n}\n\n/** end direct numarray code **/\n\nstatic void\nBOOL_multiply(char **args, intp *dimensions, intp *steps, void *func) {\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 MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nULONGLONG_multiply(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\tulonglong temp;\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\telse if (temp < MIN_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nLONGLONG_multiply(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\tlonglong temp;\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=fmod*10, 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\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\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 memcpy(op, i1, sizeof(@typ@));\n else\n memcpy(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\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\nfloat log1pf(float);\nfloat logf(float);\nfloat sqrtf(float);\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\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\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\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\nlongdouble logl(longdouble);\nlongdouble sqrtl(longdouble);\nlongdouble log1pl(longdouble);\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\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\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n#else\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\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\ndouble 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\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\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,log1p,expm1)*2#\n#typ=longdouble*18, float*18#\n#c=l*18,f*18#\n#TYPE=LONGDOUBLE*18, FLOAT*18#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\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@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@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)\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)\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)\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)\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\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@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\t}\n\telse if (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n\t}\n\telse {\n\t\tnc_log@c@(a, r);\n\t\tnc_prod@c@(r, b, r);\n\t\tnc_exp@c@(r, r);\n\t}\n\treturn;\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; i> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n\t/* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>32) || (y>>32) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>64) || (y>>64) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n\treturn 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n\tulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n\tif (a0 < 0) { a = -a0; } else { a = a0; }\n\tif (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n\tah = (a >> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n /*\n\t ulonglong c = ((x + y)<<32) + w;\n\t if ((a0 < 0) ^ (b0 < 0))\n\t *c = -c;\n\t else\n\t *c = c\n\t */\n\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>31) || (y>>31) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>63) || (y>>63) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n\treturn 0;\n#endif\n}\n\n/** end direct numarray code **/\n\nstatic void\nBOOL_multiply(char **args, intp *dimensions, intp *steps, void *func) {\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 MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nULONGLONG_multiply(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\tulonglong temp;\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\telse if (temp < MIN_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nLONGLONG_multiply(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\tlonglong temp;\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=fmod*10, 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\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\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 memcpy(op, i1, sizeof(@typ@));\n else\n memcpy(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\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\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\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\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\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\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\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\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\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n#else\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\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\ndouble 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\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\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,log1p,expm1)*2#\n#typ=longdouble*18, float*18#\n#c=l*18,f*18#\n#TYPE=LONGDOUBLE*18, FLOAT*18#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\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@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@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\nstatic double 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)\nstatic longdouble 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)\nstatic float 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)\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)\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\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@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\t}\n\telse if (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n\t}\n\telse {\n\t\tnc_log@c@(a, r);\n\t\tnc_prod@c@(r, b, r);\n\t\tnc_exp@c@(r, r);\n\t}\n\treturn;\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; i> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n\t/* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>32) || (y>>32) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>64) || (y>>64) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n\treturn 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n\tulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n\tif (a0 < 0) { a = -a0; } else { a = a0; }\n\tif (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n\tah = (a >> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n /*\n\t ulonglong c = ((x + y)<<32) + w;\n\t if ((a0 < 0) ^ (b0 < 0))\n\t *c = -c;\n\t else\n\t *c = c\n\t */\n\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>31) || (y>>31) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>63) || (y>>63) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n\treturn 0;\n#endif\n}\n\n/** end direct numarray code **/\n\nstatic void\nBOOL_multiply(char **args, intp *dimensions, intp *steps, void *func) {\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 MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nULONGLONG_multiply(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\tulonglong temp;\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\telse if (temp < MIN_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nLONGLONG_multiply(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\tlonglong temp;\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=fmod*10, 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\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\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 memcpy(op, i1, sizeof(@typ@));\n else\n memcpy(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; iob_type->tp_as_number != NULL &&\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) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else 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} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\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=NULL;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\tdescr = PyArray_DescrFromType(PyArray_INT);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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} else 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) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\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\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 if (PyBigArray_CheckExact(obj)) \n return PyArray_BIG_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\t\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\t\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\t\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\t\n dest_strides_ptr = dest_strides;\n\t\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\t\n new_data = (char *)_pya_malloc(stride);\n\t\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\t\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\t\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\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\nstatic PyArray_Descr **userdescrs=NULL;\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\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\t\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\n/* If destination is not the right type, then src \n will be cast to destination. \n*/\n\n/* Does a flat iterator-based copy. \n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however. \n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n \n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError, \n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->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, elsize);\n PyArray_INCREF(dest);\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 memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\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\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t dest->descr, 0,\n\t\t\t\t\t dest->nd, FORTRAN_IF(dest));\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\t\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/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\t\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\t\n return (PyObject *)ret;\t\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_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 (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}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize / sizeof(Py_UNICODE);\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\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, itemsize);\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/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\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\t\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\t\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 fwrite(sep, 1, n3, fp);\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\t\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\t\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\t\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\t\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\t\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\t\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \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\t\t\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\t\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\nstatic PyObject *\narray_item_nice(PyArrayObject *self, int i) \n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\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\t\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 SIZEOF_INT == SIZEOF_INTP\n#define array_ass_item array_ass_big_item\n#else\nstatic int\narray_ass_item(PyArrayObject *self, int 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\t\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\t\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\t\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\t\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\t\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\t\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\t\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);\t\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\t\n nd_old = nd_new = 0;\n\t\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\t\t\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 }\t \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\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\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);\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->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\t\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);\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}\n\t}\n\t\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, PyArray_ITEMSIZE(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}\t\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\t\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/* 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;\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\t\t\t\t\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\t\t\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\treturn PyArray_ToScalar(self->data, self);\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\treturn PyArray_ToScalar(self->data, self);\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n\t/* wrap arguments into a mapiter object */\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(op, oned);\n if (mit == NULL) return NULL;\n if (!mit->view) { /* fancy indexing */\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 Py_DECREF(mit);\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\t\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\t\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;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\t\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\t\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\t\t\t\t\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\t\t\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(index, oned);\n if (mit == NULL) return -1;\n if (!mit->view) {\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 Py_DECREF(mit);\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\t\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\treturn PyArray_Return((PyArrayObject *)array_subscript(self, op));\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n (inquiry)array_length,\t\t /*mp_length*/\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 \narray_getsegcount(PyArrayObject *self, int *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 \narray_getreadbuf(PyArrayObject *self, int 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 \narray_getwritebuf(PyArrayObject *self, int 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 \narray_getcharbuf(PyArrayObject *self, int 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 (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};\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\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;\t\n\t\n} NumericOps;\n\nstatic NumericOps n_ops = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL};\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\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);\t \n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\t\n SET(true_divide);\t\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\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;\t\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\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);\t \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\treturn dict;\t\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\t\t\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}\t\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}\t\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 *\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 PyObject *\narray_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.power);\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 *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.power);\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\t\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;\t \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 an \"\\\n\t\t\t\t\"int; 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;\t \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;\t \n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v) \n{\t \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;\t \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;\t \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*/\t\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 ilow, int ihigh) \n{\n PyArrayObject *r;\n int l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n \t\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\n self->dimensions[0] = l;\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 ilow, int ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\t\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\t\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\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, 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\n\nstatic PySequenceMethods array_as_sequence = {\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};\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\t\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\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\t\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\t\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\t\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\t\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\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\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 return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\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.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\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\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\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; ind == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tintp sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\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\t\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;\t\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by a single segment array of the provided \n dimensions and element size. If numbytes is 0 it will be calculated from \n the provided shape and element size.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\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;\t\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 */\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, \n\t\t\t intp *newstrides, int oldnd)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\t\n\told = *des;\n\t*des = old->subarray->base;\n\n\tmydim = newdims + oldnd;\n\tif (PyTuple_Check(old->subarray->shape)) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t\t\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tnumnew = 1;\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\t\n\tnewnd = oldnd + numnew;\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\t/* Make new strides */\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\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{\t\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\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);\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\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\t\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { /* strides is NULL too */\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\t\t\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\t\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 {\n\t\t\tif (data == NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"if 'strides' is given in \" \\\n\t\t\t\t\t\t\"array creation, data must \" \\\n\t\t\t\t\t\t\"be given too\");\n\t\t\t\tgoto fail;\n\t\t\t} \n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t} \t\n\t\t\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\t\tif (descr == &OBJECT_Descr) {\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 and some object passed in */\n\tif ((obj != NULL) && (subtype != &PyArray_Type) && \n\t (subtype != &PyBigArray_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 (!(self->flags & OWNDATA)) { /* did not allocate own data */\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\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\t\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*/\nstatic PyObject * \nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape)\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\t\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n \"resize only works on contiguous arrays\");\n return NULL;\n }\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\t\t\n\t\trefcnt = REFCOUNT(self);\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\t\t\t\t\n\t\tif (newsize == 0) sd = self->descr->elsize;\t\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 0, &(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);\t\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);\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\twhile (size--) {\n\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\ttoptr += itemsize;\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\t\t\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, itemsize);\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\", \n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", 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\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*/\t\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\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 &fortran)) \n\t\tgoto fail;\n\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 if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\\\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 NULL, 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\t\tbuffer.len -= offset;\n\t\tbuffer.ptr += offset;\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\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 (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\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 (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 PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\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\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\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;\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 != NULL) {\n\t\tif (PyArray_Check(new->base)) \n\t\t\tnew = (PyArrayObject *)new->base;\n\t}\n\tnumbytes = PyArray_MultiplyList(new->dimensions, \n\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes, \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 if (PyBigArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_BIG_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}\t\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 *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISEXTENDED(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->descr->elsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\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 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\t\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\t\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\t\n\telse if (newtype->elsize > self->descr->elsize) {\n\t\t\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\t\t\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\t\t\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\ttemp = (PyArrayObject *)\\\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\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tPy_DECREF(newtype);\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator */\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\ttemp->descr = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype; \n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\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\t\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"arrdescr\");\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_type_get(PyArrayObject *self)\n{\n Py_INCREF(self->descr->typeobj);\n return (PyObject *)self->descr->typeobj;\n}\n\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);\n\tif (new == NULL) return -1;\n\t\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) {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}\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{\t\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{\t\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); \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);\t\t\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));\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->descr->elsize);\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 {\"dtype\", \n\t (getter)array_type_get, \n\t NULL,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n\t{\"dtypedescr\", \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.dtypedescr object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\t\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.bigndarray\",\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 NULL, \t\t\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\t\t\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n NULL, \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/* A standard array will subclass from the Big Array and \n add the array_as_sequence table\n and the array_as_buffer table\n */\n\nstatic PyTypeObject PyArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n};\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\t\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;\t\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\t\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, sizeof(Py_UNICODE)*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\t\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, 2*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\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\t\n\tif (minitype == NULL) \n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\t\n if (max < 0) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\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 \t\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\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\t\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\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_BOOL);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_LONG);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_DOUBLE);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_CDOUBLE);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\n finish:\n\t\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\t\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\t\n l=PyObject_Length(v);\n if(l < 0) return -1; \n\t\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\t\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 *= sizeof(Py_UNICODE);\n\t}\n\n\tret = (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\n\tif (ret == NULL) return NULL;\n\n ret->descr->f->setitem(op, ret->data, ret);\n\t\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 unless return value is NULL*/\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\tPyArray_Descr *savetype=typecode;\n\t\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\t\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 return NULL;\n }\n\t\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 return NULL;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\treturn NULL;\n\t\t}\n\t\tif (type == PyArray_UNICODE) itemsize*=sizeof(Py_UNICODE);\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\t\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\t\n if(!r) {Py_XINCREF(savetype); return NULL;}\n if(Assign_Array(r,s) == -1) {\n\t\tPy_XINCREF(savetype);\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\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\t\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\t\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\t\t\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\t\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\t\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, elsize);\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\t\t\t\t\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\t\t\t\t\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 oelsize);\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);\t\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\t\t\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*sizeof(Py_UNICODE);\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize/sizeof(Py_UNICODE);\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\t\n\tPy_DECREF(out);\n\treturn NULL;\n\t\n}\n\t \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\t\t\t\t\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * outsize;\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\t\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 */\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) \n{\n\t\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\t\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 (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\t\t\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 != &PyBigArray_Type)) {\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 (subtype != &PyBigArray_Type)) {\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\t\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 != &PyBigArray_Type)) {\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\t\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}\t\t\n\t\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;\t \n\t\telse _MY_FAIL \n\t\t\tbreak;\t\t \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;\t\t \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;\t\t \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\t\tbreak;\n\tcase 'S':\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase 'U':\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize *= sizeof(Py_UNICODE);\n\t\tbreak;\t \n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\t\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/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_fromstructinterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r, *ret;\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_XDECREF(intype);\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_XDECREF(intype);\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 ret = array_fromarray((PyArrayObject*)r, intype, flags);\n Py_DECREF(r);\n return ret;\n}\n\n/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n PyObject *tstr=NULL, *shape=NULL; \n\tPyArrayObject *ret=NULL;\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\t\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\tPy_XDECREF(intype);\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\tPy_XDECREF(intype);\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\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n\n fail:\n\tPy_XDECREF(intype);\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* steals a reference to typecode */\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Descr *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode == NULL) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyObject *obj;\n\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", typecode->type,\n\t\t\t\t\t\t typecode->elsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(typecode->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\n if (new == NULL) {Py_XDECREF(typecode); 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\t\tPy_XDECREF(typecode);\n return NULL;\n }\n r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n/* Steals a reference to newtype --- which can be NULL */\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Descr *newtype, int min_depth, \n\t\t int max_depth, int flags) \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 = array_fromarray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if ((r = array_fromstructinterface(op, newtype, flags)) != \\\n\t\t Py_NotImplemented) {\n }\n else if ((r = array_frominterface(op, newtype, flags)) !=\t\\\n\t\t Py_NotImplemented) {\n\t}\n else if (PyObject_HasAttrString(op, \"__array__\")) {\n /* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, newtype, flags);\n }\n\telse {\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\t\t\t\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 PyErr_Clear();\n else\n seq = TRUE;\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\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\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\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_FromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n\t\tint max_depth, int requires) \n{\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\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 array_fromobject(op, descr, min_depth, max_depth,\n \t\t\t\trequires);\t\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 or PyBigArray_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) || PyBigArray_CheckExact(op)) return op;\n \n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FROM_OF(op, ENSUREARRAY);\n Py_DECREF(op);\n return new;\n}\n\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 * sizeof(Py_UNICODE)\\\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.\t\t \n\t\t*/\n\t}\n\treturn ret;\n}\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\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\t\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\t\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\t\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/* 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\niter_length(PyArrayIterObject *self) \n{\n return (int) 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, itemsize);\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\t\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, itemsize);\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;\t\t\t\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */ \t\n\t\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, size);\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);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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\t\t\t\t\t FORCECAST | ALIGNED);\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,\n\t\t\t\t itemsize);\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, itemsize);\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, itemsize);\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\t\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\t\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0);\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, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\t\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, itemsize);\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, itemsize);\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);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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_FromAny(obj, indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\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\t\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n (inquiry)iter_length,\t\t /*mp_length*/\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;\t\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\t{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 0, /* 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/* 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/* 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);\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\t\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\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\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 sizeof(intp));\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\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\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 sizeof(intp));\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 sizeof(intp));\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\t\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\t \n\tif (mit->view) return;\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\n\tsub = PyObject_GetItem((PyObject *)arr, mit->indexobj);\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\t\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\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\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= 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) *indptr, (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);\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\t\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->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_IndexError,\t\t\t\\\n\t\t\t\t\"arrays used as indices must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_IndexError, \"too many indices\");\n\t\tgoto fail;\n\t}\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\t\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);\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 ret:\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\t\n\tint i, err=0;\n\t\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\t\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\t\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);\t\n\t\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\t\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\t\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\t\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\t\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\t\n return (PyObject *)multi;\n\t\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\t_pya_free(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);\t\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 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/*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;\t\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(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 dtypedescr objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"dtype\", 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\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\tchar basic_=self->kind;\n\tchar endian = self->byteorder;\n\t\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\t\n\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t self->elsize);\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{\"subdescr\", \n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"arrdescr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"dtypestr\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\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\t\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\t\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, \"dtypedescr\");\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\tobj = PyString_FromFormat(\"%c%d\",self->kind, self->elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\t\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\t\n\tif (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\t\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\t\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\t\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*/\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\t\t\t\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 dtypedescr 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 dtypedescr object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\t\t\t\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);\t\t\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(\"dtypedescr(\");\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 dtypedescr 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\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtypedescr\",\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 0, \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", + "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\n/* Helper functions */\n\n#define error_converting(x) (((x) == -1) && PyErr_Occurred())\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=NULL;\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\tdescr = PyArray_DescrFromType(PyArray_INTP);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\telse if (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (longlong) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (longlong) PyLong_AsLongLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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) {\n\t\t\tlong_value = (longlong) PyLong_AsLongLong(obj);\n\t\t\tPy_DECREF(obj);\n\t\t}\n\t} else 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} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\t\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\n#if (SIZEOF_LONGLONG != SIZEOF_PY_INTPTR_T)\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=NULL;\n\tPyArray_Descr *descr;\n\tint ret;\n\n\t\n\tif (!o) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\tdescr = PyArray_DescrFromType(PyArray_INT);\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\tPy_DECREF(descr);\n\t\t\treturn -1;\n\t\t}\n\t\tarr = PyArray_CastToType((PyArrayObject *)o, descr, 0);\n\t}\n\tif (PyArray_IsScalar(o, Integer)) {\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}\t\t\n\tif (PyInt_Check(o)) {\n\t\tlong_value = (long) PyInt_AS_LONG(o);\n\t} else if (PyLong_Check(o)) {\n\t\tlong_value = (long) PyLong_AsLong(o);\n\t} else if (o->ob_type->tp_as_number != NULL &&\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} else 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) return -1;\n\t\tlong_value = (long) PyLong_AsLong(obj);\n\t\tPy_DECREF(obj);\n\t} else {\n\t\tPyErr_SetString(PyExc_NotImplementedError,\"\");\n\t}\n\tif error_converting(long_value) {\n\t\tPyErr_SetString(PyExc_TypeError, msg);\n\t\treturn -1;\n\t}\n\t\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\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 if (PyBigArray_CheckExact(obj)) \n return PyArray_BIG_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\t\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\t\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\t\n for(i=dest_nd-1; i>=0; i--) {\n dest_strides[i] = stride;\n stride *= dest_dimensions[i];\n }\n\t\n dest_strides_ptr = dest_strides;\n\t\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\t\n new_data = (char *)_pya_malloc(stride);\n\t\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\t\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\t\n if (mp->descr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\n n = PyArray_SIZE(mp);\n data2 = data;\n for(i=0; idescr->type_num != PyArray_OBJECT) return 0;\n\t\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\t\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\nstatic PyArray_Descr **userdescrs=NULL;\n/* Computer-generated arraytype and scalartype code */\n#include \"scalartypes.inc\"\n#include \"arraytypes.inc\"\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\t\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\n/* If destination is not the right type, then src \n will be cast to destination. \n*/\n\n/* Does a flat iterator-based copy. \n\n The arrays are assumed to have the same number of elements\n They can be different sizes and have different types however. \n*/\n\n/*OBJECT_API\n Copy an Array into another array.\n*/\nstatic int\nPyArray_CopyInto(PyArrayObject *dest, PyArrayObject *src)\n{\n intp dsize, ssize, sbytes, ncopies;\n\tint elsize, index;\n PyArrayIterObject *dit=NULL;\n PyArrayIterObject *sit=NULL;\n\tchar *dptr;\n\tint swap;\n PyArray_CopySwapFunc *copyswap;\n PyArray_CopySwapNFunc *copyswapn;\n \n if (!PyArray_ISWRITEABLE(dest)) {\n PyErr_SetString(PyExc_RuntimeError, \n \"cannot write to array\");\n return -1;\n }\n\n if (!PyArray_EquivArrTypes(dest, src)) {\n return PyArray_CastTo(dest, src);\n }\n\n dsize = PyArray_SIZE(dest);\n ssize = PyArray_SIZE(src);\n\tif (ssize == 0) return 0;\n if (dsize % ssize != 0) {\n PyErr_SetString(PyExc_ValueError, \n \"number of elements in destination must be \"\\\n \"integer multiple of number of \"\\\n \"elements in source\");\n return -1;\n }\n ncopies = (dsize / ssize);\n\n\tswap = PyArray_ISNOTSWAPPED(dest) != PyArray_ISNOTSWAPPED(src);\n\tcopyswap = dest->descr->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, elsize);\n PyArray_INCREF(dest);\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 memmove(dit->dataptr, sit->dataptr, elsize);\n\t\t\tif (swap)\n\t\t\t\tcopyswap(dit->dataptr, NULL, 1, elsize);\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\n\tPy_INCREF(dest->descr);\n src = (PyArrayObject *)PyArray_FromAny(src_object,\n\t\t\t\t\t dest->descr, 0,\n\t\t\t\t\t dest->nd, FORTRAN_IF(dest));\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\t\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/*OBJECT_API\n Copy an array.\n*/\nstatic PyObject *\nPyArray_NewCopy(PyArrayObject *m1, int fortran)\n{\n\tPyArrayObject *ret;\n\tif (fortran < 0) fortran = PyArray_ISFORTRAN(m1);\n\t\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\t\n return (PyObject *)ret;\t\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_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 (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}\n\t\telse if (type_num == PyArray_UNICODE) {\n\t\t\tPyUnicodeObject *uni = (PyUnicodeObject*)obj;\n\t\t\tint length = itemsize / sizeof(Py_UNICODE);\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\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, itemsize);\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/*OBJECT_API\n Get scalar-equivalent to 0-d array\n*/\nstatic PyObject *\nPyArray_ToScalar(void *data, PyArrayObject *arr)\n{\n\treturn PyArray_Scalar(data, arr->descr, (PyObject *)arr);\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\t\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\t\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 fwrite(sep, 1, n3, fp);\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\t\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\t\n sz = self->dimensions[0];\n lp = PyList_New(sz);\n\t\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\t\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\t\n\tPyDimMem_FREE(self->dimensions);\n\n\tPy_DECREF(self->descr);\n\t\n self->ob_type->tp_free((PyObject *)self);\n}\n\n/*************************************************************************\n **************** Implement Mapping Protocol ***************************\n *************************************************************************/\n\nstatic int \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\t\t\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\t\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\nstatic PyObject *\narray_item_nice(PyArrayObject *self, int i) \n{\n\treturn PyArray_Return((PyArrayObject *)array_big_item(self, (intp) i));\n}\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\t\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 SIZEOF_INT == SIZEOF_INTP\n#define array_ass_item array_ass_big_item\n#else\nstatic int\narray_ass_item(PyArrayObject *self, int 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\t\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\t\n\tdefstart = *step < 0 ? length - 1 : 0;\n\tdefstop = *step < 0 ? -1 : length;\n\t\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\t\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\t\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\t\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\t\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);\t\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\t\n nd_old = nd_new = 0;\n\t\n offset = 0;\n for(i=0; ind ? \\\n self->dimensions[nd_old] : 0);\n Py_DECREF(op1);\n if (start == -1) break;\n\t\t\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 }\t \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\n\tpermute.ptr = d;\n\tpermute.len = mit->nd;\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);\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->descr->elsize);\n\t\tPyArray_MapIterNext(mit);\n\t\tPyArray_ITER_NEXT(it);\n\t}\n\tPy_DECREF(it);\n\t\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);\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}\n\t}\n\t\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, PyArray_ITEMSIZE(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}\t\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\t\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/* 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;\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\t\t\t\t\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\t\t\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\treturn PyArray_ToScalar(self->data, self);\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\treturn PyArray_ToScalar(self->data, self);\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n\t/* wrap arguments into a mapiter object */\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(op, oned);\n if (mit == NULL) return NULL;\n if (!mit->view) { /* fancy indexing */\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 Py_DECREF(mit);\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\t\n\tPyArray_UpdateFlags(other, UPDATE_ALL_FLAGS);\n\t\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;\n\tintp i;\n PyArrayObject *tmp;\n\tPyArrayMapIterObject *mit;\n\t\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\t\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\t\t\t\t\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\t\t\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\toned = ((self->nd == 1) && !(PyTuple_Check(op) && PyTuple_GET_SIZE(op) > 1));\n\n mit = (PyArrayMapIterObject *)PyArray_MapIterNew(index, oned);\n if (mit == NULL) return -1;\n if (!mit->view) {\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 Py_DECREF(mit);\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\t\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\treturn PyArray_Return((PyArrayObject *)array_subscript(self, op));\n}\n\n\nstatic PyMappingMethods array_as_mapping = {\n (inquiry)array_length,\t\t /*mp_length*/\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 \narray_getsegcount(PyArrayObject *self, int *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 \narray_getreadbuf(PyArrayObject *self, int 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 \narray_getwritebuf(PyArrayObject *self, int 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 \narray_getcharbuf(PyArrayObject *self, int 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 (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};\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\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;\t\n\t\n} NumericOps;\n\nstatic NumericOps n_ops = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, \n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,\n NULL, NULL, NULL, NULL, NULL};\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\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);\t \n SET(less_equal);\n SET(equal);\n SET(not_equal);\n SET(greater);\n SET(greater_equal);\n SET(floor_divide);\t\n SET(true_divide);\t\n\tSET(logical_or);\n\tSET(logical_and);\n\tSET(floor);\n\tSET(ceil);\n\tSET(maximum);\n\tSET(minimum);\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;\t\n\tGET(add);\n GET(subtract);\n GET(multiply);\n GET(divide);\n GET(remainder);\n GET(power);\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);\t \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\treturn dict;\t\n\n fail:\n\tPy_DECREF(dict);\n\treturn NULL;\t\t\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}\t\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}\t\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 *\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 PyObject *\narray_power(PyArrayObject *m1, PyObject *m2) \n{\n return PyArray_GenericBinaryFunction(m1, m2, n_ops.power);\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 *m1, PyObject *m2) \n{\n return PyArray_GenericInplaceBinaryFunction(m1, m2, n_ops.power);\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\t\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;\t \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 an \"\\\n\t\t\t\t\"int; 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;\t \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;\t \n}\n\nstatic PyObject *\narray_oct(PyArrayObject *v) \n{\t \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;\t \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;\t \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*/\t\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 ilow, int ihigh) \n{\n PyArrayObject *r;\n int l;\n char *data;\n\n if (self->nd == 0) {\n PyErr_SetString(PyExc_ValueError, \"cannot slice a scalar\");\n return NULL;\n }\n \t\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\n self->dimensions[0] = l;\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 ilow, int ihigh, PyObject *v) {\n int ret;\n PyArrayObject *tmp;\n\t\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\t\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\n res = PyArray_EnsureArray(PyObject_RichCompare((PyObject *)self, 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\n\nstatic PySequenceMethods array_as_sequence = {\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};\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\t\n#define CHECK_MEMORY if (*n >= *max_n-16) { *max_n *= 2; \\\n\t\t*string = (char *)_pya_realloc(*string, *max_n); }\n\t\n if (nd == 0) {\n\t\t\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\t\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\t\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\t\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\t\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\nstatic PyObject *\narray_richcompare(PyArrayObject *self, PyObject *other, int cmp_op) \n{\n PyObject *array_other, *result;\n\n switch (cmp_op) \n {\n case Py_LT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less);\n case Py_LE:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.less_equal);\n case Py_EQ:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then return the integer\n\t\t\t object 0. This fixes code that used to\n\t\t\t allow equality comparisons between arrays\n\t\t\t and other objects which would give a result\n\t\t\t of 0\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_False);\n return Py_False;\n }\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 return result;\n case Py_NE:\n /* Try to convert other to an array */\n array_other = PyArray_FromObject(other, \n\t\t\t\t\t\t\t PyArray_NOTYPE, 0, 0);\n /* If not successful, then objects cannot be \n\t\t\t compared and cannot be equal, therefore, \n\t\t\t return True;\n */\n if ((array_other == NULL) || \\\n\t\t\t (array_other == Py_None)) {\n Py_XDECREF(array_other);\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\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.not_equal);\n Py_DECREF(array_other);\n if (result == NULL) {\n PyErr_Clear();\n Py_INCREF(Py_True);\n return Py_True;\n }\n return result;\n case Py_GT:\n return PyArray_GenericBinaryFunction(self, other, \n\t\t\t\t\t\t\t n_ops.greater);\n case Py_GE:\n return PyArray_GenericBinaryFunction(self, \n\t\t\t\t\t\t\t other, \n\t\t\t\t\t \t n_ops.greater_equal);\n }\n return NULL;\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\t*axis = 0;\n\t\treturn temp;\n\t}\n\telse {\n\t\tif (flags) {\n\t\t\ttemp = PyArray_FromAny((PyObject *)arr, NULL, \n\t\t\t\t\t 0, 0, flags);\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; ind == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i = ap->nd-1; i >= 0; --i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\n\t}\n\treturn 1;\n}\n\n\nstatic int \n_IsFortranContiguous(PyArrayObject *ap) \n{\n\tintp sd;\n\tint i;\n\t\n\tif (ap->nd == 0) return 1;\n\tsd = ap->descr->elsize;\n\tif (ap->nd == 1) return sd == ap->strides[0];\n\tfor (i=0; i< ap->nd; ++i) {\n\t\t/* contiguous by definition */\n\t\tif (ap->dimensions[i] == 0) return 1; \n\t\t\n\t\tif (ap->strides[i] != sd) return 0;\n\t\tsd *= ap->dimensions[i];\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\t\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;\t\n }\n\treturn;\n}\n\n/* This routine checks to see if newstrides (of length nd) will not \n walk outside of the memory implied by a single segment array of the provided \n dimensions and element size. If numbytes is 0 it will be calculated from \n the provided shape and element size.\n*/\n/*OBJECT_API*/\nstatic Bool\nPyArray_CheckStrides(int elsize, int nd, intp numbytes, \n\t\t intp *dims, intp *newstrides)\n{\n\tint i;\n\t\n\tif (numbytes == 0) \n\t\tnumbytes = PyArray_MultiplyList(dims, nd) * elsize;\n\t\n\tfor (i=0; i numbytes) {\n\t\t\treturn FALSE;\n\t\t}\n\t}\n\treturn TRUE;\n\t\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;\t\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 */\nstatic int\n_update_descr_and_dimensions(PyArray_Descr **des, intp *newdims, \n\t\t\t intp *newstrides, int oldnd)\n{\n\tPyArray_Descr *old;\n\tint newnd;\n\tint numnew;\n\tintp *mydim;\n\tint i;\n\t\n\told = *des;\n\t*des = old->subarray->base;\n\n\tmydim = newdims + oldnd;\n\tif (PyTuple_Check(old->subarray->shape)) {\n\t\tnumnew = PyTuple_GET_SIZE(old->subarray->shape);\n\t\t\n\t\tfor (i=0; isubarray->shape, i));\n\t\t}\n\t}\n\telse {\n\t\tnumnew = 1;\n\t\tmydim[0] = (intp) PyInt_AsLong(old->subarray->shape);\n\t}\n\t\n\tnewnd = oldnd + numnew;\n\n\tif (newstrides) {\n\t\tintp tempsize;\n\t\tintp *mystrides;\n\t\tmystrides = newstrides + oldnd;\n\t\t/* Make new strides */\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\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{\t\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\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);\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\t\n\tself = (PyArrayObject *) subtype->tp_alloc(subtype, 0);\n\tif (self == NULL) {\n\t\tPy_DECREF(descr);\n\t\treturn NULL;\t\n\t}\n\tself->nd = nd;\n\tself->dimensions = NULL;\n\tself->data = NULL;\n\tif (data == NULL) { /* strides is NULL too */\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\t\t\n\tsd = descr->elsize;\n\tself->descr = descr;\n\tself->base = (PyObject *)NULL;\n self->weakreflist = (PyObject *)NULL;\n\t\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 {\n\t\t\tif (data == NULL) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"if 'strides' is given in \" \\\n\t\t\t\t\t\t\"array creation, data must \" \\\n\t\t\t\t\t\t\"be given too\");\n\t\t\t\tgoto fail;\n\t\t\t} \n\t\t\tmemcpy(self->strides, strides, sizeof(intp)*nd);\n\t\t}\n\t} \t\n\t\t\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\t\tif (descr == &OBJECT_Descr) {\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 and some object passed in */\n\tif ((obj != NULL) && (subtype != &PyArray_Type) && \n\t (subtype != &PyBigArray_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 (!(self->flags & OWNDATA)) { /* did not allocate own data */\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\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\t\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*/\nstatic PyObject * \nPyArray_Resize(PyArrayObject *self, PyArray_Dims *newshape)\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\t\n if (!PyArray_ISCONTIGUOUS(self)) {\n PyErr_SetString(PyExc_ValueError, \n \"resize only works on contiguous arrays\");\n return NULL;\n }\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\t\t\n\t\trefcnt = REFCOUNT(self);\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\t\t\t\t\n\t\tif (newsize == 0) sd = self->descr->elsize;\t\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 0, &(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);\t\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);\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\twhile (size--) {\n\t\t\tcopyswap(toptr, fromptr, swap, itemsize);\n\t\t\ttoptr += itemsize;\n\t\t}\n\t}\n\telse {\n\t\tPyArrayIterObject *iter;\n\t\t\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, itemsize);\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\", \n\t\t\t\t \"offset\", \"strides\",\n\t\t\t\t \"fortran\", 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\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*/\t\n\n\tif (!PyArg_ParseTupleAndKeywords(args, kwds, \"O&|O&O&LO&i\",\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 &fortran)) \n\t\tgoto fail;\n\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 if (dims.ptr == NULL) {\n PyErr_SetString(PyExc_ValueError, \"need to give a \"\\\n \"valid shape as the first argument\");\n goto fail;\n }\n\n if (buffer.ptr == NULL) {\n ret = (PyArrayObject *)\\\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 NULL, 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\t\tbuffer.len -= offset;\n\t\tbuffer.ptr += offset;\n if (dims.len == 1 && dims.ptr[0] == -1) {\n dims.ptr[0] = buffer.len / itemsize;\n }\n else if (buffer.len < itemsize* \\\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 (strides.ptr != NULL) {\n\t\t\tif (strides.len != dims.len) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides, if given, must be \"\\\n\t\t\t\t\t\t\"the same length as shape\");\n\t\t\t\tgoto fail;\n\t\t\t}\n\t\t\tif (!PyArray_CheckStrides(itemsize, strides.len, \n\t\t\t\t\t\t buffer.len,\n\t\t\t\t\t\t dims.ptr, strides.ptr)) {\n\t\t\t\tPyErr_SetString(PyExc_ValueError, \n\t\t\t\t\t\t\"strides is incompatible \"\\\n\t\t\t\t\t\t\"with shape of requested\"\\\n\t\t\t\t\t\t\"array and size of buffer\");\n\t\t\t\tgoto fail;\n\t\t\t}\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 (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 PyObject_CallMethod(_numpy_internal, \"flagsobj\", \"Oii\", \n self, self->flags, 0);\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\tret = PyArray_Reshape(self, val);\n\tif (ret == NULL) return -1;\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;\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 != NULL) {\n\t\tif (PyArray_Check(new->base)) \n\t\t\tnew = (PyArrayObject *)new->base;\n\t}\n\tnumbytes = PyArray_MultiplyList(new->dimensions, \n\t\t\t\t\tnew->nd)*new->descr->elsize;\n\t\n\tif (!PyArray_CheckStrides(self->descr->elsize, self->nd, numbytes, \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 if (PyBigArray_CheckExact(self)) \n\t\treturn PyFloat_FromDouble(PyArray_BIG_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}\t\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 *\narray_typechar_get(PyArrayObject *self)\n{\n\tif PyArray_ISEXTENDED(self) \n\t\treturn PyString_FromFormat(\"%c%d\", (self->descr->type),\n\t\t\t\t\t self->descr->elsize);\n\telse \n\t\treturn PyString_FromStringAndSize(&(self->descr->type), 1);\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 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\t\n\tif (PyArray_ISCONTIGUOUS(self)) index = self->nd - 1;\n\telse index = 0;\n\t\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\t\n\telse if (newtype->elsize > self->descr->elsize) {\n\t\t\n\t\t/* Determine if last (or first if FORTRAN) dimension\n\t\t is compatible */\n\t\t\n\t\tnewdim = self->dimensions[index] * self->descr->elsize;\n\t\tif ((newdim % newtype->elsize) != 0) goto fail;\n\t\t\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\ttemp = (PyArrayObject *)\\\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\tPyDimMem_FREE(self->dimensions);\n\t\tself->dimensions = temp->dimensions;\n\t\tself->nd = temp->nd;\n\t\tself->strides = temp->strides;\n\t\tPy_DECREF(newtype);\n\t\tnewtype = temp->descr;\n\t\t/* Fool deallocator */\n\t\ttemp->nd = 0;\n\t\ttemp->dimensions = NULL;\n\t\ttemp->descr = NULL;\n\t\tPy_DECREF(temp);\n\t}\n\n\tself->descr = newtype; \n\tPyArray_UpdateFlags(self, UPDATE_ALL_FLAGS);\n\t\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\t\n\tres = PyObject_GetAttrString((PyObject *)self->descr, \"arrdescr\");\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_type_get(PyArrayObject *self)\n{\n Py_INCREF(self->descr->typeobj);\n return (PyObject *)self->descr->typeobj;\n}\n\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);\n\tif (new == NULL) return -1;\n\t\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) {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}\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{\t\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{\t\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); \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);\t\t\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));\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->descr->elsize);\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 {\"dtype\", \n\t (getter)array_type_get, \n\t NULL,\n\t \"get array type class\"},\n\t{\"dtypechar\",\n\t (getter)array_typechar_get,\n\t NULL,\n\t \"get array type character code\"},\n\t{\"dtypestr\",\n\t (getter)array_typestr_get,\n\t NULL,\n\t \"get array type string\"},\n\t{\"dtypedescr\", \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.dtypedescr object.\\n\\n\"\n\t\" No __init__ method is needed because the array is fully \\n\"\n\t\" initialized after the __new__ method.\";\n\t\nstatic PyTypeObject PyBigArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.bigndarray\",\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 NULL, \t\t\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\t\t\n (getattrofunc)0,\t\t\t /*tp_getattro*/\n (setattrofunc)0,\t\t\t /*tp_setattro*/\n NULL, \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/* A standard array will subclass from the Big Array and \n add the array_as_sequence table\n and the array_as_buffer table\n */\n\nstatic PyTypeObject PyArray_Type = { \n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /*ob_size*/\n \"numpy.ndarray\",\t\t\t /*tp_name*/\n sizeof(PyArrayObject),\t\t /*tp_basicsize*/\n 0,\t\t\t\t\t /*tp_itemsize*/\n};\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\t\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;\t\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\t\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, sizeof(Py_UNICODE)*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\t\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, 2*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\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\t\n\tif (minitype == NULL) \n\t\tminitype = PyArray_DescrFromType(PyArray_BOOL);\n\telse Py_INCREF(minitype);\n\t\n if (max < 0) goto deflt;\n\t\n if (PyArray_Check(op)) {\n\t\tchktype = PyArray_DESCR(op);\n\t\tPy_INCREF(chktype);\n\t\tgoto finish;\n\t}\n\t\n\tif (PyArray_IsScalar(op, Generic)) {\n\t\tchktype = PyArray_DescrFromScalar(op);\n\t\tgoto finish;\n\t}\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 \t\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\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\t\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\t\n\tif (PyBool_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_BOOL);\n\t\tgoto finish;\t\t\n\t}\n else if (PyInt_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_LONG);\n\t\tgoto finish;\n } else if (PyFloat_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_DOUBLE);\n\t\tgoto finish;\n\t} else if (PyComplex_Check(op)) {\n\t\tchktype = PyArray_DescrFromType(PyArray_CDOUBLE);\n\t\tgoto finish;\n\t}\n\n deflt:\n\tchktype = PyArray_DescrFromType(PyArray_OBJECT);\n\t\n finish:\n\t\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\t\n if (!PySequence_Check(v)) {\n PyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"assignment from non-sequence\");\n return -1;\n }\n\t\n l=PyObject_Length(v);\n if(l < 0) return -1; \n\t\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\t\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 *= sizeof(Py_UNICODE);\n\t}\n\n\tret = (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\n\tif (ret == NULL) return NULL;\n\n ret->descr->f->setitem(op, ret->data, ret);\n\t\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 unless return value is NULL*/\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\tPyArray_Descr *savetype=typecode;\n\t\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\t\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 return NULL;\n }\n\t\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 return NULL;\n }\n\t\n\tif(discover_dimensions(s,nd,d, !stop_at_string) == -1) {\n\t\treturn NULL;\n\t}\n\tif (itemsize == 0 && PyTypeNum_ISEXTENDED(type)) {\n\t\tif (discover_itemsize(s, nd, &itemsize) == -1) {\n\t\t\treturn NULL;\n\t\t}\n\t\tif (type == PyArray_UNICODE) itemsize*=sizeof(Py_UNICODE);\n\t}\n\n\tif (itemsize != typecode->elsize) {\n\t\tPyArray_DESCR_REPLACE(typecode);\n\t\ttypecode->elsize = itemsize;\n\t}\n\t\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\t\n if(!r) {Py_XINCREF(savetype); return NULL;}\n if(Assign_Array(r,s) == -1) {\n\t\tPy_XINCREF(savetype);\n\t\tPy_DECREF(r);\n\t\treturn NULL;\n\t}\n return (PyObject*)r;\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\t\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\t\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\t\t\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\t\n\toptr = (obuf) ? outbuffer: out->data;\n\tbptr = inbuffer;\n\tel = 0;\t\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, elsize);\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\t\t\t\t\n\t\t\t\tcastfunc(inbuffer, optr, el, in, out);\n\t\t\t\t\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 oelsize);\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);\t\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\t\t\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*sizeof(Py_UNICODE);\n\t\tif (mpd->type_num == PyArray_UNICODE &&\n\t\t at->type_num == PyArray_STRING) \n\t\t\tat->elsize = mpd->elsize/sizeof(Py_UNICODE);\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\t\n\tPy_DECREF(out);\n\treturn NULL;\n\t\n}\n\t \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\t\t\t\t\n\t}\n\n\tsimple = ((PyArray_ISCARRAY_RO(mp) && PyArray_ISCARRAY(out)) || \\\n (PyArray_ISFARRAY_RO(mp) && PyArray_ISFARRAY(out)));\n\t\n\tif (simple) {\n\t\tchar *inptr;\n\t\tchar *optr = out->data;\n\t\tintp obytes = out->descr->elsize * outsize;\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\t\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 */\nstatic PyObject *\narray_fromarray(PyArrayObject *arr, PyArray_Descr *newtype, int flags) \n{\n\t\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\t\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 (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\t\t\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 != &PyBigArray_Type)) {\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 (subtype != &PyBigArray_Type)) {\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\t\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 != &PyBigArray_Type)) {\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\t\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}\t\t\n\t\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;\t \n\t\telse _MY_FAIL \n\t\t\tbreak;\t\t \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;\t\t \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;\t\t \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\t\tbreak;\n\tcase 'S':\n\t\ttype_num = PyArray_STRING;\n\t\tbreak;\n\tcase 'U':\n\t\ttype_num = PyArray_UNICODE;\n\t\tsize *= sizeof(Py_UNICODE);\n\t\tbreak;\t \n\tcase 'V':\n\t\ttype_num = PyArray_VOID;\n\t\tbreak;\n\tdefault:\n\t\t_MY_FAIL\n\t}\n\t\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/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_fromstructinterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyArray_Descr *thetype;\n\tchar buf[40];\n\tPyArrayInterface *inter;\n\tPyObject *attr, *r, *ret;\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_XDECREF(intype);\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_XDECREF(intype);\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 ret = array_fromarray((PyArrayObject*)r, intype, flags);\n Py_DECREF(r);\n return ret;\n}\n\n/* steals a reference to intype unless NotImplemented */\nstatic PyObject *\narray_frominterface(PyObject *input, PyArray_Descr *intype, int flags)\n{\n\tPyObject *attr=NULL, *item=NULL, *r;\n PyObject *tstr=NULL, *shape=NULL; \n\tPyArrayObject *ret=NULL;\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\t\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\tPy_XDECREF(intype);\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\tPy_XDECREF(intype);\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\tr = array_fromarray(ret, intype, flags);\n\tPy_DECREF(ret);\n\treturn r;\n\n fail:\n\tPy_XDECREF(intype);\n\tPy_XDECREF(attr);\n\tPy_XDECREF(shape);\n\tPy_XDECREF(tstr);\n\treturn NULL;\n}\n\n/* steals a reference to typecode */\nstatic PyObject *\narray_fromattr(PyObject *op, PyArray_Descr *typecode, int flags) \n{\n PyObject *new, *r;\n\t \n if (typecode == NULL) {\n new = PyObject_CallMethod(op, \"__array__\", NULL);\n } else {\n\t\tPyObject *obj;\n\n\t\tif (PyTypeNum_ISEXTENDED(typecode->type_num)) {\n\t\t\tobj = PyString_FromFormat(\"%c%d\", typecode->type,\n\t\t\t\t\t\t typecode->elsize);\n\t\t}\n\t\telse { \n\t\t\tobj = (PyObject *)(typecode->typeobj); Py_INCREF(obj);\n\t\t}\n\t\tnew = PyObject_CallMethod(op, \"__array__\", \"N\", obj);\n }\n if (new == NULL) {Py_XDECREF(typecode); 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\t\tPy_DECREF(typecode);\n return NULL;\n }\n r = array_fromarray((PyArrayObject *)new, typecode, flags);\n Py_DECREF(new);\n return r;\n} \n\n/* Steals a reference to newtype --- which can be NULL */\nstatic PyObject *\narray_fromobject(PyObject *op, PyArray_Descr *newtype, int min_depth, \n\t\t int max_depth, int flags) \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 = array_fromarray((PyArrayObject *)op, newtype, flags);\n\telse if (PyArray_IsScalar(op, Generic)) {\n\t\tr = PyArray_FromScalar(op, newtype);\n\t}\n else if ((r = array_fromstructinterface(op, newtype, flags)) != \\\n\t\t Py_NotImplemented) {\n }\n else if ((r = array_frominterface(op, newtype, flags)) !=\t\\\n\t\t Py_NotImplemented) {\n\t}\n else if (PyObject_HasAttrString(op, \"__array__\")) {\n /* Code that returns the object to convert for a non\n\t\t multiarray input object from the __array__ attribute of the\n\t\t object. */\n r = array_fromattr(op, newtype, flags);\n }\n\telse {\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\t\t\t\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 PyErr_Clear();\n else\n seq = TRUE;\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\t\n\t/* Be sure we succeed here */\n\t\n if(!PyArray_Check(r)) {\n PyErr_SetString(PyExc_RuntimeError, \n\t\t\t\t\"internal error: array_fromobject \"\\\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\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_FromAny(PyObject *op, PyArray_Descr *descr, int min_depth, \n\t\tint max_depth, int requires) \n{\n\tif (requires & ENSURECOPY) {\n\t\trequires |= DEFAULT_FLAGS;\n\t}\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 array_fromobject(op, descr, min_depth, max_depth,\n \t\t\t\trequires);\t\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 or PyBigArray_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) || PyBigArray_CheckExact(op)) return op;\n \n if (PyArray_IsScalar(op, Generic)) {\n new = PyArray_FromScalar(op, NULL);\n Py_DECREF(op);\n return new;\n }\n new = PyArray_FROM_OF(op, ENSUREARRAY);\n Py_DECREF(op);\n return new;\n}\n\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 * sizeof(Py_UNICODE)\\\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.\t\t \n\t\t*/\n\t}\n\treturn ret;\n}\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\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\t\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\t\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\t\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/* 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\niter_length(PyArrayIterObject *self) \n{\n return (int) 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, itemsize);\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\t\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, itemsize);\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;\t\t\t\n\t\t}\n\t}\n\n\t/* Check for Integer or Slice */ \t\n\t\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, size);\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);\n\t\tif (obj == NULL) goto fail;\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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\t\t\t\t\t FORCECAST | ALIGNED);\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,\n\t\t\t\t itemsize);\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, itemsize);\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, itemsize);\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\t\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\t\n\tPy_INCREF(type);\n\tarrval = PyArray_FromAny(val, type, 0, 0, 0);\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, itemsize);\n\t\t}\n\t\tretval=0;\n\t\tgoto finish;\n\t}\n\n\t/* Check for Integer or Slice */\n\t\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, itemsize);\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, itemsize);\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);\n\t}\n\telse {\n\t\tPy_INCREF(ind);\n\t\tobj = ind;\n\t}\n\t\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_FromAny(obj, indtype, 0, 0, \n\t\t\t\t\t FORCECAST | BEHAVED_FLAGS);\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\t\n}\n\n\nstatic PyMappingMethods iter_as_mapping = {\n (inquiry)iter_length,\t\t /*mp_length*/\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;\t\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\t{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 0, /* 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/* 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/* 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);\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\t\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\"index objects are \" \\\n\t\t\t\t\t\t\t\"not broadcastable \" \\\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 sizeof(intp));\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\tPyArray_ITER_RESET(it);\n\t\t\tcopyswap(coord+i,it->dataptr, \n\t\t\t\t !PyArray_ISNOTSWAPPED(it->ao),\n\t\t\t\t sizeof(intp));\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 sizeof(intp));\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 sizeof(intp));\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\t\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\t \n\tif (mit->view) return;\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\n\tsub = PyObject_GetItem((PyObject *)arr, mit->indexobj);\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\t\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\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\t\t\tif (*indptr < 0) *indptr += dimsize;\n\t\t\tif (*indptr < 0 || *indptr >= 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) *indptr, (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);\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\t\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->view = 0;\n \tmit->index = 0;\n \tmit->ait = NULL;\n \tmit->subspace = NULL;\n\tmit->numiter = 0;\n\tmit->consec = 1;\n\tfancy = fancy_indexing_check(indexobj);\n\tPy_INCREF(indexobj);\n\tmit->indexobj = indexobj;\n\tif (fancy == SOBJ_NOTFANCY) { /* bail out */\n\t\tmit->view = 1;\n\t\tgoto ret;\n\t}\n\n\tif (fancy == SOBJ_BADARRAY) {\n\t\tPyErr_SetString(PyExc_IndexError,\t\t\t\\\n\t\t\t\t\"arrays used as indices must be of \" \\\n\t\t\t\t\"integer type\");\n\t\tgoto fail;\n\t}\n\tif (fancy == SOBJ_TOOMANY) {\n\t\tPyErr_SetString(PyExc_IndexError, \"too many indices\");\n\t\tgoto fail;\n\t}\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\t\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);\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 ret:\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\t\n\tint i, err=0;\n\t\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\t\n /* fprintf(stderr, \"multi new...\");*/\n multi = PyObject_New(PyArrayMultiIterObject, &PyArrayMultiIter_Type);\n if (multi == NULL)\n return NULL;\n\t\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);\t\n\t\n\tif (!err && PyArray_Broadcast(multi) < 0) err=1;\n\n\tif (err) {\n Py_DECREF(multi);\n\t\treturn NULL;\n\t}\n\t\n\tPyArray_MultiIter_RESET(multi);\n\t\n return (PyObject *)multi;\n}\n\nstatic PyObject *\narraymultiter_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)\n{\n\t\n\tint n, i;\n\tPyArrayMultiIterObject *multi;\n\tPyObject *arr;\n\t\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\t\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\t\n return (PyObject *)multi;\n\t\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\t_pya_free(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);\t\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 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/*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;\t\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(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 dtypedescr objects can be set. \n*/\nstatic PyMemberDef arraydescr_members[] = {\n\t{\"dtype\", 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\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\tchar basic_=self->kind;\n\tchar endian = self->byteorder;\n\t\n\tif (endian == '=') {\n\t\tendian = '<';\n\t\tif (!PyArray_IsNativeByteOrder(endian)) endian = '>';\n\t}\n\t\n\treturn PyString_FromFormat(\"%c%c%d\", endian, basic_,\n\t\t\t\t self->elsize);\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{\"subdescr\", \n\t (getter)arraydescr_subdescr_get,\n\t NULL,\n\t \"A tuple of (descr, shape) or None.\"},\n\t{\"arrdescr\",\n\t (getter)arraydescr_protocol_descr_get,\n\t NULL,\n\t \"The array_protocol type descriptor.\"},\n\t{\"dtypestr\",\n\t (getter)arraydescr_protocol_typestr_get,\n\t NULL,\n\t \"The array_protocol typestring.\"},\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\t\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\t\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, \"dtypedescr\");\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\tobj = PyString_FromFormat(\"%c%d\",self->kind, self->elsize);\n\t}\n\tPyTuple_SET_ITEM(ret, 1, Py_BuildValue(\"(Nii)\", obj, 0, 1));\n\t\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\t\n\tif (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\t\n\tif (fields != Py_None) {\n\t\tPy_XDECREF(self->fields);\n\t\tself->fields = fields;\n\t\tPy_INCREF(fields);\n\t}\n\t\n\tif (PyTypeNum_ISEXTENDED(self->type_num)) {\n\t\tself->elsize = elsize;\n\t\tself->alignment = alignment;\n\t}\n\t\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*/\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\t\t\t\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 dtypedescr 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 dtypedescr object.\";\n\nstatic PyObject *\narraydescr_newbyteorder(PyArray_Descr *self, PyObject *args) \n{\n\tchar endian=PyArray_SWAP;\n\t\n\tif (!PyArg_ParseTuple(args, \"|O&\", PyArray_ByteorderConverter,\n\t\t\t &endian)) return NULL;\n\t\t\t\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);\t\t\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(\"dtypedescr(\");\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 dtypedescr 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\nstatic PyTypeObject PyArrayDescr_Type = {\n PyObject_HEAD_INIT(NULL)\n 0,\t\t\t\t\t /* ob_size */\n \"numpy.dtypedescr\",\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 0, \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", + "methods": [ + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 19, + "token_count": 391, + "parameters": [ + "o" + ], + "start_line": 31, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 59, + "complexity": 19, + "token_count": 394, + "parameters": [ + "o" + ], + "start_line": 103, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 86, + "parameters": [ + "obj", + "default_" + ], + "start_line": 173, + "end_line": 191, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "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": 212, + "end_line": 240, + "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": 246, + "end_line": 275, + "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": 281, + "end_line": 331, + "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": 354, + "end_line": 385, + "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": 388, + "end_line": 422, + "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": 438, + "end_line": 460, + "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": 466, + "end_line": 487, + "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": 491, + "end_line": 529, + "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": 534, + "end_line": 554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "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": 562, + "end_line": 577, + "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": 583, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 607, + "end_line": 687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "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": 79, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 691, + "end_line": 705, + "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": 718, + "end_line": 744, + "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": 750, + "end_line": 764, + "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 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 772, + "end_line": 792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 11, + "token_count": 468, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 801, + "end_line": 883, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 899, + "end_line": 902, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 912, + "end_line": 934, + "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": 948, + "end_line": 988, + "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": 1003, + "end_line": 1044, + "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": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1051, + "end_line": 1142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "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": 1148, + "end_line": 1177, + "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": 1180, + "end_line": 1216, + "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": 1225, + "end_line": 1262, + "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": 1269, + "end_line": 1277, + "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": 1280, + "end_line": 1305, + "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 i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1308, + "end_line": 1311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 1315, + "end_line": 1350, + "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 i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1356, + "end_line": 1359, + "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": 1365, + "end_line": 1373, + "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": 1379, + "end_line": 1429, + "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": 1436, + "end_line": 1481, + "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": 1485, + "end_line": 1579, + "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": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1582, + "end_line": 1619, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1631, + "end_line": 1684, + "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": 53, + "complexity": 12, + "token_count": 380, + "parameters": [ + "mit", + "op" + ], + "start_line": 1687, + "end_line": 1747, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "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": 1750, + "end_line": 1777, + "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": 1780, + "end_line": 1799, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 28, + "token_count": 659, + "parameters": [ + "self", + "op" + ], + "start_line": 1823, + "end_line": 1938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 91, + "complexity": 28, + "token_count": 581, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 1953, + "end_line": 2055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2064, + "end_line": 2067, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , int * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2086, + "end_line": 2098, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2101, + "end_line": 2116, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2120, + "end_line": 2129, + "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 segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2132, + "end_line": 2143, + "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": 34, + "complexity": 1, + "token_count": 162, + "parameters": [ + "dict" + ], + "start_line": 2214, + "end_line": 2247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 2, + "token_count": 183, + "parameters": [], + "start_line": 2257, + "end_line": 2296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "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": 2299, + "end_line": 2322, + "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": 2326, + "end_line": 2349, + "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": 2353, + "end_line": 2360, + "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": 2363, + "end_line": 2370, + "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": 2373, + "end_line": 2381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 2384, + "end_line": 2387, + "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": 2390, + "end_line": 2393, + "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": 2396, + "end_line": 2399, + "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": 2402, + "end_line": 2405, + "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": 2408, + "end_line": 2411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2414, + "end_line": 2417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2420, + "end_line": 2423, + "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": 2426, + "end_line": 2429, + "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": 2432, + "end_line": 2435, + "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": 2438, + "end_line": 2441, + "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": 2444, + "end_line": 2447, + "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": 2450, + "end_line": 2453, + "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": 2456, + "end_line": 2459, + "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": 2462, + "end_line": 2465, + "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": 2468, + "end_line": 2471, + "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": 2474, + "end_line": 2477, + "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": 2480, + "end_line": 2483, + "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": 2486, + "end_line": 2489, + "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": 2492, + "end_line": 2495, + "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 * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2498, + "end_line": 2501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2504, + "end_line": 2507, + "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": 2510, + "end_line": 2513, + "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": 2516, + "end_line": 2519, + "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": 2522, + "end_line": 2525, + "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": 2528, + "end_line": 2531, + "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": 2534, + "end_line": 2537, + "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": 2540, + "end_line": 2543, + "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": 2546, + "end_line": 2550, + "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": 2553, + "end_line": 2557, + "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": 2561, + "end_line": 2579, + "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": 2582, + "end_line": 2599, + "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": 2604, + "end_line": 2619, + "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": 2623, + "end_line": 2649, + "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": 2652, + "end_line": 2677, + "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": 2680, + "end_line": 2702, + "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": 2705, + "end_line": 2727, + "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": 2730, + "end_line": 2752, + "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": 2755, + "end_line": 2759, + "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 ilow , int ihigh)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 11, + "token_count": 259, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 2820, + "end_line": 2860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , int ilow , int ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 2864, + "end_line": 2885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 2888, + "end_line": 2900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 2921, + "end_line": 2968, + "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": 2971, + "end_line": 3007, + "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": 3016, + "end_line": 3033, + "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": 3036, + "end_line": 3048, + "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": 3051, + "end_line": 3063, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_richcompare", + "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 13, + "token_count": 273, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3066, + "end_line": 3143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 164, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3146, + "end_line": 3175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 3181, + "end_line": 3201, + "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": 21, + "complexity": 7, + "token_count": 161, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3209, + "end_line": 3232, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 111, + "parameters": [ + "ap" + ], + "start_line": 3238, + "end_line": 3254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 109, + "parameters": [ + "ap" + ], + "start_line": 3258, + "end_line": 3274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 3277, + "end_line": 3294, + "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": 3297, + "end_line": 3330, + "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": 3337, + "end_line": 3364, + "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 * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 84, + "parameters": [ + "elsize", + "nd", + "numbytes", + "dims", + "newstrides" + ], + "start_line": 3373, + "end_line": 3388, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 3408, + "end_line": 3432, + "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": 3438, + "end_line": 3460, + "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)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 6, + "token_count": 229, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd" + ], + "start_line": 3464, + "end_line": 3506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 130, + "complexity": 26, + "token_count": 761, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3514, + "end_line": 3672, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 159, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", + "filename": "arrayobject.c", + "nloc": 82, + "complexity": 15, + "token_count": 497, + "parameters": [ + "self", + "newshape" + ], + "start_line": 3681, + "end_line": 3779, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "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": 3785, + "end_line": 3802, + "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": 41, + "complexity": 6, + "token_count": 229, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3806, + "end_line": 3848, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 19, + "token_count": 583, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 3851, + "end_line": 3970, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "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": 3974, + "end_line": 3982, + "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": 3988, + "end_line": 3991, + "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": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 3994, + "end_line": 3998, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 4001, + "end_line": 4004, + "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": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4008, + "end_line": 4037, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 4041, + "end_line": 4044, + "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": 36, + "complexity": 7, + "token_count": 231, + "parameters": [ + "self", + "obj" + ], + "start_line": 4047, + "end_line": 4085, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "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": 4089, + "end_line": 4096, + "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": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 4099, + "end_line": 4107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 4111, + "end_line": 4117, + "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": 4120, + "end_line": 4134, + "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": 4137, + "end_line": 4181, + "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": 4185, + "end_line": 4188, + "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": 4191, + "end_line": 4202, + "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": 4205, + "end_line": 4216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typechar_get", + "long_name": "array_typechar_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 4220, + "end_line": 4227, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 4232, + "end_line": 4235, + "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": 4238, + "end_line": 4242, + "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": 15, + "token_count": 443, + "parameters": [ + "self", + "arg" + ], + "start_line": 4256, + "end_line": 4341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "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": 4344, + "end_line": 4362, + "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": 4365, + "end_line": 4383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_type_get", + "long_name": "array_type_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4386, + "end_line": 4390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 4395, + "end_line": 4405, + "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": 4409, + "end_line": 4434, + "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": 32, + "complexity": 4, + "token_count": 189, + "parameters": [ + "self", + "val" + ], + "start_line": 4438, + "end_line": 4471, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "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": 4474, + "end_line": 4507, + "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": 205, + "parameters": [ + "self", + "val" + ], + "start_line": 4510, + "end_line": 4547, + "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": 4550, + "end_line": 4553, + "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": 346, + "parameters": [ + "self", + "val" + ], + "start_line": 4556, + "end_line": 4606, + "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": 4708, + "end_line": 4715, + "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": 4817, + "end_line": 4850, + "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": 161, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 4853, + "end_line": 4875, + "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": 4882, + "end_line": 4908, + "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": 4914, + "end_line": 4946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 120, + "complexity": 31, + "token_count": 691, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 4958, + "end_line": 5094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 137, + "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": 5097, + "end_line": 5120, + "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": 23, + "complexity": 6, + "token_count": 146, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5125, + "end_line": 5153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 21, + "token_count": 367, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5158, + "end_line": 5222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "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": 5229, + "end_line": 5238, + "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": 5244, + "end_line": 5337, + "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": 280, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5347, + "end_line": 5393, + "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": 5403, + "end_line": 5456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_fromarray", + "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 32, + "token_count": 673, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5460, + "end_line": 5589, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 505, + "parameters": [ + "str" + ], + "start_line": 5593, + "end_line": 5701, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "array_fromstructinterface", + "long_name": "array_fromstructinterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 6, + "token_count": 274, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5705, + "end_line": 5749, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_frominterface", + "long_name": "array_frominterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 134, + "complexity": 28, + "token_count": 839, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5753, + "end_line": 5896, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 144, + "top_nesting_level": 0 + }, + { + "name": "array_fromattr", + "long_name": "array_fromattr( PyObject * op , PyArray_Descr * typecode , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 178, + "parameters": [ + "op", + "typecode", + "flags" + ], + "start_line": 5900, + "end_line": 5930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "array_fromobject", + "long_name": "array_fromobject( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 17, + "token_count": 330, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags" + ], + "start_line": 5934, + "end_line": 6010, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 77, + "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": 6015, + "end_line": 6018, + "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": 6025, + "end_line": 6038, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 8, + "token_count": 117, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires" + ], + "start_line": 6084, + "end_line": 6103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 81, + "parameters": [ + "op" + ], + "start_line": 6116, + "end_line": 6132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 6140, + "end_line": 6228, + "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": 134, + "parameters": [ + "from", + "to" + ], + "start_line": 6233, + "end_line": 6261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 6274, + "end_line": 6312, + "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": 6320, + "end_line": 6337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "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": 6342, + "end_line": 6352, + "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": 6355, + "end_line": 6359, + "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": 16, + "parameters": [ + "self" + ], + "start_line": 6362, + "end_line": 6365, + "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": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6369, + "end_line": 6419, + "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": 6422, + "end_line": 6476, + "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": 664, + "parameters": [ + "self", + "ind" + ], + "start_line": 6480, + "end_line": 6613, + "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": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6617, + "end_line": 6649, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "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": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6652, + "end_line": 6694, + "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": 692, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 6697, + "end_line": 6831, + "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": 6844, + "end_line": 6889, + "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": 6894, + "end_line": 6898, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 6970, + "end_line": 7032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 104, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7040, + "end_line": 7056, + "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": 7063, + "end_line": 7132, + "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": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7136, + "end_line": 7173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7179, + "end_line": 7223, + "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": 99, + "complexity": 22, + "token_count": 670, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7241, + "end_line": 7371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 460, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7377, + "end_line": 7450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned)", + "filename": "arrayobject.c", + "nloc": 112, + "complexity": 25, + "token_count": 758, + "parameters": [ + "indexobj", + "oned" + ], + "start_line": 7453, + "end_line": 7588, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "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": 7592, + "end_line": 7601, + "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": 231, + "parameters": [ + "n" + ], + "start_line": 7672, + "end_line": 7721, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "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": 265, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 7724, + "end_line": 7769, + "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": 7772, + "end_line": 7791, + "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": 41, + "parameters": [ + "multi" + ], + "start_line": 7794, + "end_line": 7801, + "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": 7804, + "end_line": 7814, + "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": 7817, + "end_line": 7827, + "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": 7830, + "end_line": 7833, + "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": 7836, + "end_line": 7848, + "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": 7878, + "end_line": 7885, + "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": 7944, + "end_line": 7953, + "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": 7971, + "end_line": 7993, + "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": 64, + "parameters": [ + "self" + ], + "start_line": 7999, + "end_line": 8009, + "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": 8027, + "end_line": 8035, + "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": 11, + "complexity": 3, + "token_count": 60, + "parameters": [ + "self" + ], + "start_line": 8038, + "end_line": 8050, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 8053, + "end_line": 8072, + "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": 8079, + "end_line": 8086, + "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": 8089, + "end_line": 8096, + "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": 8099, + "end_line": 8106, + "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": 8142, + "end_line": 8194, + "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": 50, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "args" + ], + "start_line": 8200, + "end_line": 8257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8265, + "end_line": 8307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 8327, + "end_line": 8393, + "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": 8404, + "end_line": 8412, + "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": 8427, + "end_line": 8472, + "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": 8475, + "end_line": 8484, + "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": 8487, + "end_line": 8497, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyArray_PyIntAsIntp", + "long_name": "PyArray_PyIntAsIntp( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 19, + "token_count": 391, + "parameters": [ + "o" + ], + "start_line": 31, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 0 + }, + { + "name": "PyArray_PyIntAsInt", + "long_name": "PyArray_PyIntAsInt( PyObject * o)", + "filename": "arrayobject.c", + "nloc": 59, + "complexity": 19, + "token_count": 394, + "parameters": [ + "o" + ], + "start_line": 103, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetPriority", + "long_name": "PyArray_GetPriority( PyObject * obj , double default_)", + "filename": "arrayobject.c", + "nloc": 17, + "complexity": 5, + "token_count": 86, + "parameters": [ + "obj", + "default_" + ], + "start_line": 173, + "end_line": 191, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "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": 212, + "end_line": 240, + "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": 246, + "end_line": 275, + "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": 281, + "end_line": 331, + "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": 354, + "end_line": 385, + "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": 388, + "end_line": 422, + "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": 438, + "end_line": 460, + "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": 466, + "end_line": 487, + "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": 491, + "end_line": 529, + "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": 534, + "end_line": 554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "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": 562, + "end_line": 577, + "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": 583, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyArray_CopyInto", + "long_name": "PyArray_CopyInto( PyArrayObject * dest , PyArrayObject * src)", + "filename": "arrayobject.c", + "nloc": 71, + "complexity": 16, + "token_count": 435, + "parameters": [ + "dest", + "src" + ], + "start_line": 607, + "end_line": 687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 81, + "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": 79, + "parameters": [ + "dest", + "src_object" + ], + "start_line": 691, + "end_line": 705, + "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": 718, + "end_line": 744, + "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": 750, + "end_line": 764, + "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 , int fortran)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 4, + "token_count": 110, + "parameters": [ + "m1", + "fortran" + ], + "start_line": 772, + "end_line": 792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Scalar", + "long_name": "PyArray_Scalar( * data , PyArray_Descr * descr , PyObject * base)", + "filename": "arrayobject.c", + "nloc": 79, + "complexity": 11, + "token_count": 468, + "parameters": [ + "data", + "descr", + "base" + ], + "start_line": 801, + "end_line": 883, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 0 + }, + { + "name": "PyArray_ToScalar", + "long_name": "PyArray_ToScalar( * data , PyArrayObject * arr)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "data", + "arr" + ], + "start_line": 899, + "end_line": 902, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 912, + "end_line": 934, + "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": 948, + "end_line": 988, + "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": 1003, + "end_line": 1044, + "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": 89, + "complexity": 18, + "token_count": 595, + "parameters": [ + "self", + "fp", + "sep", + "format" + ], + "start_line": 1051, + "end_line": 1142, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 92, + "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": 1148, + "end_line": 1177, + "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": 1180, + "end_line": 1216, + "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": 1225, + "end_line": 1262, + "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": 1269, + "end_line": 1277, + "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": 1280, + "end_line": 1305, + "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 i)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "i" + ], + "start_line": 1308, + "end_line": 1311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 1315, + "end_line": 1350, + "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 i , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "i", + "v" + ], + "start_line": 1356, + "end_line": 1359, + "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": 1365, + "end_line": 1373, + "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": 1379, + "end_line": 1429, + "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": 1436, + "end_line": 1481, + "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": 1485, + "end_line": 1579, + "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": 26, + "complexity": 4, + "token_count": 176, + "parameters": [ + "mit", + "ret" + ], + "start_line": 1582, + "end_line": 1619, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetMap", + "long_name": "PyArray_GetMap( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 40, + "complexity": 8, + "token_count": 258, + "parameters": [ + "mit" + ], + "start_line": 1631, + "end_line": 1684, + "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": 53, + "complexity": 12, + "token_count": 380, + "parameters": [ + "mit", + "op" + ], + "start_line": 1687, + "end_line": 1747, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 61, + "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": 1750, + "end_line": 1777, + "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": 1780, + "end_line": 1799, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "array_subscript", + "long_name": "array_subscript( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 101, + "complexity": 28, + "token_count": 659, + "parameters": [ + "self", + "op" + ], + "start_line": 1823, + "end_line": 1938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 116, + "top_nesting_level": 0 + }, + { + "name": "array_ass_sub", + "long_name": "array_ass_sub( PyArrayObject * self , PyObject * index , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 91, + "complexity": 28, + "token_count": 581, + "parameters": [ + "self", + "index", + "op" + ], + "start_line": 1953, + "end_line": 2055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 103, + "top_nesting_level": 0 + }, + { + "name": "array_subscript_nice", + "long_name": "array_subscript_nice( PyArrayObject * self , PyObject * op)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "op" + ], + "start_line": 2064, + "end_line": 2067, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_getsegcount", + "long_name": "array_getsegcount( PyArrayObject * self , int * lenp)", + "filename": "arrayobject.c", + "nloc": 11, + "complexity": 4, + "token_count": 48, + "parameters": [ + "self", + "lenp" + ], + "start_line": 2086, + "end_line": 2098, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 15, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2101, + "end_line": 2116, + "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 segment , ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2120, + "end_line": 2129, + "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 segment , const char ** ptrptr)", + "filename": "arrayobject.c", + "nloc": 12, + "complexity": 3, + "token_count": 65, + "parameters": [ + "self", + "segment", + "ptrptr" + ], + "start_line": 2132, + "end_line": 2143, + "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": 34, + "complexity": 1, + "token_count": 162, + "parameters": [ + "dict" + ], + "start_line": 2214, + "end_line": 2247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 0 + }, + { + "name": "PyArray_GetNumericOps", + "long_name": "PyArray_GetNumericOps()", + "filename": "arrayobject.c", + "nloc": 39, + "complexity": 2, + "token_count": 183, + "parameters": [], + "start_line": 2257, + "end_line": 2296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "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": 2299, + "end_line": 2322, + "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": 2326, + "end_line": 2349, + "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": 2353, + "end_line": 2360, + "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": 2363, + "end_line": 2370, + "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": 2373, + "end_line": 2381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 2384, + "end_line": 2387, + "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": 2390, + "end_line": 2393, + "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": 2396, + "end_line": 2399, + "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": 2402, + "end_line": 2405, + "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": 2408, + "end_line": 2411, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "array_power", + "long_name": "array_power( PyArrayObject * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2414, + "end_line": 2417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2420, + "end_line": 2423, + "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": 2426, + "end_line": 2429, + "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": 2432, + "end_line": 2435, + "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": 2438, + "end_line": 2441, + "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": 2444, + "end_line": 2447, + "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": 2450, + "end_line": 2453, + "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": 2456, + "end_line": 2459, + "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": 2462, + "end_line": 2465, + "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": 2468, + "end_line": 2471, + "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": 2474, + "end_line": 2477, + "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": 2480, + "end_line": 2483, + "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": 2486, + "end_line": 2489, + "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": 2492, + "end_line": 2495, + "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 * m1 , PyObject * m2)", + "filename": "arrayobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 24, + "parameters": [ + "m1", + "m2" + ], + "start_line": 2498, + "end_line": 2501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 2504, + "end_line": 2507, + "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": 2510, + "end_line": 2513, + "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": 2516, + "end_line": 2519, + "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": 2522, + "end_line": 2525, + "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": 2528, + "end_line": 2531, + "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": 2534, + "end_line": 2537, + "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": 2540, + "end_line": 2543, + "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": 2546, + "end_line": 2550, + "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": 2553, + "end_line": 2557, + "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": 2561, + "end_line": 2579, + "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": 2582, + "end_line": 2599, + "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": 2604, + "end_line": 2619, + "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": 2623, + "end_line": 2649, + "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": 2652, + "end_line": 2677, + "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": 2680, + "end_line": 2702, + "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": 2705, + "end_line": 2727, + "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": 2730, + "end_line": 2752, + "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": 2755, + "end_line": 2759, + "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 ilow , int ihigh)", + "filename": "arrayobject.c", + "nloc": 36, + "complexity": 11, + "token_count": 259, + "parameters": [ + "self", + "ilow", + "ihigh" + ], + "start_line": 2820, + "end_line": 2860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 0 + }, + { + "name": "array_ass_slice", + "long_name": "array_ass_slice( PyArrayObject * self , int ilow , int ihigh , PyObject * v)", + "filename": "arrayobject.c", + "nloc": 20, + "complexity": 4, + "token_count": 108, + "parameters": [ + "self", + "ilow", + "ihigh", + "v" + ], + "start_line": 2864, + "end_line": 2885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "array_contains", + "long_name": "array_contains( PyArrayObject * self , PyObject * el)", + "filename": "arrayobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 66, + "parameters": [ + "self", + "el" + ], + "start_line": 2888, + "end_line": 2900, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 2921, + "end_line": 2968, + "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": 2971, + "end_line": 3007, + "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": 3016, + "end_line": 3033, + "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": 3036, + "end_line": 3048, + "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": 3051, + "end_line": 3063, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "array_richcompare", + "long_name": "array_richcompare( PyArrayObject * self , PyObject * other , int cmp_op)", + "filename": "arrayobject.c", + "nloc": 61, + "complexity": 13, + "token_count": 273, + "parameters": [ + "self", + "other", + "cmp_op" + ], + "start_line": 3066, + "end_line": 3143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "_check_axis", + "long_name": "_check_axis( PyArrayObject * arr , int * axis , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 8, + "token_count": 164, + "parameters": [ + "arr", + "axis", + "flags" + ], + "start_line": 3146, + "end_line": 3175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 3181, + "end_line": 3201, + "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": 21, + "complexity": 7, + "token_count": 161, + "parameters": [ + "seq", + "vals", + "maxvals" + ], + "start_line": 3209, + "end_line": 3232, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "_IsContiguous", + "long_name": "_IsContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 111, + "parameters": [ + "ap" + ], + "start_line": 3238, + "end_line": 3254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "_IsFortranContiguous", + "long_name": "_IsFortranContiguous( PyArrayObject * ap)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 6, + "token_count": 109, + "parameters": [ + "ap" + ], + "start_line": 3258, + "end_line": 3274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 3277, + "end_line": 3294, + "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": 3297, + "end_line": 3330, + "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": 3337, + "end_line": 3364, + "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 * dims , intp * newstrides)", + "filename": "arrayobject.c", + "nloc": 13, + "complexity": 4, + "token_count": 84, + "parameters": [ + "elsize", + "nd", + "numbytes", + "dims", + "newstrides" + ], + "start_line": 3373, + "end_line": 3388, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 3408, + "end_line": 3432, + "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": 3438, + "end_line": 3460, + "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)", + "filename": "arrayobject.c", + "nloc": 37, + "complexity": 6, + "token_count": 229, + "parameters": [ + "des", + "newdims", + "newstrides", + "oldnd" + ], + "start_line": 3464, + "end_line": 3506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 130, + "complexity": 26, + "token_count": 761, + "parameters": [ + "subtype", + "descr", + "nd", + "dims", + "strides", + "data", + "flags", + "obj" + ], + "start_line": 3514, + "end_line": 3672, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 159, + "top_nesting_level": 0 + }, + { + "name": "PyArray_Resize", + "long_name": "PyArray_Resize( PyArrayObject * self , PyArray_Dims * newshape)", + "filename": "arrayobject.c", + "nloc": 82, + "complexity": 15, + "token_count": 497, + "parameters": [ + "self", + "newshape" + ], + "start_line": 3681, + "end_line": 3779, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 99, + "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": 3785, + "end_line": 3802, + "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": 41, + "complexity": 6, + "token_count": 229, + "parameters": [ + "arr", + "obj" + ], + "start_line": 3806, + "end_line": 3848, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "top_nesting_level": 0 + }, + { + "name": "array_new", + "long_name": "array_new( PyTypeObject * subtype , PyObject * args , PyObject * kwds)", + "filename": "arrayobject.c", + "nloc": 103, + "complexity": 19, + "token_count": 583, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 3851, + "end_line": 3970, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 120, + "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": 3974, + "end_line": 3982, + "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": 3988, + "end_line": 3991, + "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": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 3994, + "end_line": 3998, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 4001, + "end_line": 4004, + "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": 27, + "complexity": 4, + "token_count": 183, + "parameters": [ + "self", + "val" + ], + "start_line": 4008, + "end_line": 4037, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "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": 4041, + "end_line": 4044, + "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": 36, + "complexity": 7, + "token_count": 231, + "parameters": [ + "self", + "obj" + ], + "start_line": 4047, + "end_line": 4085, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "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": 4089, + "end_line": 4096, + "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": 9, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 4099, + "end_line": 4107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "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": 4111, + "end_line": 4117, + "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": 4120, + "end_line": 4134, + "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": 4137, + "end_line": 4181, + "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": 4185, + "end_line": 4188, + "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": 4191, + "end_line": 4202, + "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": 4205, + "end_line": 4216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "array_typechar_get", + "long_name": "array_typechar_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 4220, + "end_line": 4227, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 4232, + "end_line": 4235, + "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": 4238, + "end_line": 4242, + "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": 15, + "token_count": 443, + "parameters": [ + "self", + "arg" + ], + "start_line": 4256, + "end_line": 4341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "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": 4344, + "end_line": 4362, + "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": 4365, + "end_line": 4383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "array_type_get", + "long_name": "array_type_get( PyArrayObject * self)", + "filename": "arrayobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self" + ], + "start_line": 4386, + "end_line": 4390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 4395, + "end_line": 4405, + "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": 4409, + "end_line": 4434, + "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": 32, + "complexity": 4, + "token_count": 189, + "parameters": [ + "self", + "val" + ], + "start_line": 4438, + "end_line": 4471, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "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": 4474, + "end_line": 4507, + "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": 205, + "parameters": [ + "self", + "val" + ], + "start_line": 4510, + "end_line": 4547, + "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": 4550, + "end_line": 4553, + "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": 346, + "parameters": [ + "self", + "val" + ], + "start_line": 4556, + "end_line": 4606, + "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": 4708, + "end_line": 4715, + "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": 4817, + "end_line": 4850, + "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": 161, + "parameters": [ + "s", + "nd", + "itemsize" + ], + "start_line": 4853, + "end_line": 4875, + "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": 4882, + "end_line": 4908, + "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": 4914, + "end_line": 4946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "_array_find_type", + "long_name": "_array_find_type( PyObject * op , PyArray_Descr * minitype , int max)", + "filename": "arrayobject.c", + "nloc": 120, + "complexity": 31, + "token_count": 691, + "parameters": [ + "op", + "minitype", + "max" + ], + "start_line": 4958, + "end_line": 5094, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 137, + "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": 5097, + "end_line": 5120, + "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": 23, + "complexity": 6, + "token_count": 146, + "parameters": [ + "op", + "typecode" + ], + "start_line": 5125, + "end_line": 5153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 21, + "token_count": 367, + "parameters": [ + "s", + "typecode", + "fortran", + "min_depth", + "max_depth" + ], + "start_line": 5158, + "end_line": 5222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 65, + "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": 5229, + "end_line": 5238, + "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": 5244, + "end_line": 5337, + "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": 280, + "parameters": [ + "mp", + "at", + "fortran" + ], + "start_line": 5347, + "end_line": 5393, + "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": 5403, + "end_line": 5456, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "array_fromarray", + "long_name": "array_fromarray( PyArrayObject * arr , PyArray_Descr * newtype , int flags)", + "filename": "arrayobject.c", + "nloc": 114, + "complexity": 32, + "token_count": 673, + "parameters": [ + "arr", + "newtype", + "flags" + ], + "start_line": 5460, + "end_line": 5589, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "_array_typedescr_fromstr", + "long_name": "_array_typedescr_fromstr( char * str)", + "filename": "arrayobject.c", + "nloc": 98, + "complexity": 36, + "token_count": 505, + "parameters": [ + "str" + ], + "start_line": 5593, + "end_line": 5701, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 0 + }, + { + "name": "array_fromstructinterface", + "long_name": "array_fromstructinterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 42, + "complexity": 6, + "token_count": 274, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5705, + "end_line": 5749, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "array_frominterface", + "long_name": "array_frominterface( PyObject * input , PyArray_Descr * intype , int flags)", + "filename": "arrayobject.c", + "nloc": 134, + "complexity": 28, + "token_count": 839, + "parameters": [ + "input", + "intype", + "flags" + ], + "start_line": 5753, + "end_line": 5896, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 144, + "top_nesting_level": 0 + }, + { + "name": "array_fromattr", + "long_name": "array_fromattr( PyObject * op , PyArray_Descr * typecode , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 178, + "parameters": [ + "op", + "typecode", + "flags" + ], + "start_line": 5900, + "end_line": 5930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "array_fromobject", + "long_name": "array_fromobject( PyObject * op , PyArray_Descr * newtype , int min_depth , int max_depth , int flags)", + "filename": "arrayobject.c", + "nloc": 56, + "complexity": 17, + "token_count": 330, + "parameters": [ + "op", + "newtype", + "min_depth", + "max_depth", + "flags" + ], + "start_line": 5934, + "end_line": 6010, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 77, + "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": 6015, + "end_line": 6018, + "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": 6025, + "end_line": 6038, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyArray_FromAny", + "long_name": "PyArray_FromAny( PyObject * op , PyArray_Descr * descr , int min_depth , int max_depth , int requires)", + "filename": "arrayobject.c", + "nloc": 19, + "complexity": 8, + "token_count": 117, + "parameters": [ + "op", + "descr", + "min_depth", + "max_depth", + "requires" + ], + "start_line": 6084, + "end_line": 6103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "PyArray_EnsureArray", + "long_name": "PyArray_EnsureArray( PyObject * op)", + "filename": "arrayobject.c", + "nloc": 14, + "complexity": 5, + "token_count": 81, + "parameters": [ + "op" + ], + "start_line": 6116, + "end_line": 6132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "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": 6140, + "end_line": 6228, + "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": 134, + "parameters": [ + "from", + "to" + ], + "start_line": 6233, + "end_line": 6261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "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": 6274, + "end_line": 6312, + "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": 6320, + "end_line": 6337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "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": 6342, + "end_line": 6352, + "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": 6355, + "end_line": 6359, + "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": 16, + "parameters": [ + "self" + ], + "start_line": 6362, + "end_line": 6365, + "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": 281, + "parameters": [ + "self", + "ind" + ], + "start_line": 6369, + "end_line": 6419, + "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": 6422, + "end_line": 6476, + "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": 664, + "parameters": [ + "self", + "ind" + ], + "start_line": 6480, + "end_line": 6613, + "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": 31, + "complexity": 5, + "token_count": 180, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6617, + "end_line": 6649, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "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": 282, + "parameters": [ + "self", + "ind", + "val", + "swap" + ], + "start_line": 6652, + "end_line": 6694, + "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": 692, + "parameters": [ + "self", + "ind", + "val" + ], + "start_line": 6697, + "end_line": 6831, + "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": 6844, + "end_line": 6889, + "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": 6894, + "end_line": 6898, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "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": 6970, + "end_line": 7032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 0 + }, + { + "name": "_convert_obj", + "long_name": "_convert_obj( PyObject * obj , PyArrayIterObject ** iter)", + "filename": "arrayobject.c", + "nloc": 16, + "complexity": 5, + "token_count": 104, + "parameters": [ + "obj", + "iter" + ], + "start_line": 7040, + "end_line": 7056, + "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": 7063, + "end_line": 7132, + "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": 35, + "complexity": 4, + "token_count": 263, + "parameters": [ + "mit" + ], + "start_line": 7136, + "end_line": 7173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNext", + "long_name": "PyArray_MapIterNext( PyArrayMapIterObject * mit)", + "filename": "arrayobject.c", + "nloc": 41, + "complexity": 6, + "token_count": 298, + "parameters": [ + "mit" + ], + "start_line": 7179, + "end_line": 7223, + "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": 99, + "complexity": 22, + "token_count": 670, + "parameters": [ + "mit", + "arr" + ], + "start_line": 7241, + "end_line": 7371, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 131, + "top_nesting_level": 0 + }, + { + "name": "_nonzero_indices", + "long_name": "_nonzero_indices( PyObject * myBool , PyArrayIterObject ** iters)", + "filename": "arrayobject.c", + "nloc": 60, + "complexity": 15, + "token_count": 460, + "parameters": [ + "myBool", + "iters" + ], + "start_line": 7377, + "end_line": 7450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 74, + "top_nesting_level": 0 + }, + { + "name": "PyArray_MapIterNew", + "long_name": "PyArray_MapIterNew( PyObject * indexobj , int oned)", + "filename": "arrayobject.c", + "nloc": 112, + "complexity": 25, + "token_count": 758, + "parameters": [ + "indexobj", + "oned" + ], + "start_line": 7453, + "end_line": 7588, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "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": 7592, + "end_line": 7601, + "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": 231, + "parameters": [ + "n" + ], + "start_line": 7672, + "end_line": 7721, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 50, + "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": 265, + "parameters": [ + "subtype", + "args", + "kwds" + ], + "start_line": 7724, + "end_line": 7769, + "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": 7772, + "end_line": 7791, + "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": 41, + "parameters": [ + "multi" + ], + "start_line": 7794, + "end_line": 7801, + "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": 7804, + "end_line": 7814, + "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": 7817, + "end_line": 7827, + "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": 7830, + "end_line": 7833, + "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": 7836, + "end_line": 7848, + "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": 7878, + "end_line": 7885, + "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": 7944, + "end_line": 7953, + "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": 7971, + "end_line": 7993, + "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": 64, + "parameters": [ + "self" + ], + "start_line": 7999, + "end_line": 8009, + "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": 8027, + "end_line": 8035, + "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": 11, + "complexity": 3, + "token_count": 60, + "parameters": [ + "self" + ], + "start_line": 8038, + "end_line": 8050, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "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": 8053, + "end_line": 8072, + "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": 8079, + "end_line": 8086, + "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": 8089, + "end_line": 8096, + "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": 8099, + "end_line": 8106, + "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": 8142, + "end_line": 8194, + "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": 50, + "complexity": 12, + "token_count": 377, + "parameters": [ + "self", + "args" + ], + "start_line": 8200, + "end_line": 8257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 58, + "top_nesting_level": 0 + }, + { + "name": "arraydescr_setstate", + "long_name": "arraydescr_setstate( PyArray_Descr * self , PyObject * args)", + "filename": "arrayobject.c", + "nloc": 35, + "complexity": 8, + "token_count": 260, + "parameters": [ + "self", + "args" + ], + "start_line": 8265, + "end_line": 8307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 43, + "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": 8327, + "end_line": 8393, + "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": 8404, + "end_line": 8412, + "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": 8427, + "end_line": 8472, + "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": 8475, + "end_line": 8484, + "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": 8487, + "end_line": 8497, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "array_fromattr", + "long_name": "array_fromattr( PyObject * op , PyArray_Descr * typecode , int flags)", + "filename": "arrayobject.c", + "nloc": 29, + "complexity": 5, + "token_count": 178, + "parameters": [ + "op", + "typecode", + "flags" + ], + "start_line": 5900, + "end_line": 5930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + } + ], + "nloc": 6783, + "complexity": 1443, + "token_count": 39882, + "diff_parsed": { + "added": [ + "\t\tPy_XDECREF(typecode);" + ], + "deleted": [ + "\t\tPy_DECREF(typecode);" + ] + } + }, + { + "old_path": "numpy/core/tests/test_multiarray.py", + "new_path": "numpy/core/tests/test_multiarray.py", + "filename": "test_multiarray.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -133,5 +133,12 @@ def subscript(x, i): x[i]\n self.failUnlessRaises(IndexError, subscript, a, (newaxis, 0))\n self.failUnlessRaises(IndexError, subscript, a, (newaxis,)*50)\n \n+class test_creation(ScipyTestCase):\n+ def check_from_attribute(self):\n+ class x(object):\n+ def __array__(self, dtype=None):\n+ pass\n+ self.failUnlessRaises(ValueError, array, x())\n+\n if __name__ == \"__main__\":\n ScipyTest('numpy.core.multiarray').run()\n", + "added_lines": 7, + "deleted_lines": 0, + "source_code": "\nfrom numpy.testing import *\nfrom numpy.core import *\n\nclass test_flags(ScipyTestCase):\n def setUp(self):\n self.a = arange(10)\n\n def check_writeable(self):\n mydict = locals()\n self.a.flags.writeable = False\n self.assertRaises(RuntimeError, runstring, 'self.a[0] = 3', mydict)\n self.a.flags.writeable = True\n self.a[0] = 5\n self.a[0] = 0\n\n def check_otherflags(self):\n assert_equal(self.a.flags.carray, True)\n assert_equal(self.a.flags.farray, False)\n assert_equal(self.a.flags.behaved, True)\n assert_equal(self.a.flags.fnc, False)\n assert_equal(self.a.flags.forc, True)\n assert_equal(self.a.flags.owndata, True)\n assert_equal(self.a.flags.writeable, True)\n assert_equal(self.a.flags.aligned, True)\n assert_equal(self.a.flags.updateifcopy, False)\n \n\nclass test_attributes(ScipyTestCase):\n def setUp(self):\n self.one = arange(10)\n self.two = arange(20).reshape(4,5)\n self.three = arange(60,dtype=float64).reshape(2,5,6)\n\n def check_attributes(self):\n assert_equal(self.one.shape, (10,))\n assert_equal(self.two.shape, (4,5))\n assert_equal(self.three.shape, (2,5,6))\n self.three.shape = (10,3,2)\n assert_equal(self.three.shape, (10,3,2))\n self.three.shape = (2,5,6)\n assert_equal(self.one.strides, (self.one.itemsize,))\n num = self.two.itemsize\n assert_equal(self.two.strides, (5*num, num))\n num = self.three.itemsize\n assert_equal(self.three.strides, (30*num, 6*num, num))\n assert_equal(self.one.ndim, 1)\n assert_equal(self.two.ndim, 2)\n assert_equal(self.three.ndim, 3)\n num = self.two.itemsize \n assert_equal(self.two.size, 20)\n assert_equal(self.two.nbytes, 20*num)\n assert_equal(self.two.itemsize, self.two.dtypedescr.itemsize)\n assert_equal(self.two.base, arange(20))\n\n def check_dtypeattr(self):\n assert_equal(self.one.dtype, int_)\n assert_equal(self.three.dtype, float_)\n assert_equal(self.one.dtypechar, 'l')\n assert_equal(self.three.dtypechar, 'd')\n self.failUnless(self.three.dtypestr[0] in '<>')\n assert_equal(self.one.dtypestr[1], 'i')\n assert_equal(self.three.dtypestr[1], 'f')\n\nclass test_dtypedescr(ScipyTestCase):\n def check_construction(self):\n d1 = dtypedescr('i4')\n assert_equal(d1, dtypedescr(int32))\n d2 = dtypedescr('f8')\n assert_equal(d2, dtypedescr(float64))\n \nclass test_zero_rank(ScipyTestCase):\n def setUp(self):\n self.d = array(0), array('x', object)\n \n def check_ellipsis_subscript(self):\n a,b = self.d\n self.failUnlessEqual(a[...], 0)\n self.failUnlessEqual(b[...], 'x')\n self.failUnless(type(a[...]) is a.dtype)\n self.failUnless(type(b[...]) is str)\n \n def check_empty_subscript(self):\n a,b = self.d\n self.failUnlessEqual(a[()], 0)\n self.failUnlessEqual(b[()], 'x')\n self.failUnless(type(a[()]) is a.dtype)\n\tself.failUnless(type(b[()]) is str)\n\n def check_invalid_subscript(self):\n a,b = self.d\n self.failUnlessRaises(IndexError, lambda x: x[0], a)\n self.failUnlessRaises(IndexError, lambda x: x[0], b)\n self.failUnlessRaises(IndexError, lambda x: x[array([], int)], a)\n self.failUnlessRaises(IndexError, lambda x: x[array([], int)], b)\n\n def check_ellipsis_subscript_assignment(self):\n a,b = self.d\n a[...] = 42\n self.failUnlessEqual(a, 42)\n b[...] = ''\n self.failUnlessEqual(b.item(), '')\n \n def check_empty_subscript_assignment(self):\n a,b = self.d\n a[()] = 42\n self.failUnlessEqual(a, 42)\n b[()] = ''\n self.failUnlessEqual(b.item(), '')\n\n def check_invalid_subscript_assignment(self):\n a,b = self.d\n def assign(x, i, v):\n x[i] = v\n self.failUnlessRaises(IndexError, assign, a, 0, 42)\n self.failUnlessRaises(IndexError, assign, b, 0, '')\n self.failUnlessRaises(TypeError, assign, a, (), '')\n\n def check_newaxis(self):\n a,b = self.d\n self.failUnlessEqual(a[newaxis].shape, (1,))\n self.failUnlessEqual(a[..., newaxis].shape, (1,))\n self.failUnlessEqual(a[newaxis, ...].shape, (1,))\n self.failUnlessEqual(a[..., newaxis].shape, (1,))\n self.failUnlessEqual(a[newaxis, ..., newaxis].shape, (1,1))\n self.failUnlessEqual(a[..., newaxis, newaxis].shape, (1,1))\n self.failUnlessEqual(a[newaxis, newaxis, ...].shape, (1,1))\n self.failUnlessEqual(a[(newaxis,)*10].shape, (1,)*10)\n\n def check_invalid_newaxis(self):\n a,b = self.d\n def subscript(x, i): x[i]\n self.failUnlessRaises(IndexError, subscript, a, (newaxis, 0))\n self.failUnlessRaises(IndexError, subscript, a, (newaxis,)*50)\n\nclass test_creation(ScipyTestCase):\n def check_from_attribute(self):\n class x(object):\n def __array__(self, dtype=None):\n pass\n self.failUnlessRaises(ValueError, array, x())\n\nif __name__ == \"__main__\":\n ScipyTest('numpy.core.multiarray').run()\n", + "source_code_before": "\nfrom numpy.testing import *\nfrom numpy.core import *\n\nclass test_flags(ScipyTestCase):\n def setUp(self):\n self.a = arange(10)\n\n def check_writeable(self):\n mydict = locals()\n self.a.flags.writeable = False\n self.assertRaises(RuntimeError, runstring, 'self.a[0] = 3', mydict)\n self.a.flags.writeable = True\n self.a[0] = 5\n self.a[0] = 0\n\n def check_otherflags(self):\n assert_equal(self.a.flags.carray, True)\n assert_equal(self.a.flags.farray, False)\n assert_equal(self.a.flags.behaved, True)\n assert_equal(self.a.flags.fnc, False)\n assert_equal(self.a.flags.forc, True)\n assert_equal(self.a.flags.owndata, True)\n assert_equal(self.a.flags.writeable, True)\n assert_equal(self.a.flags.aligned, True)\n assert_equal(self.a.flags.updateifcopy, False)\n \n\nclass test_attributes(ScipyTestCase):\n def setUp(self):\n self.one = arange(10)\n self.two = arange(20).reshape(4,5)\n self.three = arange(60,dtype=float64).reshape(2,5,6)\n\n def check_attributes(self):\n assert_equal(self.one.shape, (10,))\n assert_equal(self.two.shape, (4,5))\n assert_equal(self.three.shape, (2,5,6))\n self.three.shape = (10,3,2)\n assert_equal(self.three.shape, (10,3,2))\n self.three.shape = (2,5,6)\n assert_equal(self.one.strides, (self.one.itemsize,))\n num = self.two.itemsize\n assert_equal(self.two.strides, (5*num, num))\n num = self.three.itemsize\n assert_equal(self.three.strides, (30*num, 6*num, num))\n assert_equal(self.one.ndim, 1)\n assert_equal(self.two.ndim, 2)\n assert_equal(self.three.ndim, 3)\n num = self.two.itemsize \n assert_equal(self.two.size, 20)\n assert_equal(self.two.nbytes, 20*num)\n assert_equal(self.two.itemsize, self.two.dtypedescr.itemsize)\n assert_equal(self.two.base, arange(20))\n\n def check_dtypeattr(self):\n assert_equal(self.one.dtype, int_)\n assert_equal(self.three.dtype, float_)\n assert_equal(self.one.dtypechar, 'l')\n assert_equal(self.three.dtypechar, 'd')\n self.failUnless(self.three.dtypestr[0] in '<>')\n assert_equal(self.one.dtypestr[1], 'i')\n assert_equal(self.three.dtypestr[1], 'f')\n\nclass test_dtypedescr(ScipyTestCase):\n def check_construction(self):\n d1 = dtypedescr('i4')\n assert_equal(d1, dtypedescr(int32))\n d2 = dtypedescr('f8')\n assert_equal(d2, dtypedescr(float64))\n \nclass test_zero_rank(ScipyTestCase):\n def setUp(self):\n self.d = array(0), array('x', object)\n \n def check_ellipsis_subscript(self):\n a,b = self.d\n self.failUnlessEqual(a[...], 0)\n self.failUnlessEqual(b[...], 'x')\n self.failUnless(type(a[...]) is a.dtype)\n self.failUnless(type(b[...]) is str)\n \n def check_empty_subscript(self):\n a,b = self.d\n self.failUnlessEqual(a[()], 0)\n self.failUnlessEqual(b[()], 'x')\n self.failUnless(type(a[()]) is a.dtype)\n\tself.failUnless(type(b[()]) is str)\n\n def check_invalid_subscript(self):\n a,b = self.d\n self.failUnlessRaises(IndexError, lambda x: x[0], a)\n self.failUnlessRaises(IndexError, lambda x: x[0], b)\n self.failUnlessRaises(IndexError, lambda x: x[array([], int)], a)\n self.failUnlessRaises(IndexError, lambda x: x[array([], int)], b)\n\n def check_ellipsis_subscript_assignment(self):\n a,b = self.d\n a[...] = 42\n self.failUnlessEqual(a, 42)\n b[...] = ''\n self.failUnlessEqual(b.item(), '')\n \n def check_empty_subscript_assignment(self):\n a,b = self.d\n a[()] = 42\n self.failUnlessEqual(a, 42)\n b[()] = ''\n self.failUnlessEqual(b.item(), '')\n\n def check_invalid_subscript_assignment(self):\n a,b = self.d\n def assign(x, i, v):\n x[i] = v\n self.failUnlessRaises(IndexError, assign, a, 0, 42)\n self.failUnlessRaises(IndexError, assign, b, 0, '')\n self.failUnlessRaises(TypeError, assign, a, (), '')\n\n def check_newaxis(self):\n a,b = self.d\n self.failUnlessEqual(a[newaxis].shape, (1,))\n self.failUnlessEqual(a[..., newaxis].shape, (1,))\n self.failUnlessEqual(a[newaxis, ...].shape, (1,))\n self.failUnlessEqual(a[..., newaxis].shape, (1,))\n self.failUnlessEqual(a[newaxis, ..., newaxis].shape, (1,1))\n self.failUnlessEqual(a[..., newaxis, newaxis].shape, (1,1))\n self.failUnlessEqual(a[newaxis, newaxis, ...].shape, (1,1))\n self.failUnlessEqual(a[(newaxis,)*10].shape, (1,)*10)\n\n def check_invalid_newaxis(self):\n a,b = self.d\n def subscript(x, i): x[i]\n self.failUnlessRaises(IndexError, subscript, a, (newaxis, 0))\n self.failUnlessRaises(IndexError, subscript, a, (newaxis,)*50)\n\nif __name__ == \"__main__\":\n ScipyTest('numpy.core.multiarray').run()\n", + "methods": [ + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_multiarray.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 6, + "end_line": 7, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_writeable", + "long_name": "check_writeable( self )", + "filename": "test_multiarray.py", + "nloc": 7, + "complexity": 1, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9, + "end_line": 15, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_otherflags", + "long_name": "check_otherflags( self )", + "filename": "test_multiarray.py", + "nloc": 10, + "complexity": 1, + "token_count": 113, + "parameters": [ + "self" + ], + "start_line": 17, + "end_line": 26, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_multiarray.py", + "nloc": 4, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 30, + "end_line": 33, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "check_attributes", + "long_name": "check_attributes( self )", + "filename": "test_multiarray.py", + "nloc": 20, + "complexity": 1, + "token_count": 245, + "parameters": [ + "self" + ], + "start_line": 35, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "check_dtypeattr", + "long_name": "check_dtypeattr( self )", + "filename": "test_multiarray.py", + "nloc": 8, + "complexity": 1, + "token_count": 86, + "parameters": [ + "self" + ], + "start_line": 56, + "end_line": 63, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_construction", + "long_name": "check_construction( self )", + "filename": "test_multiarray.py", + "nloc": 5, + "complexity": 1, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 66, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_multiarray.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 73, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_ellipsis_subscript", + "long_name": "check_ellipsis_subscript( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 64, + "parameters": [ + "self" + ], + "start_line": 76, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_empty_subscript", + "long_name": "check_empty_subscript( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 83, + "end_line": 88, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_invalid_subscript", + "long_name": "check_invalid_subscript( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 88, + "parameters": [ + "self" + ], + "start_line": 90, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_ellipsis_subscript_assignment", + "long_name": "check_ellipsis_subscript_assignment( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 97, + "end_line": 102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_empty_subscript_assignment", + "long_name": "check_empty_subscript_assignment( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 104, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_invalid_subscript_assignment.assign", + "long_name": "check_invalid_subscript_assignment.assign( x , i , v )", + "filename": "test_multiarray.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "x", + "i", + "v" + ], + "start_line": 113, + "end_line": 114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 2 + }, + { + "name": "check_invalid_subscript_assignment", + "long_name": "check_invalid_subscript_assignment( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 111, + "end_line": 117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_newaxis", + "long_name": "check_newaxis( self )", + "filename": "test_multiarray.py", + "nloc": 10, + "complexity": 1, + "token_count": 168, + "parameters": [ + "self" + ], + "start_line": 119, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "check_invalid_newaxis.subscript", + "long_name": "check_invalid_newaxis.subscript( x , i )", + "filename": "test_multiarray.py", + "nloc": 3, + "complexity": 1, + "token_count": 44, + "parameters": [ + "x", + "i" + ], + "start_line": 132, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 2 + }, + { + "name": "check_from_attribute.__array__", + "long_name": "check_from_attribute.__array__( self , dtype = None )", + "filename": "test_multiarray.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "dtype" + ], + "start_line": 139, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 3 + }, + { + "name": "check_from_attribute", + "long_name": "check_from_attribute( self )", + "filename": "test_multiarray.py", + "nloc": 4, + "complexity": 1, + "token_count": 25, + "parameters": [ + "self" + ], + "start_line": 137, + "end_line": 141, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_multiarray.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 6, + "end_line": 7, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_writeable", + "long_name": "check_writeable( self )", + "filename": "test_multiarray.py", + "nloc": 7, + "complexity": 1, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 9, + "end_line": 15, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_otherflags", + "long_name": "check_otherflags( self )", + "filename": "test_multiarray.py", + "nloc": 10, + "complexity": 1, + "token_count": 113, + "parameters": [ + "self" + ], + "start_line": 17, + "end_line": 26, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_multiarray.py", + "nloc": 4, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 30, + "end_line": 33, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "check_attributes", + "long_name": "check_attributes( self )", + "filename": "test_multiarray.py", + "nloc": 20, + "complexity": 1, + "token_count": 245, + "parameters": [ + "self" + ], + "start_line": 35, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "check_dtypeattr", + "long_name": "check_dtypeattr( self )", + "filename": "test_multiarray.py", + "nloc": 8, + "complexity": 1, + "token_count": 86, + "parameters": [ + "self" + ], + "start_line": 56, + "end_line": 63, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_construction", + "long_name": "check_construction( self )", + "filename": "test_multiarray.py", + "nloc": 5, + "complexity": 1, + "token_count": 35, + "parameters": [ + "self" + ], + "start_line": 66, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_multiarray.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 73, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_ellipsis_subscript", + "long_name": "check_ellipsis_subscript( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 64, + "parameters": [ + "self" + ], + "start_line": 76, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_empty_subscript", + "long_name": "check_empty_subscript( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 68, + "parameters": [ + "self" + ], + "start_line": 83, + "end_line": 88, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_invalid_subscript", + "long_name": "check_invalid_subscript( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 88, + "parameters": [ + "self" + ], + "start_line": 90, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_ellipsis_subscript_assignment", + "long_name": "check_ellipsis_subscript_assignment( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 44, + "parameters": [ + "self" + ], + "start_line": 97, + "end_line": 102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_empty_subscript_assignment", + "long_name": "check_empty_subscript_assignment( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self" + ], + "start_line": 104, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "check_invalid_subscript_assignment.assign", + "long_name": "check_invalid_subscript_assignment.assign( x , i , v )", + "filename": "test_multiarray.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "x", + "i", + "v" + ], + "start_line": 113, + "end_line": 114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 2 + }, + { + "name": "check_invalid_subscript_assignment", + "long_name": "check_invalid_subscript_assignment( self )", + "filename": "test_multiarray.py", + "nloc": 6, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 111, + "end_line": 117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_newaxis", + "long_name": "check_newaxis( self )", + "filename": "test_multiarray.py", + "nloc": 10, + "complexity": 1, + "token_count": 168, + "parameters": [ + "self" + ], + "start_line": 119, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "check_invalid_newaxis.subscript", + "long_name": "check_invalid_newaxis.subscript( x , i )", + "filename": "test_multiarray.py", + "nloc": 3, + "complexity": 1, + "token_count": 44, + "parameters": [ + "x", + "i" + ], + "start_line": 132, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 2 + } + ], + "changed_methods": [ + { + "name": "check_from_attribute.__array__", + "long_name": "check_from_attribute.__array__( self , dtype = None )", + "filename": "test_multiarray.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "dtype" + ], + "start_line": 139, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 3 + }, + { + "name": "check_from_attribute", + "long_name": "check_from_attribute( self )", + "filename": "test_multiarray.py", + "nloc": 4, + "complexity": 1, + "token_count": 25, + "parameters": [ + "self" + ], + "start_line": 137, + "end_line": 141, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + } + ], + "nloc": 124, + "complexity": 19, + "token_count": 1329, + "diff_parsed": { + "added": [ + "class test_creation(ScipyTestCase):", + " def check_from_attribute(self):", + " class x(object):", + " def __array__(self, dtype=None):", + " pass", + " self.failUnlessRaises(ValueError, array, x())", + "" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "c5d8aaf28f1fad0baf3b9d8c867b66872f2c0f25", + "msg": "Remove expm1 and log1p from C99 defs.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-14T03:16:53+00:00", + "author_timezone": 0, + "committer_date": "2006-01-14T03:16:53+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "f64c19f720420b7ad0a10355864dc1f69364ef26" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/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/umathmodule.c.src", + "new_path": "numpy/core/src/umathmodule.c.src", + "filename": "umathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -301,7 +301,7 @@ double hypot(double x, double y)\n \n /**begin repeat\n \n-#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan,log1p,expm1)*2#\n+#kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan)*2#\n #typ=longdouble*18, float*18#\n #c=l*18,f*18#\n #TYPE=LONGDOUBLE*18, FLOAT*18#\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "/* -*- c -*- */\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#define _UMATHMODULE\n#include \"numpy/ufuncobject.h\"\n#include \"abstract.h\"\n#include \n\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\nfloat log1pf(float);\nfloat logf(float);\nfloat sqrtf(float);\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\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\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\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\nlongdouble logl(longdouble);\nlongdouble sqrtl(longdouble);\nlongdouble log1pl(longdouble);\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\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\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n#else\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\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\ndouble 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\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\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)*2#\n#typ=longdouble*18, float*18#\n#c=l*18,f*18#\n#TYPE=LONGDOUBLE*18, FLOAT*18#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\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@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@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)\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)\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)\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)\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\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@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\t}\n\telse if (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n\t}\n\telse {\n\t\tnc_log@c@(a, r);\n\t\tnc_prod@c@(r, b, r);\n\t\tnc_exp@c@(r, r);\n\t}\n\treturn;\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; i> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n\t/* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>32) || (y>>32) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>64) || (y>>64) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n\treturn 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n\tulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n\tif (a0 < 0) { a = -a0; } else { a = a0; }\n\tif (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n\tah = (a >> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n /*\n\t ulonglong c = ((x + y)<<32) + w;\n\t if ((a0 < 0) ^ (b0 < 0))\n\t *c = -c;\n\t else\n\t *c = c\n\t */\n\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>31) || (y>>31) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>63) || (y>>63) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n\treturn 0;\n#endif\n}\n\n/** end direct numarray code **/\n\nstatic void\nBOOL_multiply(char **args, intp *dimensions, intp *steps, void *func) {\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 MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nULONGLONG_multiply(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\tulonglong temp;\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\telse if (temp < MIN_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nLONGLONG_multiply(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\tlonglong temp;\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=fmod*10, 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\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\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 memcpy(op, i1, sizeof(@typ@));\n else\n memcpy(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\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\nfloat log1pf(float);\nfloat logf(float);\nfloat sqrtf(float);\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\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\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\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\nlongdouble logl(longdouble);\nlongdouble sqrtl(longdouble);\nlongdouble log1pl(longdouble);\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\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\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n#else\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\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\ndouble 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\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\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,log1p,expm1)*2#\n#typ=longdouble*18, float*18#\n#c=l*18,f*18#\n#TYPE=LONGDOUBLE*18, FLOAT*18#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\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@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@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)\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)\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)\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)\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\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@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\t}\n\telse if (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n\t}\n\telse {\n\t\tnc_log@c@(a, r);\n\t\tnc_prod@c@(r, b, r);\n\t\tnc_exp@c@(r, r);\n\t}\n\treturn;\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; i> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n\t/* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>32) || (y>>32) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>64) || (y>>64) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n\treturn 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n\tulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n\tif (a0 < 0) { a = -a0; } else { a = a0; }\n\tif (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n\tah = (a >> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n /*\n\t ulonglong c = ((x + y)<<32) + w;\n\t if ((a0 < 0) ^ (b0 < 0))\n\t *c = -c;\n\t else\n\t *c = c\n\t */\n\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>31) || (y>>31) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>63) || (y>>63) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n\treturn 0;\n#endif\n}\n\n/** end direct numarray code **/\n\nstatic void\nBOOL_multiply(char **args, intp *dimensions, intp *steps, void *func) {\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 MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nULONGLONG_multiply(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\tulonglong temp;\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\telse if (temp < MIN_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nLONGLONG_multiply(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\tlonglong temp;\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=fmod*10, 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\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\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 memcpy(op, i1, sizeof(@typ@));\n else\n memcpy(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 b\"\n def __init__(self, y1, y2):\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n self.y1 = y1\n self.y2 = y2\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.logical_or(umath.greater (x, self.y2),\n umath.less(x, self.y1)\n )\n\nclass domain_tan:\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n def __init__(self, eps):\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n self.eps = eps\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less(umath.absolute(umath.cos(x)), self.eps)\n\nclass domain_greater:\n \"domain_greater(v)(x) = true where x <= v\"\n def __init__(self, critical_value):\n \"domain_greater(v)(x) = true where x <= v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less_equal (x, self.critical_value)\n\nclass domain_greater_equal:\n \"domain_greater_equal(v)(x) = true where x < v\"\n def __init__(self, critical_value):\n \"domain_greater_equal(v)(x) = true where x < v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less (x, self.critical_value)\n\nclass masked_unary_operation:\n def __init__ (self, aufunc, fill=0, domain=None):\n \"\"\" masked_unary_operation(aufunc, fill=0, domain=None)\n aufunc(fill) must be defined\n self(x) returns aufunc(x)\n with masked values where domain(x) is true or getmask(x) is true.\n \"\"\"\n self.f = aufunc\n self.fill = fill\n self.domain = domain\n self.__doc__ = getattr(aufunc, \"__doc__\", str(aufunc))\n\n def __call__ (self, a, *args, **kwargs):\n \"Execute the call behavior.\"\n# numeric tries to return scalars rather than arrays when given scalars.\n m = getmask(a)\n d1 = filled(a, self.fill)\n if self.domain is not None:\n m = mask_or(m, self.domain(d1))\n result = self.f(d1, *args, **kwargs)\n if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\n\nclass domain_safe_divide:\n def __init__ (self, tolerance=divide_tolerance):\n self.tolerance = tolerance\n def __call__ (self, a, b):\n return umath.absolute(a) * self.tolerance >= umath.absolute(b)\n\nclass domained_binary_operation:\n \"\"\"Binary operations that have a domain, like divide. These are complicated so they\n are a separate class. They have no reduce, outer or accumulate.\n \"\"\"\n def __init__ (self, abfunc, domain, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.domain = domain\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__(self, a, b):\n \"Execute the call behavior.\"\n ma = getmask(a)\n mb = getmask(b)\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n t = self.domain(d1, d2)\n\n if oldnumeric.sometrue(t, None):\n d2 = where(t, self.filly, d2)\n mb = mask_or(mb, t)\n m = mask_or(ma, mb)\n result = self.f(d1, d2)\n if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n \n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nclass masked_binary_operation:\n def __init__ (self, abfunc, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__ (self, a, b, *args, **kwargs):\n \"Execute the call behavior.\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n result = self.f(d1, d2, *args, **kwargs)\n if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis with this function.\"\"\"\n m = getmask(target)\n t = filled(target, self.filly)\n if t.shape == ():\n t = t.reshape(1)\n if m is not nomask:\n m = make_mask(m, copy=1)\n m.shape = (1,)\n if m is nomask:\n return masked_array (self.f.reduce (t, axis))\n else:\n t = masked_array (t, m)\n t = self.f.reduce(filled(t, self.filly), axis)\n m = umath.logical_and.reduce(m, axis)\n if isinstance(t, ndarray):\n return masked_array(t, m, get_fill_value(target))\n elif m:\n return masked\n else:\n return t\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = self.f.outer(filled(a, self.fillx), filled(b, self.filly))\n return masked_array(d, m)\n\n def accumulate (self, target, axis=0):\n \"\"\"Accumulate target along axis after filling with y fill value.\"\"\"\n t = filled(target, self.filly)\n return masked_array (self.f.accumulate (t, axis))\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nsqrt = masked_unary_operation(umath.sqrt, 0.0, domain_greater_equal(0.0))\nlog = masked_unary_operation(umath.log, 1.0, domain_greater(0.0))\nlog10 = masked_unary_operation(umath.log10, 1.0, domain_greater(0.0))\nexp = masked_unary_operation(umath.exp)\nconjugate = masked_unary_operation(umath.conjugate)\nsin = masked_unary_operation(umath.sin)\ncos = masked_unary_operation(umath.cos)\ntan = masked_unary_operation(umath.tan, 0.0, domain_tan(1.e-35))\narcsin = masked_unary_operation(umath.arcsin, 0.0, domain_check_interval(-1.0, 1.0))\narccos = masked_unary_operation(umath.arccos, 0.0, domain_check_interval(-1.0, 1.0))\narctan = masked_unary_operation(umath.arctan)\n# Missing from numeric\narcsinh = masked_unary_operation(umath.arcsinh)\narccosh = masked_unary_operation(umath.arccosh)\narctanh = masked_unary_operation(umath.arctanh)\nsinh = masked_unary_operation(umath.sinh)\ncosh = masked_unary_operation(umath.cosh)\ntanh = masked_unary_operation(umath.tanh)\nabsolute = masked_unary_operation(umath.absolute)\nfabs = masked_unary_operation(umath.fabs)\nnegative = masked_unary_operation(umath.negative)\nnonzero = masked_unary_operation(oldnumeric.nonzero)\naround = masked_unary_operation(oldnumeric.round_)\nfloor = masked_unary_operation(umath.floor)\nceil = masked_unary_operation(umath.ceil)\nsometrue = masked_unary_operation(oldnumeric.sometrue)\nalltrue = masked_unary_operation(oldnumeric.alltrue, 1)\nlogical_not = masked_unary_operation(umath.logical_not)\n\nadd = masked_binary_operation(umath.add)\nsubtract = masked_binary_operation(umath.subtract)\nsubtract.reduce = None\nmultiply = masked_binary_operation(umath.multiply, 1, 1)\ndivide = domained_binary_operation(umath.divide, domain_safe_divide(), 0, 1)\ntrue_divide = domained_binary_operation(umath.true_divide, domain_safe_divide(), 0, 1)\nfloor_divide = domained_binary_operation(umath.floor_divide, domain_safe_divide(), 0, 1)\nremainder = domained_binary_operation(umath.remainder, domain_safe_divide(), 0, 1)\nfmod = domained_binary_operation(umath.fmod, domain_safe_divide(), 0, 1)\nhypot = masked_binary_operation(umath.hypot)\narctan2 = masked_binary_operation(umath.arctan2, 0.0, 1.0)\narctan2.reduce = None\nequal = masked_binary_operation(umath.equal)\nequal.reduce = None\nnot_equal = masked_binary_operation(umath.not_equal)\nnot_equal.reduce = None\nless_equal = masked_binary_operation(umath.less_equal)\nless_equal.reduce = None\ngreater_equal = masked_binary_operation(umath.greater_equal)\ngreater_equal.reduce = None\nless = masked_binary_operation(umath.less)\nless.reduce = None\ngreater = masked_binary_operation(umath.greater)\ngreater.reduce = None\nlogical_and = masked_binary_operation(umath.logical_and)\nlogical_or = masked_binary_operation(umath.logical_or)\nlogical_xor = masked_binary_operation(umath.logical_xor)\nbitwise_and = masked_binary_operation(umath.bitwise_and)\nbitwise_or = masked_binary_operation(umath.bitwise_or)\nbitwise_xor = masked_binary_operation(umath.bitwise_xor)\n\ndef rank (object):\n return oldnumeric.rank(filled(object))\n\ndef shape (object):\n return oldnumeric.shape(filled(object))\n\ndef size (object, axis=None):\n return oldnumeric.size(filled(object), axis)\n\nclass MaskedArray (object):\n \"\"\"Arrays with possibly masked values.\n Masked values of 1 exclude the corresponding element from \n any computation.\n\n Construction:\n x = array(data, dtype=None, copy=True, fortran=False,\n mask = nomask, fill_value=None)\n\n If copy=False, every effort is made not to copy the data:\n If data is a MaskedArray, and argument mask=nomask,\n then the candidate data is data.data and the\n mask used is data.mask. If data is a numeric array,\n it is used as the candidate raw data.\n If dtypechar is not None and\n is != data.dtypechar then a data copy is required.\n Otherwise, the candidate is used.\n\n If a data copy is required, raw data stored is the result of:\n numeric.array(data, dtype=dtypechar, copy=copy)\n\n If mask is nomask there are no masked values. Otherwise mask must\n be convertible to an array of booleans with the same shape as x.\n\n fill_value is used to fill in masked values when necessary,\n such as when printing and in method/function filled().\n The fill_value is not used for computation within this module.\n \"\"\"\n __array_priority__ = 10.1\n def __init__(self, data, dtype=None, copy=True, fortran=False, \n mask=nomask, fill_value=None):\n \"\"\"array(data, dtype=None, copy=True, fortran=False, mask=nomask, fill_value=None)\n If data already a numeric array, its dtype becomes the default value of dtype.\n \"\"\"\n tc = dtype\n need_data_copied = copy\n if isinstance(data, MaskedArray):\n c = data.data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n if mask is nomask:\n mask = data.mask\n elif mask is not nomask: #attempting to change the mask\n need_data_copied = True\n\n elif isinstance(data, ndarray):\n c = data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n else:\n need_data_copied = False #because I'll do it now\n c = numeric.array(data, dtype=tc, copy=True, fortran=fortran)\n\n if need_data_copied:\n if tc == ctc:\n self._data = numeric.array(c, dtype=tc, copy=True, fortran=fortran)\n else:\n self._data = c.astype(tc)\n else:\n self._data = c\n\n if mask is nomask:\n self._mask = nomask\n self._shared_mask = 0\n else:\n self._mask = make_mask (mask)\n if self._mask is nomask:\n self._shared_mask = 0\n else:\n self._shared_mask = (self._mask is mask)\n nm = size(self._mask)\n nd = size(self._data)\n if nm != nd:\n if nm == 1:\n self._mask = oldnumeric.resize(self._mask, self._data.shape)\n self._shared_mask = 0\n elif nd == 1:\n self._data = oldnumeric.resize(self._data, self._mask.shape)\n self._data.shape = self._mask.shape\n else:\n raise MAError, \"Mask and data not compatible.\"\n elif nm == 1 and shape(self._mask) != shape(self._data):\n self.unshare_mask()\n self._mask.shape = self._data.shape\n\n self.set_fill_value(fill_value)\n\n def __array__ (self, t = None):\n \"Special hook for numeric. Converts to numeric if possible.\"\n if self._mask is not nomask:\n if oldnumeric.ravel(self._mask).any():\n raise MAError, \\\n \"\"\"Cannot automatically convert masked array to numeric because data\n is masked in one or more locations.\n \"\"\"\n else: # Mask is all false\n # Optimize to avoid future invocations of this section.\n self._mask = nomask\n self._shared_mask = 0\n if t:\n return self._data.astype(t)\n else:\n return self._data\n\n def __array_wrap__ (self, array):\n \"\"\"Special hook for ufuncs. Converts to Masked array with\n the same mask as self.\"\"\"\n return MaskedArray(array, copy=False, mask=self._mask,\n fill_value = self._fill_value)\n \n def _get_shape(self):\n \"Return the current shape.\"\n return self._data.shape\n\n def _set_shape (self, newshape):\n \"Set the array's shape.\"\n self._data.shape = newshape\n if self._mask is not nomask:\n self._mask = self._mask.copy()\n self._mask.shape = newshape\n\n def _get_flat(self):\n \"\"\"Calculate the flat value.\n \"\"\"\n if self._mask is nomask:\n return masked_array(self._data.ravel(), mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.ravel(),\n mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_flat (self, value):\n \"x.flat = value\"\n y = self.ravel()\n y[:] = value\n\n def _get_real(self):\n \"Get the real part of a complex array.\"\n if self._mask is nomask:\n return masked_array(self._data.real, mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.real, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_real (self, value):\n \"x.real = value\"\n y = self.real\n y[...] = value\n\n def _get_imaginary(self):\n \"Get the imaginary part of a complex array.\"\n if self._mask is nomask:\n return masked_array(self._data.imag, mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.imag, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_imaginary (self, value):\n \"x.imaginary = value\"\n y = self.imaginary\n y[...] = value\n\n def __str__(self):\n \"\"\"Calculate the str representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n if masked_print_option.enabled():\n f = masked_print_option\n # XXX: Without the following special case masked\n # XXX: would print as \"[--]\", not \"--\". Can we avoid\n # XXX: checks for masked by choosing a different value\n # XXX: for the masked singleton? 2005-01-05 -- sasha\n if self is masked:\n return str(f)\n m = self._mask\n if m is not nomask and m.shape == () and m:\n return str(f)\n # convert to object array to make filled work\n self = self.astype(object)\n else:\n f = self.fill_value()\n res = self.filled(f)\n return str(res)\n\n def __repr__(self):\n \"\"\"Calculate the repr representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n with_mask = \"\"\"\\\narray(data =\n %(data)s,\n mask =\n %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n with_mask1 = \"\"\"\\\narray(data = %(data)s,\n mask = %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n without_mask = \"\"\"array(\n %(data)s)\"\"\"\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n\n n = len(self.shape)\n if self._mask is nomask:\n if n <=1:\n return without_mask1 % {'data':str(self.filled())}\n return without_mask % {'data':str(self.filled())}\n else:\n if n <=1:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n if self._mask is nomask:\n return without_mask % {'data':str(self.filled())}\n else:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n\n def __float__(self):\n \"Convert self to float.\"\n self.unmask()\n if self._mask is not nomask:\n raise MAError, 'Cannot convert masked element to a Python float.'\n return float(self.data.item())\n\n def __int__(self):\n \"Convert self to int.\"\n self.unmask()\n if self._mask is not nomask:\n raise MAError, 'Cannot convert masked element to a Python int.'\n return int(self.data.item())\n\n def __getitem__(self, i):\n \"Get item described by i. Not a copy as in previous versions.\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i]\n if m is nomask:\n return dout\n mi = m[i]\n if mi.size == 1:\n if mi: \n return masked\n else:\n return dout\n else:\n return masked_array(dout, mi, fill_value=self._fill_value)\n\n def __getslice__(self, i, j):\n \"Get slice described by i, j\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i:j]\n if m is nomask:\n return masked_array(dout, fill_value=self._fill_value)\n else:\n return masked_array(dout, mask = m[i:j], fill_value=self._fill_value)\n\n# --------\n# setitem and setslice notes\n# note that if value is masked, it means to mask those locations.\n# setting a value changes the mask to match the value in those locations.\n\n def __setitem__(self, index, value):\n \"Set item described by index. If value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, 'Cannot alter the masked element.'\n if value is masked:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n else:\n self.unshare_mask()\n self._mask[index] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[index] = value\n if m is nomask:\n if self._mask is not nomask:\n self.unshare_mask()\n self._mask[index] = False\n else:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = True\n else:\n self.unshare_mask()\n self._mask[index] = m\n\n def __setslice__(self, i, j, value):\n \"Set slice i:j; if value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, \"Cannot alter the 'masked' object.\"\n if value is masked:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n self._mask[i:j] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[i:j] = value\n if m is nomask:\n if self._mask is not nomask:\n self.unshare_mask()\n self._mask[i:j] = False\n else:\n if self._mask is nomask:\n self._mask = make_mask_none(self._data.shape)\n self._shared_mask = False\n self._mask[i:j] = m\n\n def __nonzero__(self):\n \"\"\"returns true if any element is non-zero or masked\n\n \"\"\"\n # XXX: This changes bool conversion logic from MA.\n # XXX: In MA bool(a) == len(a) != 0, but in numpy\n # XXX: scalars do not have len \n m = self._mask\n d = self._data\n return bool(m is not nomask and m.any()\n or d is not nomask and d.any())\n \n def __len__ (self):\n \"\"\"Return length of first dimension. This is weird but Python's\n slicing behavior depends on it.\"\"\"\n return len(self._data)\n\n def __and__(self, other):\n \"Return bitwise_and\"\n return bitwise_and(self, other)\n\n def __or__(self, other):\n \"Return bitwise_or\"\n return bitwise_or(self, other)\n\n def __xor__(self, other):\n \"Return bitwise_xor\"\n return bitwise_xor(self, other)\n\n __rand__ = __and__\n __ror__ = __or__\n __rxor__ = __xor__\n\n def __abs__(self):\n \"Return absolute(self)\"\n return absolute(self)\n\n def __neg__(self):\n \"Return negative(self)\"\n return negative(self)\n\n def __pos__(self):\n \"Return array(self)\"\n return array(self)\n\n def __add__(self, other):\n \"Return add(self, other)\"\n return add(self, other)\n\n __radd__ = __add__\n\n def __mod__ (self, other):\n \"Return remainder(self, other)\"\n return remainder(self, other)\n\n def __rmod__ (self, other):\n \"Return remainder(other, self)\"\n return remainder(other, self)\n\n def __lshift__ (self, n):\n return left_shift(self, n)\n\n def __rshift__ (self, n):\n return right_shift(self, n)\n\n def __sub__(self, other):\n \"Return subtract(self, other)\"\n return subtract(self, other)\n\n def __rsub__(self, other):\n \"Return subtract(other, self)\"\n return subtract(other, self)\n\n def __mul__(self, other):\n \"Return multiply(self, other)\"\n return multiply(self, other)\n\n __rmul__ = __mul__\n\n def __div__(self, other):\n \"Return divide(self, other)\"\n return divide(self, other)\n\n def __rdiv__(self, other):\n \"Return divide(other, self)\"\n return divide(other, self)\n\n def __truediv__(self, other):\n \"Return divide(self, other)\"\n return true_divide(self, other)\n\n def __rtruediv__(self, other):\n \"Return divide(other, self)\"\n return true_divide(other, self)\n\n def __floordiv__(self, other):\n \"Return divide(self, other)\"\n return floor_divide(self, other)\n\n def __rfloordiv__(self, other):\n \"Return divide(other, self)\"\n return floor_divide(other, self)\n\n def __pow__(self,other, third=None):\n \"Return power(self, other, third)\"\n return power(self, other, third)\n\n def __sqrt__(self):\n \"Return sqrt(self)\"\n return sqrt(self)\n\n def __iadd__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data += f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = add(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __imul__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data *= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = multiply(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __isub__(self, other):\n \"Subtract other from self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data -= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = subtract(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n\n\n def __idiv__(self, other):\n \"Divide self by other in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n mo = getmask(other)\n result = divide(self, masked_array(f, mask=mo))\n self._data = result.data\n dm = result.raw_mask()\n if dm is not self._mask:\n self._mask = dm\n self._shared_mask = 1\n return self\n\n def __eq__(self,other):\n return equal(self,other)\n\n def __ne__(self,other):\n return not_equal(self,other)\n\n def __lt__(self,other):\n return less(self,other)\n\n def __le__(self,other):\n return less_equal(self,other)\n\n def __gt__(self,other):\n return greater(self,other)\n\n def __ge__(self,other):\n return greater_equal(self,other)\n\n def astype (self, tc):\n \"return self as array of given type.\"\n d = self._data.astype(tc)\n return array(d, mask=self._mask)\n\n def byte_swapped(self):\n \"\"\"Returns the raw data field, byte_swapped. Included for consistency\n with numeric but doesn't make sense in this context.\n \"\"\"\n return self._data.byte_swapped()\n\n def compressed (self):\n \"A 1-D array of all the non-masked data.\"\n d = oldnumeric.ravel(self._data)\n if self._mask is nomask:\n return array(d)\n else:\n m = 1 - oldnumeric.ravel(self._mask)\n c = oldnumeric.compress(m, d)\n return array(c, copy=0)\n\n def count (self, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n m = self._mask\n s = self._data.shape\n ls = len(s)\n if m is nomask:\n if ls == 0:\n return 1\n if ls == 1:\n return s[0]\n if axis is None:\n return reduce(lambda x,y:x*y, s)\n else:\n n = s[axis]\n t = list(s)\n del t[axis]\n return ones(t) * n\n if axis is None:\n w = oldnumeric.ravel(m).astype(int) \n n1 = size(w)\n if n1 == 1:\n n2 = w[0]\n else:\n n2 = umath.add.reduce(w)\n return n1 - n2\n else:\n n1 = size(m, axis)\n n2 = sum(m.astype(int), axis)\n return n1 - n2\n\n def dot (self, other):\n \"s.dot(other) = innerproduct(s, other)\"\n return innerproduct(self, other)\n\n def fill_value(self):\n \"Get the current fill value.\"\n return self._fill_value\n\n def filled (self, fill_value=None):\n \"\"\"A numeric array with masked values filled. If fill_value is None,\n use self.fill_value().\n\n If mask is nomask, copy data only if not contiguous.\n Result is always a contiguous, numeric array.\n# Is contiguous really necessary now?\n \"\"\"\n d = self._data\n m = self._mask\n if m is nomask:\n if d.flags['CONTIGUOUS']:\n return d\n else:\n return d.copy()\n else:\n if fill_value is None:\n value = self._fill_value\n else:\n value = fill_value\n\n if self is masked:\n result = numeric.array(value).reshape(*d.shape)\n else:\n try:\n result = numeric.array(d, dtype=d.dtype, copy=1)\n result[m] = value\n except (TypeError, AttributeError):\n #ok, can't put that value in here\n value = numeric.array(value, dtype=object)\n d = d.astype(object)\n result = oldnumeric.choose(m, (d, value))\n except IndexError:\n #ok, if scalar\n if d.shape:\n raise\n elif m:\n result = numeric.array(value, dtype=d.dtype)\n else:\n result = d\n return result\n\n def ids (self):\n \"\"\"Return the ids of the data and mask areas\"\"\"\n return (id(self._data), id(self._mask))\n\n def iscontiguous (self):\n \"Is the data contiguous?\"\n return self._data.flags['CONTIGUOUS']\n\n def itemsize(self):\n \"Item size of each data item.\"\n return self._data.itemsize\n\n\n def outer(self, other):\n \"s.outer(other) = outerproduct(s, other)\"\n return outerproduct(self, other)\n\n def put (self, values):\n \"\"\"Set the non-masked entries of self to filled(values).\n No change to mask\n \"\"\"\n iota = numeric.arange(self.size)\n d = self._data\n if self._mask is nomask:\n ind = iota\n else:\n ind = oldnumeric.compress(1 - self._mask, iota)\n d[ind] = filled(values).astype(d.dtype)\n\n def putmask (self, values):\n \"\"\"Set the masked entries of self to filled(values).\n Mask changed to nomask.\n \"\"\"\n d = self._data\n if self._mask is not nomask:\n d[self._mask] = filled(values).astype(d.dtype)\n self._shared_mask = 0\n self._mask = nomask\n\n def ravel (self):\n \"\"\"Return a 1-D view of self.\"\"\"\n if self._mask is nomask:\n return masked_array(self._data.ravel())\n else:\n return masked_array(self._data.ravel(), self._mask.ravel())\n\n def raw_data (self):\n \"\"\" Obsolete; use data property instead.\n The raw data; portions may be meaningless.\n May be noncontiguous. Expert use only.\"\"\"\n return self._data\n data = property(fget=raw_data, \n doc=\"The data, but values at masked locations are meaningless.\")\n\n def raw_mask (self):\n \"\"\" Obsolete; use mask property instead.\n May be noncontiguous. Expert use only.\n \"\"\"\n return self._mask\n mask = property(fget=raw_mask, \n doc=\"The mask, may be nomask. Values where mask true are meaningless.\")\n\n def reshape (self, *s):\n \"\"\"This array reshaped to shape s\"\"\"\n d = self._data.reshape(*s)\n if self._mask is nomask:\n return masked_array(d)\n else:\n m = self._mask.reshape(*s)\n return masked_array(d, m)\n\n def set_fill_value (self, v=None):\n \"Set the fill value to v. Omit v to restore default.\"\n if v is None:\n v = default_fill_value (self.raw_data())\n self._fill_value = v\n\n def _get_size (self):\n return self._data.size\n size = property(fget=_get_size, doc=\"Number of elements in the array.\")\n## CHECK THIS: signature of numeric.array.size?\n \n def _get_dtypechar(self):\n return self._data.dtypechar\n dtypechar = property(fget=_get_dtypechar, doc=\"type character of the array.\")\n\n def _get_dtype(self):\n return self._data.dtype\n dtype = property(fget=_get_dtype, doc=\"type of the array elements.\")\n\n def item(self):\n \"Return Python scalar if possible.\"\n if self._mask is not nomask:\n m = oldnumeric.ravel(self._mask)\n try:\n if m[0]:\n return masked\n except IndexError:\n return masked\n return self._data.item()\n\n def tolist(self, fill_value=None):\n \"Convert to list\"\n return self.filled(fill_value).tolist()\n\n def tostring(self, fill_value=None):\n \"Convert to string\"\n return self.filled(fill_value).tostring()\n\n def unmask (self):\n \"Replace the mask by nomask if possible.\"\n if self._mask is nomask: return\n m = make_mask(self._mask, flag=1)\n if m is nomask:\n self._mask = nomask\n self._shared_mask = 0\n\n def unshare_mask (self):\n \"If currently sharing mask, make a copy.\"\n if self._shared_mask:\n self._mask = make_mask (self._mask, copy=1, flag=0)\n self._shared_mask = 0\n\n shape = property(_get_shape, _set_shape,\n doc = 'tuple giving the shape of the array')\n\n flat = property(_get_flat, _set_flat,\n doc = 'Access array in flat form.')\n\n real = property(_get_real, _set_real,\n doc = 'Access the real part of the array')\n\n imaginary = property(_get_imaginary, _set_imaginary,\n doc = 'Access the imaginary part of the array')\n\n imag = imaginary\n\n#end class MaskedArray\n\narray = MaskedArray\n\ndef isMaskedArray (x):\n \"Is x a masked array, that is, an instance of MaskedArray?\"\n return isinstance(x, MaskedArray)\n\nisarray = isMaskedArray\nisMA = isMaskedArray #backward compatibility\n\ndef allclose (a, b, fill_value=1, rtol=1.e-5, atol=1.e-8):\n \"\"\" Returns true if all components of a and b are equal\n subject to given tolerances.\n If fill_value is 1, masked values considered equal.\n If fill_value is 0, masked values considered unequal.\n The relative error rtol should be positive and << 1.0\n The absolute error atol comes into play for those elements\n of b that are very small or zero; it says how small a must be also.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a)\n d2 = filled(b)\n x = filled(array(d1, copy=0, mask=m), fill_value).astype(float)\n y = filled(array(d2, copy=0, mask=m), 1).astype(float)\n d = umath.less_equal(umath.absolute(x-y), atol + rtol * umath.absolute(y))\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n\ndef allequal (a, b, fill_value=1):\n \"\"\"\n True if all entries of a and b are equal, using\n fill_value as a truth value where either or both are masked.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n if m is nomask:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n elif fill_value:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n dm = array(d, mask=m, copy=0)\n return oldnumeric.alltrue(oldnumeric.ravel(filled(dm, 1)))\n else:\n return 0\n\ndef masked_values (data, value, rtol=1.e-5, atol=1.e-8, copy=1):\n \"\"\"\n masked_values(data, value, rtol=1.e-5, atol=1.e-8)\n Create a masked array; mask is nomask if possible.\n If copy==0, and otherwise possible, result\n may share data values with original array.\n Let d = filled(data, value). Returns d\n masked where abs(data-value)<= atol + rtol * abs(value)\n if d is of a floating point type. Otherwise returns\n masked_object(d, value, copy)\n \"\"\"\n abs = umath.absolute\n d = filled(data, value)\n if issubclass(d.dtype, numeric.floating):\n m = umath.less_equal(abs(d-value), atol+rtol*abs(value))\n m = make_mask(m, flag=1)\n return array(d, mask = m, copy=copy,\n fill_value=value)\n else:\n return masked_object(d, value, copy=copy)\n\ndef masked_object (data, value, copy=1):\n \"Create array masked where exactly data equal to value\"\n d = filled(data, value)\n dm = make_mask(umath.equal(d, value), flag=1)\n return array(d, mask=dm, copy=copy, fill_value=value)\n\ndef arrayrange(start, stop=None, step=1, dtype=None):\n \"\"\"Just like range() except it returns a array whose type can be specified\n by the keyword argument dtypechar.\n \"\"\"\n return array(numeric.arrayrange(start, stop, step, dtype))\n\narange = arrayrange\n\ndef fromstring (s, t):\n \"Construct a masked array from a string. Result will have no mask.\"\n return masked_array(numeric.fromstring(s, t))\n\ndef left_shift (a, n):\n \"Left shift n bits\"\n m = getmask(a)\n if m is nomask:\n d = umath.left_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.left_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef right_shift (a, n):\n \"Right shift n bits\"\n m = getmask(a)\n if m is nomask:\n d = umath.right_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.right_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef resize (a, new_shape):\n \"\"\"resize(a, new_shape) returns a new array with the specified shape.\n The original array's total size can be any size.\"\"\"\n m = getmask(a)\n if m is not nomask:\n m = oldnumeric.resize(m, new_shape)\n result = array(oldnumeric.resize(filled(a), new_shape), mask=m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n \"\"\"\n af = filled(a)\n if isinstance(repeats, types.IntType):\n repeats = tuple([repeats]*(shape(af)[axis]))\n\n m = getmask(a)\n if m is not nomask:\n m = oldnumeric.repeat(m, repeats, axis)\n d = oldnumeric.repeat(af, repeats, axis)\n result = masked_array(d, m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef identity(n):\n \"\"\"identity(n) returns the identity matrix of shape n x n.\n \"\"\"\n return array(numeric.identity(n))\n\ndef indices (dimensions, dtype=None):\n \"\"\"indices(dimensions,dtype=None) returns an array representing a grid\n of indices with row-only, and column-only variation.\n \"\"\"\n return array(numeric.indices(dimensions, dtype))\n\ndef zeros (shape, dtype=int):\n \"\"\"zeros(n, dtype=int) =\n an array of all zeros of the given length or shape.\"\"\"\n return array(numeric.zeros(shape, dtype))\n\ndef ones (shape, dtype=int):\n \"\"\"ones(n, dtype=int) =\n an array of all ones of the given length or shape.\"\"\"\n return array(numeric.ones(shape, dtype))\n\n\ndef count (a, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n a = masked_array(a)\n return a.count(axis)\n\ndef power (a, b, third=None):\n \"a**b\"\n if third is not None:\n raise MAError, \"3-argument power not supported.\"\n ma = getmask(a)\n mb = getmask(b)\n m = mask_or(ma, mb)\n fa = filled(a, 1)\n fb = filled(b, 1)\n if fb.dtypechar in typecodes[\"Integer\"]:\n return masked_array(umath.power(fa, fb), m)\n md = make_mask(umath.less_equal (fa, 0), flag=1)\n m = mask_or(m, md)\n if m is nomask:\n return masked_array(umath.power(fa, fb))\n else:\n fa = numeric.where(m, 1, fa)\n return masked_array(umath.power(fa, fb), m)\n\ndef masked_array (a, mask=nomask, fill_value=None):\n \"\"\"masked_array(a, mask=nomask) =\n array(a, mask=mask, copy=0, fill_value=fill_value)\n \"\"\"\n return array(a, mask=mask, copy=0, fill_value=fill_value)\n\nsum = add.reduce\nproduct = multiply.reduce\n\ndef average (a, axis=0, weights=None, returned = 0):\n \"\"\"average(a, axis=0, weights=None)\n Computes average along indicated axis.\n If axis is None, average over the entire array\n Inputs can be integer or floating types; result is of type float.\n\n If weights are given, result is sum(a*weights)/(sum(weights)*1.0)\n weights must have a's shape or be the 1-d with length the size\n of a in the given axis.\n\n If returned, return a tuple: the result and the sum of the weights\n or count of values. Results will have the same shape.\n\n masked values in the weights will be set to 0.0\n \"\"\"\n a = masked_array(a)\n mask = a.mask\n ash = a.shape\n if ash == ():\n ash = (1,)\n if axis is None:\n if mask is nomask:\n if weights is None:\n n = add.reduce(a.raw_data().ravel())\n d = reduce(lambda x, y: x * y, ash, 1.0)\n else:\n w = filled(weights, 0.0).ravel()\n n = umath.add.reduce(a.raw_data().ravel() * w)\n d = umath.add.reduce(w)\n del w\n else:\n if weights is None:\n n = add.reduce(a.ravel())\n w = oldnumeric.choose(mask, (1.0,0.0)).ravel()\n d = umath.add.reduce(w)\n del w\n else:\n w = array(filled(weights, 0.0), float, mask=mask).ravel()\n n = add.reduce(a.ravel() * w)\n d = add.reduce(w)\n del w\n else:\n if mask is nomask:\n if weights is None:\n d = ash[axis] * 1.0\n n = umath.add.reduce(a.raw_data(), axis)\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = numeric.array(w, float, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * ones(ash, float)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w, r\n else:\n raise ValueError, 'average: weights wrong shape.'\n else:\n if weights is None:\n n = add.reduce(a, axis)\n w = numeric.choose(mask, (1.0, 0.0))\n d = umath.add.reduce(w, axis)\n del w\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = array(w, float, mask=mask, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * masked_array(ones(ash, float), mask)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n else:\n raise ValueError, 'average: weights wrong shape.'\n del w\n #print n, d, repr(mask), repr(weights)\n if n is masked or d is masked: return masked\n result = divide (n, d)\n del n\n\n if isinstance(result, MaskedArray):\n result.unmask()\n if returned:\n if not isinstance(d, MaskedArray):\n d = masked_array(d)\n if not d.shape == result.shape:\n d = ones(result.shape, float) * d\n d.unmask()\n if returned:\n return result, d\n else:\n return result\n\ndef where (condition, x, y):\n \"\"\"where(condition, x, y) is x where condition is nonzero, y otherwise.\n condition must be convertible to an integer array.\n Answer is always the shape of condition.\n The type depends on x and y. It is integer if both x and y are\n the value masked.\n \"\"\"\n fc = filled(not_equal(condition,0), 0)\n if x is masked:\n xv = 0\n xm = 1\n else:\n xv = filled(x)\n xm = getmask(x)\n if xm is nomask: xm = 0\n if y is masked:\n yv = 0\n ym = 1\n else:\n yv = filled(y)\n ym = getmask(y)\n if ym is nomask: ym = 0\n d = numeric.choose(fc, (yv, xv))\n md = numeric.choose(fc, (ym, xm))\n m = getmask(condition)\n m = make_mask(mask_or(m, md), copy=0, flag=1)\n return masked_array(d, m)\n\ndef choose (indices, t):\n \"Returns array shaped like indices with elements chosen from t\"\n def fmask (x):\n if x is masked: return 1\n return filled(x)\n def nmask (x):\n if x is masked: return 1\n m = getmask(x)\n if m is nomask: return 0\n return m\n c = filled(indices,0)\n masks = [nmask(x) for x in t]\n a = [fmask(x) for x in t]\n d = numeric.choose(c, a)\n m = numeric.choose(c, masks)\n m = make_mask(mask_or(m, getmask(indices)), copy=0, flag=1)\n return masked_array(d, m)\n\ndef masked_where(condition, x, copy=1):\n \"\"\"Return x as an array masked where condition is true.\n Also masked where x or condition masked.\n \"\"\"\n cm = filled(condition,1)\n m = mask_or(getmask(x), cm)\n return array(filled(x), copy=copy, mask=m)\n\ndef masked_greater(x, value, copy=1):\n \"masked_greater(x, value) = x masked where x > value\"\n return masked_where(greater(x, value), x, copy)\n\ndef masked_greater_equal(x, value, copy=1):\n \"masked_greater_equal(x, value) = x masked where x >= value\"\n return masked_where(greater_equal(x, value), x, copy)\n\ndef masked_less(x, value, copy=1):\n \"masked_less(x, value) = x masked where x < value\"\n return masked_where(less(x, value), x, copy)\n\ndef masked_less_equal(x, value, copy=1):\n \"masked_less_equal(x, value) = x masked where x <= value\"\n return masked_where(less_equal(x, value), x, copy)\n\ndef masked_not_equal(x, value, copy=1):\n \"masked_not_equal(x, value) = x masked where x != value\"\n d = filled(x,0)\n c = umath.not_equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_equal(x, value, copy=1):\n \"\"\"masked_equal(x, value) = x masked where x == value\n For floating point consider masked_values(x, value) instead.\n \"\"\"\n d = filled(x,0)\n c = umath.equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_inside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are inside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d=filled(x, 0)\n c = umath.logical_and(umath.less_equal(d, v2), umath.greater_equal(d, v1))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef masked_outside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are outside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d = filled(x,0)\n c = umath.logical_or(umath.less(d, v1), umath.greater(d, v2))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef reshape (a, *newshape):\n \"Copy of a with a new shape.\"\n m = getmask(a)\n d = filled(a).reshape(*newshape)\n if m is nomask:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.reshape(m, *newshape))\n\ndef ravel (a):\n \"a as one-dimensional, may share data and mask\"\n m = getmask(a)\n d = oldnumeric.ravel(filled(a))\n if m is nomask:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.ravel(m))\n\ndef concatenate (arrays, axis=0):\n \"Concatenate the arrays along the given axis\"\n d = []\n for x in arrays:\n d.append(filled(x))\n d = numeric.concatenate(d, axis)\n for x in arrays:\n if getmask(x) is not nomask: break\n else:\n return masked_array(d)\n dm = []\n for x in arrays:\n dm.append(getmaskarray(x))\n dm = numeric.concatenate(dm, axis)\n return masked_array(d, mask=dm)\n\ndef take (a, indices, axis=0):\n \"take(a, indices, axis=0) returns selection of items from a.\"\n m = getmask(a)\n d = masked_array(a).raw_data()\n if m is nomask:\n return masked_array(numeric.take(d, indices, axis))\n else:\n return masked_array(numeric.take(d, indices, axis),\n mask = numeric.take(m, indices, axis))\n\ndef transpose(a, axes=None):\n \"transpose(a, axes=None) reorder dimensions per tuple axes\"\n m = getmask(a)\n d = filled(a)\n if m is nomask:\n return masked_array(numeric.transpose(d, axes))\n else:\n return masked_array(numeric.transpose(d, axes),\n mask = numeric.transpose(m, axes))\n\n\ndef put(a, indices, values):\n \"\"\"put(a, indices, values) sets storage-indexed locations to corresponding values.\n\n Values and indices are filled if necessary.\n\n \"\"\"\n d = a.raw_data()\n ind = filled(indices)\n v = filled(values)\n numeric.put (d, ind, v)\n m = getmask(a)\n if m is not nomask:\n a.unshare_mask()\n numeric.put(a.raw_mask(), ind, 0)\n\ndef putmask(a, mask, values):\n \"putmask(a, mask, values) sets a where mask is true.\"\n if mask is nomask:\n return\n numeric.putmask(a.raw_data(), mask, values)\n m = getmask(a)\n if m is nomask: return\n a.unshare_mask()\n numeric.putmask(a.raw_mask(), mask, 0)\n\ndef innerproduct(a,b):\n \"\"\"innerproduct(a,b) returns the dot product of two arrays, which has\n shape a.shape[:-1] + b.shape[:-1] with elements computed by summing the\n product of the elements from the last dimensions of a and b.\n Masked elements are replace by zeros.\n \"\"\"\n fa = filled(a, 0)\n fb = filled(b, 0)\n if len(fa.shape) == 0: fa.shape = (1,)\n if len(fb.shape) == 0: fb.shape = (1,)\n return masked_array(numeric.innerproduct(fa, fb))\n\ndef outerproduct(a, b):\n \"\"\"outerproduct(a,b) = {a[i]*b[j]}, has shape (len(a),len(b))\"\"\"\n fa = filled(a,0).ravel()\n fb = filled(b,0).ravel()\n d = numeric.outerproduct(fa, fb)\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n return masked_array(d)\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = make_mask(1-numeric.outerproduct(1-ma,1-mb), copy=0)\n return masked_array(d, m)\n\ndef dot(a, b):\n \"\"\"dot(a,b) returns matrix-multiplication between a and b. The product-sum\n is over the last dimension of a and the second-to-last dimension of b.\n Masked values are replaced by zeros. See also innerproduct.\n \"\"\"\n return innerproduct(filled(a,0), numeric.swapaxes(filled(b,0), -1, -2))\n\ndef compress(condition, x, dimension=-1):\n \"\"\"Select those parts of x for which condition is true.\n Masked values in condition are considered false.\n \"\"\"\n c = filled(condition, 0)\n m = getmask(x)\n if m is not nomask:\n m=numeric.compress(c, m, dimension)\n d = numeric.compress(c, filled(x), dimension)\n return masked_array(d, m)\n\nclass _minimum_operation:\n \"Object to calculate minima\"\n def __init__ (self):\n \"\"\"minimum(a, b) or minimum(a)\n In one argument case returns the scalar minimum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is nomask:\n d = amin(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amin(ac.raw_data())\n else:\n return where(less(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is nomask:\n t = filled(target)\n return masked_array (umath.minimum.reduce (t, axis))\n else:\n t = umath.minimum.reduce(filled(target, minimum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.minimum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nminimum = _minimum_operation ()\n\nclass _maximum_operation:\n \"Object to calculate maxima\"\n def __init__ (self):\n \"\"\"maximum(a, b) or maximum(a)\n In one argument case returns the scalar maximum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is nomask:\n d = amax(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amax(ac.raw_data())\n else:\n return where(greater(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is nomask:\n t = filled(target)\n return masked_array (umath.maximum.reduce (t, axis))\n else:\n t = umath.maximum.reduce(filled(target, maximum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.maximum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nmaximum = _maximum_operation ()\n\ndef sort (x, axis = -1, fill_value=None):\n \"\"\"If x does not have a mask, return a masked array formed from the\n result of numeric.sort(x, axis).\n Otherwise, fill x with fill_value. Sort it.\n Set a mask where the result is equal to fill_value.\n Note that this may have unintended consequences if the data contains the\n fill value at a non-masked site.\n\n If fill_value is not given the default fill value for x's type will be\n used.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n d = filled(x, fill_value)\n s = oldnumeric.sort(d, axis)\n if getmask(x) is nomask:\n return masked_array(s)\n return masked_values(s, fill_value, copy=0)\n\ndef diagonal(a, k = 0, axis1=0, axis2=1):\n \"\"\"diagonal(a,k=0,axis1=0, axis2=1) = the k'th diagonal of a\"\"\"\n d = oldnumeric.diagonal(filled(a), k, axis1, axis2)\n m = getmask(a)\n if m is nomask:\n return masked_array(d, m)\n else:\n return masked_array(d, oldnumeric.diagonal(m, k, axis1, axis2))\n\ndef argsort (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for sorting along given axis.\n if fill_value is None, use get_fill_value(x)\n Returns a numpy array.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argsort(d, axis)\n\ndef argmin (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return indices for minimum values along given axis.\n if fill_value is None, use get_fill_value(x).\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argmin(d, axis)\n\ndef argmax (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for maximum along given axis.\n if fill_value is None, use -get_fill_value(x) if it exists.\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n try:\n fill_value = - fill_value\n except:\n pass\n d = filled(x, fill_value)\n return oldnumeric.argmax(d, axis)\n\ndef fromfunction (f, s):\n \"\"\"apply f to s to create array as in umath.\"\"\"\n return masked_array(numeric.fromfunction(f,s))\n\ndef asarray(data, dtype=None):\n \"\"\"asarray(data, dtype) = array(data, dtype, copy=0)\n \"\"\"\n if isinstance(data, MaskedArray) and \\\n (dtype is None or dtype == data.dtype):\n return data\n return array(data, dtype=dtype, copy=0)\n\n# Add methods to support ndarray interface\n# XXX: I is better to to change the masked_*_operation adaptors\n# XXX: to wrap ndarray methods directly to create ma.array methods.\nfrom types import MethodType\ndef _m(f):\n return MethodType(f, None, array)\ndef not_implemented(*args, **kwds):\n raise NotImplementedError, \"not yet implemented for numpy.ma arrays\"\narray.all = _m(alltrue)\narray.any = _m(sometrue)\narray.argmax = _m(argmax)\narray.argmin = _m(argmin)\narray.argsort = _m(argsort)\narray.base = property(_m(not_implemented))\narray.byteswap = _m(not_implemented)\n\ndef _choose(self, *args):\n return choose(self, args)\narray.choose = _m(_choose)\ndel _choose\n\narray.clip = _m(not_implemented)\n\ndef _compress(self, cond, axis=None):\n return compress(cond, self, axis)\narray.compress = _m(_compress)\ndel _compress\n\narray.conj = array.conjugate = _m(conjugate)\narray.copy = _m(not_implemented)\narray.cumprod = _m(not_implemented)\narray.cumsum = _m(not_implemented)\narray.diagonal = _m(diagonal)\narray.dtypedescr = property(_m(not_implemented))\narray.dtypestr = property(_m(not_implemented))\narray.dump = _m(not_implemented)\narray.dumps = _m(not_implemented)\narray.fill = _m(not_implemented)\narray.flags = property(_m(not_implemented))\narray.flatten = _m(ravel)\narray.getfield = _m(not_implemented)\narray.max = _m(maximum)\narray.mean = _m(average)\narray.min = _m(minimum)\narray.nbytes = property(_m(not_implemented))\narray.ndim = _m(not_implemented)\narray.newbyteorder = _m(not_implemented)\narray.nonzero = _m(nonzero)\narray.prod = _m(product)\narray.ptp = _m(not_implemented)\narray.repeat = _m(repeat)\narray.resize = _m(resize)\narray.searchsorted = _m(not_implemented)\narray.setfield = _m(not_implemented)\narray.setflags = _m(not_implemented)\narray.sort = _m(not_implemented) # NB: ndarray.sort is inplace\narray.squeeze = _m(not_implemented)\narray.std = _m(not_implemented)\narray.strides = property(_m(not_implemented))\narray.sum = _m(sum)\narray.swapaxes = _m(not_implemented)\narray.take = _m(take)\narray.tofile = _m(not_implemented)\narray.trace = _m(not_implemented)\narray.transpose = _m(transpose)\narray.var = _m(not_implemented)\narray.view = _m(not_implemented)\ndel _m, MethodType, not_implemented\n\n\nmasked = MaskedArray(0, int, mask=1)\n", + "source_code_before": "\"\"\"MA: a facility for dealing with missing observations\nMA is generally used as a numpy.array look-alike.\nby Paul F. Dubois.\n\nCopyright 1999, 2000, 2001 Regents of the University of California.\nReleased for unlimited redistribution.\nAdapted for numpy_core 2005 by Travis Oliphant and\n(mainly) Paul Dubois.\n\"\"\"\nimport string, types, sys\n\nimport umath\nimport oldnumeric\nfrom numeric import e, pi, newaxis, ndarray, inf\nfrom oldnumeric import typecodes, amax, amin\nfrom numerictypes import *\nimport numeric\n\n \nMaskType=bool_\nnomask = None # To be changed to MaskType(0)\ndivide_tolerance = 1.e-35\n\nclass MAError (Exception):\n def __init__ (self, args=None):\n \"Create an exception\"\n self.args = args\n def __str__(self):\n \"Calculate the string representation\"\n return str(self.args)\n __repr__ = __str__\n\nclass _MaskedPrintOption:\n \"One instance of this class, masked_print_option, is created.\"\n def __init__ (self, display):\n \"Create the masked print option object.\"\n self.set_display(display)\n self._enabled = 1\n\n def display (self):\n \"Show what prints for masked values.\"\n return self._display\n\n def set_display (self, s):\n \"set_display(s) sets what prints for masked values.\"\n self._display = s\n\n def enabled (self):\n \"Is the use of the display value enabled?\"\n return self._enabled\n\n def enable(self, flag=1):\n \"Set the enabling flag to flag.\"\n self._enabled = flag\n\n def __str__ (self):\n return str(self._display)\n\n __repr__ = __str__\n \n#if you single index into a masked location you get this object.\nmasked_print_option = _MaskedPrintOption('--')\n\n# Use single element arrays or scalars.\ndefault_real_fill_value = 1.e20\ndefault_complex_fill_value = 1.e20 + 0.0j\ndefault_character_fill_value = '-'\ndefault_integer_fill_value = 999999\ndefault_object_fill_value = '?'\n\ndef default_fill_value (obj):\n \"Function to calculate default fill value for an object.\"\n if isinstance(obj, types.FloatType):\n return default_real_fill_value\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return default_integer_fill_value\n elif isinstance(obj, types.StringType):\n return default_character_fill_value\n elif isinstance(obj, types.ComplexType):\n return default_complex_fill_value\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return default_real_fill_value\n if x in typecodes['Integer']:\n return default_integer_fill_value\n if x in typecodes['Complex']:\n return default_complex_fill_value\n if x in typecodes['Character']:\n return default_character_fill_value\n if x in typecodes['UnsignedInteger']:\n return umath.absolute(default_integer_fill_value)\n return default_object_fill_value\n else:\n return default_object_fill_value\n\ndef minimum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking minima.\"\n if isinstance(obj, types.FloatType):\n return numeric.inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return numeric.inf\n if x in typecodes['Integer']:\n return sys.maxint\n if x in typecodes['UnsignedInteger']:\n return sys.maxint\n else:\n raise TypeError, 'Unsuitable type for calculating minimum.'\n\ndef maximum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking maxima.\"\n if isinstance(obj, types.FloatType):\n return -inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return -sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return -inf\n if x in typecodes['Integer']:\n return -sys.maxint\n if x in typecodes['UnsignedInteger']:\n return 0\n else:\n raise TypeError, 'Unsuitable type for calculating maximum.'\n\ndef set_fill_value (a, fill_value):\n \"Set fill value of a if it is a masked array.\"\n if isMaskedArray(a):\n a.set_fill_value (fill_value)\n\ndef getmask (a):\n \"\"\"Mask of values in a; could be nomask.\n Returns nomask if a is not a masked array.\n To get an array for sure use getmaskarray.\"\"\"\n if isinstance(a, MaskedArray):\n return a.raw_mask()\n else:\n return nomask\n\ndef getmaskarray (a):\n \"\"\"Mask of values in a; an array of zeros if mask is nomask\n or not a masked array, and is a byte-sized integer.\n Do not try to add up entries, for example.\n \"\"\"\n m = getmask(a)\n if m is nomask:\n return make_mask_none(shape(a))\n else:\n return m\n\ndef is_mask (m):\n \"\"\"Is m a legal mask? Does not check contents, only type.\n \"\"\"\n if m is nomask or (isinstance(m, ndarray) and \\\n m.dtype is MaskType):\n return 1\n else:\n return 0\n\ndef make_mask (m, copy=0, flag=0):\n \"\"\"make_mask(m, copy=0, flag=0)\n return m as a mask, creating a copy if necessary or requested.\n Can accept any sequence of integers or nomask. Does not check\n that contents must be 0s and 1s.\n if flag, return nomask if m contains no true elements.\n \"\"\"\n if m is nomask:\n return nomask\n elif isinstance(m, ndarray):\n if m.dtype is MaskType:\n if copy:\n result = numeric.array(m, dtype=MaskType, copy=copy)\n else:\n result = m\n else:\n result = m.astype(MaskType)\n else:\n result = filled(m,True).astype(MaskType)\n\n if flag and not oldnumeric.sometrue(oldnumeric.ravel(result)):\n return nomask\n else:\n return result\n\ndef make_mask_none (s):\n \"Return a mask of all zeros of shape s.\"\n result = numeric.zeros(s, dtype=MaskType)\n result.shape = s\n return result\n\ndef mask_or (m1, m2):\n \"\"\"Logical or of the mask candidates m1 and m2, treating nomask as false.\n Result may equal m1 or m2 if the other is nomask.\n \"\"\"\n if m1 is nomask: return make_mask(m2)\n if m2 is nomask: return make_mask(m1)\n if m1 is m2 and is_mask(m1): return m1\n return make_mask(umath.logical_or(m1, m2))\n\ndef filled (a, value = None):\n \"\"\"a as a contiguous numeric array with any masked areas replaced by value\n if value is None or the special element \"masked\", get_fill_value(a)\n is used instead.\n\n If a is already a contiguous numeric array, a itself is returned.\n\n filled(a) can be used to be sure that the result is numeric when\n passing an object a to other software ignorant of MA, in particular to\n numeric itself.\n \"\"\"\n if isinstance(a, MaskedArray):\n return a.filled(value)\n elif isinstance(a, ndarray) and a.flags['CONTIGUOUS']:\n return a\n elif isinstance(a, types.DictType):\n return numeric.array(a, 'O')\n else:\n return numeric.array(a)\n\ndef get_fill_value (a):\n \"\"\"\n The fill value of a, if it has one; otherwise, the default fill value\n for that type.\n \"\"\"\n if isMaskedArray(a):\n result = a.fill_value()\n else:\n result = default_fill_value(a)\n return result\n\ndef common_fill_value (a, b):\n \"The common fill_value of a and b, if there is one, or None\"\n t1 = get_fill_value(a)\n t2 = get_fill_value(b)\n if t1 == t2: return t1\n return None\n\n# Domain functions return 1 where the argument(s) are not in the domain.\nclass domain_check_interval:\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n def __init__(self, y1, y2):\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n self.y1 = y1\n self.y2 = y2\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.logical_or(umath.greater (x, self.y2),\n umath.less(x, self.y1)\n )\n\nclass domain_tan:\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n def __init__(self, eps):\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n self.eps = eps\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less(umath.absolute(umath.cos(x)), self.eps)\n\nclass domain_greater:\n \"domain_greater(v)(x) = true where x <= v\"\n def __init__(self, critical_value):\n \"domain_greater(v)(x) = true where x <= v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less_equal (x, self.critical_value)\n\nclass domain_greater_equal:\n \"domain_greater_equal(v)(x) = true where x < v\"\n def __init__(self, critical_value):\n \"domain_greater_equal(v)(x) = true where x < v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less (x, self.critical_value)\n\nclass masked_unary_operation:\n def __init__ (self, aufunc, fill=0, domain=None):\n \"\"\" masked_unary_operation(aufunc, fill=0, domain=None)\n aufunc(fill) must be defined\n self(x) returns aufunc(x)\n with masked values where domain(x) is true or getmask(x) is true.\n \"\"\"\n self.f = aufunc\n self.fill = fill\n self.domain = domain\n self.__doc__ = getattr(aufunc, \"__doc__\", str(aufunc))\n\n def __call__ (self, a, *args, **kwargs):\n \"Execute the call behavior.\"\n# numeric tries to return scalars rather than arrays when given scalars.\n m = getmask(a)\n d1 = filled(a, self.fill)\n if self.domain is not None:\n m = mask_or(m, self.domain(d1))\n result = self.f(d1, *args, **kwargs)\n if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\n\nclass domain_safe_divide:\n def __init__ (self, tolerance=divide_tolerance):\n self.tolerance = tolerance\n def __call__ (self, a, b):\n return umath.absolute(a) * self.tolerance >= umath.absolute(b)\n\nclass domained_binary_operation:\n \"\"\"Binary operations that have a domain, like divide. These are complicated so they\n are a separate class. They have no reduce, outer or accumulate.\n \"\"\"\n def __init__ (self, abfunc, domain, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.domain = domain\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__(self, a, b):\n \"Execute the call behavior.\"\n ma = getmask(a)\n mb = getmask(b)\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n t = self.domain(d1, d2)\n\n if oldnumeric.sometrue(t, None):\n d2 = where(t, self.filly, d2)\n mb = mask_or(mb, t)\n m = mask_or(ma, mb)\n result = self.f(d1, d2)\n if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n \n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nclass masked_binary_operation:\n def __init__ (self, abfunc, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__ (self, a, b, *args, **kwargs):\n \"Execute the call behavior.\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n result = self.f(d1, d2, *args, **kwargs)\n if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis with this function.\"\"\"\n m = getmask(target)\n t = filled(target, self.filly)\n if t.shape == ():\n t = t.reshape(1)\n if m is not nomask:\n m = make_mask(m, copy=1)\n m.shape = (1,)\n if m is nomask:\n return masked_array (self.f.reduce (t, axis))\n else:\n t = masked_array (t, m)\n t = self.f.reduce(filled(t, self.filly), axis)\n m = umath.logical_and.reduce(m, axis)\n if isinstance(t, ndarray):\n return masked_array(t, m, get_fill_value(target))\n elif m:\n return masked\n else:\n return t\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = self.f.outer(filled(a, self.fillx), filled(b, self.filly))\n return masked_array(d, m)\n\n def accumulate (self, target, axis=0):\n \"\"\"Accumulate target along axis after filling with y fill value.\"\"\"\n t = filled(target, self.filly)\n return masked_array (self.f.accumulate (t, axis))\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nsqrt = masked_unary_operation(umath.sqrt, 0.0, domain_greater_equal(0.0))\nlog = masked_unary_operation(umath.log, 1.0, domain_greater(0.0))\nlog10 = masked_unary_operation(umath.log10, 1.0, domain_greater(0.0))\nexp = masked_unary_operation(umath.exp)\nconjugate = masked_unary_operation(umath.conjugate)\nsin = masked_unary_operation(umath.sin)\ncos = masked_unary_operation(umath.cos)\ntan = masked_unary_operation(umath.tan, 0.0, domain_tan(1.e-35))\narcsin = masked_unary_operation(umath.arcsin, 0.0, domain_check_interval(-1.0, 1.0))\narccos = masked_unary_operation(umath.arccos, 0.0, domain_check_interval(-1.0, 1.0))\narctan = masked_unary_operation(umath.arctan)\n# Missing from numeric\narcsinh = masked_unary_operation(umath.arcsinh)\narccosh = masked_unary_operation(umath.arccosh)\narctanh = masked_unary_operation(umath.arctanh)\nsinh = masked_unary_operation(umath.sinh)\ncosh = masked_unary_operation(umath.cosh)\ntanh = masked_unary_operation(umath.tanh)\nabsolute = masked_unary_operation(umath.absolute)\nfabs = masked_unary_operation(umath.fabs)\nnegative = masked_unary_operation(umath.negative)\nnonzero = masked_unary_operation(oldnumeric.nonzero)\naround = masked_unary_operation(oldnumeric.round_)\nfloor = masked_unary_operation(umath.floor)\nceil = masked_unary_operation(umath.ceil)\nsometrue = masked_unary_operation(oldnumeric.sometrue)\nalltrue = masked_unary_operation(oldnumeric.alltrue, 1)\nlogical_not = masked_unary_operation(umath.logical_not)\n\nadd = masked_binary_operation(umath.add)\nsubtract = masked_binary_operation(umath.subtract)\nsubtract.reduce = None\nmultiply = masked_binary_operation(umath.multiply, 1, 1)\ndivide = domained_binary_operation(umath.divide, domain_safe_divide(), 0, 1)\ntrue_divide = domained_binary_operation(umath.true_divide, domain_safe_divide(), 0, 1)\nfloor_divide = domained_binary_operation(umath.floor_divide, domain_safe_divide(), 0, 1)\nremainder = domained_binary_operation(umath.remainder, domain_safe_divide(), 0, 1)\nfmod = domained_binary_operation(umath.fmod, domain_safe_divide(), 0, 1)\nhypot = masked_binary_operation(umath.hypot)\narctan2 = masked_binary_operation(umath.arctan2, 0.0, 1.0)\narctan2.reduce = None\nequal = masked_binary_operation(umath.equal)\nequal.reduce = None\nnot_equal = masked_binary_operation(umath.not_equal)\nnot_equal.reduce = None\nless_equal = masked_binary_operation(umath.less_equal)\nless_equal.reduce = None\ngreater_equal = masked_binary_operation(umath.greater_equal)\ngreater_equal.reduce = None\nless = masked_binary_operation(umath.less)\nless.reduce = None\ngreater = masked_binary_operation(umath.greater)\ngreater.reduce = None\nlogical_and = masked_binary_operation(umath.logical_and)\nlogical_or = masked_binary_operation(umath.logical_or)\nlogical_xor = masked_binary_operation(umath.logical_xor)\nbitwise_and = masked_binary_operation(umath.bitwise_and)\nbitwise_or = masked_binary_operation(umath.bitwise_or)\nbitwise_xor = masked_binary_operation(umath.bitwise_xor)\n\ndef rank (object):\n return oldnumeric.rank(filled(object))\n\ndef shape (object):\n return oldnumeric.shape(filled(object))\n\ndef size (object, axis=None):\n return oldnumeric.size(filled(object), axis)\n\nclass MaskedArray (object):\n \"\"\"Arrays with possibly masked values.\n Masked values of 1 exclude the corresponding element from \n any computation.\n\n Construction:\n x = array(data, dtype=None, copy=True, fortran=False,\n mask = nomask, fill_value=None)\n\n If copy=False, every effort is made not to copy the data:\n If data is a MaskedArray, and argument mask=nomask,\n then the candidate data is data.data and the\n mask used is data.mask. If data is a numeric array,\n it is used as the candidate raw data.\n If dtypechar is not None and\n is != data.dtypechar then a data copy is required.\n Otherwise, the candidate is used.\n\n If a data copy is required, raw data stored is the result of:\n numeric.array(data, dtype=dtypechar, copy=copy)\n\n If mask is nomask there are no masked values. Otherwise mask must\n be convertible to an array of booleans with the same shape as x.\n\n fill_value is used to fill in masked values when necessary,\n such as when printing and in method/function filled().\n The fill_value is not used for computation within this module.\n \"\"\"\n __array_priority__ = 10.1\n def __init__(self, data, dtype=None, copy=True, fortran=False, \n mask=nomask, fill_value=None):\n \"\"\"array(data, dtype=None, copy=True, fortran=False, mask=nomask, fill_value=None)\n If data already a numeric array, its dtype becomes the default value of dtype.\n \"\"\"\n tc = dtype\n need_data_copied = copy\n if isinstance(data, MaskedArray):\n c = data.data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n if mask is nomask:\n mask = data.mask\n elif mask is not nomask: #attempting to change the mask\n need_data_copied = True\n\n elif isinstance(data, ndarray):\n c = data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n else:\n need_data_copied = False #because I'll do it now\n c = numeric.array(data, dtype=tc, copy=True, fortran=fortran)\n\n if need_data_copied:\n if tc == ctc:\n self._data = numeric.array(c, dtype=tc, copy=True, fortran=fortran)\n else:\n self._data = c.astype(tc)\n else:\n self._data = c\n\n if mask is nomask:\n self._mask = nomask\n self._shared_mask = 0\n else:\n self._mask = make_mask (mask)\n if self._mask is nomask:\n self._shared_mask = 0\n else:\n self._shared_mask = (self._mask is mask)\n nm = size(self._mask)\n nd = size(self._data)\n if nm != nd:\n if nm == 1:\n self._mask = oldnumeric.resize(self._mask, self._data.shape)\n self._shared_mask = 0\n elif nd == 1:\n self._data = oldnumeric.resize(self._data, self._mask.shape)\n self._data.shape = self._mask.shape\n else:\n raise MAError, \"Mask and data not compatible.\"\n elif nm == 1 and shape(self._mask) != shape(self._data):\n self.unshare_mask()\n self._mask.shape = self._data.shape\n\n self.set_fill_value(fill_value)\n\n def __array__ (self, t = None):\n \"Special hook for numeric. Converts to numeric if possible.\"\n if self._mask is not nomask:\n if oldnumeric.ravel(self._mask).any():\n raise MAError, \\\n \"\"\"Cannot automatically convert masked array to numeric because data\n is masked in one or more locations.\n \"\"\"\n else: # Mask is all false\n # Optimize to avoid future invocations of this section.\n self._mask = nomask\n self._shared_mask = 0\n if t:\n return self._data.astype(t)\n else:\n return self._data\n\n def __array_wrap__ (self, array):\n \"\"\"Special hook for ufuncs. Converts to Masked array with\n the same mask as self.\"\"\"\n return MaskedArray(array, copy=False, mask=self._mask,\n fill_value = self._fill_value)\n \n def _get_shape(self):\n \"Return the current shape.\"\n return self._data.shape\n\n def _set_shape (self, newshape):\n \"Set the array's shape.\"\n self._data.shape = newshape\n if self._mask is not nomask:\n self._mask = self._mask.copy()\n self._mask.shape = newshape\n\n def _get_flat(self):\n \"\"\"Calculate the flat value.\n \"\"\"\n if self._mask is nomask:\n return masked_array(self._data.ravel(), mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.ravel(),\n mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_flat (self, value):\n \"x.flat = value\"\n y = self.ravel()\n y[:] = value\n\n def _get_real(self):\n \"Get the real part of a complex array.\"\n if self._mask is nomask:\n return masked_array(self._data.real, mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.real, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_real (self, value):\n \"x.real = value\"\n y = self.real\n y[...] = value\n\n def _get_imaginary(self):\n \"Get the imaginary part of a complex array.\"\n if self._mask is nomask:\n return masked_array(self._data.imag, mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.imag, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_imaginary (self, value):\n \"x.imaginary = value\"\n y = self.imaginary\n y[...] = value\n\n def __str__(self):\n \"\"\"Calculate the str representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n if masked_print_option.enabled():\n f = masked_print_option\n # XXX: Without the following special case masked\n # XXX: would print as \"[--]\", not \"--\". Can we avoid\n # XXX: checks for masked by choosing a different value\n # XXX: for the masked singleton? 2005-01-05 -- sasha\n if self is masked:\n return str(f)\n # convert to object array to make filled work\n self = self.astype(object)\n else:\n f = self.fill_value()\n res = self.filled(f)\n return str(res)\n\n def __repr__(self):\n \"\"\"Calculate the repr representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n with_mask = \"\"\"\\\narray(data =\n %(data)s,\n mask =\n %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n with_mask1 = \"\"\"\\\narray(data = %(data)s,\n mask = %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n without_mask = \"\"\"array(\n %(data)s)\"\"\"\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n\n n = len(self.shape)\n if self._mask is nomask:\n if n <=1:\n return without_mask1 % {'data':str(self.filled())}\n return without_mask % {'data':str(self.filled())}\n else:\n if n <=1:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n if self._mask is nomask:\n return without_mask % {'data':str(self.filled())}\n else:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n\n def __float__(self):\n \"Convert self to float.\"\n self.unmask()\n if self._mask is not nomask:\n raise MAError, 'Cannot convert masked element to a Python float.'\n return float(self.data.item())\n\n def __int__(self):\n \"Convert self to int.\"\n self.unmask()\n if self._mask is not nomask:\n raise MAError, 'Cannot convert masked element to a Python int.'\n return int(self.data.item())\n\n def __getitem__(self, i):\n \"Get item described by i. Not a copy as in previous versions.\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i]\n if m is nomask:\n return dout\n mi = m[i]\n if mi.size == 1:\n if mi: \n return masked\n else:\n return dout\n else:\n return masked_array(dout, mi, fill_value=self._fill_value)\n\n def __getslice__(self, i, j):\n \"Get slice described by i, j\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i:j]\n if m is nomask:\n return masked_array(dout, fill_value=self._fill_value)\n else:\n return masked_array(dout, mask = m[i:j], fill_value=self._fill_value)\n\n# --------\n# setitem and setslice notes\n# note that if value is masked, it means to mask those locations.\n# setting a value changes the mask to match the value in those locations.\n\n def __setitem__(self, index, value):\n \"Set item described by index. If value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, 'Cannot alter the masked element.'\n if value is masked:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n else:\n self.unshare_mask()\n self._mask[index] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[index] = value\n if m is nomask:\n if self._mask is not nomask:\n self.unshare_mask()\n self._mask[index] = False\n else:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = True\n else:\n self.unshare_mask()\n self._mask[index] = m\n\n def __setslice__(self, i, j, value):\n \"Set slice i:j; if value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, \"Cannot alter the 'masked' object.\"\n if value is masked:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n self._mask[i:j] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[i:j] = value\n if m is nomask:\n if self._mask is not nomask:\n self.unshare_mask()\n self._mask[i:j] = False\n else:\n if self._mask is nomask:\n self._mask = make_mask_none(self._data.shape)\n self._shared_mask = False\n self._mask[i:j] = m\n\n def __nonzero__(self):\n \"\"\"returns true if any element is non-zero or masked\n\n \"\"\"\n # XXX: This changes bool conversion logic from MA.\n # XXX: In MA bool(a) == len(a) != 0, but in numpy\n # XXX: scalars do not have len \n m = self._mask\n d = self._data\n return bool(m is not nomask and m.any()\n or d is not nomask and d.any())\n \n def __len__ (self):\n \"\"\"Return length of first dimension. This is weird but Python's\n slicing behavior depends on it.\"\"\"\n return len(self._data)\n\n def __and__(self, other):\n \"Return bitwise_and\"\n return bitwise_and(self, other)\n\n def __or__(self, other):\n \"Return bitwise_or\"\n return bitwise_or(self, other)\n\n def __xor__(self, other):\n \"Return bitwise_xor\"\n return bitwise_xor(self, other)\n\n __rand__ = __and__\n __ror__ = __or__\n __rxor__ = __xor__\n\n def __abs__(self):\n \"Return absolute(self)\"\n return absolute(self)\n\n def __neg__(self):\n \"Return negative(self)\"\n return negative(self)\n\n def __pos__(self):\n \"Return array(self)\"\n return array(self)\n\n def __add__(self, other):\n \"Return add(self, other)\"\n return add(self, other)\n\n __radd__ = __add__\n\n def __mod__ (self, other):\n \"Return remainder(self, other)\"\n return remainder(self, other)\n\n def __rmod__ (self, other):\n \"Return remainder(other, self)\"\n return remainder(other, self)\n\n def __lshift__ (self, n):\n return left_shift(self, n)\n\n def __rshift__ (self, n):\n return right_shift(self, n)\n\n def __sub__(self, other):\n \"Return subtract(self, other)\"\n return subtract(self, other)\n\n def __rsub__(self, other):\n \"Return subtract(other, self)\"\n return subtract(other, self)\n\n def __mul__(self, other):\n \"Return multiply(self, other)\"\n return multiply(self, other)\n\n __rmul__ = __mul__\n\n def __div__(self, other):\n \"Return divide(self, other)\"\n return divide(self, other)\n\n def __rdiv__(self, other):\n \"Return divide(other, self)\"\n return divide(other, self)\n\n def __truediv__(self, other):\n \"Return divide(self, other)\"\n return true_divide(self, other)\n\n def __rtruediv__(self, other):\n \"Return divide(other, self)\"\n return true_divide(other, self)\n\n def __floordiv__(self, other):\n \"Return divide(self, other)\"\n return floor_divide(self, other)\n\n def __rfloordiv__(self, other):\n \"Return divide(other, self)\"\n return floor_divide(other, self)\n\n def __pow__(self,other, third=None):\n \"Return power(self, other, third)\"\n return power(self, other, third)\n\n def __sqrt__(self):\n \"Return sqrt(self)\"\n return sqrt(self)\n\n def __iadd__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data += f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = add(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __imul__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data *= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = multiply(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __isub__(self, other):\n \"Subtract other from self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data -= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = subtract(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n\n\n def __idiv__(self, other):\n \"Divide self by other in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n mo = getmask(other)\n result = divide(self, masked_array(f, mask=mo))\n self._data = result.data\n dm = result.raw_mask()\n if dm is not self._mask:\n self._mask = dm\n self._shared_mask = 1\n return self\n\n def __eq__(self,other):\n return equal(self,other)\n\n def __ne__(self,other):\n return not_equal(self,other)\n\n def __lt__(self,other):\n return less(self,other)\n\n def __le__(self,other):\n return less_equal(self,other)\n\n def __gt__(self,other):\n return greater(self,other)\n\n def __ge__(self,other):\n return greater_equal(self,other)\n\n def astype (self, tc):\n \"return self as array of given type.\"\n d = self._data.astype(tc)\n return array(d, mask=self._mask)\n\n def byte_swapped(self):\n \"\"\"Returns the raw data field, byte_swapped. Included for consistency\n with numeric but doesn't make sense in this context.\n \"\"\"\n return self._data.byte_swapped()\n\n def compressed (self):\n \"A 1-D array of all the non-masked data.\"\n d = oldnumeric.ravel(self._data)\n if self._mask is nomask:\n return array(d)\n else:\n m = 1 - oldnumeric.ravel(self._mask)\n c = oldnumeric.compress(m, d)\n return array(c, copy=0)\n\n def count (self, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n m = self._mask\n s = self._data.shape\n ls = len(s)\n if m is nomask:\n if ls == 0:\n return 1\n if ls == 1:\n return s[0]\n if axis is None:\n return reduce(lambda x,y:x*y, s)\n else:\n n = s[axis]\n t = list(s)\n del t[axis]\n return ones(t) * n\n if axis is None:\n w = oldnumeric.ravel(m).astype(int) \n n1 = size(w)\n if n1 == 1:\n n2 = w[0]\n else:\n n2 = umath.add.reduce(w)\n return n1 - n2\n else:\n n1 = size(m, axis)\n n2 = sum(m.astype(int), axis)\n return n1 - n2\n\n def dot (self, other):\n \"s.dot(other) = innerproduct(s, other)\"\n return innerproduct(self, other)\n\n def fill_value(self):\n \"Get the current fill value.\"\n return self._fill_value\n\n def filled (self, fill_value=None):\n \"\"\"A numeric array with masked values filled. If fill_value is None,\n use self.fill_value().\n\n If mask is nomask, copy data only if not contiguous.\n Result is always a contiguous, numeric array.\n# Is contiguous really necessary now?\n \"\"\"\n d = self._data\n m = self._mask\n if m is nomask:\n if d.flags['CONTIGUOUS']:\n return d\n else:\n return d.copy()\n else:\n if fill_value is None:\n value = self._fill_value\n else:\n value = fill_value\n\n if self is masked:\n result = numeric.array(value).reshape(*d.shape)\n else:\n try:\n result = numeric.array(d, dtype=d.dtype, copy=1)\n result[m] = value\n except (TypeError, AttributeError):\n #ok, can't put that value in here\n value = numeric.array(value, dtype=object)\n d = d.astype(object)\n result = oldnumeric.choose(m, (d, value))\n except IndexError:\n #ok, if scalar\n if d.shape:\n raise\n elif m:\n result = numeric.array(value, dtype=d.dtype)\n else:\n result = d\n return result\n\n def ids (self):\n \"\"\"Return the ids of the data and mask areas\"\"\"\n return (id(self._data), id(self._mask))\n\n def iscontiguous (self):\n \"Is the data contiguous?\"\n return self._data.flags['CONTIGUOUS']\n\n def itemsize(self):\n \"Item size of each data item.\"\n return self._data.itemsize\n\n\n def outer(self, other):\n \"s.outer(other) = outerproduct(s, other)\"\n return outerproduct(self, other)\n\n def put (self, values):\n \"\"\"Set the non-masked entries of self to filled(values).\n No change to mask\n \"\"\"\n iota = numeric.arange(self.size)\n d = self._data\n if self._mask is nomask:\n ind = iota\n else:\n ind = oldnumeric.compress(1 - self._mask, iota)\n d[ind] = filled(values).astype(d.dtype)\n\n def putmask (self, values):\n \"\"\"Set the masked entries of self to filled(values).\n Mask changed to nomask.\n \"\"\"\n d = self._data\n if self._mask is not nomask:\n d[self._mask] = filled(values).astype(d.dtype)\n self._shared_mask = 0\n self._mask = nomask\n\n def ravel (self):\n \"\"\"Return a 1-D view of self.\"\"\"\n if self._mask is nomask:\n return masked_array(self._data.ravel())\n else:\n return masked_array(self._data.ravel(), self._mask.ravel())\n\n def raw_data (self):\n \"\"\" Obsolete; use data property instead.\n The raw data; portions may be meaningless.\n May be noncontiguous. Expert use only.\"\"\"\n return self._data\n data = property(fget=raw_data, \n doc=\"The data, but values at masked locations are meaningless.\")\n\n def raw_mask (self):\n \"\"\" Obsolete; use mask property instead.\n May be noncontiguous. Expert use only.\n \"\"\"\n return self._mask\n mask = property(fget=raw_mask, \n doc=\"The mask, may be nomask. Values where mask true are meaningless.\")\n\n def reshape (self, *s):\n \"\"\"This array reshaped to shape s\"\"\"\n d = self._data.reshape(*s)\n if self._mask is nomask:\n return masked_array(d)\n else:\n m = self._mask.reshape(*s)\n return masked_array(d, m)\n\n def set_fill_value (self, v=None):\n \"Set the fill value to v. Omit v to restore default.\"\n if v is None:\n v = default_fill_value (self.raw_data())\n self._fill_value = v\n\n def _get_size (self):\n return self._data.size\n size = property(fget=_get_size, doc=\"Number of elements in the array.\")\n## CHECK THIS: signature of numeric.array.size?\n \n def _get_dtypechar(self):\n return self._data.dtypechar\n dtypechar = property(fget=_get_dtypechar, doc=\"type character of the array.\")\n\n def _get_dtype(self):\n return self._data.dtype\n dtype = property(fget=_get_dtype, doc=\"type of the array elements.\")\n\n def item(self):\n \"Return Python scalar if possible.\"\n if self._mask is not nomask:\n m = oldnumeric.ravel(self._mask)\n try:\n if m[0]:\n return masked\n except IndexError:\n return masked\n return self._data.item()\n\n def tolist(self, fill_value=None):\n \"Convert to list\"\n return self.filled(fill_value).tolist()\n\n def tostring(self, fill_value=None):\n \"Convert to string\"\n return self.filled(fill_value).tostring()\n\n def unmask (self):\n \"Replace the mask by nomask if possible.\"\n if self._mask is nomask: return\n m = make_mask(self._mask, flag=1)\n if m is nomask:\n self._mask = nomask\n self._shared_mask = 0\n\n def unshare_mask (self):\n \"If currently sharing mask, make a copy.\"\n if self._shared_mask:\n self._mask = make_mask (self._mask, copy=1, flag=0)\n self._shared_mask = 0\n\n shape = property(_get_shape, _set_shape,\n doc = 'tuple giving the shape of the array')\n\n flat = property(_get_flat, _set_flat,\n doc = 'Access array in flat form.')\n\n real = property(_get_real, _set_real,\n doc = 'Access the real part of the array')\n\n imaginary = property(_get_imaginary, _set_imaginary,\n doc = 'Access the imaginary part of the array')\n\n imag = imaginary\n\n#end class MaskedArray\n\narray = MaskedArray\n\ndef isMaskedArray (x):\n \"Is x a masked array, that is, an instance of MaskedArray?\"\n return isinstance(x, MaskedArray)\n\nisarray = isMaskedArray\nisMA = isMaskedArray #backward compatibility\n\ndef allclose (a, b, fill_value=1, rtol=1.e-5, atol=1.e-8):\n \"\"\" Returns true if all components of a and b are equal\n subject to given tolerances.\n If fill_value is 1, masked values considered equal.\n If fill_value is 0, masked values considered unequal.\n The relative error rtol should be positive and << 1.0\n The absolute error atol comes into play for those elements\n of b that are very small or zero; it says how small a must be also.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a)\n d2 = filled(b)\n x = filled(array(d1, copy=0, mask=m), fill_value).astype(float)\n y = filled(array(d2, copy=0, mask=m), 1).astype(float)\n d = umath.less_equal(umath.absolute(x-y), atol + rtol * umath.absolute(y))\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n\ndef allequal (a, b, fill_value=1):\n \"\"\"\n True if all entries of a and b are equal, using\n fill_value as a truth value where either or both are masked.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n if m is nomask:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n elif fill_value:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n dm = array(d, mask=m, copy=0)\n return oldnumeric.alltrue(oldnumeric.ravel(filled(dm, 1)))\n else:\n return 0\n\ndef masked_values (data, value, rtol=1.e-5, atol=1.e-8, copy=1):\n \"\"\"\n masked_values(data, value, rtol=1.e-5, atol=1.e-8)\n Create a masked array; mask is nomask if possible.\n If copy==0, and otherwise possible, result\n may share data values with original array.\n Let d = filled(data, value). Returns d\n masked where abs(data-value)<= atol + rtol * abs(value)\n if d is of a floating point type. Otherwise returns\n masked_object(d, value, copy)\n \"\"\"\n abs = umath.absolute\n d = filled(data, value)\n if issubclass(d.dtype, numeric.floating):\n m = umath.less_equal(abs(d-value), atol+rtol*abs(value))\n m = make_mask(m, flag=1)\n return array(d, mask = m, copy=copy,\n fill_value=value)\n else:\n return masked_object(d, value, copy=copy)\n\ndef masked_object (data, value, copy=1):\n \"Create array masked where exactly data equal to value\"\n d = filled(data, value)\n dm = make_mask(umath.equal(d, value), flag=1)\n return array(d, mask=dm, copy=copy, fill_value=value)\n\ndef arrayrange(start, stop=None, step=1, dtype=None):\n \"\"\"Just like range() except it returns a array whose type can be specified\n by the keyword argument dtypechar.\n \"\"\"\n return array(numeric.arrayrange(start, stop, step, dtype))\n\narange = arrayrange\n\ndef fromstring (s, t):\n \"Construct a masked array from a string. Result will have no mask.\"\n return masked_array(numeric.fromstring(s, t))\n\ndef left_shift (a, n):\n \"Left shift n bits\"\n m = getmask(a)\n if m is nomask:\n d = umath.left_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.left_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef right_shift (a, n):\n \"Right shift n bits\"\n m = getmask(a)\n if m is nomask:\n d = umath.right_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.right_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef resize (a, new_shape):\n \"\"\"resize(a, new_shape) returns a new array with the specified shape.\n The original array's total size can be any size.\"\"\"\n m = getmask(a)\n if m is not nomask:\n m = oldnumeric.resize(m, new_shape)\n result = array(oldnumeric.resize(filled(a), new_shape), mask=m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n \"\"\"\n af = filled(a)\n if isinstance(repeats, types.IntType):\n repeats = tuple([repeats]*(shape(af)[axis]))\n\n m = getmask(a)\n if m is not nomask:\n m = oldnumeric.repeat(m, repeats, axis)\n d = oldnumeric.repeat(af, repeats, axis)\n result = masked_array(d, m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef identity(n):\n \"\"\"identity(n) returns the identity matrix of shape n x n.\n \"\"\"\n return array(numeric.identity(n))\n\ndef indices (dimensions, dtype=None):\n \"\"\"indices(dimensions,dtype=None) returns an array representing a grid\n of indices with row-only, and column-only variation.\n \"\"\"\n return array(numeric.indices(dimensions, dtype))\n\ndef zeros (shape, dtype=int):\n \"\"\"zeros(n, dtype=int) =\n an array of all zeros of the given length or shape.\"\"\"\n return array(numeric.zeros(shape, dtype))\n\ndef ones (shape, dtype=int):\n \"\"\"ones(n, dtype=int) =\n an array of all ones of the given length or shape.\"\"\"\n return array(numeric.ones(shape, dtype))\n\n\ndef count (a, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n a = masked_array(a)\n return a.count(axis)\n\ndef power (a, b, third=None):\n \"a**b\"\n if third is not None:\n raise MAError, \"3-argument power not supported.\"\n ma = getmask(a)\n mb = getmask(b)\n m = mask_or(ma, mb)\n fa = filled(a, 1)\n fb = filled(b, 1)\n if fb.dtypechar in typecodes[\"Integer\"]:\n return masked_array(umath.power(fa, fb), m)\n md = make_mask(umath.less_equal (fa, 0), flag=1)\n m = mask_or(m, md)\n if m is nomask:\n return masked_array(umath.power(fa, fb))\n else:\n fa = numeric.where(m, 1, fa)\n return masked_array(umath.power(fa, fb), m)\n\ndef masked_array (a, mask=nomask, fill_value=None):\n \"\"\"masked_array(a, mask=nomask) =\n array(a, mask=mask, copy=0, fill_value=fill_value)\n \"\"\"\n return array(a, mask=mask, copy=0, fill_value=fill_value)\n\nsum = add.reduce\nproduct = multiply.reduce\n\ndef average (a, axis=0, weights=None, returned = 0):\n \"\"\"average(a, axis=0, weights=None)\n Computes average along indicated axis.\n If axis is None, average over the entire array\n Inputs can be integer or floating types; result is of type float.\n\n If weights are given, result is sum(a*weights)/(sum(weights)*1.0)\n weights must have a's shape or be the 1-d with length the size\n of a in the given axis.\n\n If returned, return a tuple: the result and the sum of the weights\n or count of values. Results will have the same shape.\n\n masked values in the weights will be set to 0.0\n \"\"\"\n a = masked_array(a)\n mask = a.mask\n ash = a.shape\n if ash == ():\n ash = (1,)\n if axis is None:\n if mask is nomask:\n if weights is None:\n n = add.reduce(a.raw_data().ravel())\n d = reduce(lambda x, y: x * y, ash, 1.0)\n else:\n w = filled(weights, 0.0).ravel()\n n = umath.add.reduce(a.raw_data().ravel() * w)\n d = umath.add.reduce(w)\n del w\n else:\n if weights is None:\n n = add.reduce(a.ravel())\n w = oldnumeric.choose(mask, (1.0,0.0)).ravel()\n d = umath.add.reduce(w)\n del w\n else:\n w = array(filled(weights, 0.0), float, mask=mask).ravel()\n n = add.reduce(a.ravel() * w)\n d = add.reduce(w)\n del w\n else:\n if mask is nomask:\n if weights is None:\n d = ash[axis] * 1.0\n n = umath.add.reduce(a.raw_data(), axis)\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = numeric.array(w, float, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * ones(ash, float)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w, r\n else:\n raise ValueError, 'average: weights wrong shape.'\n else:\n if weights is None:\n n = add.reduce(a, axis)\n w = numeric.choose(mask, (1.0, 0.0))\n d = umath.add.reduce(w, axis)\n del w\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = array(w, float, mask=mask, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * masked_array(ones(ash, float), mask)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n else:\n raise ValueError, 'average: weights wrong shape.'\n del w\n #print n, d, repr(mask), repr(weights)\n if n is masked or d is masked: return masked\n result = divide (n, d)\n del n\n\n if isinstance(result, MaskedArray):\n result.unmask()\n if returned:\n if not isinstance(d, MaskedArray):\n d = masked_array(d)\n if not d.shape == result.shape:\n d = ones(result.shape, float) * d\n d.unmask()\n if returned:\n return result, d\n else:\n return result\n\ndef where (condition, x, y):\n \"\"\"where(condition, x, y) is x where condition is nonzero, y otherwise.\n condition must be convertible to an integer array.\n Answer is always the shape of condition.\n The type depends on x and y. It is integer if both x and y are\n the value masked.\n \"\"\"\n fc = filled(not_equal(condition,0), 0)\n if x is masked:\n xv = 0\n xm = 1\n else:\n xv = filled(x)\n xm = getmask(x)\n if xm is nomask: xm = 0\n if y is masked:\n yv = 0\n ym = 1\n else:\n yv = filled(y)\n ym = getmask(y)\n if ym is nomask: ym = 0\n d = numeric.choose(fc, (yv, xv))\n md = numeric.choose(fc, (ym, xm))\n m = getmask(condition)\n m = make_mask(mask_or(m, md), copy=0, flag=1)\n return masked_array(d, m)\n\ndef choose (indices, t):\n \"Returns array shaped like indices with elements chosen from t\"\n def fmask (x):\n if x is masked: return 1\n return filled(x)\n def nmask (x):\n if x is masked: return 1\n m = getmask(x)\n if m is nomask: return 0\n return m\n c = filled(indices,0)\n masks = [nmask(x) for x in t]\n a = [fmask(x) for x in t]\n d = numeric.choose(c, a)\n m = numeric.choose(c, masks)\n m = make_mask(mask_or(m, getmask(indices)), copy=0, flag=1)\n return masked_array(d, m)\n\ndef masked_where(condition, x, copy=1):\n \"\"\"Return x as an array masked where condition is true.\n Also masked where x or condition masked.\n \"\"\"\n cm = filled(condition,1)\n m = mask_or(getmask(x), cm)\n return array(filled(x), copy=copy, mask=m)\n\ndef masked_greater(x, value, copy=1):\n \"masked_greater(x, value) = x masked where x > value\"\n return masked_where(greater(x, value), x, copy)\n\ndef masked_greater_equal(x, value, copy=1):\n \"masked_greater_equal(x, value) = x masked where x >= value\"\n return masked_where(greater_equal(x, value), x, copy)\n\ndef masked_less(x, value, copy=1):\n \"masked_less(x, value) = x masked where x < value\"\n return masked_where(less(x, value), x, copy)\n\ndef masked_less_equal(x, value, copy=1):\n \"masked_less_equal(x, value) = x masked where x <= value\"\n return masked_where(less_equal(x, value), x, copy)\n\ndef masked_not_equal(x, value, copy=1):\n \"masked_not_equal(x, value) = x masked where x != value\"\n d = filled(x,0)\n c = umath.not_equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_equal(x, value, copy=1):\n \"\"\"masked_equal(x, value) = x masked where x == value\n For floating point consider masked_values(x, value) instead.\n \"\"\"\n d = filled(x,0)\n c = umath.equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_inside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are inside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d=filled(x, 0)\n c = umath.logical_and(umath.less_equal(d, v2), umath.greater_equal(d, v1))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef masked_outside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are outside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d = filled(x,0)\n c = umath.logical_or(umath.less(d, v1), umath.greater(d, v2))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef reshape (a, *newshape):\n \"Copy of a with a new shape.\"\n m = getmask(a)\n d = filled(a).reshape(*newshape)\n if m is nomask:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.reshape(m, *newshape))\n\ndef ravel (a):\n \"a as one-dimensional, may share data and mask\"\n m = getmask(a)\n d = oldnumeric.ravel(filled(a))\n if m is nomask:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.ravel(m))\n\ndef concatenate (arrays, axis=0):\n \"Concatenate the arrays along the given axis\"\n d = []\n for x in arrays:\n d.append(filled(x))\n d = numeric.concatenate(d, axis)\n for x in arrays:\n if getmask(x) is not nomask: break\n else:\n return masked_array(d)\n dm = []\n for x in arrays:\n dm.append(getmaskarray(x))\n dm = numeric.concatenate(dm, axis)\n return masked_array(d, mask=dm)\n\ndef take (a, indices, axis=0):\n \"take(a, indices, axis=0) returns selection of items from a.\"\n m = getmask(a)\n d = masked_array(a).raw_data()\n if m is nomask:\n return masked_array(numeric.take(d, indices, axis))\n else:\n return masked_array(numeric.take(d, indices, axis),\n mask = numeric.take(m, indices, axis))\n\ndef transpose(a, axes=None):\n \"transpose(a, axes=None) reorder dimensions per tuple axes\"\n m = getmask(a)\n d = filled(a)\n if m is nomask:\n return masked_array(numeric.transpose(d, axes))\n else:\n return masked_array(numeric.transpose(d, axes),\n mask = numeric.transpose(m, axes))\n\n\ndef put(a, indices, values):\n \"\"\"put(a, indices, values) sets storage-indexed locations to corresponding values.\n\n Values and indices are filled if necessary.\n\n \"\"\"\n d = a.raw_data()\n ind = filled(indices)\n v = filled(values)\n numeric.put (d, ind, v)\n m = getmask(a)\n if m is not nomask:\n a.unshare_mask()\n numeric.put(a.raw_mask(), ind, 0)\n\ndef putmask(a, mask, values):\n \"putmask(a, mask, values) sets a where mask is true.\"\n if mask is nomask:\n return\n numeric.putmask(a.raw_data(), mask, values)\n m = getmask(a)\n if m is nomask: return\n a.unshare_mask()\n numeric.putmask(a.raw_mask(), mask, 0)\n\ndef innerproduct(a,b):\n \"\"\"innerproduct(a,b) returns the dot product of two arrays, which has\n shape a.shape[:-1] + b.shape[:-1] with elements computed by summing the\n product of the elements from the last dimensions of a and b.\n Masked elements are replace by zeros.\n \"\"\"\n fa = filled(a, 0)\n fb = filled(b, 0)\n if len(fa.shape) == 0: fa.shape = (1,)\n if len(fb.shape) == 0: fb.shape = (1,)\n return masked_array(numeric.innerproduct(fa, fb))\n\ndef outerproduct(a, b):\n \"\"\"outerproduct(a,b) = {a[i]*b[j]}, has shape (len(a),len(b))\"\"\"\n fa = filled(a,0).ravel()\n fb = filled(b,0).ravel()\n d = numeric.outerproduct(fa, fb)\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n return masked_array(d)\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = make_mask(1-numeric.outerproduct(1-ma,1-mb), copy=0)\n return masked_array(d, m)\n\ndef dot(a, b):\n \"\"\"dot(a,b) returns matrix-multiplication between a and b. The product-sum\n is over the last dimension of a and the second-to-last dimension of b.\n Masked values are replaced by zeros. See also innerproduct.\n \"\"\"\n return innerproduct(filled(a,0), numeric.swapaxes(filled(b,0), -1, -2))\n\ndef compress(condition, x, dimension=-1):\n \"\"\"Select those parts of x for which condition is true.\n Masked values in condition are considered false.\n \"\"\"\n c = filled(condition, 0)\n m = getmask(x)\n if m is not nomask:\n m=numeric.compress(c, m, dimension)\n d = numeric.compress(c, filled(x), dimension)\n return masked_array(d, m)\n\nclass _minimum_operation:\n \"Object to calculate minima\"\n def __init__ (self):\n \"\"\"minimum(a, b) or minimum(a)\n In one argument case returns the scalar minimum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is nomask:\n d = amin(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amin(ac.raw_data())\n else:\n return where(less(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is nomask:\n t = filled(target)\n return masked_array (umath.minimum.reduce (t, axis))\n else:\n t = umath.minimum.reduce(filled(target, minimum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.minimum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nminimum = _minimum_operation ()\n\nclass _maximum_operation:\n \"Object to calculate maxima\"\n def __init__ (self):\n \"\"\"maximum(a, b) or maximum(a)\n In one argument case returns the scalar maximum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is nomask:\n d = amax(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amax(ac.raw_data())\n else:\n return where(greater(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is nomask:\n t = filled(target)\n return masked_array (umath.maximum.reduce (t, axis))\n else:\n t = umath.maximum.reduce(filled(target, maximum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.maximum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nmaximum = _maximum_operation ()\n\ndef sort (x, axis = -1, fill_value=None):\n \"\"\"If x does not have a mask, return a masked array formed from the\n result of numeric.sort(x, axis).\n Otherwise, fill x with fill_value. Sort it.\n Set a mask where the result is equal to fill_value.\n Note that this may have unintended consequences if the data contains the\n fill value at a non-masked site.\n\n If fill_value is not given the default fill value for x's type will be\n used.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n d = filled(x, fill_value)\n s = oldnumeric.sort(d, axis)\n if getmask(x) is nomask:\n return masked_array(s)\n return masked_values(s, fill_value, copy=0)\n\ndef diagonal(a, k = 0, axis1=0, axis2=1):\n \"\"\"diagonal(a,k=0,axis1=0, axis2=1) = the k'th diagonal of a\"\"\"\n d = oldnumeric.diagonal(filled(a), k, axis1, axis2)\n m = getmask(a)\n if m is nomask:\n return masked_array(d, m)\n else:\n return masked_array(d, oldnumeric.diagonal(m, k, axis1, axis2))\n\ndef argsort (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for sorting along given axis.\n if fill_value is None, use get_fill_value(x)\n Returns a numpy array.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argsort(d, axis)\n\ndef argmin (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return indices for minimum values along given axis.\n if fill_value is None, use get_fill_value(x).\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argmin(d, axis)\n\ndef argmax (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for maximum along given axis.\n if fill_value is None, use -get_fill_value(x) if it exists.\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n try:\n fill_value = - fill_value\n except:\n pass\n d = filled(x, fill_value)\n return oldnumeric.argmax(d, axis)\n\ndef fromfunction (f, s):\n \"\"\"apply f to s to create array as in umath.\"\"\"\n return masked_array(numeric.fromfunction(f,s))\n\ndef asarray(data, dtype=None):\n \"\"\"asarray(data, dtype) = array(data, dtype, copy=0)\n \"\"\"\n if isinstance(data, MaskedArray) and \\\n (dtype is None or dtype == data.dtype):\n return data\n return array(data, dtype=dtype, copy=0)\n\n# Add methods to support ndarray interface\n# XXX: I is better to to change the masked_*_operation adaptors\n# XXX: to wrap ndarray methods directly to create ma.array methods.\nfrom types import MethodType\ndef _m(f):\n return MethodType(f, None, array)\ndef not_implemented(*args, **kwds):\n raise NotImplementedError, \"not yet implemented for numpy.ma arrays\"\narray.all = _m(alltrue)\narray.any = _m(sometrue)\narray.argmax = _m(argmax)\narray.argmin = _m(argmin)\narray.argsort = _m(argsort)\narray.base = property(_m(not_implemented))\narray.byteswap = _m(not_implemented)\n\ndef _choose(self, *args):\n return choose(self, args)\narray.choose = _m(_choose)\ndel _choose\n\narray.clip = _m(not_implemented)\n\ndef _compress(self, cond, axis=None):\n return compress(cond, self, axis)\narray.compress = _m(_compress)\ndel _compress\n\narray.conj = array.conjugate = _m(conjugate)\narray.copy = _m(not_implemented)\narray.cumprod = _m(not_implemented)\narray.cumsum = _m(not_implemented)\narray.diagonal = _m(diagonal)\narray.dtypedescr = property(_m(not_implemented))\narray.dtypestr = property(_m(not_implemented))\narray.dump = _m(not_implemented)\narray.dumps = _m(not_implemented)\narray.fill = _m(not_implemented)\narray.flags = property(_m(not_implemented))\narray.flatten = _m(ravel)\narray.getfield = _m(not_implemented)\narray.max = _m(maximum)\narray.mean = _m(average)\narray.min = _m(minimum)\narray.nbytes = property(_m(not_implemented))\narray.ndim = _m(not_implemented)\narray.newbyteorder = _m(not_implemented)\narray.nonzero = _m(nonzero)\narray.prod = _m(product)\narray.ptp = _m(not_implemented)\narray.repeat = _m(repeat)\narray.resize = _m(resize)\narray.searchsorted = _m(not_implemented)\narray.setfield = _m(not_implemented)\narray.setflags = _m(not_implemented)\narray.sort = _m(not_implemented) # NB: ndarray.sort is inplace\narray.squeeze = _m(not_implemented)\narray.std = _m(not_implemented)\narray.strides = property(_m(not_implemented))\narray.sum = _m(sum)\narray.swapaxes = _m(not_implemented)\narray.take = _m(take)\narray.tofile = _m(not_implemented)\narray.trace = _m(not_implemented)\narray.transpose = _m(transpose)\narray.var = _m(not_implemented)\narray.view = _m(not_implemented)\ndel _m, MethodType, not_implemented\n\n\nmasked = MaskedArray(0, int, mask=1)\n", + "methods": [ + { + "name": "__init__", + "long_name": "__init__( self , args = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 25, + "end_line": 27, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 28, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , display )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "display" + ], + "start_line": 35, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "display", + "long_name": "display( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 40, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "set_display", + "long_name": "set_display( self , s )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "s" + ], + "start_line": 44, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enabled", + "long_name": "enabled( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 48, + "end_line": 50, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enable", + "long_name": "enable( self , flag = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "flag" + ], + "start_line": 52, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 56, + "end_line": 57, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "default_fill_value", + "long_name": "default_fill_value( obj )", + "filename": "ma.py", + "nloc": 25, + "complexity": 13, + "token_count": 144, + "parameters": [ + "obj" + ], + "start_line": 71, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "minimum_fill_value", + "long_name": "minimum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 105, + "parameters": [ + "obj" + ], + "start_line": 97, + "end_line": 112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "maximum_fill_value", + "long_name": "maximum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 103, + "parameters": [ + "obj" + ], + "start_line": 114, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( a , fill_value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 2, + "token_count": 20, + "parameters": [ + "a", + "fill_value" + ], + "start_line": 131, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "getmask", + "long_name": "getmask( a )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "a" + ], + "start_line": 136, + "end_line": 143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "getmaskarray", + "long_name": "getmaskarray( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 145, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "is_mask", + "long_name": "is_mask( m )", + "filename": "ma.py", + "nloc": 6, + "complexity": 4, + "token_count": 33, + "parameters": [ + "m" + ], + "start_line": 156, + "end_line": 163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "make_mask", + "long_name": "make_mask( m , copy = 0 , flag = 0 )", + "filename": "ma.py", + "nloc": 17, + "complexity": 7, + "token_count": 107, + "parameters": [ + "m", + "copy", + "flag" + ], + "start_line": 165, + "end_line": 188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "make_mask_none", + "long_name": "make_mask_none( s )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 25, + "parameters": [ + "s" + ], + "start_line": 190, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "mask_or", + "long_name": "mask_or( m1 , m2 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 5, + "token_count": 52, + "parameters": [ + "m1", + "m2" + ], + "start_line": 196, + "end_line": 203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "filled", + "long_name": "filled( a , value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 5, + "token_count": 70, + "parameters": [ + "a", + "value" + ], + "start_line": 205, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "get_fill_value", + "long_name": "get_fill_value( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 225, + "end_line": 234, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "common_fill_value", + "long_name": "common_fill_value( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a", + "b" + ], + "start_line": 236, + "end_line": 241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , y1 , y2 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "y1", + "y2" + ], + "start_line": 246, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 35, + "parameters": [ + "self", + "x" + ], + "start_line": 251, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , eps )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "eps" + ], + "start_line": 259, + "end_line": 261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "x" + ], + "start_line": 263, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 269, + "end_line": 271, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 273, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 279, + "end_line": 281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 283, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , aufunc , fill = 0 , domain = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "aufunc", + "fill", + "domain" + ], + "start_line": 288, + "end_line": 297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 16, + "complexity": 5, + "token_count": 112, + "parameters": [ + "self", + "a", + "args", + "kwargs" + ], + "start_line": 299, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 317, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , tolerance = divide_tolerance )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "tolerance" + ], + "start_line": 322, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 324, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , domain , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 53, + "parameters": [ + "self", + "abfunc", + "domain", + "fillx", + "filly" + ], + "start_line": 331, + "end_line": 339, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 147, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 341, + "end_line": 362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 364, + "end_line": 365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "abfunc", + "fillx", + "filly" + ], + "start_line": 368, + "end_line": 375, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 113, + "parameters": [ + "self", + "a", + "b", + "args", + "kwargs" + ], + "start_line": 377, + "end_line": 391, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 20, + "complexity": 6, + "token_count": 157, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 393, + "end_line": 413, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 415, + "end_line": 426, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "accumulate", + "long_name": "accumulate( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 428, + "end_line": 431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 432, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "rank", + "long_name": "rank( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 495, + "end_line": 496, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 498, + "end_line": 499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( object , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 21, + "parameters": [ + "object", + "axis" + ], + "start_line": 501, + "end_line": 502, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , data , dtype = None , copy = True , fortran = False , mask = nomask , fill_value = None )", + "filename": "ma.py", + "nloc": 56, + "complexity": 18, + "token_count": 379, + "parameters": [ + "self", + "data", + "dtype", + "copy", + "fortran", + "mask", + "fill_value" + ], + "start_line": 533, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "__array__", + "long_name": "__array__( self , t = None )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 67, + "parameters": [ + "self", + "t" + ], + "start_line": 597, + "end_line": 612, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__array_wrap__", + "long_name": "__array_wrap__( self , array )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "array" + ], + "start_line": 614, + "end_line": 618, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_shape", + "long_name": "_get_shape( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 620, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_set_shape", + "long_name": "_set_shape( self , newshape )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "newshape" + ], + "start_line": 624, + "end_line": 629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_get_flat", + "long_name": "_get_flat( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 631, + "end_line": 640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "_set_flat", + "long_name": "_set_flat( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "value" + ], + "start_line": 642, + "end_line": 645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_real", + "long_name": "_get_real( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 647, + "end_line": 654, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_real", + "long_name": "_set_real( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 656, + "end_line": 659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_imaginary", + "long_name": "_get_imaginary( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 661, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_imaginary", + "long_name": "_set_imaginary( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 670, + "end_line": 673, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 13, + "complexity": 6, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 675, + "end_line": 695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "ma.py", + "nloc": 42, + "complexity": 5, + "token_count": 207, + "parameters": [ + "self" + ], + "start_line": 697, + "end_line": 742, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 1 + }, + { + "name": "__float__", + "long_name": "__float__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 744, + "end_line": 749, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__int__", + "long_name": "__int__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 751, + "end_line": 756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , i )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 70, + "parameters": [ + "self", + "i" + ], + "start_line": 758, + "end_line": 772, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 774, + "end_line": 782, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__setitem__", + "long_name": "__setitem__( self , index , value )", + "filename": "ma.py", + "nloc": 27, + "complexity": 7, + "token_count": 157, + "parameters": [ + "self", + "index", + "value" + ], + "start_line": 789, + "end_line": 815, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "__setslice__", + "long_name": "__setslice__( self , i , j , value )", + "filename": "ma.py", + "nloc": 23, + "complexity": 7, + "token_count": 155, + "parameters": [ + "self", + "i", + "j", + "value" + ], + "start_line": 817, + "end_line": 839, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "__nonzero__", + "long_name": "__nonzero__( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 841, + "end_line": 851, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 853, + "end_line": 856, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__and__", + "long_name": "__and__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 858, + "end_line": 860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__or__", + "long_name": "__or__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 862, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__xor__", + "long_name": "__xor__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 866, + "end_line": 868, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__abs__", + "long_name": "__abs__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 874, + "end_line": 876, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__neg__", + "long_name": "__neg__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 878, + "end_line": 880, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pos__", + "long_name": "__pos__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 882, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__add__", + "long_name": "__add__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 886, + "end_line": 888, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mod__", + "long_name": "__mod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 892, + "end_line": 894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rmod__", + "long_name": "__rmod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 896, + "end_line": 898, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__lshift__", + "long_name": "__lshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 900, + "end_line": 901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__rshift__", + "long_name": "__rshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 903, + "end_line": 904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__sub__", + "long_name": "__sub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 906, + "end_line": 908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rsub__", + "long_name": "__rsub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 910, + "end_line": 912, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mul__", + "long_name": "__mul__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 914, + "end_line": 916, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__div__", + "long_name": "__div__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 920, + "end_line": 922, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rdiv__", + "long_name": "__rdiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 924, + "end_line": 926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__truediv__", + "long_name": "__truediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 928, + "end_line": 930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rtruediv__", + "long_name": "__rtruediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 932, + "end_line": 934, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__floordiv__", + "long_name": "__floordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 936, + "end_line": 938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rfloordiv__", + "long_name": "__rfloordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 940, + "end_line": 942, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pow__", + "long_name": "__pow__( self , other , third = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "other", + "third" + ], + "start_line": 944, + "end_line": 946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__sqrt__", + "long_name": "__sqrt__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 948, + "end_line": 950, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__iadd__", + "long_name": "__iadd__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 952, + "end_line": 993, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__imul__", + "long_name": "__imul__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 251, + "parameters": [ + "self", + "other" + ], + "start_line": 995, + "end_line": 1036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__isub__", + "long_name": "__isub__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 1038, + "end_line": 1079, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__idiv__", + "long_name": "__idiv__( self , other )", + "filename": "ma.py", + "nloc": 38, + "complexity": 12, + "token_count": 233, + "parameters": [ + "self", + "other" + ], + "start_line": 1083, + "end_line": 1120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 1 + }, + { + "name": "__eq__", + "long_name": "__eq__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1122, + "end_line": 1123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ne__", + "long_name": "__ne__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1125, + "end_line": 1126, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__lt__", + "long_name": "__lt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1128, + "end_line": 1129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__le__", + "long_name": "__le__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1131, + "end_line": 1132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__gt__", + "long_name": "__gt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1134, + "end_line": 1135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ge__", + "long_name": "__ge__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1137, + "end_line": 1138, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "astype", + "long_name": "astype( self , tc )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "tc" + ], + "start_line": 1140, + "end_line": 1143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "byte_swapped", + "long_name": "byte_swapped( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 1145, + "end_line": 1149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "compressed", + "long_name": "compressed( self )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 1151, + "end_line": 1159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "count", + "long_name": "count( self , axis = None )", + "filename": "ma.py", + "nloc": 29, + "complexity": 7, + "token_count": 173, + "parameters": [ + "self", + "axis" + ], + "start_line": 1161, + "end_line": 1189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "dot", + "long_name": "dot( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1191, + "end_line": 1193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "fill_value", + "long_name": "fill_value( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1195, + "end_line": 1197, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "filled", + "long_name": "filled( self , fill_value = None )", + "filename": "ma.py", + "nloc": 31, + "complexity": 9, + "token_count": 183, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1199, + "end_line": 1239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + }, + { + "name": "ids", + "long_name": "ids( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 1241, + "end_line": 1243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "iscontiguous", + "long_name": "iscontiguous( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 1245, + "end_line": 1247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "itemsize", + "long_name": "itemsize( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 1249, + "end_line": 1251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1254, + "end_line": 1256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "put", + "long_name": "put( self , values )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "values" + ], + "start_line": 1258, + "end_line": 1268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "putmask", + "long_name": "putmask( self , values )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "values" + ], + "start_line": 1270, + "end_line": 1278, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "ravel", + "long_name": "ravel( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 1280, + "end_line": 1285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "raw_data", + "long_name": "raw_data( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1287, + "end_line": 1291, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "raw_mask", + "long_name": "raw_mask( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1295, + "end_line": 1299, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "reshape", + "long_name": "reshape( self , * s )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self", + "s" + ], + "start_line": 1303, + "end_line": 1310, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( self , v = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self", + "v" + ], + "start_line": 1312, + "end_line": 1316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_size", + "long_name": "_get_size( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1318, + "end_line": 1319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtypechar", + "long_name": "_get_dtypechar( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1323, + "end_line": 1324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtype", + "long_name": "_get_dtype( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1327, + "end_line": 1328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "item", + "long_name": "item( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 4, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 1331, + "end_line": 1340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "tolist", + "long_name": "tolist( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1342, + "end_line": 1344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "tostring", + "long_name": "tostring( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1346, + "end_line": 1348, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "unmask", + "long_name": "unmask( self )", + "filename": "ma.py", + "nloc": 7, + "complexity": 3, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 1350, + "end_line": 1356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "unshare_mask", + "long_name": "unshare_mask( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 1358, + "end_line": 1362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "isMaskedArray", + "long_name": "isMaskedArray( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "x" + ], + "start_line": 1382, + "end_line": 1384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "allclose", + "long_name": "allclose( a , b , fill_value = 1 , rtol = 1 . e - 5 , atol = 1 . e - 8 )", + "filename": "ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 140, + "parameters": [ + "a", + "b", + "fill_value", + "rtol", + "atol" + ], + "start_line": 1389, + "end_line": 1404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "allequal", + "long_name": "allequal( a , b , fill_value = 1 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 3, + "token_count": 125, + "parameters": [ + "a", + "b", + "fill_value" + ], + "start_line": 1406, + "end_line": 1424, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "masked_values", + "long_name": "masked_values( data , value , rtol = 1 . e - 5 , atol = 1 . e - 8 , copy = 1 )", + "filename": "ma.py", + "nloc": 10, + "complexity": 2, + "token_count": 115, + "parameters": [ + "data", + "value", + "rtol", + "atol", + "copy" + ], + "start_line": 1426, + "end_line": 1445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "masked_object", + "long_name": "masked_object( data , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "data", + "value", + "copy" + ], + "start_line": 1447, + "end_line": 1451, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayrange", + "long_name": "arrayrange( start , stop = None , step = 1 , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 34, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 1453, + "end_line": 1457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "fromstring", + "long_name": "fromstring( s , t )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "s", + "t" + ], + "start_line": 1461, + "end_line": 1463, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "left_shift", + "long_name": "left_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1465, + "end_line": 1473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "right_shift", + "long_name": "right_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1475, + "end_line": 1483, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 1485, + "end_line": 1493, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 101, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 1495, + "end_line": 1510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "identity", + "long_name": "identity( n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "n" + ], + "start_line": 1512, + "end_line": 1515, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "indices", + "long_name": "indices( dimensions , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "dimensions", + "dtype" + ], + "start_line": 1517, + "end_line": 1521, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "zeros", + "long_name": "zeros( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1523, + "end_line": 1526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ones", + "long_name": "ones( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1528, + "end_line": 1531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "count", + "long_name": "count( a , axis = None )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a", + "axis" + ], + "start_line": 1534, + "end_line": 1537, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "power", + "long_name": "power( a , b , third = None )", + "filename": "ma.py", + "nloc": 18, + "complexity": 4, + "token_count": 152, + "parameters": [ + "a", + "b", + "third" + ], + "start_line": 1539, + "end_line": 1556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "masked_array", + "long_name": "masked_array( a , mask = nomask , fill_value = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "mask", + "fill_value" + ], + "start_line": 1558, + "end_line": 1562, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "average", + "long_name": "average( a , axis = 0 , weights = None , returned = 0 )", + "filename": "ma.py", + "nloc": 92, + "complexity": 22, + "token_count": 741, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 1567, + "end_line": 1674, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "where", + "long_name": "where( condition , x , y )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 149, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 1676, + "end_line": 1702, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "choose.fmask", + "long_name": "choose.fmask( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 2, + "token_count": 17, + "parameters": [ + "x" + ], + "start_line": 1706, + "end_line": 1708, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "choose.nmask", + "long_name": "choose.nmask( x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 3, + "token_count": 27, + "parameters": [ + "x" + ], + "start_line": 1709, + "end_line": 1713, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "choose", + "long_name": "choose( indices , t )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 93, + "parameters": [ + "indices", + "t" + ], + "start_line": 1704, + "end_line": 1720, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "masked_where", + "long_name": "masked_where( condition , x , copy = 1 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 47, + "parameters": [ + "condition", + "x", + "copy" + ], + "start_line": 1722, + "end_line": 1728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "masked_greater", + "long_name": "masked_greater( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1730, + "end_line": 1732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_greater_equal", + "long_name": "masked_greater_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1734, + "end_line": 1736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less", + "long_name": "masked_less( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1738, + "end_line": 1740, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less_equal", + "long_name": "masked_less_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1742, + "end_line": 1744, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_not_equal", + "long_name": "masked_not_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1746, + "end_line": 1751, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "masked_equal", + "long_name": "masked_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1753, + "end_line": 1760, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "masked_inside", + "long_name": "masked_inside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1762, + "end_line": 1773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "masked_outside", + "long_name": "masked_outside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1775, + "end_line": 1786, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , * newshape )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 56, + "parameters": [ + "a", + "newshape" + ], + "start_line": 1788, + "end_line": 1795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( a )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "a" + ], + "start_line": 1797, + "end_line": 1804, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "concatenate", + "long_name": "concatenate( arrays , axis = 0 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 5, + "token_count": 97, + "parameters": [ + "arrays", + "axis" + ], + "start_line": 1806, + "end_line": 1820, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 76, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 1822, + "end_line": 1830, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "a", + "axes" + ], + "start_line": 1832, + "end_line": 1840, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , indices , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 70, + "parameters": [ + "a", + "indices", + "values" + ], + "start_line": 1843, + "end_line": 1856, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 61, + "parameters": [ + "a", + "mask", + "values" + ], + "start_line": 1858, + "end_line": 1866, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "innerproduct", + "long_name": "innerproduct( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 3, + "token_count": 72, + "parameters": [ + "a", + "b" + ], + "start_line": 1868, + "end_line": 1878, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "outerproduct", + "long_name": "outerproduct( a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 110, + "parameters": [ + "a", + "b" + ], + "start_line": 1880, + "end_line": 1892, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dot", + "long_name": "dot( a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 36, + "parameters": [ + "a", + "b" + ], + "start_line": 1894, + "end_line": 1899, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , x , dimension = - 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 67, + "parameters": [ + "condition", + "x", + "dimension" + ], + "start_line": 1901, + "end_line": 1910, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1914, + "end_line": 1918, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1920, + "end_line": 1933, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1935, + "end_line": 1944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1946, + "end_line": 1957, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1963, + "end_line": 1967, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1969, + "end_line": 1982, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1984, + "end_line": 1993, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1995, + "end_line": 2006, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "sort", + "long_name": "sort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 8, + "complexity": 3, + "token_count": 68, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2010, + "end_line": 2027, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , k = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 73, + "parameters": [ + "a", + "k", + "axis1", + "axis2" + ], + "start_line": 2029, + "end_line": 2036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2038, + "end_line": 2045, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2047, + "end_line": 2055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 52, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2057, + "end_line": 2071, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "fromfunction", + "long_name": "fromfunction( f , s )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "f", + "s" + ], + "start_line": 2073, + "end_line": 2075, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( data , dtype = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 46, + "parameters": [ + "data", + "dtype" + ], + "start_line": 2077, + "end_line": 2083, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_m", + "long_name": "_m( f )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "f" + ], + "start_line": 2089, + "end_line": 2090, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "not_implemented", + "long_name": "not_implemented( * args , ** kwds )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "args", + "kwds" + ], + "start_line": 2091, + "end_line": 2092, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_choose", + "long_name": "_choose( self , * args )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 2101, + "end_line": 2102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_compress", + "long_name": "_compress( self , cond , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "cond", + "axis" + ], + "start_line": 2108, + "end_line": 2109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "__init__", + "long_name": "__init__( self , args = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 25, + "end_line": 27, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 28, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , display )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "display" + ], + "start_line": 35, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "display", + "long_name": "display( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 40, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "set_display", + "long_name": "set_display( self , s )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "s" + ], + "start_line": 44, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enabled", + "long_name": "enabled( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 48, + "end_line": 50, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enable", + "long_name": "enable( self , flag = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "flag" + ], + "start_line": 52, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 56, + "end_line": 57, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "default_fill_value", + "long_name": "default_fill_value( obj )", + "filename": "ma.py", + "nloc": 25, + "complexity": 13, + "token_count": 144, + "parameters": [ + "obj" + ], + "start_line": 71, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "minimum_fill_value", + "long_name": "minimum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 105, + "parameters": [ + "obj" + ], + "start_line": 97, + "end_line": 112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "maximum_fill_value", + "long_name": "maximum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 103, + "parameters": [ + "obj" + ], + "start_line": 114, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( a , fill_value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 2, + "token_count": 20, + "parameters": [ + "a", + "fill_value" + ], + "start_line": 131, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "getmask", + "long_name": "getmask( a )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "a" + ], + "start_line": 136, + "end_line": 143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "getmaskarray", + "long_name": "getmaskarray( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 145, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "is_mask", + "long_name": "is_mask( m )", + "filename": "ma.py", + "nloc": 6, + "complexity": 4, + "token_count": 33, + "parameters": [ + "m" + ], + "start_line": 156, + "end_line": 163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "make_mask", + "long_name": "make_mask( m , copy = 0 , flag = 0 )", + "filename": "ma.py", + "nloc": 17, + "complexity": 7, + "token_count": 107, + "parameters": [ + "m", + "copy", + "flag" + ], + "start_line": 165, + "end_line": 188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "make_mask_none", + "long_name": "make_mask_none( s )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 25, + "parameters": [ + "s" + ], + "start_line": 190, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "mask_or", + "long_name": "mask_or( m1 , m2 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 5, + "token_count": 52, + "parameters": [ + "m1", + "m2" + ], + "start_line": 196, + "end_line": 203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "filled", + "long_name": "filled( a , value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 5, + "token_count": 70, + "parameters": [ + "a", + "value" + ], + "start_line": 205, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "get_fill_value", + "long_name": "get_fill_value( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 225, + "end_line": 234, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "common_fill_value", + "long_name": "common_fill_value( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a", + "b" + ], + "start_line": 236, + "end_line": 241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , y1 , y2 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "y1", + "y2" + ], + "start_line": 246, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 35, + "parameters": [ + "self", + "x" + ], + "start_line": 251, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , eps )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "eps" + ], + "start_line": 259, + "end_line": 261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "x" + ], + "start_line": 263, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 269, + "end_line": 271, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 273, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 279, + "end_line": 281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 283, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , aufunc , fill = 0 , domain = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "aufunc", + "fill", + "domain" + ], + "start_line": 288, + "end_line": 297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 16, + "complexity": 5, + "token_count": 112, + "parameters": [ + "self", + "a", + "args", + "kwargs" + ], + "start_line": 299, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 317, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , tolerance = divide_tolerance )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "tolerance" + ], + "start_line": 322, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 324, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , domain , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 53, + "parameters": [ + "self", + "abfunc", + "domain", + "fillx", + "filly" + ], + "start_line": 331, + "end_line": 339, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 147, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 341, + "end_line": 362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 364, + "end_line": 365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "abfunc", + "fillx", + "filly" + ], + "start_line": 368, + "end_line": 375, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 113, + "parameters": [ + "self", + "a", + "b", + "args", + "kwargs" + ], + "start_line": 377, + "end_line": 391, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 20, + "complexity": 6, + "token_count": 157, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 393, + "end_line": 413, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 415, + "end_line": 426, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "accumulate", + "long_name": "accumulate( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 428, + "end_line": 431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 432, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "rank", + "long_name": "rank( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 495, + "end_line": 496, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 498, + "end_line": 499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( object , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 21, + "parameters": [ + "object", + "axis" + ], + "start_line": 501, + "end_line": 502, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , data , dtype = None , copy = True , fortran = False , mask = nomask , fill_value = None )", + "filename": "ma.py", + "nloc": 56, + "complexity": 18, + "token_count": 379, + "parameters": [ + "self", + "data", + "dtype", + "copy", + "fortran", + "mask", + "fill_value" + ], + "start_line": 533, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "__array__", + "long_name": "__array__( self , t = None )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 67, + "parameters": [ + "self", + "t" + ], + "start_line": 597, + "end_line": 612, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__array_wrap__", + "long_name": "__array_wrap__( self , array )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "array" + ], + "start_line": 614, + "end_line": 618, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_shape", + "long_name": "_get_shape( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 620, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_set_shape", + "long_name": "_set_shape( self , newshape )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "newshape" + ], + "start_line": 624, + "end_line": 629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_get_flat", + "long_name": "_get_flat( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 631, + "end_line": 640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "_set_flat", + "long_name": "_set_flat( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "value" + ], + "start_line": 642, + "end_line": 645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_real", + "long_name": "_get_real( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 647, + "end_line": 654, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_real", + "long_name": "_set_real( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 656, + "end_line": 659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_imaginary", + "long_name": "_get_imaginary( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 661, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_imaginary", + "long_name": "_set_imaginary( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 670, + "end_line": 673, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 3, + "token_count": 56, + "parameters": [ + "self" + ], + "start_line": 675, + "end_line": 692, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "ma.py", + "nloc": 42, + "complexity": 5, + "token_count": 207, + "parameters": [ + "self" + ], + "start_line": 694, + "end_line": 739, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 1 + }, + { + "name": "__float__", + "long_name": "__float__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 741, + "end_line": 746, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__int__", + "long_name": "__int__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 748, + "end_line": 753, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , i )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 70, + "parameters": [ + "self", + "i" + ], + "start_line": 755, + "end_line": 769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 771, + "end_line": 779, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__setitem__", + "long_name": "__setitem__( self , index , value )", + "filename": "ma.py", + "nloc": 27, + "complexity": 7, + "token_count": 157, + "parameters": [ + "self", + "index", + "value" + ], + "start_line": 786, + "end_line": 812, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "__setslice__", + "long_name": "__setslice__( self , i , j , value )", + "filename": "ma.py", + "nloc": 23, + "complexity": 7, + "token_count": 155, + "parameters": [ + "self", + "i", + "j", + "value" + ], + "start_line": 814, + "end_line": 836, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "__nonzero__", + "long_name": "__nonzero__( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 838, + "end_line": 848, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 850, + "end_line": 853, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__and__", + "long_name": "__and__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 855, + "end_line": 857, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__or__", + "long_name": "__or__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 859, + "end_line": 861, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__xor__", + "long_name": "__xor__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 863, + "end_line": 865, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__abs__", + "long_name": "__abs__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 871, + "end_line": 873, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__neg__", + "long_name": "__neg__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 875, + "end_line": 877, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pos__", + "long_name": "__pos__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 879, + "end_line": 881, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__add__", + "long_name": "__add__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 883, + "end_line": 885, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mod__", + "long_name": "__mod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 889, + "end_line": 891, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rmod__", + "long_name": "__rmod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 893, + "end_line": 895, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__lshift__", + "long_name": "__lshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 897, + "end_line": 898, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__rshift__", + "long_name": "__rshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 900, + "end_line": 901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__sub__", + "long_name": "__sub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 903, + "end_line": 905, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rsub__", + "long_name": "__rsub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 907, + "end_line": 909, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mul__", + "long_name": "__mul__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 911, + "end_line": 913, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__div__", + "long_name": "__div__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 917, + "end_line": 919, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rdiv__", + "long_name": "__rdiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 921, + "end_line": 923, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__truediv__", + "long_name": "__truediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 925, + "end_line": 927, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rtruediv__", + "long_name": "__rtruediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 929, + "end_line": 931, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__floordiv__", + "long_name": "__floordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 933, + "end_line": 935, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rfloordiv__", + "long_name": "__rfloordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 937, + "end_line": 939, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pow__", + "long_name": "__pow__( self , other , third = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "other", + "third" + ], + "start_line": 941, + "end_line": 943, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__sqrt__", + "long_name": "__sqrt__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 945, + "end_line": 947, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__iadd__", + "long_name": "__iadd__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 949, + "end_line": 990, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__imul__", + "long_name": "__imul__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 251, + "parameters": [ + "self", + "other" + ], + "start_line": 992, + "end_line": 1033, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__isub__", + "long_name": "__isub__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 1035, + "end_line": 1076, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__idiv__", + "long_name": "__idiv__( self , other )", + "filename": "ma.py", + "nloc": 38, + "complexity": 12, + "token_count": 233, + "parameters": [ + "self", + "other" + ], + "start_line": 1080, + "end_line": 1117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 1 + }, + { + "name": "__eq__", + "long_name": "__eq__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1119, + "end_line": 1120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ne__", + "long_name": "__ne__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1122, + "end_line": 1123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__lt__", + "long_name": "__lt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1125, + "end_line": 1126, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__le__", + "long_name": "__le__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1128, + "end_line": 1129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__gt__", + "long_name": "__gt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1131, + "end_line": 1132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ge__", + "long_name": "__ge__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1134, + "end_line": 1135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "astype", + "long_name": "astype( self , tc )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "tc" + ], + "start_line": 1137, + "end_line": 1140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "byte_swapped", + "long_name": "byte_swapped( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 1142, + "end_line": 1146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "compressed", + "long_name": "compressed( self )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 1148, + "end_line": 1156, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "count", + "long_name": "count( self , axis = None )", + "filename": "ma.py", + "nloc": 29, + "complexity": 7, + "token_count": 173, + "parameters": [ + "self", + "axis" + ], + "start_line": 1158, + "end_line": 1186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "dot", + "long_name": "dot( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1188, + "end_line": 1190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "fill_value", + "long_name": "fill_value( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1192, + "end_line": 1194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "filled", + "long_name": "filled( self , fill_value = None )", + "filename": "ma.py", + "nloc": 31, + "complexity": 9, + "token_count": 183, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1196, + "end_line": 1236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + }, + { + "name": "ids", + "long_name": "ids( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 1238, + "end_line": 1240, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "iscontiguous", + "long_name": "iscontiguous( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 1242, + "end_line": 1244, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "itemsize", + "long_name": "itemsize( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 1246, + "end_line": 1248, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1251, + "end_line": 1253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "put", + "long_name": "put( self , values )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "values" + ], + "start_line": 1255, + "end_line": 1265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "putmask", + "long_name": "putmask( self , values )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "values" + ], + "start_line": 1267, + "end_line": 1275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "ravel", + "long_name": "ravel( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 1277, + "end_line": 1282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "raw_data", + "long_name": "raw_data( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1284, + "end_line": 1288, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "raw_mask", + "long_name": "raw_mask( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1292, + "end_line": 1296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "reshape", + "long_name": "reshape( self , * s )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self", + "s" + ], + "start_line": 1300, + "end_line": 1307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( self , v = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self", + "v" + ], + "start_line": 1309, + "end_line": 1313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_size", + "long_name": "_get_size( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1315, + "end_line": 1316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtypechar", + "long_name": "_get_dtypechar( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1320, + "end_line": 1321, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtype", + "long_name": "_get_dtype( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1324, + "end_line": 1325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "item", + "long_name": "item( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 4, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 1328, + "end_line": 1337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "tolist", + "long_name": "tolist( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1339, + "end_line": 1341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "tostring", + "long_name": "tostring( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1343, + "end_line": 1345, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "unmask", + "long_name": "unmask( self )", + "filename": "ma.py", + "nloc": 7, + "complexity": 3, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 1347, + "end_line": 1353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "unshare_mask", + "long_name": "unshare_mask( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 1355, + "end_line": 1359, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "isMaskedArray", + "long_name": "isMaskedArray( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "x" + ], + "start_line": 1379, + "end_line": 1381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "allclose", + "long_name": "allclose( a , b , fill_value = 1 , rtol = 1 . e - 5 , atol = 1 . e - 8 )", + "filename": "ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 140, + "parameters": [ + "a", + "b", + "fill_value", + "rtol", + "atol" + ], + "start_line": 1386, + "end_line": 1401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "allequal", + "long_name": "allequal( a , b , fill_value = 1 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 3, + "token_count": 125, + "parameters": [ + "a", + "b", + "fill_value" + ], + "start_line": 1403, + "end_line": 1421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "masked_values", + "long_name": "masked_values( data , value , rtol = 1 . e - 5 , atol = 1 . e - 8 , copy = 1 )", + "filename": "ma.py", + "nloc": 10, + "complexity": 2, + "token_count": 115, + "parameters": [ + "data", + "value", + "rtol", + "atol", + "copy" + ], + "start_line": 1423, + "end_line": 1442, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "masked_object", + "long_name": "masked_object( data , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "data", + "value", + "copy" + ], + "start_line": 1444, + "end_line": 1448, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayrange", + "long_name": "arrayrange( start , stop = None , step = 1 , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 34, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 1450, + "end_line": 1454, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "fromstring", + "long_name": "fromstring( s , t )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "s", + "t" + ], + "start_line": 1458, + "end_line": 1460, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "left_shift", + "long_name": "left_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1462, + "end_line": 1470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "right_shift", + "long_name": "right_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1472, + "end_line": 1480, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 1482, + "end_line": 1490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 101, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 1492, + "end_line": 1507, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "identity", + "long_name": "identity( n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "n" + ], + "start_line": 1509, + "end_line": 1512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "indices", + "long_name": "indices( dimensions , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "dimensions", + "dtype" + ], + "start_line": 1514, + "end_line": 1518, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "zeros", + "long_name": "zeros( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1520, + "end_line": 1523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ones", + "long_name": "ones( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1525, + "end_line": 1528, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "count", + "long_name": "count( a , axis = None )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a", + "axis" + ], + "start_line": 1531, + "end_line": 1534, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "power", + "long_name": "power( a , b , third = None )", + "filename": "ma.py", + "nloc": 18, + "complexity": 4, + "token_count": 152, + "parameters": [ + "a", + "b", + "third" + ], + "start_line": 1536, + "end_line": 1553, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "masked_array", + "long_name": "masked_array( a , mask = nomask , fill_value = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "mask", + "fill_value" + ], + "start_line": 1555, + "end_line": 1559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "average", + "long_name": "average( a , axis = 0 , weights = None , returned = 0 )", + "filename": "ma.py", + "nloc": 92, + "complexity": 22, + "token_count": 741, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 1564, + "end_line": 1671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "where", + "long_name": "where( condition , x , y )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 149, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 1673, + "end_line": 1699, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "choose.fmask", + "long_name": "choose.fmask( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 2, + "token_count": 17, + "parameters": [ + "x" + ], + "start_line": 1703, + "end_line": 1705, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "choose.nmask", + "long_name": "choose.nmask( x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 3, + "token_count": 27, + "parameters": [ + "x" + ], + "start_line": 1706, + "end_line": 1710, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "choose", + "long_name": "choose( indices , t )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 93, + "parameters": [ + "indices", + "t" + ], + "start_line": 1701, + "end_line": 1717, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "masked_where", + "long_name": "masked_where( condition , x , copy = 1 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 47, + "parameters": [ + "condition", + "x", + "copy" + ], + "start_line": 1719, + "end_line": 1725, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "masked_greater", + "long_name": "masked_greater( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1727, + "end_line": 1729, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_greater_equal", + "long_name": "masked_greater_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1731, + "end_line": 1733, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less", + "long_name": "masked_less( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1735, + "end_line": 1737, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less_equal", + "long_name": "masked_less_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1739, + "end_line": 1741, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_not_equal", + "long_name": "masked_not_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1743, + "end_line": 1748, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "masked_equal", + "long_name": "masked_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1750, + "end_line": 1757, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "masked_inside", + "long_name": "masked_inside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1759, + "end_line": 1770, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "masked_outside", + "long_name": "masked_outside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1772, + "end_line": 1783, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , * newshape )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 56, + "parameters": [ + "a", + "newshape" + ], + "start_line": 1785, + "end_line": 1792, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( a )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "a" + ], + "start_line": 1794, + "end_line": 1801, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "concatenate", + "long_name": "concatenate( arrays , axis = 0 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 5, + "token_count": 97, + "parameters": [ + "arrays", + "axis" + ], + "start_line": 1803, + "end_line": 1817, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 76, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 1819, + "end_line": 1827, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "a", + "axes" + ], + "start_line": 1829, + "end_line": 1837, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , indices , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 70, + "parameters": [ + "a", + "indices", + "values" + ], + "start_line": 1840, + "end_line": 1853, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 61, + "parameters": [ + "a", + "mask", + "values" + ], + "start_line": 1855, + "end_line": 1863, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "innerproduct", + "long_name": "innerproduct( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 3, + "token_count": 72, + "parameters": [ + "a", + "b" + ], + "start_line": 1865, + "end_line": 1875, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "outerproduct", + "long_name": "outerproduct( a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 110, + "parameters": [ + "a", + "b" + ], + "start_line": 1877, + "end_line": 1889, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dot", + "long_name": "dot( a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 36, + "parameters": [ + "a", + "b" + ], + "start_line": 1891, + "end_line": 1896, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , x , dimension = - 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 67, + "parameters": [ + "condition", + "x", + "dimension" + ], + "start_line": 1898, + "end_line": 1907, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1911, + "end_line": 1915, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1917, + "end_line": 1930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1932, + "end_line": 1941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1943, + "end_line": 1954, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1960, + "end_line": 1964, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1966, + "end_line": 1979, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1981, + "end_line": 1990, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1992, + "end_line": 2003, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "sort", + "long_name": "sort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 8, + "complexity": 3, + "token_count": 68, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2007, + "end_line": 2024, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , k = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 73, + "parameters": [ + "a", + "k", + "axis1", + "axis2" + ], + "start_line": 2026, + "end_line": 2033, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2035, + "end_line": 2042, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2044, + "end_line": 2052, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 52, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2054, + "end_line": 2068, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "fromfunction", + "long_name": "fromfunction( f , s )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "f", + "s" + ], + "start_line": 2070, + "end_line": 2072, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( data , dtype = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 46, + "parameters": [ + "data", + "dtype" + ], + "start_line": 2074, + "end_line": 2080, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_m", + "long_name": "_m( f )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "f" + ], + "start_line": 2086, + "end_line": 2087, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "not_implemented", + "long_name": "not_implemented( * args , ** kwds )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "args", + "kwds" + ], + "start_line": 2088, + "end_line": 2089, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_choose", + "long_name": "_choose( self , * args )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 2098, + "end_line": 2099, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_compress", + "long_name": "_compress( self , cond , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "cond", + "axis" + ], + "start_line": 2105, + "end_line": 2106, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 13, + "complexity": 6, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 675, + "end_line": 695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + } + ], + "nloc": 1681, + "complexity": 458, + "token_count": 11697, + "diff_parsed": { + "added": [ + " m = self._mask", + " if m is not nomask and m.shape == () and m:", + " return str(f)" + ], + "deleted": [] + } + }, + { + "old_path": "numpy/core/tests/test_ma.py", + "new_path": "numpy/core/tests/test_ma.py", + "filename": "test_ma.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -605,6 +605,7 @@ def check_testScalarArithmetic(self):\n self.failUnless(xm.filled().dtype is xm.data.dtype)\n x = array(0, mask=0)\n self.failUnless(x.filled() is x.data)\n+ self.failUnlessEqual(str(xm), str(masked_print_option))\n \n def check_testArrayMethods(self):\n a = array([1,3,2])\n", + "added_lines": 1, + "deleted_lines": 0, + "source_code": "import numpy \nimport types, time\nfrom numpy.core.ma import *\nfrom numpy.testing import ScipyTestCase, ScipyTest\ndef eq(v,w):\n result = allclose(v,w)\n if not result:\n print \"\"\"Not eq:\n%s\n----\n%s\"\"\"% (str(v), str(w))\n return result\n\nclass test_ma(ScipyTestCase):\n def __init__(self, *args, **kwds):\n ScipyTestCase.__init__(self, *args, **kwds)\n self.setUp()\n \n def setUp (self):\n x=numpy.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])\n y=numpy.array([5.,0.,3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])\n a10 = 10.\n m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]\n m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0 ,0, 1]\n xm = array(x, mask=m1)\n ym = array(y, mask=m2)\n z = numpy.array([-.5, 0., .5, .8])\n zm = array(z, mask=[0,1,0,0])\n xf = numpy.where(m1, 1.e+20, x)\n s = x.shape\n xm.set_fill_value(1.e+20)\n self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf, s)\n\n def check_testBasic1d(self):\n \"Test of basic array creation and properties in 1 dimension.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual(xm.dtype, x.dtype)\n self.assertEqual(xm.dtypechar, x.dtypechar)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual(count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n\n def check_testBasic2d(self):\n \"Test of basic array creation and properties in 2 dimensions.\"\n for s in [(4,3), (6,2)]: \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n x.shape = s\n y.shape = s\n xm.shape = s\n ym.shape = s\n xf.shape = s\n \n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual( count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n self.setUp()\n\n def check_testArithmetic (self):\n \"Test of basic arithmetic.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n a2d = array([[1,2],[0,4]])\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n self.failUnless(eq (a2d * a2d, a2d * a2dm))\n self.failUnless(eq (a2d + a2d, a2d + a2dm))\n self.failUnless(eq (a2d - a2d, a2d - a2dm))\n for s in [(12,), (4,3), (2,6)]: \n x = x.reshape(s)\n y = y.reshape(s)\n xm = xm.reshape(s)\n ym = ym.reshape(s)\n xf = xf.reshape(s)\n self.failUnless(eq(-x, -xm))\n self.failUnless(eq(x + y, xm + ym))\n self.failUnless(eq(x - y, xm - ym))\n self.failUnless(eq(x * y, xm * ym))\n self.failUnless(eq(x / y, xm / ym))\n self.failUnless(eq(a10 + y, a10 + ym))\n self.failUnless(eq(a10 - y, a10 - ym))\n self.failUnless(eq(a10 * y, a10 * ym))\n self.failUnless(eq(a10 / y, a10 / ym))\n self.failUnless(eq(x + a10, xm + a10))\n self.failUnless(eq(x - a10, xm - a10))\n self.failUnless(eq(x * a10, xm * a10))\n self.failUnless(eq(x / a10, xm / a10))\n self.failUnless(eq(x**2, xm**2))\n self.failUnless(eq(abs(x)**2.5, abs(xm) **2.5))\n self.failUnless(eq(x**y, xm**ym))\n self.failUnless(eq(numpy.add(x,y), add(xm, ym)))\n self.failUnless(eq(numpy.subtract(x,y), subtract(xm, ym)))\n self.failUnless(eq(numpy.multiply(x,y), multiply(xm, ym)))\n self.failUnless(eq(numpy.divide(x,y), divide(xm, ym)))\n\n\n def check_testMixedArithmetic(self):\n na = numpy.array([1])\n ma = array([1])\n self.failUnless(isinstance(na + ma, MaskedArray))\n self.failUnless(isinstance(ma + na, MaskedArray))\n \n def check_testUfuncs1 (self):\n \"Test various functions such as sin, cos.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.cos(x), cos(xm)))\n self.failUnless (eq(numpy.cosh(x), cosh(xm)))\n self.failUnless (eq(numpy.sin(x), sin(xm)))\n self.failUnless (eq(numpy.sinh(x), sinh(xm)))\n self.failUnless (eq(numpy.tan(x), tan(xm)))\n self.failUnless (eq(numpy.tanh(x), tanh(xm)))\n self.failUnless (eq(numpy.sqrt(abs(x)), sqrt(xm)))\n self.failUnless (eq(numpy.log(abs(x)), log(xm)))\n self.failUnless (eq(numpy.log10(abs(x)), log10(xm)))\n self.failUnless (eq(numpy.exp(x), exp(xm)))\n self.failUnless (eq(numpy.arcsin(z), arcsin(zm)))\n self.failUnless (eq(numpy.arccos(z), arccos(zm)))\n self.failUnless (eq(numpy.arctan(z), arctan(zm)))\n self.failUnless (eq(numpy.arctan2(x, y), arctan2(xm, ym)))\n self.failUnless (eq(numpy.absolute(x), absolute(xm)))\n self.failUnless (eq(numpy.equal(x,y), equal(xm, ym)))\n self.failUnless (eq(numpy.not_equal(x,y), not_equal(xm, ym)))\n self.failUnless (eq(numpy.less(x,y), less(xm, ym)))\n self.failUnless (eq(numpy.greater(x,y), greater(xm, ym)))\n self.failUnless (eq(numpy.less_equal(x,y), less_equal(xm, ym)))\n self.failUnless (eq(numpy.greater_equal(x,y), greater_equal(xm, ym)))\n self.failUnless (eq(numpy.conjugate(x), conjugate(xm)))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,ym))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((x,y))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,y))))\n self.failUnless (eq(numpy.concatenate((x,y,x)), concatenate((x,ym,x))))\n \n def check_xtestCount (self):\n \"Test count\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless( isinstance(count(ott), types.IntType))\n self.assertEqual(3, count(ott))\n self.assertEqual(1, count(1))\n self.failUnless (eq(0, array(1,mask=[1])))\n ott=ott.reshape((2,2))\n assert isMaskedArray(count(ott,0))\n assert isinstance(count(ott), types.IntType)\n self.failUnless (eq(3, count(ott)))\n assert getmask(count(ott,0)) is None\n self.failUnless (eq([1,2],count(ott,0)))\n \n def check_testMinMax (self):\n \"Test minimum and maximum.\" \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n xr = numpy.ravel(x) #max doesn't work if shaped\n xmr = ravel(xm)\n self.failUnless (eq(max(xr), maximum(xmr))) #true because of careful selection of data\n self.failUnless (eq(min(xr), minimum(xmr))) #true because of careful selection of data\n\n def check_testAddSumProd (self):\n \"Test add, sum, product.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.add.reduce(x), add.reduce(x)))\n self.failUnless (eq(numpy.add.accumulate(x), add.accumulate(x)))\n self.failUnless (eq(4, sum(array(4))))\n self.failUnless (eq(4, sum(array(4), axis=0)))\n self.failUnless (eq(numpy.sum(x), sum(x)))\n self.failUnless (eq(numpy.sum(filled(xm,0)), sum(xm)))\n self.failUnless (eq(numpy.sum(x,0), sum(x,0)))\n self.failUnless (eq(numpy.product(x), product(x)))\n self.failUnless (eq(numpy.product(x,0), product(x,0)))\n self.failUnless (eq(numpy.product(filled(xm,1)), product(xm)))\n if len(s) > 1:\n self.failUnless (eq(numpy.concatenate((x,y),1), concatenate((xm,ym),1)))\n self.failUnless (eq(numpy.add.reduce(x,1), add.reduce(x,1)))\n self.failUnless (eq(numpy.sum(x,1), sum(x,1)))\n self.failUnless (eq(numpy.product(x,1), product(x,1)))\n \n \n def check_testCI(self):\n \"Test of conversions and indexing\"\n x1 = numpy.array([1,2,4,3])\n x2 = array(x1, mask = [1,0,0,0])\n x3 = array(x1, mask = [0,1,0,1])\n x4 = array(x1)\n # test conversion to strings\n junk, garbage = str(x2), repr(x2)\n assert eq(numpy.sort(x1),sort(x2, fill_value=0))\n # tests of indexing\n assert type(x2[1]) is type(x1[1])\n assert x1[1] == x2[1]\n assert x2[0] is masked\n assert eq(x1[2],x2[2])\n assert eq(x1[2:5],x2[2:5])\n assert eq(x1[:],x2[:])\n assert eq(x1[1:], x3[1:])\n x1[2]=9\n x2[2]=9\n assert eq(x1,x2)\n x1[1:3] = 99\n x2[1:3] = 99\n assert eq(x1,x2)\n x2[1] = masked\n assert eq(x1,x2)\n x2[1:3]=masked\n assert eq(x1,x2)\n x2[:] = x1\n x2[1] = masked\n assert allequal(getmask(x2),array([0,1,0,0]))\n x3[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x3), array([0,1,1,0]))\n x4[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x4), array([0,1,1,0]))\n assert allequal(x4, array([1,2,3,4]))\n x1 = numpy.arange(5)*1.0\n x2 = masked_values(x1, 3.0)\n assert eq(x1,x2)\n assert allequal(array([0,0,0,1,0],MaskType), x2.mask)\n assert eq(3.0, x2.fill_value())\n x1 = array([1,'hello',2,3],object)\n x2 = numpy.array([1,'hello',2,3],object)\n s1 = x1[1]\n s2 = x2[1]\n self.assertEqual(type(s2), str)\n self.assertEqual(type(s1), str)\n self.assertEqual(s1, s2)\n assert x1[1:1].shape == (0,)\n \n def check_testCopySize(self):\n \"Tests of some subtle points of copying and sizing.\"\n n = [0,0,1,0,0]\n m = make_mask(n)\n m2 = make_mask(m)\n self.failUnless(m is m2)\n m3 = make_mask(m, copy=1)\n self.failUnless(m is not m3)\n \n x1 = numpy.arange(5)\n y1 = array(x1, mask=m)\n self.failUnless( y1.raw_data() is not x1)\n self.failUnless( allequal(x1,y1.raw_data()))\n self.failUnless( y1.mask is m)\n \n y1a = array(y1, copy=0)\n self.failUnless( y1a.raw_data() is y1.raw_data())\n self.failUnless( y1a.mask is y1.mask)\n \n y2 = array(x1, mask=m, copy=0)\n self.failUnless( y2.raw_data() is x1)\n self.failUnless( y2.mask is m)\n self.failUnless( y2[2] is masked)\n y2[2]=9\n self.failUnless( y2[2] is not masked)\n self.failUnless( y2.mask is not m)\n self.failUnless( allequal(y2.mask, 0))\n \n y3 = array(x1*1.0, mask=m)\n self.failUnless(filled(y3).dtype is (x1*1.0).dtype)\n \n x4 = arange(4)\n x4[2] = masked\n y4 = resize(x4, (8,))\n self.failUnless( eq(concatenate([x4,x4]), y4))\n self.failUnless( eq(getmask(y4),[0,0,1,0,0,0,1,0]))\n y5 = repeat(x4, (2,2,2,2))\n self.failUnless( eq(y5, [0,0,1,1,2,2,3,3]))\n y6 = repeat(x4, 2)\n self.failUnless( eq(y5, y6))\n \n def check_testPut(self):\n \"Test of put\"\n d = arange(5)\n n = [0,0,0,1,1]\n m = make_mask(n)\n x = array(d, mask = m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n x[[1,4]] = [10,40]\n self.failUnless( x.mask is not m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is not masked)\n self.failUnless( eq(x, [0,10,2,-1,40]))\n \n x = array(d, mask = m) \n x.put([-1,100,200])\n self.failUnless( eq(x, [-1,100,200,0,0]))\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n \n x = array(d, mask = m) \n x.putmask([30,40])\n self.failUnless( eq(x, [0,1,2,30,40]))\n self.failUnless( x.mask is None)\n \n x = array(d, mask = m) \n y = x.compressed()\n z = array(x, mask = m)\n z.put(y)\n assert eq (x, z)\n \n def check_testMaPut(self):\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]\n i = numpy.nonzero(m)\n putmask(xm, m, z)\n assert take(xm, i) == z\n put(ym, i, zm)\n assert take(ym, i) == zm\n \n def check_testOddFeatures(self):\n \"Test of other odd features\"\n x = arange(20); x=x.reshape(4,5)\n x.flat[5] = 12\n assert x[1,0] == 12\n z = x + 10j * x\n assert eq(z.real, x)\n assert eq(z.imag, 10*x)\n assert eq((z*conjugate(z)).real, 101*x*x)\n z.imag[...] = 0.0\n \n x = arange(10)\n x[3] = masked\n assert str(x[3]) == str(masked)\n c = x >= 8\n assert count(where(c,masked,masked)) == 0\n assert shape(where(c,masked,masked)) == c.shape\n z = where(c , x, masked)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is masked\n assert z[7] is masked\n assert z[8] is not masked\n assert z[9] is not masked\n assert eq(x,z)\n z = where(c , masked, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n z = masked_where(c, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n assert eq(x,z)\n x = array([1.,2.,3.,4.,5.])\n c = array([1,1,1,0,0])\n x[2] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n c[0] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n assert eq(masked_where(greater(x, 2), x), masked_greater(x,2))\n assert eq(masked_where(greater_equal(x, 2), x), masked_greater_equal(x,2))\n assert eq(masked_where(less(x, 2), x), masked_less(x,2))\n assert eq(masked_where(less_equal(x, 2), x), masked_less_equal(x,2))\n assert eq(masked_where(not_equal(x, 2), x), masked_not_equal(x,2))\n assert eq(masked_where(equal(x, 2), x), masked_equal(x,2))\n assert eq(masked_where(not_equal(x,2), x), masked_not_equal(x,2))\n assert eq(masked_inside(range(5), 1, 3), [0, 199, 199, 199, 4])\n assert eq(masked_outside(range(5), 1, 3),[199,1,2,3,199])\n assert eq(masked_inside(array(range(5), mask=[1,0,0,0,0]), 1, 3).mask, [1,1,1,1,0])\n assert eq(masked_outside(array(range(5), mask=[0,1,0,0,0]), 1, 3).mask, [1,1,0,0,1])\n assert eq(masked_equal(array(range(5), mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,0])\n assert eq(masked_not_equal(array([2,2,1,2,1], mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,1])\n assert eq(masked_where([1,1,0,0,0], [1,2,3,4,5]), [99,99,3,4,5])\n atest = ones((10,10,10), dtype=float32)\n btest = zeros(atest.shape, MaskType)\n ctest = masked_where(btest,atest)\n assert eq(atest,ctest)\n z = choose(c, (-x, x))\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n x = arange(6)\n x[5] = masked\n y = arange(6)*10\n y[2]= masked\n c = array([1,1,1,0,0,0], mask=[1,0,0,0,0,0])\n cm = c.filled(1)\n z = where(c,x,y)\n zm = where(cm,x,y)\n assert eq(z, zm)\n assert getmask(zm) is None\n assert eq(zm, [0,1,2,30,40,50])\n z = where(c, masked, 1)\n assert eq(z, [99,99,99,1,1,1])\n z = where(c, 1, masked)\n assert eq(z, [99, 1, 1, 99, 99, 99])\n \n def check_testMinMax(self):\n \"Test of minumum, maximum.\" \n assert eq(minimum([1,2,3],[4,0,9]), [1,0,3])\n assert eq(maximum([1,2,3],[4,0,9]), [4,2,9])\n x = arange(5)\n y = arange(5) - 2\n x[3] = masked\n y[0] = masked\n assert eq(minimum(x,y), where(less(x,y), x, y))\n assert eq(maximum(x,y), where(greater(x,y), x, y))\n assert minimum(x) == 0\n assert maximum(x) == 4\n \n def check_testTakeTransposeInnerOuter(self):\n \"Test of take, transpose, inner, outer products\"\n x = arange(24)\n y = numpy.arange(24)\n x[5:6] = masked\n x=x.reshape(2,3,4)\n y=y.reshape(2,3,4)\n assert eq(numpy.transpose(y,(2,0,1)), transpose(x,(2,0,1)))\n assert eq(numpy.take(y, (2,0,1), 1), take(x, (2,0,1), 1))\n assert eq(numpy.innerproduct(filled(x,0),filled(y,0)),\n innerproduct(x, y))\n assert eq(numpy.outerproduct(filled(x,0),filled(y,0)),\n outerproduct(x, y))\n y = array(['abc', 1, 'def', 2, 3], object)\n y[2] = masked\n t = take(y,[0,3,4])\n assert t[0] == 'abc'\n assert t[1] == 2\n assert t[2] == 3\n \n def check_testInplace(self):\n \"\"\"Test of inplace operations and rich comparisons\"\"\"\n y = arange(10)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x += 1\n assert eq(x, y+1)\n xm += 1\n assert eq(x, y+1)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x -= 1\n assert eq(x, y-1)\n xm -= 1\n assert eq(xm, y-1)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x *= 2.0\n assert eq(x, y*2)\n xm *= 2.0\n assert eq(xm, y*2)\n \n x = arange(10)*2\n xm = arange(10)\n xm[2] = masked\n x /= 2\n assert eq(x, y)\n xm /= 2\n assert eq(x, y)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x /= 2.0\n assert eq(x, y/2.0)\n xm /= arange(10)\n assert eq(xm, ones((10,)))\n \n x = arange(10).astype(float32)\n xm = arange(10)\n xm[2] = masked\n id1 = id(x.raw_data())\n x += 1.\n assert id1 == id(x.raw_data())\n assert eq(x, y+1.)\n \n def check_testPickle(self):\n \"Test of pickling\"\n x = arange(12)\n x[4:10:2] = masked\n x=x.reshape(4,3)\n f = open('test9.pik','wb')\n import pickle\n pickle.dump(x, f)\n f.close()\n f = open('test9.pik', 'rb')\n y = pickle.load(f)\n assert eq(x,y) \n \n def check_testMasked(self):\n \"Test of masked element\"\n xx=arange(6)\n xx[1] = masked\n self.failUnless(str(masked) == '--')\n self.failUnless(xx[1] is masked)\n # don't know why these should raise an exception...\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, masked)\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, 2)\n self.failUnlessRaises(Exception, lambda x,y: x+y, masked, xx)\n self.failUnlessRaises(Exception, lambda x,y: x+y, xx, masked)\n \n def check_testAverage1(self):\n \"Test of average.\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless(eq(2.0, average(ott)))\n self.failUnless(eq(2.0, average(ott, weights=[1., 1., 2., 1.])))\n result, wts = average(ott, weights=[1.,1.,2.,1.], returned=1)\n self.failUnless(eq(2.0, result))\n self.failUnless(wts == 4.0)\n ott[:] = masked\n self.failUnless(average(ott) is masked)\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n ott=ott.reshape(2,2)\n ott[:,1] = masked\n self.failUnless(eq(average(ott), [2.0, 0.0]))\n self.failUnless(average(ott,axis=1)[0] is masked)\n self.failUnless(eq([2.,0.], average(ott)))\n result, wts = average(ott, returned=1)\n self.failUnless(eq(wts, [1., 0.]))\n\n def check_testAverage2(self):\n \"More tests of average.\"\n w1 = [0,1,1,1,1,0]\n w2 = [[0,1,1,1,1,0],[1,0,0,0,0,1]]\n x=arange(6)\n self.failUnless(allclose(average(x), 2.5))\n self.failUnless(allclose(average(x, weights=w1), 2.5))\n y=array([arange(6), 2.0*arange(6)])\n self.failUnless(allclose(average(y, None), numpy.add.reduce(numpy.arange(6))*3./12.))\n self.failUnless(allclose(average(y, axis=0), numpy.arange(6) * 3./2.))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n self.failUnless(allclose(average(y, None, weights=w2), 20./6.))\n self.failUnless(allclose(average(y, axis=0, weights=w2), [0.,1.,2.,3.,4.,10.]))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n m1 = zeros(6)\n m2 = [0,0,1,1,0,0]\n m3 = [[0,0,1,1,0,0],[0,1,1,1,1,0]]\n m4 = ones(6)\n m5 = [0, 1, 1, 1, 1, 1]\n self.failUnless(allclose(average(masked_array(x, m1)), 2.5))\n self.failUnless(allclose(average(masked_array(x, m2)), 2.5))\n self.failUnless(average(masked_array(x, m4)) is masked)\n self.assertEqual(average(masked_array(x, m5)), 0.0)\n self.assertEqual(count(average(masked_array(x, m4))), 0)\n z = masked_array(y, m3)\n self.failUnless(allclose(average(z, None), 20./6.))\n self.failUnless(allclose(average(z, axis=0), [0.,1.,99.,99.,4.0, 7.5]))\n self.failUnless(allclose(average(z, axis=1), [2.5, 5.0]))\n self.failUnless(allclose( average(z,weights=w2), [0.,1., 99., 99., 4.0, 10.0]))\n \n a = arange(6)\n b = arange(6) * 3\n r1, w1 = average([[a,b],[b,a]], axis=1, returned=1)\n self.assertEqual(shape(r1) , shape(w1))\n self.assertEqual(r1.shape , w1.shape)\n r2, w2 = average(ones((2,2,3)), axis=0, weights=[3,1], returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), weights=ones((2,2,3)), returned=1)\n self.failUnless(shape(w2) == shape(r2))\n a2d = array([[1,2],[0,4]], float)\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n a2da = average(a2d)\n self.failUnless(eq (a2da, [0.5, 3.0]))\n a2dma = average(a2dm)\n self.failUnless(eq( a2dma, [1.0, 3.0]))\n a2dma = average(a2dm, axis=None)\n self.failUnless(eq(a2dma, 7./3.))\n a2dma = average(a2dm, axis=1)\n self.failUnless(eq(a2dma, [1.5, 4.0]))\n\n def check_testToPython(self):\n self.assertEqual(1, int(array(1)))\n self.assertEqual(1.0, float(array(1)))\n self.assertEqual(1, int(array([[[1]]])))\n self.assertEqual(1.0, float(array([[1]])))\n self.failUnlessRaises(ValueError, float, array([1,1]))\n self.failUnlessRaises(MAError, float, array([1],mask=[1]))\n self.failUnless(bool(array([0,1])))\n self.failUnless(bool(array([0,0],mask=[0,1])))\n self.failIf(bool(array([0,0])))\n self.failIf(bool(array([0,0],mask=[0,0])))\n\n def check_testScalarArithmetic(self):\n xm = array(0, mask=1)\n self.failUnless((1/array(0)).mask)\n self.failUnless((1 + xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless(maximum(xm, xm).mask)\n self.failUnless(minimum(xm, xm).mask)\n self.failUnless(xm.filled().dtype is xm.data.dtype)\n x = array(0, mask=0)\n self.failUnless(x.filled() is x.data)\n self.failUnlessEqual(str(xm), str(masked_print_option))\n\n def check_testArrayMethods(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnless(eq(a.any(), a.data.any()))\n self.failUnless(eq(a.all(), a.data.all()))\n self.failUnless(eq(a.argmax(), a.data.argmax()))\n self.failUnless(eq(a.argmin(), a.data.argmin()))\n self.failUnless(eq(a.choose(0,1,2,3,4), a.data.choose(0,1,2,3,4)))\n self.failUnless(eq(a.compress([1,0,1]), a.data.compress([1,0,1])))\n self.failUnless(eq(a.conj(), a.data.conj()))\n self.failUnless(eq(a.conjugate(), a.data.conjugate()))\n m = array([[1,2],[3,4]])\n self.failUnless(eq(m.diagonal(), m.data.diagonal()))\n self.failUnless(eq(a.sum(), a.data.sum()))\n self.failUnless(eq(a.take([1,2]), a.data.take([1,2])))\n self.failUnless(eq(m.transpose(), m.data.transpose()))\n \n def check_testAPI(self):\n self.failIf([m for m in dir(numpy.ndarray)\n if m not in dir(array) and not m.startswith('_')])\n\n def check_testSingleElementSubscript(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnlessEqual(a[0].shape, ())\n self.failUnlessEqual(b[0].shape, ())\n self.failUnlessEqual(b[1].shape, ())\n\n \ndef timingTest():\n for f in [testf, testinplace]:\n for n in [1000,10000,50000]:\n t = testta(n, f)\n t1 = testtb(n, f)\n t2 = testtc(n, f)\n print f.test_name\n print \"\"\"\\\nn = %7d \nnumpy time (ms) %6.1f \nMA maskless ratio %6.1f\nMA masked ratio %6.1f\n\"\"\" % (n, t*1000.0, t1/t, t2/t)\n\ndef testta(n, f):\n x=numpy.arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtb(n, f):\n x=arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtc(n, f):\n x=arange(n) + 1.0\n x[0] = masked\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testf(x):\n for i in range(25):\n y = x **2 + 2.0 * x - 1.0\n w = x **2 + 1.0\n z = (y / w) ** 2\n return z\ntestf.test_name = 'Simple arithmetic'\n\ndef testinplace(x):\n for i in range(25):\n y = x**2\n y += 2.0*x\n y -= 1.0\n y /= x\n return y\ntestinplace.test_name = 'Inplace operations'\n\nif __name__ == \"__main__\":\n ScipyTest('numpy.core.ma').run() \n #timingTest()\n", + "source_code_before": "import numpy \nimport types, time\nfrom numpy.core.ma import *\nfrom numpy.testing import ScipyTestCase, ScipyTest\ndef eq(v,w):\n result = allclose(v,w)\n if not result:\n print \"\"\"Not eq:\n%s\n----\n%s\"\"\"% (str(v), str(w))\n return result\n\nclass test_ma(ScipyTestCase):\n def __init__(self, *args, **kwds):\n ScipyTestCase.__init__(self, *args, **kwds)\n self.setUp()\n \n def setUp (self):\n x=numpy.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])\n y=numpy.array([5.,0.,3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])\n a10 = 10.\n m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]\n m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0 ,0, 1]\n xm = array(x, mask=m1)\n ym = array(y, mask=m2)\n z = numpy.array([-.5, 0., .5, .8])\n zm = array(z, mask=[0,1,0,0])\n xf = numpy.where(m1, 1.e+20, x)\n s = x.shape\n xm.set_fill_value(1.e+20)\n self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf, s)\n\n def check_testBasic1d(self):\n \"Test of basic array creation and properties in 1 dimension.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual(xm.dtype, x.dtype)\n self.assertEqual(xm.dtypechar, x.dtypechar)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual(count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n\n def check_testBasic2d(self):\n \"Test of basic array creation and properties in 2 dimensions.\"\n for s in [(4,3), (6,2)]: \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n x.shape = s\n y.shape = s\n xm.shape = s\n ym.shape = s\n xf.shape = s\n \n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual( count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n self.setUp()\n\n def check_testArithmetic (self):\n \"Test of basic arithmetic.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n a2d = array([[1,2],[0,4]])\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n self.failUnless(eq (a2d * a2d, a2d * a2dm))\n self.failUnless(eq (a2d + a2d, a2d + a2dm))\n self.failUnless(eq (a2d - a2d, a2d - a2dm))\n for s in [(12,), (4,3), (2,6)]: \n x = x.reshape(s)\n y = y.reshape(s)\n xm = xm.reshape(s)\n ym = ym.reshape(s)\n xf = xf.reshape(s)\n self.failUnless(eq(-x, -xm))\n self.failUnless(eq(x + y, xm + ym))\n self.failUnless(eq(x - y, xm - ym))\n self.failUnless(eq(x * y, xm * ym))\n self.failUnless(eq(x / y, xm / ym))\n self.failUnless(eq(a10 + y, a10 + ym))\n self.failUnless(eq(a10 - y, a10 - ym))\n self.failUnless(eq(a10 * y, a10 * ym))\n self.failUnless(eq(a10 / y, a10 / ym))\n self.failUnless(eq(x + a10, xm + a10))\n self.failUnless(eq(x - a10, xm - a10))\n self.failUnless(eq(x * a10, xm * a10))\n self.failUnless(eq(x / a10, xm / a10))\n self.failUnless(eq(x**2, xm**2))\n self.failUnless(eq(abs(x)**2.5, abs(xm) **2.5))\n self.failUnless(eq(x**y, xm**ym))\n self.failUnless(eq(numpy.add(x,y), add(xm, ym)))\n self.failUnless(eq(numpy.subtract(x,y), subtract(xm, ym)))\n self.failUnless(eq(numpy.multiply(x,y), multiply(xm, ym)))\n self.failUnless(eq(numpy.divide(x,y), divide(xm, ym)))\n\n\n def check_testMixedArithmetic(self):\n na = numpy.array([1])\n ma = array([1])\n self.failUnless(isinstance(na + ma, MaskedArray))\n self.failUnless(isinstance(ma + na, MaskedArray))\n \n def check_testUfuncs1 (self):\n \"Test various functions such as sin, cos.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.cos(x), cos(xm)))\n self.failUnless (eq(numpy.cosh(x), cosh(xm)))\n self.failUnless (eq(numpy.sin(x), sin(xm)))\n self.failUnless (eq(numpy.sinh(x), sinh(xm)))\n self.failUnless (eq(numpy.tan(x), tan(xm)))\n self.failUnless (eq(numpy.tanh(x), tanh(xm)))\n self.failUnless (eq(numpy.sqrt(abs(x)), sqrt(xm)))\n self.failUnless (eq(numpy.log(abs(x)), log(xm)))\n self.failUnless (eq(numpy.log10(abs(x)), log10(xm)))\n self.failUnless (eq(numpy.exp(x), exp(xm)))\n self.failUnless (eq(numpy.arcsin(z), arcsin(zm)))\n self.failUnless (eq(numpy.arccos(z), arccos(zm)))\n self.failUnless (eq(numpy.arctan(z), arctan(zm)))\n self.failUnless (eq(numpy.arctan2(x, y), arctan2(xm, ym)))\n self.failUnless (eq(numpy.absolute(x), absolute(xm)))\n self.failUnless (eq(numpy.equal(x,y), equal(xm, ym)))\n self.failUnless (eq(numpy.not_equal(x,y), not_equal(xm, ym)))\n self.failUnless (eq(numpy.less(x,y), less(xm, ym)))\n self.failUnless (eq(numpy.greater(x,y), greater(xm, ym)))\n self.failUnless (eq(numpy.less_equal(x,y), less_equal(xm, ym)))\n self.failUnless (eq(numpy.greater_equal(x,y), greater_equal(xm, ym)))\n self.failUnless (eq(numpy.conjugate(x), conjugate(xm)))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,ym))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((x,y))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,y))))\n self.failUnless (eq(numpy.concatenate((x,y,x)), concatenate((x,ym,x))))\n \n def check_xtestCount (self):\n \"Test count\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless( isinstance(count(ott), types.IntType))\n self.assertEqual(3, count(ott))\n self.assertEqual(1, count(1))\n self.failUnless (eq(0, array(1,mask=[1])))\n ott=ott.reshape((2,2))\n assert isMaskedArray(count(ott,0))\n assert isinstance(count(ott), types.IntType)\n self.failUnless (eq(3, count(ott)))\n assert getmask(count(ott,0)) is None\n self.failUnless (eq([1,2],count(ott,0)))\n \n def check_testMinMax (self):\n \"Test minimum and maximum.\" \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n xr = numpy.ravel(x) #max doesn't work if shaped\n xmr = ravel(xm)\n self.failUnless (eq(max(xr), maximum(xmr))) #true because of careful selection of data\n self.failUnless (eq(min(xr), minimum(xmr))) #true because of careful selection of data\n\n def check_testAddSumProd (self):\n \"Test add, sum, product.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.add.reduce(x), add.reduce(x)))\n self.failUnless (eq(numpy.add.accumulate(x), add.accumulate(x)))\n self.failUnless (eq(4, sum(array(4))))\n self.failUnless (eq(4, sum(array(4), axis=0)))\n self.failUnless (eq(numpy.sum(x), sum(x)))\n self.failUnless (eq(numpy.sum(filled(xm,0)), sum(xm)))\n self.failUnless (eq(numpy.sum(x,0), sum(x,0)))\n self.failUnless (eq(numpy.product(x), product(x)))\n self.failUnless (eq(numpy.product(x,0), product(x,0)))\n self.failUnless (eq(numpy.product(filled(xm,1)), product(xm)))\n if len(s) > 1:\n self.failUnless (eq(numpy.concatenate((x,y),1), concatenate((xm,ym),1)))\n self.failUnless (eq(numpy.add.reduce(x,1), add.reduce(x,1)))\n self.failUnless (eq(numpy.sum(x,1), sum(x,1)))\n self.failUnless (eq(numpy.product(x,1), product(x,1)))\n \n \n def check_testCI(self):\n \"Test of conversions and indexing\"\n x1 = numpy.array([1,2,4,3])\n x2 = array(x1, mask = [1,0,0,0])\n x3 = array(x1, mask = [0,1,0,1])\n x4 = array(x1)\n # test conversion to strings\n junk, garbage = str(x2), repr(x2)\n assert eq(numpy.sort(x1),sort(x2, fill_value=0))\n # tests of indexing\n assert type(x2[1]) is type(x1[1])\n assert x1[1] == x2[1]\n assert x2[0] is masked\n assert eq(x1[2],x2[2])\n assert eq(x1[2:5],x2[2:5])\n assert eq(x1[:],x2[:])\n assert eq(x1[1:], x3[1:])\n x1[2]=9\n x2[2]=9\n assert eq(x1,x2)\n x1[1:3] = 99\n x2[1:3] = 99\n assert eq(x1,x2)\n x2[1] = masked\n assert eq(x1,x2)\n x2[1:3]=masked\n assert eq(x1,x2)\n x2[:] = x1\n x2[1] = masked\n assert allequal(getmask(x2),array([0,1,0,0]))\n x3[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x3), array([0,1,1,0]))\n x4[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x4), array([0,1,1,0]))\n assert allequal(x4, array([1,2,3,4]))\n x1 = numpy.arange(5)*1.0\n x2 = masked_values(x1, 3.0)\n assert eq(x1,x2)\n assert allequal(array([0,0,0,1,0],MaskType), x2.mask)\n assert eq(3.0, x2.fill_value())\n x1 = array([1,'hello',2,3],object)\n x2 = numpy.array([1,'hello',2,3],object)\n s1 = x1[1]\n s2 = x2[1]\n self.assertEqual(type(s2), str)\n self.assertEqual(type(s1), str)\n self.assertEqual(s1, s2)\n assert x1[1:1].shape == (0,)\n \n def check_testCopySize(self):\n \"Tests of some subtle points of copying and sizing.\"\n n = [0,0,1,0,0]\n m = make_mask(n)\n m2 = make_mask(m)\n self.failUnless(m is m2)\n m3 = make_mask(m, copy=1)\n self.failUnless(m is not m3)\n \n x1 = numpy.arange(5)\n y1 = array(x1, mask=m)\n self.failUnless( y1.raw_data() is not x1)\n self.failUnless( allequal(x1,y1.raw_data()))\n self.failUnless( y1.mask is m)\n \n y1a = array(y1, copy=0)\n self.failUnless( y1a.raw_data() is y1.raw_data())\n self.failUnless( y1a.mask is y1.mask)\n \n y2 = array(x1, mask=m, copy=0)\n self.failUnless( y2.raw_data() is x1)\n self.failUnless( y2.mask is m)\n self.failUnless( y2[2] is masked)\n y2[2]=9\n self.failUnless( y2[2] is not masked)\n self.failUnless( y2.mask is not m)\n self.failUnless( allequal(y2.mask, 0))\n \n y3 = array(x1*1.0, mask=m)\n self.failUnless(filled(y3).dtype is (x1*1.0).dtype)\n \n x4 = arange(4)\n x4[2] = masked\n y4 = resize(x4, (8,))\n self.failUnless( eq(concatenate([x4,x4]), y4))\n self.failUnless( eq(getmask(y4),[0,0,1,0,0,0,1,0]))\n y5 = repeat(x4, (2,2,2,2))\n self.failUnless( eq(y5, [0,0,1,1,2,2,3,3]))\n y6 = repeat(x4, 2)\n self.failUnless( eq(y5, y6))\n \n def check_testPut(self):\n \"Test of put\"\n d = arange(5)\n n = [0,0,0,1,1]\n m = make_mask(n)\n x = array(d, mask = m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n x[[1,4]] = [10,40]\n self.failUnless( x.mask is not m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is not masked)\n self.failUnless( eq(x, [0,10,2,-1,40]))\n \n x = array(d, mask = m) \n x.put([-1,100,200])\n self.failUnless( eq(x, [-1,100,200,0,0]))\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n \n x = array(d, mask = m) \n x.putmask([30,40])\n self.failUnless( eq(x, [0,1,2,30,40]))\n self.failUnless( x.mask is None)\n \n x = array(d, mask = m) \n y = x.compressed()\n z = array(x, mask = m)\n z.put(y)\n assert eq (x, z)\n \n def check_testMaPut(self):\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]\n i = numpy.nonzero(m)\n putmask(xm, m, z)\n assert take(xm, i) == z\n put(ym, i, zm)\n assert take(ym, i) == zm\n \n def check_testOddFeatures(self):\n \"Test of other odd features\"\n x = arange(20); x=x.reshape(4,5)\n x.flat[5] = 12\n assert x[1,0] == 12\n z = x + 10j * x\n assert eq(z.real, x)\n assert eq(z.imag, 10*x)\n assert eq((z*conjugate(z)).real, 101*x*x)\n z.imag[...] = 0.0\n \n x = arange(10)\n x[3] = masked\n assert str(x[3]) == str(masked)\n c = x >= 8\n assert count(where(c,masked,masked)) == 0\n assert shape(where(c,masked,masked)) == c.shape\n z = where(c , x, masked)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is masked\n assert z[7] is masked\n assert z[8] is not masked\n assert z[9] is not masked\n assert eq(x,z)\n z = where(c , masked, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n z = masked_where(c, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n assert eq(x,z)\n x = array([1.,2.,3.,4.,5.])\n c = array([1,1,1,0,0])\n x[2] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n c[0] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n assert eq(masked_where(greater(x, 2), x), masked_greater(x,2))\n assert eq(masked_where(greater_equal(x, 2), x), masked_greater_equal(x,2))\n assert eq(masked_where(less(x, 2), x), masked_less(x,2))\n assert eq(masked_where(less_equal(x, 2), x), masked_less_equal(x,2))\n assert eq(masked_where(not_equal(x, 2), x), masked_not_equal(x,2))\n assert eq(masked_where(equal(x, 2), x), masked_equal(x,2))\n assert eq(masked_where(not_equal(x,2), x), masked_not_equal(x,2))\n assert eq(masked_inside(range(5), 1, 3), [0, 199, 199, 199, 4])\n assert eq(masked_outside(range(5), 1, 3),[199,1,2,3,199])\n assert eq(masked_inside(array(range(5), mask=[1,0,0,0,0]), 1, 3).mask, [1,1,1,1,0])\n assert eq(masked_outside(array(range(5), mask=[0,1,0,0,0]), 1, 3).mask, [1,1,0,0,1])\n assert eq(masked_equal(array(range(5), mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,0])\n assert eq(masked_not_equal(array([2,2,1,2,1], mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,1])\n assert eq(masked_where([1,1,0,0,0], [1,2,3,4,5]), [99,99,3,4,5])\n atest = ones((10,10,10), dtype=float32)\n btest = zeros(atest.shape, MaskType)\n ctest = masked_where(btest,atest)\n assert eq(atest,ctest)\n z = choose(c, (-x, x))\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n x = arange(6)\n x[5] = masked\n y = arange(6)*10\n y[2]= masked\n c = array([1,1,1,0,0,0], mask=[1,0,0,0,0,0])\n cm = c.filled(1)\n z = where(c,x,y)\n zm = where(cm,x,y)\n assert eq(z, zm)\n assert getmask(zm) is None\n assert eq(zm, [0,1,2,30,40,50])\n z = where(c, masked, 1)\n assert eq(z, [99,99,99,1,1,1])\n z = where(c, 1, masked)\n assert eq(z, [99, 1, 1, 99, 99, 99])\n \n def check_testMinMax(self):\n \"Test of minumum, maximum.\" \n assert eq(minimum([1,2,3],[4,0,9]), [1,0,3])\n assert eq(maximum([1,2,3],[4,0,9]), [4,2,9])\n x = arange(5)\n y = arange(5) - 2\n x[3] = masked\n y[0] = masked\n assert eq(minimum(x,y), where(less(x,y), x, y))\n assert eq(maximum(x,y), where(greater(x,y), x, y))\n assert minimum(x) == 0\n assert maximum(x) == 4\n \n def check_testTakeTransposeInnerOuter(self):\n \"Test of take, transpose, inner, outer products\"\n x = arange(24)\n y = numpy.arange(24)\n x[5:6] = masked\n x=x.reshape(2,3,4)\n y=y.reshape(2,3,4)\n assert eq(numpy.transpose(y,(2,0,1)), transpose(x,(2,0,1)))\n assert eq(numpy.take(y, (2,0,1), 1), take(x, (2,0,1), 1))\n assert eq(numpy.innerproduct(filled(x,0),filled(y,0)),\n innerproduct(x, y))\n assert eq(numpy.outerproduct(filled(x,0),filled(y,0)),\n outerproduct(x, y))\n y = array(['abc', 1, 'def', 2, 3], object)\n y[2] = masked\n t = take(y,[0,3,4])\n assert t[0] == 'abc'\n assert t[1] == 2\n assert t[2] == 3\n \n def check_testInplace(self):\n \"\"\"Test of inplace operations and rich comparisons\"\"\"\n y = arange(10)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x += 1\n assert eq(x, y+1)\n xm += 1\n assert eq(x, y+1)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x -= 1\n assert eq(x, y-1)\n xm -= 1\n assert eq(xm, y-1)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x *= 2.0\n assert eq(x, y*2)\n xm *= 2.0\n assert eq(xm, y*2)\n \n x = arange(10)*2\n xm = arange(10)\n xm[2] = masked\n x /= 2\n assert eq(x, y)\n xm /= 2\n assert eq(x, y)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x /= 2.0\n assert eq(x, y/2.0)\n xm /= arange(10)\n assert eq(xm, ones((10,)))\n \n x = arange(10).astype(float32)\n xm = arange(10)\n xm[2] = masked\n id1 = id(x.raw_data())\n x += 1.\n assert id1 == id(x.raw_data())\n assert eq(x, y+1.)\n \n def check_testPickle(self):\n \"Test of pickling\"\n x = arange(12)\n x[4:10:2] = masked\n x=x.reshape(4,3)\n f = open('test9.pik','wb')\n import pickle\n pickle.dump(x, f)\n f.close()\n f = open('test9.pik', 'rb')\n y = pickle.load(f)\n assert eq(x,y) \n \n def check_testMasked(self):\n \"Test of masked element\"\n xx=arange(6)\n xx[1] = masked\n self.failUnless(str(masked) == '--')\n self.failUnless(xx[1] is masked)\n # don't know why these should raise an exception...\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, masked)\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, 2)\n self.failUnlessRaises(Exception, lambda x,y: x+y, masked, xx)\n self.failUnlessRaises(Exception, lambda x,y: x+y, xx, masked)\n \n def check_testAverage1(self):\n \"Test of average.\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless(eq(2.0, average(ott)))\n self.failUnless(eq(2.0, average(ott, weights=[1., 1., 2., 1.])))\n result, wts = average(ott, weights=[1.,1.,2.,1.], returned=1)\n self.failUnless(eq(2.0, result))\n self.failUnless(wts == 4.0)\n ott[:] = masked\n self.failUnless(average(ott) is masked)\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n ott=ott.reshape(2,2)\n ott[:,1] = masked\n self.failUnless(eq(average(ott), [2.0, 0.0]))\n self.failUnless(average(ott,axis=1)[0] is masked)\n self.failUnless(eq([2.,0.], average(ott)))\n result, wts = average(ott, returned=1)\n self.failUnless(eq(wts, [1., 0.]))\n\n def check_testAverage2(self):\n \"More tests of average.\"\n w1 = [0,1,1,1,1,0]\n w2 = [[0,1,1,1,1,0],[1,0,0,0,0,1]]\n x=arange(6)\n self.failUnless(allclose(average(x), 2.5))\n self.failUnless(allclose(average(x, weights=w1), 2.5))\n y=array([arange(6), 2.0*arange(6)])\n self.failUnless(allclose(average(y, None), numpy.add.reduce(numpy.arange(6))*3./12.))\n self.failUnless(allclose(average(y, axis=0), numpy.arange(6) * 3./2.))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n self.failUnless(allclose(average(y, None, weights=w2), 20./6.))\n self.failUnless(allclose(average(y, axis=0, weights=w2), [0.,1.,2.,3.,4.,10.]))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n m1 = zeros(6)\n m2 = [0,0,1,1,0,0]\n m3 = [[0,0,1,1,0,0],[0,1,1,1,1,0]]\n m4 = ones(6)\n m5 = [0, 1, 1, 1, 1, 1]\n self.failUnless(allclose(average(masked_array(x, m1)), 2.5))\n self.failUnless(allclose(average(masked_array(x, m2)), 2.5))\n self.failUnless(average(masked_array(x, m4)) is masked)\n self.assertEqual(average(masked_array(x, m5)), 0.0)\n self.assertEqual(count(average(masked_array(x, m4))), 0)\n z = masked_array(y, m3)\n self.failUnless(allclose(average(z, None), 20./6.))\n self.failUnless(allclose(average(z, axis=0), [0.,1.,99.,99.,4.0, 7.5]))\n self.failUnless(allclose(average(z, axis=1), [2.5, 5.0]))\n self.failUnless(allclose( average(z,weights=w2), [0.,1., 99., 99., 4.0, 10.0]))\n \n a = arange(6)\n b = arange(6) * 3\n r1, w1 = average([[a,b],[b,a]], axis=1, returned=1)\n self.assertEqual(shape(r1) , shape(w1))\n self.assertEqual(r1.shape , w1.shape)\n r2, w2 = average(ones((2,2,3)), axis=0, weights=[3,1], returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), weights=ones((2,2,3)), returned=1)\n self.failUnless(shape(w2) == shape(r2))\n a2d = array([[1,2],[0,4]], float)\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n a2da = average(a2d)\n self.failUnless(eq (a2da, [0.5, 3.0]))\n a2dma = average(a2dm)\n self.failUnless(eq( a2dma, [1.0, 3.0]))\n a2dma = average(a2dm, axis=None)\n self.failUnless(eq(a2dma, 7./3.))\n a2dma = average(a2dm, axis=1)\n self.failUnless(eq(a2dma, [1.5, 4.0]))\n\n def check_testToPython(self):\n self.assertEqual(1, int(array(1)))\n self.assertEqual(1.0, float(array(1)))\n self.assertEqual(1, int(array([[[1]]])))\n self.assertEqual(1.0, float(array([[1]])))\n self.failUnlessRaises(ValueError, float, array([1,1]))\n self.failUnlessRaises(MAError, float, array([1],mask=[1]))\n self.failUnless(bool(array([0,1])))\n self.failUnless(bool(array([0,0],mask=[0,1])))\n self.failIf(bool(array([0,0])))\n self.failIf(bool(array([0,0],mask=[0,0])))\n\n def check_testScalarArithmetic(self):\n xm = array(0, mask=1)\n self.failUnless((1/array(0)).mask)\n self.failUnless((1 + xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless(maximum(xm, xm).mask)\n self.failUnless(minimum(xm, xm).mask)\n self.failUnless(xm.filled().dtype is xm.data.dtype)\n x = array(0, mask=0)\n self.failUnless(x.filled() is x.data)\n\n def check_testArrayMethods(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnless(eq(a.any(), a.data.any()))\n self.failUnless(eq(a.all(), a.data.all()))\n self.failUnless(eq(a.argmax(), a.data.argmax()))\n self.failUnless(eq(a.argmin(), a.data.argmin()))\n self.failUnless(eq(a.choose(0,1,2,3,4), a.data.choose(0,1,2,3,4)))\n self.failUnless(eq(a.compress([1,0,1]), a.data.compress([1,0,1])))\n self.failUnless(eq(a.conj(), a.data.conj()))\n self.failUnless(eq(a.conjugate(), a.data.conjugate()))\n m = array([[1,2],[3,4]])\n self.failUnless(eq(m.diagonal(), m.data.diagonal()))\n self.failUnless(eq(a.sum(), a.data.sum()))\n self.failUnless(eq(a.take([1,2]), a.data.take([1,2])))\n self.failUnless(eq(m.transpose(), m.data.transpose()))\n \n def check_testAPI(self):\n self.failIf([m for m in dir(numpy.ndarray)\n if m not in dir(array) and not m.startswith('_')])\n\n def check_testSingleElementSubscript(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnlessEqual(a[0].shape, ())\n self.failUnlessEqual(b[0].shape, ())\n self.failUnlessEqual(b[1].shape, ())\n\n \ndef timingTest():\n for f in [testf, testinplace]:\n for n in [1000,10000,50000]:\n t = testta(n, f)\n t1 = testtb(n, f)\n t2 = testtc(n, f)\n print f.test_name\n print \"\"\"\\\nn = %7d \nnumpy time (ms) %6.1f \nMA maskless ratio %6.1f\nMA masked ratio %6.1f\n\"\"\" % (n, t*1000.0, t1/t, t2/t)\n\ndef testta(n, f):\n x=numpy.arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtb(n, f):\n x=arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtc(n, f):\n x=arange(n) + 1.0\n x[0] = masked\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testf(x):\n for i in range(25):\n y = x **2 + 2.0 * x - 1.0\n w = x **2 + 1.0\n z = (y / w) ** 2\n return z\ntestf.test_name = 'Simple arithmetic'\n\ndef testinplace(x):\n for i in range(25):\n y = x**2\n y += 2.0*x\n y -= 1.0\n y /= x\n return y\ntestinplace.test_name = 'Inplace operations'\n\nif __name__ == \"__main__\":\n ScipyTest('numpy.core.ma').run() \n #timingTest()\n", + "methods": [ + { + "name": "eq", + "long_name": "eq( v , w )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "v", + "w" + ], + "start_line": 5, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , * args , ** kwds )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 15, + "end_line": 17, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 276, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 32, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic1d", + "long_name": "check_testBasic1d( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 186, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 47, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic2d", + "long_name": "check_testBasic2d( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 2, + "token_count": 209, + "parameters": [ + "self" + ], + "start_line": 49, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "check_testArithmetic", + "long_name": "check_testArithmetic( self )", + "filename": "test_ma.py", + "nloc": 34, + "complexity": 2, + "token_count": 518, + "parameters": [ + "self" + ], + "start_line": 70, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "check_testMixedArithmetic", + "long_name": "check_testMixedArithmetic( self )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 106, + "end_line": 110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_testUfuncs1", + "long_name": "check_testUfuncs1( self )", + "filename": "test_ma.py", + "nloc": 29, + "complexity": 1, + "token_count": 600, + "parameters": [ + "self" + ], + "start_line": 112, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "check_xtestCount", + "long_name": "check_xtestCount( self )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 1, + "token_count": 174, + "parameters": [ + "self" + ], + "start_line": 142, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 156, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_testAddSumProd", + "long_name": "check_testAddSumProd( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 2, + "token_count": 361, + "parameters": [ + "self" + ], + "start_line": 164, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testCI", + "long_name": "check_testCI( self )", + "filename": "test_ma.py", + "nloc": 46, + "complexity": 1, + "token_count": 560, + "parameters": [ + "self" + ], + "start_line": 184, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 1 + }, + { + "name": "check_testCopySize", + "long_name": "check_testCopySize( self )", + "filename": "test_ma.py", + "nloc": 35, + "complexity": 1, + "token_count": 409, + "parameters": [ + "self" + ], + "start_line": 233, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 1 + }, + { + "name": "check_testPut", + "long_name": "check_testPut( self )", + "filename": "test_ma.py", + "nloc": 27, + "complexity": 1, + "token_count": 291, + "parameters": [ + "self" + ], + "start_line": 274, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "check_testMaPut", + "long_name": "check_testMaPut( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 101, + "parameters": [ + "self" + ], + "start_line": 305, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_testOddFeatures", + "long_name": "check_testOddFeatures( self )", + "filename": "test_ma.py", + "nloc": 88, + "complexity": 1, + "token_count": 1188, + "parameters": [ + "self" + ], + "start_line": 314, + "end_line": 402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 154, + "parameters": [ + "self" + ], + "start_line": 404, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testTakeTransposeInnerOuter", + "long_name": "check_testTakeTransposeInnerOuter( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 1, + "token_count": 235, + "parameters": [ + "self" + ], + "start_line": 417, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "check_testInplace", + "long_name": "check_testInplace( self )", + "filename": "test_ma.py", + "nloc": 44, + "complexity": 1, + "token_count": 315, + "parameters": [ + "self" + ], + "start_line": 437, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testPickle", + "long_name": "check_testPickle( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 489, + "end_line": 500, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testMasked", + "long_name": "check_testMasked( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 502, + "end_line": 512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage1", + "long_name": "check_testAverage1( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 1, + "token_count": 289, + "parameters": [ + "self" + ], + "start_line": 514, + "end_line": 531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage2", + "long_name": "check_testAverage2( self )", + "filename": "test_ma.py", + "nloc": 50, + "complexity": 1, + "token_count": 945, + "parameters": [ + "self" + ], + "start_line": 533, + "end_line": 583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testToPython", + "long_name": "check_testToPython( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 193, + "parameters": [ + "self" + ], + "start_line": 585, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testScalarArithmetic", + "long_name": "check_testScalarArithmetic( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 146, + "parameters": [ + "self" + ], + "start_line": 597, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testArrayMethods", + "long_name": "check_testArrayMethods( self )", + "filename": "test_ma.py", + "nloc": 16, + "complexity": 1, + "token_count": 351, + "parameters": [ + "self" + ], + "start_line": 610, + "end_line": 625, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "check_testAPI", + "long_name": "check_testAPI( self )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 4, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 627, + "end_line": 629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_testSingleElementSubscript", + "long_name": "check_testSingleElementSubscript( self )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 631, + "end_line": 636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "timingTest", + "long_name": "timingTest( )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 3, + "token_count": 72, + "parameters": [], + "start_line": 639, + "end_line": 651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "testta", + "long_name": "testta( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 40, + "parameters": [ + "n", + "f" + ], + "start_line": 653, + "end_line": 657, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtb", + "long_name": "testtb( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 38, + "parameters": [ + "n", + "f" + ], + "start_line": 659, + "end_line": 663, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtc", + "long_name": "testtc( n , f )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 44, + "parameters": [ + "n", + "f" + ], + "start_line": 665, + "end_line": 670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testf", + "long_name": "testf( x )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 48, + "parameters": [ + "x" + ], + "start_line": 672, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testinplace", + "long_name": "testinplace( x )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 36, + "parameters": [ + "x" + ], + "start_line": 680, + "end_line": 686, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "eq", + "long_name": "eq( v , w )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "v", + "w" + ], + "start_line": 5, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , * args , ** kwds )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 15, + "end_line": 17, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 276, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 32, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic1d", + "long_name": "check_testBasic1d( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 186, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 47, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic2d", + "long_name": "check_testBasic2d( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 2, + "token_count": 209, + "parameters": [ + "self" + ], + "start_line": 49, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "check_testArithmetic", + "long_name": "check_testArithmetic( self )", + "filename": "test_ma.py", + "nloc": 34, + "complexity": 2, + "token_count": 518, + "parameters": [ + "self" + ], + "start_line": 70, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "check_testMixedArithmetic", + "long_name": "check_testMixedArithmetic( self )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 106, + "end_line": 110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_testUfuncs1", + "long_name": "check_testUfuncs1( self )", + "filename": "test_ma.py", + "nloc": 29, + "complexity": 1, + "token_count": 600, + "parameters": [ + "self" + ], + "start_line": 112, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "check_xtestCount", + "long_name": "check_xtestCount( self )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 1, + "token_count": 174, + "parameters": [ + "self" + ], + "start_line": 142, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 156, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_testAddSumProd", + "long_name": "check_testAddSumProd( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 2, + "token_count": 361, + "parameters": [ + "self" + ], + "start_line": 164, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testCI", + "long_name": "check_testCI( self )", + "filename": "test_ma.py", + "nloc": 46, + "complexity": 1, + "token_count": 560, + "parameters": [ + "self" + ], + "start_line": 184, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 1 + }, + { + "name": "check_testCopySize", + "long_name": "check_testCopySize( self )", + "filename": "test_ma.py", + "nloc": 35, + "complexity": 1, + "token_count": 409, + "parameters": [ + "self" + ], + "start_line": 233, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 1 + }, + { + "name": "check_testPut", + "long_name": "check_testPut( self )", + "filename": "test_ma.py", + "nloc": 27, + "complexity": 1, + "token_count": 291, + "parameters": [ + "self" + ], + "start_line": 274, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "check_testMaPut", + "long_name": "check_testMaPut( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 101, + "parameters": [ + "self" + ], + "start_line": 305, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_testOddFeatures", + "long_name": "check_testOddFeatures( self )", + "filename": "test_ma.py", + "nloc": 88, + "complexity": 1, + "token_count": 1188, + "parameters": [ + "self" + ], + "start_line": 314, + "end_line": 402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 154, + "parameters": [ + "self" + ], + "start_line": 404, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testTakeTransposeInnerOuter", + "long_name": "check_testTakeTransposeInnerOuter( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 1, + "token_count": 235, + "parameters": [ + "self" + ], + "start_line": 417, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "check_testInplace", + "long_name": "check_testInplace( self )", + "filename": "test_ma.py", + "nloc": 44, + "complexity": 1, + "token_count": 315, + "parameters": [ + "self" + ], + "start_line": 437, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testPickle", + "long_name": "check_testPickle( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 489, + "end_line": 500, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testMasked", + "long_name": "check_testMasked( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 502, + "end_line": 512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage1", + "long_name": "check_testAverage1( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 1, + "token_count": 289, + "parameters": [ + "self" + ], + "start_line": 514, + "end_line": 531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage2", + "long_name": "check_testAverage2( self )", + "filename": "test_ma.py", + "nloc": 50, + "complexity": 1, + "token_count": 945, + "parameters": [ + "self" + ], + "start_line": 533, + "end_line": 583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testToPython", + "long_name": "check_testToPython( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 193, + "parameters": [ + "self" + ], + "start_line": 585, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testScalarArithmetic", + "long_name": "check_testScalarArithmetic( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 132, + "parameters": [ + "self" + ], + "start_line": 597, + "end_line": 607, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testArrayMethods", + "long_name": "check_testArrayMethods( self )", + "filename": "test_ma.py", + "nloc": 16, + "complexity": 1, + "token_count": 351, + "parameters": [ + "self" + ], + "start_line": 609, + "end_line": 624, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "check_testAPI", + "long_name": "check_testAPI( self )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 4, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 626, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_testSingleElementSubscript", + "long_name": "check_testSingleElementSubscript( self )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 630, + "end_line": 635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "timingTest", + "long_name": "timingTest( )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 3, + "token_count": 72, + "parameters": [], + "start_line": 638, + "end_line": 650, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "testta", + "long_name": "testta( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 40, + "parameters": [ + "n", + "f" + ], + "start_line": 652, + "end_line": 656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtb", + "long_name": "testtb( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 38, + "parameters": [ + "n", + "f" + ], + "start_line": 658, + "end_line": 662, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtc", + "long_name": "testtc( n , f )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 44, + "parameters": [ + "n", + "f" + ], + "start_line": 664, + "end_line": 669, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testf", + "long_name": "testf( x )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 48, + "parameters": [ + "x" + ], + "start_line": 671, + "end_line": 676, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testinplace", + "long_name": "testinplace( x )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 36, + "parameters": [ + "x" + ], + "start_line": 679, + "end_line": 685, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "check_testScalarArithmetic", + "long_name": "check_testScalarArithmetic( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 146, + "parameters": [ + "self" + ], + "start_line": 597, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + } + ], + "nloc": 630, + "complexity": 45, + "token_count": 8332, + "diff_parsed": { + "added": [ + " self.failUnlessEqual(str(xm), str(masked_print_option))" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "6de260c36f24bdd93cef333fbd0df964b7adf440", + "msg": "Finish the fix...", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2006-01-14T04:14:57+00:00", + "author_timezone": 0, + "committer_date": "2006-01-14T04:14:57+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "438efdea7004a9d9962184854dcb02df82e6f897" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4g_96ds6/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/umathmodule.c.src", + "new_path": "numpy/core/src/umathmodule.c.src", + "filename": "umathmodule.c.src", + "extension": "src", + "change_type": "MODIFY", + "diff": "@@ -302,9 +302,9 @@ double hypot(double x, double y)\n /**begin repeat\n \n #kind=(sin,cos,tan,sinh,cosh,tanh,fabs,floor,ceil,sqrt,log10,log,exp,asin,acos,atan)*2#\n-#typ=longdouble*18, float*18#\n-#c=l*18,f*18#\n-#TYPE=LONGDOUBLE*18, FLOAT*18#\n+#typ=longdouble*16, float*16#\n+#c=l*16,f*16#\n+#TYPE=LONGDOUBLE*16, FLOAT*16#\n */\n #ifndef HAVE_@TYPE@_FUNCS\n @typ@ @kind@@c@(@typ@ x) {\n", + "added_lines": 3, + "deleted_lines": 3, + "source_code": "/* -*- c -*- */\n\n#include \"Python.h\"\n#include \"numpy/arrayobject.h\"\n#define _UMATHMODULE\n#include \"numpy/ufuncobject.h\"\n#include \"abstract.h\"\n#include \n\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\nfloat log1pf(float);\nfloat logf(float);\nfloat sqrtf(float);\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\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\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\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\nlongdouble logl(longdouble);\nlongdouble sqrtl(longdouble);\nlongdouble log1pl(longdouble);\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\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\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n#else\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\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\ndouble 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\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\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)*2#\n#typ=longdouble*16, float*16#\n#c=l*16,f*16#\n#TYPE=LONGDOUBLE*16, FLOAT*16#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\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@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@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)\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)\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)\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)\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\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@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\t}\n\telse if (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n\t}\n\telse {\n\t\tnc_log@c@(a, r);\n\t\tnc_prod@c@(r, b, r);\n\t\tnc_exp@c@(r, r);\n\t}\n\treturn;\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; i> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n\t/* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>32) || (y>>32) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>64) || (y>>64) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n\treturn 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n\tulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n\tif (a0 < 0) { a = -a0; } else { a = a0; }\n\tif (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n\tah = (a >> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n /*\n\t ulonglong c = ((x + y)<<32) + w;\n\t if ((a0 < 0) ^ (b0 < 0))\n\t *c = -c;\n\t else\n\t *c = c\n\t */\n\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>31) || (y>>31) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>63) || (y>>63) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n\treturn 0;\n#endif\n}\n\n/** end direct numarray code **/\n\nstatic void\nBOOL_multiply(char **args, intp *dimensions, intp *steps, void *func) {\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 MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nULONGLONG_multiply(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\tulonglong temp;\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\telse if (temp < MIN_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nLONGLONG_multiply(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\tlonglong temp;\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=fmod*10, 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\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\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 memcpy(op, i1, sizeof(@typ@));\n else\n memcpy(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\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\nfloat log1pf(float);\nfloat logf(float);\nfloat sqrtf(float);\nstatic float acoshf(float x)\n{\n\treturn 2*logf(sqrtf((x+1.0)/2)+sqrtf((x-1.0)/2));\n}\n\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\nstatic float atanhf(float x)\n{\n\treturn 0.5*log1pf(2.0*x/(1.0-x));\n}\n#else\nstatic float acoshf(float x)\n{\n return (float)acosh((double)(x));\n}\n\nstatic float asinhf(float x)\n{\n return (float)asinh((double)(x));\n}\n\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\nlongdouble logl(longdouble);\nlongdouble sqrtl(longdouble);\nlongdouble log1pl(longdouble);\nstatic longdouble acoshl(longdouble x)\n{\n\treturn 2*logl(sqrtl((x+1.0)/2)+sqrtl((x-1.0)/2));\n}\n\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\nstatic longdouble atanhl(longdouble x)\n{\n\treturn 0.5*log1pl(2.0*x/(1.0-x));\n}\n#else\nstatic longdouble acoshl(longdouble x)\n{\n return (longdouble)acosh((double)(x));\n}\n\nstatic longdouble asinhl(longdouble x)\n{\n return (longdouble)asinh((double)(x));\n}\n\nstatic longdouble atanhl(longdouble x)\n{\n return (longdouble)atanh((double)(x));\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\ndouble 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\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\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)*2#\n#typ=longdouble*18, float*18#\n#c=l*18,f*18#\n#TYPE=LONGDOUBLE*18, FLOAT*18#\n*/\n#ifndef HAVE_@TYPE@_FUNCS\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@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@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)\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)\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)\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)\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\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@typ@ ar=a->real, br=b->real, ai=a->imag, bi=b->imag;\n\t@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\t@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\t}\n\telse if (ar == 0. && ai == 0.) {\n\t\tr->real = 0.;\n\t\tr->imag = 0.;\n\t}\n\telse {\n\t\tnc_log@c@(a, r);\n\t\tnc_prod@c@(r, b, r);\n\t\tnc_exp@c@(r, r);\n\t}\n\treturn;\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; i> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n /* 128-bit product: z*2**64 + (x+y)*2**32 + w */\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n\t/* *c = ((x + y)<<32) + w; */\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>32) || (y>>32) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 32);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>64) || (y>>64) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 64);\n#else\n\treturn 0;\n#endif\n\n}\n\nstatic int slonglong_overflow(longlong a0, longlong b0)\n{\n\tulonglong a, b;\n ulonglong ah, al, bh, bl, w, x, y, z;\n\n /* Convert to non-negative quantities */\n\tif (a0 < 0) { a = -a0; } else { a = a0; }\n\tif (b0 < 0) { b = -b0; } else { b = b0; }\n\n\n#if SIZEOF_LONGLONG == 64\n\tah = (a >> 32);\n\tal = (a & 0xFFFFFFFFL);\n\tbh = (b >> 32);\n\tbl = (b & 0xFFFFFFFFL);\n#elif SIZEOF_LONGLONG == 128\n\tah = (a >> 64);\n\tal = (a & 0xFFFFFFFFFFFFFFFFL);\n\tbh = (b >> 64);\n\tbl = (b & 0xFFFFFFFFFFFFFFFFL);\n#else\n\tah = al = bh = bl = 0;\n#endif\n\n\tw = al*bl;\n\tx = bh*al;\n\ty = ah*bl;\n\tz = ah*bh;\n\n /*\n\t ulonglong c = ((x + y)<<32) + w;\n\t if ((a0 < 0) ^ (b0 < 0))\n\t *c = -c;\n\t else\n\t *c = c\n\t */\n\n#if SIZEOF_LONGLONG == 64\n\treturn z || (x>>31) || (y>>31) ||\n\t\t(((x & 0xFFFFFFFFL) + (y & 0xFFFFFFFFL) + (w >> 32)) >> 31);\n#elif SIZEOF_LONGLONG == 128\n\treturn z || (x>>63) || (y>>63) ||\n\t\t(((x & 0xFFFFFFFFFFFFFFFFL) + (y & 0xFFFFFFFFFFFFFFFFL) + (w >> 64)) >> 63);\n#else\n\treturn 0;\n#endif\n}\n\n/** end direct numarray code **/\n\nstatic void\nBOOL_multiply(char **args, intp *dimensions, intp *steps, void *func) {\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 MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nULONGLONG_multiply(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\tulonglong temp;\n\tfor (i=0; i MAX_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\telse if (temp < MIN_@TYP@)\n\t\t\tgenerate_overflow_error();\n\t\t*((@typ@ *)op) = temp;\n\t}\n}\n\n/**end repeat**/\n\nstatic void\nLONGLONG_multiply(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\tlonglong temp;\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=fmod*10, 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\tchar *i1=args[0], *i2=args[1], *op=args[2];\n\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 memcpy(op, i1, sizeof(@typ@));\n else\n memcpy(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 maxpriority) {\n \t\t\tmaxpriority = priority[i];\n-\t\t\targmax = i;\n+\t\t\tPy_DECREF(wrap);\t\n+\t\t\twrap = with_wrap[i];\n+\t\t} else {\n+\t\t\tPy_DECREF(with_wrap[i]);\n \t\t}\n \t}\n-\n-\treturn with_wrap[argmax];\n+\t\n+\treturn wrap;\n }\n \n static PyObject *\n@@ -2616,8 +2616,13 @@ ufunc_generic_call(PyUFuncObject *self, PyObject *args)\n \t\t\tmps[j] = (PyArrayObject *)old;\n \t\t}\n \t\tif (obj != NULL) {\n-\t\t\tres = PyObject_CallMethod(obj, \"__array_wrap__\",\n-\t\t\t\t\t\t \"O\", mps[j]);\n+\t\t\tres = PyObject_CallFunction(obj, \"O(OOi)\",\n+\t\t\t\t\t\t mps[j], self, args, i);\n+\t\t\tif (res == NULL) {\n+\t\t\t\tPyErr_Clear();\n+\t\t\t\tres = PyObject_CallFunctionObjArgs(obj, mps[j], NULL);\n+\t\t\t}\n+\t\t\tPy_DECREF(obj);\n \t\t\tif (res == NULL) PyErr_Clear();\n \t\t\telse if (res == Py_None) Py_DECREF(res);\n \t\t\telse {\n", + "added_lines": 20, + "deleted_lines": 15, + "source_code": "\n/*\n Python Universal Functions Object -- Math for all types, plus fast \n arrays math\n \n Full description\n \n This supports mathematical (and Boolean) functions on arrays and other python\n objects. Math on large arrays of basic C types is rather efficient.\n\n Travis E. Oliphant (2005)\n Assistant Professor\n Brigham Young University\n\n based on the \n\n Original Implementation: \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n with inspiration and code from\n Numarray\n Space Science Telescope Institute\n J. Todd Miller\n Perry Greenfield\n Rick White\n \n*/\n\n\ntypedef double (DoubleBinaryFunc)(double x, double y);\ntypedef float (FloatBinaryFunc)(float x, float y);\ntypedef longdouble (LongdoubleBinaryFunc)(longdouble x, longdouble y);\n\ntypedef void (CdoubleBinaryFunc)(cdouble *x, cdouble *y, cdouble *res);\ntypedef void (CfloatBinaryFunc)(cfloat *x, cfloat *y, cfloat *res);\ntypedef void (ClongdoubleBinaryFunc)(clongdouble *x, clongdouble *y, \\\n\t\t\t\t clongdouble *res);\n\n/*UFUNC_API*/\nstatic void\nPyUFunc_ff_f_As_dd_d(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i, n=dimensions[0];\n\tregister intp is1=steps[0],is2=steps[1],os=steps[2];\n\tchar *ip1=args[0], *ip2=args[1], *op=args[2];\n\t\n\tfor(i=0; inin, nout=data->nout;\n int ntot;\n PyObject *tocall = data->callable; \n char *ptrs[MAX_ARGS];\n PyObject *arglist, *result;\n PyObject *in, **op;\n\n ntot = nin+nout;\n\n for (j=0; j < ntot; j++) ptrs[j] = args[j];\n\tfor(i=0; i> UFUNC_SHIFT_##NAME, \\\n\t\t\t\t\t errobj, str, retstatus) < 0) \\\n\t\t\t\treturn -1;\t\t \\\n\t\t\t}}\n\n\tif (errmask && retstatus) {\n\t\tHANDLEIT(DIVIDEBYZERO, \"divide by zero\");\n\t\tHANDLEIT(OVERFLOW, \"overflow\");\n\t\tHANDLEIT(UNDERFLOW, \"underflow\");\n\t\tHANDLEIT(INVALID, \"invalid\");\n\t}\n\n#undef HANDLEIT\n\n\treturn 0;\n}\n\n\n/* Checking the status flag clears it */\n/*UFUNC_API*/\nstatic void\nPyUFunc_clearfperr()\n{\n\tint retstatus;\n\n\tUFUNC_CHECK_STATUS(retstatus)\n}\n\n\n#define UFUNC_NOSCALAR 0\n#define UFUNC_BOOL_SCALAR 1\n#define UFUNC_INTPOS_SCALAR 2\n#define UFUNC_INTNEG_SCALAR 3\n#define UFUNC_FLOAT_SCALAR 4\n#define UFUNC_COMPLEX_SCALAR 5\n#define UFUNC_OBJECT_SCALAR 6\n\n#define NO_UFUNCLOOP 0\n#define ZERODIM_REDUCELOOP 0\n#define ONE_UFUNCLOOP 1\n#define ONEDIM_REDUCELOOP 1\n#define NOBUFFER_UFUNCLOOP 2\n#define NOBUFFER_REDUCELOOP 2\n#define BUFFER_UFUNCLOOP 3\n#define BUFFER_REDUCELOOP 3\n\n\nstatic char\n_lowest_type(char intype)\n{\n switch(intype) {\n\t/* case PyArray_BYTE */\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\treturn PyArray_BYTE;\n\t/* case PyArray_UBYTE */\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\treturn PyArray_UBYTE;\n\t/* case PyArray_FLOAT:*/\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\treturn PyArray_FLOAT;\n\t/* case PyArray_CFLOAT:*/\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn PyArray_CFLOAT;\n default:\n return intype;\n }\n}\n\n/* Called to determine coercion\n */\n\nstatic int \n_cancoerce(char thistype, char neededtype, char scalar) \n{\n\n\tswitch(scalar) {\n\tcase UFUNC_NOSCALAR:\n\tcase UFUNC_BOOL_SCALAR:\n\tcase UFUNC_OBJECT_SCALAR:\n\t\treturn PyArray_CanCastSafely(thistype, neededtype);\n\tcase UFUNC_INTPOS_SCALAR:\n\t\treturn (neededtype >= PyArray_UBYTE);\n\tcase UFUNC_INTNEG_SCALAR:\n\t\treturn (neededtype >= PyArray_BYTE) &&\t\t\\\n\t\t\t!(PyTypeNum_ISUNSIGNED(neededtype));\n\tcase UFUNC_FLOAT_SCALAR:\n\t\treturn (neededtype >= PyArray_FLOAT);\n\tcase UFUNC_COMPLEX_SCALAR:\n\t\treturn (neededtype >= PyArray_CFLOAT);\n\t}\n\tfprintf(stderr, \"\\n**Error** coerce fall through: %d %d %d\\n\\n\", \n\t\tthistype, neededtype, scalar);\n\treturn 1; /* should never get here... */ \n}\n\n\nstatic int \nselect_types(PyUFuncObject *self, int *arg_types, \n PyUFuncGenericFunction *function, void **data,\n\t char *scalars)\n{\n\n\tint i=0, j;\n\tchar start_type;\n\t\n\tif (PyTypeNum_ISUSERDEF((arg_types[0]))) {\n\t\tPyObject *key, *obj;\n\t\tfor (i=0; inin; i++) {\n\t\t\tif (arg_types[i] != arg_types[0]) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"ufuncs on user defined\" \\\n\t\t\t\t\t\t\" types don't support \"\\\n\t\t\t\t\t\t\"coercion\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\t\tfor (i=self->nin; inargs; i++) {\n\t\t\targ_types[i] = arg_types[0];\n\t\t}\n\n\t\tobj = NULL;\n\t\tif (self->userloops) {\n\t\t\tkey = PyInt_FromLong((long) arg_types[0]);\n\t\t\tif (key == NULL) return -1;\n\t\t\tobj = PyDict_GetItem(self->userloops, key);\n\t\t\tPy_DECREF(key);\n\t\t}\n\t\tif (obj == NULL) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"no registered loop for this \"\t\\\n\t\t\t\t\t\"user-defined type\");\n\t\t\treturn -1;\t\t\t\n\t\t}\n\t\tif PyTuple_Check(obj) {\n\t\t\t*function = (PyUFuncGenericFunction) \\\n\t\t\t\tPyCObject_AsVoidPtr(PyTuple_GET_ITEM(obj, 0));\n\t\t\t*data = PyCObject_AsVoidPtr(PyTuple_GET_ITEM(obj, 1));\n\t\t}\n\t\telse {\n\t\t\t*function = (PyUFuncGenericFunction)\t\\\n\t\t\t\tPyCObject_AsVoidPtr(obj);\n\t\t\t*data = NULL;\n\t\t}\n Py_DECREF(obj);\n\t\treturn 0;\n\t}\n\t\n\n\tstart_type = arg_types[0];\n\t/* If the first argument is a scalar we need to place \n\t the start type as the lowest type in the class\n\t*/\n\tif (scalars[0] != UFUNC_NOSCALAR) {\n\t\tstart_type = _lowest_type(start_type);\n\t}\n\n\twhile (intypes && start_type > self->types[i*self->nargs]) \n\t\ti++;\n\n\tfor(;intypes; i++) {\n\t\tfor(j=0; jnin; j++) {\n\t\t\tif (!_cancoerce(arg_types[j], \n\t\t\t\t\tself->types[i*self->nargs+j],\n\t\t\t\t\tscalars[j]))\n\t\t\t\tbreak;\n\t\t}\n\t\tif (j == self->nin) break;\n\t}\n\tif(i>=self->ntypes) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"function not supported for these types, \"\\\n\t\t\t\t\"and can't coerce safely to supported types\");\n\t\treturn -1;\n\t}\n\tfor(j=0; jnargs; j++) \n\t\targ_types[j] = self->types[i*self->nargs+j];\n\n if (self->data)\n *data = self->data[i];\n else \n *data = NULL;\n\t*function = self->functions[i];\n\n\treturn 0;\n}\n\nstatic int PyUFunc_USEDEFAULTS=0;\n\n/*UFUNC_API*/\nstatic int\nPyUFunc_GetPyValues(char *name, int *bufsize, int *errmask, PyObject **errobj)\n{\n PyObject *thedict;\n PyObject *ref=NULL;\n\tPyObject *retval;\n\tstatic PyObject *thestring=NULL;\n\n\tif (!PyUFunc_USEDEFAULTS) {\n\t\tif (thestring == NULL) {\n\t\t\tthestring = PyString_InternFromString(UFUNC_PYVALS_NAME);\n\t\t}\n\t\tthedict = PyEval_GetLocals();\n\t\tref = PyDict_GetItem(thedict, thestring);\n\t\tif (ref == NULL) {\n\t\t\tthedict = PyEval_GetGlobals();\n\t\t\tref = PyDict_GetItem(thedict, thestring);\n\t\t}\n\t\tif (ref == NULL) {\n\t\t\tthedict = PyEval_GetBuiltins();\n\t\t\tref = PyDict_GetItem(thedict, thestring);\n\t\t}\n\t}\n\tif (ref == NULL) {\n\t\t*errmask = UFUNC_ERR_DEFAULT;\n\t\t*errobj = Py_BuildValue(\"NO\",\n\t\t\t\t\tPyString_FromString(name),\n\t\t\t\t\tPy_None);\n\t\t*bufsize = PyArray_BUFSIZE;\n\t\treturn 0;\n\t}\n\t*errobj = NULL;\n\tif (!PyList_Check(ref) || (PyList_GET_SIZE(ref)!=3)) {\n\t\tPyErr_Format(PyExc_TypeError, \"%s must be a length 3 list.\",\n\t\t\t UFUNC_PYVALS_NAME);\n\t\treturn -1;\n\t}\n\n\t*bufsize = PyInt_AsLong(PyList_GET_ITEM(ref, 0));\n\tif ((*bufsize == -1) && PyErr_Occurred()) return -1;\n\tif ((*bufsize < PyArray_MIN_BUFSIZE) ||\t\\\n\t (*bufsize > PyArray_MAX_BUFSIZE) || \\\n\t (*bufsize % 16 != 0)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"buffer size (%d) is not \"\t\\\n\t\t\t \"in range (%d - %d) or not a multiple of 16\", \n\t\t\t *bufsize, PyArray_MIN_BUFSIZE, \n\t\t\t PyArray_MAX_BUFSIZE);\n\t\treturn -1;\n\t}\n\n\t*errmask = PyInt_AsLong(PyList_GET_ITEM(ref, 1));\n\tif (*errmask < 0) {\n\t\tif (PyErr_Occurred()) return -1;\n\t\tPyErr_Format(PyExc_ValueError,\t\t\\\n\t\t\t \"invalid error mask (%d)\", \n\t\t\t *errmask);\n\t\treturn -1;\n\t}\n\t\n\tretval = PyList_GET_ITEM(ref, 2);\n\tif (retval != Py_None && !PyCallable_Check(retval)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"callback function must be callable\");\n\t\treturn -1;\n\t}\n\n\t*errobj = Py_BuildValue(\"NO\", \n\t\t\t\tPyString_FromString(name),\n\t\t\t\tretval);\n\tif (*errobj == NULL) return -1;\n\t\n\treturn 0;\n}\n\n\nstatic char\n_scalar_kind(int typenum, PyArrayObject **arr) \n{\n\tif (PyTypeNum_ISSIGNED(typenum)) return UFUNC_INTNEG_SCALAR;\n\tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;\n\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;\n\tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;\n\tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;\n\treturn UFUNC_OBJECT_SCALAR;\n}\n\n\n/* Create copies for any arrays that are less than loop->bufsize\n in total size and are mis-behaved or in need\n of casting.\n*/\n\nstatic int\n_create_copies(PyUFuncLoopObject *loop, int *arg_types, PyArrayObject **mps)\n{\n\tint nin = loop->ufunc->nin;\n\tint i;\n\tintp size;\n\tPyObject *new;\n\tPyArray_Descr *ntype; \n\tPyArray_Descr *atype;\n\n\tfor (i=0; idescr;\n\t\t\tatype = PyArray_DescrFromType(arg_types[i]);\n\t\t\tif (PyArray_EquivTypes(atype, ntype)) {\n\t\t\t\targ_types[i] = ntype->type_num;\n\t\t\t}\n\t\t\tPy_DECREF(atype);\n\t\t}\n\t\tif (size < loop->bufsize) {\n\t\t\tif (!(PyArray_ISBEHAVED_RO(mps[i])) ||\t\t\\\n\t\t\t PyArray_TYPE(mps[i]) != arg_types[i]) {\n\t\t\t\tntype = PyArray_DescrFromType(arg_types[i]);\n\t\t\t\tnew = PyArray_FromAny((PyObject *)mps[i], \n\t\t\t\t\t\t ntype, 0, 0,\n\t\t\t\t\t\t FORCECAST | ALIGNED);\n\t\t\t\tif (new == NULL) return -1;\n\t\t\t\tPy_DECREF(mps[i]);\n\t\t\t\tmps[i] = (PyArrayObject *)new;\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn 0;\n}\n\n#define _GETATTR_(str, rstr) if (strcmp(name, #str) == 0) { \\\n return PyObject_HasAttrString(op, \"__\" #rstr \"__\");}\n\nstatic int\n_has_reflected_op(PyObject *op, char *name)\n{\n _GETATTR_(add, radd)\n _GETATTR_(subtract, rsub)\n _GETATTR_(multiply, rmul)\n _GETATTR_(divide, rdiv)\n _GETATTR_(true_divide, rtruediv)\n _GETATTR_(floor_divide, rfloordiv)\n _GETATTR_(remainder, rmod)\n _GETATTR_(power, rpow)\n _GETATTR_(left_shift, rrlshift)\n _GETATTR_(right_shift, rrshift)\n _GETATTR_(bitwise_and, rand)\n _GETATTR_(bitwise_xor, rxor)\n _GETATTR_(bitwise_or, ror)\n return 0;\n}\n\n#undef _GETATTR_\n\n\nstatic int\nconstruct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps)\n{\n int nargs, i, maxsize;\n int arg_types[MAX_ARGS];\n\tchar scalars[MAX_ARGS];\n\tPyUFuncObject *self=loop->ufunc;\n\tBool allscalars=TRUE;\n\tPyTypeObject *subtype=&PyArray_Type;\n\n /* Check number of arguments */\n nargs = PyTuple_Size(args);\n if ((nargs != self->nin) && (nargs != self->nargs)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of arguments\");\n return -1;\n }\n\n\n /* Get each input argument */\n for (i=0; inin; i++) {\n mps[i] = (PyArrayObject *)\\\n\t\t\tPyArray_FromAny(PyTuple_GET_ITEM(args,i), \n\t\t\t\t\tNULL, 0, 0, 0);\n if (mps[i] == NULL) return -1;\n arg_types[i] = PyArray_TYPE(mps[i]);\n if (PyTypeNum_ISFLEXIBLE(arg_types[i])) {\n\t\t\tloop->notimplemented = 1;\n\t\t\treturn nargs;\n }\n\t\t/*\n\t\tfprintf(stderr, \"array %d has reference %d\\n\", i, \n\t\t (mps[i])->ob_refcnt);\n\t\t*/\n\n\t\t/* Scalars are 0-dimensional arrays\n\t\t at this point\n\t\t*/\n\t\tif (mps[i]->nd > 0) {\n\t\t\tscalars[i] = UFUNC_NOSCALAR;\n\t\t\tallscalars=FALSE;\n\t\t}\n\t\telse scalars[i] = _scalar_kind(arg_types[i], &(mps[i]));\n\n\t\t/* If any input is a big-array */\n\t\tif (!PyType_IsSubtype(mps[i]->ob_type, &PyArray_Type)) {\n\t\t\tsubtype = &PyBigArray_Type;\n\t\t}\n }\n\n\t/* If everything is a scalar, then use normal coercion rules */\n\tif (allscalars) {\n\t\tfor (i=0; inin; i++) {\n\t\t\tscalars[i] = UFUNC_NOSCALAR;\n\t\t}\n\t}\n \n /* Select an appropriate function for these argument types. */\n if (select_types(loop->ufunc, arg_types, &(loop->function), \n &(loop->funcdata), scalars) == -1)\n\t\treturn -1;\n\n /* FAIL with NotImplemented if the other object has \n\t the __r__ method and has __array_priority__ as \n\t an attribute (signalling it can handle ndarray's) \n\t and is not already an ndarray or bigndarray\n\t*/\n if ((arg_types[1] == PyArray_OBJECT) &&\t\t\t\t\\\n (loop->ufunc->nin==2) && (loop->ufunc->nout == 1)) {\n\t\tPyObject *_obj = PyTuple_GET_ITEM(args, 1);\n if (!PyArray_CheckExact(_obj) &&\t\t\t\\\n\t\t !PyBigArray_CheckExact(_obj) &&\t\t\t\\\n\t\t PyObject_HasAttrString(_obj, \"__array_priority__\") && \\\n\t\t _has_reflected_op(_obj, loop->ufunc->name)) {\n loop->notimplemented = 1;\n return nargs;\n }\n }\n loop->notimplemented=0;\n \n\t/* Create copies for some of the arrays if appropriate */\n\tif (_create_copies(loop, arg_types, mps) < 0) return -1;\n\t\n\t/* Create Iterators for the Inputs */\n\tfor (i=0; inin; i++) {\n loop->iters[i] = (PyArrayIterObject *)\t\t\\\n\t\t\tPyArray_IterNew((PyObject *)mps[i]);\n if (loop->iters[i] == NULL) return -1;\n\t}\n \n /* Broadcast the result */\n loop->numiter = self->nin;\n if (PyArray_Broadcast((PyArrayMultiIterObject *)loop) < 0)\n\t\treturn -1;\n\t\n /* Get any return arguments */\n for (i=self->nin; idimensions, \n\t\t\t\t\t loop->dimensions, loop->nd)) {\n PyErr_SetString(PyExc_ValueError, \n \"invalid return array shape\");\n\t\t\tPy_DECREF(mps[i]);\n mps[i] = NULL;\n return -1;\n }\n if (!PyArray_ISWRITEABLE(mps[i])) {\n PyErr_SetString(PyExc_ValueError, \n \"return array is not writeable\");\n\t\t\tPy_DECREF(mps[i]);\n mps[i] = NULL;\n return -1;\n }\n }\n\n /* construct any missing return arrays and make output iterators */\n \n for (i=self->nin; inargs; i++) {\n\t\tPyArray_Descr *ntype;\n\n if (mps[i] == NULL) {\n mps[i] = (PyArrayObject *)PyArray_New(subtype,\n loop->nd, \n loop->dimensions,\n arg_types[i], \n NULL, NULL,\n 0, 0, NULL);\n if (mps[i] == NULL) return -1;\n }\n\n\t\t/* reset types for outputs that are equivalent \n\t\t -- no sense casting uselessly\n\t\t*/\n\t\telse {\n \t\t if (mps[i]->descr->type_num != arg_types[i]) {\n\t\t\t PyArray_Descr *atype;\n\t\t\t ntype = mps[i]->descr;\n\t\t\t atype = PyArray_DescrFromType(arg_types[i]);\n\t\t\t if (PyArray_EquivTypes(atype, ntype)) {\n\t\t\t\t arg_types[i] = ntype->type_num;\n\t\t\t }\n\t\t\t Py_DECREF(atype);\n\t\t }\n\t\t \n\t\t/* still not the same -- or will we have to use buffers?*/\n\t\t if (mps[i]->descr->type_num != arg_types[i] ||\n\t\t !PyArray_ISBEHAVED_RO(mps[i])) {\n\t\t\t if (loop->size < loop->bufsize) {\n\t\t\t\t PyObject *new;\n\t\t\t\t /* Copy the array to a temporary copy \n\t\t\t\t and set the UPDATEIFCOPY flag\n\t\t\t\t */\n\t\t\t\t ntype = PyArray_DescrFromType(arg_types[i]);\n\t\t\t\t new = PyArray_FromAny((PyObject *)mps[i],\n\t\t\t\t\t\t\tntype, 0, 0,\n\t\t\t\t\t\t\tFORCECAST | ALIGNED |\n\t\t\t\t\t\t\tUPDATEIFCOPY);\n\t\t\t\t if (new == NULL) return -1;\n\t\t\t\t Py_DECREF(mps[i]);\n\t\t\t\t mps[i] = (PyArrayObject *)new;\n\t\t\t }\n\t\t }\n\t\t}\n\t\t\n loop->iters[i] = (PyArrayIterObject *)\t\t\\\n\t\t\tPyArray_IterNew((PyObject *)mps[i]);\n if (loop->iters[i] == NULL) return -1;\n }\n\n\n /* If any of different type, or misaligned or swapped\n then must use buffers */\n\n loop->bufcnt = 0;\n\n loop->obj = 0;\n\n /* Determine looping method needed */\n loop->meth = NO_UFUNCLOOP;\n\n\tmaxsize = 0;\n for (i=0; inargs; i++) {\n\t\tloop->needbuffer[i] = 0;\n if (arg_types[i] != mps[i]->descr->type_num || \n\t\t !PyArray_ISBEHAVED_RO(mps[i])) {\n loop->meth = BUFFER_UFUNCLOOP;\n\t\t\tloop->needbuffer[i] = 1;\n }\n if (!loop->obj && mps[i]->descr->type_num == PyArray_OBJECT) {\n\t\t\tloop->obj = 1;\n\t\t}\n }\n \n if (loop->meth == NO_UFUNCLOOP) {\n \n loop->meth = ONE_UFUNCLOOP;\n\n /* All correct type and BEHAVED */\n /* Check for non-uniform stridedness */\n\n for (i=0; inargs; i++) {\n if (!(loop->iters[i]->contiguous)) {\n\t\t\t\t/* may still have uniform stride\n\t\t\t\t if (broadcated result) <= 1-d */\n\t\t\t\tif (mps[i]->nd != 0 &&\t\t\t\\\n\t\t\t\t (loop->iters[i]->nd_m1 > 0)) {\n\t\t\t\t\tloop->meth = NOBUFFER_UFUNCLOOP;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n }\n\t\tif (loop->meth == ONE_UFUNCLOOP) {\n\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\tloop->bufptr[i] = mps[i]->data;\n\t\t\t}\n\t\t}\n }\n\n loop->numiter = self->nargs;\n\n /* Fill in steps */\n if (loop->meth != ONE_UFUNCLOOP) {\n\t\tint ldim = 0;\n\t\tintp maxdim=-1;\n\t\tPyArrayIterObject *it;\n\n /* Fix iterators */\n\n /* Find the **largest** dimension */\n \n\t\tmaxdim = -1;\n\t\tfor (i=loop->nd - 1; i>=0; i--) {\n\t\t\tif (loop->dimensions[i] > maxdim) {\n\t\t\t\tldim = i;\n\t\t\t\tmaxdim = loop->dimensions[i];\n\t\t\t}\n\t\t}\n\n\t\tloop->size /= maxdim;\n loop->bufcnt = maxdim;\n\t\tloop->lastdim = ldim;\n\n /* Fix the iterators so the inner loop occurs over the \n\t\t largest dimensions -- This can be done by \n\t\t setting the size to 1 in that dimension \n\t\t (just in the iterators)\n */\n\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = loop->iters[i];\n it->contiguous = 0;\n\t\t\tit->size /= (it->dims_m1[ldim]+1);\n\t\t\tit->dims_m1[ldim] = 0;\n\t\t\tit->backstrides[ldim] = 0;\n\n\t\t\t/* (won't fix factors because we\n\t\t\t don't use PyArray_ITER_GOTO1D \n\t\t\t so don't change them) */\n\n\t\t\t/* Set the steps to the strides in that dimension */\n loop->steps[i] = it->strides[ldim];\n\t\t}\n\n\t\t/* fix up steps where we will be copying data to \n\t\t buffers and calculate the ninnerloops and leftover\n\t\t values -- if step size is already zero that is not changed... \n\t\t*/\n\t\tif (loop->meth == BUFFER_UFUNCLOOP) {\n\t\t\tloop->leftover = maxdim % loop->bufsize;\n\t\t\tloop->ninnerloops = (maxdim / loop->bufsize) + 1;\n\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\tif (loop->needbuffer[i] && loop->steps[i]) {\n\t\t\t\t\tloop->steps[i] = mps[i]->descr->elsize;\n\t\t\t\t}\n\t\t\t\t/* These are changed later if casting is needed */\n\t\t\t}\n\t\t}\n }\n else { /* uniformly-strided case ONE_UFUNCLOOP */\n\t\tfor (i=0; inargs; i++) {\n\t\t\tif (PyArray_SIZE(mps[i]) == 1)\n\t\t\t\tloop->steps[i] = 0;\n\t\t\telse\n\t\t\t\tloop->steps[i] = mps[i]->strides[mps[i]->nd-1];\n\t\t}\n\t}\n \n\n\t/* Finally, create memory for buffers if we need them */\n\t\n\t/* buffers for scalars are specially made small -- scalars are\n\t not copied multiple times */\n\tif (loop->meth == BUFFER_UFUNCLOOP) {\n\t\tint cnt = 0, cntcast = 0; /* keeps track of bytes to allocate */\n\t\tint scnt = 0, scntcast = 0;\n\t\tchar *castptr;\n\t\tchar *bufptr;\n\t\tint last_was_scalar=0;\n\t\tint last_cast_was_scalar=0;\n\t\tint oldbufsize=0;\n\t\tint oldsize=0;\n\t\tint scbufsize = 4*sizeof(double);\n\t\tint memsize;\n PyArray_Descr *descr;\n\n\t\t/* compute the element size */\n\t\tfor (i=0; inargs;i++) {\n\t\t\tif (!loop->needbuffer) continue;\n\t\t\tif (arg_types[i] != mps[i]->descr->type_num) {\n\t\t\t\tdescr = PyArray_DescrFromType(arg_types[i]);\n\t\t\t\tif (loop->steps[i])\n\t\t\t\t\tcntcast += descr->elsize;\n\t\t\t\telse\n\t\t\t\t\tscntcast += descr->elsize;\n\t\t\t\tif (i < self->nin) {\n\t\t\t\t\tloop->cast[i] =\t\t\t\\\n\t\t\t\t\t\tmps[i]->descr->f->cast[arg_types[i]];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tloop->cast[i] = descr->f->\t\\\n\t\t\t\t\t\tcast[mps[i]->descr->type_num];\n\t\t\t\t}\n\t\t\t\tPy_DECREF(descr);\n\t\t\t}\n\t\t\tloop->swap[i] = !(PyArray_ISNOTSWAPPED(mps[i]));\n\t\t\tif (loop->steps[i])\n\t\t\t\tcnt += mps[i]->descr->elsize;\n\t\t\telse\n\t\t\t\tscnt += mps[i]->descr->elsize;\n\t\t}\n\t\tmemsize = loop->bufsize*(cnt+cntcast) + scbufsize*(scnt+scntcast);\n \t\tloop->buffer[0] = PyDataMem_NEW(memsize);\n\n\t\t/* fprintf(stderr, \"Allocated buffer at %p of size %d, cnt=%d, cntcast=%d\\n\", loop->buffer[0], loop->bufsize * (cnt + cntcast), cnt, cntcast); */\n\n\t\tif (loop->buffer[0] == NULL) {PyErr_NoMemory(); return -1;}\n\t\tcastptr = loop->buffer[0] + loop->bufsize*cnt + scbufsize*scnt;\n\t\tbufptr = loop->buffer[0];\n\t\tfor (i=0; inargs; i++) {\n\t\t\tif (!loop->needbuffer[i]) continue;\n\t\t\tloop->buffer[i] = bufptr + (last_was_scalar ? scbufsize : \\\n\t\t\t\t\t\t loop->bufsize)*oldbufsize;\n\t\t\tlast_was_scalar = (loop->steps[i] == 0);\n\t\t\tbufptr = loop->buffer[i];\n\t\t\toldbufsize = mps[i]->descr->elsize;\n\t\t\t/* fprintf(stderr, \"buffer[%d] = %p\\n\", i, loop->buffer[i]); */\n\t\t\tif (loop->cast[i]) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tloop->castbuf[i] = castptr + (last_cast_was_scalar ? scbufsize : \\\n\t\t\t\t\t\t\t loop->bufsize)*oldsize;\n\t\t\t\tlast_cast_was_scalar = last_was_scalar;\n\t\t\t\t/* fprintf(stderr, \"castbuf[%d] = %p\\n\", i, loop->castbuf[i]); */\n\t\t\t\tdescr = PyArray_DescrFromType(arg_types[i]);\n\t\t\t\toldsize = descr->elsize;\n\t\t\t\tPy_DECREF(descr);\n\t\t\t\tloop->bufptr[i] = loop->castbuf[i];\n\t\t\t\tcastptr = loop->castbuf[i];\n\t\t\t\tif (loop->steps[i])\n\t\t\t\t\tloop->steps[i] = oldsize;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tloop->bufptr[i] = loop->buffer[i];\n\t\t\t}\n\t\t}\n\t}\n return nargs;\n}\n\nstatic void\nufuncreduce_dealloc(PyUFuncReduceObject *self)\n{\n if (self->ufunc) {\n Py_XDECREF(self->it);\n\t\tPy_XDECREF(self->rit);\n Py_XDECREF(self->ret);\n\t\tPy_XDECREF(self->errobj);\n\t\tPy_XDECREF(self->decref);\n if (self->buffer) PyDataMem_FREE(self->buffer);\n Py_DECREF(self->ufunc);\n }\n _pya_free(self);\n}\n\nstatic void\nufuncloop_dealloc(PyUFuncLoopObject *self)\n{\n\tint i;\n\t\n\tif (self->ufunc != NULL) {\n\t\tfor (i=0; iufunc->nargs; i++)\n\t\t\tPy_XDECREF(self->iters[i]);\n\t\tif (self->buffer[0]) PyDataMem_FREE(self->buffer[0]);\n\t\tPy_XDECREF(self->errobj);\n\t\tPy_DECREF(self->ufunc);\n\t}\n _pya_free(self);\n}\n\nstatic PyUFuncLoopObject *\nconstruct_loop(PyUFuncObject *self, PyObject *args, PyArrayObject **mps)\n{\n\tPyUFuncLoopObject *loop;\n\tint i;\n\t\n\tif (self == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \"function not supported\");\n\t\treturn NULL;\n\t}\n if ((loop = _pya_malloc(sizeof(PyUFuncLoopObject)))==NULL) {\n PyErr_NoMemory(); return loop;\n }\n\t\n\tloop->index = 0;\n\tloop->ufunc = self;\n Py_INCREF(self);\n\tloop->buffer[0] = NULL;\n for (i=0; inargs; i++) {\n loop->iters[i] = NULL;\n loop->cast[i] = NULL;\n }\n\tloop->errobj = NULL;\n\n\tif (PyUFunc_GetPyValues((self->name ? self->name : \"\"),\n\t\t\t\t&(loop->bufsize), &(loop->errormask), \n\t\t\t\t&(loop->errobj)) < 0) goto fail;\n \n\t/* Setup the matrices */\n\tif (construct_matrices(loop, args, mps) < 0) goto fail;\n\n\tPyUFunc_clearfperr();\n\n\treturn loop;\n\n fail:\n ufuncloop_dealloc(loop);\n\treturn NULL;\n}\n\n\n/* \nstatic void\n_printbytebuf(PyUFuncLoopObject *loop, int bufnum) \n{ \n\tint i;\n\t\n \tfprintf(stderr, \"Printing byte buffer %d\\n\", bufnum);\n for (i=0; ibufcnt; i++) {\n\t \tfprintf(stderr, \" %d\\n\", *(((byte *)(loop->buffer[bufnum]))+i));\n\t} \n}\n\nstatic void\n_printlongbuf(PyUFuncLoopObject *loop, int bufnum) \n{ \n\tint i;\n\t\n \tfprintf(stderr, \"Printing long buffer %d\\n\", bufnum);\n for (i=0; ibufcnt; i++) {\n\t \tfprintf(stderr, \" %ld\\n\", *(((long *)(loop->buffer[bufnum]))+i));\n\t} \n}\n\nstatic void\n_printlongbufptr(PyUFuncLoopObject *loop, int bufnum) \n{ \n\tint i;\n\t\n \tfprintf(stderr, \"Printing long buffer %d\\n\", bufnum);\n for (i=0; ibufcnt; i++) {\n\t \tfprintf(stderr, \" %ld\\n\", *(((long *)(loop->bufptr[bufnum]))+i));\n\t} \n}\n\n\n \nstatic void\n_printcastbuf(PyUFuncLoopObject *loop, int bufnum) \n{ \n\tint i;\n\t\n \tfprintf(stderr, \"Printing long buffer %d\\n\", bufnum);\n for (i=0; ibufcnt; i++) {\n\t \tfprintf(stderr, \" %ld\\n\", *(((long *)(loop->castbuf[bufnum]))+i));\n\t} \n}\n\n*/\n\n\n\n\n/* currently generic ufuncs cannot be built for use on flexible arrays.\n\n The cast functions in the generic loop would need to be fixed to pass \n in something besides NULL, NULL.\n\n Also the underlying ufunc loops would not know the element-size unless\n that was passed in as data (which could be arranged).\n\n*/\n\n/* This generic function is called with the ufunc object, the arguments to it,\n and an array of (pointers to) PyArrayObjects which are NULL. The \n arguments are parsed and placed in mps in construct_loop (construct_matrices)\n*/\n\n/*UFUNC_API*/\nstatic int \nPyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, \n\t\t\tPyArrayObject **mps) \n{\n\tPyUFuncLoopObject *loop;\n\tint i;\n BEGIN_THREADS_DEF\n\n\tif (!(loop = construct_loop(self, args, mps))) return -1;\n if (loop->notimplemented) {ufuncloop_dealloc(loop); return -2;}\n\n\tLOOP_BEGIN_THREADS\n\n\tswitch(loop->meth) {\n\tcase ONE_UFUNCLOOP:\n\t\t/* Everything is contiguous, notswapped, aligned,\n\t\t and of the right type. -- Fastest.\n\t\t Or if not contiguous, then a single-stride\n\t\t increment moves through the entire array. \n\t\t*/\n /*fprintf(stderr, \"ONE...%d\\n\", loop->size);*/\n\t\tloop->function((char **)loop->bufptr, &(loop->size), \n\t\t\t loop->steps, loop->funcdata);\n\t\tUFUNC_CHECK_ERROR(loop);\n\t\tbreak;\n\tcase NOBUFFER_UFUNCLOOP:\n\t\t/* Everything is notswapped, aligned and of the \n\t\t right type but not contiguous. -- Almost as fast.\n\t\t*/\n /*fprintf(stderr, \"NOBUFFER...%d\\n\", loop->size);*/\n\t\twhile (loop->index < loop->size) {\n\t\t\tfor (i=0; inargs; i++) \n\t\t\t\tloop->bufptr[i] = loop->iters[i]->dataptr;\n\n\t\t\tloop->function((char **)loop->bufptr, &(loop->bufcnt),\n\t\t\t\t loop->steps, loop->funcdata);\n\t\t\tUFUNC_CHECK_ERROR(loop);\n\n\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\tPyArray_ITER_NEXT(loop->iters[i]);\n\t\t\t}\n\t\t\tloop->index++;\n\t\t}\n\t\tbreak;\n\tcase BUFFER_UFUNCLOOP: {\n\t\tPyArray_CopySwapNFunc *copyswapn[MAX_ARGS];\n\t\tPyArrayIterObject **iters=loop->iters;\n\t\tint *swap=loop->swap;\n\t\tvoid **dptr=loop->dptr;\n\t\tint mpselsize[MAX_ARGS];\n\t\tintp laststrides[MAX_ARGS];\n\t\tint fastmemcpy[MAX_ARGS];\n\t\tint *needbuffer=loop->needbuffer;\n\t\tintp index=loop->index, size=loop->size;\n\t\tint bufsize;\n\t\tintp bufcnt;\n\t\tint copysizes[MAX_ARGS];\n\t\tvoid **bufptr = loop->bufptr;\n\t\tvoid **buffer = loop->buffer;\n\t\tvoid **castbuf = loop->castbuf;\n\t\tintp *steps = loop->steps;\n\t\tchar *tptr[MAX_ARGS];\n\t\tint ninnerloops = loop->ninnerloops;\n\t\tBool pyobject[MAX_ARGS];\n\t\tint datasize[MAX_ARGS];\n int i, j, k, stopcondition;\n\t\tchar *myptr1, *myptr2;\n\n\t\t\n\t\tfor (i=0; inargs; i++) {\n\t\t\tcopyswapn[i] = mps[i]->descr->f->copyswapn;\n\t\t\tmpselsize[i] = mps[i]->descr->elsize;\n\t\t\tpyobject[i] = (loop->obj && \\\n (mps[i]->descr->type_num == PyArray_OBJECT));\n\t\t\tlaststrides[i] = iters[i]->strides[loop->lastdim];\n\t\t\tif (steps[i] && laststrides[i] != mpselsize[i]) fastmemcpy[i] = 0;\n\t\t\telse fastmemcpy[i] = 1;\n\t\t}\n\t\t/* Do generic buffered looping here (works for any kind of\n\t\t arrays -- some need buffers, some don't. \n\t\t*/\n\t\t\n\t\t/* New algorithm: N is the largest dimension. B is the buffer-size.\n\t\t quotient is loop->ninnerloops-1\n\t\t remainder is loop->leftover\n\n\t\tCompute N = quotient * B + remainder. \n\t\tquotient = N / B # integer math \n\t\t(store quotient + 1) as the number of innerloops\n\t\tremainder = N % B # integer remainder\n\t\t\n\t\tOn the inner-dimension we will have (quotient + 1) loops where \n\t\tthe size of the inner function is B for all but the last when the niter size is\n\t\tremainder. \n\t\t\n\t\tSo, the code looks very similar to NOBUFFER_LOOP except the inner-most loop is \n\t\treplaced with...\n\t\t\n\t\tfor(i=0; isize, \n\t\t loop->ninnerloops, loop->leftover);\n\t\t*/\n\t\t/*\n\t\tfor (i=0; inargs; i++) {\n\t\t fprintf(stderr, \"iters[%d]->dataptr = %p, %p of size %d\\n\", i, \n\t\t\t iters[i], iters[i]->ao->data, PyArray_NBYTES(iters[i]->ao));\n\t\t}\n\t\t*/\n\n\t\tstopcondition = ninnerloops;\n\t\tif (loop->leftover == 0) stopcondition--;\n\t\twhile (index < size) {\n\t\t\tbufsize=loop->bufsize;\n\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\ttptr[i] = loop->iters[i]->dataptr;\n\t\t\t\tif (needbuffer[i]) {\n\t\t\t\t\tdptr[i] = bufptr[i];\n\t\t\t\t\tdatasize[i] = (steps[i] ? bufsize : 1);\n\t\t\t\t\tcopysizes[i] = datasize[i] * mpselsize[i];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdptr[i] = tptr[i];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t/* This is the inner function over the last dimension */\n\t\t\tfor (k=1; k<=stopcondition; k++) {\n\t\t\t\tif (k==ninnerloops) {\n bufsize = loop->leftover;\n for (i=0; inargs;i++) {\n\t\t\t\t\t\tif (!needbuffer[i]) continue;\n datasize[i] = (steps[i] ? bufsize : 1);\n\t\t\t\t\t\tcopysizes[i] = datasize[i] * mpselsize[i];\n }\n }\n \n\t\t\t\tfor (i=0; inin; i++) {\n\t\t\t\t\tif (!needbuffer[i]) continue;\n\t\t\t\t\tif (fastmemcpy[i]) \n\t\t\t\t\t\tmemcpy(buffer[i], tptr[i],\n\t\t\t\t\t\t copysizes[i]);\n\t\t\t\t\telse {\n\t\t\t\t\t\tmyptr1 = buffer[i];\n\t\t\t\t\t\tmyptr2 = tptr[i];\n\t\t\t\t\t\tfor (j=0; jcast[i]) {\n\t\t\t\t\t\tloop->cast[i](buffer[i],\n\t\t\t\t\t\t\t castbuf[i],\n\t\t\t\t\t\t\t (intp) datasize[i],\n\t\t\t\t\t\t\t NULL, NULL);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tbufcnt = (intp) bufsize;\n\t\t\t\tloop->function((char **)dptr, &bufcnt, steps, loop->funcdata);\n\t\t\t\t\n\t\t\t\tfor (i=self->nin; inargs; i++) {\n\t\t\t\t\tif (!needbuffer[i]) continue;\n\t\t\t\t\tif (loop->cast[i]) {\n\t\t\t\t\t\tloop->cast[i](castbuf[i],\n\t\t\t\t\t\t\t buffer[i],\n\t\t\t\t\t\t\t (intp) datasize[i],\n\t\t\t\t\t\t\t NULL, NULL);\n\t\t\t\t\t}\n\t\t\t\t\tif (swap[i]) {\n\t\t\t\t\t\tcopyswapn[i](buffer[i], NULL,\n\t\t\t\t\t\t\t (intp) datasize[i], 1, \n\t\t\t\t\t\t\t mpselsize[i]);\n\t\t\t\t\t}\n\t\t\t\t\t/* copy back to output arrays */\n\t\t\t\t\t/* decref what's already there for object arrays */\n\t\t\t\t\tif (pyobject[i]) {\n\t\t\t\t\t\tmyptr1 = tptr[i];\n\t\t\t\t\t\tfor (j=0; jnargs; i++) {\n\t\t\t\t\ttptr[i] += bufsize * laststrides[i];\n\t\t\t\t\tif (!needbuffer[i]) dptr[i] = tptr[i];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (loop->obj) { /* DECREF castbuf for object arrays */\n\t\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\t\tif (pyobject[i]) {\n\t\t\t\t\t\tif (steps[i] == 0) {\n\t\t\t\t\t\t\tPy_XDECREF(*((PyObject **)castbuf[i]));\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tint size = loop->bufsize;\n\t\t\t\t\t\t\tPyObject **objptr = castbuf[i];\n\t\t\t\t\t\t\t/* size is loop->bufsize unless there\n\t\t\t\t\t\t\t was only one loop */\n\t\t\t\t\t\t\tif (ninnerloops == 1) \\\n\t\t\t\t\t\t\t\tsize = loop->leftover;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tfor (j=0; jnargs; i++) {\n\t\t\t\tPyArray_ITER_NEXT(loop->iters[i]);\n\t\t\t}\n\t\t\tindex++;\n }\n }\n }\n \n LOOP_END_THREADS\n \n ufuncloop_dealloc(loop);\n\treturn 0;\n\n fail:\n LOOP_END_THREADS\n\n\tif (loop) ufuncloop_dealloc(loop);\n\treturn -1;\n}\n\nstatic PyArrayObject *\n_getidentity(PyUFuncObject *self, int otype, char *str)\n{\n PyObject *obj, *arr;\n PyArray_Descr *typecode;\n\t\n if (self->identity == PyUFunc_None) {\n PyErr_Format(PyExc_ValueError, \n \"zero-size array to ufunc.%s \" \\\n \"without identity\", str);\n return NULL;\n }\n if (self->identity == PyUFunc_One) {\n obj = PyInt_FromLong((long) 1);\n } else {\n obj = PyInt_FromLong((long) 0);\n }\n\n\ttypecode = PyArray_DescrFromType(otype); \n arr = PyArray_FromAny(obj, typecode, 0, 0, CARRAY_FLAGS);\n Py_DECREF(obj);\n return (PyArrayObject *)arr;\n}\n\nstatic int\n_create_reduce_copy(PyUFuncReduceObject *loop, PyArrayObject **arr, int rtype)\n{\n\tintp maxsize;\n\tPyObject *new;\n\tPyArray_Descr *ntype;\n\t\n\tmaxsize = PyArray_SIZE(*arr);\n\t\n\tif (maxsize < loop->bufsize) {\n\t\tif (!(PyArray_ISBEHAVED_RO(*arr)) ||\t\\\n\t\t PyArray_TYPE(*arr) != rtype) {\n\t\t\tntype = PyArray_DescrFromType(rtype);\n\t\t\tnew = PyArray_FromAny((PyObject *)(*arr), \n\t\t\t\t\t ntype, 0, 0,\n\t\t\t\t\t FORCECAST | ALIGNED);\n\t\t\tif (new == NULL) return -1;\n\t\t\t*arr = (PyArrayObject *)new;\n\t\t\tloop->decref = new;\n\t\t}\n\t}\n\n\t/* Don't decref *arr before re-assigning\n\t because it was not going to be DECREF'd anyway.\n\t \n\t If a copy is made, then the copy will be removed\n\t on deallocation of the loop structure by setting \n\t loop->decref.\n\t*/\n\t\n\treturn 0;\n}\n\nstatic PyUFuncReduceObject *\nconstruct_reduce(PyUFuncObject *self, PyArrayObject **arr, int axis, \n\t\t int otype, int operation, intp ind_size, char *str)\n{\n PyUFuncReduceObject *loop;\n PyArrayObject *idarr;\n\tPyArrayObject *aar;\n intp loop_i[MAX_DIMS];\n int arg_types[3] = {otype, otype, otype};\n\tchar scalars[3] = {UFUNC_NOSCALAR, UFUNC_NOSCALAR, UFUNC_NOSCALAR};\n\tint i, j;\n\tint nd = (*arr)->nd;\n\t/* Reduce type is the type requested of the input \n\t during reduction */\n \n if ((loop = _pya_malloc(sizeof(PyUFuncReduceObject)))==NULL) {\n PyErr_NoMemory(); return loop;\n }\n \n loop->swap = 0;\n\tloop->index = 0;\n\tloop->ufunc = self;\n Py_INCREF(self);\n loop->cast = NULL;\n loop->buffer = NULL;\n loop->ret = NULL;\n\tloop->it = NULL;\n\tloop->rit = NULL;\n\tloop->errobj = NULL;\n\tloop->decref=NULL; \n loop->N = (*arr)->dimensions[axis];\n\tloop->instrides = (*arr)->strides[axis];\n\n\tif (select_types(loop->ufunc, arg_types, &(loop->function), \n\t\t\t &(loop->funcdata), scalars) == -1) goto fail; \n\t\n\t/* output type may change -- if it does \n\t reduction is forced into that type \n\t and we need to select the reduction function again\n\t*/\n\tif (otype != arg_types[2]) {\n\t\totype = arg_types[2];\n\t\targ_types[0] = otype;\n\t\targ_types[1] = otype;\n\t\tif (select_types(loop->ufunc, arg_types, &(loop->function), \n\t\t\t\t &(loop->funcdata), scalars) == -1) \n\t\t\tgoto fail; \t\t\n\t}\n\t\n\t/* get looping parameters from Python */\n\tif (PyUFunc_GetPyValues(str, &(loop->bufsize), &(loop->errormask), \n\t\t\t\t&(loop->errobj)) < 0) goto fail;\n\t\n\t/* Make copy if misbehaved or not otype for small arrays */\n\tif (_create_reduce_copy(loop, arr, otype) < 0) goto fail; \n\taar = *arr;\n\t\n if (loop->N == 0) {\n loop->meth = ZERODIM_REDUCELOOP;\n }\n else if (PyArray_ISBEHAVED_RO(aar) &&\t\t\\\n otype == (aar)->descr->type_num) {\n\t\tif (loop->N == 1) {\n\t\t\tloop->meth = ONEDIM_REDUCELOOP;\n\t\t}\n\t\telse {\n\t\t\tloop->meth = NOBUFFER_UFUNCLOOP;\n\t\t\tloop->steps[0] = (aar)->strides[axis];\n\t\t\tloop->N -= 1;\n\t\t}\n }\n else {\n loop->meth = BUFFER_UFUNCLOOP;\n loop->swap = !(PyArray_ISNOTSWAPPED(aar));\n }\n\n /* Determine if object arrays are involved */\n if (otype == PyArray_OBJECT || aar->descr->type_num == PyArray_OBJECT)\n loop->obj = 1;\n else\n loop->obj = 0;\n\n if (loop->meth == ZERODIM_REDUCELOOP) {\n idarr = _getidentity(self, otype, str);\n if (idarr == NULL) goto fail;\n if (idarr->descr->elsize > UFUNC_MAXIDENTITY) {\n PyErr_Format(PyExc_RuntimeError, \n\t\t\t\t \"UFUNC_MAXIDENTITY (%d)\"\t\t\\\n \" is too small (needs to be at least %d)\",\n UFUNC_MAXIDENTITY, idarr->descr->elsize);\n Py_DECREF(idarr);\n goto fail;\n }\n memcpy(loop->idptr, idarr->data, idarr->descr->elsize);\n Py_DECREF(idarr);\n }\n\t\n /* Construct return array */\n\tswitch(operation) {\n\tcase UFUNC_REDUCE:\n\t\tfor (j=0, i=0; idimensions[i];\n\t\t\t\n\t\t}\n\t\tloop->ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_New(aar->ob_type, aar->nd-1, loop_i, otype, \n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)aar);\n\t\tbreak;\n\tcase UFUNC_ACCUMULATE:\n\t\tloop->ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_New(aar->ob_type, aar->nd, aar->dimensions, \n\t\t\t\t otype, NULL, NULL, 0, 0, (PyObject *)aar);\n\t\tbreak;\n\tcase UFUNC_REDUCEAT:\n\t\tmemcpy(loop_i, aar->dimensions, nd*sizeof(intp));\n\t\t/* Index is 1-d array */\n\t\tloop_i[axis] = ind_size; \n\t\tloop->ret = (PyArrayObject *)\\\n\t\t\tPyArray_New(aar->ob_type, aar->nd, loop_i, otype,\n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)aar);\n\t\tif (loop->ret == NULL) goto fail;\n\t\tif (ind_size == 0) {\n\t\t\tloop->meth = ZERODIM_REDUCELOOP;\n\t\t\treturn loop;\n\t\t}\n\t\tif (loop->meth == ONEDIM_REDUCELOOP)\n\t\t\tloop->meth = NOBUFFER_REDUCELOOP;\n\t\tbreak;\n\t}\n if (loop->ret == NULL) goto fail;\n loop->insize = aar->descr->elsize;\n loop->outsize = loop->ret->descr->elsize;\n loop->bufptr[1] = loop->ret->data;\n\n\tif (loop->meth == ZERODIM_REDUCELOOP) {\n\t\tloop->size = PyArray_SIZE(loop->ret);\n\t\treturn loop;\n\t}\n\n\tloop->it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)aar);\n if (loop->it == NULL) return NULL;\n\n\tif (loop->meth == ONEDIM_REDUCELOOP) {\n\t\tloop->size = loop->it->size;\t\t\n\t\treturn loop;\n\t}\n\n /* Fix iterator to loop over correct dimension */\n\t/* Set size in axis dimension to 1 */\n \n loop->it->contiguous = 0;\n loop->it->size /= (loop->it->dims_m1[axis]+1);\n loop->it->dims_m1[axis] = 0;\n loop->it->backstrides[axis] = 0;\n\n\n loop->size = loop->it->size;\n\n\tif (operation == UFUNC_REDUCE) {\n\t\tloop->steps[1] = 0;\n\t}\n\telse {\n\t\tloop->rit = (PyArrayIterObject *)\t\t\t\\\n\t\t\tPyArray_IterNew((PyObject *)(loop->ret));\n\t\tif (loop->rit == NULL) return NULL;\t\t\n\n\t\t/* Fix iterator to loop over correct dimension */\n\t\t/* Set size in axis dimension to 1 */\n\t\t\n\t\tloop->rit->contiguous = 0;\n\t\tloop->rit->size /= (loop->rit->dims_m1[axis]+1);\n\t\tloop->rit->dims_m1[axis] = 0;\n\t\tloop->rit->backstrides[axis] = 0;\n\n\t\tif (operation == UFUNC_ACCUMULATE)\n\t\t\tloop->steps[1] = loop->ret->strides[axis];\n\t\telse \n\t\t\tloop->steps[1] = 0;\n\t}\n\tloop->steps[2] = loop->steps[1];\n\tloop->bufptr[2] = loop->bufptr[1] + loop->steps[2];\n\n\t\n\tif (loop->meth == BUFFER_UFUNCLOOP) {\n\t\tint _size;\n\t\tloop->steps[0] = loop->outsize;\n if (otype != aar->descr->type_num) {\n\t\t\t_size=loop->bufsize*(loop->outsize +\t\t\\\n\t\t\t\t\t aar->descr->elsize);\n loop->buffer = PyDataMem_NEW(_size);\n if (loop->buffer == NULL) goto fail;\n\t\t\tif (loop->obj) memset(loop->buffer, 0, _size);\n loop->castbuf = loop->buffer + \\\n loop->bufsize*aar->descr->elsize;\n loop->bufptr[0] = loop->castbuf; \n loop->cast = aar->descr->f->cast[otype];\n }\n else {\n\t\t\t_size = loop->bufsize * loop->outsize;\n loop->buffer = PyDataMem_NEW(_size);\n if (loop->buffer == NULL) goto fail;\n\t\t\tif (loop->obj) memset(loop->buffer, 0, _size);\n loop->bufptr[0] = loop->buffer;\n }\n\t}\n\n\n\tPyUFunc_clearfperr();\n\treturn loop;\n\n fail:\n ufuncreduce_dealloc(loop);\n\treturn NULL;\t\n}\n\n\n/* We have two basic kinds of loops */\n/* One is used when arr is not-swapped and aligned and output type\n is the same as input type.\n and another using buffers when one of these is not satisfied.\n\n Zero-length and one-length axes-to-be-reduced are handled separately.\n*/\n\nstatic PyObject *\nPyUFunc_Reduce(PyUFuncObject *self, PyArrayObject *arr, int axis, int otype)\n{\n PyArrayObject *ret=NULL;\n PyUFuncReduceObject *loop;\n intp i, n;\n char *dptr;\n BEGIN_THREADS_DEF\n \t\n /* Construct loop object */\n loop = construct_reduce(self, &arr, axis, otype, UFUNC_REDUCE, 0,\n\t\t\t\t\"reduce\");\n\tif (!loop) return NULL;\n\n LOOP_BEGIN_THREADS\n switch(loop->meth) {\n case ZERODIM_REDUCELOOP:\n\t\t/* fprintf(stderr, \"ZERO..%d\\n\", loop->size); */\n\t\tfor(i=0; isize; i++) {\n\t\t\tif (loop->obj) Py_INCREF(*((PyObject **)loop->idptr));\n\t\t\tmemmove(loop->bufptr[1], loop->idptr, loop->outsize);\n\t\t\tloop->bufptr[1] += loop->outsize;\n\t\t}\n break;\n case ONEDIM_REDUCELOOP:\n\t\t/*fprintf(stderr, \"ONEDIM..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\n\t\t\tif (loop->obj) Py_INCREF(*((PyObject **)loop->it->dataptr));\n memmove(loop->bufptr[1], loop->it->dataptr, \n loop->outsize);\n\t\t\tPyArray_ITER_NEXT(loop->it);\n\t\t\tloop->bufptr[1] += loop->outsize;\n\t\t\tloop->index++;\n\t\t}\t\t\n\t\tbreak;\n case NOBUFFER_UFUNCLOOP:\n\t\t/*fprintf(stderr, \"NOBUFFER..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\n\t\t\t/* Copy first element to output */\n\t\t\tif (loop->obj) \n\t\t\t\tPy_INCREF(*((PyObject **)loop->it->dataptr));\n memmove(loop->bufptr[1], loop->it->dataptr, \n loop->outsize);\n\t\t\t/* Adjust input pointer */\n loop->bufptr[0] = loop->it->dataptr+loop->steps[0];\n loop->function((char **)loop->bufptr, \n\t\t\t\t &(loop->N),\n loop->steps, loop->funcdata);\n\t\t\tUFUNC_CHECK_ERROR(loop);\n\n PyArray_ITER_NEXT(loop->it)\n loop->bufptr[1] += loop->outsize;\n loop->bufptr[2] = loop->bufptr[1];\n loop->index++; \n }\n break;\n case BUFFER_UFUNCLOOP: \n /* use buffer for arr */\n /* \n For each row to reduce\n 1. copy first item over to output (casting if necessary)\n 2. Fill inner buffer \n 3. When buffer is filled or end of row\n a. Cast input buffers if needed\n b. Call inner function.\n 4. Repeat 2 until row is done.\n */\n\t\t/* fprintf(stderr, \"BUFFERED..%d %d\\n\", loop->size, \n\t\t loop->swap); */\n while(loop->index < loop->size) {\n loop->inptr = loop->it->dataptr;\t\t\t\n\t\t\t/* Copy (cast) First term over to output */\n\t\t\tif (loop->cast) {\n\t\t\t\t/* A little tricky because we need to\n\t\t\t\t cast it first */\n\t\t\t\tarr->descr->f->copyswap(loop->buffer,\n\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t loop->insize);\n\t\t\t\tloop->cast(loop->buffer, loop->castbuf,\n\t\t\t\t\t 1, NULL, NULL);\n\t\t\t\tif (loop->obj) \n\t\t\t\t\tPy_INCREF(*((PyObject **)loop->castbuf));\n\t\t\t\tmemcpy(loop->bufptr[1], loop->castbuf,\n\t\t\t\t loop->outsize);\n\t\t\t}\n\t\t\telse { /* Simple copy */\n\t\t\t\tarr->descr->f->copyswap(loop->bufptr[1], \n\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t loop->insize);\n\t\t\t}\n\t\t\tloop->inptr += loop->instrides;\n n = 1;\n while(n < loop->N) {\n /* Copy up to loop->bufsize elements to \n buffer */\n dptr = loop->buffer;\n for (i=0; ibufsize; i++, n++) {\n if (n == loop->N) break;\n arr->descr->f->copyswap(dptr,\n loop->inptr,\n loop->swap,\n loop->insize);\n loop->inptr += loop->instrides;\n dptr += loop->insize;\n }\n if (loop->cast)\n loop->cast(loop->buffer,\n loop->castbuf,\n i, NULL, NULL);\n loop->function((char **)loop->bufptr,\n &i, \n\t\t\t\t\t loop->steps, loop->funcdata);\n\t\t\t\tUFUNC_CHECK_ERROR(loop);\n } \n PyArray_ITER_NEXT(loop->it);\n loop->bufptr[1] += loop->outsize;\n loop->bufptr[2] = loop->bufptr[1]; \n loop->index++;\n }\n }\n\n LOOP_END_THREADS\n\n ret = loop->ret;\n\t/* Hang on to this reference -- will be decref'd with loop */\n Py_INCREF(ret);\n ufuncreduce_dealloc(loop);\n return (PyObject *)ret;\n\n fail:\n LOOP_END_THREADS\n\n if (loop) ufuncreduce_dealloc(loop);\n return NULL;\n}\n\n\nstatic PyObject *\nPyUFunc_Accumulate(PyUFuncObject *self, PyArrayObject *arr, int axis, \n\t\t int otype)\n{\n PyArrayObject *ret=NULL;\n PyUFuncReduceObject *loop;\n intp i, n;\n char *dptr;\n \n /* Construct loop object */\n loop = construct_reduce(self, &arr, axis, otype, UFUNC_ACCUMULATE, 0,\n\t\t\t\t\"accumulate\");\n\tif (!loop) return NULL;\n\n\tLOOP_BEGIN_THREADS\n switch(loop->meth) {\n case ZERODIM_REDUCELOOP: /* Accumulate */\n\t\t/* fprintf(stderr, \"ZERO..%d\\n\", loop->size); */\n\t\tfor(i=0; isize; i++) {\n\t\t\tif (loop->obj) \n\t\t\t\tPy_INCREF(*((PyObject **)loop->idptr));\n\t\t\tmemcpy(loop->bufptr[1], loop->idptr, loop->outsize);\n\t\t\tloop->bufptr[1] += loop->outsize;\n\t\t} \n break;\n case ONEDIM_REDUCELOOP: /* Accumulate */\n\t\t/* fprintf(stderr, \"ONEDIM..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\n\t\t\tif (loop->obj) \n\t\t\t\tPy_INCREF(*((PyObject **)loop->it->dataptr));\n memcpy(loop->bufptr[1], loop->it->dataptr, \n loop->outsize);\n\t\t\tPyArray_ITER_NEXT(loop->it);\n\t\t\tloop->bufptr[1] += loop->outsize;\n\t\t\tloop->index++;\n\t\t}\t\t\n\t\tbreak;\n case NOBUFFER_UFUNCLOOP: /* Accumulate */\n\t\t/* fprintf(stderr, \"NOBUFFER..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\n\t\t\t/* Copy first element to output */\n\t\t\tif (loop->obj) \n\t\t\t\tPy_INCREF(*((PyObject **)loop->it->dataptr));\n memcpy(loop->bufptr[1], loop->it->dataptr, \n loop->outsize);\n\t\t\t/* Adjust input pointer */\n loop->bufptr[0] = loop->it->dataptr+loop->steps[0];\n loop->function((char **)loop->bufptr, \n\t\t\t\t &(loop->N),\n loop->steps, loop->funcdata);\n\t\t\tUFUNC_CHECK_ERROR(loop);\n\n PyArray_ITER_NEXT(loop->it);\n\t\t\tPyArray_ITER_NEXT(loop->rit);\n loop->bufptr[1] = loop->rit->dataptr;\n\t\t\tloop->bufptr[2] = loop->bufptr[1] + loop->steps[1];\n loop->index++;\n }\n break;\n case BUFFER_UFUNCLOOP: /* Accumulate */\n /* use buffer for arr */\n /* \n For each row to reduce\n 1. copy identity over to output (casting if necessary)\n 2. Fill inner buffer \n 3. When buffer is filled or end of row\n a. Cast input buffers if needed\n b. Call inner function.\n 4. Repeat 2 until row is done.\n */\n\t\t/* fprintf(stderr, \"BUFFERED..%d %p\\n\", loop->size, \n\t\t loop->cast); */\n while(loop->index < loop->size) {\n loop->inptr = loop->it->dataptr;\t\t\t\n\t\t\t/* Copy (cast) First term over to output */\n\t\t\tif (loop->cast) {\n\t\t\t\t/* A little tricky because we need to\n\t\t\t\t cast it first */\n\t\t\t\tarr->descr->f->copyswap(loop->buffer,\n\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t loop->insize);\n\t\t\t\tloop->cast(loop->buffer, loop->castbuf,\n\t\t\t\t\t 1, NULL, NULL);\n\t\t\t\tif (loop->obj) \n\t\t\t\t\tPy_INCREF(*((PyObject **)loop->castbuf));\n\t\t\t\tmemcpy(loop->bufptr[1], loop->castbuf,\n\t\t\t\t loop->outsize);\n\t\t\t}\n\t\t\telse { /* Simple copy */\n\t\t\t\tarr->descr->f->copyswap(loop->bufptr[1], \n\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t loop->insize);\n\t\t\t}\n\t\t\tloop->inptr += loop->instrides;\n n = 1;\n while(n < loop->N) {\n /* Copy up to loop->bufsize elements to \n buffer */\n dptr = loop->buffer;\n for (i=0; ibufsize; i++, n++) {\n if (n == loop->N) break;\n arr->descr->f->copyswap(dptr,\n loop->inptr,\n loop->swap,\n loop->insize);\n loop->inptr += loop->instrides;\n dptr += loop->insize;\n }\n if (loop->cast)\n loop->cast(loop->buffer,\n loop->castbuf,\n i, NULL, NULL);\n loop->function((char **)loop->bufptr,\n &i, \n\t\t\t\t\t loop->steps, loop->funcdata);\n\t\t\t\tUFUNC_CHECK_ERROR(loop);\n } \n PyArray_ITER_NEXT(loop->it);\n\t\t\tPyArray_ITER_NEXT(loop->rit);\n loop->bufptr[1] = loop->rit->dataptr;\n\t\t\tloop->bufptr[2] = loop->bufptr[1] + loop->steps[1];\n loop->index++;\n }\n }\n\n\tLOOP_END_THREADS\n ret = loop->ret;\n\t/* Hang on to this reference -- will be decref'd with loop */\n Py_INCREF(ret);\n ufuncreduce_dealloc(loop);\n return (PyObject *)ret;\n\n fail:\n\tLOOP_END_THREADS\n\n if (loop) ufuncreduce_dealloc(loop);\n return NULL;\n}\n\n/* Reduceat performs a reduce over an axis using the indices as a guide\n\nop.reduceat(array,indices) computes\nop.reduce(array[indices[i]:indices[i+1]] \n for i=0..end with an implicit indices[i+1]=len(array)\n assumed when i=end-1\n\nif indices[i+1] <= indices[i]+1 \n then the result is array[indices[i]] for that value\n\nop.accumulate(array) is the same as\nop.reduceat(array,indices)[::2]\nwhere indices is range(len(array)-1) with a zero placed in every other sample\n indices = zeros(len(array)*2-1)\n indices[1::2] = range(1,len(array))\n\noutput shape is based on the size of indices\n */\n\nstatic PyObject *\nPyUFunc_Reduceat(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *ind, \n int axis, int otype)\n{\t\n\tPyArrayObject *ret;\n PyUFuncReduceObject *loop;\n\tintp *ptr=(intp *)ind->data;\n\tintp nn=ind->dimensions[0];\t\t\n\tintp mm=arr->dimensions[axis]-1;\n\tintp n, i, j;\n\tchar *dptr;\n\n\t/* Check for out-of-bounds values in indices array */\t\t\n\tfor (i=0; i mm)) {\n\t\t\tPyErr_Format(PyExc_IndexError, \n\t\t\t\t \"index out-of-bounds (0, %d)\", (int) mm);\n\t\t\treturn NULL;\n\t\t}\n\t\tptr++;\n\t}\n\t\n\tptr = (intp *)ind->data;\n /* Construct loop object */\n loop = construct_reduce(self, &arr, axis, otype, UFUNC_REDUCEAT, nn,\n\t\t\t\t\"reduceat\");\n\tif (!loop) return NULL;\n\n\tLOOP_BEGIN_THREADS\n\tswitch(loop->meth) {\n\t/* zero-length index -- return array immediately */\n\tcase ZERODIM_REDUCELOOP:\n\t\t/* fprintf(stderr, \"ZERO..\\n\"); */\n\t\tbreak;\n\t/* NOBUFFER -- behaved array and same type */\n\tcase NOBUFFER_UFUNCLOOP: \t /* Reduceat */\n\t\t/* fprintf(stderr, \"NOBUFFER..%d\\n\", loop->size); */\n\t\twhile(loop->index < loop->size) {\n\t\t\tptr = (intp *)ind->data;\n\t\t\tfor (i=0; ibufptr[0] = loop->it->dataptr +\t\\\n\t\t\t\t\t(*ptr)*loop->instrides;\n\t\t\t\tif (loop->obj) \n\t\t\t\t\tPy_INCREF(*((PyObject **)loop->bufptr[0]));\n\t\t\t\tmemcpy(loop->bufptr[1], loop->bufptr[0],\n\t\t\t\t loop->outsize);\n\t\t\t\tmm = (i==nn-1 ? arr->dimensions[axis]-*ptr : \\\n\t\t\t\t *(ptr+1) - *ptr) - 1;\n\t\t\t\tif (mm > 0) {\n\t\t\t\t\tloop->bufptr[0] += loop->instrides;\n\t\t\t\t\tloop->bufptr[2] = loop->bufptr[1];\n\t\t\t\t\tloop->function((char **)loop->bufptr,\n\t\t\t\t\t\t &mm, loop->steps,\n\t\t\t\t\t\t loop->funcdata);\n\t\t\t\t\tUFUNC_CHECK_ERROR(loop);\n\t\t\t\t}\t\n\t\t\t\tloop->bufptr[1] += loop->ret->strides[axis];\n\t\t\t\tptr++;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(loop->it);\n\t\t\tPyArray_ITER_NEXT(loop->rit);\n\t\t\tloop->bufptr[1] = loop->rit->dataptr;\n\t\t\tloop->index++;\n\t\t}\n\t\tbreak;\n\n\t/* BUFFER -- misbehaved array or different types */ \n\tcase BUFFER_UFUNCLOOP: /* Reduceat */\n\t\t/* fprintf(stderr, \"BUFFERED..%d\\n\", loop->size); */\n\t\twhile(loop->index < loop->size) {\n\t\t\tptr = (intp *)ind->data;\n\t\t\tfor (i=0; iobj) \n\t\t\t\t\tPy_INCREF(*((PyObject **)loop->idptr));\n\t\t\t\tmemcpy(loop->bufptr[1], loop->idptr, \n\t\t\t\t loop->outsize);\n\t\t\t\tn = 0;\n\t\t\t\tmm = (i==nn-1 ? arr->dimensions[axis] - *ptr :\\\n\t\t\t\t *(ptr+1) - *ptr);\n\t\t\t\tif (mm < 1) mm = 1;\n\t\t\t\tloop->inptr = loop->it->dataptr + \\\n\t\t\t\t\t(*ptr)*loop->instrides;\n\t\t\t\twhile (n < mm) {\n\t\t\t\t\t/* Copy up to loop->bufsize elements\n\t\t\t\t\t to buffer */\n\t\t\t\t\tdptr = loop->buffer;\n\t\t\t\t\tfor (j=0; jbufsize; j++, n++) {\n\t\t\t\t\t\tif (n == mm) break;\n\t\t\t\t\t\tarr->descr->f->copyswap\\\n\t\t\t\t\t\t\t(dptr,\n\t\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t\t loop->insize);\n\t\t\t\t\t\tloop->inptr += loop->instrides;\n\t\t\t\t\t\tdptr += loop->insize;\n\t\t\t\t\t}\n\t\t\t\t\tif (loop->cast)\n\t\t\t\t\t\tloop->cast(loop->buffer,\n\t\t\t\t\t\t\t loop->castbuf,\n\t\t\t\t\t\t\t j, NULL, NULL);\n\t\t\t\t\tloop->bufptr[2] = loop->bufptr[1];\n\t\t\t\t\tloop->function((char **)loop->bufptr,\n\t\t\t\t\t\t &j, loop->steps,\n\t\t\t\t\t\t loop->funcdata);\n\t\t\t\t\tUFUNC_CHECK_ERROR(loop);\n\t\t\t\t} \n\t\t\t\tloop->bufptr[1] += loop->ret->strides[axis];\n\t\t\t\tptr++;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(loop->it);\n\t\t\tPyArray_ITER_NEXT(loop->rit);\n\t\t\tloop->bufptr[1] = loop->rit->dataptr;\n\t\t\tloop->index++;\n\t\t}\n\t\tbreak;\n\t}\n\n\tLOOP_END_THREADS\n\t\n ret = loop->ret;\n\t/* Hang on to this reference -- will be decref'd with loop */\n Py_INCREF(ret);\n ufuncreduce_dealloc(loop);\n return (PyObject *)ret;\n\t\n fail:\n\tLOOP_END_THREADS\n\n if (loop) ufuncreduce_dealloc(loop);\n\treturn NULL;\n}\n\n\n/* This code handles reduce, reduceat, and accumulate \n (accumulate and reduce are special cases of the more general reduceat \n but they are handled separately for speed) \n*/\n\nstatic PyObject * \nPyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args, \n PyObject *kwds, int operation) \n{\n\tint axis=0;\n\tPyArrayObject *mp, *ret = NULL;\n\tPyObject *op, *res=NULL;\n\tPyObject *obj_ind; \n\tPyArrayObject *indices = NULL;\n\tPyArray_Descr *otype=NULL;\n\tstatic char *kwlist1[] = {\"array\", \"axis\", \"dtype\", NULL};\n\tstatic char *kwlist2[] = {\"array\", \"indices\", \"axis\", \"dtype\", NULL}; \n static char *_reduce_type[] = {\"reduce\", \"accumulate\", \\\n\t\t\t\t \"reduceat\", NULL};\n\tif (self == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \"function not supported\");\n\t\treturn NULL;\n\t}\t\n\n\tif (self->nin != 2) {\n\t\tPyErr_Format(PyExc_ValueError, \n \"%s only supported for binary functions\",\n _reduce_type[operation]);\n\t\treturn NULL;\n\t}\n\tif (self->nout != 1) {\n\t\tPyErr_Format(PyExc_ValueError,\n \"%s only supported for functions \" \\\n \"returning a single value\",\n _reduce_type[operation]);\n\t\treturn NULL;\n\t}\n\n\tif (operation == UFUNC_REDUCEAT) {\n\t\tPyArray_Descr *indtype;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"OO|iO&\", kwlist2, \n\t\t\t\t\t\t&op, &obj_ind, &axis, \n\t\t\t\t\t\tPyArray_DescrConverter, \n\t\t\t\t\t\t&otype)) return NULL;\n indices = (PyArrayObject *)PyArray_FromAny(obj_ind, indtype, \n\t\t\t\t\t\t\t 1, 1, CARRAY_FLAGS);\n if (indices == NULL) return NULL;\n\t\tPy_DECREF(indtype);\t\t\n\t}\n\telse {\n\t\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\", kwlist1,\n\t\t\t\t\t\t&op, &axis, \n\t\t\t\t\t\tPyArray_DescrConverter, \n\t\t\t\t\t\t&otype)) return NULL;\n\t}\n\t\n\t/* Ensure input is an array */\t\n\tmp = (PyArrayObject *)PyArray_FromAny(op, NULL, 0, 0, 0);\n\tif (mp == NULL) return NULL;\n\n /* Check to see if input is zero-dimensional */\n if (mp->nd == 0) {\n PyErr_Format(PyExc_TypeError, \"cannot %s on a scalar\",\n _reduce_type[operation]);\n Py_DECREF(mp);\n return NULL; \n }\n\n /* Check to see that type (and otype) is not FLEXIBLE */\n\tif (PyArray_ISFLEXIBLE(mp) || (otype && PyTypeNum_ISFLEXIBLE(otype->type_num))) {\n PyErr_Format(PyExc_TypeError, \n\t\t\t \"cannot perform %s with flexible type\",\n _reduce_type[operation]);\n Py_DECREF(mp);\n return NULL;\n }\n\n\tif (axis < 0) axis += mp->nd;\n\tif (axis < 0 || axis >= mp->nd) {\n\t\tPyErr_SetString(PyExc_ValueError, \"axis not in array\");\n Py_DECREF(mp);\n\t\treturn NULL;\n\t}\n\n\t/* Get default type to reduce over if not given */\n if (otype == NULL) {\n\t\t/* For integer types --- makes sure at \n\t\t least a long is used */\n\t\tint typenum = PyArray_TYPE(mp);\n\t\tif (PyTypeNum_ISINTEGER(typenum) &&\t\\\n\t\t (mp->descr->elsize < sizeof(long))) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(typenum))\n\t\t\t\ttypenum = PyArray_ULONG;\n\t\t\telse\n\t\t\t\ttypenum = PyArray_LONG;\n\t\t}\n\t\telse if (PyTypeNum_ISBOOL(typenum) && \\\n\t\t\t ((strcmp(self->name,\"add\")==0) ||\t\\\n\t\t\t (strcmp(self->name,\"multiply\")==0))) {\n\t\t\ttypenum = PyArray_LONG;\n\t\t}\n\t\totype = PyArray_DescrFromType(typenum);\n\t}\n\n switch(operation) {\n case UFUNC_REDUCE:\n ret = (PyArrayObject *)PyUFunc_Reduce(self, mp, axis, \n otype->type_num);\n\t\tbreak;\n case UFUNC_ACCUMULATE:\n ret = (PyArrayObject *)PyUFunc_Accumulate(self, mp, axis, \n otype->type_num);\n\t\tbreak;\n case UFUNC_REDUCEAT:\n ret = (PyArrayObject *)PyUFunc_Reduceat(self, mp, indices, \n axis, otype->type_num);\n Py_DECREF(indices);\n\t\tbreak;\n }\n Py_DECREF(mp);\n\tPy_DECREF(otype);\n\tif (ret==NULL) return NULL;\n\tif (op->ob_type != ret->ob_type) {\n\t\tres = PyObject_CallMethod(op, \"__array_wrap__\", \"O\", ret);\n\t\tif (res == NULL) PyErr_Clear();\n\t\telse if (res == Py_None) Py_DECREF(res);\n\t\telse {\n\t\t\tPy_DECREF(ret);\n\t\t\treturn res;\n\t\t}\t\n\t}\n\treturn PyArray_Return(ret);\n\t\n}\n\n\n\n/* ---------- */\n\nstatic PyObject *\n_find_array_wrap(PyObject *args)\n{\n\tint nargs, i;\n\tint np = 0;\n\tint argmax = 0;\n\tdouble priority[MAX_ARGS];\n\tdouble maxpriority = PyArray_SUBTYPE_PRIORITY;\n\tPyObject *with_wrap[MAX_ARGS];\n\tPyObject *attr, *wrap;\n\tPyObject *obj;\n\n\tnargs = PyTuple_Size(args);\n\tfor (i=0; i maxpriority) {\n\t\t\tmaxpriority = priority[i];\n\t\t\tPy_DECREF(wrap);\t\n\t\t\twrap = with_wrap[i];\n\t\t} else {\n\t\t\tPy_DECREF(with_wrap[i]);\n\t\t}\n\t}\n\t\n\treturn wrap;\n}\n\nstatic PyObject *\nufunc_generic_call(PyUFuncObject *self, PyObject *args) \n{\n\tint i;\n\tPyTupleObject *ret;\n\tPyArrayObject *mps[MAX_ARGS];\n\tPyObject *retobj[MAX_ARGS];\n\tPyObject *res;\n\tPyObject *obj;\n int errval;\n \n\t/* Initialize all array objects to NULL to make cleanup easier \n\t if something goes wrong. */\n\tfor(i=0; inargs; i++) mps[i] = NULL;\n\t\n errval = PyUFunc_GenericFunction(self, args, mps);\n if (errval < 0) {\n\t\tfor(i=0; inargs; i++) Py_XDECREF(mps[i]);\n\t\tif (errval == -1)\n\t\t\treturn NULL;\n\t\telse {\n\t\t\tPy_INCREF(Py_NotImplemented);\n\t\t\treturn Py_NotImplemented;\n\t\t}\n }\n\t\n\tfor(i=0; inin; i++) Py_DECREF(mps[i]);\n\n\t/* Use __array_wrap__ on all outputs \n\t if present on one of the input arguments.\n\t If present for multiple inputs:\n\t use __array_wrap__ of input object with largest \n\t\t__array_priority__ (default = 0.0)\n\t */\n\tobj = _find_array_wrap(args);\n\t\n\t/* wrap outputs */\n\tfor (i=0; inout; i++) {\n\t\tint j=self->nin+i;\n\t\t/* check to see if any UPDATEIFCOPY flags are set \n\t\t which meant that a temporary output was generated \n\t\t*/\n\t\tif (mps[j]->flags & UPDATEIFCOPY) {\n\t\t\tPyObject *old = mps[j]->base;\n\t\t\tPy_INCREF(old); /* we want to hang on to this */\n\t\t\tPy_DECREF(mps[j]); /* should trigger the copy \n\t\t\t\t\t back into old */\n\t\t\tmps[j] = (PyArrayObject *)old;\n\t\t}\n\t\tif (obj != NULL) {\n\t\t\tres = PyObject_CallFunction(obj, \"O(OOi)\",\n\t\t\t\t\t\t mps[j], self, args, i);\n\t\t\tif (res == NULL) {\n\t\t\t\tPyErr_Clear();\n\t\t\t\tres = PyObject_CallFunctionObjArgs(obj, mps[j], NULL);\n\t\t\t}\n\t\t\tPy_DECREF(obj);\n\t\t\tif (res == NULL) PyErr_Clear();\n\t\t\telse if (res == Py_None) Py_DECREF(res);\n\t\t\telse {\n\t\t\t\tPy_DECREF(mps[j]);\n\t\t\t\tretobj[i] = res;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tretobj[i] = PyArray_Return(mps[j]);\n\t}\n\t\n\tif (self->nout == 1) { \n\t\treturn retobj[0];\n\t} else { \n\t\tret = (PyTupleObject *)PyTuple_New(self->nout);\n\t\tfor(i=0; inout; i++) {\n\t\t\tPyTuple_SET_ITEM(ret, i, retobj[i]);\n\t\t}\n\t\treturn (PyObject *)ret;\n\t}\t\n\n}\n\nstatic PyObject *\nufunc_update_use_defaults(PyObject *dummy, PyObject *args)\n{\n\tPyObject *errobj;\n\tint errmask, bufsize;\n\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n\tPyUFunc_USEDEFAULTS = 0;\n\tif (PyUFunc_GetPyValues(\"test\", &bufsize, &errmask, &errobj) < 0) return NULL;\n\t\n\tif ((errmask == UFUNC_ERR_DEFAULT) &&\t\t\\\n\t (bufsize == PyArray_BUFSIZE) &&\t\t\\\n\t (PyTuple_GET_ITEM(errobj, 1) == Py_None)) {\n\t\tPyUFunc_USEDEFAULTS = 1;\n\t}\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyUFuncGenericFunction pyfunc_functions[] = {PyUFunc_On_Om};\n\nstatic char \ndoc_frompyfunc[] = \"frompyfunc(func, nin, nout) take an arbitrary python function that takes nin objects as input and returns nout objects and return a universal function (ufunc). This ufunc always returns PyObject arrays\";\n\nstatic PyObject *\nufunc_frompyfunc(PyObject *dummy, PyObject *args, PyObject *kwds) {\n /* Keywords are ignored for now */\n \n PyObject *function, *pyname=NULL;\n int nin, nout, i;\n PyUFunc_PyFuncData *fdata;\n PyUFuncObject *self;\n char *fname, *str;\n int fname_len=-1;\n\tint offset[2];\n\n if (!PyArg_ParseTuple(args, \"Oii\", &function, &nin, &nout)) return NULL;\n\n if (!PyCallable_Check(function)) {\n PyErr_SetString(PyExc_TypeError, \"function must be callable\");\n return NULL;\n }\n\t\n self = _pya_malloc(sizeof(PyUFuncObject));\n if (self == NULL) return NULL;\n PyObject_Init((PyObject *)self, &PyUFunc_Type);\n\n\tself->userloops = NULL;\n\tself->nin = nin;\n\tself->nout = nout;\n\tself->nargs = nin+nout;\n\tself->identity = PyUFunc_None;\t\n\tself->functions = pyfunc_functions;\n\n\tself->ntypes = 1;\n\tself->check_return = 0;\n\n pyname = PyObject_GetAttrString(function, \"__name__\");\n if (pyname)\n (void) PyString_AsStringAndSize(pyname, &fname, &fname_len);\n \n if (PyErr_Occurred()) {\n fname = \"?\";\n fname_len = 1;\n PyErr_Clear();\n } \n Py_XDECREF(pyname);\n\n\n\n\t/* self->ptr holds a pointer for enough memory for\n\t self->data[0] (fdata)\n\t self->data\n\t self->name\n\t self->types\n\n\t To be safest, all of these need their memory aligned on void * pointers\n\t Therefore, we may need to allocate extra space.\n\t*/\n\toffset[0] = sizeof(PyUFunc_PyFuncData);\n\ti = (sizeof(PyUFunc_PyFuncData) % sizeof(void *));\n\tif (i) offset[0] += (sizeof(void *) - i);\n\toffset[1] = self->nargs;\n\ti = (self->nargs % sizeof(void *));\n\tif (i) offset[1] += (sizeof(void *)-i);\n\n self->ptr = _pya_malloc(offset[0] + offset[1] + sizeof(void *) + \\\n\t\t\t (fname_len+14));\n\n\tif (self->ptr == NULL) return PyErr_NoMemory();\n Py_INCREF(function);\n self->obj = function;\n\tfdata = (PyUFunc_PyFuncData *)(self->ptr);\n fdata->nin = nin;\n fdata->nout = nout;\n fdata->callable = function;\n \n self->data = (void **)(self->ptr + offset[0]);\n self->data[0] = (void *)fdata;\n\t\n\tself->types = (char *)self->data + sizeof(void *);\n for (i=0; inargs; i++) self->types[i] = PyArray_OBJECT;\n\n str = self->types + offset[1];\n memcpy(str, fname, fname_len);\n memcpy(str+fname_len, \" (vectorized)\", 14);\n \n self->name = str;\n\n /* Do a better job someday */\n self->doc = \"dynamic ufunc based on a python function\";\n \n\t\n\treturn (PyObject *)self;\n}\n\n\n/*UFUNC_API*/\nstatic PyObject *\nPyUFunc_FromFuncAndData(PyUFuncGenericFunction *func, void **data, \n\t\t\tchar *types, int ntypes,\n\t\t\tint nin, int nout, int identity, \n\t\t\tchar *name, char *doc, int check_return) \n{\n\tPyUFuncObject *self;\n\n self = _pya_malloc(sizeof(PyUFuncObject));\n if (self == NULL) return NULL;\n PyObject_Init((PyObject *)self, &PyUFunc_Type);\n\t\n\tself->nin = nin;\n\tself->nout = nout;\n\tself->nargs = nin+nout;\n\tself->identity = identity;\n\t\n\tself->functions = func;\n\tself->data = data;\n\tself->types = types;\n\tself->ntypes = ntypes;\n\tself->check_return = check_return;\n self->ptr = NULL;\n self->obj = NULL;\n\tself->userloops=NULL;\n\t\n\tif (name == NULL) self->name = \"?\";\n\telse self->name = name;\n\t\n if (doc == NULL) self->doc = \"NULL\";\n\telse self->doc = doc;\n\t\n\treturn (PyObject *)self;\n}\n\n/*UFUNC_API*/\nstatic int\nPyUFunc_RegisterLoopForType(PyUFuncObject *ufunc, \n\t\t\t int usertype,\n\t\t\t PyUFuncGenericFunction function,\n\t\t\t void *data)\n{\n\tPyArray_Descr *descr;\n \tPyObject *key, *cobj;\n\tint ret;\t\n\t\n\tdescr=PyArray_DescrFromType(usertype);\n\tif ((usertype < PyArray_USERDEF) || (descr==NULL)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"unknown type\");\n\t\treturn -1;\n\t}\n\tPy_DECREF(descr);\n\t\n\tif (ufunc->userloops == NULL) {\n\t\tufunc->userloops = PyDict_New();\n\t}\n\tkey = PyInt_FromLong((long) usertype);\n\tif (key == NULL) return -1;\n\tcobj = PyCObject_FromVoidPtr((void *)function, NULL);\n\tif (cobj == NULL) {Py_DECREF(key); return -1;}\n\tif (data == NULL) {\n\t\tret = PyDict_SetItem(ufunc->userloops, key, cobj);\n\t\tPy_DECREF(cobj);\n\t\tPy_DECREF(key);\n\t\treturn ret;\n\t}\n\telse {\n\t\tPyObject *cobj2, *tmp;\n\t\tcobj2 = PyCObject_FromVoidPtr(data, NULL);\n\t\tif (cobj2 == NULL) {\n\t\t\tPy_DECREF(cobj); \n\t\t\tPy_DECREF(key);\n\t\t\treturn -1;\n\t\t}\n\t\ttmp=Py_BuildValue(\"NN\", cobj, cobj2);\n\t\tret = PyDict_SetItem(ufunc->userloops, key, tmp);\n\t\tPy_DECREF(tmp);\n\t\tPy_DECREF(key);\n\t\treturn ret;\n\t}\n}\n\nstatic void\nufunc_dealloc(PyUFuncObject *self)\n{\n if (self->ptr) _pya_free(self->ptr);\n\tPy_XDECREF(self->userloops);\n Py_XDECREF(self->obj);\n _pya_free(self);\n}\n\nstatic PyObject *\nufunc_repr(PyUFuncObject *self)\n{\n\tchar buf[100];\n\t\n\tsprintf(buf, \"\", self->name);\n\t\n\treturn PyString_FromString(buf);\n}\n\n\n/* -------------------------------------------------------- */\n\n/* op.outer(a,b) is equivalent to op(a[:,NewAxis,NewAxis,etc.],b)\n where a has b.ndim NewAxis terms appended.\n\n The result has dimensions a.ndim + b.ndim\n */\n\nstatic PyObject *\nufunc_outer(PyUFuncObject *self, PyObject *args) \n{\n\tint i;\n\tPyObject *ret;\n\tPyArrayObject *ap1=NULL, *ap2=NULL, *ap_new=NULL;\n\tPyObject *new_args, *tmp;\n\tPyObject *shape1, *shape2, *newshape;\n\n\tif(self->nin != 2) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"outer product only supported \"\\\n\t\t\t\t\"for binary functions\");\n\t\treturn NULL;\n\t}\n\t\n\tif (PySequence_Length(args) != 2) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"exactly two arguments expected\");\n\t\treturn NULL;\n\t}\n\t\n\ttmp = PySequence_GetItem(args, 0);\n\tif (tmp == NULL) return NULL;\n\tap1 = (PyArrayObject *)\t\t\t\t\t\\\n\t\tPyArray_FromObject(tmp, PyArray_NOTYPE, 0, 0);\n\tPy_DECREF(tmp);\n\tif (ap1 == NULL) return NULL;\n\t\n\ttmp = PySequence_GetItem(args, 1);\n\tif (tmp == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_FromObject(tmp, PyArray_NOTYPE, 0, 0);\n\tPy_DECREF(tmp);\n\tif (ap2 == NULL) {Py_DECREF(ap1); return NULL;}\n\n\t/* Construct new shape tuple */\n\tshape1 = PyTuple_New(ap1->nd);\n\tif (shape1 == NULL) goto fail;\n\tfor (i=0; ind; i++) \n\t\tPyTuple_SET_ITEM(shape1, i, \n\t\t\t\t PyLong_FromLongLong((longlong)ap1->\t\\\n\t\t\t\t\t\t dimensions[i]));\n\t\n\tshape2 = PyTuple_New(ap2->nd);\n\tfor (i=0; ind; i++) \n\t\tPyTuple_SET_ITEM(shape2, i, PyInt_FromLong((long) 1));\n\tif (shape2 == NULL) {Py_DECREF(shape1); goto fail;}\n\tnewshape = PyNumber_Add(shape1, shape2);\n\tPy_DECREF(shape1);\n\tPy_DECREF(shape2);\n\tif (newshape == NULL) goto fail;\n\t\n\tap_new = (PyArrayObject *)PyArray_Reshape(ap1, newshape);\n\tPy_DECREF(newshape);\n\tif (ap_new == NULL) goto fail;\n\t\n\tnew_args = Py_BuildValue(\"(OO)\", ap_new, ap2);\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\tPy_DECREF(ap_new);\t\n\tret = ufunc_generic_call(self, new_args);\n\tPy_DECREF(new_args);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ap_new);\n\treturn NULL;\n\n}\n\n\nstatic PyObject *\nufunc_reduce(PyUFuncObject *self, PyObject *args, PyObject *kwds) \n{\n\t\n\treturn PyUFunc_GenericReduction(self, args, kwds, UFUNC_REDUCE);\n}\n\nstatic PyObject *\nufunc_accumulate(PyUFuncObject *self, PyObject *args, PyObject *kwds) \n{\n\t\n\treturn PyUFunc_GenericReduction(self, args, kwds, UFUNC_ACCUMULATE);\n}\n\nstatic PyObject *\nufunc_reduceat(PyUFuncObject *self, PyObject *args, PyObject *kwds) \n{\t\n\treturn PyUFunc_GenericReduction(self, args, kwds, UFUNC_REDUCEAT);\n}\n\n\nstatic struct PyMethodDef ufunc_methods[] = {\n\t{\"reduce\", (PyCFunction)ufunc_reduce, METH_VARARGS | METH_KEYWORDS},\n\t{\"accumulate\", (PyCFunction)ufunc_accumulate, \n\t METH_VARARGS | METH_KEYWORDS},\n\t{\"reduceat\", (PyCFunction)ufunc_reduceat, \n\t METH_VARARGS | METH_KEYWORDS},\t\n\t{\"outer\", (PyCFunction)ufunc_outer, METH_VARARGS},\n\t{NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\n\n/* construct the string\n y1,y2,...,yn\n*/\n\nstatic void\n_makeargs(int num, char ltr, char *str) \n{\n\tint ind=0;\n\tint k;\n\tstatic char *digits=\"123456789ABCDE\";\n\n\tif (num == 1) {\n\t\tstr[0] = ltr;\n\t\tind = 1;\n\t}\n\telse {\n\t\tfor (k=0; ktype;\n\tPy_DECREF(descr);\n\treturn ret;\n} \n\nstatic PyObject *\nufunc_getattr(PyUFuncObject *self, char *name)\n{\n\tPyObject *obj;\n\t/* Put docstring first or FindMethod finds it...*/\n\t/* could so some introspection on name and nin + nout */\n\t/* to automate the first part of it */\n\t/* the doc string shouldn't need the calling convention */\n\tif (strcmp(name, \"__doc__\") == 0) {\n\t\tstatic char doc[256];\n\t\tstatic char tmp1[3*MAX_ARGS+2];\n\t\tstatic char tmp2[3*MAX_ARGS+2];\n\t\t/* construct \n\t\t y1,y2,,... = name(x1,x2,...) __doc__\n\t\t*/\t\t\n\t\t_makeargs(self->nout, 'y', tmp1);\n\t\t_makeargs(self->nin, 'x', tmp2);\n\t\tsnprintf(doc, 256, \"%s = %s(%s) %s\", tmp1, self->name, \n\t\t\t tmp2, self->doc);\n\t\treturn PyString_FromString(doc);\n\t}\n\tobj = Py_FindMethod(ufunc_methods, (PyObject *)self, name);\n\tif (obj != NULL) return obj;\n\tPyErr_Clear();\n\tif (strcmp(name, \"nin\") == 0) {\n\t\treturn PyInt_FromLong(self->nin);\n\t}\n\telse if (strcmp(name, \"nout\") == 0) {\n\t\treturn PyInt_FromLong(self->nout);\n\t}\n\telse if (strcmp(name, \"nargs\") == 0) {\n\t\treturn PyInt_FromLong(self->nargs);\n\t}\n\telse if (strcmp(name, \"ntypes\") == 0) {\n\t\treturn PyInt_FromLong(self->ntypes);\n\t}\n\telse if (strcmp(name, \"types\") == 0) {\n\t\t/* return a list with types grouped\n\t\t input->output */\n\t\tPyObject *list;\n\t\tPyObject *str;\n\t\tint k, j, n, nt=self->ntypes;\n\t\tint ni = self->nin;\n\t\tint no = self->nout;\n\t\tchar *t;\n\t\tlist = PyList_New(nt);\n\t\tif (list == NULL) return NULL;\n\t\tt = _pya_malloc(no+ni+2);\n\t\tn = 0;\n\t\tfor (k=0; ktypes[n]);\n\t\t\t\tn++;\n\t\t\t}\n\t\t\tt[ni] = '-';\n\t\t\tt[ni+1] = '>';\n\t\t\tfor (j=0; jtypes[n]);\n\t\t\t\tn++;\n\t\t\t}\n\t\t\tstr = PyString_FromStringAndSize(t, no+ni+2);\n\t\t\tPyList_SET_ITEM(list, k, str);\n\t\t}\n\t\t_pya_free(t);\n\t\treturn list;\n\t\t\n\t}\n\telse if (strcmp(name, \"__name__\") == 0) {\n\t\treturn PyString_FromString(self->name);\n\t}\n\telse if (strcmp(name, \"identity\") == 0) {\n\t\tswitch(self->identity) {\n\t\tcase PyUFunc_One:\n\t\t\treturn PyInt_FromLong(1);\n\t\tcase PyUFunc_Zero:\n\t\t\treturn PyInt_FromLong(0);\n\t\tdefault:\n\t\t\tPy_INCREF(Py_None);\n\t\t\treturn Py_None;\n\t\t}\n\t}\n\tPyErr_SetString(PyExc_AttributeError, name);\n\treturn NULL;\n}\n\n#undef _typecharfromnum\n\nstatic int\nufunc_setattr(PyUFuncObject *self, char *name, PyObject *v) \n{\n\treturn -1;\n}\n\nstatic char Ufunctype__doc__[] = \n\t\"Optimized functions make it possible to implement arithmetic \"\\\n\t\"with arrays efficiently\";\n\nstatic PyTypeObject PyUFunc_Type = {\n\tPyObject_HEAD_INIT(0)\n\t0,\t\t\t\t/*ob_size*/\n\t\"numpy.ufunc\",\t\t\t/*tp_name*/\n\tsizeof(PyUFuncObject),\t\t/*tp_basicsize*/\n\t0,\t\t\t\t/*tp_itemsize*/\n\t/* methods */\n\t(destructor)ufunc_dealloc,\t/*tp_dealloc*/\n\t(printfunc)0,\t\t /*tp_print*/\n\t(getattrfunc)ufunc_getattr,\t/*tp_getattr*/\n\t(setattrfunc)ufunc_setattr,\t/*tp_setattr*/\n\t(cmpfunc)0,\t \t/*tp_compare*/\n\t(reprfunc)ufunc_repr,\t\t/*tp_repr*/\n\t0,\t\t\t /*tp_as_number*/\n\t0,\t\t /*tp_as_sequence*/\n\t0,\t\t /*tp_as_mapping*/\n\t(hashfunc)0,\t\t/*tp_hash*/\n\t(ternaryfunc)ufunc_generic_call,\t\t/*tp_call*/\n\t(reprfunc)ufunc_repr,\t\t/*tp_str*/\n\t\t\n\t/* Space for future expansion */\n\t0L,0L,0L,0L,\n\tUfunctype__doc__ /* Documentation string */\n};\n\n/* End of code for ufunc objects */\n/* -------------------------------------------------------- */\n", + "source_code_before": "\n/*\n Python Universal Functions Object -- Math for all types, plus fast \n arrays math\n \n Full description\n \n This supports mathematical (and Boolean) functions on arrays and other python\n objects. Math on large arrays of basic C types is rather efficient.\n\n Travis E. Oliphant (2005)\n Assistant Professor\n Brigham Young University\n\n based on the \n\n Original Implementation: \n Copyright (c) 1995, 1996, 1997 Jim Hugunin, hugunin@mit.edu\n\n with inspiration and code from\n Numarray\n Space Science Telescope Institute\n J. Todd Miller\n Perry Greenfield\n Rick White\n \n*/\n\n\ntypedef double (DoubleBinaryFunc)(double x, double y);\ntypedef float (FloatBinaryFunc)(float x, float y);\ntypedef longdouble (LongdoubleBinaryFunc)(longdouble x, longdouble y);\n\ntypedef void (CdoubleBinaryFunc)(cdouble *x, cdouble *y, cdouble *res);\ntypedef void (CfloatBinaryFunc)(cfloat *x, cfloat *y, cfloat *res);\ntypedef void (ClongdoubleBinaryFunc)(clongdouble *x, clongdouble *y, \\\n\t\t\t\t clongdouble *res);\n\n/*UFUNC_API*/\nstatic void\nPyUFunc_ff_f_As_dd_d(char **args, intp *dimensions, intp *steps, void *func)\n{\n\tregister intp i, n=dimensions[0];\n\tregister intp is1=steps[0],is2=steps[1],os=steps[2];\n\tchar *ip1=args[0], *ip2=args[1], *op=args[2];\n\t\n\tfor(i=0; inin, nout=data->nout;\n int ntot;\n PyObject *tocall = data->callable; \n char *ptrs[MAX_ARGS];\n PyObject *arglist, *result;\n PyObject *in, **op;\n\n ntot = nin+nout;\n\n for (j=0; j < ntot; j++) ptrs[j] = args[j];\n\tfor(i=0; i> UFUNC_SHIFT_##NAME, \\\n\t\t\t\t\t errobj, str, retstatus) < 0) \\\n\t\t\t\treturn -1;\t\t \\\n\t\t\t}}\n\n\tif (errmask && retstatus) {\n\t\tHANDLEIT(DIVIDEBYZERO, \"divide by zero\");\n\t\tHANDLEIT(OVERFLOW, \"overflow\");\n\t\tHANDLEIT(UNDERFLOW, \"underflow\");\n\t\tHANDLEIT(INVALID, \"invalid\");\n\t}\n\n#undef HANDLEIT\n\n\treturn 0;\n}\n\n\n/* Checking the status flag clears it */\n/*UFUNC_API*/\nstatic void\nPyUFunc_clearfperr()\n{\n\tint retstatus;\n\n\tUFUNC_CHECK_STATUS(retstatus)\n}\n\n\n#define UFUNC_NOSCALAR 0\n#define UFUNC_BOOL_SCALAR 1\n#define UFUNC_INTPOS_SCALAR 2\n#define UFUNC_INTNEG_SCALAR 3\n#define UFUNC_FLOAT_SCALAR 4\n#define UFUNC_COMPLEX_SCALAR 5\n#define UFUNC_OBJECT_SCALAR 6\n\n#define NO_UFUNCLOOP 0\n#define ZERODIM_REDUCELOOP 0\n#define ONE_UFUNCLOOP 1\n#define ONEDIM_REDUCELOOP 1\n#define NOBUFFER_UFUNCLOOP 2\n#define NOBUFFER_REDUCELOOP 2\n#define BUFFER_UFUNCLOOP 3\n#define BUFFER_REDUCELOOP 3\n\n\nstatic char\n_lowest_type(char intype)\n{\n switch(intype) {\n\t/* case PyArray_BYTE */\n\tcase PyArray_SHORT:\n case PyArray_INT:\n case PyArray_LONG:\n\tcase PyArray_LONGLONG:\n\t\treturn PyArray_BYTE;\n\t/* case PyArray_UBYTE */\n case PyArray_USHORT:\n case PyArray_UINT:\n\tcase PyArray_ULONG:\n\tcase PyArray_ULONGLONG:\n\t\treturn PyArray_UBYTE;\n\t/* case PyArray_FLOAT:*/\n case PyArray_DOUBLE:\n\tcase PyArray_LONGDOUBLE:\n\t\treturn PyArray_FLOAT;\n\t/* case PyArray_CFLOAT:*/\n case PyArray_CDOUBLE:\n\tcase PyArray_CLONGDOUBLE:\n\t\treturn PyArray_CFLOAT;\n default:\n return intype;\n }\n}\n\n/* Called to determine coercion\n */\n\nstatic int \n_cancoerce(char thistype, char neededtype, char scalar) \n{\n\n\tswitch(scalar) {\n\tcase UFUNC_NOSCALAR:\n\tcase UFUNC_BOOL_SCALAR:\n\tcase UFUNC_OBJECT_SCALAR:\n\t\treturn PyArray_CanCastSafely(thistype, neededtype);\n\tcase UFUNC_INTPOS_SCALAR:\n\t\treturn (neededtype >= PyArray_UBYTE);\n\tcase UFUNC_INTNEG_SCALAR:\n\t\treturn (neededtype >= PyArray_BYTE) &&\t\t\\\n\t\t\t!(PyTypeNum_ISUNSIGNED(neededtype));\n\tcase UFUNC_FLOAT_SCALAR:\n\t\treturn (neededtype >= PyArray_FLOAT);\n\tcase UFUNC_COMPLEX_SCALAR:\n\t\treturn (neededtype >= PyArray_CFLOAT);\n\t}\n\tfprintf(stderr, \"\\n**Error** coerce fall through: %d %d %d\\n\\n\", \n\t\tthistype, neededtype, scalar);\n\treturn 1; /* should never get here... */ \n}\n\n\nstatic int \nselect_types(PyUFuncObject *self, int *arg_types, \n PyUFuncGenericFunction *function, void **data,\n\t char *scalars)\n{\n\n\tint i=0, j;\n\tchar start_type;\n\t\n\tif (PyTypeNum_ISUSERDEF((arg_types[0]))) {\n\t\tPyObject *key, *obj;\n\t\tfor (i=0; inin; i++) {\n\t\t\tif (arg_types[i] != arg_types[0]) {\n\t\t\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\t\t\"ufuncs on user defined\" \\\n\t\t\t\t\t\t\" types don't support \"\\\n\t\t\t\t\t\t\"coercion\");\n\t\t\t\treturn -1;\n\t\t\t}\n\t\t}\n\t\tfor (i=self->nin; inargs; i++) {\n\t\t\targ_types[i] = arg_types[0];\n\t\t}\n\n\t\tobj = NULL;\n\t\tif (self->userloops) {\n\t\t\tkey = PyInt_FromLong((long) arg_types[0]);\n\t\t\tif (key == NULL) return -1;\n\t\t\tobj = PyDict_GetItem(self->userloops, key);\n\t\t\tPy_DECREF(key);\n\t\t}\n\t\tif (obj == NULL) {\n\t\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\t\"no registered loop for this \"\t\\\n\t\t\t\t\t\"user-defined type\");\n\t\t\treturn -1;\t\t\t\n\t\t}\n\t\tif PyTuple_Check(obj) {\n\t\t\t*function = (PyUFuncGenericFunction) \\\n\t\t\t\tPyCObject_AsVoidPtr(PyTuple_GET_ITEM(obj, 0));\n\t\t\t*data = PyCObject_AsVoidPtr(PyTuple_GET_ITEM(obj, 1));\n\t\t}\n\t\telse {\n\t\t\t*function = (PyUFuncGenericFunction)\t\\\n\t\t\t\tPyCObject_AsVoidPtr(obj);\n\t\t\t*data = NULL;\n\t\t}\n Py_DECREF(obj);\n\t\treturn 0;\n\t}\n\t\n\n\tstart_type = arg_types[0];\n\t/* If the first argument is a scalar we need to place \n\t the start type as the lowest type in the class\n\t*/\n\tif (scalars[0] != UFUNC_NOSCALAR) {\n\t\tstart_type = _lowest_type(start_type);\n\t}\n\n\twhile (intypes && start_type > self->types[i*self->nargs]) \n\t\ti++;\n\n\tfor(;intypes; i++) {\n\t\tfor(j=0; jnin; j++) {\n\t\t\tif (!_cancoerce(arg_types[j], \n\t\t\t\t\tself->types[i*self->nargs+j],\n\t\t\t\t\tscalars[j]))\n\t\t\t\tbreak;\n\t\t}\n\t\tif (j == self->nin) break;\n\t}\n\tif(i>=self->ntypes) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"function not supported for these types, \"\\\n\t\t\t\t\"and can't coerce safely to supported types\");\n\t\treturn -1;\n\t}\n\tfor(j=0; jnargs; j++) \n\t\targ_types[j] = self->types[i*self->nargs+j];\n\n if (self->data)\n *data = self->data[i];\n else \n *data = NULL;\n\t*function = self->functions[i];\n\n\treturn 0;\n}\n\nstatic int PyUFunc_USEDEFAULTS=0;\n\n/*UFUNC_API*/\nstatic int\nPyUFunc_GetPyValues(char *name, int *bufsize, int *errmask, PyObject **errobj)\n{\n PyObject *thedict;\n PyObject *ref=NULL;\n\tPyObject *retval;\n\tstatic PyObject *thestring=NULL;\n\n\tif (!PyUFunc_USEDEFAULTS) {\n\t\tif (thestring == NULL) {\n\t\t\tthestring = PyString_InternFromString(UFUNC_PYVALS_NAME);\n\t\t}\n\t\tthedict = PyEval_GetLocals();\n\t\tref = PyDict_GetItem(thedict, thestring);\n\t\tif (ref == NULL) {\n\t\t\tthedict = PyEval_GetGlobals();\n\t\t\tref = PyDict_GetItem(thedict, thestring);\n\t\t}\n\t\tif (ref == NULL) {\n\t\t\tthedict = PyEval_GetBuiltins();\n\t\t\tref = PyDict_GetItem(thedict, thestring);\n\t\t}\n\t}\n\tif (ref == NULL) {\n\t\t*errmask = UFUNC_ERR_DEFAULT;\n\t\t*errobj = Py_BuildValue(\"NO\",\n\t\t\t\t\tPyString_FromString(name),\n\t\t\t\t\tPy_None);\n\t\t*bufsize = PyArray_BUFSIZE;\n\t\treturn 0;\n\t}\n\t*errobj = NULL;\n\tif (!PyList_Check(ref) || (PyList_GET_SIZE(ref)!=3)) {\n\t\tPyErr_Format(PyExc_TypeError, \"%s must be a length 3 list.\",\n\t\t\t UFUNC_PYVALS_NAME);\n\t\treturn -1;\n\t}\n\n\t*bufsize = PyInt_AsLong(PyList_GET_ITEM(ref, 0));\n\tif ((*bufsize == -1) && PyErr_Occurred()) return -1;\n\tif ((*bufsize < PyArray_MIN_BUFSIZE) ||\t\\\n\t (*bufsize > PyArray_MAX_BUFSIZE) || \\\n\t (*bufsize % 16 != 0)) {\n\t\tPyErr_Format(PyExc_ValueError, \n\t\t\t \"buffer size (%d) is not \"\t\\\n\t\t\t \"in range (%d - %d) or not a multiple of 16\", \n\t\t\t *bufsize, PyArray_MIN_BUFSIZE, \n\t\t\t PyArray_MAX_BUFSIZE);\n\t\treturn -1;\n\t}\n\n\t*errmask = PyInt_AsLong(PyList_GET_ITEM(ref, 1));\n\tif (*errmask < 0) {\n\t\tif (PyErr_Occurred()) return -1;\n\t\tPyErr_Format(PyExc_ValueError,\t\t\\\n\t\t\t \"invalid error mask (%d)\", \n\t\t\t *errmask);\n\t\treturn -1;\n\t}\n\t\n\tretval = PyList_GET_ITEM(ref, 2);\n\tif (retval != Py_None && !PyCallable_Check(retval)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"callback function must be callable\");\n\t\treturn -1;\n\t}\n\n\t*errobj = Py_BuildValue(\"NO\", \n\t\t\t\tPyString_FromString(name),\n\t\t\t\tretval);\n\tif (*errobj == NULL) return -1;\n\t\n\treturn 0;\n}\n\n\nstatic char\n_scalar_kind(int typenum, PyArrayObject **arr) \n{\n\tif (PyTypeNum_ISSIGNED(typenum)) return UFUNC_INTNEG_SCALAR;\n\tif (PyTypeNum_ISFLOAT(typenum)) return UFUNC_FLOAT_SCALAR;\n\tif (PyTypeNum_ISCOMPLEX(typenum)) return UFUNC_COMPLEX_SCALAR;\n\tif (PyTypeNum_ISUNSIGNED(typenum)) return UFUNC_INTPOS_SCALAR;\n\tif (PyTypeNum_ISBOOL(typenum)) return UFUNC_BOOL_SCALAR;\n\treturn UFUNC_OBJECT_SCALAR;\n}\n\n\n/* Create copies for any arrays that are less than loop->bufsize\n in total size and are mis-behaved or in need\n of casting.\n*/\n\nstatic int\n_create_copies(PyUFuncLoopObject *loop, int *arg_types, PyArrayObject **mps)\n{\n\tint nin = loop->ufunc->nin;\n\tint i;\n\tintp size;\n\tPyObject *new;\n\tPyArray_Descr *ntype; \n\tPyArray_Descr *atype;\n\n\tfor (i=0; idescr;\n\t\t\tatype = PyArray_DescrFromType(arg_types[i]);\n\t\t\tif (PyArray_EquivTypes(atype, ntype)) {\n\t\t\t\targ_types[i] = ntype->type_num;\n\t\t\t}\n\t\t\tPy_DECREF(atype);\n\t\t}\n\t\tif (size < loop->bufsize) {\n\t\t\tif (!(PyArray_ISBEHAVED_RO(mps[i])) ||\t\t\\\n\t\t\t PyArray_TYPE(mps[i]) != arg_types[i]) {\n\t\t\t\tntype = PyArray_DescrFromType(arg_types[i]);\n\t\t\t\tnew = PyArray_FromAny((PyObject *)mps[i], \n\t\t\t\t\t\t ntype, 0, 0,\n\t\t\t\t\t\t FORCECAST | ALIGNED);\n\t\t\t\tif (new == NULL) return -1;\n\t\t\t\tPy_DECREF(mps[i]);\n\t\t\t\tmps[i] = (PyArrayObject *)new;\n\t\t\t}\n\t\t}\n\t}\n\t\n\treturn 0;\n}\n\n#define _GETATTR_(str, rstr) if (strcmp(name, #str) == 0) { \\\n return PyObject_HasAttrString(op, \"__\" #rstr \"__\");}\n\nstatic int\n_has_reflected_op(PyObject *op, char *name)\n{\n _GETATTR_(add, radd)\n _GETATTR_(subtract, rsub)\n _GETATTR_(multiply, rmul)\n _GETATTR_(divide, rdiv)\n _GETATTR_(true_divide, rtruediv)\n _GETATTR_(floor_divide, rfloordiv)\n _GETATTR_(remainder, rmod)\n _GETATTR_(power, rpow)\n _GETATTR_(left_shift, rrlshift)\n _GETATTR_(right_shift, rrshift)\n _GETATTR_(bitwise_and, rand)\n _GETATTR_(bitwise_xor, rxor)\n _GETATTR_(bitwise_or, ror)\n return 0;\n}\n\n#undef _GETATTR_\n\n\nstatic int\nconstruct_matrices(PyUFuncLoopObject *loop, PyObject *args, PyArrayObject **mps)\n{\n int nargs, i, maxsize;\n int arg_types[MAX_ARGS];\n\tchar scalars[MAX_ARGS];\n\tPyUFuncObject *self=loop->ufunc;\n\tBool allscalars=TRUE;\n\tPyTypeObject *subtype=&PyArray_Type;\n\n /* Check number of arguments */\n nargs = PyTuple_Size(args);\n if ((nargs != self->nin) && (nargs != self->nargs)) {\n PyErr_SetString(PyExc_ValueError, \n\t\t\t\t\"invalid number of arguments\");\n return -1;\n }\n\n\n /* Get each input argument */\n for (i=0; inin; i++) {\n mps[i] = (PyArrayObject *)\\\n\t\t\tPyArray_FromAny(PyTuple_GET_ITEM(args,i), \n\t\t\t\t\tNULL, 0, 0, 0);\n if (mps[i] == NULL) return -1;\n arg_types[i] = PyArray_TYPE(mps[i]);\n if (PyTypeNum_ISFLEXIBLE(arg_types[i])) {\n\t\t\tloop->notimplemented = 1;\n\t\t\treturn nargs;\n }\n\t\t/*\n\t\tfprintf(stderr, \"array %d has reference %d\\n\", i, \n\t\t (mps[i])->ob_refcnt);\n\t\t*/\n\n\t\t/* Scalars are 0-dimensional arrays\n\t\t at this point\n\t\t*/\n\t\tif (mps[i]->nd > 0) {\n\t\t\tscalars[i] = UFUNC_NOSCALAR;\n\t\t\tallscalars=FALSE;\n\t\t}\n\t\telse scalars[i] = _scalar_kind(arg_types[i], &(mps[i]));\n\n\t\t/* If any input is a big-array */\n\t\tif (!PyType_IsSubtype(mps[i]->ob_type, &PyArray_Type)) {\n\t\t\tsubtype = &PyBigArray_Type;\n\t\t}\n }\n\n\t/* If everything is a scalar, then use normal coercion rules */\n\tif (allscalars) {\n\t\tfor (i=0; inin; i++) {\n\t\t\tscalars[i] = UFUNC_NOSCALAR;\n\t\t}\n\t}\n \n /* Select an appropriate function for these argument types. */\n if (select_types(loop->ufunc, arg_types, &(loop->function), \n &(loop->funcdata), scalars) == -1)\n\t\treturn -1;\n\n /* FAIL with NotImplemented if the other object has \n\t the __r__ method and has __array_priority__ as \n\t an attribute (signalling it can handle ndarray's) \n\t and is not already an ndarray or bigndarray\n\t*/\n if ((arg_types[1] == PyArray_OBJECT) &&\t\t\t\t\\\n (loop->ufunc->nin==2) && (loop->ufunc->nout == 1)) {\n\t\tPyObject *_obj = PyTuple_GET_ITEM(args, 1);\n if (!PyArray_CheckExact(_obj) &&\t\t\t\\\n\t\t !PyBigArray_CheckExact(_obj) &&\t\t\t\\\n\t\t PyObject_HasAttrString(_obj, \"__array_priority__\") && \\\n\t\t _has_reflected_op(_obj, loop->ufunc->name)) {\n loop->notimplemented = 1;\n return nargs;\n }\n }\n loop->notimplemented=0;\n \n\t/* Create copies for some of the arrays if appropriate */\n\tif (_create_copies(loop, arg_types, mps) < 0) return -1;\n\t\n\t/* Create Iterators for the Inputs */\n\tfor (i=0; inin; i++) {\n loop->iters[i] = (PyArrayIterObject *)\t\t\\\n\t\t\tPyArray_IterNew((PyObject *)mps[i]);\n if (loop->iters[i] == NULL) return -1;\n\t}\n \n /* Broadcast the result */\n loop->numiter = self->nin;\n if (PyArray_Broadcast((PyArrayMultiIterObject *)loop) < 0)\n\t\treturn -1;\n\t\n /* Get any return arguments */\n for (i=self->nin; idimensions, \n\t\t\t\t\t loop->dimensions, loop->nd)) {\n PyErr_SetString(PyExc_ValueError, \n \"invalid return array shape\");\n\t\t\tPy_DECREF(mps[i]);\n mps[i] = NULL;\n return -1;\n }\n if (!PyArray_ISWRITEABLE(mps[i])) {\n PyErr_SetString(PyExc_ValueError, \n \"return array is not writeable\");\n\t\t\tPy_DECREF(mps[i]);\n mps[i] = NULL;\n return -1;\n }\n }\n\n /* construct any missing return arrays and make output iterators */\n \n for (i=self->nin; inargs; i++) {\n\t\tPyArray_Descr *ntype;\n\n if (mps[i] == NULL) {\n mps[i] = (PyArrayObject *)PyArray_New(subtype,\n loop->nd, \n loop->dimensions,\n arg_types[i], \n NULL, NULL,\n 0, 0, NULL);\n if (mps[i] == NULL) return -1;\n }\n\n\t\t/* reset types for outputs that are equivalent \n\t\t -- no sense casting uselessly\n\t\t*/\n\t\telse {\n \t\t if (mps[i]->descr->type_num != arg_types[i]) {\n\t\t\t PyArray_Descr *atype;\n\t\t\t ntype = mps[i]->descr;\n\t\t\t atype = PyArray_DescrFromType(arg_types[i]);\n\t\t\t if (PyArray_EquivTypes(atype, ntype)) {\n\t\t\t\t arg_types[i] = ntype->type_num;\n\t\t\t }\n\t\t\t Py_DECREF(atype);\n\t\t }\n\t\t \n\t\t/* still not the same -- or will we have to use buffers?*/\n\t\t if (mps[i]->descr->type_num != arg_types[i] ||\n\t\t !PyArray_ISBEHAVED_RO(mps[i])) {\n\t\t\t if (loop->size < loop->bufsize) {\n\t\t\t\t PyObject *new;\n\t\t\t\t /* Copy the array to a temporary copy \n\t\t\t\t and set the UPDATEIFCOPY flag\n\t\t\t\t */\n\t\t\t\t ntype = PyArray_DescrFromType(arg_types[i]);\n\t\t\t\t new = PyArray_FromAny((PyObject *)mps[i],\n\t\t\t\t\t\t\tntype, 0, 0,\n\t\t\t\t\t\t\tFORCECAST | ALIGNED |\n\t\t\t\t\t\t\tUPDATEIFCOPY);\n\t\t\t\t if (new == NULL) return -1;\n\t\t\t\t Py_DECREF(mps[i]);\n\t\t\t\t mps[i] = (PyArrayObject *)new;\n\t\t\t }\n\t\t }\n\t\t}\n\t\t\n loop->iters[i] = (PyArrayIterObject *)\t\t\\\n\t\t\tPyArray_IterNew((PyObject *)mps[i]);\n if (loop->iters[i] == NULL) return -1;\n }\n\n\n /* If any of different type, or misaligned or swapped\n then must use buffers */\n\n loop->bufcnt = 0;\n\n loop->obj = 0;\n\n /* Determine looping method needed */\n loop->meth = NO_UFUNCLOOP;\n\n\tmaxsize = 0;\n for (i=0; inargs; i++) {\n\t\tloop->needbuffer[i] = 0;\n if (arg_types[i] != mps[i]->descr->type_num || \n\t\t !PyArray_ISBEHAVED_RO(mps[i])) {\n loop->meth = BUFFER_UFUNCLOOP;\n\t\t\tloop->needbuffer[i] = 1;\n }\n if (!loop->obj && mps[i]->descr->type_num == PyArray_OBJECT) {\n\t\t\tloop->obj = 1;\n\t\t}\n }\n \n if (loop->meth == NO_UFUNCLOOP) {\n \n loop->meth = ONE_UFUNCLOOP;\n\n /* All correct type and BEHAVED */\n /* Check for non-uniform stridedness */\n\n for (i=0; inargs; i++) {\n if (!(loop->iters[i]->contiguous)) {\n\t\t\t\t/* may still have uniform stride\n\t\t\t\t if (broadcated result) <= 1-d */\n\t\t\t\tif (mps[i]->nd != 0 &&\t\t\t\\\n\t\t\t\t (loop->iters[i]->nd_m1 > 0)) {\n\t\t\t\t\tloop->meth = NOBUFFER_UFUNCLOOP;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n }\n\t\tif (loop->meth == ONE_UFUNCLOOP) {\n\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\tloop->bufptr[i] = mps[i]->data;\n\t\t\t}\n\t\t}\n }\n\n loop->numiter = self->nargs;\n\n /* Fill in steps */\n if (loop->meth != ONE_UFUNCLOOP) {\n\t\tint ldim = 0;\n\t\tintp maxdim=-1;\n\t\tPyArrayIterObject *it;\n\n /* Fix iterators */\n\n /* Find the **largest** dimension */\n \n\t\tmaxdim = -1;\n\t\tfor (i=loop->nd - 1; i>=0; i--) {\n\t\t\tif (loop->dimensions[i] > maxdim) {\n\t\t\t\tldim = i;\n\t\t\t\tmaxdim = loop->dimensions[i];\n\t\t\t}\n\t\t}\n\n\t\tloop->size /= maxdim;\n loop->bufcnt = maxdim;\n\t\tloop->lastdim = ldim;\n\n /* Fix the iterators so the inner loop occurs over the \n\t\t largest dimensions -- This can be done by \n\t\t setting the size to 1 in that dimension \n\t\t (just in the iterators)\n */\n\n\t\tfor (i=0; inumiter; i++) {\n\t\t\tit = loop->iters[i];\n it->contiguous = 0;\n\t\t\tit->size /= (it->dims_m1[ldim]+1);\n\t\t\tit->dims_m1[ldim] = 0;\n\t\t\tit->backstrides[ldim] = 0;\n\n\t\t\t/* (won't fix factors because we\n\t\t\t don't use PyArray_ITER_GOTO1D \n\t\t\t so don't change them) */\n\n\t\t\t/* Set the steps to the strides in that dimension */\n loop->steps[i] = it->strides[ldim];\n\t\t}\n\n\t\t/* fix up steps where we will be copying data to \n\t\t buffers and calculate the ninnerloops and leftover\n\t\t values -- if step size is already zero that is not changed... \n\t\t*/\n\t\tif (loop->meth == BUFFER_UFUNCLOOP) {\n\t\t\tloop->leftover = maxdim % loop->bufsize;\n\t\t\tloop->ninnerloops = (maxdim / loop->bufsize) + 1;\n\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\tif (loop->needbuffer[i] && loop->steps[i]) {\n\t\t\t\t\tloop->steps[i] = mps[i]->descr->elsize;\n\t\t\t\t}\n\t\t\t\t/* These are changed later if casting is needed */\n\t\t\t}\n\t\t}\n }\n else { /* uniformly-strided case ONE_UFUNCLOOP */\n\t\tfor (i=0; inargs; i++) {\n\t\t\tif (PyArray_SIZE(mps[i]) == 1)\n\t\t\t\tloop->steps[i] = 0;\n\t\t\telse\n\t\t\t\tloop->steps[i] = mps[i]->strides[mps[i]->nd-1];\n\t\t}\n\t}\n \n\n\t/* Finally, create memory for buffers if we need them */\n\t\n\t/* buffers for scalars are specially made small -- scalars are\n\t not copied multiple times */\n\tif (loop->meth == BUFFER_UFUNCLOOP) {\n\t\tint cnt = 0, cntcast = 0; /* keeps track of bytes to allocate */\n\t\tint scnt = 0, scntcast = 0;\n\t\tchar *castptr;\n\t\tchar *bufptr;\n\t\tint last_was_scalar=0;\n\t\tint last_cast_was_scalar=0;\n\t\tint oldbufsize=0;\n\t\tint oldsize=0;\n\t\tint scbufsize = 4*sizeof(double);\n\t\tint memsize;\n PyArray_Descr *descr;\n\n\t\t/* compute the element size */\n\t\tfor (i=0; inargs;i++) {\n\t\t\tif (!loop->needbuffer) continue;\n\t\t\tif (arg_types[i] != mps[i]->descr->type_num) {\n\t\t\t\tdescr = PyArray_DescrFromType(arg_types[i]);\n\t\t\t\tif (loop->steps[i])\n\t\t\t\t\tcntcast += descr->elsize;\n\t\t\t\telse\n\t\t\t\t\tscntcast += descr->elsize;\n\t\t\t\tif (i < self->nin) {\n\t\t\t\t\tloop->cast[i] =\t\t\t\\\n\t\t\t\t\t\tmps[i]->descr->f->cast[arg_types[i]];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tloop->cast[i] = descr->f->\t\\\n\t\t\t\t\t\tcast[mps[i]->descr->type_num];\n\t\t\t\t}\n\t\t\t\tPy_DECREF(descr);\n\t\t\t}\n\t\t\tloop->swap[i] = !(PyArray_ISNOTSWAPPED(mps[i]));\n\t\t\tif (loop->steps[i])\n\t\t\t\tcnt += mps[i]->descr->elsize;\n\t\t\telse\n\t\t\t\tscnt += mps[i]->descr->elsize;\n\t\t}\n\t\tmemsize = loop->bufsize*(cnt+cntcast) + scbufsize*(scnt+scntcast);\n \t\tloop->buffer[0] = PyDataMem_NEW(memsize);\n\n\t\t/* fprintf(stderr, \"Allocated buffer at %p of size %d, cnt=%d, cntcast=%d\\n\", loop->buffer[0], loop->bufsize * (cnt + cntcast), cnt, cntcast); */\n\n\t\tif (loop->buffer[0] == NULL) {PyErr_NoMemory(); return -1;}\n\t\tcastptr = loop->buffer[0] + loop->bufsize*cnt + scbufsize*scnt;\n\t\tbufptr = loop->buffer[0];\n\t\tfor (i=0; inargs; i++) {\n\t\t\tif (!loop->needbuffer[i]) continue;\n\t\t\tloop->buffer[i] = bufptr + (last_was_scalar ? scbufsize : \\\n\t\t\t\t\t\t loop->bufsize)*oldbufsize;\n\t\t\tlast_was_scalar = (loop->steps[i] == 0);\n\t\t\tbufptr = loop->buffer[i];\n\t\t\toldbufsize = mps[i]->descr->elsize;\n\t\t\t/* fprintf(stderr, \"buffer[%d] = %p\\n\", i, loop->buffer[i]); */\n\t\t\tif (loop->cast[i]) {\n\t\t\t\tPyArray_Descr *descr;\n\t\t\t\tloop->castbuf[i] = castptr + (last_cast_was_scalar ? scbufsize : \\\n\t\t\t\t\t\t\t loop->bufsize)*oldsize;\n\t\t\t\tlast_cast_was_scalar = last_was_scalar;\n\t\t\t\t/* fprintf(stderr, \"castbuf[%d] = %p\\n\", i, loop->castbuf[i]); */\n\t\t\t\tdescr = PyArray_DescrFromType(arg_types[i]);\n\t\t\t\toldsize = descr->elsize;\n\t\t\t\tPy_DECREF(descr);\n\t\t\t\tloop->bufptr[i] = loop->castbuf[i];\n\t\t\t\tcastptr = loop->castbuf[i];\n\t\t\t\tif (loop->steps[i])\n\t\t\t\t\tloop->steps[i] = oldsize;\n\t\t\t}\n\t\t\telse {\n\t\t\t\tloop->bufptr[i] = loop->buffer[i];\n\t\t\t}\n\t\t}\n\t}\n return nargs;\n}\n\nstatic void\nufuncreduce_dealloc(PyUFuncReduceObject *self)\n{\n if (self->ufunc) {\n Py_XDECREF(self->it);\n\t\tPy_XDECREF(self->rit);\n Py_XDECREF(self->ret);\n\t\tPy_XDECREF(self->errobj);\n\t\tPy_XDECREF(self->decref);\n if (self->buffer) PyDataMem_FREE(self->buffer);\n Py_DECREF(self->ufunc);\n }\n _pya_free(self);\n}\n\nstatic void\nufuncloop_dealloc(PyUFuncLoopObject *self)\n{\n\tint i;\n\t\n\tif (self->ufunc != NULL) {\n\t\tfor (i=0; iufunc->nargs; i++)\n\t\t\tPy_XDECREF(self->iters[i]);\n\t\tif (self->buffer[0]) PyDataMem_FREE(self->buffer[0]);\n\t\tPy_XDECREF(self->errobj);\n\t\tPy_DECREF(self->ufunc);\n\t}\n _pya_free(self);\n}\n\nstatic PyUFuncLoopObject *\nconstruct_loop(PyUFuncObject *self, PyObject *args, PyArrayObject **mps)\n{\n\tPyUFuncLoopObject *loop;\n\tint i;\n\t\n\tif (self == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \"function not supported\");\n\t\treturn NULL;\n\t}\n if ((loop = _pya_malloc(sizeof(PyUFuncLoopObject)))==NULL) {\n PyErr_NoMemory(); return loop;\n }\n\t\n\tloop->index = 0;\n\tloop->ufunc = self;\n Py_INCREF(self);\n\tloop->buffer[0] = NULL;\n for (i=0; inargs; i++) {\n loop->iters[i] = NULL;\n loop->cast[i] = NULL;\n }\n\tloop->errobj = NULL;\n\n\tif (PyUFunc_GetPyValues((self->name ? self->name : \"\"),\n\t\t\t\t&(loop->bufsize), &(loop->errormask), \n\t\t\t\t&(loop->errobj)) < 0) goto fail;\n \n\t/* Setup the matrices */\n\tif (construct_matrices(loop, args, mps) < 0) goto fail;\n\n\tPyUFunc_clearfperr();\n\n\treturn loop;\n\n fail:\n ufuncloop_dealloc(loop);\n\treturn NULL;\n}\n\n\n/* \nstatic void\n_printbytebuf(PyUFuncLoopObject *loop, int bufnum) \n{ \n\tint i;\n\t\n \tfprintf(stderr, \"Printing byte buffer %d\\n\", bufnum);\n for (i=0; ibufcnt; i++) {\n\t \tfprintf(stderr, \" %d\\n\", *(((byte *)(loop->buffer[bufnum]))+i));\n\t} \n}\n\nstatic void\n_printlongbuf(PyUFuncLoopObject *loop, int bufnum) \n{ \n\tint i;\n\t\n \tfprintf(stderr, \"Printing long buffer %d\\n\", bufnum);\n for (i=0; ibufcnt; i++) {\n\t \tfprintf(stderr, \" %ld\\n\", *(((long *)(loop->buffer[bufnum]))+i));\n\t} \n}\n\nstatic void\n_printlongbufptr(PyUFuncLoopObject *loop, int bufnum) \n{ \n\tint i;\n\t\n \tfprintf(stderr, \"Printing long buffer %d\\n\", bufnum);\n for (i=0; ibufcnt; i++) {\n\t \tfprintf(stderr, \" %ld\\n\", *(((long *)(loop->bufptr[bufnum]))+i));\n\t} \n}\n\n\n \nstatic void\n_printcastbuf(PyUFuncLoopObject *loop, int bufnum) \n{ \n\tint i;\n\t\n \tfprintf(stderr, \"Printing long buffer %d\\n\", bufnum);\n for (i=0; ibufcnt; i++) {\n\t \tfprintf(stderr, \" %ld\\n\", *(((long *)(loop->castbuf[bufnum]))+i));\n\t} \n}\n\n*/\n\n\n\n\n/* currently generic ufuncs cannot be built for use on flexible arrays.\n\n The cast functions in the generic loop would need to be fixed to pass \n in something besides NULL, NULL.\n\n Also the underlying ufunc loops would not know the element-size unless\n that was passed in as data (which could be arranged).\n\n*/\n\n/* This generic function is called with the ufunc object, the arguments to it,\n and an array of (pointers to) PyArrayObjects which are NULL. The \n arguments are parsed and placed in mps in construct_loop (construct_matrices)\n*/\n\n/*UFUNC_API*/\nstatic int \nPyUFunc_GenericFunction(PyUFuncObject *self, PyObject *args, \n\t\t\tPyArrayObject **mps) \n{\n\tPyUFuncLoopObject *loop;\n\tint i;\n BEGIN_THREADS_DEF\n\n\tif (!(loop = construct_loop(self, args, mps))) return -1;\n if (loop->notimplemented) {ufuncloop_dealloc(loop); return -2;}\n\n\tLOOP_BEGIN_THREADS\n\n\tswitch(loop->meth) {\n\tcase ONE_UFUNCLOOP:\n\t\t/* Everything is contiguous, notswapped, aligned,\n\t\t and of the right type. -- Fastest.\n\t\t Or if not contiguous, then a single-stride\n\t\t increment moves through the entire array. \n\t\t*/\n /*fprintf(stderr, \"ONE...%d\\n\", loop->size);*/\n\t\tloop->function((char **)loop->bufptr, &(loop->size), \n\t\t\t loop->steps, loop->funcdata);\n\t\tUFUNC_CHECK_ERROR(loop);\n\t\tbreak;\n\tcase NOBUFFER_UFUNCLOOP:\n\t\t/* Everything is notswapped, aligned and of the \n\t\t right type but not contiguous. -- Almost as fast.\n\t\t*/\n /*fprintf(stderr, \"NOBUFFER...%d\\n\", loop->size);*/\n\t\twhile (loop->index < loop->size) {\n\t\t\tfor (i=0; inargs; i++) \n\t\t\t\tloop->bufptr[i] = loop->iters[i]->dataptr;\n\n\t\t\tloop->function((char **)loop->bufptr, &(loop->bufcnt),\n\t\t\t\t loop->steps, loop->funcdata);\n\t\t\tUFUNC_CHECK_ERROR(loop);\n\n\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\tPyArray_ITER_NEXT(loop->iters[i]);\n\t\t\t}\n\t\t\tloop->index++;\n\t\t}\n\t\tbreak;\n\tcase BUFFER_UFUNCLOOP: {\n\t\tPyArray_CopySwapNFunc *copyswapn[MAX_ARGS];\n\t\tPyArrayIterObject **iters=loop->iters;\n\t\tint *swap=loop->swap;\n\t\tvoid **dptr=loop->dptr;\n\t\tint mpselsize[MAX_ARGS];\n\t\tintp laststrides[MAX_ARGS];\n\t\tint fastmemcpy[MAX_ARGS];\n\t\tint *needbuffer=loop->needbuffer;\n\t\tintp index=loop->index, size=loop->size;\n\t\tint bufsize;\n\t\tintp bufcnt;\n\t\tint copysizes[MAX_ARGS];\n\t\tvoid **bufptr = loop->bufptr;\n\t\tvoid **buffer = loop->buffer;\n\t\tvoid **castbuf = loop->castbuf;\n\t\tintp *steps = loop->steps;\n\t\tchar *tptr[MAX_ARGS];\n\t\tint ninnerloops = loop->ninnerloops;\n\t\tBool pyobject[MAX_ARGS];\n\t\tint datasize[MAX_ARGS];\n int i, j, k, stopcondition;\n\t\tchar *myptr1, *myptr2;\n\n\t\t\n\t\tfor (i=0; inargs; i++) {\n\t\t\tcopyswapn[i] = mps[i]->descr->f->copyswapn;\n\t\t\tmpselsize[i] = mps[i]->descr->elsize;\n\t\t\tpyobject[i] = (loop->obj && \\\n (mps[i]->descr->type_num == PyArray_OBJECT));\n\t\t\tlaststrides[i] = iters[i]->strides[loop->lastdim];\n\t\t\tif (steps[i] && laststrides[i] != mpselsize[i]) fastmemcpy[i] = 0;\n\t\t\telse fastmemcpy[i] = 1;\n\t\t}\n\t\t/* Do generic buffered looping here (works for any kind of\n\t\t arrays -- some need buffers, some don't. \n\t\t*/\n\t\t\n\t\t/* New algorithm: N is the largest dimension. B is the buffer-size.\n\t\t quotient is loop->ninnerloops-1\n\t\t remainder is loop->leftover\n\n\t\tCompute N = quotient * B + remainder. \n\t\tquotient = N / B # integer math \n\t\t(store quotient + 1) as the number of innerloops\n\t\tremainder = N % B # integer remainder\n\t\t\n\t\tOn the inner-dimension we will have (quotient + 1) loops where \n\t\tthe size of the inner function is B for all but the last when the niter size is\n\t\tremainder. \n\t\t\n\t\tSo, the code looks very similar to NOBUFFER_LOOP except the inner-most loop is \n\t\treplaced with...\n\t\t\n\t\tfor(i=0; isize, \n\t\t loop->ninnerloops, loop->leftover);\n\t\t*/\n\t\t/*\n\t\tfor (i=0; inargs; i++) {\n\t\t fprintf(stderr, \"iters[%d]->dataptr = %p, %p of size %d\\n\", i, \n\t\t\t iters[i], iters[i]->ao->data, PyArray_NBYTES(iters[i]->ao));\n\t\t}\n\t\t*/\n\n\t\tstopcondition = ninnerloops;\n\t\tif (loop->leftover == 0) stopcondition--;\n\t\twhile (index < size) {\n\t\t\tbufsize=loop->bufsize;\n\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\ttptr[i] = loop->iters[i]->dataptr;\n\t\t\t\tif (needbuffer[i]) {\n\t\t\t\t\tdptr[i] = bufptr[i];\n\t\t\t\t\tdatasize[i] = (steps[i] ? bufsize : 1);\n\t\t\t\t\tcopysizes[i] = datasize[i] * mpselsize[i];\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tdptr[i] = tptr[i];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t/* This is the inner function over the last dimension */\n\t\t\tfor (k=1; k<=stopcondition; k++) {\n\t\t\t\tif (k==ninnerloops) {\n bufsize = loop->leftover;\n for (i=0; inargs;i++) {\n\t\t\t\t\t\tif (!needbuffer[i]) continue;\n datasize[i] = (steps[i] ? bufsize : 1);\n\t\t\t\t\t\tcopysizes[i] = datasize[i] * mpselsize[i];\n }\n }\n \n\t\t\t\tfor (i=0; inin; i++) {\n\t\t\t\t\tif (!needbuffer[i]) continue;\n\t\t\t\t\tif (fastmemcpy[i]) \n\t\t\t\t\t\tmemcpy(buffer[i], tptr[i],\n\t\t\t\t\t\t copysizes[i]);\n\t\t\t\t\telse {\n\t\t\t\t\t\tmyptr1 = buffer[i];\n\t\t\t\t\t\tmyptr2 = tptr[i];\n\t\t\t\t\t\tfor (j=0; jcast[i]) {\n\t\t\t\t\t\tloop->cast[i](buffer[i],\n\t\t\t\t\t\t\t castbuf[i],\n\t\t\t\t\t\t\t (intp) datasize[i],\n\t\t\t\t\t\t\t NULL, NULL);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tbufcnt = (intp) bufsize;\n\t\t\t\tloop->function((char **)dptr, &bufcnt, steps, loop->funcdata);\n\t\t\t\t\n\t\t\t\tfor (i=self->nin; inargs; i++) {\n\t\t\t\t\tif (!needbuffer[i]) continue;\n\t\t\t\t\tif (loop->cast[i]) {\n\t\t\t\t\t\tloop->cast[i](castbuf[i],\n\t\t\t\t\t\t\t buffer[i],\n\t\t\t\t\t\t\t (intp) datasize[i],\n\t\t\t\t\t\t\t NULL, NULL);\n\t\t\t\t\t}\n\t\t\t\t\tif (swap[i]) {\n\t\t\t\t\t\tcopyswapn[i](buffer[i], NULL,\n\t\t\t\t\t\t\t (intp) datasize[i], 1, \n\t\t\t\t\t\t\t mpselsize[i]);\n\t\t\t\t\t}\n\t\t\t\t\t/* copy back to output arrays */\n\t\t\t\t\t/* decref what's already there for object arrays */\n\t\t\t\t\tif (pyobject[i]) {\n\t\t\t\t\t\tmyptr1 = tptr[i];\n\t\t\t\t\t\tfor (j=0; jnargs; i++) {\n\t\t\t\t\ttptr[i] += bufsize * laststrides[i];\n\t\t\t\t\tif (!needbuffer[i]) dptr[i] = tptr[i];\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (loop->obj) { /* DECREF castbuf for object arrays */\n\t\t\t\tfor (i=0; inargs; i++) {\n\t\t\t\t\tif (pyobject[i]) {\n\t\t\t\t\t\tif (steps[i] == 0) {\n\t\t\t\t\t\t\tPy_XDECREF(*((PyObject **)castbuf[i]));\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse {\n\t\t\t\t\t\t\tint size = loop->bufsize;\n\t\t\t\t\t\t\tPyObject **objptr = castbuf[i];\n\t\t\t\t\t\t\t/* size is loop->bufsize unless there\n\t\t\t\t\t\t\t was only one loop */\n\t\t\t\t\t\t\tif (ninnerloops == 1) \\\n\t\t\t\t\t\t\t\tsize = loop->leftover;\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\tfor (j=0; jnargs; i++) {\n\t\t\t\tPyArray_ITER_NEXT(loop->iters[i]);\n\t\t\t}\n\t\t\tindex++;\n }\n }\n }\n \n LOOP_END_THREADS\n \n ufuncloop_dealloc(loop);\n\treturn 0;\n\n fail:\n LOOP_END_THREADS\n\n\tif (loop) ufuncloop_dealloc(loop);\n\treturn -1;\n}\n\nstatic PyArrayObject *\n_getidentity(PyUFuncObject *self, int otype, char *str)\n{\n PyObject *obj, *arr;\n PyArray_Descr *typecode;\n\t\n if (self->identity == PyUFunc_None) {\n PyErr_Format(PyExc_ValueError, \n \"zero-size array to ufunc.%s \" \\\n \"without identity\", str);\n return NULL;\n }\n if (self->identity == PyUFunc_One) {\n obj = PyInt_FromLong((long) 1);\n } else {\n obj = PyInt_FromLong((long) 0);\n }\n\n\ttypecode = PyArray_DescrFromType(otype); \n arr = PyArray_FromAny(obj, typecode, 0, 0, CARRAY_FLAGS);\n Py_DECREF(obj);\n return (PyArrayObject *)arr;\n}\n\nstatic int\n_create_reduce_copy(PyUFuncReduceObject *loop, PyArrayObject **arr, int rtype)\n{\n\tintp maxsize;\n\tPyObject *new;\n\tPyArray_Descr *ntype;\n\t\n\tmaxsize = PyArray_SIZE(*arr);\n\t\n\tif (maxsize < loop->bufsize) {\n\t\tif (!(PyArray_ISBEHAVED_RO(*arr)) ||\t\\\n\t\t PyArray_TYPE(*arr) != rtype) {\n\t\t\tntype = PyArray_DescrFromType(rtype);\n\t\t\tnew = PyArray_FromAny((PyObject *)(*arr), \n\t\t\t\t\t ntype, 0, 0,\n\t\t\t\t\t FORCECAST | ALIGNED);\n\t\t\tif (new == NULL) return -1;\n\t\t\t*arr = (PyArrayObject *)new;\n\t\t\tloop->decref = new;\n\t\t}\n\t}\n\n\t/* Don't decref *arr before re-assigning\n\t because it was not going to be DECREF'd anyway.\n\t \n\t If a copy is made, then the copy will be removed\n\t on deallocation of the loop structure by setting \n\t loop->decref.\n\t*/\n\t\n\treturn 0;\n}\n\nstatic PyUFuncReduceObject *\nconstruct_reduce(PyUFuncObject *self, PyArrayObject **arr, int axis, \n\t\t int otype, int operation, intp ind_size, char *str)\n{\n PyUFuncReduceObject *loop;\n PyArrayObject *idarr;\n\tPyArrayObject *aar;\n intp loop_i[MAX_DIMS];\n int arg_types[3] = {otype, otype, otype};\n\tchar scalars[3] = {UFUNC_NOSCALAR, UFUNC_NOSCALAR, UFUNC_NOSCALAR};\n\tint i, j;\n\tint nd = (*arr)->nd;\n\t/* Reduce type is the type requested of the input \n\t during reduction */\n \n if ((loop = _pya_malloc(sizeof(PyUFuncReduceObject)))==NULL) {\n PyErr_NoMemory(); return loop;\n }\n \n loop->swap = 0;\n\tloop->index = 0;\n\tloop->ufunc = self;\n Py_INCREF(self);\n loop->cast = NULL;\n loop->buffer = NULL;\n loop->ret = NULL;\n\tloop->it = NULL;\n\tloop->rit = NULL;\n\tloop->errobj = NULL;\n\tloop->decref=NULL; \n loop->N = (*arr)->dimensions[axis];\n\tloop->instrides = (*arr)->strides[axis];\n\n\tif (select_types(loop->ufunc, arg_types, &(loop->function), \n\t\t\t &(loop->funcdata), scalars) == -1) goto fail; \n\t\n\t/* output type may change -- if it does \n\t reduction is forced into that type \n\t and we need to select the reduction function again\n\t*/\n\tif (otype != arg_types[2]) {\n\t\totype = arg_types[2];\n\t\targ_types[0] = otype;\n\t\targ_types[1] = otype;\n\t\tif (select_types(loop->ufunc, arg_types, &(loop->function), \n\t\t\t\t &(loop->funcdata), scalars) == -1) \n\t\t\tgoto fail; \t\t\n\t}\n\t\n\t/* get looping parameters from Python */\n\tif (PyUFunc_GetPyValues(str, &(loop->bufsize), &(loop->errormask), \n\t\t\t\t&(loop->errobj)) < 0) goto fail;\n\t\n\t/* Make copy if misbehaved or not otype for small arrays */\n\tif (_create_reduce_copy(loop, arr, otype) < 0) goto fail; \n\taar = *arr;\n\t\n if (loop->N == 0) {\n loop->meth = ZERODIM_REDUCELOOP;\n }\n else if (PyArray_ISBEHAVED_RO(aar) &&\t\t\\\n otype == (aar)->descr->type_num) {\n\t\tif (loop->N == 1) {\n\t\t\tloop->meth = ONEDIM_REDUCELOOP;\n\t\t}\n\t\telse {\n\t\t\tloop->meth = NOBUFFER_UFUNCLOOP;\n\t\t\tloop->steps[0] = (aar)->strides[axis];\n\t\t\tloop->N -= 1;\n\t\t}\n }\n else {\n loop->meth = BUFFER_UFUNCLOOP;\n loop->swap = !(PyArray_ISNOTSWAPPED(aar));\n }\n\n /* Determine if object arrays are involved */\n if (otype == PyArray_OBJECT || aar->descr->type_num == PyArray_OBJECT)\n loop->obj = 1;\n else\n loop->obj = 0;\n\n if (loop->meth == ZERODIM_REDUCELOOP) {\n idarr = _getidentity(self, otype, str);\n if (idarr == NULL) goto fail;\n if (idarr->descr->elsize > UFUNC_MAXIDENTITY) {\n PyErr_Format(PyExc_RuntimeError, \n\t\t\t\t \"UFUNC_MAXIDENTITY (%d)\"\t\t\\\n \" is too small (needs to be at least %d)\",\n UFUNC_MAXIDENTITY, idarr->descr->elsize);\n Py_DECREF(idarr);\n goto fail;\n }\n memcpy(loop->idptr, idarr->data, idarr->descr->elsize);\n Py_DECREF(idarr);\n }\n\t\n /* Construct return array */\n\tswitch(operation) {\n\tcase UFUNC_REDUCE:\n\t\tfor (j=0, i=0; idimensions[i];\n\t\t\t\n\t\t}\n\t\tloop->ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_New(aar->ob_type, aar->nd-1, loop_i, otype, \n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)aar);\n\t\tbreak;\n\tcase UFUNC_ACCUMULATE:\n\t\tloop->ret = (PyArrayObject *)\t\t\t\t\\\n\t\t\tPyArray_New(aar->ob_type, aar->nd, aar->dimensions, \n\t\t\t\t otype, NULL, NULL, 0, 0, (PyObject *)aar);\n\t\tbreak;\n\tcase UFUNC_REDUCEAT:\n\t\tmemcpy(loop_i, aar->dimensions, nd*sizeof(intp));\n\t\t/* Index is 1-d array */\n\t\tloop_i[axis] = ind_size; \n\t\tloop->ret = (PyArrayObject *)\\\n\t\t\tPyArray_New(aar->ob_type, aar->nd, loop_i, otype,\n\t\t\t\t NULL, NULL, 0, 0, (PyObject *)aar);\n\t\tif (loop->ret == NULL) goto fail;\n\t\tif (ind_size == 0) {\n\t\t\tloop->meth = ZERODIM_REDUCELOOP;\n\t\t\treturn loop;\n\t\t}\n\t\tif (loop->meth == ONEDIM_REDUCELOOP)\n\t\t\tloop->meth = NOBUFFER_REDUCELOOP;\n\t\tbreak;\n\t}\n if (loop->ret == NULL) goto fail;\n loop->insize = aar->descr->elsize;\n loop->outsize = loop->ret->descr->elsize;\n loop->bufptr[1] = loop->ret->data;\n\n\tif (loop->meth == ZERODIM_REDUCELOOP) {\n\t\tloop->size = PyArray_SIZE(loop->ret);\n\t\treturn loop;\n\t}\n\n\tloop->it = (PyArrayIterObject *)PyArray_IterNew((PyObject *)aar);\n if (loop->it == NULL) return NULL;\n\n\tif (loop->meth == ONEDIM_REDUCELOOP) {\n\t\tloop->size = loop->it->size;\t\t\n\t\treturn loop;\n\t}\n\n /* Fix iterator to loop over correct dimension */\n\t/* Set size in axis dimension to 1 */\n \n loop->it->contiguous = 0;\n loop->it->size /= (loop->it->dims_m1[axis]+1);\n loop->it->dims_m1[axis] = 0;\n loop->it->backstrides[axis] = 0;\n\n\n loop->size = loop->it->size;\n\n\tif (operation == UFUNC_REDUCE) {\n\t\tloop->steps[1] = 0;\n\t}\n\telse {\n\t\tloop->rit = (PyArrayIterObject *)\t\t\t\\\n\t\t\tPyArray_IterNew((PyObject *)(loop->ret));\n\t\tif (loop->rit == NULL) return NULL;\t\t\n\n\t\t/* Fix iterator to loop over correct dimension */\n\t\t/* Set size in axis dimension to 1 */\n\t\t\n\t\tloop->rit->contiguous = 0;\n\t\tloop->rit->size /= (loop->rit->dims_m1[axis]+1);\n\t\tloop->rit->dims_m1[axis] = 0;\n\t\tloop->rit->backstrides[axis] = 0;\n\n\t\tif (operation == UFUNC_ACCUMULATE)\n\t\t\tloop->steps[1] = loop->ret->strides[axis];\n\t\telse \n\t\t\tloop->steps[1] = 0;\n\t}\n\tloop->steps[2] = loop->steps[1];\n\tloop->bufptr[2] = loop->bufptr[1] + loop->steps[2];\n\n\t\n\tif (loop->meth == BUFFER_UFUNCLOOP) {\n\t\tint _size;\n\t\tloop->steps[0] = loop->outsize;\n if (otype != aar->descr->type_num) {\n\t\t\t_size=loop->bufsize*(loop->outsize +\t\t\\\n\t\t\t\t\t aar->descr->elsize);\n loop->buffer = PyDataMem_NEW(_size);\n if (loop->buffer == NULL) goto fail;\n\t\t\tif (loop->obj) memset(loop->buffer, 0, _size);\n loop->castbuf = loop->buffer + \\\n loop->bufsize*aar->descr->elsize;\n loop->bufptr[0] = loop->castbuf; \n loop->cast = aar->descr->f->cast[otype];\n }\n else {\n\t\t\t_size = loop->bufsize * loop->outsize;\n loop->buffer = PyDataMem_NEW(_size);\n if (loop->buffer == NULL) goto fail;\n\t\t\tif (loop->obj) memset(loop->buffer, 0, _size);\n loop->bufptr[0] = loop->buffer;\n }\n\t}\n\n\n\tPyUFunc_clearfperr();\n\treturn loop;\n\n fail:\n ufuncreduce_dealloc(loop);\n\treturn NULL;\t\n}\n\n\n/* We have two basic kinds of loops */\n/* One is used when arr is not-swapped and aligned and output type\n is the same as input type.\n and another using buffers when one of these is not satisfied.\n\n Zero-length and one-length axes-to-be-reduced are handled separately.\n*/\n\nstatic PyObject *\nPyUFunc_Reduce(PyUFuncObject *self, PyArrayObject *arr, int axis, int otype)\n{\n PyArrayObject *ret=NULL;\n PyUFuncReduceObject *loop;\n intp i, n;\n char *dptr;\n BEGIN_THREADS_DEF\n \t\n /* Construct loop object */\n loop = construct_reduce(self, &arr, axis, otype, UFUNC_REDUCE, 0,\n\t\t\t\t\"reduce\");\n\tif (!loop) return NULL;\n\n LOOP_BEGIN_THREADS\n switch(loop->meth) {\n case ZERODIM_REDUCELOOP:\n\t\t/* fprintf(stderr, \"ZERO..%d\\n\", loop->size); */\n\t\tfor(i=0; isize; i++) {\n\t\t\tif (loop->obj) Py_INCREF(*((PyObject **)loop->idptr));\n\t\t\tmemmove(loop->bufptr[1], loop->idptr, loop->outsize);\n\t\t\tloop->bufptr[1] += loop->outsize;\n\t\t}\n break;\n case ONEDIM_REDUCELOOP:\n\t\t/*fprintf(stderr, \"ONEDIM..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\n\t\t\tif (loop->obj) Py_INCREF(*((PyObject **)loop->it->dataptr));\n memmove(loop->bufptr[1], loop->it->dataptr, \n loop->outsize);\n\t\t\tPyArray_ITER_NEXT(loop->it);\n\t\t\tloop->bufptr[1] += loop->outsize;\n\t\t\tloop->index++;\n\t\t}\t\t\n\t\tbreak;\n case NOBUFFER_UFUNCLOOP:\n\t\t/*fprintf(stderr, \"NOBUFFER..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\n\t\t\t/* Copy first element to output */\n\t\t\tif (loop->obj) \n\t\t\t\tPy_INCREF(*((PyObject **)loop->it->dataptr));\n memmove(loop->bufptr[1], loop->it->dataptr, \n loop->outsize);\n\t\t\t/* Adjust input pointer */\n loop->bufptr[0] = loop->it->dataptr+loop->steps[0];\n loop->function((char **)loop->bufptr, \n\t\t\t\t &(loop->N),\n loop->steps, loop->funcdata);\n\t\t\tUFUNC_CHECK_ERROR(loop);\n\n PyArray_ITER_NEXT(loop->it)\n loop->bufptr[1] += loop->outsize;\n loop->bufptr[2] = loop->bufptr[1];\n loop->index++; \n }\n break;\n case BUFFER_UFUNCLOOP: \n /* use buffer for arr */\n /* \n For each row to reduce\n 1. copy first item over to output (casting if necessary)\n 2. Fill inner buffer \n 3. When buffer is filled or end of row\n a. Cast input buffers if needed\n b. Call inner function.\n 4. Repeat 2 until row is done.\n */\n\t\t/* fprintf(stderr, \"BUFFERED..%d %d\\n\", loop->size, \n\t\t loop->swap); */\n while(loop->index < loop->size) {\n loop->inptr = loop->it->dataptr;\t\t\t\n\t\t\t/* Copy (cast) First term over to output */\n\t\t\tif (loop->cast) {\n\t\t\t\t/* A little tricky because we need to\n\t\t\t\t cast it first */\n\t\t\t\tarr->descr->f->copyswap(loop->buffer,\n\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t loop->insize);\n\t\t\t\tloop->cast(loop->buffer, loop->castbuf,\n\t\t\t\t\t 1, NULL, NULL);\n\t\t\t\tif (loop->obj) \n\t\t\t\t\tPy_INCREF(*((PyObject **)loop->castbuf));\n\t\t\t\tmemcpy(loop->bufptr[1], loop->castbuf,\n\t\t\t\t loop->outsize);\n\t\t\t}\n\t\t\telse { /* Simple copy */\n\t\t\t\tarr->descr->f->copyswap(loop->bufptr[1], \n\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t loop->insize);\n\t\t\t}\n\t\t\tloop->inptr += loop->instrides;\n n = 1;\n while(n < loop->N) {\n /* Copy up to loop->bufsize elements to \n buffer */\n dptr = loop->buffer;\n for (i=0; ibufsize; i++, n++) {\n if (n == loop->N) break;\n arr->descr->f->copyswap(dptr,\n loop->inptr,\n loop->swap,\n loop->insize);\n loop->inptr += loop->instrides;\n dptr += loop->insize;\n }\n if (loop->cast)\n loop->cast(loop->buffer,\n loop->castbuf,\n i, NULL, NULL);\n loop->function((char **)loop->bufptr,\n &i, \n\t\t\t\t\t loop->steps, loop->funcdata);\n\t\t\t\tUFUNC_CHECK_ERROR(loop);\n } \n PyArray_ITER_NEXT(loop->it);\n loop->bufptr[1] += loop->outsize;\n loop->bufptr[2] = loop->bufptr[1]; \n loop->index++;\n }\n }\n\n LOOP_END_THREADS\n\n ret = loop->ret;\n\t/* Hang on to this reference -- will be decref'd with loop */\n Py_INCREF(ret);\n ufuncreduce_dealloc(loop);\n return (PyObject *)ret;\n\n fail:\n LOOP_END_THREADS\n\n if (loop) ufuncreduce_dealloc(loop);\n return NULL;\n}\n\n\nstatic PyObject *\nPyUFunc_Accumulate(PyUFuncObject *self, PyArrayObject *arr, int axis, \n\t\t int otype)\n{\n PyArrayObject *ret=NULL;\n PyUFuncReduceObject *loop;\n intp i, n;\n char *dptr;\n \n /* Construct loop object */\n loop = construct_reduce(self, &arr, axis, otype, UFUNC_ACCUMULATE, 0,\n\t\t\t\t\"accumulate\");\n\tif (!loop) return NULL;\n\n\tLOOP_BEGIN_THREADS\n switch(loop->meth) {\n case ZERODIM_REDUCELOOP: /* Accumulate */\n\t\t/* fprintf(stderr, \"ZERO..%d\\n\", loop->size); */\n\t\tfor(i=0; isize; i++) {\n\t\t\tif (loop->obj) \n\t\t\t\tPy_INCREF(*((PyObject **)loop->idptr));\n\t\t\tmemcpy(loop->bufptr[1], loop->idptr, loop->outsize);\n\t\t\tloop->bufptr[1] += loop->outsize;\n\t\t} \n break;\n case ONEDIM_REDUCELOOP: /* Accumulate */\n\t\t/* fprintf(stderr, \"ONEDIM..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\n\t\t\tif (loop->obj) \n\t\t\t\tPy_INCREF(*((PyObject **)loop->it->dataptr));\n memcpy(loop->bufptr[1], loop->it->dataptr, \n loop->outsize);\n\t\t\tPyArray_ITER_NEXT(loop->it);\n\t\t\tloop->bufptr[1] += loop->outsize;\n\t\t\tloop->index++;\n\t\t}\t\t\n\t\tbreak;\n case NOBUFFER_UFUNCLOOP: /* Accumulate */\n\t\t/* fprintf(stderr, \"NOBUFFER..%d\\n\", loop->size); */\n while(loop->index < loop->size) {\n\t\t\t/* Copy first element to output */\n\t\t\tif (loop->obj) \n\t\t\t\tPy_INCREF(*((PyObject **)loop->it->dataptr));\n memcpy(loop->bufptr[1], loop->it->dataptr, \n loop->outsize);\n\t\t\t/* Adjust input pointer */\n loop->bufptr[0] = loop->it->dataptr+loop->steps[0];\n loop->function((char **)loop->bufptr, \n\t\t\t\t &(loop->N),\n loop->steps, loop->funcdata);\n\t\t\tUFUNC_CHECK_ERROR(loop);\n\n PyArray_ITER_NEXT(loop->it);\n\t\t\tPyArray_ITER_NEXT(loop->rit);\n loop->bufptr[1] = loop->rit->dataptr;\n\t\t\tloop->bufptr[2] = loop->bufptr[1] + loop->steps[1];\n loop->index++;\n }\n break;\n case BUFFER_UFUNCLOOP: /* Accumulate */\n /* use buffer for arr */\n /* \n For each row to reduce\n 1. copy identity over to output (casting if necessary)\n 2. Fill inner buffer \n 3. When buffer is filled or end of row\n a. Cast input buffers if needed\n b. Call inner function.\n 4. Repeat 2 until row is done.\n */\n\t\t/* fprintf(stderr, \"BUFFERED..%d %p\\n\", loop->size, \n\t\t loop->cast); */\n while(loop->index < loop->size) {\n loop->inptr = loop->it->dataptr;\t\t\t\n\t\t\t/* Copy (cast) First term over to output */\n\t\t\tif (loop->cast) {\n\t\t\t\t/* A little tricky because we need to\n\t\t\t\t cast it first */\n\t\t\t\tarr->descr->f->copyswap(loop->buffer,\n\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t loop->insize);\n\t\t\t\tloop->cast(loop->buffer, loop->castbuf,\n\t\t\t\t\t 1, NULL, NULL);\n\t\t\t\tif (loop->obj) \n\t\t\t\t\tPy_INCREF(*((PyObject **)loop->castbuf));\n\t\t\t\tmemcpy(loop->bufptr[1], loop->castbuf,\n\t\t\t\t loop->outsize);\n\t\t\t}\n\t\t\telse { /* Simple copy */\n\t\t\t\tarr->descr->f->copyswap(loop->bufptr[1], \n\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t loop->insize);\n\t\t\t}\n\t\t\tloop->inptr += loop->instrides;\n n = 1;\n while(n < loop->N) {\n /* Copy up to loop->bufsize elements to \n buffer */\n dptr = loop->buffer;\n for (i=0; ibufsize; i++, n++) {\n if (n == loop->N) break;\n arr->descr->f->copyswap(dptr,\n loop->inptr,\n loop->swap,\n loop->insize);\n loop->inptr += loop->instrides;\n dptr += loop->insize;\n }\n if (loop->cast)\n loop->cast(loop->buffer,\n loop->castbuf,\n i, NULL, NULL);\n loop->function((char **)loop->bufptr,\n &i, \n\t\t\t\t\t loop->steps, loop->funcdata);\n\t\t\t\tUFUNC_CHECK_ERROR(loop);\n } \n PyArray_ITER_NEXT(loop->it);\n\t\t\tPyArray_ITER_NEXT(loop->rit);\n loop->bufptr[1] = loop->rit->dataptr;\n\t\t\tloop->bufptr[2] = loop->bufptr[1] + loop->steps[1];\n loop->index++;\n }\n }\n\n\tLOOP_END_THREADS\n ret = loop->ret;\n\t/* Hang on to this reference -- will be decref'd with loop */\n Py_INCREF(ret);\n ufuncreduce_dealloc(loop);\n return (PyObject *)ret;\n\n fail:\n\tLOOP_END_THREADS\n\n if (loop) ufuncreduce_dealloc(loop);\n return NULL;\n}\n\n/* Reduceat performs a reduce over an axis using the indices as a guide\n\nop.reduceat(array,indices) computes\nop.reduce(array[indices[i]:indices[i+1]] \n for i=0..end with an implicit indices[i+1]=len(array)\n assumed when i=end-1\n\nif indices[i+1] <= indices[i]+1 \n then the result is array[indices[i]] for that value\n\nop.accumulate(array) is the same as\nop.reduceat(array,indices)[::2]\nwhere indices is range(len(array)-1) with a zero placed in every other sample\n indices = zeros(len(array)*2-1)\n indices[1::2] = range(1,len(array))\n\noutput shape is based on the size of indices\n */\n\nstatic PyObject *\nPyUFunc_Reduceat(PyUFuncObject *self, PyArrayObject *arr, PyArrayObject *ind, \n int axis, int otype)\n{\t\n\tPyArrayObject *ret;\n PyUFuncReduceObject *loop;\n\tintp *ptr=(intp *)ind->data;\n\tintp nn=ind->dimensions[0];\t\t\n\tintp mm=arr->dimensions[axis]-1;\n\tintp n, i, j;\n\tchar *dptr;\n\n\t/* Check for out-of-bounds values in indices array */\t\t\n\tfor (i=0; i mm)) {\n\t\t\tPyErr_Format(PyExc_IndexError, \n\t\t\t\t \"index out-of-bounds (0, %d)\", (int) mm);\n\t\t\treturn NULL;\n\t\t}\n\t\tptr++;\n\t}\n\t\n\tptr = (intp *)ind->data;\n /* Construct loop object */\n loop = construct_reduce(self, &arr, axis, otype, UFUNC_REDUCEAT, nn,\n\t\t\t\t\"reduceat\");\n\tif (!loop) return NULL;\n\n\tLOOP_BEGIN_THREADS\n\tswitch(loop->meth) {\n\t/* zero-length index -- return array immediately */\n\tcase ZERODIM_REDUCELOOP:\n\t\t/* fprintf(stderr, \"ZERO..\\n\"); */\n\t\tbreak;\n\t/* NOBUFFER -- behaved array and same type */\n\tcase NOBUFFER_UFUNCLOOP: \t /* Reduceat */\n\t\t/* fprintf(stderr, \"NOBUFFER..%d\\n\", loop->size); */\n\t\twhile(loop->index < loop->size) {\n\t\t\tptr = (intp *)ind->data;\n\t\t\tfor (i=0; ibufptr[0] = loop->it->dataptr +\t\\\n\t\t\t\t\t(*ptr)*loop->instrides;\n\t\t\t\tif (loop->obj) \n\t\t\t\t\tPy_INCREF(*((PyObject **)loop->bufptr[0]));\n\t\t\t\tmemcpy(loop->bufptr[1], loop->bufptr[0],\n\t\t\t\t loop->outsize);\n\t\t\t\tmm = (i==nn-1 ? arr->dimensions[axis]-*ptr : \\\n\t\t\t\t *(ptr+1) - *ptr) - 1;\n\t\t\t\tif (mm > 0) {\n\t\t\t\t\tloop->bufptr[0] += loop->instrides;\n\t\t\t\t\tloop->bufptr[2] = loop->bufptr[1];\n\t\t\t\t\tloop->function((char **)loop->bufptr,\n\t\t\t\t\t\t &mm, loop->steps,\n\t\t\t\t\t\t loop->funcdata);\n\t\t\t\t\tUFUNC_CHECK_ERROR(loop);\n\t\t\t\t}\t\n\t\t\t\tloop->bufptr[1] += loop->ret->strides[axis];\n\t\t\t\tptr++;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(loop->it);\n\t\t\tPyArray_ITER_NEXT(loop->rit);\n\t\t\tloop->bufptr[1] = loop->rit->dataptr;\n\t\t\tloop->index++;\n\t\t}\n\t\tbreak;\n\n\t/* BUFFER -- misbehaved array or different types */ \n\tcase BUFFER_UFUNCLOOP: /* Reduceat */\n\t\t/* fprintf(stderr, \"BUFFERED..%d\\n\", loop->size); */\n\t\twhile(loop->index < loop->size) {\n\t\t\tptr = (intp *)ind->data;\n\t\t\tfor (i=0; iobj) \n\t\t\t\t\tPy_INCREF(*((PyObject **)loop->idptr));\n\t\t\t\tmemcpy(loop->bufptr[1], loop->idptr, \n\t\t\t\t loop->outsize);\n\t\t\t\tn = 0;\n\t\t\t\tmm = (i==nn-1 ? arr->dimensions[axis] - *ptr :\\\n\t\t\t\t *(ptr+1) - *ptr);\n\t\t\t\tif (mm < 1) mm = 1;\n\t\t\t\tloop->inptr = loop->it->dataptr + \\\n\t\t\t\t\t(*ptr)*loop->instrides;\n\t\t\t\twhile (n < mm) {\n\t\t\t\t\t/* Copy up to loop->bufsize elements\n\t\t\t\t\t to buffer */\n\t\t\t\t\tdptr = loop->buffer;\n\t\t\t\t\tfor (j=0; jbufsize; j++, n++) {\n\t\t\t\t\t\tif (n == mm) break;\n\t\t\t\t\t\tarr->descr->f->copyswap\\\n\t\t\t\t\t\t\t(dptr,\n\t\t\t\t\t\t\t loop->inptr,\n\t\t\t\t\t\t\t loop->swap,\n\t\t\t\t\t\t\t loop->insize);\n\t\t\t\t\t\tloop->inptr += loop->instrides;\n\t\t\t\t\t\tdptr += loop->insize;\n\t\t\t\t\t}\n\t\t\t\t\tif (loop->cast)\n\t\t\t\t\t\tloop->cast(loop->buffer,\n\t\t\t\t\t\t\t loop->castbuf,\n\t\t\t\t\t\t\t j, NULL, NULL);\n\t\t\t\t\tloop->bufptr[2] = loop->bufptr[1];\n\t\t\t\t\tloop->function((char **)loop->bufptr,\n\t\t\t\t\t\t &j, loop->steps,\n\t\t\t\t\t\t loop->funcdata);\n\t\t\t\t\tUFUNC_CHECK_ERROR(loop);\n\t\t\t\t} \n\t\t\t\tloop->bufptr[1] += loop->ret->strides[axis];\n\t\t\t\tptr++;\n\t\t\t}\n\t\t\tPyArray_ITER_NEXT(loop->it);\n\t\t\tPyArray_ITER_NEXT(loop->rit);\n\t\t\tloop->bufptr[1] = loop->rit->dataptr;\n\t\t\tloop->index++;\n\t\t}\n\t\tbreak;\n\t}\n\n\tLOOP_END_THREADS\n\t\n ret = loop->ret;\n\t/* Hang on to this reference -- will be decref'd with loop */\n Py_INCREF(ret);\n ufuncreduce_dealloc(loop);\n return (PyObject *)ret;\n\t\n fail:\n\tLOOP_END_THREADS\n\n if (loop) ufuncreduce_dealloc(loop);\n\treturn NULL;\n}\n\n\n/* This code handles reduce, reduceat, and accumulate \n (accumulate and reduce are special cases of the more general reduceat \n but they are handled separately for speed) \n*/\n\nstatic PyObject * \nPyUFunc_GenericReduction(PyUFuncObject *self, PyObject *args, \n PyObject *kwds, int operation) \n{\n\tint axis=0;\n\tPyArrayObject *mp, *ret = NULL;\n\tPyObject *op, *res=NULL;\n\tPyObject *obj_ind; \n\tPyArrayObject *indices = NULL;\n\tPyArray_Descr *otype=NULL;\n\tstatic char *kwlist1[] = {\"array\", \"axis\", \"dtype\", NULL};\n\tstatic char *kwlist2[] = {\"array\", \"indices\", \"axis\", \"dtype\", NULL}; \n static char *_reduce_type[] = {\"reduce\", \"accumulate\", \\\n\t\t\t\t \"reduceat\", NULL};\n\tif (self == NULL) {\n\t\tPyErr_SetString(PyExc_ValueError, \"function not supported\");\n\t\treturn NULL;\n\t}\t\n\n\tif (self->nin != 2) {\n\t\tPyErr_Format(PyExc_ValueError, \n \"%s only supported for binary functions\",\n _reduce_type[operation]);\n\t\treturn NULL;\n\t}\n\tif (self->nout != 1) {\n\t\tPyErr_Format(PyExc_ValueError,\n \"%s only supported for functions \" \\\n \"returning a single value\",\n _reduce_type[operation]);\n\t\treturn NULL;\n\t}\n\n\tif (operation == UFUNC_REDUCEAT) {\n\t\tPyArray_Descr *indtype;\n\t\tindtype = PyArray_DescrFromType(PyArray_INTP);\n\t\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"OO|iO&\", kwlist2, \n\t\t\t\t\t\t&op, &obj_ind, &axis, \n\t\t\t\t\t\tPyArray_DescrConverter, \n\t\t\t\t\t\t&otype)) return NULL;\n indices = (PyArrayObject *)PyArray_FromAny(obj_ind, indtype, \n\t\t\t\t\t\t\t 1, 1, CARRAY_FLAGS);\n if (indices == NULL) return NULL;\n\t\tPy_DECREF(indtype);\t\t\n\t}\n\telse {\n\t\tif(!PyArg_ParseTupleAndKeywords(args, kwds, \"O|iO&\", kwlist1,\n\t\t\t\t\t\t&op, &axis, \n\t\t\t\t\t\tPyArray_DescrConverter, \n\t\t\t\t\t\t&otype)) return NULL;\n\t}\n\t\n\t/* Ensure input is an array */\t\n\tmp = (PyArrayObject *)PyArray_FromAny(op, NULL, 0, 0, 0);\n\tif (mp == NULL) return NULL;\n\n /* Check to see if input is zero-dimensional */\n if (mp->nd == 0) {\n PyErr_Format(PyExc_TypeError, \"cannot %s on a scalar\",\n _reduce_type[operation]);\n Py_DECREF(mp);\n return NULL; \n }\n\n /* Check to see that type (and otype) is not FLEXIBLE */\n\tif (PyArray_ISFLEXIBLE(mp) || (otype && PyTypeNum_ISFLEXIBLE(otype->type_num))) {\n PyErr_Format(PyExc_TypeError, \n\t\t\t \"cannot perform %s with flexible type\",\n _reduce_type[operation]);\n Py_DECREF(mp);\n return NULL;\n }\n\n\tif (axis < 0) axis += mp->nd;\n\tif (axis < 0 || axis >= mp->nd) {\n\t\tPyErr_SetString(PyExc_ValueError, \"axis not in array\");\n Py_DECREF(mp);\n\t\treturn NULL;\n\t}\n\n\t/* Get default type to reduce over if not given */\n if (otype == NULL) {\n\t\t/* For integer types --- makes sure at \n\t\t least a long is used */\n\t\tint typenum = PyArray_TYPE(mp);\n\t\tif (PyTypeNum_ISINTEGER(typenum) &&\t\\\n\t\t (mp->descr->elsize < sizeof(long))) {\n\t\t\tif (PyTypeNum_ISUNSIGNED(typenum))\n\t\t\t\ttypenum = PyArray_ULONG;\n\t\t\telse\n\t\t\t\ttypenum = PyArray_LONG;\n\t\t}\n\t\telse if (PyTypeNum_ISBOOL(typenum) && \\\n\t\t\t ((strcmp(self->name,\"add\")==0) ||\t\\\n\t\t\t (strcmp(self->name,\"multiply\")==0))) {\n\t\t\ttypenum = PyArray_LONG;\n\t\t}\n\t\totype = PyArray_DescrFromType(typenum);\n\t}\n\n switch(operation) {\n case UFUNC_REDUCE:\n ret = (PyArrayObject *)PyUFunc_Reduce(self, mp, axis, \n otype->type_num);\n\t\tbreak;\n case UFUNC_ACCUMULATE:\n ret = (PyArrayObject *)PyUFunc_Accumulate(self, mp, axis, \n otype->type_num);\n\t\tbreak;\n case UFUNC_REDUCEAT:\n ret = (PyArrayObject *)PyUFunc_Reduceat(self, mp, indices, \n axis, otype->type_num);\n Py_DECREF(indices);\n\t\tbreak;\n }\n Py_DECREF(mp);\n\tPy_DECREF(otype);\n\tif (ret==NULL) return NULL;\n\tif (op->ob_type != ret->ob_type) {\n\t\tres = PyObject_CallMethod(op, \"__array_wrap__\", \"O\", ret);\n\t\tif (res == NULL) PyErr_Clear();\n\t\telse if (res == Py_None) Py_DECREF(res);\n\t\telse {\n\t\t\tPy_DECREF(ret);\n\t\t\treturn res;\n\t\t}\t\n\t}\n\treturn PyArray_Return(ret);\n\t\n}\n\n\n\n/* ---------- */\n\nstatic PyObject *\n_find_array_wrap(PyObject *args)\n{\n\tint nargs, i;\n\tint np = 0;\n\tint argmax = 0;\n\tint val;\n\tdouble priority[MAX_ARGS];\n\tdouble maxpriority = PyArray_SUBTYPE_PRIORITY;\n\tPyObject *with_wrap[MAX_ARGS];\n\tPyObject *attr;\n\tPyObject *obj;\n\n\tnargs = PyTuple_Size(args);\n\tfor (i=0; i maxpriority) {\n\t\t\tmaxpriority = priority[i];\n\t\t\targmax = i;\n\t\t}\n\t}\n\n\treturn with_wrap[argmax];\n}\n\nstatic PyObject *\nufunc_generic_call(PyUFuncObject *self, PyObject *args) \n{\n\tint i;\n\tPyTupleObject *ret;\n\tPyArrayObject *mps[MAX_ARGS];\n\tPyObject *retobj[MAX_ARGS];\n\tPyObject *res;\n\tPyObject *obj;\n int errval;\n \n\t/* Initialize all array objects to NULL to make cleanup easier \n\t if something goes wrong. */\n\tfor(i=0; inargs; i++) mps[i] = NULL;\n\t\n errval = PyUFunc_GenericFunction(self, args, mps);\n if (errval < 0) {\n\t\tfor(i=0; inargs; i++) Py_XDECREF(mps[i]);\n\t\tif (errval == -1)\n\t\t\treturn NULL;\n\t\telse {\n\t\t\tPy_INCREF(Py_NotImplemented);\n\t\t\treturn Py_NotImplemented;\n\t\t}\n }\n\t\n\tfor(i=0; inin; i++) Py_DECREF(mps[i]);\n\n\t/* Use __array_wrap__ on all outputs \n\t if present on one of the input arguments.\n\t If present for multiple inputs:\n\t use __array_wrap__ of input object with largest \n\t\t__array_priority__ (default = 0.0)\n\t */\n\tobj = _find_array_wrap(args);\n\t\n\t/* wrap outputs */\n\tfor (i=0; inout; i++) {\n\t\tint j=self->nin+i;\n\t\t/* check to see if any UPDATEIFCOPY flags are set \n\t\t which meant that a temporary output was generated \n\t\t*/\n\t\tif (mps[j]->flags & UPDATEIFCOPY) {\n\t\t\tPyObject *old = mps[j]->base;\n\t\t\tPy_INCREF(old); /* we want to hang on to this */\n\t\t\tPy_DECREF(mps[j]); /* should trigger the copy \n\t\t\t\t\t back into old */\n\t\t\tmps[j] = (PyArrayObject *)old;\n\t\t}\n\t\tif (obj != NULL) {\n\t\t\tres = PyObject_CallMethod(obj, \"__array_wrap__\",\n\t\t\t\t\t\t \"O\", mps[j]);\n\t\t\tif (res == NULL) PyErr_Clear();\n\t\t\telse if (res == Py_None) Py_DECREF(res);\n\t\t\telse {\n\t\t\t\tPy_DECREF(mps[j]);\n\t\t\t\tretobj[i] = res;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t}\n\t\tretobj[i] = PyArray_Return(mps[j]);\n\t}\n\t\n\tif (self->nout == 1) { \n\t\treturn retobj[0];\n\t} else { \n\t\tret = (PyTupleObject *)PyTuple_New(self->nout);\n\t\tfor(i=0; inout; i++) {\n\t\t\tPyTuple_SET_ITEM(ret, i, retobj[i]);\n\t\t}\n\t\treturn (PyObject *)ret;\n\t}\t\n\n}\n\nstatic PyObject *\nufunc_update_use_defaults(PyObject *dummy, PyObject *args)\n{\n\tPyObject *errobj;\n\tint errmask, bufsize;\n\n\tif (!PyArg_ParseTuple(args, \"\")) return NULL;\n\t\n\tPyUFunc_USEDEFAULTS = 0;\n\tif (PyUFunc_GetPyValues(\"test\", &bufsize, &errmask, &errobj) < 0) return NULL;\n\t\n\tif ((errmask == UFUNC_ERR_DEFAULT) &&\t\t\\\n\t (bufsize == PyArray_BUFSIZE) &&\t\t\\\n\t (PyTuple_GET_ITEM(errobj, 1) == Py_None)) {\n\t\tPyUFunc_USEDEFAULTS = 1;\n\t}\n\t\n\tPy_INCREF(Py_None);\n\treturn Py_None;\n}\n\nstatic PyUFuncGenericFunction pyfunc_functions[] = {PyUFunc_On_Om};\n\nstatic char \ndoc_frompyfunc[] = \"frompyfunc(func, nin, nout) take an arbitrary python function that takes nin objects as input and returns nout objects and return a universal function (ufunc). This ufunc always returns PyObject arrays\";\n\nstatic PyObject *\nufunc_frompyfunc(PyObject *dummy, PyObject *args, PyObject *kwds) {\n /* Keywords are ignored for now */\n \n PyObject *function, *pyname=NULL;\n int nin, nout, i;\n PyUFunc_PyFuncData *fdata;\n PyUFuncObject *self;\n char *fname, *str;\n int fname_len=-1;\n\tint offset[2];\n\n if (!PyArg_ParseTuple(args, \"Oii\", &function, &nin, &nout)) return NULL;\n\n if (!PyCallable_Check(function)) {\n PyErr_SetString(PyExc_TypeError, \"function must be callable\");\n return NULL;\n }\n\t\n self = _pya_malloc(sizeof(PyUFuncObject));\n if (self == NULL) return NULL;\n PyObject_Init((PyObject *)self, &PyUFunc_Type);\n\n\tself->userloops = NULL;\n\tself->nin = nin;\n\tself->nout = nout;\n\tself->nargs = nin+nout;\n\tself->identity = PyUFunc_None;\t\n\tself->functions = pyfunc_functions;\n\n\tself->ntypes = 1;\n\tself->check_return = 0;\n\n pyname = PyObject_GetAttrString(function, \"__name__\");\n if (pyname)\n (void) PyString_AsStringAndSize(pyname, &fname, &fname_len);\n \n if (PyErr_Occurred()) {\n fname = \"?\";\n fname_len = 1;\n PyErr_Clear();\n } \n Py_XDECREF(pyname);\n\n\n\n\t/* self->ptr holds a pointer for enough memory for\n\t self->data[0] (fdata)\n\t self->data\n\t self->name\n\t self->types\n\n\t To be safest, all of these need their memory aligned on void * pointers\n\t Therefore, we may need to allocate extra space.\n\t*/\n\toffset[0] = sizeof(PyUFunc_PyFuncData);\n\ti = (sizeof(PyUFunc_PyFuncData) % sizeof(void *));\n\tif (i) offset[0] += (sizeof(void *) - i);\n\toffset[1] = self->nargs;\n\ti = (self->nargs % sizeof(void *));\n\tif (i) offset[1] += (sizeof(void *)-i);\n\n self->ptr = _pya_malloc(offset[0] + offset[1] + sizeof(void *) + \\\n\t\t\t (fname_len+14));\n\n\tif (self->ptr == NULL) return PyErr_NoMemory();\n Py_INCREF(function);\n self->obj = function;\n\tfdata = (PyUFunc_PyFuncData *)(self->ptr);\n fdata->nin = nin;\n fdata->nout = nout;\n fdata->callable = function;\n \n self->data = (void **)(self->ptr + offset[0]);\n self->data[0] = (void *)fdata;\n\t\n\tself->types = (char *)self->data + sizeof(void *);\n for (i=0; inargs; i++) self->types[i] = PyArray_OBJECT;\n\n str = self->types + offset[1];\n memcpy(str, fname, fname_len);\n memcpy(str+fname_len, \" (vectorized)\", 14);\n \n self->name = str;\n\n /* Do a better job someday */\n self->doc = \"dynamic ufunc based on a python function\";\n \n\t\n\treturn (PyObject *)self;\n}\n\n\n/*UFUNC_API*/\nstatic PyObject *\nPyUFunc_FromFuncAndData(PyUFuncGenericFunction *func, void **data, \n\t\t\tchar *types, int ntypes,\n\t\t\tint nin, int nout, int identity, \n\t\t\tchar *name, char *doc, int check_return) \n{\n\tPyUFuncObject *self;\n\n self = _pya_malloc(sizeof(PyUFuncObject));\n if (self == NULL) return NULL;\n PyObject_Init((PyObject *)self, &PyUFunc_Type);\n\t\n\tself->nin = nin;\n\tself->nout = nout;\n\tself->nargs = nin+nout;\n\tself->identity = identity;\n\t\n\tself->functions = func;\n\tself->data = data;\n\tself->types = types;\n\tself->ntypes = ntypes;\n\tself->check_return = check_return;\n self->ptr = NULL;\n self->obj = NULL;\n\tself->userloops=NULL;\n\t\n\tif (name == NULL) self->name = \"?\";\n\telse self->name = name;\n\t\n if (doc == NULL) self->doc = \"NULL\";\n\telse self->doc = doc;\n\t\n\treturn (PyObject *)self;\n}\n\n/*UFUNC_API*/\nstatic int\nPyUFunc_RegisterLoopForType(PyUFuncObject *ufunc, \n\t\t\t int usertype,\n\t\t\t PyUFuncGenericFunction function,\n\t\t\t void *data)\n{\n\tPyArray_Descr *descr;\n \tPyObject *key, *cobj;\n\tint ret;\t\n\t\n\tdescr=PyArray_DescrFromType(usertype);\n\tif ((usertype < PyArray_USERDEF) || (descr==NULL)) {\n\t\tPyErr_SetString(PyExc_TypeError, \n\t\t\t\t\"unknown type\");\n\t\treturn -1;\n\t}\n\tPy_DECREF(descr);\n\t\n\tif (ufunc->userloops == NULL) {\n\t\tufunc->userloops = PyDict_New();\n\t}\n\tkey = PyInt_FromLong((long) usertype);\n\tif (key == NULL) return -1;\n\tcobj = PyCObject_FromVoidPtr((void *)function, NULL);\n\tif (cobj == NULL) {Py_DECREF(key); return -1;}\n\tif (data == NULL) {\n\t\tret = PyDict_SetItem(ufunc->userloops, key, cobj);\n\t\tPy_DECREF(cobj);\n\t\tPy_DECREF(key);\n\t\treturn ret;\n\t}\n\telse {\n\t\tPyObject *cobj2, *tmp;\n\t\tcobj2 = PyCObject_FromVoidPtr(data, NULL);\n\t\tif (cobj2 == NULL) {\n\t\t\tPy_DECREF(cobj); \n\t\t\tPy_DECREF(key);\n\t\t\treturn -1;\n\t\t}\n\t\ttmp=Py_BuildValue(\"NN\", cobj, cobj2);\n\t\tret = PyDict_SetItem(ufunc->userloops, key, tmp);\n\t\tPy_DECREF(tmp);\n\t\tPy_DECREF(key);\n\t\treturn ret;\n\t}\n}\n\nstatic void\nufunc_dealloc(PyUFuncObject *self)\n{\n if (self->ptr) _pya_free(self->ptr);\n\tPy_XDECREF(self->userloops);\n Py_XDECREF(self->obj);\n _pya_free(self);\n}\n\nstatic PyObject *\nufunc_repr(PyUFuncObject *self)\n{\n\tchar buf[100];\n\t\n\tsprintf(buf, \"\", self->name);\n\t\n\treturn PyString_FromString(buf);\n}\n\n\n/* -------------------------------------------------------- */\n\n/* op.outer(a,b) is equivalent to op(a[:,NewAxis,NewAxis,etc.],b)\n where a has b.ndim NewAxis terms appended.\n\n The result has dimensions a.ndim + b.ndim\n */\n\nstatic PyObject *\nufunc_outer(PyUFuncObject *self, PyObject *args) \n{\n\tint i;\n\tPyObject *ret;\n\tPyArrayObject *ap1=NULL, *ap2=NULL, *ap_new=NULL;\n\tPyObject *new_args, *tmp;\n\tPyObject *shape1, *shape2, *newshape;\n\n\tif(self->nin != 2) {\n\t\tPyErr_SetString(PyExc_ValueError,\n\t\t\t\t\"outer product only supported \"\\\n\t\t\t\t\"for binary functions\");\n\t\treturn NULL;\n\t}\n\t\n\tif (PySequence_Length(args) != 2) {\n\t\tPyErr_SetString(PyExc_TypeError,\n\t\t\t\t\"exactly two arguments expected\");\n\t\treturn NULL;\n\t}\n\t\n\ttmp = PySequence_GetItem(args, 0);\n\tif (tmp == NULL) return NULL;\n\tap1 = (PyArrayObject *)\t\t\t\t\t\\\n\t\tPyArray_FromObject(tmp, PyArray_NOTYPE, 0, 0);\n\tPy_DECREF(tmp);\n\tif (ap1 == NULL) return NULL;\n\t\n\ttmp = PySequence_GetItem(args, 1);\n\tif (tmp == NULL) return NULL;\n\tap2 = (PyArrayObject *)PyArray_FromObject(tmp, PyArray_NOTYPE, 0, 0);\n\tPy_DECREF(tmp);\n\tif (ap2 == NULL) {Py_DECREF(ap1); return NULL;}\n\n\t/* Construct new shape tuple */\n\tshape1 = PyTuple_New(ap1->nd);\n\tif (shape1 == NULL) goto fail;\n\tfor (i=0; ind; i++) \n\t\tPyTuple_SET_ITEM(shape1, i, \n\t\t\t\t PyLong_FromLongLong((longlong)ap1->\t\\\n\t\t\t\t\t\t dimensions[i]));\n\t\n\tshape2 = PyTuple_New(ap2->nd);\n\tfor (i=0; ind; i++) \n\t\tPyTuple_SET_ITEM(shape2, i, PyInt_FromLong((long) 1));\n\tif (shape2 == NULL) {Py_DECREF(shape1); goto fail;}\n\tnewshape = PyNumber_Add(shape1, shape2);\n\tPy_DECREF(shape1);\n\tPy_DECREF(shape2);\n\tif (newshape == NULL) goto fail;\n\t\n\tap_new = (PyArrayObject *)PyArray_Reshape(ap1, newshape);\n\tPy_DECREF(newshape);\n\tif (ap_new == NULL) goto fail;\n\t\n\tnew_args = Py_BuildValue(\"(OO)\", ap_new, ap2);\n\tPy_DECREF(ap1);\n\tPy_DECREF(ap2);\n\tPy_DECREF(ap_new);\t\n\tret = ufunc_generic_call(self, new_args);\n\tPy_DECREF(new_args);\n\treturn ret;\n\n fail:\n\tPy_XDECREF(ap1);\n\tPy_XDECREF(ap2);\n\tPy_XDECREF(ap_new);\n\treturn NULL;\n\n}\n\n\nstatic PyObject *\nufunc_reduce(PyUFuncObject *self, PyObject *args, PyObject *kwds) \n{\n\t\n\treturn PyUFunc_GenericReduction(self, args, kwds, UFUNC_REDUCE);\n}\n\nstatic PyObject *\nufunc_accumulate(PyUFuncObject *self, PyObject *args, PyObject *kwds) \n{\n\t\n\treturn PyUFunc_GenericReduction(self, args, kwds, UFUNC_ACCUMULATE);\n}\n\nstatic PyObject *\nufunc_reduceat(PyUFuncObject *self, PyObject *args, PyObject *kwds) \n{\t\n\treturn PyUFunc_GenericReduction(self, args, kwds, UFUNC_REDUCEAT);\n}\n\n\nstatic struct PyMethodDef ufunc_methods[] = {\n\t{\"reduce\", (PyCFunction)ufunc_reduce, METH_VARARGS | METH_KEYWORDS},\n\t{\"accumulate\", (PyCFunction)ufunc_accumulate, \n\t METH_VARARGS | METH_KEYWORDS},\n\t{\"reduceat\", (PyCFunction)ufunc_reduceat, \n\t METH_VARARGS | METH_KEYWORDS},\t\n\t{\"outer\", (PyCFunction)ufunc_outer, METH_VARARGS},\n\t{NULL,\t\tNULL}\t\t/* sentinel */\n};\n\n\n\n/* construct the string\n y1,y2,...,yn\n*/\n\nstatic void\n_makeargs(int num, char ltr, char *str) \n{\n\tint ind=0;\n\tint k;\n\tstatic char *digits=\"123456789ABCDE\";\n\n\tif (num == 1) {\n\t\tstr[0] = ltr;\n\t\tind = 1;\n\t}\n\telse {\n\t\tfor (k=0; ktype;\n\tPy_DECREF(descr);\n\treturn ret;\n} \n\nstatic PyObject *\nufunc_getattr(PyUFuncObject *self, char *name)\n{\n\tPyObject *obj;\n\t/* Put docstring first or FindMethod finds it...*/\n\t/* could so some introspection on name and nin + nout */\n\t/* to automate the first part of it */\n\t/* the doc string shouldn't need the calling convention */\n\tif (strcmp(name, \"__doc__\") == 0) {\n\t\tstatic char doc[256];\n\t\tstatic char tmp1[3*MAX_ARGS+2];\n\t\tstatic char tmp2[3*MAX_ARGS+2];\n\t\t/* construct \n\t\t y1,y2,,... = name(x1,x2,...) __doc__\n\t\t*/\t\t\n\t\t_makeargs(self->nout, 'y', tmp1);\n\t\t_makeargs(self->nin, 'x', tmp2);\n\t\tsnprintf(doc, 256, \"%s = %s(%s) %s\", tmp1, self->name, \n\t\t\t tmp2, self->doc);\n\t\treturn PyString_FromString(doc);\n\t}\n\tobj = Py_FindMethod(ufunc_methods, (PyObject *)self, name);\n\tif (obj != NULL) return obj;\n\tPyErr_Clear();\n\tif (strcmp(name, \"nin\") == 0) {\n\t\treturn PyInt_FromLong(self->nin);\n\t}\n\telse if (strcmp(name, \"nout\") == 0) {\n\t\treturn PyInt_FromLong(self->nout);\n\t}\n\telse if (strcmp(name, \"nargs\") == 0) {\n\t\treturn PyInt_FromLong(self->nargs);\n\t}\n\telse if (strcmp(name, \"ntypes\") == 0) {\n\t\treturn PyInt_FromLong(self->ntypes);\n\t}\n\telse if (strcmp(name, \"types\") == 0) {\n\t\t/* return a list with types grouped\n\t\t input->output */\n\t\tPyObject *list;\n\t\tPyObject *str;\n\t\tint k, j, n, nt=self->ntypes;\n\t\tint ni = self->nin;\n\t\tint no = self->nout;\n\t\tchar *t;\n\t\tlist = PyList_New(nt);\n\t\tif (list == NULL) return NULL;\n\t\tt = _pya_malloc(no+ni+2);\n\t\tn = 0;\n\t\tfor (k=0; ktypes[n]);\n\t\t\t\tn++;\n\t\t\t}\n\t\t\tt[ni] = '-';\n\t\t\tt[ni+1] = '>';\n\t\t\tfor (j=0; jtypes[n]);\n\t\t\t\tn++;\n\t\t\t}\n\t\t\tstr = PyString_FromStringAndSize(t, no+ni+2);\n\t\t\tPyList_SET_ITEM(list, k, str);\n\t\t}\n\t\t_pya_free(t);\n\t\treturn list;\n\t\t\n\t}\n\telse if (strcmp(name, \"__name__\") == 0) {\n\t\treturn PyString_FromString(self->name);\n\t}\n\telse if (strcmp(name, \"identity\") == 0) {\n\t\tswitch(self->identity) {\n\t\tcase PyUFunc_One:\n\t\t\treturn PyInt_FromLong(1);\n\t\tcase PyUFunc_Zero:\n\t\t\treturn PyInt_FromLong(0);\n\t\tdefault:\n\t\t\tPy_INCREF(Py_None);\n\t\t\treturn Py_None;\n\t\t}\n\t}\n\tPyErr_SetString(PyExc_AttributeError, name);\n\treturn NULL;\n}\n\n#undef _typecharfromnum\n\nstatic int\nufunc_setattr(PyUFuncObject *self, char *name, PyObject *v) \n{\n\treturn -1;\n}\n\nstatic char Ufunctype__doc__[] = \n\t\"Optimized functions make it possible to implement arithmetic \"\\\n\t\"with arrays efficiently\";\n\nstatic PyTypeObject PyUFunc_Type = {\n\tPyObject_HEAD_INIT(0)\n\t0,\t\t\t\t/*ob_size*/\n\t\"numpy.ufunc\",\t\t\t/*tp_name*/\n\tsizeof(PyUFuncObject),\t\t/*tp_basicsize*/\n\t0,\t\t\t\t/*tp_itemsize*/\n\t/* methods */\n\t(destructor)ufunc_dealloc,\t/*tp_dealloc*/\n\t(printfunc)0,\t\t /*tp_print*/\n\t(getattrfunc)ufunc_getattr,\t/*tp_getattr*/\n\t(setattrfunc)ufunc_setattr,\t/*tp_setattr*/\n\t(cmpfunc)0,\t \t/*tp_compare*/\n\t(reprfunc)ufunc_repr,\t\t/*tp_repr*/\n\t0,\t\t\t /*tp_as_number*/\n\t0,\t\t /*tp_as_sequence*/\n\t0,\t\t /*tp_as_mapping*/\n\t(hashfunc)0,\t\t/*tp_hash*/\n\t(ternaryfunc)ufunc_generic_call,\t\t/*tp_call*/\n\t(reprfunc)ufunc_repr,\t\t/*tp_str*/\n\t\t\n\t/* Space for future expansion */\n\t0L,0L,0L,0L,\n\tUfunctype__doc__ /* Documentation string */\n};\n\n/* End of code for ufunc objects */\n/* -------------------------------------------------------- */\n", + "methods": [ + { + "name": "PyUFunc_ff_f_As_dd_d", + "long_name": "PyUFunc_ff_f_As_dd_d( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 146, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 41, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_ff_f", + "long_name": "PyUFunc_ff_f( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 136, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 55, + "end_line": 66, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_dd_d", + "long_name": "PyUFunc_dd_d( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 137, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 70, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_gg_g", + "long_name": "PyUFunc_gg_g( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 137, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 85, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_FF_F_As_DD_D", + "long_name": "PyUFunc_FF_F_As_DD_D( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 225, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 101, + "end_line": 114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_DD_D", + "long_name": "PyUFunc_DD_D( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 219, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 118, + "end_line": 131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_FF_F", + "long_name": "PyUFunc_FF_F( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 219, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 135, + "end_line": 148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_GG_G", + "long_name": "PyUFunc_GG_G( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 15, + "complexity": 2, + "token_count": 219, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 152, + "end_line": 167, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_OO_O", + "long_name": "PyUFunc_OO_O( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 22, + "complexity": 6, + "token_count": 236, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 171, + "end_line": 193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_f_f_As_d_d", + "long_name": "PyUFunc_f_f_As_d_d( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 106, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 205, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_d_d", + "long_name": "PyUFunc_d_d( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 93, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 216, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_f_f", + "long_name": "PyUFunc_f_f( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 101, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 227, + "end_line": 235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_g_g", + "long_name": "PyUFunc_g_g( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 102, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 239, + "end_line": 248, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_F_F_As_D_D", + "long_name": "PyUFunc_F_F_As_D_D( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 164, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 253, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_F_F", + "long_name": "PyUFunc_F_F( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 150, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 268, + "end_line": 279, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_D_D", + "long_name": "PyUFunc_D_D( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 150, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 284, + "end_line": 295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_G_G", + "long_name": "PyUFunc_G_G( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 150, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 300, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_O_O", + "long_name": "PyUFunc_O_O( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 149, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 315, + "end_line": 330, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_O_O_method", + "long_name": "PyUFunc_O_O_method( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 190, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 334, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_On_Om", + "long_name": "PyUFunc_On_Om( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 47, + "complexity": 11, + "token_count": 357, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 366, + "end_line": 414, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 49, + "top_nesting_level": 0 + }, + { + "name": "_error_handler", + "long_name": "_error_handler( int method , PyObject * errobj , char * errtype , int retstatus)", + "filename": "ufuncobject.c", + "nloc": 41, + "complexity": 8, + "token_count": 211, + "parameters": [ + "method", + "errobj", + "errtype", + "retstatus" + ], + "start_line": 438, + "end_line": 484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_checkfperr", + "long_name": "PyUFunc_checkfperr( int errmask , PyObject * errobj)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 60, + "parameters": [ + "errmask", + "errobj" + ], + "start_line": 489, + "end_line": 518, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_clearfperr", + "long_name": "PyUFunc_clearfperr()", + "filename": "ufuncobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 12, + "parameters": [], + "start_line": 524, + "end_line": 529, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_lowest_type", + "long_name": "_lowest_type( char intype)", + "filename": "ufuncobject.c", + "nloc": 23, + "complexity": 13, + "token_count": 66, + "parameters": [ + "intype" + ], + "start_line": 551, + "end_line": 577, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_cancoerce", + "long_name": "_cancoerce( char thistype , char neededtype , char scalar)", + "filename": "ufuncobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 101, + "parameters": [ + "thistype", + "neededtype", + "scalar" + ], + "start_line": 583, + "end_line": 604, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "select_types", + "long_name": "select_types( PyUFuncObject * self , int * arg_types , PyUFuncGenericFunction * function , ** data , char * scalars)", + "filename": "ufuncobject.c", + "nloc": 76, + "complexity": 19, + "token_count": 479, + "parameters": [ + "self", + "arg_types", + "function", + "data", + "scalars" + ], + "start_line": 608, + "end_line": 695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_GetPyValues", + "long_name": "PyUFunc_GetPyValues( char * name , int * bufsize , int * errmask , PyObject ** errobj)", + "filename": "ufuncobject.c", + "nloc": 67, + "complexity": 18, + "token_count": 387, + "parameters": [ + "name", + "bufsize", + "errmask", + "errobj" + ], + "start_line": 701, + "end_line": 773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "_scalar_kind", + "long_name": "_scalar_kind( int typenum , PyArrayObject ** arr)", + "filename": "ufuncobject.c", + "nloc": 9, + "complexity": 6, + "token_count": 64, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 777, + "end_line": 785, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "_create_copies", + "long_name": "_create_copies( PyUFuncLoopObject * loop , int * arg_types , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 234, + "parameters": [ + "loop", + "arg_types", + "mps" + ], + "start_line": 794, + "end_line": 832, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "_has_reflected_op", + "long_name": "_has_reflected_op( PyObject * op , char * name)", + "filename": "ufuncobject.c", + "nloc": 17, + "complexity": 1, + "token_count": 93, + "parameters": [ + "op", + "name" + ], + "start_line": 838, + "end_line": 854, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "construct_matrices", + "long_name": "construct_matrices( PyUFuncLoopObject * loop , PyObject * args , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 283, + "complexity": 74, + "token_count": 2197, + "parameters": [ + "loop", + "args", + "mps" + ], + "start_line": 860, + "end_line": 1247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 388, + "top_nesting_level": 0 + }, + { + "name": "ufuncreduce_dealloc", + "long_name": "ufuncreduce_dealloc( PyUFuncReduceObject * self)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 76, + "parameters": [ + "self" + ], + "start_line": 1250, + "end_line": 1262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "ufuncloop_dealloc", + "long_name": "ufuncloop_dealloc( PyUFuncLoopObject * self)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 86, + "parameters": [ + "self" + ], + "start_line": 1265, + "end_line": 1277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "construct_loop", + "long_name": "construct_loop( PyUFuncObject * self , PyObject * args , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 30, + "complexity": 7, + "token_count": 209, + "parameters": [ + "self", + "args", + "mps" + ], + "start_line": 1280, + "end_line": 1317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_GenericFunction", + "long_name": "PyUFunc_GenericFunction( PyUFuncObject * self , PyObject * args , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 186, + "complexity": 48, + "token_count": 1403, + "parameters": [ + "self", + "args", + "mps" + ], + "start_line": 1389, + "end_line": 1657, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 269, + "top_nesting_level": 0 + }, + { + "name": "_getidentity", + "long_name": "_getidentity( PyUFuncObject * self , int otype , char * str)", + "filename": "ufuncobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 117, + "parameters": [ + "self", + "otype", + "str" + ], + "start_line": 1660, + "end_line": 1681, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "_create_reduce_copy", + "long_name": "_create_reduce_copy( PyUFuncReduceObject * loop , PyArrayObject ** arr , int rtype)", + "filename": "ufuncobject.c", + "nloc": 20, + "complexity": 5, + "token_count": 125, + "parameters": [ + "loop", + "arr", + "rtype" + ], + "start_line": 1684, + "end_line": 1714, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "construct_reduce", + "long_name": "construct_reduce( PyUFuncObject * self , PyArrayObject ** arr , int axis , int otype , int operation , intp ind_size , char * str)", + "filename": "ufuncobject.c", + "nloc": 172, + "complexity": 37, + "token_count": 1390, + "parameters": [ + "self", + "arr", + "axis", + "otype", + "operation", + "ind_size", + "str" + ], + "start_line": 1717, + "end_line": 1930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 214, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_Reduce", + "long_name": "PyUFunc_Reduce( PyUFuncObject * self , PyArrayObject * arr , int axis , int otype)", + "filename": "ufuncobject.c", + "nloc": 105, + "complexity": 20, + "token_count": 747, + "parameters": [ + "self", + "arr", + "axis", + "otype" + ], + "start_line": 1942, + "end_line": 2077, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_Accumulate", + "long_name": "PyUFunc_Accumulate( PyUFuncObject * self , PyArrayObject * arr , int axis , int otype)", + "filename": "ufuncobject.c", + "nloc": 109, + "complexity": 20, + "token_count": 779, + "parameters": [ + "self", + "arr", + "axis", + "otype" + ], + "start_line": 2081, + "end_line": 2219, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_Reduceat", + "long_name": "PyUFunc_Reduceat( PyUFuncObject * self , PyArrayObject * arr , PyArrayObject * ind , int axis , int otype)", + "filename": "ufuncobject.c", + "nloc": 111, + "complexity": 23, + "token_count": 816, + "parameters": [ + "self", + "arr", + "ind", + "axis", + "otype" + ], + "start_line": 2241, + "end_line": 2370, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_GenericReduction", + "long_name": "PyUFunc_GenericReduction( PyUFuncObject * self , PyObject * args , PyObject * kwds , int operation)", + "filename": "ufuncobject.c", + "nloc": 114, + "complexity": 30, + "token_count": 709, + "parameters": [ + "self", + "args", + "kwds", + "operation" + ], + "start_line": 2379, + "end_line": 2507, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "top_nesting_level": 0 + }, + { + "name": "_find_array_wrap", + "long_name": "_find_array_wrap( PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 51, + "complexity": 12, + "token_count": 279, + "parameters": [ + "args" + ], + "start_line": 2514, + "end_line": 2567, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "ufunc_generic_call", + "long_name": "ufunc_generic_call( PyUFuncObject * self , PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 58, + "complexity": 14, + "token_count": 415, + "parameters": [ + "self", + "args" + ], + "start_line": 2570, + "end_line": 2647, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + }, + { + "name": "ufunc_update_use_defaults", + "long_name": "ufunc_update_use_defaults( PyObject * dummy , PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 15, + "complexity": 6, + "token_count": 100, + "parameters": [ + "dummy", + "args" + ], + "start_line": 2650, + "end_line": 2668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "ufunc_frompyfunc", + "long_name": "ufunc_frompyfunc( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "ufuncobject.c", + "nloc": 59, + "complexity": 10, + "token_count": 528, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 2676, + "end_line": 2765, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 90, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_FromFuncAndData", + "long_name": "PyUFunc_FromFuncAndData( PyUFuncGenericFunction * func , ** data , char * types , int ntypes , int nin , int nout , int identity , char * name , char * doc , int check_return)", + "filename": "ufuncobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 193, + "parameters": [ + "func", + "data", + "types", + "ntypes", + "nin", + "nout", + "identity", + "name", + "doc", + "check_return" + ], + "start_line": 2770, + "end_line": 2802, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_RegisterLoopForType", + "long_name": "PyUFunc_RegisterLoopForType( PyUFuncObject * ufunc , int usertype , PyUFuncGenericFunction function , * data)", + "filename": "ufuncobject.c", + "nloc": 43, + "complexity": 8, + "token_count": 251, + "parameters": [ + "ufunc", + "usertype", + "function", + "data" + ], + "start_line": 2806, + "end_line": 2850, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "ufunc_dealloc", + "long_name": "ufunc_dealloc( PyUFuncObject * self)", + "filename": "ufuncobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 2853, + "end_line": 2859, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "ufunc_repr", + "long_name": "ufunc_repr( PyUFuncObject * self)", + "filename": "ufuncobject.c", + "nloc": 6, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self" + ], + "start_line": 2862, + "end_line": 2869, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ufunc_outer", + "long_name": "ufunc_outer( PyUFuncObject * self , PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 59, + "complexity": 13, + "token_count": 428, + "parameters": [ + "self", + "args" + ], + "start_line": 2881, + "end_line": 2950, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "ufunc_reduce", + "long_name": "ufunc_reduce( PyUFuncObject * self , PyObject * args , PyObject * kwds)", + "filename": "ufuncobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 2954, + "end_line": 2958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "ufunc_accumulate", + "long_name": "ufunc_accumulate( PyUFuncObject * self , PyObject * args , PyObject * kwds)", + "filename": "ufuncobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 2961, + "end_line": 2965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "ufunc_reduceat", + "long_name": "ufunc_reduceat( PyUFuncObject * self , PyObject * args , PyObject * kwds)", + "filename": "ufuncobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 2968, + "end_line": 2971, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_makeargs", + "long_name": "_makeargs( int num , char ltr , char * str)", + "filename": "ufuncobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 117, + "parameters": [ + "num", + "ltr", + "str" + ], + "start_line": 2991, + "end_line": 3013, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_typecharfromnum", + "long_name": "_typecharfromnum( int num)", + "filename": "ufuncobject.c", + "nloc": 8, + "complexity": 1, + "token_count": 35, + "parameters": [ + "num" + ], + "start_line": 3016, + "end_line": 3024, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "ufunc_getattr", + "long_name": "ufunc_getattr( PyUFuncObject * self , char * name)", + "filename": "ufuncobject.c", + "nloc": 74, + "complexity": 16, + "token_count": 520, + "parameters": [ + "self", + "name" + ], + "start_line": 3027, + "end_line": 3110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 84, + "top_nesting_level": 0 + }, + { + "name": "ufunc_setattr", + "long_name": "ufunc_setattr( PyUFuncObject * self , char * name , PyObject * v)", + "filename": "ufuncobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "name", + "v" + ], + "start_line": 3115, + "end_line": 3118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "PyUFunc_ff_f_As_dd_d", + "long_name": "PyUFunc_ff_f_As_dd_d( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 146, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 41, + "end_line": 51, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_ff_f", + "long_name": "PyUFunc_ff_f( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 136, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 55, + "end_line": 66, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_dd_d", + "long_name": "PyUFunc_dd_d( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 137, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 70, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_gg_g", + "long_name": "PyUFunc_gg_g( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 11, + "complexity": 2, + "token_count": 137, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 85, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_FF_F_As_DD_D", + "long_name": "PyUFunc_FF_F_As_DD_D( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 225, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 101, + "end_line": 114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_DD_D", + "long_name": "PyUFunc_DD_D( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 219, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 118, + "end_line": 131, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_FF_F", + "long_name": "PyUFunc_FF_F( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 2, + "token_count": 219, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 135, + "end_line": 148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_GG_G", + "long_name": "PyUFunc_GG_G( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 15, + "complexity": 2, + "token_count": 219, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 152, + "end_line": 167, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_OO_O", + "long_name": "PyUFunc_OO_O( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 22, + "complexity": 6, + "token_count": 236, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 171, + "end_line": 193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_f_f_As_d_d", + "long_name": "PyUFunc_f_f_As_d_d( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 106, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 205, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_d_d", + "long_name": "PyUFunc_d_d( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 8, + "complexity": 2, + "token_count": 93, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 216, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_f_f", + "long_name": "PyUFunc_f_f( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 9, + "complexity": 2, + "token_count": 101, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 227, + "end_line": 235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_g_g", + "long_name": "PyUFunc_g_g( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 10, + "complexity": 2, + "token_count": 102, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 239, + "end_line": 248, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_F_F_As_D_D", + "long_name": "PyUFunc_F_F_As_D_D( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 164, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 253, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_F_F", + "long_name": "PyUFunc_F_F( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 150, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 268, + "end_line": 279, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_D_D", + "long_name": "PyUFunc_D_D( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 150, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 284, + "end_line": 295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_G_G", + "long_name": "PyUFunc_G_G( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 2, + "token_count": 150, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 300, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_O_O", + "long_name": "PyUFunc_O_O( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 15, + "complexity": 5, + "token_count": 149, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 315, + "end_line": 330, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_O_O_method", + "long_name": "PyUFunc_O_O_method( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 21, + "complexity": 6, + "token_count": 190, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 334, + "end_line": 356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_On_Om", + "long_name": "PyUFunc_On_Om( char ** args , intp * dimensions , intp * steps , * func)", + "filename": "ufuncobject.c", + "nloc": 47, + "complexity": 11, + "token_count": 357, + "parameters": [ + "args", + "dimensions", + "steps", + "func" + ], + "start_line": 366, + "end_line": 414, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 49, + "top_nesting_level": 0 + }, + { + "name": "_error_handler", + "long_name": "_error_handler( int method , PyObject * errobj , char * errtype , int retstatus)", + "filename": "ufuncobject.c", + "nloc": 41, + "complexity": 8, + "token_count": 211, + "parameters": [ + "method", + "errobj", + "errtype", + "retstatus" + ], + "start_line": 438, + "end_line": 484, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 47, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_checkfperr", + "long_name": "PyUFunc_checkfperr( int errmask , PyObject * errobj)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 60, + "parameters": [ + "errmask", + "errobj" + ], + "start_line": 489, + "end_line": 518, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_clearfperr", + "long_name": "PyUFunc_clearfperr()", + "filename": "ufuncobject.c", + "nloc": 5, + "complexity": 1, + "token_count": 12, + "parameters": [], + "start_line": 524, + "end_line": 529, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "_lowest_type", + "long_name": "_lowest_type( char intype)", + "filename": "ufuncobject.c", + "nloc": 23, + "complexity": 13, + "token_count": 66, + "parameters": [ + "intype" + ], + "start_line": 551, + "end_line": 577, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "_cancoerce", + "long_name": "_cancoerce( char thistype , char neededtype , char scalar)", + "filename": "ufuncobject.c", + "nloc": 21, + "complexity": 9, + "token_count": 101, + "parameters": [ + "thistype", + "neededtype", + "scalar" + ], + "start_line": 583, + "end_line": 604, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "select_types", + "long_name": "select_types( PyUFuncObject * self , int * arg_types , PyUFuncGenericFunction * function , ** data , char * scalars)", + "filename": "ufuncobject.c", + "nloc": 76, + "complexity": 19, + "token_count": 479, + "parameters": [ + "self", + "arg_types", + "function", + "data", + "scalars" + ], + "start_line": 608, + "end_line": 695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_GetPyValues", + "long_name": "PyUFunc_GetPyValues( char * name , int * bufsize , int * errmask , PyObject ** errobj)", + "filename": "ufuncobject.c", + "nloc": 67, + "complexity": 18, + "token_count": 387, + "parameters": [ + "name", + "bufsize", + "errmask", + "errobj" + ], + "start_line": 701, + "end_line": 773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "_scalar_kind", + "long_name": "_scalar_kind( int typenum , PyArrayObject ** arr)", + "filename": "ufuncobject.c", + "nloc": 9, + "complexity": 6, + "token_count": 64, + "parameters": [ + "typenum", + "arr" + ], + "start_line": 777, + "end_line": 785, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "_create_copies", + "long_name": "_create_copies( PyUFuncLoopObject * loop , int * arg_types , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 33, + "complexity": 8, + "token_count": 234, + "parameters": [ + "loop", + "arg_types", + "mps" + ], + "start_line": 794, + "end_line": 832, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 0 + }, + { + "name": "_has_reflected_op", + "long_name": "_has_reflected_op( PyObject * op , char * name)", + "filename": "ufuncobject.c", + "nloc": 17, + "complexity": 1, + "token_count": 93, + "parameters": [ + "op", + "name" + ], + "start_line": 838, + "end_line": 854, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "construct_matrices", + "long_name": "construct_matrices( PyUFuncLoopObject * loop , PyObject * args , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 283, + "complexity": 74, + "token_count": 2197, + "parameters": [ + "loop", + "args", + "mps" + ], + "start_line": 860, + "end_line": 1247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 388, + "top_nesting_level": 0 + }, + { + "name": "ufuncreduce_dealloc", + "long_name": "ufuncreduce_dealloc( PyUFuncReduceObject * self)", + "filename": "ufuncobject.c", + "nloc": 13, + "complexity": 3, + "token_count": 76, + "parameters": [ + "self" + ], + "start_line": 1250, + "end_line": 1262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "ufuncloop_dealloc", + "long_name": "ufuncloop_dealloc( PyUFuncLoopObject * self)", + "filename": "ufuncobject.c", + "nloc": 12, + "complexity": 4, + "token_count": 86, + "parameters": [ + "self" + ], + "start_line": 1265, + "end_line": 1277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "construct_loop", + "long_name": "construct_loop( PyUFuncObject * self , PyObject * args , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 30, + "complexity": 7, + "token_count": 209, + "parameters": [ + "self", + "args", + "mps" + ], + "start_line": 1280, + "end_line": 1317, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_GenericFunction", + "long_name": "PyUFunc_GenericFunction( PyUFuncObject * self , PyObject * args , PyArrayObject ** mps)", + "filename": "ufuncobject.c", + "nloc": 186, + "complexity": 48, + "token_count": 1403, + "parameters": [ + "self", + "args", + "mps" + ], + "start_line": 1389, + "end_line": 1657, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 269, + "top_nesting_level": 0 + }, + { + "name": "_getidentity", + "long_name": "_getidentity( PyUFuncObject * self , int otype , char * str)", + "filename": "ufuncobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 117, + "parameters": [ + "self", + "otype", + "str" + ], + "start_line": 1660, + "end_line": 1681, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "_create_reduce_copy", + "long_name": "_create_reduce_copy( PyUFuncReduceObject * loop , PyArrayObject ** arr , int rtype)", + "filename": "ufuncobject.c", + "nloc": 20, + "complexity": 5, + "token_count": 125, + "parameters": [ + "loop", + "arr", + "rtype" + ], + "start_line": 1684, + "end_line": 1714, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 31, + "top_nesting_level": 0 + }, + { + "name": "construct_reduce", + "long_name": "construct_reduce( PyUFuncObject * self , PyArrayObject ** arr , int axis , int otype , int operation , intp ind_size , char * str)", + "filename": "ufuncobject.c", + "nloc": 172, + "complexity": 37, + "token_count": 1390, + "parameters": [ + "self", + "arr", + "axis", + "otype", + "operation", + "ind_size", + "str" + ], + "start_line": 1717, + "end_line": 1930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 214, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_Reduce", + "long_name": "PyUFunc_Reduce( PyUFuncObject * self , PyArrayObject * arr , int axis , int otype)", + "filename": "ufuncobject.c", + "nloc": 105, + "complexity": 20, + "token_count": 747, + "parameters": [ + "self", + "arr", + "axis", + "otype" + ], + "start_line": 1942, + "end_line": 2077, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 136, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_Accumulate", + "long_name": "PyUFunc_Accumulate( PyUFuncObject * self , PyArrayObject * arr , int axis , int otype)", + "filename": "ufuncobject.c", + "nloc": 109, + "complexity": 20, + "token_count": 779, + "parameters": [ + "self", + "arr", + "axis", + "otype" + ], + "start_line": 2081, + "end_line": 2219, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 139, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_Reduceat", + "long_name": "PyUFunc_Reduceat( PyUFuncObject * self , PyArrayObject * arr , PyArrayObject * ind , int axis , int otype)", + "filename": "ufuncobject.c", + "nloc": 111, + "complexity": 23, + "token_count": 816, + "parameters": [ + "self", + "arr", + "ind", + "axis", + "otype" + ], + "start_line": 2241, + "end_line": 2370, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 130, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_GenericReduction", + "long_name": "PyUFunc_GenericReduction( PyUFuncObject * self , PyObject * args , PyObject * kwds , int operation)", + "filename": "ufuncobject.c", + "nloc": 114, + "complexity": 30, + "token_count": 709, + "parameters": [ + "self", + "args", + "kwds", + "operation" + ], + "start_line": 2379, + "end_line": 2507, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 129, + "top_nesting_level": 0 + }, + { + "name": "_find_array_wrap", + "long_name": "_find_array_wrap( PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 50, + "complexity": 12, + "token_count": 265, + "parameters": [ + "args" + ], + "start_line": 2514, + "end_line": 2567, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "ufunc_generic_call", + "long_name": "ufunc_generic_call( PyUFuncObject * self , PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 53, + "complexity": 13, + "token_count": 380, + "parameters": [ + "self", + "args" + ], + "start_line": 2570, + "end_line": 2642, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 0 + }, + { + "name": "ufunc_update_use_defaults", + "long_name": "ufunc_update_use_defaults( PyObject * dummy , PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 15, + "complexity": 6, + "token_count": 100, + "parameters": [ + "dummy", + "args" + ], + "start_line": 2645, + "end_line": 2663, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "ufunc_frompyfunc", + "long_name": "ufunc_frompyfunc( PyObject * dummy , PyObject * args , PyObject * kwds)", + "filename": "ufuncobject.c", + "nloc": 59, + "complexity": 10, + "token_count": 528, + "parameters": [ + "dummy", + "args", + "kwds" + ], + "start_line": 2671, + "end_line": 2760, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 90, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_FromFuncAndData", + "long_name": "PyUFunc_FromFuncAndData( PyUFuncGenericFunction * func , ** data , char * types , int ntypes , int nin , int nout , int identity , char * name , char * doc , int check_return)", + "filename": "ufuncobject.c", + "nloc": 27, + "complexity": 4, + "token_count": 193, + "parameters": [ + "func", + "data", + "types", + "ntypes", + "nin", + "nout", + "identity", + "name", + "doc", + "check_return" + ], + "start_line": 2765, + "end_line": 2797, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 0 + }, + { + "name": "PyUFunc_RegisterLoopForType", + "long_name": "PyUFunc_RegisterLoopForType( PyUFuncObject * ufunc , int usertype , PyUFuncGenericFunction function , * data)", + "filename": "ufuncobject.c", + "nloc": 43, + "complexity": 8, + "token_count": 251, + "parameters": [ + "ufunc", + "usertype", + "function", + "data" + ], + "start_line": 2801, + "end_line": 2845, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 45, + "top_nesting_level": 0 + }, + { + "name": "ufunc_dealloc", + "long_name": "ufunc_dealloc( PyUFuncObject * self)", + "filename": "ufuncobject.c", + "nloc": 7, + "complexity": 2, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 2848, + "end_line": 2854, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "ufunc_repr", + "long_name": "ufunc_repr( PyUFuncObject * self)", + "filename": "ufuncobject.c", + "nloc": 6, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self" + ], + "start_line": 2857, + "end_line": 2864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ufunc_outer", + "long_name": "ufunc_outer( PyUFuncObject * self , PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 59, + "complexity": 13, + "token_count": 428, + "parameters": [ + "self", + "args" + ], + "start_line": 2876, + "end_line": 2945, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 70, + "top_nesting_level": 0 + }, + { + "name": "ufunc_reduce", + "long_name": "ufunc_reduce( PyUFuncObject * self , PyObject * args , PyObject * kwds)", + "filename": "ufuncobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 2949, + "end_line": 2953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "ufunc_accumulate", + "long_name": "ufunc_accumulate( PyUFuncObject * self , PyObject * args , PyObject * kwds)", + "filename": "ufuncobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 2956, + "end_line": 2960, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "ufunc_reduceat", + "long_name": "ufunc_reduceat( PyUFuncObject * self , PyObject * args , PyObject * kwds)", + "filename": "ufuncobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 2963, + "end_line": 2966, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "_makeargs", + "long_name": "_makeargs( int num , char ltr , char * str)", + "filename": "ufuncobject.c", + "nloc": 20, + "complexity": 3, + "token_count": 117, + "parameters": [ + "num", + "ltr", + "str" + ], + "start_line": 2986, + "end_line": 3008, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "_typecharfromnum", + "long_name": "_typecharfromnum( int num)", + "filename": "ufuncobject.c", + "nloc": 8, + "complexity": 1, + "token_count": 35, + "parameters": [ + "num" + ], + "start_line": 3011, + "end_line": 3019, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "ufunc_getattr", + "long_name": "ufunc_getattr( PyUFuncObject * self , char * name)", + "filename": "ufuncobject.c", + "nloc": 74, + "complexity": 16, + "token_count": 520, + "parameters": [ + "self", + "name" + ], + "start_line": 3022, + "end_line": 3105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 84, + "top_nesting_level": 0 + }, + { + "name": "ufunc_setattr", + "long_name": "ufunc_setattr( PyUFuncObject * self , char * name , PyObject * v)", + "filename": "ufuncobject.c", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "name", + "v" + ], + "start_line": 3110, + "end_line": 3113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "_find_array_wrap", + "long_name": "_find_array_wrap( PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 51, + "complexity": 12, + "token_count": 279, + "parameters": [ + "args" + ], + "start_line": 2514, + "end_line": 2567, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 54, + "top_nesting_level": 0 + }, + { + "name": "ufunc_generic_call", + "long_name": "ufunc_generic_call( PyUFuncObject * self , PyObject * args)", + "filename": "ufuncobject.c", + "nloc": 58, + "complexity": 14, + "token_count": 415, + "parameters": [ + "self", + "args" + ], + "start_line": 2570, + "end_line": 2647, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 78, + "top_nesting_level": 0 + } + ], + "nloc": 2314, + "complexity": 514, + "token_count": 17263, + "diff_parsed": { + "added": [ + "\tPyObject *attr, *wrap;", + "\t\twrap = PyObject_GetAttrString(obj, \"__array_wrap__\");", + "\t\tif (wrap != NULL) {", + "\t\t\tif (PyCallable_Check(wrap)) {", + "\t\t\t\twith_wrap[np] = wrap;", + "\twrap = with_wrap[0];", + "\tfor (i=1; i b\"\n def __init__(self, y1, y2):\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n self.y1 = y1\n self.y2 = y2\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.logical_or(umath.greater (x, self.y2),\n umath.less(x, self.y1)\n )\n\nclass domain_tan:\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n def __init__(self, eps):\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n self.eps = eps\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less(umath.absolute(umath.cos(x)), self.eps)\n\nclass domain_greater:\n \"domain_greater(v)(x) = true where x <= v\"\n def __init__(self, critical_value):\n \"domain_greater(v)(x) = true where x <= v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less_equal (x, self.critical_value)\n\nclass domain_greater_equal:\n \"domain_greater_equal(v)(x) = true where x < v\"\n def __init__(self, critical_value):\n \"domain_greater_equal(v)(x) = true where x < v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less (x, self.critical_value)\n\nclass masked_unary_operation:\n def __init__ (self, aufunc, fill=0, domain=None):\n \"\"\" masked_unary_operation(aufunc, fill=0, domain=None)\n aufunc(fill) must be defined\n self(x) returns aufunc(x)\n with masked values where domain(x) is true or getmask(x) is true.\n \"\"\"\n self.f = aufunc\n self.fill = fill\n self.domain = domain\n self.__doc__ = getattr(aufunc, \"__doc__\", str(aufunc))\n ufunc_domain[aufunc] = domain\n ufunc_fills[aufunc] = fill,\n \n def __call__ (self, a, *args, **kwargs):\n \"Execute the call behavior.\"\n# numeric tries to return scalars rather than arrays when given scalars.\n m = getmask(a)\n d1 = filled(a, self.fill)\n if self.domain is not None:\n m = mask_or(m, self.domain(d1))\n result = self.f(d1, *args, **kwargs)\n if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\n\nclass domain_safe_divide:\n def __init__ (self, tolerance=divide_tolerance):\n self.tolerance = tolerance\n def __call__ (self, a, b):\n return umath.absolute(a) * self.tolerance >= umath.absolute(b)\n\nclass domained_binary_operation:\n \"\"\"Binary operations that have a domain, like divide. These are complicated so they\n are a separate class. They have no reduce, outer or accumulate.\n \"\"\"\n def __init__ (self, abfunc, domain, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.domain = domain\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n ufunc_domain[abfunc] = domain\n ufunc_fills[abfunc] = fillx,filly\n\n def __call__(self, a, b):\n \"Execute the call behavior.\"\n ma = getmask(a)\n mb = getmask(b)\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n t = self.domain(d1, d2)\n\n if oldnumeric.sometrue(t, None):\n d2 = where(t, self.filly, d2)\n mb = mask_or(mb, t)\n m = mask_or(ma, mb)\n result = self.f(d1, d2)\n if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n \n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nclass masked_binary_operation:\n def __init__ (self, abfunc, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n ufunc_domain[abfunc] = None\n ufunc_fills[abfunc] = fillx,filly\n\n def __call__ (self, a, b, *args, **kwargs):\n \"Execute the call behavior.\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n result = self.f(d1, d2, *args, **kwargs)\n if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis with this function.\"\"\"\n m = getmask(target)\n t = filled(target, self.filly)\n if t.shape == ():\n t = t.reshape(1)\n if m is not nomask:\n m = make_mask(m, copy=1)\n m.shape = (1,)\n if m is nomask:\n return masked_array (self.f.reduce (t, axis))\n else:\n t = masked_array (t, m)\n t = self.f.reduce(filled(t, self.filly), axis)\n m = umath.logical_and.reduce(m, axis)\n if isinstance(t, ndarray):\n return masked_array(t, m, get_fill_value(target))\n elif m:\n return masked\n else:\n return t\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = self.f.outer(filled(a, self.fillx), filled(b, self.filly))\n return masked_array(d, m)\n\n def accumulate (self, target, axis=0):\n \"\"\"Accumulate target along axis after filling with y fill value.\"\"\"\n t = filled(target, self.filly)\n return masked_array (self.f.accumulate (t, axis))\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nsqrt = masked_unary_operation(umath.sqrt, 0.0, domain_greater_equal(0.0))\nlog = masked_unary_operation(umath.log, 1.0, domain_greater(0.0))\nlog10 = masked_unary_operation(umath.log10, 1.0, domain_greater(0.0))\nexp = masked_unary_operation(umath.exp)\nconjugate = masked_unary_operation(umath.conjugate)\nsin = masked_unary_operation(umath.sin)\ncos = masked_unary_operation(umath.cos)\ntan = masked_unary_operation(umath.tan, 0.0, domain_tan(1.e-35))\narcsin = masked_unary_operation(umath.arcsin, 0.0, domain_check_interval(-1.0, 1.0))\narccos = masked_unary_operation(umath.arccos, 0.0, domain_check_interval(-1.0, 1.0))\narctan = masked_unary_operation(umath.arctan)\n# Missing from numeric\narcsinh = masked_unary_operation(umath.arcsinh)\narccosh = masked_unary_operation(umath.arccosh)\narctanh = masked_unary_operation(umath.arctanh)\nsinh = masked_unary_operation(umath.sinh)\ncosh = masked_unary_operation(umath.cosh)\ntanh = masked_unary_operation(umath.tanh)\nabsolute = masked_unary_operation(umath.absolute)\nfabs = masked_unary_operation(umath.fabs)\nnegative = masked_unary_operation(umath.negative)\nnonzero = masked_unary_operation(oldnumeric.nonzero)\naround = masked_unary_operation(oldnumeric.round_)\nfloor = masked_unary_operation(umath.floor)\nceil = masked_unary_operation(umath.ceil)\nsometrue = masked_unary_operation(oldnumeric.sometrue)\nalltrue = masked_unary_operation(oldnumeric.alltrue, 1)\nlogical_not = masked_unary_operation(umath.logical_not)\n\nadd = masked_binary_operation(umath.add)\nsubtract = masked_binary_operation(umath.subtract)\nsubtract.reduce = None\nmultiply = masked_binary_operation(umath.multiply, 1, 1)\ndivide = domained_binary_operation(umath.divide, domain_safe_divide(), 0, 1)\ntrue_divide = domained_binary_operation(umath.true_divide, domain_safe_divide(), 0, 1)\nfloor_divide = domained_binary_operation(umath.floor_divide, domain_safe_divide(), 0, 1)\nremainder = domained_binary_operation(umath.remainder, domain_safe_divide(), 0, 1)\nfmod = domained_binary_operation(umath.fmod, domain_safe_divide(), 0, 1)\nhypot = masked_binary_operation(umath.hypot)\narctan2 = masked_binary_operation(umath.arctan2, 0.0, 1.0)\narctan2.reduce = None\nequal = masked_binary_operation(umath.equal)\nequal.reduce = None\nnot_equal = masked_binary_operation(umath.not_equal)\nnot_equal.reduce = None\nless_equal = masked_binary_operation(umath.less_equal)\nless_equal.reduce = None\ngreater_equal = masked_binary_operation(umath.greater_equal)\ngreater_equal.reduce = None\nless = masked_binary_operation(umath.less)\nless.reduce = None\ngreater = masked_binary_operation(umath.greater)\ngreater.reduce = None\nlogical_and = masked_binary_operation(umath.logical_and)\nlogical_or = masked_binary_operation(umath.logical_or)\nlogical_xor = masked_binary_operation(umath.logical_xor)\nbitwise_and = masked_binary_operation(umath.bitwise_and)\nbitwise_or = masked_binary_operation(umath.bitwise_or)\nbitwise_xor = masked_binary_operation(umath.bitwise_xor)\n\ndef rank (object):\n return oldnumeric.rank(filled(object))\n\ndef shape (object):\n return oldnumeric.shape(filled(object))\n\ndef size (object, axis=None):\n return oldnumeric.size(filled(object), axis)\n\nclass MaskedArray (object):\n \"\"\"Arrays with possibly masked values.\n Masked values of 1 exclude the corresponding element from \n any computation.\n\n Construction:\n x = array(data, dtype=None, copy=True, fortran=False,\n mask = nomask, fill_value=None)\n\n If copy=False, every effort is made not to copy the data:\n If data is a MaskedArray, and argument mask=nomask,\n then the candidate data is data.data and the\n mask used is data.mask. If data is a numeric array,\n it is used as the candidate raw data.\n If dtypechar is not None and\n is != data.dtypechar then a data copy is required.\n Otherwise, the candidate is used.\n\n If a data copy is required, raw data stored is the result of:\n numeric.array(data, dtype=dtypechar, copy=copy)\n\n If mask is nomask there are no masked values. Otherwise mask must\n be convertible to an array of booleans with the same shape as x.\n\n fill_value is used to fill in masked values when necessary,\n such as when printing and in method/function filled().\n The fill_value is not used for computation within this module.\n \"\"\"\n __array_priority__ = 10.1\n def __init__(self, data, dtype=None, copy=True, fortran=False, \n mask=nomask, fill_value=None):\n \"\"\"array(data, dtype=None, copy=True, fortran=False, mask=nomask, fill_value=None)\n If data already a numeric array, its dtype becomes the default value of dtype.\n \"\"\"\n tc = dtype\n need_data_copied = copy\n if isinstance(data, MaskedArray):\n c = data.data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n if mask is nomask:\n mask = data.mask\n elif mask is not nomask: #attempting to change the mask\n need_data_copied = True\n\n elif isinstance(data, ndarray):\n c = data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n else:\n need_data_copied = False #because I'll do it now\n c = numeric.array(data, dtype=tc, copy=True, fortran=fortran)\n\n if need_data_copied:\n if tc == ctc:\n self._data = numeric.array(c, dtype=tc, copy=True, fortran=fortran)\n else:\n self._data = c.astype(tc)\n else:\n self._data = c\n\n if mask is nomask:\n self._mask = nomask\n self._shared_mask = 0\n else:\n self._mask = make_mask (mask)\n if self._mask is nomask:\n self._shared_mask = 0\n else:\n self._shared_mask = (self._mask is mask)\n nm = size(self._mask)\n nd = size(self._data)\n if nm != nd:\n if nm == 1:\n self._mask = oldnumeric.resize(self._mask, self._data.shape)\n self._shared_mask = 0\n elif nd == 1:\n self._data = oldnumeric.resize(self._data, self._mask.shape)\n self._data.shape = self._mask.shape\n else:\n raise MAError, \"Mask and data not compatible.\"\n elif nm == 1 and shape(self._mask) != shape(self._data):\n self.unshare_mask()\n self._mask.shape = self._data.shape\n\n self.set_fill_value(fill_value)\n\n def __array__ (self, t = None):\n \"Special hook for numeric. Converts to numeric if possible.\"\n if self._mask is not nomask:\n if oldnumeric.ravel(self._mask).any():\n raise MAError, \\\n \"\"\"Cannot automatically convert masked array to numeric because data\n is masked in one or more locations.\n \"\"\"\n else: # Mask is all false\n # Optimize to avoid future invocations of this section.\n self._mask = nomask\n self._shared_mask = 0\n if t:\n return self._data.astype(t)\n else:\n return self._data\n\n def __array_wrap__ (self, array, context):\n \"\"\"Special hook for ufuncs.\n\n Wraps the numpy array and sets the mask according to\n context.\n \"\"\"\n func, args = context[:2]\n domain = ufunc_domain[func]\n fills = ufunc_fills[func]\n m = reduce(mask_or, [getmask(a) for a in args])\n if domain is not None:\n m = mask_or(m, domain(*[filled(a,f) for (a,f)\n in zip(args, fills)]))\n if m is not nomask:\n try:\n shape = array.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = reduce(mask_or, [getmaskarray(a) for a in args])\n \n return MaskedArray(array, copy=False, mask=m)\n \n def _get_shape(self):\n \"Return the current shape.\"\n return self._data.shape\n\n def _set_shape (self, newshape):\n \"Set the array's shape.\"\n self._data.shape = newshape\n if self._mask is not nomask:\n self._mask = self._mask.copy()\n self._mask.shape = newshape\n\n def _get_flat(self):\n \"\"\"Calculate the flat value.\n \"\"\"\n if self._mask is nomask:\n return masked_array(self._data.ravel(), mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.ravel(),\n mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_flat (self, value):\n \"x.flat = value\"\n y = self.ravel()\n y[:] = value\n\n def _get_real(self):\n \"Get the real part of a complex array.\"\n if self._mask is nomask:\n return masked_array(self._data.real, mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.real, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_real (self, value):\n \"x.real = value\"\n y = self.real\n y[...] = value\n\n def _get_imaginary(self):\n \"Get the imaginary part of a complex array.\"\n if self._mask is nomask:\n return masked_array(self._data.imag, mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.imag, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_imaginary (self, value):\n \"x.imaginary = value\"\n y = self.imaginary\n y[...] = value\n\n def __str__(self):\n \"\"\"Calculate the str representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n if masked_print_option.enabled():\n f = masked_print_option\n # XXX: Without the following special case masked\n # XXX: would print as \"[--]\", not \"--\". Can we avoid\n # XXX: checks for masked by choosing a different value\n # XXX: for the masked singleton? 2005-01-05 -- sasha\n if self is masked:\n return str(f)\n m = self._mask\n if m is not nomask and m.shape == () and m:\n return str(f)\n # convert to object array to make filled work\n self = self.astype(object)\n else:\n f = self.fill_value()\n res = self.filled(f)\n return str(res)\n\n def __repr__(self):\n \"\"\"Calculate the repr representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n with_mask = \"\"\"\\\narray(data =\n %(data)s,\n mask =\n %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n with_mask1 = \"\"\"\\\narray(data = %(data)s,\n mask = %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n without_mask = \"\"\"array(\n %(data)s)\"\"\"\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n\n n = len(self.shape)\n if self._mask is nomask:\n if n <=1:\n return without_mask1 % {'data':str(self.filled())}\n return without_mask % {'data':str(self.filled())}\n else:\n if n <=1:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n if self._mask is nomask:\n return without_mask % {'data':str(self.filled())}\n else:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n\n def __float__(self):\n \"Convert self to float.\"\n self.unmask()\n if self._mask is not nomask:\n raise MAError, 'Cannot convert masked element to a Python float.'\n return float(self.data.item())\n\n def __int__(self):\n \"Convert self to int.\"\n self.unmask()\n if self._mask is not nomask:\n raise MAError, 'Cannot convert masked element to a Python int.'\n return int(self.data.item())\n\n def __getitem__(self, i):\n \"Get item described by i. Not a copy as in previous versions.\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i]\n if m is nomask:\n return dout\n mi = m[i]\n if mi.size == 1:\n if mi: \n return masked\n else:\n return dout\n else:\n return masked_array(dout, mi, fill_value=self._fill_value)\n\n def __getslice__(self, i, j):\n \"Get slice described by i, j\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i:j]\n if m is nomask:\n return masked_array(dout, fill_value=self._fill_value)\n else:\n return masked_array(dout, mask = m[i:j], fill_value=self._fill_value)\n\n# --------\n# setitem and setslice notes\n# note that if value is masked, it means to mask those locations.\n# setting a value changes the mask to match the value in those locations.\n\n def __setitem__(self, index, value):\n \"Set item described by index. If value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, 'Cannot alter the masked element.'\n if value is masked:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n else:\n self.unshare_mask()\n self._mask[index] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[index] = value\n if m is nomask:\n if self._mask is not nomask:\n self.unshare_mask()\n self._mask[index] = False\n else:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = True\n else:\n self.unshare_mask()\n self._mask[index] = m\n\n def __setslice__(self, i, j, value):\n \"Set slice i:j; if value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, \"Cannot alter the 'masked' object.\"\n if value is masked:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n self._mask[i:j] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[i:j] = value\n if m is nomask:\n if self._mask is not nomask:\n self.unshare_mask()\n self._mask[i:j] = False\n else:\n if self._mask is nomask:\n self._mask = make_mask_none(self._data.shape)\n self._shared_mask = False\n self._mask[i:j] = m\n\n def __nonzero__(self):\n \"\"\"returns true if any element is non-zero or masked\n\n \"\"\"\n # XXX: This changes bool conversion logic from MA.\n # XXX: In MA bool(a) == len(a) != 0, but in numpy\n # XXX: scalars do not have len \n m = self._mask\n d = self._data\n return bool(m is not nomask and m.any()\n or d is not nomask and d.any())\n \n def __len__ (self):\n \"\"\"Return length of first dimension. This is weird but Python's\n slicing behavior depends on it.\"\"\"\n return len(self._data)\n\n def __and__(self, other):\n \"Return bitwise_and\"\n return bitwise_and(self, other)\n\n def __or__(self, other):\n \"Return bitwise_or\"\n return bitwise_or(self, other)\n\n def __xor__(self, other):\n \"Return bitwise_xor\"\n return bitwise_xor(self, other)\n\n __rand__ = __and__\n __ror__ = __or__\n __rxor__ = __xor__\n\n def __abs__(self):\n \"Return absolute(self)\"\n return absolute(self)\n\n def __neg__(self):\n \"Return negative(self)\"\n return negative(self)\n\n def __pos__(self):\n \"Return array(self)\"\n return array(self)\n\n def __add__(self, other):\n \"Return add(self, other)\"\n return add(self, other)\n\n __radd__ = __add__\n\n def __mod__ (self, other):\n \"Return remainder(self, other)\"\n return remainder(self, other)\n\n def __rmod__ (self, other):\n \"Return remainder(other, self)\"\n return remainder(other, self)\n\n def __lshift__ (self, n):\n return left_shift(self, n)\n\n def __rshift__ (self, n):\n return right_shift(self, n)\n\n def __sub__(self, other):\n \"Return subtract(self, other)\"\n return subtract(self, other)\n\n def __rsub__(self, other):\n \"Return subtract(other, self)\"\n return subtract(other, self)\n\n def __mul__(self, other):\n \"Return multiply(self, other)\"\n return multiply(self, other)\n\n __rmul__ = __mul__\n\n def __div__(self, other):\n \"Return divide(self, other)\"\n return divide(self, other)\n\n def __rdiv__(self, other):\n \"Return divide(other, self)\"\n return divide(other, self)\n\n def __truediv__(self, other):\n \"Return divide(self, other)\"\n return true_divide(self, other)\n\n def __rtruediv__(self, other):\n \"Return divide(other, self)\"\n return true_divide(other, self)\n\n def __floordiv__(self, other):\n \"Return divide(self, other)\"\n return floor_divide(self, other)\n\n def __rfloordiv__(self, other):\n \"Return divide(other, self)\"\n return floor_divide(other, self)\n\n def __pow__(self,other, third=None):\n \"Return power(self, other, third)\"\n return power(self, other, third)\n\n def __sqrt__(self):\n \"Return sqrt(self)\"\n return sqrt(self)\n\n def __iadd__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data += f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = add(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __imul__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data *= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = multiply(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __isub__(self, other):\n \"Subtract other from self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data -= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = subtract(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n\n\n def __idiv__(self, other):\n \"Divide self by other in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n mo = getmask(other)\n result = divide(self, masked_array(f, mask=mo))\n self._data = result.data\n dm = result.raw_mask()\n if dm is not self._mask:\n self._mask = dm\n self._shared_mask = 1\n return self\n\n def __eq__(self,other):\n return equal(self,other)\n\n def __ne__(self,other):\n return not_equal(self,other)\n\n def __lt__(self,other):\n return less(self,other)\n\n def __le__(self,other):\n return less_equal(self,other)\n\n def __gt__(self,other):\n return greater(self,other)\n\n def __ge__(self,other):\n return greater_equal(self,other)\n\n def astype (self, tc):\n \"return self as array of given type.\"\n d = self._data.astype(tc)\n return array(d, mask=self._mask)\n\n def byte_swapped(self):\n \"\"\"Returns the raw data field, byte_swapped. Included for consistency\n with numeric but doesn't make sense in this context.\n \"\"\"\n return self._data.byte_swapped()\n\n def compressed (self):\n \"A 1-D array of all the non-masked data.\"\n d = oldnumeric.ravel(self._data)\n if self._mask is nomask:\n return array(d)\n else:\n m = 1 - oldnumeric.ravel(self._mask)\n c = oldnumeric.compress(m, d)\n return array(c, copy=0)\n\n def count (self, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n m = self._mask\n s = self._data.shape\n ls = len(s)\n if m is nomask:\n if ls == 0:\n return 1\n if ls == 1:\n return s[0]\n if axis is None:\n return reduce(lambda x,y:x*y, s)\n else:\n n = s[axis]\n t = list(s)\n del t[axis]\n return ones(t) * n\n if axis is None:\n w = oldnumeric.ravel(m).astype(int) \n n1 = size(w)\n if n1 == 1:\n n2 = w[0]\n else:\n n2 = umath.add.reduce(w)\n return n1 - n2\n else:\n n1 = size(m, axis)\n n2 = sum(m.astype(int), axis)\n return n1 - n2\n\n def dot (self, other):\n \"s.dot(other) = innerproduct(s, other)\"\n return innerproduct(self, other)\n\n def fill_value(self):\n \"Get the current fill value.\"\n return self._fill_value\n\n def filled (self, fill_value=None):\n \"\"\"A numeric array with masked values filled. If fill_value is None,\n use self.fill_value().\n\n If mask is nomask, copy data only if not contiguous.\n Result is always a contiguous, numeric array.\n# Is contiguous really necessary now?\n \"\"\"\n d = self._data\n m = self._mask\n if m is nomask:\n if d.flags['CONTIGUOUS']:\n return d\n else:\n return d.copy()\n else:\n if fill_value is None:\n value = self._fill_value\n else:\n value = fill_value\n\n if self is masked:\n result = numeric.array(value).reshape(*d.shape)\n else:\n try:\n result = numeric.array(d, dtype=d.dtype, copy=1)\n result[m] = value\n except (TypeError, AttributeError):\n #ok, can't put that value in here\n value = numeric.array(value, dtype=object)\n d = d.astype(object)\n result = oldnumeric.choose(m, (d, value))\n except IndexError:\n #ok, if scalar\n if d.shape:\n raise\n elif m:\n result = numeric.array(value, dtype=d.dtype)\n else:\n result = d\n return result\n\n def ids (self):\n \"\"\"Return the ids of the data and mask areas\"\"\"\n return (id(self._data), id(self._mask))\n\n def iscontiguous (self):\n \"Is the data contiguous?\"\n return self._data.flags['CONTIGUOUS']\n\n def itemsize(self):\n \"Item size of each data item.\"\n return self._data.itemsize\n\n\n def outer(self, other):\n \"s.outer(other) = outerproduct(s, other)\"\n return outerproduct(self, other)\n\n def put (self, values):\n \"\"\"Set the non-masked entries of self to filled(values).\n No change to mask\n \"\"\"\n iota = numeric.arange(self.size)\n d = self._data\n if self._mask is nomask:\n ind = iota\n else:\n ind = oldnumeric.compress(1 - self._mask, iota)\n d[ind] = filled(values).astype(d.dtype)\n\n def putmask (self, values):\n \"\"\"Set the masked entries of self to filled(values).\n Mask changed to nomask.\n \"\"\"\n d = self._data\n if self._mask is not nomask:\n d[self._mask] = filled(values).astype(d.dtype)\n self._shared_mask = 0\n self._mask = nomask\n\n def ravel (self):\n \"\"\"Return a 1-D view of self.\"\"\"\n if self._mask is nomask:\n return masked_array(self._data.ravel())\n else:\n return masked_array(self._data.ravel(), self._mask.ravel())\n\n def raw_data (self):\n \"\"\" Obsolete; use data property instead.\n The raw data; portions may be meaningless.\n May be noncontiguous. Expert use only.\"\"\"\n return self._data\n data = property(fget=raw_data, \n doc=\"The data, but values at masked locations are meaningless.\")\n\n def raw_mask (self):\n \"\"\" Obsolete; use mask property instead.\n May be noncontiguous. Expert use only.\n \"\"\"\n return self._mask\n mask = property(fget=raw_mask, \n doc=\"The mask, may be nomask. Values where mask true are meaningless.\")\n\n def reshape (self, *s):\n \"\"\"This array reshaped to shape s\"\"\"\n d = self._data.reshape(*s)\n if self._mask is nomask:\n return masked_array(d)\n else:\n m = self._mask.reshape(*s)\n return masked_array(d, m)\n\n def set_fill_value (self, v=None):\n \"Set the fill value to v. Omit v to restore default.\"\n if v is None:\n v = default_fill_value (self.raw_data())\n self._fill_value = v\n\n def _get_size (self):\n return self._data.size\n size = property(fget=_get_size, doc=\"Number of elements in the array.\")\n## CHECK THIS: signature of numeric.array.size?\n \n def _get_dtypechar(self):\n return self._data.dtypechar\n dtypechar = property(fget=_get_dtypechar, doc=\"type character of the array.\")\n\n def _get_dtype(self):\n return self._data.dtype\n dtype = property(fget=_get_dtype, doc=\"type of the array elements.\")\n\n def item(self):\n \"Return Python scalar if possible.\"\n if self._mask is not nomask:\n m = oldnumeric.ravel(self._mask)\n try:\n if m[0]:\n return masked\n except IndexError:\n return masked\n return self._data.item()\n\n def tolist(self, fill_value=None):\n \"Convert to list\"\n return self.filled(fill_value).tolist()\n\n def tostring(self, fill_value=None):\n \"Convert to string\"\n return self.filled(fill_value).tostring()\n\n def unmask (self):\n \"Replace the mask by nomask if possible.\"\n if self._mask is nomask: return\n m = make_mask(self._mask, flag=1)\n if m is nomask:\n self._mask = nomask\n self._shared_mask = 0\n\n def unshare_mask (self):\n \"If currently sharing mask, make a copy.\"\n if self._shared_mask:\n self._mask = make_mask (self._mask, copy=1, flag=0)\n self._shared_mask = 0\n\n shape = property(_get_shape, _set_shape,\n doc = 'tuple giving the shape of the array')\n\n flat = property(_get_flat, _set_flat,\n doc = 'Access array in flat form.')\n\n real = property(_get_real, _set_real,\n doc = 'Access the real part of the array')\n\n imaginary = property(_get_imaginary, _set_imaginary,\n doc = 'Access the imaginary part of the array')\n\n imag = imaginary\n\n#end class MaskedArray\n\narray = MaskedArray\n\ndef isMaskedArray (x):\n \"Is x a masked array, that is, an instance of MaskedArray?\"\n return isinstance(x, MaskedArray)\n\nisarray = isMaskedArray\nisMA = isMaskedArray #backward compatibility\n\ndef allclose (a, b, fill_value=1, rtol=1.e-5, atol=1.e-8):\n \"\"\" Returns true if all components of a and b are equal\n subject to given tolerances.\n If fill_value is 1, masked values considered equal.\n If fill_value is 0, masked values considered unequal.\n The relative error rtol should be positive and << 1.0\n The absolute error atol comes into play for those elements\n of b that are very small or zero; it says how small a must be also.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a)\n d2 = filled(b)\n x = filled(array(d1, copy=0, mask=m), fill_value).astype(float)\n y = filled(array(d2, copy=0, mask=m), 1).astype(float)\n d = umath.less_equal(umath.absolute(x-y), atol + rtol * umath.absolute(y))\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n\ndef allequal (a, b, fill_value=1):\n \"\"\"\n True if all entries of a and b are equal, using\n fill_value as a truth value where either or both are masked.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n if m is nomask:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n elif fill_value:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n dm = array(d, mask=m, copy=0)\n return oldnumeric.alltrue(oldnumeric.ravel(filled(dm, 1)))\n else:\n return 0\n\ndef masked_values (data, value, rtol=1.e-5, atol=1.e-8, copy=1):\n \"\"\"\n masked_values(data, value, rtol=1.e-5, atol=1.e-8)\n Create a masked array; mask is nomask if possible.\n If copy==0, and otherwise possible, result\n may share data values with original array.\n Let d = filled(data, value). Returns d\n masked where abs(data-value)<= atol + rtol * abs(value)\n if d is of a floating point type. Otherwise returns\n masked_object(d, value, copy)\n \"\"\"\n abs = umath.absolute\n d = filled(data, value)\n if issubclass(d.dtype, numeric.floating):\n m = umath.less_equal(abs(d-value), atol+rtol*abs(value))\n m = make_mask(m, flag=1)\n return array(d, mask = m, copy=copy,\n fill_value=value)\n else:\n return masked_object(d, value, copy=copy)\n\ndef masked_object (data, value, copy=1):\n \"Create array masked where exactly data equal to value\"\n d = filled(data, value)\n dm = make_mask(umath.equal(d, value), flag=1)\n return array(d, mask=dm, copy=copy, fill_value=value)\n\ndef arrayrange(start, stop=None, step=1, dtype=None):\n \"\"\"Just like range() except it returns a array whose type can be specified\n by the keyword argument dtypechar.\n \"\"\"\n return array(numeric.arrayrange(start, stop, step, dtype))\n\narange = arrayrange\n\ndef fromstring (s, t):\n \"Construct a masked array from a string. Result will have no mask.\"\n return masked_array(numeric.fromstring(s, t))\n\ndef left_shift (a, n):\n \"Left shift n bits\"\n m = getmask(a)\n if m is nomask:\n d = umath.left_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.left_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef right_shift (a, n):\n \"Right shift n bits\"\n m = getmask(a)\n if m is nomask:\n d = umath.right_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.right_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef resize (a, new_shape):\n \"\"\"resize(a, new_shape) returns a new array with the specified shape.\n The original array's total size can be any size.\"\"\"\n m = getmask(a)\n if m is not nomask:\n m = oldnumeric.resize(m, new_shape)\n result = array(oldnumeric.resize(filled(a), new_shape), mask=m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n \"\"\"\n af = filled(a)\n if isinstance(repeats, types.IntType):\n repeats = tuple([repeats]*(shape(af)[axis]))\n\n m = getmask(a)\n if m is not nomask:\n m = oldnumeric.repeat(m, repeats, axis)\n d = oldnumeric.repeat(af, repeats, axis)\n result = masked_array(d, m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef identity(n):\n \"\"\"identity(n) returns the identity matrix of shape n x n.\n \"\"\"\n return array(numeric.identity(n))\n\ndef indices (dimensions, dtype=None):\n \"\"\"indices(dimensions,dtype=None) returns an array representing a grid\n of indices with row-only, and column-only variation.\n \"\"\"\n return array(numeric.indices(dimensions, dtype))\n\ndef zeros (shape, dtype=int):\n \"\"\"zeros(n, dtype=int) =\n an array of all zeros of the given length or shape.\"\"\"\n return array(numeric.zeros(shape, dtype))\n\ndef ones (shape, dtype=int):\n \"\"\"ones(n, dtype=int) =\n an array of all ones of the given length or shape.\"\"\"\n return array(numeric.ones(shape, dtype))\n\n\ndef count (a, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n a = masked_array(a)\n return a.count(axis)\n\ndef power (a, b, third=None):\n \"a**b\"\n if third is not None:\n raise MAError, \"3-argument power not supported.\"\n ma = getmask(a)\n mb = getmask(b)\n m = mask_or(ma, mb)\n fa = filled(a, 1)\n fb = filled(b, 1)\n if fb.dtypechar in typecodes[\"Integer\"]:\n return masked_array(umath.power(fa, fb), m)\n md = make_mask(umath.less_equal (fa, 0), flag=1)\n m = mask_or(m, md)\n if m is nomask:\n return masked_array(umath.power(fa, fb))\n else:\n fa = numeric.where(m, 1, fa)\n return masked_array(umath.power(fa, fb), m)\n\ndef masked_array (a, mask=nomask, fill_value=None):\n \"\"\"masked_array(a, mask=nomask) =\n array(a, mask=mask, copy=0, fill_value=fill_value)\n \"\"\"\n return array(a, mask=mask, copy=0, fill_value=fill_value)\n\nsum = add.reduce\nproduct = multiply.reduce\n\ndef average (a, axis=0, weights=None, returned = 0):\n \"\"\"average(a, axis=0, weights=None)\n Computes average along indicated axis.\n If axis is None, average over the entire array\n Inputs can be integer or floating types; result is of type float.\n\n If weights are given, result is sum(a*weights)/(sum(weights)*1.0)\n weights must have a's shape or be the 1-d with length the size\n of a in the given axis.\n\n If returned, return a tuple: the result and the sum of the weights\n or count of values. Results will have the same shape.\n\n masked values in the weights will be set to 0.0\n \"\"\"\n a = masked_array(a)\n mask = a.mask\n ash = a.shape\n if ash == ():\n ash = (1,)\n if axis is None:\n if mask is nomask:\n if weights is None:\n n = add.reduce(a.raw_data().ravel())\n d = reduce(lambda x, y: x * y, ash, 1.0)\n else:\n w = filled(weights, 0.0).ravel()\n n = umath.add.reduce(a.raw_data().ravel() * w)\n d = umath.add.reduce(w)\n del w\n else:\n if weights is None:\n n = add.reduce(a.ravel())\n w = oldnumeric.choose(mask, (1.0,0.0)).ravel()\n d = umath.add.reduce(w)\n del w\n else:\n w = array(filled(weights, 0.0), float, mask=mask).ravel()\n n = add.reduce(a.ravel() * w)\n d = add.reduce(w)\n del w\n else:\n if mask is nomask:\n if weights is None:\n d = ash[axis] * 1.0\n n = umath.add.reduce(a.raw_data(), axis)\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = numeric.array(w, float, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * ones(ash, float)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w, r\n else:\n raise ValueError, 'average: weights wrong shape.'\n else:\n if weights is None:\n n = add.reduce(a, axis)\n w = numeric.choose(mask, (1.0, 0.0))\n d = umath.add.reduce(w, axis)\n del w\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = array(w, float, mask=mask, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * masked_array(ones(ash, float), mask)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n else:\n raise ValueError, 'average: weights wrong shape.'\n del w\n #print n, d, repr(mask), repr(weights)\n if n is masked or d is masked: return masked\n result = divide (n, d)\n del n\n\n if isinstance(result, MaskedArray):\n result.unmask()\n if returned:\n if not isinstance(d, MaskedArray):\n d = masked_array(d)\n if not d.shape == result.shape:\n d = ones(result.shape, float) * d\n d.unmask()\n if returned:\n return result, d\n else:\n return result\n\ndef where (condition, x, y):\n \"\"\"where(condition, x, y) is x where condition is nonzero, y otherwise.\n condition must be convertible to an integer array.\n Answer is always the shape of condition.\n The type depends on x and y. It is integer if both x and y are\n the value masked.\n \"\"\"\n fc = filled(not_equal(condition,0), 0)\n if x is masked:\n xv = 0\n xm = 1\n else:\n xv = filled(x)\n xm = getmask(x)\n if xm is nomask: xm = 0\n if y is masked:\n yv = 0\n ym = 1\n else:\n yv = filled(y)\n ym = getmask(y)\n if ym is nomask: ym = 0\n d = numeric.choose(fc, (yv, xv))\n md = numeric.choose(fc, (ym, xm))\n m = getmask(condition)\n m = make_mask(mask_or(m, md), copy=0, flag=1)\n return masked_array(d, m)\n\ndef choose (indices, t):\n \"Returns array shaped like indices with elements chosen from t\"\n def fmask (x):\n if x is masked: return 1\n return filled(x)\n def nmask (x):\n if x is masked: return 1\n m = getmask(x)\n if m is nomask: return 0\n return m\n c = filled(indices,0)\n masks = [nmask(x) for x in t]\n a = [fmask(x) for x in t]\n d = numeric.choose(c, a)\n m = numeric.choose(c, masks)\n m = make_mask(mask_or(m, getmask(indices)), copy=0, flag=1)\n return masked_array(d, m)\n\ndef masked_where(condition, x, copy=1):\n \"\"\"Return x as an array masked where condition is true.\n Also masked where x or condition masked.\n \"\"\"\n cm = filled(condition,1)\n m = mask_or(getmask(x), cm)\n return array(filled(x), copy=copy, mask=m)\n\ndef masked_greater(x, value, copy=1):\n \"masked_greater(x, value) = x masked where x > value\"\n return masked_where(greater(x, value), x, copy)\n\ndef masked_greater_equal(x, value, copy=1):\n \"masked_greater_equal(x, value) = x masked where x >= value\"\n return masked_where(greater_equal(x, value), x, copy)\n\ndef masked_less(x, value, copy=1):\n \"masked_less(x, value) = x masked where x < value\"\n return masked_where(less(x, value), x, copy)\n\ndef masked_less_equal(x, value, copy=1):\n \"masked_less_equal(x, value) = x masked where x <= value\"\n return masked_where(less_equal(x, value), x, copy)\n\ndef masked_not_equal(x, value, copy=1):\n \"masked_not_equal(x, value) = x masked where x != value\"\n d = filled(x,0)\n c = umath.not_equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_equal(x, value, copy=1):\n \"\"\"masked_equal(x, value) = x masked where x == value\n For floating point consider masked_values(x, value) instead.\n \"\"\"\n d = filled(x,0)\n c = umath.equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_inside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are inside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d=filled(x, 0)\n c = umath.logical_and(umath.less_equal(d, v2), umath.greater_equal(d, v1))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef masked_outside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are outside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d = filled(x,0)\n c = umath.logical_or(umath.less(d, v1), umath.greater(d, v2))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef reshape (a, *newshape):\n \"Copy of a with a new shape.\"\n m = getmask(a)\n d = filled(a).reshape(*newshape)\n if m is nomask:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.reshape(m, *newshape))\n\ndef ravel (a):\n \"a as one-dimensional, may share data and mask\"\n m = getmask(a)\n d = oldnumeric.ravel(filled(a))\n if m is nomask:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.ravel(m))\n\ndef concatenate (arrays, axis=0):\n \"Concatenate the arrays along the given axis\"\n d = []\n for x in arrays:\n d.append(filled(x))\n d = numeric.concatenate(d, axis)\n for x in arrays:\n if getmask(x) is not nomask: break\n else:\n return masked_array(d)\n dm = []\n for x in arrays:\n dm.append(getmaskarray(x))\n dm = numeric.concatenate(dm, axis)\n return masked_array(d, mask=dm)\n\ndef take (a, indices, axis=0):\n \"take(a, indices, axis=0) returns selection of items from a.\"\n m = getmask(a)\n d = masked_array(a).raw_data()\n if m is nomask:\n return masked_array(numeric.take(d, indices, axis))\n else:\n return masked_array(numeric.take(d, indices, axis),\n mask = numeric.take(m, indices, axis))\n\ndef transpose(a, axes=None):\n \"transpose(a, axes=None) reorder dimensions per tuple axes\"\n m = getmask(a)\n d = filled(a)\n if m is nomask:\n return masked_array(numeric.transpose(d, axes))\n else:\n return masked_array(numeric.transpose(d, axes),\n mask = numeric.transpose(m, axes))\n\n\ndef put(a, indices, values):\n \"\"\"put(a, indices, values) sets storage-indexed locations to corresponding values.\n\n Values and indices are filled if necessary.\n\n \"\"\"\n d = a.raw_data()\n ind = filled(indices)\n v = filled(values)\n numeric.put (d, ind, v)\n m = getmask(a)\n if m is not nomask:\n a.unshare_mask()\n numeric.put(a.raw_mask(), ind, 0)\n\ndef putmask(a, mask, values):\n \"putmask(a, mask, values) sets a where mask is true.\"\n if mask is nomask:\n return\n numeric.putmask(a.raw_data(), mask, values)\n m = getmask(a)\n if m is nomask: return\n a.unshare_mask()\n numeric.putmask(a.raw_mask(), mask, 0)\n\ndef innerproduct(a,b):\n \"\"\"innerproduct(a,b) returns the dot product of two arrays, which has\n shape a.shape[:-1] + b.shape[:-1] with elements computed by summing the\n product of the elements from the last dimensions of a and b.\n Masked elements are replace by zeros.\n \"\"\"\n fa = filled(a, 0)\n fb = filled(b, 0)\n if len(fa.shape) == 0: fa.shape = (1,)\n if len(fb.shape) == 0: fb.shape = (1,)\n return masked_array(numeric.innerproduct(fa, fb))\n\ndef outerproduct(a, b):\n \"\"\"outerproduct(a,b) = {a[i]*b[j]}, has shape (len(a),len(b))\"\"\"\n fa = filled(a,0).ravel()\n fb = filled(b,0).ravel()\n d = numeric.outerproduct(fa, fb)\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n return masked_array(d)\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = make_mask(1-numeric.outerproduct(1-ma,1-mb), copy=0)\n return masked_array(d, m)\n\ndef dot(a, b):\n \"\"\"dot(a,b) returns matrix-multiplication between a and b. The product-sum\n is over the last dimension of a and the second-to-last dimension of b.\n Masked values are replaced by zeros. See also innerproduct.\n \"\"\"\n return innerproduct(filled(a,0), numeric.swapaxes(filled(b,0), -1, -2))\n\ndef compress(condition, x, dimension=-1):\n \"\"\"Select those parts of x for which condition is true.\n Masked values in condition are considered false.\n \"\"\"\n c = filled(condition, 0)\n m = getmask(x)\n if m is not nomask:\n m=numeric.compress(c, m, dimension)\n d = numeric.compress(c, filled(x), dimension)\n return masked_array(d, m)\n\nclass _minimum_operation:\n \"Object to calculate minima\"\n def __init__ (self):\n \"\"\"minimum(a, b) or minimum(a)\n In one argument case returns the scalar minimum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is nomask:\n d = amin(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amin(ac.raw_data())\n else:\n return where(less(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is nomask:\n t = filled(target)\n return masked_array (umath.minimum.reduce (t, axis))\n else:\n t = umath.minimum.reduce(filled(target, minimum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.minimum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nminimum = _minimum_operation ()\n\nclass _maximum_operation:\n \"Object to calculate maxima\"\n def __init__ (self):\n \"\"\"maximum(a, b) or maximum(a)\n In one argument case returns the scalar maximum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is nomask:\n d = amax(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amax(ac.raw_data())\n else:\n return where(greater(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is nomask:\n t = filled(target)\n return masked_array (umath.maximum.reduce (t, axis))\n else:\n t = umath.maximum.reduce(filled(target, maximum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.maximum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nmaximum = _maximum_operation ()\n\ndef sort (x, axis = -1, fill_value=None):\n \"\"\"If x does not have a mask, return a masked array formed from the\n result of numeric.sort(x, axis).\n Otherwise, fill x with fill_value. Sort it.\n Set a mask where the result is equal to fill_value.\n Note that this may have unintended consequences if the data contains the\n fill value at a non-masked site.\n\n If fill_value is not given the default fill value for x's type will be\n used.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n d = filled(x, fill_value)\n s = oldnumeric.sort(d, axis)\n if getmask(x) is nomask:\n return masked_array(s)\n return masked_values(s, fill_value, copy=0)\n\ndef diagonal(a, k = 0, axis1=0, axis2=1):\n \"\"\"diagonal(a,k=0,axis1=0, axis2=1) = the k'th diagonal of a\"\"\"\n d = oldnumeric.diagonal(filled(a), k, axis1, axis2)\n m = getmask(a)\n if m is nomask:\n return masked_array(d, m)\n else:\n return masked_array(d, oldnumeric.diagonal(m, k, axis1, axis2))\n\ndef argsort (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for sorting along given axis.\n if fill_value is None, use get_fill_value(x)\n Returns a numpy array.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argsort(d, axis)\n\ndef argmin (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return indices for minimum values along given axis.\n if fill_value is None, use get_fill_value(x).\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argmin(d, axis)\n\ndef argmax (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for maximum along given axis.\n if fill_value is None, use -get_fill_value(x) if it exists.\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n try:\n fill_value = - fill_value\n except:\n pass\n d = filled(x, fill_value)\n return oldnumeric.argmax(d, axis)\n\ndef fromfunction (f, s):\n \"\"\"apply f to s to create array as in umath.\"\"\"\n return masked_array(numeric.fromfunction(f,s))\n\ndef asarray(data, dtype=None):\n \"\"\"asarray(data, dtype) = array(data, dtype, copy=0)\n \"\"\"\n if isinstance(data, MaskedArray) and \\\n (dtype is None or dtype == data.dtype):\n return data\n return array(data, dtype=dtype, copy=0)\n\n# Add methods to support ndarray interface\n# XXX: I is better to to change the masked_*_operation adaptors\n# XXX: to wrap ndarray methods directly to create ma.array methods.\nfrom types import MethodType\ndef _m(f):\n return MethodType(f, None, array)\ndef not_implemented(*args, **kwds):\n raise NotImplementedError, \"not yet implemented for numpy.ma arrays\"\narray.all = _m(alltrue)\narray.any = _m(sometrue)\narray.argmax = _m(argmax)\narray.argmin = _m(argmin)\narray.argsort = _m(argsort)\narray.base = property(_m(not_implemented))\narray.byteswap = _m(not_implemented)\n\ndef _choose(self, *args):\n return choose(self, args)\narray.choose = _m(_choose)\ndel _choose\n\narray.clip = _m(not_implemented)\n\ndef _compress(self, cond, axis=None):\n return compress(cond, self, axis)\narray.compress = _m(_compress)\ndel _compress\n\narray.conj = array.conjugate = _m(conjugate)\narray.copy = _m(not_implemented)\narray.cumprod = _m(not_implemented)\narray.cumsum = _m(not_implemented)\narray.diagonal = _m(diagonal)\narray.dtypedescr = property(_m(not_implemented))\narray.dtypestr = property(_m(not_implemented))\narray.dump = _m(not_implemented)\narray.dumps = _m(not_implemented)\narray.fill = _m(not_implemented)\narray.flags = property(_m(not_implemented))\narray.flatten = _m(ravel)\narray.getfield = _m(not_implemented)\narray.max = _m(maximum)\narray.mean = _m(average)\narray.min = _m(minimum)\narray.nbytes = property(_m(not_implemented))\narray.ndim = _m(not_implemented)\narray.newbyteorder = _m(not_implemented)\narray.nonzero = _m(nonzero)\narray.prod = _m(product)\narray.ptp = _m(not_implemented)\narray.repeat = _m(repeat)\narray.resize = _m(resize)\narray.searchsorted = _m(not_implemented)\narray.setfield = _m(not_implemented)\narray.setflags = _m(not_implemented)\narray.sort = _m(not_implemented) # NB: ndarray.sort is inplace\narray.squeeze = _m(not_implemented)\narray.std = _m(not_implemented)\narray.strides = property(_m(not_implemented))\narray.sum = _m(sum)\narray.swapaxes = _m(not_implemented)\narray.take = _m(take)\narray.tofile = _m(not_implemented)\narray.trace = _m(not_implemented)\narray.transpose = _m(transpose)\narray.var = _m(not_implemented)\narray.view = _m(not_implemented)\ndel _m, MethodType, not_implemented\n\n\nmasked = MaskedArray(0, int, mask=1)\n", + "source_code_before": "\"\"\"MA: a facility for dealing with missing observations\nMA is generally used as a numpy.array look-alike.\nby Paul F. Dubois.\n\nCopyright 1999, 2000, 2001 Regents of the University of California.\nReleased for unlimited redistribution.\nAdapted for numpy_core 2005 by Travis Oliphant and\n(mainly) Paul Dubois.\n\"\"\"\nimport string, types, sys\n\nimport umath\nimport oldnumeric\nfrom numeric import e, pi, newaxis, ndarray, inf\nfrom oldnumeric import typecodes, amax, amin\nfrom numerictypes import *\nimport numeric\n\n \nMaskType=bool_\nnomask = None # To be changed to MaskType(0)\ndivide_tolerance = 1.e-35\n\nclass MAError (Exception):\n def __init__ (self, args=None):\n \"Create an exception\"\n self.args = args\n def __str__(self):\n \"Calculate the string representation\"\n return str(self.args)\n __repr__ = __str__\n\nclass _MaskedPrintOption:\n \"One instance of this class, masked_print_option, is created.\"\n def __init__ (self, display):\n \"Create the masked print option object.\"\n self.set_display(display)\n self._enabled = 1\n\n def display (self):\n \"Show what prints for masked values.\"\n return self._display\n\n def set_display (self, s):\n \"set_display(s) sets what prints for masked values.\"\n self._display = s\n\n def enabled (self):\n \"Is the use of the display value enabled?\"\n return self._enabled\n\n def enable(self, flag=1):\n \"Set the enabling flag to flag.\"\n self._enabled = flag\n\n def __str__ (self):\n return str(self._display)\n\n __repr__ = __str__\n \n#if you single index into a masked location you get this object.\nmasked_print_option = _MaskedPrintOption('--')\n\n# Use single element arrays or scalars.\ndefault_real_fill_value = 1.e20\ndefault_complex_fill_value = 1.e20 + 0.0j\ndefault_character_fill_value = '-'\ndefault_integer_fill_value = 999999\ndefault_object_fill_value = '?'\n\ndef default_fill_value (obj):\n \"Function to calculate default fill value for an object.\"\n if isinstance(obj, types.FloatType):\n return default_real_fill_value\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return default_integer_fill_value\n elif isinstance(obj, types.StringType):\n return default_character_fill_value\n elif isinstance(obj, types.ComplexType):\n return default_complex_fill_value\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return default_real_fill_value\n if x in typecodes['Integer']:\n return default_integer_fill_value\n if x in typecodes['Complex']:\n return default_complex_fill_value\n if x in typecodes['Character']:\n return default_character_fill_value\n if x in typecodes['UnsignedInteger']:\n return umath.absolute(default_integer_fill_value)\n return default_object_fill_value\n else:\n return default_object_fill_value\n\ndef minimum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking minima.\"\n if isinstance(obj, types.FloatType):\n return numeric.inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return numeric.inf\n if x in typecodes['Integer']:\n return sys.maxint\n if x in typecodes['UnsignedInteger']:\n return sys.maxint\n else:\n raise TypeError, 'Unsuitable type for calculating minimum.'\n\ndef maximum_fill_value (obj):\n \"Function to calculate default fill value suitable for taking maxima.\"\n if isinstance(obj, types.FloatType):\n return -inf\n elif isinstance(obj, types.IntType) or isinstance(obj, types.LongType):\n return -sys.maxint\n elif isinstance(obj, MaskedArray) or isinstance(obj, ndarray):\n x = obj.dtypechar\n if x in typecodes['Float']:\n return -inf\n if x in typecodes['Integer']:\n return -sys.maxint\n if x in typecodes['UnsignedInteger']:\n return 0\n else:\n raise TypeError, 'Unsuitable type for calculating maximum.'\n\ndef set_fill_value (a, fill_value):\n \"Set fill value of a if it is a masked array.\"\n if isMaskedArray(a):\n a.set_fill_value (fill_value)\n\ndef getmask (a):\n \"\"\"Mask of values in a; could be nomask.\n Returns nomask if a is not a masked array.\n To get an array for sure use getmaskarray.\"\"\"\n if isinstance(a, MaskedArray):\n return a.raw_mask()\n else:\n return nomask\n\ndef getmaskarray (a):\n \"\"\"Mask of values in a; an array of zeros if mask is nomask\n or not a masked array, and is a byte-sized integer.\n Do not try to add up entries, for example.\n \"\"\"\n m = getmask(a)\n if m is nomask:\n return make_mask_none(shape(a))\n else:\n return m\n\ndef is_mask (m):\n \"\"\"Is m a legal mask? Does not check contents, only type.\n \"\"\"\n if m is nomask or (isinstance(m, ndarray) and \\\n m.dtype is MaskType):\n return 1\n else:\n return 0\n\ndef make_mask (m, copy=0, flag=0):\n \"\"\"make_mask(m, copy=0, flag=0)\n return m as a mask, creating a copy if necessary or requested.\n Can accept any sequence of integers or nomask. Does not check\n that contents must be 0s and 1s.\n if flag, return nomask if m contains no true elements.\n \"\"\"\n if m is nomask:\n return nomask\n elif isinstance(m, ndarray):\n if m.dtype is MaskType:\n if copy:\n result = numeric.array(m, dtype=MaskType, copy=copy)\n else:\n result = m\n else:\n result = m.astype(MaskType)\n else:\n result = filled(m,True).astype(MaskType)\n\n if flag and not oldnumeric.sometrue(oldnumeric.ravel(result)):\n return nomask\n else:\n return result\n\ndef make_mask_none (s):\n \"Return a mask of all zeros of shape s.\"\n result = numeric.zeros(s, dtype=MaskType)\n result.shape = s\n return result\n\ndef mask_or (m1, m2):\n \"\"\"Logical or of the mask candidates m1 and m2, treating nomask as false.\n Result may equal m1 or m2 if the other is nomask.\n \"\"\"\n if m1 is nomask: return make_mask(m2)\n if m2 is nomask: return make_mask(m1)\n if m1 is m2 and is_mask(m1): return m1\n return make_mask(umath.logical_or(m1, m2))\n\ndef filled (a, value = None):\n \"\"\"a as a contiguous numeric array with any masked areas replaced by value\n if value is None or the special element \"masked\", get_fill_value(a)\n is used instead.\n\n If a is already a contiguous numeric array, a itself is returned.\n\n filled(a) can be used to be sure that the result is numeric when\n passing an object a to other software ignorant of MA, in particular to\n numeric itself.\n \"\"\"\n if isinstance(a, MaskedArray):\n return a.filled(value)\n elif isinstance(a, ndarray) and a.flags['CONTIGUOUS']:\n return a\n elif isinstance(a, types.DictType):\n return numeric.array(a, 'O')\n else:\n return numeric.array(a)\n\ndef get_fill_value (a):\n \"\"\"\n The fill value of a, if it has one; otherwise, the default fill value\n for that type.\n \"\"\"\n if isMaskedArray(a):\n result = a.fill_value()\n else:\n result = default_fill_value(a)\n return result\n\ndef common_fill_value (a, b):\n \"The common fill_value of a and b, if there is one, or None\"\n t1 = get_fill_value(a)\n t2 = get_fill_value(b)\n if t1 == t2: return t1\n return None\n\n# Domain functions return 1 where the argument(s) are not in the domain.\nclass domain_check_interval:\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n def __init__(self, y1, y2):\n \"domain_check_interval(a,b)(x) = true where x < a or y > b\"\n self.y1 = y1\n self.y2 = y2\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.logical_or(umath.greater (x, self.y2),\n umath.less(x, self.y1)\n )\n\nclass domain_tan:\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n def __init__(self, eps):\n \"domain_tan(eps) = true where abs(cos(x)) < eps)\"\n self.eps = eps\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less(umath.absolute(umath.cos(x)), self.eps)\n\nclass domain_greater:\n \"domain_greater(v)(x) = true where x <= v\"\n def __init__(self, critical_value):\n \"domain_greater(v)(x) = true where x <= v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less_equal (x, self.critical_value)\n\nclass domain_greater_equal:\n \"domain_greater_equal(v)(x) = true where x < v\"\n def __init__(self, critical_value):\n \"domain_greater_equal(v)(x) = true where x < v\"\n self.critical_value = critical_value\n\n def __call__ (self, x):\n \"Execute the call behavior.\"\n return umath.less (x, self.critical_value)\n\nclass masked_unary_operation:\n def __init__ (self, aufunc, fill=0, domain=None):\n \"\"\" masked_unary_operation(aufunc, fill=0, domain=None)\n aufunc(fill) must be defined\n self(x) returns aufunc(x)\n with masked values where domain(x) is true or getmask(x) is true.\n \"\"\"\n self.f = aufunc\n self.fill = fill\n self.domain = domain\n self.__doc__ = getattr(aufunc, \"__doc__\", str(aufunc))\n\n def __call__ (self, a, *args, **kwargs):\n \"Execute the call behavior.\"\n# numeric tries to return scalars rather than arrays when given scalars.\n m = getmask(a)\n d1 = filled(a, self.fill)\n if self.domain is not None:\n m = mask_or(m, self.domain(d1))\n result = self.f(d1, *args, **kwargs)\n if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\n\nclass domain_safe_divide:\n def __init__ (self, tolerance=divide_tolerance):\n self.tolerance = tolerance\n def __call__ (self, a, b):\n return umath.absolute(a) * self.tolerance >= umath.absolute(b)\n\nclass domained_binary_operation:\n \"\"\"Binary operations that have a domain, like divide. These are complicated so they\n are a separate class. They have no reduce, outer or accumulate.\n \"\"\"\n def __init__ (self, abfunc, domain, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.domain = domain\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__(self, a, b):\n \"Execute the call behavior.\"\n ma = getmask(a)\n mb = getmask(b)\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n t = self.domain(d1, d2)\n\n if oldnumeric.sometrue(t, None):\n d2 = where(t, self.filly, d2)\n mb = mask_or(mb, t)\n m = mask_or(ma, mb)\n result = self.f(d1, d2)\n if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n \n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nclass masked_binary_operation:\n def __init__ (self, abfunc, fillx=0, filly=0):\n \"\"\"abfunc(fillx, filly) must be defined.\n abfunc(x, filly) = x for all x to enable reduce.\n \"\"\"\n self.f = abfunc\n self.fillx = fillx\n self.filly = filly\n self.__doc__ = getattr(abfunc, \"__doc__\", str(abfunc))\n\n def __call__ (self, a, b, *args, **kwargs):\n \"Execute the call behavior.\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a, self.fillx)\n d2 = filled(b, self.filly)\n result = self.f(d1, d2, *args, **kwargs)\n if m is not nomask:\n try:\n shape = result.shape\n except AttributeError:\n pass\n else:\n if m.shape != shape:\n m = mask_or(getmaskarray(a), getmaskarray(b))\n return masked_array(result, m)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis with this function.\"\"\"\n m = getmask(target)\n t = filled(target, self.filly)\n if t.shape == ():\n t = t.reshape(1)\n if m is not nomask:\n m = make_mask(m, copy=1)\n m.shape = (1,)\n if m is nomask:\n return masked_array (self.f.reduce (t, axis))\n else:\n t = masked_array (t, m)\n t = self.f.reduce(filled(t, self.filly), axis)\n m = umath.logical_and.reduce(m, axis)\n if isinstance(t, ndarray):\n return masked_array(t, m, get_fill_value(target))\n elif m:\n return masked\n else:\n return t\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = self.f.outer(filled(a, self.fillx), filled(b, self.filly))\n return masked_array(d, m)\n\n def accumulate (self, target, axis=0):\n \"\"\"Accumulate target along axis after filling with y fill value.\"\"\"\n t = filled(target, self.filly)\n return masked_array (self.f.accumulate (t, axis))\n def __str__ (self):\n return \"Masked version of \" + str(self.f)\n\nsqrt = masked_unary_operation(umath.sqrt, 0.0, domain_greater_equal(0.0))\nlog = masked_unary_operation(umath.log, 1.0, domain_greater(0.0))\nlog10 = masked_unary_operation(umath.log10, 1.0, domain_greater(0.0))\nexp = masked_unary_operation(umath.exp)\nconjugate = masked_unary_operation(umath.conjugate)\nsin = masked_unary_operation(umath.sin)\ncos = masked_unary_operation(umath.cos)\ntan = masked_unary_operation(umath.tan, 0.0, domain_tan(1.e-35))\narcsin = masked_unary_operation(umath.arcsin, 0.0, domain_check_interval(-1.0, 1.0))\narccos = masked_unary_operation(umath.arccos, 0.0, domain_check_interval(-1.0, 1.0))\narctan = masked_unary_operation(umath.arctan)\n# Missing from numeric\narcsinh = masked_unary_operation(umath.arcsinh)\narccosh = masked_unary_operation(umath.arccosh)\narctanh = masked_unary_operation(umath.arctanh)\nsinh = masked_unary_operation(umath.sinh)\ncosh = masked_unary_operation(umath.cosh)\ntanh = masked_unary_operation(umath.tanh)\nabsolute = masked_unary_operation(umath.absolute)\nfabs = masked_unary_operation(umath.fabs)\nnegative = masked_unary_operation(umath.negative)\nnonzero = masked_unary_operation(oldnumeric.nonzero)\naround = masked_unary_operation(oldnumeric.round_)\nfloor = masked_unary_operation(umath.floor)\nceil = masked_unary_operation(umath.ceil)\nsometrue = masked_unary_operation(oldnumeric.sometrue)\nalltrue = masked_unary_operation(oldnumeric.alltrue, 1)\nlogical_not = masked_unary_operation(umath.logical_not)\n\nadd = masked_binary_operation(umath.add)\nsubtract = masked_binary_operation(umath.subtract)\nsubtract.reduce = None\nmultiply = masked_binary_operation(umath.multiply, 1, 1)\ndivide = domained_binary_operation(umath.divide, domain_safe_divide(), 0, 1)\ntrue_divide = domained_binary_operation(umath.true_divide, domain_safe_divide(), 0, 1)\nfloor_divide = domained_binary_operation(umath.floor_divide, domain_safe_divide(), 0, 1)\nremainder = domained_binary_operation(umath.remainder, domain_safe_divide(), 0, 1)\nfmod = domained_binary_operation(umath.fmod, domain_safe_divide(), 0, 1)\nhypot = masked_binary_operation(umath.hypot)\narctan2 = masked_binary_operation(umath.arctan2, 0.0, 1.0)\narctan2.reduce = None\nequal = masked_binary_operation(umath.equal)\nequal.reduce = None\nnot_equal = masked_binary_operation(umath.not_equal)\nnot_equal.reduce = None\nless_equal = masked_binary_operation(umath.less_equal)\nless_equal.reduce = None\ngreater_equal = masked_binary_operation(umath.greater_equal)\ngreater_equal.reduce = None\nless = masked_binary_operation(umath.less)\nless.reduce = None\ngreater = masked_binary_operation(umath.greater)\ngreater.reduce = None\nlogical_and = masked_binary_operation(umath.logical_and)\nlogical_or = masked_binary_operation(umath.logical_or)\nlogical_xor = masked_binary_operation(umath.logical_xor)\nbitwise_and = masked_binary_operation(umath.bitwise_and)\nbitwise_or = masked_binary_operation(umath.bitwise_or)\nbitwise_xor = masked_binary_operation(umath.bitwise_xor)\n\ndef rank (object):\n return oldnumeric.rank(filled(object))\n\ndef shape (object):\n return oldnumeric.shape(filled(object))\n\ndef size (object, axis=None):\n return oldnumeric.size(filled(object), axis)\n\nclass MaskedArray (object):\n \"\"\"Arrays with possibly masked values.\n Masked values of 1 exclude the corresponding element from \n any computation.\n\n Construction:\n x = array(data, dtype=None, copy=True, fortran=False,\n mask = nomask, fill_value=None)\n\n If copy=False, every effort is made not to copy the data:\n If data is a MaskedArray, and argument mask=nomask,\n then the candidate data is data.data and the\n mask used is data.mask. If data is a numeric array,\n it is used as the candidate raw data.\n If dtypechar is not None and\n is != data.dtypechar then a data copy is required.\n Otherwise, the candidate is used.\n\n If a data copy is required, raw data stored is the result of:\n numeric.array(data, dtype=dtypechar, copy=copy)\n\n If mask is nomask there are no masked values. Otherwise mask must\n be convertible to an array of booleans with the same shape as x.\n\n fill_value is used to fill in masked values when necessary,\n such as when printing and in method/function filled().\n The fill_value is not used for computation within this module.\n \"\"\"\n __array_priority__ = 10.1\n def __init__(self, data, dtype=None, copy=True, fortran=False, \n mask=nomask, fill_value=None):\n \"\"\"array(data, dtype=None, copy=True, fortran=False, mask=nomask, fill_value=None)\n If data already a numeric array, its dtype becomes the default value of dtype.\n \"\"\"\n tc = dtype\n need_data_copied = copy\n if isinstance(data, MaskedArray):\n c = data.data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n if mask is nomask:\n mask = data.mask\n elif mask is not nomask: #attempting to change the mask\n need_data_copied = True\n\n elif isinstance(data, ndarray):\n c = data\n ctc = c.dtypechar\n if tc is None:\n tc = ctc\n elif dtype2char(tc) != ctc:\n need_data_copied = True\n else:\n need_data_copied = False #because I'll do it now\n c = numeric.array(data, dtype=tc, copy=True, fortran=fortran)\n\n if need_data_copied:\n if tc == ctc:\n self._data = numeric.array(c, dtype=tc, copy=True, fortran=fortran)\n else:\n self._data = c.astype(tc)\n else:\n self._data = c\n\n if mask is nomask:\n self._mask = nomask\n self._shared_mask = 0\n else:\n self._mask = make_mask (mask)\n if self._mask is nomask:\n self._shared_mask = 0\n else:\n self._shared_mask = (self._mask is mask)\n nm = size(self._mask)\n nd = size(self._data)\n if nm != nd:\n if nm == 1:\n self._mask = oldnumeric.resize(self._mask, self._data.shape)\n self._shared_mask = 0\n elif nd == 1:\n self._data = oldnumeric.resize(self._data, self._mask.shape)\n self._data.shape = self._mask.shape\n else:\n raise MAError, \"Mask and data not compatible.\"\n elif nm == 1 and shape(self._mask) != shape(self._data):\n self.unshare_mask()\n self._mask.shape = self._data.shape\n\n self.set_fill_value(fill_value)\n\n def __array__ (self, t = None):\n \"Special hook for numeric. Converts to numeric if possible.\"\n if self._mask is not nomask:\n if oldnumeric.ravel(self._mask).any():\n raise MAError, \\\n \"\"\"Cannot automatically convert masked array to numeric because data\n is masked in one or more locations.\n \"\"\"\n else: # Mask is all false\n # Optimize to avoid future invocations of this section.\n self._mask = nomask\n self._shared_mask = 0\n if t:\n return self._data.astype(t)\n else:\n return self._data\n\n def __array_wrap__ (self, array):\n \"\"\"Special hook for ufuncs. Converts to Masked array with\n the same mask as self.\"\"\"\n return MaskedArray(array, copy=False, mask=self._mask,\n fill_value = self._fill_value)\n \n def _get_shape(self):\n \"Return the current shape.\"\n return self._data.shape\n\n def _set_shape (self, newshape):\n \"Set the array's shape.\"\n self._data.shape = newshape\n if self._mask is not nomask:\n self._mask = self._mask.copy()\n self._mask.shape = newshape\n\n def _get_flat(self):\n \"\"\"Calculate the flat value.\n \"\"\"\n if self._mask is nomask:\n return masked_array(self._data.ravel(), mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.ravel(),\n mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_flat (self, value):\n \"x.flat = value\"\n y = self.ravel()\n y[:] = value\n\n def _get_real(self):\n \"Get the real part of a complex array.\"\n if self._mask is nomask:\n return masked_array(self._data.real, mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.real, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_real (self, value):\n \"x.real = value\"\n y = self.real\n y[...] = value\n\n def _get_imaginary(self):\n \"Get the imaginary part of a complex array.\"\n if self._mask is nomask:\n return masked_array(self._data.imag, mask=nomask,\n fill_value = self.fill_value())\n else:\n return masked_array(self._data.imag, mask=self._mask.ravel(),\n fill_value = self.fill_value())\n\n def _set_imaginary (self, value):\n \"x.imaginary = value\"\n y = self.imaginary\n y[...] = value\n\n def __str__(self):\n \"\"\"Calculate the str representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n if masked_print_option.enabled():\n f = masked_print_option\n # XXX: Without the following special case masked\n # XXX: would print as \"[--]\", not \"--\". Can we avoid\n # XXX: checks for masked by choosing a different value\n # XXX: for the masked singleton? 2005-01-05 -- sasha\n if self is masked:\n return str(f)\n m = self._mask\n if m is not nomask and m.shape == () and m:\n return str(f)\n # convert to object array to make filled work\n self = self.astype(object)\n else:\n f = self.fill_value()\n res = self.filled(f)\n return str(res)\n\n def __repr__(self):\n \"\"\"Calculate the repr representation, using masked for fill if\n it is enabled. Otherwise fill with fill value.\n \"\"\"\n with_mask = \"\"\"\\\narray(data =\n %(data)s,\n mask =\n %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n with_mask1 = \"\"\"\\\narray(data = %(data)s,\n mask = %(mask)s,\n fill_value=%(fill)s)\n\"\"\"\n without_mask = \"\"\"array(\n %(data)s)\"\"\"\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n\n n = len(self.shape)\n if self._mask is nomask:\n if n <=1:\n return without_mask1 % {'data':str(self.filled())}\n return without_mask % {'data':str(self.filled())}\n else:\n if n <=1:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n without_mask1 = \"\"\"array(%(data)s)\"\"\"\n if self._mask is nomask:\n return without_mask % {'data':str(self.filled())}\n else:\n return with_mask % {\n 'data': str(self.filled()),\n 'mask': str(self._mask),\n 'fill': str(self.fill_value())\n }\n\n def __float__(self):\n \"Convert self to float.\"\n self.unmask()\n if self._mask is not nomask:\n raise MAError, 'Cannot convert masked element to a Python float.'\n return float(self.data.item())\n\n def __int__(self):\n \"Convert self to int.\"\n self.unmask()\n if self._mask is not nomask:\n raise MAError, 'Cannot convert masked element to a Python int.'\n return int(self.data.item())\n\n def __getitem__(self, i):\n \"Get item described by i. Not a copy as in previous versions.\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i]\n if m is nomask:\n return dout\n mi = m[i]\n if mi.size == 1:\n if mi: \n return masked\n else:\n return dout\n else:\n return masked_array(dout, mi, fill_value=self._fill_value)\n\n def __getslice__(self, i, j):\n \"Get slice described by i, j\"\n self.unshare_mask()\n m = self._mask\n dout = self._data[i:j]\n if m is nomask:\n return masked_array(dout, fill_value=self._fill_value)\n else:\n return masked_array(dout, mask = m[i:j], fill_value=self._fill_value)\n\n# --------\n# setitem and setslice notes\n# note that if value is masked, it means to mask those locations.\n# setting a value changes the mask to match the value in those locations.\n\n def __setitem__(self, index, value):\n \"Set item described by index. If value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, 'Cannot alter the masked element.'\n if value is masked:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n else:\n self.unshare_mask()\n self._mask[index] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[index] = value\n if m is nomask:\n if self._mask is not nomask:\n self.unshare_mask()\n self._mask[index] = False\n else:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = True\n else:\n self.unshare_mask()\n self._mask[index] = m\n\n def __setslice__(self, i, j, value):\n \"Set slice i:j; if value is masked, mask those locations.\"\n d = self._data\n if self is masked:\n raise MAError, \"Cannot alter the 'masked' object.\"\n if value is masked:\n if self._mask is nomask:\n self._mask = make_mask_none(d.shape)\n self._shared_mask = False\n self._mask[i:j] = True\n return\n m = getmask(value)\n value = filled(value).astype(d.dtype)\n d[i:j] = value\n if m is nomask:\n if self._mask is not nomask:\n self.unshare_mask()\n self._mask[i:j] = False\n else:\n if self._mask is nomask:\n self._mask = make_mask_none(self._data.shape)\n self._shared_mask = False\n self._mask[i:j] = m\n\n def __nonzero__(self):\n \"\"\"returns true if any element is non-zero or masked\n\n \"\"\"\n # XXX: This changes bool conversion logic from MA.\n # XXX: In MA bool(a) == len(a) != 0, but in numpy\n # XXX: scalars do not have len \n m = self._mask\n d = self._data\n return bool(m is not nomask and m.any()\n or d is not nomask and d.any())\n \n def __len__ (self):\n \"\"\"Return length of first dimension. This is weird but Python's\n slicing behavior depends on it.\"\"\"\n return len(self._data)\n\n def __and__(self, other):\n \"Return bitwise_and\"\n return bitwise_and(self, other)\n\n def __or__(self, other):\n \"Return bitwise_or\"\n return bitwise_or(self, other)\n\n def __xor__(self, other):\n \"Return bitwise_xor\"\n return bitwise_xor(self, other)\n\n __rand__ = __and__\n __ror__ = __or__\n __rxor__ = __xor__\n\n def __abs__(self):\n \"Return absolute(self)\"\n return absolute(self)\n\n def __neg__(self):\n \"Return negative(self)\"\n return negative(self)\n\n def __pos__(self):\n \"Return array(self)\"\n return array(self)\n\n def __add__(self, other):\n \"Return add(self, other)\"\n return add(self, other)\n\n __radd__ = __add__\n\n def __mod__ (self, other):\n \"Return remainder(self, other)\"\n return remainder(self, other)\n\n def __rmod__ (self, other):\n \"Return remainder(other, self)\"\n return remainder(other, self)\n\n def __lshift__ (self, n):\n return left_shift(self, n)\n\n def __rshift__ (self, n):\n return right_shift(self, n)\n\n def __sub__(self, other):\n \"Return subtract(self, other)\"\n return subtract(self, other)\n\n def __rsub__(self, other):\n \"Return subtract(other, self)\"\n return subtract(other, self)\n\n def __mul__(self, other):\n \"Return multiply(self, other)\"\n return multiply(self, other)\n\n __rmul__ = __mul__\n\n def __div__(self, other):\n \"Return divide(self, other)\"\n return divide(self, other)\n\n def __rdiv__(self, other):\n \"Return divide(other, self)\"\n return divide(other, self)\n\n def __truediv__(self, other):\n \"Return divide(self, other)\"\n return true_divide(self, other)\n\n def __rtruediv__(self, other):\n \"Return divide(other, self)\"\n return true_divide(other, self)\n\n def __floordiv__(self, other):\n \"Return divide(self, other)\"\n return floor_divide(self, other)\n\n def __rfloordiv__(self, other):\n \"Return divide(other, self)\"\n return floor_divide(other, self)\n\n def __pow__(self,other, third=None):\n \"Return power(self, other, third)\"\n return power(self, other, third)\n\n def __sqrt__(self):\n \"Return sqrt(self)\"\n return sqrt(self)\n\n def __iadd__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data += f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = add(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __imul__(self, other):\n \"Add other to self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data *= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = multiply(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n def __isub__(self, other):\n \"Subtract other from self in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n\n if self._mask is nomask:\n self._data -= f\n m = getmask(other)\n self._mask = m\n self._shared_mask = m is not nomask\n else:\n result = subtract(self, masked_array(f, mask=getmask(other)))\n self._data = result.data\n self._mask = result.mask\n self._shared_mask = 1\n return self\n\n\n\n def __idiv__(self, other):\n \"Divide self by other in place.\"\n t = self._data.dtypechar\n f = filled(other,0)\n t1 = f.dtypechar\n if t == t1:\n pass\n elif t in typecodes['Integer']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Float']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n elif t in typecodes['Complex']:\n if t1 in typecodes['Integer']:\n f = f.astype(t)\n elif t1 in typecodes['Float']:\n f = f.astype(t)\n elif t1 in typecodes['Complex']:\n f = f.astype(t)\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n else:\n raise TypeError, 'Incorrect type for in-place operation.'\n mo = getmask(other)\n result = divide(self, masked_array(f, mask=mo))\n self._data = result.data\n dm = result.raw_mask()\n if dm is not self._mask:\n self._mask = dm\n self._shared_mask = 1\n return self\n\n def __eq__(self,other):\n return equal(self,other)\n\n def __ne__(self,other):\n return not_equal(self,other)\n\n def __lt__(self,other):\n return less(self,other)\n\n def __le__(self,other):\n return less_equal(self,other)\n\n def __gt__(self,other):\n return greater(self,other)\n\n def __ge__(self,other):\n return greater_equal(self,other)\n\n def astype (self, tc):\n \"return self as array of given type.\"\n d = self._data.astype(tc)\n return array(d, mask=self._mask)\n\n def byte_swapped(self):\n \"\"\"Returns the raw data field, byte_swapped. Included for consistency\n with numeric but doesn't make sense in this context.\n \"\"\"\n return self._data.byte_swapped()\n\n def compressed (self):\n \"A 1-D array of all the non-masked data.\"\n d = oldnumeric.ravel(self._data)\n if self._mask is nomask:\n return array(d)\n else:\n m = 1 - oldnumeric.ravel(self._mask)\n c = oldnumeric.compress(m, d)\n return array(c, copy=0)\n\n def count (self, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n m = self._mask\n s = self._data.shape\n ls = len(s)\n if m is nomask:\n if ls == 0:\n return 1\n if ls == 1:\n return s[0]\n if axis is None:\n return reduce(lambda x,y:x*y, s)\n else:\n n = s[axis]\n t = list(s)\n del t[axis]\n return ones(t) * n\n if axis is None:\n w = oldnumeric.ravel(m).astype(int) \n n1 = size(w)\n if n1 == 1:\n n2 = w[0]\n else:\n n2 = umath.add.reduce(w)\n return n1 - n2\n else:\n n1 = size(m, axis)\n n2 = sum(m.astype(int), axis)\n return n1 - n2\n\n def dot (self, other):\n \"s.dot(other) = innerproduct(s, other)\"\n return innerproduct(self, other)\n\n def fill_value(self):\n \"Get the current fill value.\"\n return self._fill_value\n\n def filled (self, fill_value=None):\n \"\"\"A numeric array with masked values filled. If fill_value is None,\n use self.fill_value().\n\n If mask is nomask, copy data only if not contiguous.\n Result is always a contiguous, numeric array.\n# Is contiguous really necessary now?\n \"\"\"\n d = self._data\n m = self._mask\n if m is nomask:\n if d.flags['CONTIGUOUS']:\n return d\n else:\n return d.copy()\n else:\n if fill_value is None:\n value = self._fill_value\n else:\n value = fill_value\n\n if self is masked:\n result = numeric.array(value).reshape(*d.shape)\n else:\n try:\n result = numeric.array(d, dtype=d.dtype, copy=1)\n result[m] = value\n except (TypeError, AttributeError):\n #ok, can't put that value in here\n value = numeric.array(value, dtype=object)\n d = d.astype(object)\n result = oldnumeric.choose(m, (d, value))\n except IndexError:\n #ok, if scalar\n if d.shape:\n raise\n elif m:\n result = numeric.array(value, dtype=d.dtype)\n else:\n result = d\n return result\n\n def ids (self):\n \"\"\"Return the ids of the data and mask areas\"\"\"\n return (id(self._data), id(self._mask))\n\n def iscontiguous (self):\n \"Is the data contiguous?\"\n return self._data.flags['CONTIGUOUS']\n\n def itemsize(self):\n \"Item size of each data item.\"\n return self._data.itemsize\n\n\n def outer(self, other):\n \"s.outer(other) = outerproduct(s, other)\"\n return outerproduct(self, other)\n\n def put (self, values):\n \"\"\"Set the non-masked entries of self to filled(values).\n No change to mask\n \"\"\"\n iota = numeric.arange(self.size)\n d = self._data\n if self._mask is nomask:\n ind = iota\n else:\n ind = oldnumeric.compress(1 - self._mask, iota)\n d[ind] = filled(values).astype(d.dtype)\n\n def putmask (self, values):\n \"\"\"Set the masked entries of self to filled(values).\n Mask changed to nomask.\n \"\"\"\n d = self._data\n if self._mask is not nomask:\n d[self._mask] = filled(values).astype(d.dtype)\n self._shared_mask = 0\n self._mask = nomask\n\n def ravel (self):\n \"\"\"Return a 1-D view of self.\"\"\"\n if self._mask is nomask:\n return masked_array(self._data.ravel())\n else:\n return masked_array(self._data.ravel(), self._mask.ravel())\n\n def raw_data (self):\n \"\"\" Obsolete; use data property instead.\n The raw data; portions may be meaningless.\n May be noncontiguous. Expert use only.\"\"\"\n return self._data\n data = property(fget=raw_data, \n doc=\"The data, but values at masked locations are meaningless.\")\n\n def raw_mask (self):\n \"\"\" Obsolete; use mask property instead.\n May be noncontiguous. Expert use only.\n \"\"\"\n return self._mask\n mask = property(fget=raw_mask, \n doc=\"The mask, may be nomask. Values where mask true are meaningless.\")\n\n def reshape (self, *s):\n \"\"\"This array reshaped to shape s\"\"\"\n d = self._data.reshape(*s)\n if self._mask is nomask:\n return masked_array(d)\n else:\n m = self._mask.reshape(*s)\n return masked_array(d, m)\n\n def set_fill_value (self, v=None):\n \"Set the fill value to v. Omit v to restore default.\"\n if v is None:\n v = default_fill_value (self.raw_data())\n self._fill_value = v\n\n def _get_size (self):\n return self._data.size\n size = property(fget=_get_size, doc=\"Number of elements in the array.\")\n## CHECK THIS: signature of numeric.array.size?\n \n def _get_dtypechar(self):\n return self._data.dtypechar\n dtypechar = property(fget=_get_dtypechar, doc=\"type character of the array.\")\n\n def _get_dtype(self):\n return self._data.dtype\n dtype = property(fget=_get_dtype, doc=\"type of the array elements.\")\n\n def item(self):\n \"Return Python scalar if possible.\"\n if self._mask is not nomask:\n m = oldnumeric.ravel(self._mask)\n try:\n if m[0]:\n return masked\n except IndexError:\n return masked\n return self._data.item()\n\n def tolist(self, fill_value=None):\n \"Convert to list\"\n return self.filled(fill_value).tolist()\n\n def tostring(self, fill_value=None):\n \"Convert to string\"\n return self.filled(fill_value).tostring()\n\n def unmask (self):\n \"Replace the mask by nomask if possible.\"\n if self._mask is nomask: return\n m = make_mask(self._mask, flag=1)\n if m is nomask:\n self._mask = nomask\n self._shared_mask = 0\n\n def unshare_mask (self):\n \"If currently sharing mask, make a copy.\"\n if self._shared_mask:\n self._mask = make_mask (self._mask, copy=1, flag=0)\n self._shared_mask = 0\n\n shape = property(_get_shape, _set_shape,\n doc = 'tuple giving the shape of the array')\n\n flat = property(_get_flat, _set_flat,\n doc = 'Access array in flat form.')\n\n real = property(_get_real, _set_real,\n doc = 'Access the real part of the array')\n\n imaginary = property(_get_imaginary, _set_imaginary,\n doc = 'Access the imaginary part of the array')\n\n imag = imaginary\n\n#end class MaskedArray\n\narray = MaskedArray\n\ndef isMaskedArray (x):\n \"Is x a masked array, that is, an instance of MaskedArray?\"\n return isinstance(x, MaskedArray)\n\nisarray = isMaskedArray\nisMA = isMaskedArray #backward compatibility\n\ndef allclose (a, b, fill_value=1, rtol=1.e-5, atol=1.e-8):\n \"\"\" Returns true if all components of a and b are equal\n subject to given tolerances.\n If fill_value is 1, masked values considered equal.\n If fill_value is 0, masked values considered unequal.\n The relative error rtol should be positive and << 1.0\n The absolute error atol comes into play for those elements\n of b that are very small or zero; it says how small a must be also.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n d1 = filled(a)\n d2 = filled(b)\n x = filled(array(d1, copy=0, mask=m), fill_value).astype(float)\n y = filled(array(d2, copy=0, mask=m), 1).astype(float)\n d = umath.less_equal(umath.absolute(x-y), atol + rtol * umath.absolute(y))\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n\ndef allequal (a, b, fill_value=1):\n \"\"\"\n True if all entries of a and b are equal, using\n fill_value as a truth value where either or both are masked.\n \"\"\"\n m = mask_or(getmask(a), getmask(b))\n if m is nomask:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n return oldnumeric.alltrue(oldnumeric.ravel(d))\n elif fill_value:\n x = filled(a)\n y = filled(b)\n d = umath.equal(x, y)\n dm = array(d, mask=m, copy=0)\n return oldnumeric.alltrue(oldnumeric.ravel(filled(dm, 1)))\n else:\n return 0\n\ndef masked_values (data, value, rtol=1.e-5, atol=1.e-8, copy=1):\n \"\"\"\n masked_values(data, value, rtol=1.e-5, atol=1.e-8)\n Create a masked array; mask is nomask if possible.\n If copy==0, and otherwise possible, result\n may share data values with original array.\n Let d = filled(data, value). Returns d\n masked where abs(data-value)<= atol + rtol * abs(value)\n if d is of a floating point type. Otherwise returns\n masked_object(d, value, copy)\n \"\"\"\n abs = umath.absolute\n d = filled(data, value)\n if issubclass(d.dtype, numeric.floating):\n m = umath.less_equal(abs(d-value), atol+rtol*abs(value))\n m = make_mask(m, flag=1)\n return array(d, mask = m, copy=copy,\n fill_value=value)\n else:\n return masked_object(d, value, copy=copy)\n\ndef masked_object (data, value, copy=1):\n \"Create array masked where exactly data equal to value\"\n d = filled(data, value)\n dm = make_mask(umath.equal(d, value), flag=1)\n return array(d, mask=dm, copy=copy, fill_value=value)\n\ndef arrayrange(start, stop=None, step=1, dtype=None):\n \"\"\"Just like range() except it returns a array whose type can be specified\n by the keyword argument dtypechar.\n \"\"\"\n return array(numeric.arrayrange(start, stop, step, dtype))\n\narange = arrayrange\n\ndef fromstring (s, t):\n \"Construct a masked array from a string. Result will have no mask.\"\n return masked_array(numeric.fromstring(s, t))\n\ndef left_shift (a, n):\n \"Left shift n bits\"\n m = getmask(a)\n if m is nomask:\n d = umath.left_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.left_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef right_shift (a, n):\n \"Right shift n bits\"\n m = getmask(a)\n if m is nomask:\n d = umath.right_shift(filled(a), n)\n return masked_array(d)\n else:\n d = umath.right_shift(filled(a,0), n)\n return masked_array(d, m)\n\ndef resize (a, new_shape):\n \"\"\"resize(a, new_shape) returns a new array with the specified shape.\n The original array's total size can be any size.\"\"\"\n m = getmask(a)\n if m is not nomask:\n m = oldnumeric.resize(m, new_shape)\n result = array(oldnumeric.resize(filled(a), new_shape), mask=m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef repeat(a, repeats, axis=0):\n \"\"\"repeat elements of a repeats times along axis\n repeats is a sequence of length a.shape[axis]\n telling how many times to repeat each element.\n \"\"\"\n af = filled(a)\n if isinstance(repeats, types.IntType):\n repeats = tuple([repeats]*(shape(af)[axis]))\n\n m = getmask(a)\n if m is not nomask:\n m = oldnumeric.repeat(m, repeats, axis)\n d = oldnumeric.repeat(af, repeats, axis)\n result = masked_array(d, m)\n result.set_fill_value(get_fill_value(a))\n return result\n\ndef identity(n):\n \"\"\"identity(n) returns the identity matrix of shape n x n.\n \"\"\"\n return array(numeric.identity(n))\n\ndef indices (dimensions, dtype=None):\n \"\"\"indices(dimensions,dtype=None) returns an array representing a grid\n of indices with row-only, and column-only variation.\n \"\"\"\n return array(numeric.indices(dimensions, dtype))\n\ndef zeros (shape, dtype=int):\n \"\"\"zeros(n, dtype=int) =\n an array of all zeros of the given length or shape.\"\"\"\n return array(numeric.zeros(shape, dtype))\n\ndef ones (shape, dtype=int):\n \"\"\"ones(n, dtype=int) =\n an array of all ones of the given length or shape.\"\"\"\n return array(numeric.ones(shape, dtype))\n\n\ndef count (a, axis = None):\n \"Count of the non-masked elements in a, or along a certain axis.\"\n a = masked_array(a)\n return a.count(axis)\n\ndef power (a, b, third=None):\n \"a**b\"\n if third is not None:\n raise MAError, \"3-argument power not supported.\"\n ma = getmask(a)\n mb = getmask(b)\n m = mask_or(ma, mb)\n fa = filled(a, 1)\n fb = filled(b, 1)\n if fb.dtypechar in typecodes[\"Integer\"]:\n return masked_array(umath.power(fa, fb), m)\n md = make_mask(umath.less_equal (fa, 0), flag=1)\n m = mask_or(m, md)\n if m is nomask:\n return masked_array(umath.power(fa, fb))\n else:\n fa = numeric.where(m, 1, fa)\n return masked_array(umath.power(fa, fb), m)\n\ndef masked_array (a, mask=nomask, fill_value=None):\n \"\"\"masked_array(a, mask=nomask) =\n array(a, mask=mask, copy=0, fill_value=fill_value)\n \"\"\"\n return array(a, mask=mask, copy=0, fill_value=fill_value)\n\nsum = add.reduce\nproduct = multiply.reduce\n\ndef average (a, axis=0, weights=None, returned = 0):\n \"\"\"average(a, axis=0, weights=None)\n Computes average along indicated axis.\n If axis is None, average over the entire array\n Inputs can be integer or floating types; result is of type float.\n\n If weights are given, result is sum(a*weights)/(sum(weights)*1.0)\n weights must have a's shape or be the 1-d with length the size\n of a in the given axis.\n\n If returned, return a tuple: the result and the sum of the weights\n or count of values. Results will have the same shape.\n\n masked values in the weights will be set to 0.0\n \"\"\"\n a = masked_array(a)\n mask = a.mask\n ash = a.shape\n if ash == ():\n ash = (1,)\n if axis is None:\n if mask is nomask:\n if weights is None:\n n = add.reduce(a.raw_data().ravel())\n d = reduce(lambda x, y: x * y, ash, 1.0)\n else:\n w = filled(weights, 0.0).ravel()\n n = umath.add.reduce(a.raw_data().ravel() * w)\n d = umath.add.reduce(w)\n del w\n else:\n if weights is None:\n n = add.reduce(a.ravel())\n w = oldnumeric.choose(mask, (1.0,0.0)).ravel()\n d = umath.add.reduce(w)\n del w\n else:\n w = array(filled(weights, 0.0), float, mask=mask).ravel()\n n = add.reduce(a.ravel() * w)\n d = add.reduce(w)\n del w\n else:\n if mask is nomask:\n if weights is None:\n d = ash[axis] * 1.0\n n = umath.add.reduce(a.raw_data(), axis)\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = numeric.array(w, float, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * ones(ash, float)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n del w, r\n else:\n raise ValueError, 'average: weights wrong shape.'\n else:\n if weights is None:\n n = add.reduce(a, axis)\n w = numeric.choose(mask, (1.0, 0.0))\n d = umath.add.reduce(w, axis)\n del w\n else:\n w = filled(weights, 0.0)\n wsh = w.shape\n if wsh == ():\n wsh = (1,)\n if wsh == ash:\n w = array(w, float, mask=mask, copy=0)\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n elif wsh == (ash[axis],):\n ni = ash[axis]\n r = [newaxis]*len(ash)\n r[axis] = slice(None,None,1)\n w = eval (\"w[\"+ repr(tuple(r)) + \"] * masked_array(ones(ash, float), mask)\")\n n = add.reduce(a*w, axis)\n d = add.reduce(w, axis)\n else:\n raise ValueError, 'average: weights wrong shape.'\n del w\n #print n, d, repr(mask), repr(weights)\n if n is masked or d is masked: return masked\n result = divide (n, d)\n del n\n\n if isinstance(result, MaskedArray):\n result.unmask()\n if returned:\n if not isinstance(d, MaskedArray):\n d = masked_array(d)\n if not d.shape == result.shape:\n d = ones(result.shape, float) * d\n d.unmask()\n if returned:\n return result, d\n else:\n return result\n\ndef where (condition, x, y):\n \"\"\"where(condition, x, y) is x where condition is nonzero, y otherwise.\n condition must be convertible to an integer array.\n Answer is always the shape of condition.\n The type depends on x and y. It is integer if both x and y are\n the value masked.\n \"\"\"\n fc = filled(not_equal(condition,0), 0)\n if x is masked:\n xv = 0\n xm = 1\n else:\n xv = filled(x)\n xm = getmask(x)\n if xm is nomask: xm = 0\n if y is masked:\n yv = 0\n ym = 1\n else:\n yv = filled(y)\n ym = getmask(y)\n if ym is nomask: ym = 0\n d = numeric.choose(fc, (yv, xv))\n md = numeric.choose(fc, (ym, xm))\n m = getmask(condition)\n m = make_mask(mask_or(m, md), copy=0, flag=1)\n return masked_array(d, m)\n\ndef choose (indices, t):\n \"Returns array shaped like indices with elements chosen from t\"\n def fmask (x):\n if x is masked: return 1\n return filled(x)\n def nmask (x):\n if x is masked: return 1\n m = getmask(x)\n if m is nomask: return 0\n return m\n c = filled(indices,0)\n masks = [nmask(x) for x in t]\n a = [fmask(x) for x in t]\n d = numeric.choose(c, a)\n m = numeric.choose(c, masks)\n m = make_mask(mask_or(m, getmask(indices)), copy=0, flag=1)\n return masked_array(d, m)\n\ndef masked_where(condition, x, copy=1):\n \"\"\"Return x as an array masked where condition is true.\n Also masked where x or condition masked.\n \"\"\"\n cm = filled(condition,1)\n m = mask_or(getmask(x), cm)\n return array(filled(x), copy=copy, mask=m)\n\ndef masked_greater(x, value, copy=1):\n \"masked_greater(x, value) = x masked where x > value\"\n return masked_where(greater(x, value), x, copy)\n\ndef masked_greater_equal(x, value, copy=1):\n \"masked_greater_equal(x, value) = x masked where x >= value\"\n return masked_where(greater_equal(x, value), x, copy)\n\ndef masked_less(x, value, copy=1):\n \"masked_less(x, value) = x masked where x < value\"\n return masked_where(less(x, value), x, copy)\n\ndef masked_less_equal(x, value, copy=1):\n \"masked_less_equal(x, value) = x masked where x <= value\"\n return masked_where(less_equal(x, value), x, copy)\n\ndef masked_not_equal(x, value, copy=1):\n \"masked_not_equal(x, value) = x masked where x != value\"\n d = filled(x,0)\n c = umath.not_equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_equal(x, value, copy=1):\n \"\"\"masked_equal(x, value) = x masked where x == value\n For floating point consider masked_values(x, value) instead.\n \"\"\"\n d = filled(x,0)\n c = umath.equal(d, value)\n m = mask_or(c, getmask(x))\n return array(d, mask=m, copy=copy)\n\ndef masked_inside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are inside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d=filled(x, 0)\n c = umath.logical_and(umath.less_equal(d, v2), umath.greater_equal(d, v1))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef masked_outside(x, v1, v2, copy=1):\n \"\"\"x with mask of all values of x that are outside [v1,v2]\n v1 and v2 can be given in either order.\n \"\"\"\n if v2 < v1:\n t = v2\n v2 = v1\n v1 = t\n d = filled(x,0)\n c = umath.logical_or(umath.less(d, v1), umath.greater(d, v2))\n m = mask_or(c, getmask(x))\n return array(d, mask = m, copy=copy)\n\ndef reshape (a, *newshape):\n \"Copy of a with a new shape.\"\n m = getmask(a)\n d = filled(a).reshape(*newshape)\n if m is nomask:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.reshape(m, *newshape))\n\ndef ravel (a):\n \"a as one-dimensional, may share data and mask\"\n m = getmask(a)\n d = oldnumeric.ravel(filled(a))\n if m is nomask:\n return masked_array(d)\n else:\n return masked_array(d, mask=numeric.ravel(m))\n\ndef concatenate (arrays, axis=0):\n \"Concatenate the arrays along the given axis\"\n d = []\n for x in arrays:\n d.append(filled(x))\n d = numeric.concatenate(d, axis)\n for x in arrays:\n if getmask(x) is not nomask: break\n else:\n return masked_array(d)\n dm = []\n for x in arrays:\n dm.append(getmaskarray(x))\n dm = numeric.concatenate(dm, axis)\n return masked_array(d, mask=dm)\n\ndef take (a, indices, axis=0):\n \"take(a, indices, axis=0) returns selection of items from a.\"\n m = getmask(a)\n d = masked_array(a).raw_data()\n if m is nomask:\n return masked_array(numeric.take(d, indices, axis))\n else:\n return masked_array(numeric.take(d, indices, axis),\n mask = numeric.take(m, indices, axis))\n\ndef transpose(a, axes=None):\n \"transpose(a, axes=None) reorder dimensions per tuple axes\"\n m = getmask(a)\n d = filled(a)\n if m is nomask:\n return masked_array(numeric.transpose(d, axes))\n else:\n return masked_array(numeric.transpose(d, axes),\n mask = numeric.transpose(m, axes))\n\n\ndef put(a, indices, values):\n \"\"\"put(a, indices, values) sets storage-indexed locations to corresponding values.\n\n Values and indices are filled if necessary.\n\n \"\"\"\n d = a.raw_data()\n ind = filled(indices)\n v = filled(values)\n numeric.put (d, ind, v)\n m = getmask(a)\n if m is not nomask:\n a.unshare_mask()\n numeric.put(a.raw_mask(), ind, 0)\n\ndef putmask(a, mask, values):\n \"putmask(a, mask, values) sets a where mask is true.\"\n if mask is nomask:\n return\n numeric.putmask(a.raw_data(), mask, values)\n m = getmask(a)\n if m is nomask: return\n a.unshare_mask()\n numeric.putmask(a.raw_mask(), mask, 0)\n\ndef innerproduct(a,b):\n \"\"\"innerproduct(a,b) returns the dot product of two arrays, which has\n shape a.shape[:-1] + b.shape[:-1] with elements computed by summing the\n product of the elements from the last dimensions of a and b.\n Masked elements are replace by zeros.\n \"\"\"\n fa = filled(a, 0)\n fb = filled(b, 0)\n if len(fa.shape) == 0: fa.shape = (1,)\n if len(fb.shape) == 0: fb.shape = (1,)\n return masked_array(numeric.innerproduct(fa, fb))\n\ndef outerproduct(a, b):\n \"\"\"outerproduct(a,b) = {a[i]*b[j]}, has shape (len(a),len(b))\"\"\"\n fa = filled(a,0).ravel()\n fb = filled(b,0).ravel()\n d = numeric.outerproduct(fa, fb)\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n return masked_array(d)\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = make_mask(1-numeric.outerproduct(1-ma,1-mb), copy=0)\n return masked_array(d, m)\n\ndef dot(a, b):\n \"\"\"dot(a,b) returns matrix-multiplication between a and b. The product-sum\n is over the last dimension of a and the second-to-last dimension of b.\n Masked values are replaced by zeros. See also innerproduct.\n \"\"\"\n return innerproduct(filled(a,0), numeric.swapaxes(filled(b,0), -1, -2))\n\ndef compress(condition, x, dimension=-1):\n \"\"\"Select those parts of x for which condition is true.\n Masked values in condition are considered false.\n \"\"\"\n c = filled(condition, 0)\n m = getmask(x)\n if m is not nomask:\n m=numeric.compress(c, m, dimension)\n d = numeric.compress(c, filled(x), dimension)\n return masked_array(d, m)\n\nclass _minimum_operation:\n \"Object to calculate minima\"\n def __init__ (self):\n \"\"\"minimum(a, b) or minimum(a)\n In one argument case returns the scalar minimum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is nomask:\n d = amin(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amin(ac.raw_data())\n else:\n return where(less(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is nomask:\n t = filled(target)\n return masked_array (umath.minimum.reduce (t, axis))\n else:\n t = umath.minimum.reduce(filled(target, minimum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.minimum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nminimum = _minimum_operation ()\n\nclass _maximum_operation:\n \"Object to calculate maxima\"\n def __init__ (self):\n \"\"\"maximum(a, b) or maximum(a)\n In one argument case returns the scalar maximum.\n \"\"\"\n pass\n\n def __call__ (self, a, b=None):\n \"Execute the call behavior.\"\n if b is None:\n m = getmask(a)\n if m is nomask:\n d = amax(filled(a).ravel())\n return d\n ac = a.compressed()\n if len(ac) == 0:\n return masked\n else:\n return amax(ac.raw_data())\n else:\n return where(greater(a, b), a, b)\n\n def reduce (self, target, axis=0):\n \"\"\"Reduce target along the given axis.\"\"\"\n m = getmask(target)\n if m is nomask:\n t = filled(target)\n return masked_array (umath.maximum.reduce (t, axis))\n else:\n t = umath.maximum.reduce(filled(target, maximum_fill_value(target)), axis)\n m = umath.logical_and.reduce(m, axis)\n return masked_array(t, m, get_fill_value(target))\n\n def outer (self, a, b):\n \"Return the function applied to the outer product of a and b.\"\n ma = getmask(a)\n mb = getmask(b)\n if ma is nomask and mb is nomask:\n m = nomask\n else:\n ma = getmaskarray(a)\n mb = getmaskarray(b)\n m = logical_or.outer(ma, mb)\n d = umath.maximum.outer(filled(a), filled(b))\n return masked_array(d, m)\n\nmaximum = _maximum_operation ()\n\ndef sort (x, axis = -1, fill_value=None):\n \"\"\"If x does not have a mask, return a masked array formed from the\n result of numeric.sort(x, axis).\n Otherwise, fill x with fill_value. Sort it.\n Set a mask where the result is equal to fill_value.\n Note that this may have unintended consequences if the data contains the\n fill value at a non-masked site.\n\n If fill_value is not given the default fill value for x's type will be\n used.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n d = filled(x, fill_value)\n s = oldnumeric.sort(d, axis)\n if getmask(x) is nomask:\n return masked_array(s)\n return masked_values(s, fill_value, copy=0)\n\ndef diagonal(a, k = 0, axis1=0, axis2=1):\n \"\"\"diagonal(a,k=0,axis1=0, axis2=1) = the k'th diagonal of a\"\"\"\n d = oldnumeric.diagonal(filled(a), k, axis1, axis2)\n m = getmask(a)\n if m is nomask:\n return masked_array(d, m)\n else:\n return masked_array(d, oldnumeric.diagonal(m, k, axis1, axis2))\n\ndef argsort (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for sorting along given axis.\n if fill_value is None, use get_fill_value(x)\n Returns a numpy array.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argsort(d, axis)\n\ndef argmin (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return indices for minimum values along given axis.\n if fill_value is None, use get_fill_value(x).\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n d = filled(x, fill_value)\n return oldnumeric.argmin(d, axis)\n\ndef argmax (x, axis = -1, fill_value=None):\n \"\"\"Treating masked values as if they have the value fill_value,\n return sort indices for maximum along given axis.\n if fill_value is None, use -get_fill_value(x) if it exists.\n Returns a numpy array if x has more than one dimension.\n Otherwise, returns a scalar index.\n \"\"\"\n if fill_value is None:\n fill_value = default_fill_value (x)\n try:\n fill_value = - fill_value\n except:\n pass\n d = filled(x, fill_value)\n return oldnumeric.argmax(d, axis)\n\ndef fromfunction (f, s):\n \"\"\"apply f to s to create array as in umath.\"\"\"\n return masked_array(numeric.fromfunction(f,s))\n\ndef asarray(data, dtype=None):\n \"\"\"asarray(data, dtype) = array(data, dtype, copy=0)\n \"\"\"\n if isinstance(data, MaskedArray) and \\\n (dtype is None or dtype == data.dtype):\n return data\n return array(data, dtype=dtype, copy=0)\n\n# Add methods to support ndarray interface\n# XXX: I is better to to change the masked_*_operation adaptors\n# XXX: to wrap ndarray methods directly to create ma.array methods.\nfrom types import MethodType\ndef _m(f):\n return MethodType(f, None, array)\ndef not_implemented(*args, **kwds):\n raise NotImplementedError, \"not yet implemented for numpy.ma arrays\"\narray.all = _m(alltrue)\narray.any = _m(sometrue)\narray.argmax = _m(argmax)\narray.argmin = _m(argmin)\narray.argsort = _m(argsort)\narray.base = property(_m(not_implemented))\narray.byteswap = _m(not_implemented)\n\ndef _choose(self, *args):\n return choose(self, args)\narray.choose = _m(_choose)\ndel _choose\n\narray.clip = _m(not_implemented)\n\ndef _compress(self, cond, axis=None):\n return compress(cond, self, axis)\narray.compress = _m(_compress)\ndel _compress\n\narray.conj = array.conjugate = _m(conjugate)\narray.copy = _m(not_implemented)\narray.cumprod = _m(not_implemented)\narray.cumsum = _m(not_implemented)\narray.diagonal = _m(diagonal)\narray.dtypedescr = property(_m(not_implemented))\narray.dtypestr = property(_m(not_implemented))\narray.dump = _m(not_implemented)\narray.dumps = _m(not_implemented)\narray.fill = _m(not_implemented)\narray.flags = property(_m(not_implemented))\narray.flatten = _m(ravel)\narray.getfield = _m(not_implemented)\narray.max = _m(maximum)\narray.mean = _m(average)\narray.min = _m(minimum)\narray.nbytes = property(_m(not_implemented))\narray.ndim = _m(not_implemented)\narray.newbyteorder = _m(not_implemented)\narray.nonzero = _m(nonzero)\narray.prod = _m(product)\narray.ptp = _m(not_implemented)\narray.repeat = _m(repeat)\narray.resize = _m(resize)\narray.searchsorted = _m(not_implemented)\narray.setfield = _m(not_implemented)\narray.setflags = _m(not_implemented)\narray.sort = _m(not_implemented) # NB: ndarray.sort is inplace\narray.squeeze = _m(not_implemented)\narray.std = _m(not_implemented)\narray.strides = property(_m(not_implemented))\narray.sum = _m(sum)\narray.swapaxes = _m(not_implemented)\narray.take = _m(take)\narray.tofile = _m(not_implemented)\narray.trace = _m(not_implemented)\narray.transpose = _m(transpose)\narray.var = _m(not_implemented)\narray.view = _m(not_implemented)\ndel _m, MethodType, not_implemented\n\n\nmasked = MaskedArray(0, int, mask=1)\n", + "methods": [ + { + "name": "__init__", + "long_name": "__init__( self , args = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 29, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 32, + "end_line": 34, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , display )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "display" + ], + "start_line": 39, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "display", + "long_name": "display( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 44, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "set_display", + "long_name": "set_display( self , s )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "s" + ], + "start_line": 48, + "end_line": 50, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enabled", + "long_name": "enabled( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 52, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enable", + "long_name": "enable( self , flag = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "flag" + ], + "start_line": 56, + "end_line": 58, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 60, + "end_line": 61, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "default_fill_value", + "long_name": "default_fill_value( obj )", + "filename": "ma.py", + "nloc": 25, + "complexity": 13, + "token_count": 144, + "parameters": [ + "obj" + ], + "start_line": 75, + "end_line": 99, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "minimum_fill_value", + "long_name": "minimum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 105, + "parameters": [ + "obj" + ], + "start_line": 101, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "maximum_fill_value", + "long_name": "maximum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 103, + "parameters": [ + "obj" + ], + "start_line": 118, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( a , fill_value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 2, + "token_count": 20, + "parameters": [ + "a", + "fill_value" + ], + "start_line": 135, + "end_line": 138, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "getmask", + "long_name": "getmask( a )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "a" + ], + "start_line": 140, + "end_line": 147, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "getmaskarray", + "long_name": "getmaskarray( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 149, + "end_line": 158, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "is_mask", + "long_name": "is_mask( m )", + "filename": "ma.py", + "nloc": 6, + "complexity": 4, + "token_count": 33, + "parameters": [ + "m" + ], + "start_line": 160, + "end_line": 167, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "make_mask", + "long_name": "make_mask( m , copy = 0 , flag = 0 )", + "filename": "ma.py", + "nloc": 17, + "complexity": 7, + "token_count": 107, + "parameters": [ + "m", + "copy", + "flag" + ], + "start_line": 169, + "end_line": 192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "make_mask_none", + "long_name": "make_mask_none( s )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 25, + "parameters": [ + "s" + ], + "start_line": 194, + "end_line": 198, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "mask_or", + "long_name": "mask_or( m1 , m2 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 5, + "token_count": 52, + "parameters": [ + "m1", + "m2" + ], + "start_line": 200, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "filled", + "long_name": "filled( a , value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 5, + "token_count": 70, + "parameters": [ + "a", + "value" + ], + "start_line": 209, + "end_line": 227, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "get_fill_value", + "long_name": "get_fill_value( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 229, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "common_fill_value", + "long_name": "common_fill_value( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a", + "b" + ], + "start_line": 240, + "end_line": 245, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , y1 , y2 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "y1", + "y2" + ], + "start_line": 250, + "end_line": 253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 35, + "parameters": [ + "self", + "x" + ], + "start_line": 255, + "end_line": 259, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , eps )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "eps" + ], + "start_line": 263, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "x" + ], + "start_line": 267, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 273, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 277, + "end_line": 279, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 283, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 287, + "end_line": 289, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , aufunc , fill = 0 , domain = None )", + "filename": "ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 59, + "parameters": [ + "self", + "aufunc", + "fill", + "domain" + ], + "start_line": 292, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 16, + "complexity": 5, + "token_count": 112, + "parameters": [ + "self", + "a", + "args", + "kwargs" + ], + "start_line": 305, + "end_line": 321, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 323, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , tolerance = divide_tolerance )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "tolerance" + ], + "start_line": 328, + "end_line": 329, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 330, + "end_line": 331, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , domain , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 67, + "parameters": [ + "self", + "abfunc", + "domain", + "fillx", + "filly" + ], + "start_line": 337, + "end_line": 347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 147, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 349, + "end_line": 370, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 372, + "end_line": 373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 60, + "parameters": [ + "self", + "abfunc", + "fillx", + "filly" + ], + "start_line": 376, + "end_line": 385, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 113, + "parameters": [ + "self", + "a", + "b", + "args", + "kwargs" + ], + "start_line": 387, + "end_line": 401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 20, + "complexity": 6, + "token_count": 157, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 403, + "end_line": 423, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 425, + "end_line": 436, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "accumulate", + "long_name": "accumulate( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 438, + "end_line": 441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 442, + "end_line": 443, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "rank", + "long_name": "rank( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 505, + "end_line": 506, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 508, + "end_line": 509, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( object , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 21, + "parameters": [ + "object", + "axis" + ], + "start_line": 511, + "end_line": 512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , data , dtype = None , copy = True , fortran = False , mask = nomask , fill_value = None )", + "filename": "ma.py", + "nloc": 56, + "complexity": 18, + "token_count": 379, + "parameters": [ + "self", + "data", + "dtype", + "copy", + "fortran", + "mask", + "fill_value" + ], + "start_line": 543, + "end_line": 605, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "__array__", + "long_name": "__array__( self , t = None )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 67, + "parameters": [ + "self", + "t" + ], + "start_line": 607, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__array_wrap__", + "long_name": "__array_wrap__( self , array , context )", + "filename": "ma.py", + "nloc": 17, + "complexity": 8, + "token_count": 142, + "parameters": [ + "self", + "array", + "context" + ], + "start_line": 624, + "end_line": 646, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "_get_shape", + "long_name": "_get_shape( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 648, + "end_line": 650, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_set_shape", + "long_name": "_set_shape( self , newshape )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "newshape" + ], + "start_line": 652, + "end_line": 657, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_get_flat", + "long_name": "_get_flat( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 659, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "_set_flat", + "long_name": "_set_flat( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "value" + ], + "start_line": 670, + "end_line": 673, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_real", + "long_name": "_get_real( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 675, + "end_line": 682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_real", + "long_name": "_set_real( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 684, + "end_line": 687, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_imaginary", + "long_name": "_get_imaginary( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 689, + "end_line": 696, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_imaginary", + "long_name": "_set_imaginary( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 698, + "end_line": 701, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 13, + "complexity": 6, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 703, + "end_line": 723, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "ma.py", + "nloc": 42, + "complexity": 5, + "token_count": 207, + "parameters": [ + "self" + ], + "start_line": 725, + "end_line": 770, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 1 + }, + { + "name": "__float__", + "long_name": "__float__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 772, + "end_line": 777, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__int__", + "long_name": "__int__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 779, + "end_line": 784, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , i )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 70, + "parameters": [ + "self", + "i" + ], + "start_line": 786, + "end_line": 800, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 802, + "end_line": 810, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__setitem__", + "long_name": "__setitem__( self , index , value )", + "filename": "ma.py", + "nloc": 27, + "complexity": 7, + "token_count": 157, + "parameters": [ + "self", + "index", + "value" + ], + "start_line": 817, + "end_line": 843, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "__setslice__", + "long_name": "__setslice__( self , i , j , value )", + "filename": "ma.py", + "nloc": 23, + "complexity": 7, + "token_count": 155, + "parameters": [ + "self", + "i", + "j", + "value" + ], + "start_line": 845, + "end_line": 867, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "__nonzero__", + "long_name": "__nonzero__( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 869, + "end_line": 879, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 881, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__and__", + "long_name": "__and__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 886, + "end_line": 888, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__or__", + "long_name": "__or__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 890, + "end_line": 892, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__xor__", + "long_name": "__xor__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 894, + "end_line": 896, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__abs__", + "long_name": "__abs__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 902, + "end_line": 904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__neg__", + "long_name": "__neg__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 906, + "end_line": 908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pos__", + "long_name": "__pos__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 910, + "end_line": 912, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__add__", + "long_name": "__add__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 914, + "end_line": 916, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mod__", + "long_name": "__mod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 920, + "end_line": 922, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rmod__", + "long_name": "__rmod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 924, + "end_line": 926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__lshift__", + "long_name": "__lshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 928, + "end_line": 929, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__rshift__", + "long_name": "__rshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 931, + "end_line": 932, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__sub__", + "long_name": "__sub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 934, + "end_line": 936, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rsub__", + "long_name": "__rsub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 938, + "end_line": 940, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mul__", + "long_name": "__mul__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 942, + "end_line": 944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__div__", + "long_name": "__div__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 948, + "end_line": 950, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rdiv__", + "long_name": "__rdiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 952, + "end_line": 954, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__truediv__", + "long_name": "__truediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 956, + "end_line": 958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rtruediv__", + "long_name": "__rtruediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 960, + "end_line": 962, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__floordiv__", + "long_name": "__floordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 964, + "end_line": 966, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rfloordiv__", + "long_name": "__rfloordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 968, + "end_line": 970, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pow__", + "long_name": "__pow__( self , other , third = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "other", + "third" + ], + "start_line": 972, + "end_line": 974, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__sqrt__", + "long_name": "__sqrt__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 976, + "end_line": 978, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__iadd__", + "long_name": "__iadd__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 980, + "end_line": 1021, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__imul__", + "long_name": "__imul__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 251, + "parameters": [ + "self", + "other" + ], + "start_line": 1023, + "end_line": 1064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__isub__", + "long_name": "__isub__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 1066, + "end_line": 1107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__idiv__", + "long_name": "__idiv__( self , other )", + "filename": "ma.py", + "nloc": 38, + "complexity": 12, + "token_count": 233, + "parameters": [ + "self", + "other" + ], + "start_line": 1111, + "end_line": 1148, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 1 + }, + { + "name": "__eq__", + "long_name": "__eq__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1150, + "end_line": 1151, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ne__", + "long_name": "__ne__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1153, + "end_line": 1154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__lt__", + "long_name": "__lt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1156, + "end_line": 1157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__le__", + "long_name": "__le__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1159, + "end_line": 1160, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__gt__", + "long_name": "__gt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1162, + "end_line": 1163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ge__", + "long_name": "__ge__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1165, + "end_line": 1166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "astype", + "long_name": "astype( self , tc )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "tc" + ], + "start_line": 1168, + "end_line": 1171, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "byte_swapped", + "long_name": "byte_swapped( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 1173, + "end_line": 1177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "compressed", + "long_name": "compressed( self )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 1179, + "end_line": 1187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "count", + "long_name": "count( self , axis = None )", + "filename": "ma.py", + "nloc": 29, + "complexity": 7, + "token_count": 173, + "parameters": [ + "self", + "axis" + ], + "start_line": 1189, + "end_line": 1217, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "dot", + "long_name": "dot( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1219, + "end_line": 1221, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "fill_value", + "long_name": "fill_value( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1223, + "end_line": 1225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "filled", + "long_name": "filled( self , fill_value = None )", + "filename": "ma.py", + "nloc": 31, + "complexity": 9, + "token_count": 183, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1227, + "end_line": 1267, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + }, + { + "name": "ids", + "long_name": "ids( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 1269, + "end_line": 1271, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "iscontiguous", + "long_name": "iscontiguous( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 1273, + "end_line": 1275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "itemsize", + "long_name": "itemsize( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 1277, + "end_line": 1279, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1282, + "end_line": 1284, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "put", + "long_name": "put( self , values )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "values" + ], + "start_line": 1286, + "end_line": 1296, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "putmask", + "long_name": "putmask( self , values )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "values" + ], + "start_line": 1298, + "end_line": 1306, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "ravel", + "long_name": "ravel( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 1308, + "end_line": 1313, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "raw_data", + "long_name": "raw_data( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1315, + "end_line": 1319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "raw_mask", + "long_name": "raw_mask( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1323, + "end_line": 1327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "reshape", + "long_name": "reshape( self , * s )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self", + "s" + ], + "start_line": 1331, + "end_line": 1338, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( self , v = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self", + "v" + ], + "start_line": 1340, + "end_line": 1344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_size", + "long_name": "_get_size( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1346, + "end_line": 1347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtypechar", + "long_name": "_get_dtypechar( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1351, + "end_line": 1352, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtype", + "long_name": "_get_dtype( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1355, + "end_line": 1356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "item", + "long_name": "item( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 4, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 1359, + "end_line": 1368, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "tolist", + "long_name": "tolist( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1370, + "end_line": 1372, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "tostring", + "long_name": "tostring( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1374, + "end_line": 1376, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "unmask", + "long_name": "unmask( self )", + "filename": "ma.py", + "nloc": 7, + "complexity": 3, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 1378, + "end_line": 1384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "unshare_mask", + "long_name": "unshare_mask( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 1386, + "end_line": 1390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "isMaskedArray", + "long_name": "isMaskedArray( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "x" + ], + "start_line": 1410, + "end_line": 1412, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "allclose", + "long_name": "allclose( a , b , fill_value = 1 , rtol = 1 . e - 5 , atol = 1 . e - 8 )", + "filename": "ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 140, + "parameters": [ + "a", + "b", + "fill_value", + "rtol", + "atol" + ], + "start_line": 1417, + "end_line": 1432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "allequal", + "long_name": "allequal( a , b , fill_value = 1 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 3, + "token_count": 125, + "parameters": [ + "a", + "b", + "fill_value" + ], + "start_line": 1434, + "end_line": 1452, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "masked_values", + "long_name": "masked_values( data , value , rtol = 1 . e - 5 , atol = 1 . e - 8 , copy = 1 )", + "filename": "ma.py", + "nloc": 10, + "complexity": 2, + "token_count": 115, + "parameters": [ + "data", + "value", + "rtol", + "atol", + "copy" + ], + "start_line": 1454, + "end_line": 1473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "masked_object", + "long_name": "masked_object( data , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "data", + "value", + "copy" + ], + "start_line": 1475, + "end_line": 1479, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayrange", + "long_name": "arrayrange( start , stop = None , step = 1 , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 34, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 1481, + "end_line": 1485, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "fromstring", + "long_name": "fromstring( s , t )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "s", + "t" + ], + "start_line": 1489, + "end_line": 1491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "left_shift", + "long_name": "left_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1493, + "end_line": 1501, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "right_shift", + "long_name": "right_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1503, + "end_line": 1511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 1513, + "end_line": 1521, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 101, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 1523, + "end_line": 1538, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "identity", + "long_name": "identity( n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "n" + ], + "start_line": 1540, + "end_line": 1543, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "indices", + "long_name": "indices( dimensions , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "dimensions", + "dtype" + ], + "start_line": 1545, + "end_line": 1549, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "zeros", + "long_name": "zeros( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1551, + "end_line": 1554, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ones", + "long_name": "ones( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1556, + "end_line": 1559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "count", + "long_name": "count( a , axis = None )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a", + "axis" + ], + "start_line": 1562, + "end_line": 1565, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "power", + "long_name": "power( a , b , third = None )", + "filename": "ma.py", + "nloc": 18, + "complexity": 4, + "token_count": 152, + "parameters": [ + "a", + "b", + "third" + ], + "start_line": 1567, + "end_line": 1584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "masked_array", + "long_name": "masked_array( a , mask = nomask , fill_value = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "mask", + "fill_value" + ], + "start_line": 1586, + "end_line": 1590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "average", + "long_name": "average( a , axis = 0 , weights = None , returned = 0 )", + "filename": "ma.py", + "nloc": 92, + "complexity": 22, + "token_count": 741, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 1595, + "end_line": 1702, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "where", + "long_name": "where( condition , x , y )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 149, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 1704, + "end_line": 1730, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "choose.fmask", + "long_name": "choose.fmask( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 2, + "token_count": 17, + "parameters": [ + "x" + ], + "start_line": 1734, + "end_line": 1736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "choose.nmask", + "long_name": "choose.nmask( x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 3, + "token_count": 27, + "parameters": [ + "x" + ], + "start_line": 1737, + "end_line": 1741, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "choose", + "long_name": "choose( indices , t )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 93, + "parameters": [ + "indices", + "t" + ], + "start_line": 1732, + "end_line": 1748, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "masked_where", + "long_name": "masked_where( condition , x , copy = 1 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 47, + "parameters": [ + "condition", + "x", + "copy" + ], + "start_line": 1750, + "end_line": 1756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "masked_greater", + "long_name": "masked_greater( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1758, + "end_line": 1760, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_greater_equal", + "long_name": "masked_greater_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1762, + "end_line": 1764, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less", + "long_name": "masked_less( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1766, + "end_line": 1768, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less_equal", + "long_name": "masked_less_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1770, + "end_line": 1772, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_not_equal", + "long_name": "masked_not_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1774, + "end_line": 1779, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "masked_equal", + "long_name": "masked_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1781, + "end_line": 1788, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "masked_inside", + "long_name": "masked_inside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1790, + "end_line": 1801, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "masked_outside", + "long_name": "masked_outside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1803, + "end_line": 1814, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , * newshape )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 56, + "parameters": [ + "a", + "newshape" + ], + "start_line": 1816, + "end_line": 1823, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( a )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "a" + ], + "start_line": 1825, + "end_line": 1832, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "concatenate", + "long_name": "concatenate( arrays , axis = 0 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 5, + "token_count": 97, + "parameters": [ + "arrays", + "axis" + ], + "start_line": 1834, + "end_line": 1848, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 76, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 1850, + "end_line": 1858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "a", + "axes" + ], + "start_line": 1860, + "end_line": 1868, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , indices , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 70, + "parameters": [ + "a", + "indices", + "values" + ], + "start_line": 1871, + "end_line": 1884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 61, + "parameters": [ + "a", + "mask", + "values" + ], + "start_line": 1886, + "end_line": 1894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "innerproduct", + "long_name": "innerproduct( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 3, + "token_count": 72, + "parameters": [ + "a", + "b" + ], + "start_line": 1896, + "end_line": 1906, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "outerproduct", + "long_name": "outerproduct( a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 110, + "parameters": [ + "a", + "b" + ], + "start_line": 1908, + "end_line": 1920, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dot", + "long_name": "dot( a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 36, + "parameters": [ + "a", + "b" + ], + "start_line": 1922, + "end_line": 1927, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , x , dimension = - 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 67, + "parameters": [ + "condition", + "x", + "dimension" + ], + "start_line": 1929, + "end_line": 1938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1942, + "end_line": 1946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1948, + "end_line": 1961, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1963, + "end_line": 1972, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1974, + "end_line": 1985, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1991, + "end_line": 1995, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1997, + "end_line": 2010, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 2012, + "end_line": 2021, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 2023, + "end_line": 2034, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "sort", + "long_name": "sort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 8, + "complexity": 3, + "token_count": 68, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2038, + "end_line": 2055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , k = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 73, + "parameters": [ + "a", + "k", + "axis1", + "axis2" + ], + "start_line": 2057, + "end_line": 2064, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2066, + "end_line": 2073, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2075, + "end_line": 2083, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 52, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2085, + "end_line": 2099, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "fromfunction", + "long_name": "fromfunction( f , s )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "f", + "s" + ], + "start_line": 2101, + "end_line": 2103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( data , dtype = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 46, + "parameters": [ + "data", + "dtype" + ], + "start_line": 2105, + "end_line": 2111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_m", + "long_name": "_m( f )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "f" + ], + "start_line": 2117, + "end_line": 2118, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "not_implemented", + "long_name": "not_implemented( * args , ** kwds )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "args", + "kwds" + ], + "start_line": 2119, + "end_line": 2120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_choose", + "long_name": "_choose( self , * args )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 2129, + "end_line": 2130, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_compress", + "long_name": "_compress( self , cond , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "cond", + "axis" + ], + "start_line": 2136, + "end_line": 2137, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "__init__", + "long_name": "__init__( self , args = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 25, + "end_line": 27, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 28, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , display )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "display" + ], + "start_line": 35, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "display", + "long_name": "display( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 40, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "set_display", + "long_name": "set_display( self , s )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "s" + ], + "start_line": 44, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enabled", + "long_name": "enabled( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 48, + "end_line": 50, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "enable", + "long_name": "enable( self , flag = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "flag" + ], + "start_line": 52, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 56, + "end_line": 57, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "default_fill_value", + "long_name": "default_fill_value( obj )", + "filename": "ma.py", + "nloc": 25, + "complexity": 13, + "token_count": 144, + "parameters": [ + "obj" + ], + "start_line": 71, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 0 + }, + { + "name": "minimum_fill_value", + "long_name": "minimum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 105, + "parameters": [ + "obj" + ], + "start_line": 97, + "end_line": 112, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "maximum_fill_value", + "long_name": "maximum_fill_value( obj )", + "filename": "ma.py", + "nloc": 16, + "complexity": 9, + "token_count": 103, + "parameters": [ + "obj" + ], + "start_line": 114, + "end_line": 129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( a , fill_value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 2, + "token_count": 20, + "parameters": [ + "a", + "fill_value" + ], + "start_line": 131, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "getmask", + "long_name": "getmask( a )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 24, + "parameters": [ + "a" + ], + "start_line": 136, + "end_line": 143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "getmaskarray", + "long_name": "getmaskarray( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 145, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "is_mask", + "long_name": "is_mask( m )", + "filename": "ma.py", + "nloc": 6, + "complexity": 4, + "token_count": 33, + "parameters": [ + "m" + ], + "start_line": 156, + "end_line": 163, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "make_mask", + "long_name": "make_mask( m , copy = 0 , flag = 0 )", + "filename": "ma.py", + "nloc": 17, + "complexity": 7, + "token_count": 107, + "parameters": [ + "m", + "copy", + "flag" + ], + "start_line": 165, + "end_line": 188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "make_mask_none", + "long_name": "make_mask_none( s )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 25, + "parameters": [ + "s" + ], + "start_line": 190, + "end_line": 194, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "mask_or", + "long_name": "mask_or( m1 , m2 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 5, + "token_count": 52, + "parameters": [ + "m1", + "m2" + ], + "start_line": 196, + "end_line": 203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "filled", + "long_name": "filled( a , value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 5, + "token_count": 70, + "parameters": [ + "a", + "value" + ], + "start_line": 205, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "get_fill_value", + "long_name": "get_fill_value( a )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a" + ], + "start_line": 225, + "end_line": 234, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "common_fill_value", + "long_name": "common_fill_value( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 29, + "parameters": [ + "a", + "b" + ], + "start_line": 236, + "end_line": 241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , y1 , y2 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "y1", + "y2" + ], + "start_line": 246, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 35, + "parameters": [ + "self", + "x" + ], + "start_line": 251, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , eps )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "eps" + ], + "start_line": 259, + "end_line": 261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "x" + ], + "start_line": 263, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 269, + "end_line": 271, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 273, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , critical_value )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self", + "critical_value" + ], + "start_line": 279, + "end_line": 281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "x" + ], + "start_line": 283, + "end_line": 285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , aufunc , fill = 0 , domain = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "aufunc", + "fill", + "domain" + ], + "start_line": 288, + "end_line": 297, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 16, + "complexity": 5, + "token_count": 112, + "parameters": [ + "self", + "a", + "args", + "kwargs" + ], + "start_line": 299, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 317, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , tolerance = divide_tolerance )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "tolerance" + ], + "start_line": 322, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 324, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , domain , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 53, + "parameters": [ + "self", + "abfunc", + "domain", + "fillx", + "filly" + ], + "start_line": 331, + "end_line": 339, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 147, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 341, + "end_line": 362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 364, + "end_line": 365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 46, + "parameters": [ + "self", + "abfunc", + "fillx", + "filly" + ], + "start_line": 368, + "end_line": 375, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b , * args , ** kwargs )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 113, + "parameters": [ + "self", + "a", + "b", + "args", + "kwargs" + ], + "start_line": 377, + "end_line": 391, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 20, + "complexity": 6, + "token_count": 157, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 393, + "end_line": 413, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 415, + "end_line": 426, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "accumulate", + "long_name": "accumulate( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 428, + "end_line": 431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 432, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "rank", + "long_name": "rank( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 495, + "end_line": 496, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "shape", + "long_name": "shape( object )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "object" + ], + "start_line": 498, + "end_line": 499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "size", + "long_name": "size( object , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 21, + "parameters": [ + "object", + "axis" + ], + "start_line": 501, + "end_line": 502, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , data , dtype = None , copy = True , fortran = False , mask = nomask , fill_value = None )", + "filename": "ma.py", + "nloc": 56, + "complexity": 18, + "token_count": 379, + "parameters": [ + "self", + "data", + "dtype", + "copy", + "fortran", + "mask", + "fill_value" + ], + "start_line": 533, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 63, + "top_nesting_level": 1 + }, + { + "name": "__array__", + "long_name": "__array__( self , t = None )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 67, + "parameters": [ + "self", + "t" + ], + "start_line": 597, + "end_line": 612, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "__array_wrap__", + "long_name": "__array_wrap__( self , array )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "array" + ], + "start_line": 614, + "end_line": 618, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_shape", + "long_name": "_get_shape( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 620, + "end_line": 622, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "_set_shape", + "long_name": "_set_shape( self , newshape )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "newshape" + ], + "start_line": 624, + "end_line": 629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "_get_flat", + "long_name": "_get_flat( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 631, + "end_line": 640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "_set_flat", + "long_name": "_set_flat( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "value" + ], + "start_line": 642, + "end_line": 645, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_real", + "long_name": "_get_real( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 647, + "end_line": 654, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_real", + "long_name": "_set_real( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 656, + "end_line": 659, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "_get_imaginary", + "long_name": "_get_imaginary( self )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 63, + "parameters": [ + "self" + ], + "start_line": 661, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "_set_imaginary", + "long_name": "_set_imaginary( self , value )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self", + "value" + ], + "start_line": 670, + "end_line": 673, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "ma.py", + "nloc": 13, + "complexity": 6, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 675, + "end_line": 695, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "ma.py", + "nloc": 42, + "complexity": 5, + "token_count": 207, + "parameters": [ + "self" + ], + "start_line": 697, + "end_line": 742, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 46, + "top_nesting_level": 1 + }, + { + "name": "__float__", + "long_name": "__float__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 744, + "end_line": 749, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__int__", + "long_name": "__int__( self )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 751, + "end_line": 756, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__getitem__", + "long_name": "__getitem__( self , i )", + "filename": "ma.py", + "nloc": 15, + "complexity": 4, + "token_count": 70, + "parameters": [ + "self", + "i" + ], + "start_line": 758, + "end_line": 772, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__getslice__", + "long_name": "__getslice__( self , i , j )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "i", + "j" + ], + "start_line": 774, + "end_line": 782, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__setitem__", + "long_name": "__setitem__( self , index , value )", + "filename": "ma.py", + "nloc": 27, + "complexity": 7, + "token_count": 157, + "parameters": [ + "self", + "index", + "value" + ], + "start_line": 789, + "end_line": 815, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "__setslice__", + "long_name": "__setslice__( self , i , j , value )", + "filename": "ma.py", + "nloc": 23, + "complexity": 7, + "token_count": 155, + "parameters": [ + "self", + "i", + "j", + "value" + ], + "start_line": 817, + "end_line": 839, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "__nonzero__", + "long_name": "__nonzero__( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 841, + "end_line": 851, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "__len__", + "long_name": "__len__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 853, + "end_line": 856, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__and__", + "long_name": "__and__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 858, + "end_line": 860, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__or__", + "long_name": "__or__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 862, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__xor__", + "long_name": "__xor__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 866, + "end_line": 868, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__abs__", + "long_name": "__abs__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 874, + "end_line": 876, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__neg__", + "long_name": "__neg__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 878, + "end_line": 880, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pos__", + "long_name": "__pos__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 882, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__add__", + "long_name": "__add__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 886, + "end_line": 888, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mod__", + "long_name": "__mod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 892, + "end_line": 894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rmod__", + "long_name": "__rmod__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 896, + "end_line": 898, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__lshift__", + "long_name": "__lshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 900, + "end_line": 901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__rshift__", + "long_name": "__rshift__( self , n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "n" + ], + "start_line": 903, + "end_line": 904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__sub__", + "long_name": "__sub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 906, + "end_line": 908, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rsub__", + "long_name": "__rsub__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 910, + "end_line": 912, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__mul__", + "long_name": "__mul__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 914, + "end_line": 916, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__div__", + "long_name": "__div__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 920, + "end_line": 922, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rdiv__", + "long_name": "__rdiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 924, + "end_line": 926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__truediv__", + "long_name": "__truediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 928, + "end_line": 930, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rtruediv__", + "long_name": "__rtruediv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 932, + "end_line": 934, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__floordiv__", + "long_name": "__floordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 936, + "end_line": 938, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__rfloordiv__", + "long_name": "__rfloordiv__( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 940, + "end_line": 942, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__pow__", + "long_name": "__pow__( self , other , third = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "other", + "third" + ], + "start_line": 944, + "end_line": 946, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__sqrt__", + "long_name": "__sqrt__( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 948, + "end_line": 950, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__iadd__", + "long_name": "__iadd__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 952, + "end_line": 993, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__imul__", + "long_name": "__imul__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 251, + "parameters": [ + "self", + "other" + ], + "start_line": 995, + "end_line": 1036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__isub__", + "long_name": "__isub__( self , other )", + "filename": "ma.py", + "nloc": 41, + "complexity": 12, + "token_count": 250, + "parameters": [ + "self", + "other" + ], + "start_line": 1038, + "end_line": 1079, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 42, + "top_nesting_level": 1 + }, + { + "name": "__idiv__", + "long_name": "__idiv__( self , other )", + "filename": "ma.py", + "nloc": 38, + "complexity": 12, + "token_count": 233, + "parameters": [ + "self", + "other" + ], + "start_line": 1083, + "end_line": 1120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 1 + }, + { + "name": "__eq__", + "long_name": "__eq__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1122, + "end_line": 1123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ne__", + "long_name": "__ne__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1125, + "end_line": 1126, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__lt__", + "long_name": "__lt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1128, + "end_line": 1129, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__le__", + "long_name": "__le__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1131, + "end_line": 1132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__gt__", + "long_name": "__gt__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1134, + "end_line": 1135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__ge__", + "long_name": "__ge__( self , other )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "other" + ], + "start_line": 1137, + "end_line": 1138, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "astype", + "long_name": "astype( self , tc )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "tc" + ], + "start_line": 1140, + "end_line": 1143, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "byte_swapped", + "long_name": "byte_swapped( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self" + ], + "start_line": 1145, + "end_line": 1149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "compressed", + "long_name": "compressed( self )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "self" + ], + "start_line": 1151, + "end_line": 1159, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "count", + "long_name": "count( self , axis = None )", + "filename": "ma.py", + "nloc": 29, + "complexity": 7, + "token_count": 173, + "parameters": [ + "self", + "axis" + ], + "start_line": 1161, + "end_line": 1189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "dot", + "long_name": "dot( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1191, + "end_line": 1193, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "fill_value", + "long_name": "fill_value( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1195, + "end_line": 1197, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "filled", + "long_name": "filled( self , fill_value = None )", + "filename": "ma.py", + "nloc": 31, + "complexity": 9, + "token_count": 183, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1199, + "end_line": 1239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + }, + { + "name": "ids", + "long_name": "ids( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 1241, + "end_line": 1243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "iscontiguous", + "long_name": "iscontiguous( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self" + ], + "start_line": 1245, + "end_line": 1247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "itemsize", + "long_name": "itemsize( self )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self" + ], + "start_line": 1249, + "end_line": 1251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , other )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "other" + ], + "start_line": 1254, + "end_line": 1256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "put", + "long_name": "put( self , values )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 65, + "parameters": [ + "self", + "values" + ], + "start_line": 1258, + "end_line": 1268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "putmask", + "long_name": "putmask( self , values )", + "filename": "ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 49, + "parameters": [ + "self", + "values" + ], + "start_line": 1270, + "end_line": 1278, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "ravel", + "long_name": "ravel( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 45, + "parameters": [ + "self" + ], + "start_line": 1280, + "end_line": 1285, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "raw_data", + "long_name": "raw_data( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1287, + "end_line": 1291, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "raw_mask", + "long_name": "raw_mask( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 1295, + "end_line": 1299, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "reshape", + "long_name": "reshape( self , * s )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 52, + "parameters": [ + "self", + "s" + ], + "start_line": 1303, + "end_line": 1310, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "set_fill_value", + "long_name": "set_fill_value( self , v = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 30, + "parameters": [ + "self", + "v" + ], + "start_line": 1312, + "end_line": 1316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "_get_size", + "long_name": "_get_size( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1318, + "end_line": 1319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtypechar", + "long_name": "_get_dtypechar( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1323, + "end_line": 1324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "_get_dtype", + "long_name": "_get_dtype( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 1327, + "end_line": 1328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "item", + "long_name": "item( self )", + "filename": "ma.py", + "nloc": 10, + "complexity": 4, + "token_count": 47, + "parameters": [ + "self" + ], + "start_line": 1331, + "end_line": 1340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "tolist", + "long_name": "tolist( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1342, + "end_line": 1344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "tostring", + "long_name": "tostring( self , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "fill_value" + ], + "start_line": 1346, + "end_line": 1348, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "unmask", + "long_name": "unmask( self )", + "filename": "ma.py", + "nloc": 7, + "complexity": 3, + "token_count": 41, + "parameters": [ + "self" + ], + "start_line": 1350, + "end_line": 1356, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "unshare_mask", + "long_name": "unshare_mask( self )", + "filename": "ma.py", + "nloc": 5, + "complexity": 2, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 1358, + "end_line": 1362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "isMaskedArray", + "long_name": "isMaskedArray( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 13, + "parameters": [ + "x" + ], + "start_line": 1382, + "end_line": 1384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "allclose", + "long_name": "allclose( a , b , fill_value = 1 , rtol = 1 . e - 5 , atol = 1 . e - 8 )", + "filename": "ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 140, + "parameters": [ + "a", + "b", + "fill_value", + "rtol", + "atol" + ], + "start_line": 1389, + "end_line": 1404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "allequal", + "long_name": "allequal( a , b , fill_value = 1 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 3, + "token_count": 125, + "parameters": [ + "a", + "b", + "fill_value" + ], + "start_line": 1406, + "end_line": 1424, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 0 + }, + { + "name": "masked_values", + "long_name": "masked_values( data , value , rtol = 1 . e - 5 , atol = 1 . e - 8 , copy = 1 )", + "filename": "ma.py", + "nloc": 10, + "complexity": 2, + "token_count": 115, + "parameters": [ + "data", + "value", + "rtol", + "atol", + "copy" + ], + "start_line": 1426, + "end_line": 1445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "masked_object", + "long_name": "masked_object( data , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "data", + "value", + "copy" + ], + "start_line": 1447, + "end_line": 1451, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "arrayrange", + "long_name": "arrayrange( start , stop = None , step = 1 , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 34, + "parameters": [ + "start", + "stop", + "step", + "dtype" + ], + "start_line": 1453, + "end_line": 1457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "fromstring", + "long_name": "fromstring( s , t )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 20, + "parameters": [ + "s", + "t" + ], + "start_line": 1461, + "end_line": 1463, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "left_shift", + "long_name": "left_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1465, + "end_line": 1473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "right_shift", + "long_name": "right_shift( a , n )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "n" + ], + "start_line": 1475, + "end_line": 1483, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "resize", + "long_name": "resize( a , new_shape )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 61, + "parameters": [ + "a", + "new_shape" + ], + "start_line": 1485, + "end_line": 1493, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "repeat", + "long_name": "repeat( a , repeats , axis = 0 )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 101, + "parameters": [ + "a", + "repeats", + "axis" + ], + "start_line": 1495, + "end_line": 1510, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "identity", + "long_name": "identity( n )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "n" + ], + "start_line": 1512, + "end_line": 1515, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "indices", + "long_name": "indices( dimensions , dtype = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "dimensions", + "dtype" + ], + "start_line": 1517, + "end_line": 1521, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "zeros", + "long_name": "zeros( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1523, + "end_line": 1526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "ones", + "long_name": "ones( shape , dtype = int )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "shape", + "dtype" + ], + "start_line": 1528, + "end_line": 1531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "count", + "long_name": "count( a , axis = None )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 23, + "parameters": [ + "a", + "axis" + ], + "start_line": 1534, + "end_line": 1537, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "power", + "long_name": "power( a , b , third = None )", + "filename": "ma.py", + "nloc": 18, + "complexity": 4, + "token_count": 152, + "parameters": [ + "a", + "b", + "third" + ], + "start_line": 1539, + "end_line": 1556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "masked_array", + "long_name": "masked_array( a , mask = nomask , fill_value = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 31, + "parameters": [ + "a", + "mask", + "fill_value" + ], + "start_line": 1558, + "end_line": 1562, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "average", + "long_name": "average( a , axis = 0 , weights = None , returned = 0 )", + "filename": "ma.py", + "nloc": 92, + "complexity": 22, + "token_count": 741, + "parameters": [ + "a", + "axis", + "weights", + "returned" + ], + "start_line": 1567, + "end_line": 1674, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 108, + "top_nesting_level": 0 + }, + { + "name": "where", + "long_name": "where( condition , x , y )", + "filename": "ma.py", + "nloc": 21, + "complexity": 5, + "token_count": 149, + "parameters": [ + "condition", + "x", + "y" + ], + "start_line": 1676, + "end_line": 1702, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 0 + }, + { + "name": "choose.fmask", + "long_name": "choose.fmask( x )", + "filename": "ma.py", + "nloc": 3, + "complexity": 2, + "token_count": 17, + "parameters": [ + "x" + ], + "start_line": 1706, + "end_line": 1708, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "choose.nmask", + "long_name": "choose.nmask( x )", + "filename": "ma.py", + "nloc": 5, + "complexity": 3, + "token_count": 27, + "parameters": [ + "x" + ], + "start_line": 1709, + "end_line": 1713, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "choose", + "long_name": "choose( indices , t )", + "filename": "ma.py", + "nloc": 11, + "complexity": 3, + "token_count": 93, + "parameters": [ + "indices", + "t" + ], + "start_line": 1704, + "end_line": 1720, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "masked_where", + "long_name": "masked_where( condition , x , copy = 1 )", + "filename": "ma.py", + "nloc": 4, + "complexity": 1, + "token_count": 47, + "parameters": [ + "condition", + "x", + "copy" + ], + "start_line": 1722, + "end_line": 1728, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "masked_greater", + "long_name": "masked_greater( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1730, + "end_line": 1732, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_greater_equal", + "long_name": "masked_greater_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1734, + "end_line": 1736, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less", + "long_name": "masked_less( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1738, + "end_line": 1740, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_less_equal", + "long_name": "masked_less_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1742, + "end_line": 1744, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "masked_not_equal", + "long_name": "masked_not_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1746, + "end_line": 1751, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "masked_equal", + "long_name": "masked_equal( x , value , copy = 1 )", + "filename": "ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 54, + "parameters": [ + "x", + "value", + "copy" + ], + "start_line": 1753, + "end_line": 1760, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "masked_inside", + "long_name": "masked_inside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1762, + "end_line": 1773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "masked_outside", + "long_name": "masked_outside( x , v1 , v2 , copy = 1 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 84, + "parameters": [ + "x", + "v1", + "v2", + "copy" + ], + "start_line": 1775, + "end_line": 1786, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 0 + }, + { + "name": "reshape", + "long_name": "reshape( a , * newshape )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 56, + "parameters": [ + "a", + "newshape" + ], + "start_line": 1788, + "end_line": 1795, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "ravel", + "long_name": "ravel( a )", + "filename": "ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 49, + "parameters": [ + "a" + ], + "start_line": 1797, + "end_line": 1804, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "concatenate", + "long_name": "concatenate( arrays , axis = 0 )", + "filename": "ma.py", + "nloc": 15, + "complexity": 5, + "token_count": 97, + "parameters": [ + "arrays", + "axis" + ], + "start_line": 1806, + "end_line": 1820, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "take", + "long_name": "take( a , indices , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 76, + "parameters": [ + "a", + "indices", + "axis" + ], + "start_line": 1822, + "end_line": 1830, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "transpose", + "long_name": "transpose( a , axes = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 64, + "parameters": [ + "a", + "axes" + ], + "start_line": 1832, + "end_line": 1840, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "put", + "long_name": "put( a , indices , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 70, + "parameters": [ + "a", + "indices", + "values" + ], + "start_line": 1843, + "end_line": 1856, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "putmask", + "long_name": "putmask( a , mask , values )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 61, + "parameters": [ + "a", + "mask", + "values" + ], + "start_line": 1858, + "end_line": 1866, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "innerproduct", + "long_name": "innerproduct( a , b )", + "filename": "ma.py", + "nloc": 6, + "complexity": 3, + "token_count": 72, + "parameters": [ + "a", + "b" + ], + "start_line": 1868, + "end_line": 1878, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "outerproduct", + "long_name": "outerproduct( a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 110, + "parameters": [ + "a", + "b" + ], + "start_line": 1880, + "end_line": 1892, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "dot", + "long_name": "dot( a , b )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 36, + "parameters": [ + "a", + "b" + ], + "start_line": 1894, + "end_line": 1899, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "compress", + "long_name": "compress( condition , x , dimension = - 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 67, + "parameters": [ + "condition", + "x", + "dimension" + ], + "start_line": 1901, + "end_line": 1910, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1914, + "end_line": 1918, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1920, + "end_line": 1933, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1935, + "end_line": 1944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1946, + "end_line": 1957, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 7, + "parameters": [ + "self" + ], + "start_line": 1963, + "end_line": 1967, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , a , b = None )", + "filename": "ma.py", + "nloc": 14, + "complexity": 4, + "token_count": 87, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1969, + "end_line": 1982, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "reduce", + "long_name": "reduce( self , target , axis = 0 )", + "filename": "ma.py", + "nloc": 9, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "target", + "axis" + ], + "start_line": 1984, + "end_line": 1993, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "outer", + "long_name": "outer( self , a , b )", + "filename": "ma.py", + "nloc": 12, + "complexity": 3, + "token_count": 83, + "parameters": [ + "self", + "a", + "b" + ], + "start_line": 1995, + "end_line": 2006, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "sort", + "long_name": "sort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 8, + "complexity": 3, + "token_count": 68, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2010, + "end_line": 2027, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 0 + }, + { + "name": "diagonal", + "long_name": "diagonal( a , k = 0 , axis1 = 0 , axis2 = 1 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 73, + "parameters": [ + "a", + "k", + "axis1", + "axis2" + ], + "start_line": 2029, + "end_line": 2036, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argsort", + "long_name": "argsort( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2038, + "end_line": 2045, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "argmin", + "long_name": "argmin( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 32, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2047, + "end_line": 2055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 0 + }, + { + "name": "argmax", + "long_name": "argmax( x , axis = - 1 , fill_value = None )", + "filename": "ma.py", + "nloc": 9, + "complexity": 3, + "token_count": 52, + "parameters": [ + "x", + "axis", + "fill_value" + ], + "start_line": 2057, + "end_line": 2071, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "fromfunction", + "long_name": "fromfunction( f , s )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "f", + "s" + ], + "start_line": 2073, + "end_line": 2075, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "asarray", + "long_name": "asarray( data , dtype = None )", + "filename": "ma.py", + "nloc": 5, + "complexity": 4, + "token_count": 46, + "parameters": [ + "data", + "dtype" + ], + "start_line": 2077, + "end_line": 2083, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "_m", + "long_name": "_m( f )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "f" + ], + "start_line": 2089, + "end_line": 2090, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "not_implemented", + "long_name": "not_implemented( * args , ** kwds )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "args", + "kwds" + ], + "start_line": 2091, + "end_line": 2092, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_choose", + "long_name": "_choose( self , * args )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "args" + ], + "start_line": 2101, + "end_line": 2102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "_compress", + "long_name": "_compress( self , cond , axis = None )", + "filename": "ma.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "cond", + "axis" + ], + "start_line": 2108, + "end_line": 2109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "__init__", + "long_name": "__init__( self , abfunc , domain , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 67, + "parameters": [ + "self", + "abfunc", + "domain", + "fillx", + "filly" + ], + "start_line": 337, + "end_line": 347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "__array_wrap__", + "long_name": "__array_wrap__( self , array )", + "filename": "ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "array" + ], + "start_line": 614, + "end_line": 618, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , aufunc , fill = 0 , domain = None )", + "filename": "ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 59, + "parameters": [ + "self", + "aufunc", + "fill", + "domain" + ], + "start_line": 292, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__array_wrap__", + "long_name": "__array_wrap__( self , array , context )", + "filename": "ma.py", + "nloc": 17, + "complexity": 8, + "token_count": 142, + "parameters": [ + "self", + "array", + "context" + ], + "start_line": 624, + "end_line": 646, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , abfunc , fillx = 0 , filly = 0 )", + "filename": "ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 60, + "parameters": [ + "self", + "abfunc", + "fillx", + "filly" + ], + "start_line": 376, + "end_line": 385, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + } + ], + "nloc": 1703, + "complexity": 465, + "token_count": 11859, + "diff_parsed": { + "added": [ + "# Ufunc domain lookup for __array_wrap__", + "ufunc_domain = {}", + "# Ufunc fills lookup for __array__", + "ufunc_fills = {}", + "", + " ufunc_domain[aufunc] = domain", + " ufunc_fills[aufunc] = fill,", + "", + " ufunc_domain[abfunc] = domain", + " ufunc_fills[abfunc] = fillx,filly", + " ufunc_domain[abfunc] = None", + " ufunc_fills[abfunc] = fillx,filly", + " def __array_wrap__ (self, array, context):", + " \"\"\"Special hook for ufuncs.", + "", + " Wraps the numpy array and sets the mask according to", + " context.", + " \"\"\"", + " func, args = context[:2]", + " domain = ufunc_domain[func]", + " fills = ufunc_fills[func]", + " m = reduce(mask_or, [getmask(a) for a in args])", + " if domain is not None:", + " m = mask_or(m, domain(*[filled(a,f) for (a,f)", + " in zip(args, fills)]))", + " if m is not nomask:", + " try:", + " shape = array.shape", + " except AttributeError:", + " pass", + " else:", + " if m.shape != shape:", + " m = reduce(mask_or, [getmaskarray(a) for a in args])", + "", + " return MaskedArray(array, copy=False, mask=m)" + ], + "deleted": [ + "", + "", + " def __array_wrap__ (self, array):", + " \"\"\"Special hook for ufuncs. Converts to Masked array with", + " the same mask as self.\"\"\"", + " return MaskedArray(array, copy=False, mask=self._mask,", + " fill_value = self._fill_value)" + ] + } + }, + { + "old_path": "numpy/core/tests/test_ma.py", + "new_path": "numpy/core/tests/test_ma.py", + "filename": "test_ma.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -2,13 +2,13 @@\n import types, time\n from numpy.core.ma import *\n from numpy.testing import ScipyTestCase, ScipyTest\n-def eq(v,w):\n+def eq(v,w, msg=''):\n result = allclose(v,w)\n if not result:\n- print \"\"\"Not eq:\n+ print \"\"\"Not eq:%s\n %s\n ----\n-%s\"\"\"% (str(v), str(w))\n+%s\"\"\"% (msg, str(v), str(w))\n return result\n \n class test_ma(ScipyTestCase):\n@@ -635,6 +635,47 @@ def check_testSingleElementSubscript(self):\n self.failUnlessEqual(b[0].shape, ())\n self.failUnlessEqual(b[1].shape, ())\n \n+class test_ufuncs(ScipyTestCase):\n+ def setUp(self):\n+ self.d = (array([1.0, 0, -1, pi/2]*2, mask=[0]*8),\n+ array([1.0, 0, -1, pi/2]*2, mask=[0]*8),)\n+ def check_testUfuncRegression(self):\n+ for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate',\n+ 'sin', 'cos', 'tan', \n+ 'arcsin', 'arccos', 'arctan',\n+ 'sinh', 'cosh', 'tanh', \n+ 'arcsinh',\n+ # 'arccosh', # buggy domain\n+ # 'arctanh', # buggy domain\n+ 'absolute', 'fabs', 'negative',\n+ # 'nonzero', 'around',\n+ 'floor', 'ceil',\n+ # 'sometrue', 'alltrue',\n+ 'logical_not',\n+ 'add', 'subtract', 'multiply',\n+ 'divide', 'true_divide', 'floor_divide',\n+ 'remainder', 'fmod', 'hypot', 'arctan2',\n+ 'equal', 'not_equal', 'less_equal', 'greater_equal',\n+ 'less', 'greater',\n+ 'logical_and', 'logical_or', 'logical_xor',\n+ ]:\n+ try:\n+ uf = getattr(umath, f)\n+ except AttributeError:\n+ uf = getattr(oldnumeric, f)\n+ mf = getattr(numpy.ma, f)\n+ args = self.d[:uf.nin]\n+ ur = uf(*args)\n+ mr = mf(*args)\n+ self.failUnless(eq(ur.filled(0), mr.filled(0), f))\n+ self.failUnless(eqmask(ur.mask, mr.mask))\n+\n+def eqmask(m1, m2):\n+ if m1 is nomask:\n+ return m2 is nomask\n+ if m2 is nomask:\n+ return m1 is nomask\n+ return (m1 == m2).all()\n \n def timingTest():\n for f in [testf, testinplace]:\n", + "added_lines": 44, + "deleted_lines": 3, + "source_code": "import numpy \nimport types, time\nfrom numpy.core.ma import *\nfrom numpy.testing import ScipyTestCase, ScipyTest\ndef eq(v,w, msg=''):\n result = allclose(v,w)\n if not result:\n print \"\"\"Not eq:%s\n%s\n----\n%s\"\"\"% (msg, str(v), str(w))\n return result\n\nclass test_ma(ScipyTestCase):\n def __init__(self, *args, **kwds):\n ScipyTestCase.__init__(self, *args, **kwds)\n self.setUp()\n \n def setUp (self):\n x=numpy.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])\n y=numpy.array([5.,0.,3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])\n a10 = 10.\n m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]\n m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0 ,0, 1]\n xm = array(x, mask=m1)\n ym = array(y, mask=m2)\n z = numpy.array([-.5, 0., .5, .8])\n zm = array(z, mask=[0,1,0,0])\n xf = numpy.where(m1, 1.e+20, x)\n s = x.shape\n xm.set_fill_value(1.e+20)\n self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf, s)\n\n def check_testBasic1d(self):\n \"Test of basic array creation and properties in 1 dimension.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual(xm.dtype, x.dtype)\n self.assertEqual(xm.dtypechar, x.dtypechar)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual(count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n\n def check_testBasic2d(self):\n \"Test of basic array creation and properties in 2 dimensions.\"\n for s in [(4,3), (6,2)]: \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n x.shape = s\n y.shape = s\n xm.shape = s\n ym.shape = s\n xf.shape = s\n \n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual( count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n self.setUp()\n\n def check_testArithmetic (self):\n \"Test of basic arithmetic.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n a2d = array([[1,2],[0,4]])\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n self.failUnless(eq (a2d * a2d, a2d * a2dm))\n self.failUnless(eq (a2d + a2d, a2d + a2dm))\n self.failUnless(eq (a2d - a2d, a2d - a2dm))\n for s in [(12,), (4,3), (2,6)]: \n x = x.reshape(s)\n y = y.reshape(s)\n xm = xm.reshape(s)\n ym = ym.reshape(s)\n xf = xf.reshape(s)\n self.failUnless(eq(-x, -xm))\n self.failUnless(eq(x + y, xm + ym))\n self.failUnless(eq(x - y, xm - ym))\n self.failUnless(eq(x * y, xm * ym))\n self.failUnless(eq(x / y, xm / ym))\n self.failUnless(eq(a10 + y, a10 + ym))\n self.failUnless(eq(a10 - y, a10 - ym))\n self.failUnless(eq(a10 * y, a10 * ym))\n self.failUnless(eq(a10 / y, a10 / ym))\n self.failUnless(eq(x + a10, xm + a10))\n self.failUnless(eq(x - a10, xm - a10))\n self.failUnless(eq(x * a10, xm * a10))\n self.failUnless(eq(x / a10, xm / a10))\n self.failUnless(eq(x**2, xm**2))\n self.failUnless(eq(abs(x)**2.5, abs(xm) **2.5))\n self.failUnless(eq(x**y, xm**ym))\n self.failUnless(eq(numpy.add(x,y), add(xm, ym)))\n self.failUnless(eq(numpy.subtract(x,y), subtract(xm, ym)))\n self.failUnless(eq(numpy.multiply(x,y), multiply(xm, ym)))\n self.failUnless(eq(numpy.divide(x,y), divide(xm, ym)))\n\n\n def check_testMixedArithmetic(self):\n na = numpy.array([1])\n ma = array([1])\n self.failUnless(isinstance(na + ma, MaskedArray))\n self.failUnless(isinstance(ma + na, MaskedArray))\n \n def check_testUfuncs1 (self):\n \"Test various functions such as sin, cos.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.cos(x), cos(xm)))\n self.failUnless (eq(numpy.cosh(x), cosh(xm)))\n self.failUnless (eq(numpy.sin(x), sin(xm)))\n self.failUnless (eq(numpy.sinh(x), sinh(xm)))\n self.failUnless (eq(numpy.tan(x), tan(xm)))\n self.failUnless (eq(numpy.tanh(x), tanh(xm)))\n self.failUnless (eq(numpy.sqrt(abs(x)), sqrt(xm)))\n self.failUnless (eq(numpy.log(abs(x)), log(xm)))\n self.failUnless (eq(numpy.log10(abs(x)), log10(xm)))\n self.failUnless (eq(numpy.exp(x), exp(xm)))\n self.failUnless (eq(numpy.arcsin(z), arcsin(zm)))\n self.failUnless (eq(numpy.arccos(z), arccos(zm)))\n self.failUnless (eq(numpy.arctan(z), arctan(zm)))\n self.failUnless (eq(numpy.arctan2(x, y), arctan2(xm, ym)))\n self.failUnless (eq(numpy.absolute(x), absolute(xm)))\n self.failUnless (eq(numpy.equal(x,y), equal(xm, ym)))\n self.failUnless (eq(numpy.not_equal(x,y), not_equal(xm, ym)))\n self.failUnless (eq(numpy.less(x,y), less(xm, ym)))\n self.failUnless (eq(numpy.greater(x,y), greater(xm, ym)))\n self.failUnless (eq(numpy.less_equal(x,y), less_equal(xm, ym)))\n self.failUnless (eq(numpy.greater_equal(x,y), greater_equal(xm, ym)))\n self.failUnless (eq(numpy.conjugate(x), conjugate(xm)))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,ym))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((x,y))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,y))))\n self.failUnless (eq(numpy.concatenate((x,y,x)), concatenate((x,ym,x))))\n \n def check_xtestCount (self):\n \"Test count\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless( isinstance(count(ott), types.IntType))\n self.assertEqual(3, count(ott))\n self.assertEqual(1, count(1))\n self.failUnless (eq(0, array(1,mask=[1])))\n ott=ott.reshape((2,2))\n assert isMaskedArray(count(ott,0))\n assert isinstance(count(ott), types.IntType)\n self.failUnless (eq(3, count(ott)))\n assert getmask(count(ott,0)) is None\n self.failUnless (eq([1,2],count(ott,0)))\n \n def check_testMinMax (self):\n \"Test minimum and maximum.\" \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n xr = numpy.ravel(x) #max doesn't work if shaped\n xmr = ravel(xm)\n self.failUnless (eq(max(xr), maximum(xmr))) #true because of careful selection of data\n self.failUnless (eq(min(xr), minimum(xmr))) #true because of careful selection of data\n\n def check_testAddSumProd (self):\n \"Test add, sum, product.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.add.reduce(x), add.reduce(x)))\n self.failUnless (eq(numpy.add.accumulate(x), add.accumulate(x)))\n self.failUnless (eq(4, sum(array(4))))\n self.failUnless (eq(4, sum(array(4), axis=0)))\n self.failUnless (eq(numpy.sum(x), sum(x)))\n self.failUnless (eq(numpy.sum(filled(xm,0)), sum(xm)))\n self.failUnless (eq(numpy.sum(x,0), sum(x,0)))\n self.failUnless (eq(numpy.product(x), product(x)))\n self.failUnless (eq(numpy.product(x,0), product(x,0)))\n self.failUnless (eq(numpy.product(filled(xm,1)), product(xm)))\n if len(s) > 1:\n self.failUnless (eq(numpy.concatenate((x,y),1), concatenate((xm,ym),1)))\n self.failUnless (eq(numpy.add.reduce(x,1), add.reduce(x,1)))\n self.failUnless (eq(numpy.sum(x,1), sum(x,1)))\n self.failUnless (eq(numpy.product(x,1), product(x,1)))\n \n \n def check_testCI(self):\n \"Test of conversions and indexing\"\n x1 = numpy.array([1,2,4,3])\n x2 = array(x1, mask = [1,0,0,0])\n x3 = array(x1, mask = [0,1,0,1])\n x4 = array(x1)\n # test conversion to strings\n junk, garbage = str(x2), repr(x2)\n assert eq(numpy.sort(x1),sort(x2, fill_value=0))\n # tests of indexing\n assert type(x2[1]) is type(x1[1])\n assert x1[1] == x2[1]\n assert x2[0] is masked\n assert eq(x1[2],x2[2])\n assert eq(x1[2:5],x2[2:5])\n assert eq(x1[:],x2[:])\n assert eq(x1[1:], x3[1:])\n x1[2]=9\n x2[2]=9\n assert eq(x1,x2)\n x1[1:3] = 99\n x2[1:3] = 99\n assert eq(x1,x2)\n x2[1] = masked\n assert eq(x1,x2)\n x2[1:3]=masked\n assert eq(x1,x2)\n x2[:] = x1\n x2[1] = masked\n assert allequal(getmask(x2),array([0,1,0,0]))\n x3[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x3), array([0,1,1,0]))\n x4[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x4), array([0,1,1,0]))\n assert allequal(x4, array([1,2,3,4]))\n x1 = numpy.arange(5)*1.0\n x2 = masked_values(x1, 3.0)\n assert eq(x1,x2)\n assert allequal(array([0,0,0,1,0],MaskType), x2.mask)\n assert eq(3.0, x2.fill_value())\n x1 = array([1,'hello',2,3],object)\n x2 = numpy.array([1,'hello',2,3],object)\n s1 = x1[1]\n s2 = x2[1]\n self.assertEqual(type(s2), str)\n self.assertEqual(type(s1), str)\n self.assertEqual(s1, s2)\n assert x1[1:1].shape == (0,)\n \n def check_testCopySize(self):\n \"Tests of some subtle points of copying and sizing.\"\n n = [0,0,1,0,0]\n m = make_mask(n)\n m2 = make_mask(m)\n self.failUnless(m is m2)\n m3 = make_mask(m, copy=1)\n self.failUnless(m is not m3)\n \n x1 = numpy.arange(5)\n y1 = array(x1, mask=m)\n self.failUnless( y1.raw_data() is not x1)\n self.failUnless( allequal(x1,y1.raw_data()))\n self.failUnless( y1.mask is m)\n \n y1a = array(y1, copy=0)\n self.failUnless( y1a.raw_data() is y1.raw_data())\n self.failUnless( y1a.mask is y1.mask)\n \n y2 = array(x1, mask=m, copy=0)\n self.failUnless( y2.raw_data() is x1)\n self.failUnless( y2.mask is m)\n self.failUnless( y2[2] is masked)\n y2[2]=9\n self.failUnless( y2[2] is not masked)\n self.failUnless( y2.mask is not m)\n self.failUnless( allequal(y2.mask, 0))\n \n y3 = array(x1*1.0, mask=m)\n self.failUnless(filled(y3).dtype is (x1*1.0).dtype)\n \n x4 = arange(4)\n x4[2] = masked\n y4 = resize(x4, (8,))\n self.failUnless( eq(concatenate([x4,x4]), y4))\n self.failUnless( eq(getmask(y4),[0,0,1,0,0,0,1,0]))\n y5 = repeat(x4, (2,2,2,2))\n self.failUnless( eq(y5, [0,0,1,1,2,2,3,3]))\n y6 = repeat(x4, 2)\n self.failUnless( eq(y5, y6))\n \n def check_testPut(self):\n \"Test of put\"\n d = arange(5)\n n = [0,0,0,1,1]\n m = make_mask(n)\n x = array(d, mask = m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n x[[1,4]] = [10,40]\n self.failUnless( x.mask is not m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is not masked)\n self.failUnless( eq(x, [0,10,2,-1,40]))\n \n x = array(d, mask = m) \n x.put([-1,100,200])\n self.failUnless( eq(x, [-1,100,200,0,0]))\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n \n x = array(d, mask = m) \n x.putmask([30,40])\n self.failUnless( eq(x, [0,1,2,30,40]))\n self.failUnless( x.mask is None)\n \n x = array(d, mask = m) \n y = x.compressed()\n z = array(x, mask = m)\n z.put(y)\n assert eq (x, z)\n \n def check_testMaPut(self):\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]\n i = numpy.nonzero(m)\n putmask(xm, m, z)\n assert take(xm, i) == z\n put(ym, i, zm)\n assert take(ym, i) == zm\n \n def check_testOddFeatures(self):\n \"Test of other odd features\"\n x = arange(20); x=x.reshape(4,5)\n x.flat[5] = 12\n assert x[1,0] == 12\n z = x + 10j * x\n assert eq(z.real, x)\n assert eq(z.imag, 10*x)\n assert eq((z*conjugate(z)).real, 101*x*x)\n z.imag[...] = 0.0\n \n x = arange(10)\n x[3] = masked\n assert str(x[3]) == str(masked)\n c = x >= 8\n assert count(where(c,masked,masked)) == 0\n assert shape(where(c,masked,masked)) == c.shape\n z = where(c , x, masked)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is masked\n assert z[7] is masked\n assert z[8] is not masked\n assert z[9] is not masked\n assert eq(x,z)\n z = where(c , masked, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n z = masked_where(c, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n assert eq(x,z)\n x = array([1.,2.,3.,4.,5.])\n c = array([1,1,1,0,0])\n x[2] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n c[0] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n assert eq(masked_where(greater(x, 2), x), masked_greater(x,2))\n assert eq(masked_where(greater_equal(x, 2), x), masked_greater_equal(x,2))\n assert eq(masked_where(less(x, 2), x), masked_less(x,2))\n assert eq(masked_where(less_equal(x, 2), x), masked_less_equal(x,2))\n assert eq(masked_where(not_equal(x, 2), x), masked_not_equal(x,2))\n assert eq(masked_where(equal(x, 2), x), masked_equal(x,2))\n assert eq(masked_where(not_equal(x,2), x), masked_not_equal(x,2))\n assert eq(masked_inside(range(5), 1, 3), [0, 199, 199, 199, 4])\n assert eq(masked_outside(range(5), 1, 3),[199,1,2,3,199])\n assert eq(masked_inside(array(range(5), mask=[1,0,0,0,0]), 1, 3).mask, [1,1,1,1,0])\n assert eq(masked_outside(array(range(5), mask=[0,1,0,0,0]), 1, 3).mask, [1,1,0,0,1])\n assert eq(masked_equal(array(range(5), mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,0])\n assert eq(masked_not_equal(array([2,2,1,2,1], mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,1])\n assert eq(masked_where([1,1,0,0,0], [1,2,3,4,5]), [99,99,3,4,5])\n atest = ones((10,10,10), dtype=float32)\n btest = zeros(atest.shape, MaskType)\n ctest = masked_where(btest,atest)\n assert eq(atest,ctest)\n z = choose(c, (-x, x))\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n x = arange(6)\n x[5] = masked\n y = arange(6)*10\n y[2]= masked\n c = array([1,1,1,0,0,0], mask=[1,0,0,0,0,0])\n cm = c.filled(1)\n z = where(c,x,y)\n zm = where(cm,x,y)\n assert eq(z, zm)\n assert getmask(zm) is None\n assert eq(zm, [0,1,2,30,40,50])\n z = where(c, masked, 1)\n assert eq(z, [99,99,99,1,1,1])\n z = where(c, 1, masked)\n assert eq(z, [99, 1, 1, 99, 99, 99])\n \n def check_testMinMax(self):\n \"Test of minumum, maximum.\" \n assert eq(minimum([1,2,3],[4,0,9]), [1,0,3])\n assert eq(maximum([1,2,3],[4,0,9]), [4,2,9])\n x = arange(5)\n y = arange(5) - 2\n x[3] = masked\n y[0] = masked\n assert eq(minimum(x,y), where(less(x,y), x, y))\n assert eq(maximum(x,y), where(greater(x,y), x, y))\n assert minimum(x) == 0\n assert maximum(x) == 4\n \n def check_testTakeTransposeInnerOuter(self):\n \"Test of take, transpose, inner, outer products\"\n x = arange(24)\n y = numpy.arange(24)\n x[5:6] = masked\n x=x.reshape(2,3,4)\n y=y.reshape(2,3,4)\n assert eq(numpy.transpose(y,(2,0,1)), transpose(x,(2,0,1)))\n assert eq(numpy.take(y, (2,0,1), 1), take(x, (2,0,1), 1))\n assert eq(numpy.innerproduct(filled(x,0),filled(y,0)),\n innerproduct(x, y))\n assert eq(numpy.outerproduct(filled(x,0),filled(y,0)),\n outerproduct(x, y))\n y = array(['abc', 1, 'def', 2, 3], object)\n y[2] = masked\n t = take(y,[0,3,4])\n assert t[0] == 'abc'\n assert t[1] == 2\n assert t[2] == 3\n \n def check_testInplace(self):\n \"\"\"Test of inplace operations and rich comparisons\"\"\"\n y = arange(10)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x += 1\n assert eq(x, y+1)\n xm += 1\n assert eq(x, y+1)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x -= 1\n assert eq(x, y-1)\n xm -= 1\n assert eq(xm, y-1)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x *= 2.0\n assert eq(x, y*2)\n xm *= 2.0\n assert eq(xm, y*2)\n \n x = arange(10)*2\n xm = arange(10)\n xm[2] = masked\n x /= 2\n assert eq(x, y)\n xm /= 2\n assert eq(x, y)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x /= 2.0\n assert eq(x, y/2.0)\n xm /= arange(10)\n assert eq(xm, ones((10,)))\n \n x = arange(10).astype(float32)\n xm = arange(10)\n xm[2] = masked\n id1 = id(x.raw_data())\n x += 1.\n assert id1 == id(x.raw_data())\n assert eq(x, y+1.)\n \n def check_testPickle(self):\n \"Test of pickling\"\n x = arange(12)\n x[4:10:2] = masked\n x=x.reshape(4,3)\n f = open('test9.pik','wb')\n import pickle\n pickle.dump(x, f)\n f.close()\n f = open('test9.pik', 'rb')\n y = pickle.load(f)\n assert eq(x,y) \n \n def check_testMasked(self):\n \"Test of masked element\"\n xx=arange(6)\n xx[1] = masked\n self.failUnless(str(masked) == '--')\n self.failUnless(xx[1] is masked)\n # don't know why these should raise an exception...\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, masked)\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, 2)\n self.failUnlessRaises(Exception, lambda x,y: x+y, masked, xx)\n self.failUnlessRaises(Exception, lambda x,y: x+y, xx, masked)\n \n def check_testAverage1(self):\n \"Test of average.\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless(eq(2.0, average(ott)))\n self.failUnless(eq(2.0, average(ott, weights=[1., 1., 2., 1.])))\n result, wts = average(ott, weights=[1.,1.,2.,1.], returned=1)\n self.failUnless(eq(2.0, result))\n self.failUnless(wts == 4.0)\n ott[:] = masked\n self.failUnless(average(ott) is masked)\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n ott=ott.reshape(2,2)\n ott[:,1] = masked\n self.failUnless(eq(average(ott), [2.0, 0.0]))\n self.failUnless(average(ott,axis=1)[0] is masked)\n self.failUnless(eq([2.,0.], average(ott)))\n result, wts = average(ott, returned=1)\n self.failUnless(eq(wts, [1., 0.]))\n\n def check_testAverage2(self):\n \"More tests of average.\"\n w1 = [0,1,1,1,1,0]\n w2 = [[0,1,1,1,1,0],[1,0,0,0,0,1]]\n x=arange(6)\n self.failUnless(allclose(average(x), 2.5))\n self.failUnless(allclose(average(x, weights=w1), 2.5))\n y=array([arange(6), 2.0*arange(6)])\n self.failUnless(allclose(average(y, None), numpy.add.reduce(numpy.arange(6))*3./12.))\n self.failUnless(allclose(average(y, axis=0), numpy.arange(6) * 3./2.))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n self.failUnless(allclose(average(y, None, weights=w2), 20./6.))\n self.failUnless(allclose(average(y, axis=0, weights=w2), [0.,1.,2.,3.,4.,10.]))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n m1 = zeros(6)\n m2 = [0,0,1,1,0,0]\n m3 = [[0,0,1,1,0,0],[0,1,1,1,1,0]]\n m4 = ones(6)\n m5 = [0, 1, 1, 1, 1, 1]\n self.failUnless(allclose(average(masked_array(x, m1)), 2.5))\n self.failUnless(allclose(average(masked_array(x, m2)), 2.5))\n self.failUnless(average(masked_array(x, m4)) is masked)\n self.assertEqual(average(masked_array(x, m5)), 0.0)\n self.assertEqual(count(average(masked_array(x, m4))), 0)\n z = masked_array(y, m3)\n self.failUnless(allclose(average(z, None), 20./6.))\n self.failUnless(allclose(average(z, axis=0), [0.,1.,99.,99.,4.0, 7.5]))\n self.failUnless(allclose(average(z, axis=1), [2.5, 5.0]))\n self.failUnless(allclose( average(z,weights=w2), [0.,1., 99., 99., 4.0, 10.0]))\n \n a = arange(6)\n b = arange(6) * 3\n r1, w1 = average([[a,b],[b,a]], axis=1, returned=1)\n self.assertEqual(shape(r1) , shape(w1))\n self.assertEqual(r1.shape , w1.shape)\n r2, w2 = average(ones((2,2,3)), axis=0, weights=[3,1], returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), weights=ones((2,2,3)), returned=1)\n self.failUnless(shape(w2) == shape(r2))\n a2d = array([[1,2],[0,4]], float)\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n a2da = average(a2d)\n self.failUnless(eq (a2da, [0.5, 3.0]))\n a2dma = average(a2dm)\n self.failUnless(eq( a2dma, [1.0, 3.0]))\n a2dma = average(a2dm, axis=None)\n self.failUnless(eq(a2dma, 7./3.))\n a2dma = average(a2dm, axis=1)\n self.failUnless(eq(a2dma, [1.5, 4.0]))\n\n def check_testToPython(self):\n self.assertEqual(1, int(array(1)))\n self.assertEqual(1.0, float(array(1)))\n self.assertEqual(1, int(array([[[1]]])))\n self.assertEqual(1.0, float(array([[1]])))\n self.failUnlessRaises(ValueError, float, array([1,1]))\n self.failUnlessRaises(MAError, float, array([1],mask=[1]))\n self.failUnless(bool(array([0,1])))\n self.failUnless(bool(array([0,0],mask=[0,1])))\n self.failIf(bool(array([0,0])))\n self.failIf(bool(array([0,0],mask=[0,0])))\n\n def check_testScalarArithmetic(self):\n xm = array(0, mask=1)\n self.failUnless((1/array(0)).mask)\n self.failUnless((1 + xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless(maximum(xm, xm).mask)\n self.failUnless(minimum(xm, xm).mask)\n self.failUnless(xm.filled().dtype is xm.data.dtype)\n x = array(0, mask=0)\n self.failUnless(x.filled() is x.data)\n self.failUnlessEqual(str(xm), str(masked_print_option))\n\n def check_testArrayMethods(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnless(eq(a.any(), a.data.any()))\n self.failUnless(eq(a.all(), a.data.all()))\n self.failUnless(eq(a.argmax(), a.data.argmax()))\n self.failUnless(eq(a.argmin(), a.data.argmin()))\n self.failUnless(eq(a.choose(0,1,2,3,4), a.data.choose(0,1,2,3,4)))\n self.failUnless(eq(a.compress([1,0,1]), a.data.compress([1,0,1])))\n self.failUnless(eq(a.conj(), a.data.conj()))\n self.failUnless(eq(a.conjugate(), a.data.conjugate()))\n m = array([[1,2],[3,4]])\n self.failUnless(eq(m.diagonal(), m.data.diagonal()))\n self.failUnless(eq(a.sum(), a.data.sum()))\n self.failUnless(eq(a.take([1,2]), a.data.take([1,2])))\n self.failUnless(eq(m.transpose(), m.data.transpose()))\n \n def check_testAPI(self):\n self.failIf([m for m in dir(numpy.ndarray)\n if m not in dir(array) and not m.startswith('_')])\n\n def check_testSingleElementSubscript(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnlessEqual(a[0].shape, ())\n self.failUnlessEqual(b[0].shape, ())\n self.failUnlessEqual(b[1].shape, ())\n\nclass test_ufuncs(ScipyTestCase):\n def setUp(self):\n self.d = (array([1.0, 0, -1, pi/2]*2, mask=[0]*8),\n array([1.0, 0, -1, pi/2]*2, mask=[0]*8),)\n def check_testUfuncRegression(self):\n for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate',\n 'sin', 'cos', 'tan', \n 'arcsin', 'arccos', 'arctan',\n 'sinh', 'cosh', 'tanh', \n 'arcsinh',\n # 'arccosh', # buggy domain\n # 'arctanh', # buggy domain\n 'absolute', 'fabs', 'negative',\n # 'nonzero', 'around',\n 'floor', 'ceil',\n # 'sometrue', 'alltrue',\n 'logical_not',\n 'add', 'subtract', 'multiply',\n 'divide', 'true_divide', 'floor_divide',\n 'remainder', 'fmod', 'hypot', 'arctan2',\n 'equal', 'not_equal', 'less_equal', 'greater_equal',\n 'less', 'greater',\n 'logical_and', 'logical_or', 'logical_xor',\n ]:\n try:\n uf = getattr(umath, f)\n except AttributeError:\n uf = getattr(oldnumeric, f)\n mf = getattr(numpy.ma, f)\n args = self.d[:uf.nin]\n ur = uf(*args)\n mr = mf(*args)\n self.failUnless(eq(ur.filled(0), mr.filled(0), f))\n self.failUnless(eqmask(ur.mask, mr.mask))\n\ndef eqmask(m1, m2):\n if m1 is nomask:\n return m2 is nomask\n if m2 is nomask:\n return m1 is nomask\n return (m1 == m2).all()\n \ndef timingTest():\n for f in [testf, testinplace]:\n for n in [1000,10000,50000]:\n t = testta(n, f)\n t1 = testtb(n, f)\n t2 = testtc(n, f)\n print f.test_name\n print \"\"\"\\\nn = %7d \nnumpy time (ms) %6.1f \nMA maskless ratio %6.1f\nMA masked ratio %6.1f\n\"\"\" % (n, t*1000.0, t1/t, t2/t)\n\ndef testta(n, f):\n x=numpy.arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtb(n, f):\n x=arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtc(n, f):\n x=arange(n) + 1.0\n x[0] = masked\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testf(x):\n for i in range(25):\n y = x **2 + 2.0 * x - 1.0\n w = x **2 + 1.0\n z = (y / w) ** 2\n return z\ntestf.test_name = 'Simple arithmetic'\n\ndef testinplace(x):\n for i in range(25):\n y = x**2\n y += 2.0*x\n y -= 1.0\n y /= x\n return y\ntestinplace.test_name = 'Inplace operations'\n\nif __name__ == \"__main__\":\n ScipyTest('numpy.core.ma').run() \n #timingTest()\n", + "source_code_before": "import numpy \nimport types, time\nfrom numpy.core.ma import *\nfrom numpy.testing import ScipyTestCase, ScipyTest\ndef eq(v,w):\n result = allclose(v,w)\n if not result:\n print \"\"\"Not eq:\n%s\n----\n%s\"\"\"% (str(v), str(w))\n return result\n\nclass test_ma(ScipyTestCase):\n def __init__(self, *args, **kwds):\n ScipyTestCase.__init__(self, *args, **kwds)\n self.setUp()\n \n def setUp (self):\n x=numpy.array([1.,1.,1.,-2., pi/2.0, 4., 5., -10., 10., 1., 2., 3.])\n y=numpy.array([5.,0.,3., 2., -1., -4., 0., -10., 10., 1., 0., 3.])\n a10 = 10.\n m1 = [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]\n m2 = [0, 0, 1, 0, 0, 1, 1, 0, 0, 0 ,0, 1]\n xm = array(x, mask=m1)\n ym = array(y, mask=m2)\n z = numpy.array([-.5, 0., .5, .8])\n zm = array(z, mask=[0,1,0,0])\n xf = numpy.where(m1, 1.e+20, x)\n s = x.shape\n xm.set_fill_value(1.e+20)\n self.d = (x, y, a10, m1, m2, xm, ym, z, zm, xf, s)\n\n def check_testBasic1d(self):\n \"Test of basic array creation and properties in 1 dimension.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual(xm.dtype, x.dtype)\n self.assertEqual(xm.dtypechar, x.dtypechar)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual(count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n\n def check_testBasic2d(self):\n \"Test of basic array creation and properties in 2 dimensions.\"\n for s in [(4,3), (6,2)]: \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n x.shape = s\n y.shape = s\n xm.shape = s\n ym.shape = s\n xf.shape = s\n \n self.failIf(isMaskedArray(x))\n self.failUnless(isMaskedArray(xm))\n self.assertEqual(shape(xm), s)\n self.assertEqual(xm.shape, s)\n self.assertEqual( xm.size , reduce(lambda x,y:x*y, s))\n self.assertEqual( count(xm) , len(m1) - reduce(lambda x,y:x+y, m1))\n self.failUnless(eq(xm, xf))\n self.failUnless(eq(filled(xm, 1.e20), xf))\n self.failUnless(eq(x, xm))\n self.setUp()\n\n def check_testArithmetic (self):\n \"Test of basic arithmetic.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n a2d = array([[1,2],[0,4]])\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n self.failUnless(eq (a2d * a2d, a2d * a2dm))\n self.failUnless(eq (a2d + a2d, a2d + a2dm))\n self.failUnless(eq (a2d - a2d, a2d - a2dm))\n for s in [(12,), (4,3), (2,6)]: \n x = x.reshape(s)\n y = y.reshape(s)\n xm = xm.reshape(s)\n ym = ym.reshape(s)\n xf = xf.reshape(s)\n self.failUnless(eq(-x, -xm))\n self.failUnless(eq(x + y, xm + ym))\n self.failUnless(eq(x - y, xm - ym))\n self.failUnless(eq(x * y, xm * ym))\n self.failUnless(eq(x / y, xm / ym))\n self.failUnless(eq(a10 + y, a10 + ym))\n self.failUnless(eq(a10 - y, a10 - ym))\n self.failUnless(eq(a10 * y, a10 * ym))\n self.failUnless(eq(a10 / y, a10 / ym))\n self.failUnless(eq(x + a10, xm + a10))\n self.failUnless(eq(x - a10, xm - a10))\n self.failUnless(eq(x * a10, xm * a10))\n self.failUnless(eq(x / a10, xm / a10))\n self.failUnless(eq(x**2, xm**2))\n self.failUnless(eq(abs(x)**2.5, abs(xm) **2.5))\n self.failUnless(eq(x**y, xm**ym))\n self.failUnless(eq(numpy.add(x,y), add(xm, ym)))\n self.failUnless(eq(numpy.subtract(x,y), subtract(xm, ym)))\n self.failUnless(eq(numpy.multiply(x,y), multiply(xm, ym)))\n self.failUnless(eq(numpy.divide(x,y), divide(xm, ym)))\n\n\n def check_testMixedArithmetic(self):\n na = numpy.array([1])\n ma = array([1])\n self.failUnless(isinstance(na + ma, MaskedArray))\n self.failUnless(isinstance(ma + na, MaskedArray))\n \n def check_testUfuncs1 (self):\n \"Test various functions such as sin, cos.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.cos(x), cos(xm)))\n self.failUnless (eq(numpy.cosh(x), cosh(xm)))\n self.failUnless (eq(numpy.sin(x), sin(xm)))\n self.failUnless (eq(numpy.sinh(x), sinh(xm)))\n self.failUnless (eq(numpy.tan(x), tan(xm)))\n self.failUnless (eq(numpy.tanh(x), tanh(xm)))\n self.failUnless (eq(numpy.sqrt(abs(x)), sqrt(xm)))\n self.failUnless (eq(numpy.log(abs(x)), log(xm)))\n self.failUnless (eq(numpy.log10(abs(x)), log10(xm)))\n self.failUnless (eq(numpy.exp(x), exp(xm)))\n self.failUnless (eq(numpy.arcsin(z), arcsin(zm)))\n self.failUnless (eq(numpy.arccos(z), arccos(zm)))\n self.failUnless (eq(numpy.arctan(z), arctan(zm)))\n self.failUnless (eq(numpy.arctan2(x, y), arctan2(xm, ym)))\n self.failUnless (eq(numpy.absolute(x), absolute(xm)))\n self.failUnless (eq(numpy.equal(x,y), equal(xm, ym)))\n self.failUnless (eq(numpy.not_equal(x,y), not_equal(xm, ym)))\n self.failUnless (eq(numpy.less(x,y), less(xm, ym)))\n self.failUnless (eq(numpy.greater(x,y), greater(xm, ym)))\n self.failUnless (eq(numpy.less_equal(x,y), less_equal(xm, ym)))\n self.failUnless (eq(numpy.greater_equal(x,y), greater_equal(xm, ym)))\n self.failUnless (eq(numpy.conjugate(x), conjugate(xm)))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,ym))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((x,y))))\n self.failUnless (eq(numpy.concatenate((x,y)), concatenate((xm,y))))\n self.failUnless (eq(numpy.concatenate((x,y,x)), concatenate((x,ym,x))))\n \n def check_xtestCount (self):\n \"Test count\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless( isinstance(count(ott), types.IntType))\n self.assertEqual(3, count(ott))\n self.assertEqual(1, count(1))\n self.failUnless (eq(0, array(1,mask=[1])))\n ott=ott.reshape((2,2))\n assert isMaskedArray(count(ott,0))\n assert isinstance(count(ott), types.IntType)\n self.failUnless (eq(3, count(ott)))\n assert getmask(count(ott,0)) is None\n self.failUnless (eq([1,2],count(ott,0)))\n \n def check_testMinMax (self):\n \"Test minimum and maximum.\" \n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n xr = numpy.ravel(x) #max doesn't work if shaped\n xmr = ravel(xm)\n self.failUnless (eq(max(xr), maximum(xmr))) #true because of careful selection of data\n self.failUnless (eq(min(xr), minimum(xmr))) #true because of careful selection of data\n\n def check_testAddSumProd (self):\n \"Test add, sum, product.\"\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n self.failUnless (eq(numpy.add.reduce(x), add.reduce(x)))\n self.failUnless (eq(numpy.add.accumulate(x), add.accumulate(x)))\n self.failUnless (eq(4, sum(array(4))))\n self.failUnless (eq(4, sum(array(4), axis=0)))\n self.failUnless (eq(numpy.sum(x), sum(x)))\n self.failUnless (eq(numpy.sum(filled(xm,0)), sum(xm)))\n self.failUnless (eq(numpy.sum(x,0), sum(x,0)))\n self.failUnless (eq(numpy.product(x), product(x)))\n self.failUnless (eq(numpy.product(x,0), product(x,0)))\n self.failUnless (eq(numpy.product(filled(xm,1)), product(xm)))\n if len(s) > 1:\n self.failUnless (eq(numpy.concatenate((x,y),1), concatenate((xm,ym),1)))\n self.failUnless (eq(numpy.add.reduce(x,1), add.reduce(x,1)))\n self.failUnless (eq(numpy.sum(x,1), sum(x,1)))\n self.failUnless (eq(numpy.product(x,1), product(x,1)))\n \n \n def check_testCI(self):\n \"Test of conversions and indexing\"\n x1 = numpy.array([1,2,4,3])\n x2 = array(x1, mask = [1,0,0,0])\n x3 = array(x1, mask = [0,1,0,1])\n x4 = array(x1)\n # test conversion to strings\n junk, garbage = str(x2), repr(x2)\n assert eq(numpy.sort(x1),sort(x2, fill_value=0))\n # tests of indexing\n assert type(x2[1]) is type(x1[1])\n assert x1[1] == x2[1]\n assert x2[0] is masked\n assert eq(x1[2],x2[2])\n assert eq(x1[2:5],x2[2:5])\n assert eq(x1[:],x2[:])\n assert eq(x1[1:], x3[1:])\n x1[2]=9\n x2[2]=9\n assert eq(x1,x2)\n x1[1:3] = 99\n x2[1:3] = 99\n assert eq(x1,x2)\n x2[1] = masked\n assert eq(x1,x2)\n x2[1:3]=masked\n assert eq(x1,x2)\n x2[:] = x1\n x2[1] = masked\n assert allequal(getmask(x2),array([0,1,0,0]))\n x3[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x3), array([0,1,1,0]))\n x4[:] = masked_array([1,2,3,4],[0,1,1,0])\n assert allequal(getmask(x4), array([0,1,1,0]))\n assert allequal(x4, array([1,2,3,4]))\n x1 = numpy.arange(5)*1.0\n x2 = masked_values(x1, 3.0)\n assert eq(x1,x2)\n assert allequal(array([0,0,0,1,0],MaskType), x2.mask)\n assert eq(3.0, x2.fill_value())\n x1 = array([1,'hello',2,3],object)\n x2 = numpy.array([1,'hello',2,3],object)\n s1 = x1[1]\n s2 = x2[1]\n self.assertEqual(type(s2), str)\n self.assertEqual(type(s1), str)\n self.assertEqual(s1, s2)\n assert x1[1:1].shape == (0,)\n \n def check_testCopySize(self):\n \"Tests of some subtle points of copying and sizing.\"\n n = [0,0,1,0,0]\n m = make_mask(n)\n m2 = make_mask(m)\n self.failUnless(m is m2)\n m3 = make_mask(m, copy=1)\n self.failUnless(m is not m3)\n \n x1 = numpy.arange(5)\n y1 = array(x1, mask=m)\n self.failUnless( y1.raw_data() is not x1)\n self.failUnless( allequal(x1,y1.raw_data()))\n self.failUnless( y1.mask is m)\n \n y1a = array(y1, copy=0)\n self.failUnless( y1a.raw_data() is y1.raw_data())\n self.failUnless( y1a.mask is y1.mask)\n \n y2 = array(x1, mask=m, copy=0)\n self.failUnless( y2.raw_data() is x1)\n self.failUnless( y2.mask is m)\n self.failUnless( y2[2] is masked)\n y2[2]=9\n self.failUnless( y2[2] is not masked)\n self.failUnless( y2.mask is not m)\n self.failUnless( allequal(y2.mask, 0))\n \n y3 = array(x1*1.0, mask=m)\n self.failUnless(filled(y3).dtype is (x1*1.0).dtype)\n \n x4 = arange(4)\n x4[2] = masked\n y4 = resize(x4, (8,))\n self.failUnless( eq(concatenate([x4,x4]), y4))\n self.failUnless( eq(getmask(y4),[0,0,1,0,0,0,1,0]))\n y5 = repeat(x4, (2,2,2,2))\n self.failUnless( eq(y5, [0,0,1,1,2,2,3,3]))\n y6 = repeat(x4, 2)\n self.failUnless( eq(y5, y6))\n \n def check_testPut(self):\n \"Test of put\"\n d = arange(5)\n n = [0,0,0,1,1]\n m = make_mask(n)\n x = array(d, mask = m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n x[[1,4]] = [10,40]\n self.failUnless( x.mask is not m)\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is not masked)\n self.failUnless( eq(x, [0,10,2,-1,40]))\n \n x = array(d, mask = m) \n x.put([-1,100,200])\n self.failUnless( eq(x, [-1,100,200,0,0]))\n self.failUnless( x[3] is masked)\n self.failUnless( x[4] is masked)\n \n x = array(d, mask = m) \n x.putmask([30,40])\n self.failUnless( eq(x, [0,1,2,30,40]))\n self.failUnless( x.mask is None)\n \n x = array(d, mask = m) \n y = x.compressed()\n z = array(x, mask = m)\n z.put(y)\n assert eq (x, z)\n \n def check_testMaPut(self):\n (x, y, a10, m1, m2, xm, ym, z, zm, xf, s) = self.d\n m = [1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1]\n i = numpy.nonzero(m)\n putmask(xm, m, z)\n assert take(xm, i) == z\n put(ym, i, zm)\n assert take(ym, i) == zm\n \n def check_testOddFeatures(self):\n \"Test of other odd features\"\n x = arange(20); x=x.reshape(4,5)\n x.flat[5] = 12\n assert x[1,0] == 12\n z = x + 10j * x\n assert eq(z.real, x)\n assert eq(z.imag, 10*x)\n assert eq((z*conjugate(z)).real, 101*x*x)\n z.imag[...] = 0.0\n \n x = arange(10)\n x[3] = masked\n assert str(x[3]) == str(masked)\n c = x >= 8\n assert count(where(c,masked,masked)) == 0\n assert shape(where(c,masked,masked)) == c.shape\n z = where(c , x, masked)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is masked\n assert z[7] is masked\n assert z[8] is not masked\n assert z[9] is not masked\n assert eq(x,z)\n z = where(c , masked, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n z = masked_where(c, x)\n assert z.dtype is x.dtype\n assert z[3] is masked\n assert z[4] is not masked\n assert z[7] is not masked\n assert z[8] is masked\n assert z[9] is masked\n assert eq(x,z)\n x = array([1.,2.,3.,4.,5.])\n c = array([1,1,1,0,0])\n x[2] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n c[0] = masked\n z = where(c, x, -x)\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n assert eq(masked_where(greater(x, 2), x), masked_greater(x,2))\n assert eq(masked_where(greater_equal(x, 2), x), masked_greater_equal(x,2))\n assert eq(masked_where(less(x, 2), x), masked_less(x,2))\n assert eq(masked_where(less_equal(x, 2), x), masked_less_equal(x,2))\n assert eq(masked_where(not_equal(x, 2), x), masked_not_equal(x,2))\n assert eq(masked_where(equal(x, 2), x), masked_equal(x,2))\n assert eq(masked_where(not_equal(x,2), x), masked_not_equal(x,2))\n assert eq(masked_inside(range(5), 1, 3), [0, 199, 199, 199, 4])\n assert eq(masked_outside(range(5), 1, 3),[199,1,2,3,199])\n assert eq(masked_inside(array(range(5), mask=[1,0,0,0,0]), 1, 3).mask, [1,1,1,1,0])\n assert eq(masked_outside(array(range(5), mask=[0,1,0,0,0]), 1, 3).mask, [1,1,0,0,1])\n assert eq(masked_equal(array(range(5), mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,0])\n assert eq(masked_not_equal(array([2,2,1,2,1], mask=[1,0,0,0,0]), 2).mask, [1,0,1,0,1])\n assert eq(masked_where([1,1,0,0,0], [1,2,3,4,5]), [99,99,3,4,5])\n atest = ones((10,10,10), dtype=float32)\n btest = zeros(atest.shape, MaskType)\n ctest = masked_where(btest,atest)\n assert eq(atest,ctest)\n z = choose(c, (-x, x))\n assert eq(z, [1.,2.,0., -4., -5])\n assert z[0] is masked\n assert z[1] is not masked\n assert z[2] is masked\n x = arange(6)\n x[5] = masked\n y = arange(6)*10\n y[2]= masked\n c = array([1,1,1,0,0,0], mask=[1,0,0,0,0,0])\n cm = c.filled(1)\n z = where(c,x,y)\n zm = where(cm,x,y)\n assert eq(z, zm)\n assert getmask(zm) is None\n assert eq(zm, [0,1,2,30,40,50])\n z = where(c, masked, 1)\n assert eq(z, [99,99,99,1,1,1])\n z = where(c, 1, masked)\n assert eq(z, [99, 1, 1, 99, 99, 99])\n \n def check_testMinMax(self):\n \"Test of minumum, maximum.\" \n assert eq(minimum([1,2,3],[4,0,9]), [1,0,3])\n assert eq(maximum([1,2,3],[4,0,9]), [4,2,9])\n x = arange(5)\n y = arange(5) - 2\n x[3] = masked\n y[0] = masked\n assert eq(minimum(x,y), where(less(x,y), x, y))\n assert eq(maximum(x,y), where(greater(x,y), x, y))\n assert minimum(x) == 0\n assert maximum(x) == 4\n \n def check_testTakeTransposeInnerOuter(self):\n \"Test of take, transpose, inner, outer products\"\n x = arange(24)\n y = numpy.arange(24)\n x[5:6] = masked\n x=x.reshape(2,3,4)\n y=y.reshape(2,3,4)\n assert eq(numpy.transpose(y,(2,0,1)), transpose(x,(2,0,1)))\n assert eq(numpy.take(y, (2,0,1), 1), take(x, (2,0,1), 1))\n assert eq(numpy.innerproduct(filled(x,0),filled(y,0)),\n innerproduct(x, y))\n assert eq(numpy.outerproduct(filled(x,0),filled(y,0)),\n outerproduct(x, y))\n y = array(['abc', 1, 'def', 2, 3], object)\n y[2] = masked\n t = take(y,[0,3,4])\n assert t[0] == 'abc'\n assert t[1] == 2\n assert t[2] == 3\n \n def check_testInplace(self):\n \"\"\"Test of inplace operations and rich comparisons\"\"\"\n y = arange(10)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x += 1\n assert eq(x, y+1)\n xm += 1\n assert eq(x, y+1)\n \n x = arange(10)\n xm = arange(10)\n xm[2] = masked\n x -= 1\n assert eq(x, y-1)\n xm -= 1\n assert eq(xm, y-1)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x *= 2.0\n assert eq(x, y*2)\n xm *= 2.0\n assert eq(xm, y*2)\n \n x = arange(10)*2\n xm = arange(10)\n xm[2] = masked\n x /= 2\n assert eq(x, y)\n xm /= 2\n assert eq(x, y)\n \n x = arange(10)*1.0\n xm = arange(10)*1.0\n xm[2] = masked\n x /= 2.0\n assert eq(x, y/2.0)\n xm /= arange(10)\n assert eq(xm, ones((10,)))\n \n x = arange(10).astype(float32)\n xm = arange(10)\n xm[2] = masked\n id1 = id(x.raw_data())\n x += 1.\n assert id1 == id(x.raw_data())\n assert eq(x, y+1.)\n \n def check_testPickle(self):\n \"Test of pickling\"\n x = arange(12)\n x[4:10:2] = masked\n x=x.reshape(4,3)\n f = open('test9.pik','wb')\n import pickle\n pickle.dump(x, f)\n f.close()\n f = open('test9.pik', 'rb')\n y = pickle.load(f)\n assert eq(x,y) \n \n def check_testMasked(self):\n \"Test of masked element\"\n xx=arange(6)\n xx[1] = masked\n self.failUnless(str(masked) == '--')\n self.failUnless(xx[1] is masked)\n # don't know why these should raise an exception...\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, masked)\n #self.failUnlessRaises(Exception, lambda x,y: x+y, masked, 2)\n self.failUnlessRaises(Exception, lambda x,y: x+y, masked, xx)\n self.failUnlessRaises(Exception, lambda x,y: x+y, xx, masked)\n \n def check_testAverage1(self):\n \"Test of average.\"\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n self.failUnless(eq(2.0, average(ott)))\n self.failUnless(eq(2.0, average(ott, weights=[1., 1., 2., 1.])))\n result, wts = average(ott, weights=[1.,1.,2.,1.], returned=1)\n self.failUnless(eq(2.0, result))\n self.failUnless(wts == 4.0)\n ott[:] = masked\n self.failUnless(average(ott) is masked)\n ott = array([0.,1.,2.,3.], mask=[1,0,0,0])\n ott=ott.reshape(2,2)\n ott[:,1] = masked\n self.failUnless(eq(average(ott), [2.0, 0.0]))\n self.failUnless(average(ott,axis=1)[0] is masked)\n self.failUnless(eq([2.,0.], average(ott)))\n result, wts = average(ott, returned=1)\n self.failUnless(eq(wts, [1., 0.]))\n\n def check_testAverage2(self):\n \"More tests of average.\"\n w1 = [0,1,1,1,1,0]\n w2 = [[0,1,1,1,1,0],[1,0,0,0,0,1]]\n x=arange(6)\n self.failUnless(allclose(average(x), 2.5))\n self.failUnless(allclose(average(x, weights=w1), 2.5))\n y=array([arange(6), 2.0*arange(6)])\n self.failUnless(allclose(average(y, None), numpy.add.reduce(numpy.arange(6))*3./12.))\n self.failUnless(allclose(average(y, axis=0), numpy.arange(6) * 3./2.))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n self.failUnless(allclose(average(y, None, weights=w2), 20./6.))\n self.failUnless(allclose(average(y, axis=0, weights=w2), [0.,1.,2.,3.,4.,10.]))\n self.failUnless(allclose(average(y, axis=1), [average(x), average(x) * 2.0]))\n m1 = zeros(6)\n m2 = [0,0,1,1,0,0]\n m3 = [[0,0,1,1,0,0],[0,1,1,1,1,0]]\n m4 = ones(6)\n m5 = [0, 1, 1, 1, 1, 1]\n self.failUnless(allclose(average(masked_array(x, m1)), 2.5))\n self.failUnless(allclose(average(masked_array(x, m2)), 2.5))\n self.failUnless(average(masked_array(x, m4)) is masked)\n self.assertEqual(average(masked_array(x, m5)), 0.0)\n self.assertEqual(count(average(masked_array(x, m4))), 0)\n z = masked_array(y, m3)\n self.failUnless(allclose(average(z, None), 20./6.))\n self.failUnless(allclose(average(z, axis=0), [0.,1.,99.,99.,4.0, 7.5]))\n self.failUnless(allclose(average(z, axis=1), [2.5, 5.0]))\n self.failUnless(allclose( average(z,weights=w2), [0.,1., 99., 99., 4.0, 10.0]))\n \n a = arange(6)\n b = arange(6) * 3\n r1, w1 = average([[a,b],[b,a]], axis=1, returned=1)\n self.assertEqual(shape(r1) , shape(w1))\n self.assertEqual(r1.shape , w1.shape)\n r2, w2 = average(ones((2,2,3)), axis=0, weights=[3,1], returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), returned=1)\n self.assertEqual(shape(w2) , shape(r2))\n r2, w2 = average(ones((2,2,3)), weights=ones((2,2,3)), returned=1)\n self.failUnless(shape(w2) == shape(r2))\n a2d = array([[1,2],[0,4]], float)\n a2dm = masked_array(a2d, [[0,0],[1,0]])\n a2da = average(a2d)\n self.failUnless(eq (a2da, [0.5, 3.0]))\n a2dma = average(a2dm)\n self.failUnless(eq( a2dma, [1.0, 3.0]))\n a2dma = average(a2dm, axis=None)\n self.failUnless(eq(a2dma, 7./3.))\n a2dma = average(a2dm, axis=1)\n self.failUnless(eq(a2dma, [1.5, 4.0]))\n\n def check_testToPython(self):\n self.assertEqual(1, int(array(1)))\n self.assertEqual(1.0, float(array(1)))\n self.assertEqual(1, int(array([[[1]]])))\n self.assertEqual(1.0, float(array([[1]])))\n self.failUnlessRaises(ValueError, float, array([1,1]))\n self.failUnlessRaises(MAError, float, array([1],mask=[1]))\n self.failUnless(bool(array([0,1])))\n self.failUnless(bool(array([0,0],mask=[0,1])))\n self.failIf(bool(array([0,0])))\n self.failIf(bool(array([0,0],mask=[0,0])))\n\n def check_testScalarArithmetic(self):\n xm = array(0, mask=1)\n self.failUnless((1/array(0)).mask)\n self.failUnless((1 + xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless((-xm).mask)\n self.failUnless(maximum(xm, xm).mask)\n self.failUnless(minimum(xm, xm).mask)\n self.failUnless(xm.filled().dtype is xm.data.dtype)\n x = array(0, mask=0)\n self.failUnless(x.filled() is x.data)\n self.failUnlessEqual(str(xm), str(masked_print_option))\n\n def check_testArrayMethods(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnless(eq(a.any(), a.data.any()))\n self.failUnless(eq(a.all(), a.data.all()))\n self.failUnless(eq(a.argmax(), a.data.argmax()))\n self.failUnless(eq(a.argmin(), a.data.argmin()))\n self.failUnless(eq(a.choose(0,1,2,3,4), a.data.choose(0,1,2,3,4)))\n self.failUnless(eq(a.compress([1,0,1]), a.data.compress([1,0,1])))\n self.failUnless(eq(a.conj(), a.data.conj()))\n self.failUnless(eq(a.conjugate(), a.data.conjugate()))\n m = array([[1,2],[3,4]])\n self.failUnless(eq(m.diagonal(), m.data.diagonal()))\n self.failUnless(eq(a.sum(), a.data.sum()))\n self.failUnless(eq(a.take([1,2]), a.data.take([1,2])))\n self.failUnless(eq(m.transpose(), m.data.transpose()))\n \n def check_testAPI(self):\n self.failIf([m for m in dir(numpy.ndarray)\n if m not in dir(array) and not m.startswith('_')])\n\n def check_testSingleElementSubscript(self):\n a = array([1,3,2])\n b = array([1,3,2], mask=[1,0,1])\n self.failUnlessEqual(a[0].shape, ())\n self.failUnlessEqual(b[0].shape, ())\n self.failUnlessEqual(b[1].shape, ())\n\n \ndef timingTest():\n for f in [testf, testinplace]:\n for n in [1000,10000,50000]:\n t = testta(n, f)\n t1 = testtb(n, f)\n t2 = testtc(n, f)\n print f.test_name\n print \"\"\"\\\nn = %7d \nnumpy time (ms) %6.1f \nMA maskless ratio %6.1f\nMA masked ratio %6.1f\n\"\"\" % (n, t*1000.0, t1/t, t2/t)\n\ndef testta(n, f):\n x=numpy.arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtb(n, f):\n x=arange(n) + 1.0\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testtc(n, f):\n x=arange(n) + 1.0\n x[0] = masked\n tn0 = time.time()\n z = f(x)\n return time.time() - tn0\n\ndef testf(x):\n for i in range(25):\n y = x **2 + 2.0 * x - 1.0\n w = x **2 + 1.0\n z = (y / w) ** 2\n return z\ntestf.test_name = 'Simple arithmetic'\n\ndef testinplace(x):\n for i in range(25):\n y = x**2\n y += 2.0*x\n y -= 1.0\n y /= x\n return y\ntestinplace.test_name = 'Inplace operations'\n\nif __name__ == \"__main__\":\n ScipyTest('numpy.core.ma').run() \n #timingTest()\n", + "methods": [ + { + "name": "eq", + "long_name": "eq( v , w , msg = '' )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 41, + "parameters": [ + "v", + "w", + "msg" + ], + "start_line": 5, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , * args , ** kwds )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 15, + "end_line": 17, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 276, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 32, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic1d", + "long_name": "check_testBasic1d( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 186, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 47, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic2d", + "long_name": "check_testBasic2d( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 2, + "token_count": 209, + "parameters": [ + "self" + ], + "start_line": 49, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "check_testArithmetic", + "long_name": "check_testArithmetic( self )", + "filename": "test_ma.py", + "nloc": 34, + "complexity": 2, + "token_count": 518, + "parameters": [ + "self" + ], + "start_line": 70, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "check_testMixedArithmetic", + "long_name": "check_testMixedArithmetic( self )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 106, + "end_line": 110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_testUfuncs1", + "long_name": "check_testUfuncs1( self )", + "filename": "test_ma.py", + "nloc": 29, + "complexity": 1, + "token_count": 600, + "parameters": [ + "self" + ], + "start_line": 112, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "check_xtestCount", + "long_name": "check_xtestCount( self )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 1, + "token_count": 174, + "parameters": [ + "self" + ], + "start_line": 142, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 156, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_testAddSumProd", + "long_name": "check_testAddSumProd( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 2, + "token_count": 361, + "parameters": [ + "self" + ], + "start_line": 164, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testCI", + "long_name": "check_testCI( self )", + "filename": "test_ma.py", + "nloc": 46, + "complexity": 1, + "token_count": 560, + "parameters": [ + "self" + ], + "start_line": 184, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 1 + }, + { + "name": "check_testCopySize", + "long_name": "check_testCopySize( self )", + "filename": "test_ma.py", + "nloc": 35, + "complexity": 1, + "token_count": 409, + "parameters": [ + "self" + ], + "start_line": 233, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 1 + }, + { + "name": "check_testPut", + "long_name": "check_testPut( self )", + "filename": "test_ma.py", + "nloc": 27, + "complexity": 1, + "token_count": 291, + "parameters": [ + "self" + ], + "start_line": 274, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "check_testMaPut", + "long_name": "check_testMaPut( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 101, + "parameters": [ + "self" + ], + "start_line": 305, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_testOddFeatures", + "long_name": "check_testOddFeatures( self )", + "filename": "test_ma.py", + "nloc": 88, + "complexity": 1, + "token_count": 1188, + "parameters": [ + "self" + ], + "start_line": 314, + "end_line": 402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 154, + "parameters": [ + "self" + ], + "start_line": 404, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testTakeTransposeInnerOuter", + "long_name": "check_testTakeTransposeInnerOuter( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 1, + "token_count": 235, + "parameters": [ + "self" + ], + "start_line": 417, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "check_testInplace", + "long_name": "check_testInplace( self )", + "filename": "test_ma.py", + "nloc": 44, + "complexity": 1, + "token_count": 315, + "parameters": [ + "self" + ], + "start_line": 437, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testPickle", + "long_name": "check_testPickle( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 489, + "end_line": 500, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testMasked", + "long_name": "check_testMasked( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 502, + "end_line": 512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage1", + "long_name": "check_testAverage1( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 1, + "token_count": 289, + "parameters": [ + "self" + ], + "start_line": 514, + "end_line": 531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage2", + "long_name": "check_testAverage2( self )", + "filename": "test_ma.py", + "nloc": 50, + "complexity": 1, + "token_count": 945, + "parameters": [ + "self" + ], + "start_line": 533, + "end_line": 583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testToPython", + "long_name": "check_testToPython( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 193, + "parameters": [ + "self" + ], + "start_line": 585, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testScalarArithmetic", + "long_name": "check_testScalarArithmetic( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 146, + "parameters": [ + "self" + ], + "start_line": 597, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testArrayMethods", + "long_name": "check_testArrayMethods( self )", + "filename": "test_ma.py", + "nloc": 16, + "complexity": 1, + "token_count": 351, + "parameters": [ + "self" + ], + "start_line": 610, + "end_line": 625, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "check_testAPI", + "long_name": "check_testAPI( self )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 4, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 627, + "end_line": 629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_testSingleElementSubscript", + "long_name": "check_testSingleElementSubscript( self )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 631, + "end_line": 636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 639, + "end_line": 641, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_testUfuncRegression", + "long_name": "check_testUfuncRegression( self )", + "filename": "test_ma.py", + "nloc": 26, + "complexity": 3, + "token_count": 185, + "parameters": [ + "self" + ], + "start_line": 642, + "end_line": 671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "eqmask", + "long_name": "eqmask( m1 , m2 )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 3, + "token_count": 35, + "parameters": [ + "m1", + "m2" + ], + "start_line": 673, + "end_line": 678, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "timingTest", + "long_name": "timingTest( )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 3, + "token_count": 72, + "parameters": [], + "start_line": 680, + "end_line": 692, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "testta", + "long_name": "testta( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 40, + "parameters": [ + "n", + "f" + ], + "start_line": 694, + "end_line": 698, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtb", + "long_name": "testtb( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 38, + "parameters": [ + "n", + "f" + ], + "start_line": 700, + "end_line": 704, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtc", + "long_name": "testtc( n , f )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 44, + "parameters": [ + "n", + "f" + ], + "start_line": 706, + "end_line": 711, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testf", + "long_name": "testf( x )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 48, + "parameters": [ + "x" + ], + "start_line": 713, + "end_line": 718, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testinplace", + "long_name": "testinplace( x )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 36, + "parameters": [ + "x" + ], + "start_line": 721, + "end_line": 727, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "eq", + "long_name": "eq( v , w )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "v", + "w" + ], + "start_line": 5, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , * args , ** kwds )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 28, + "parameters": [ + "self", + "args", + "kwds" + ], + "start_line": 15, + "end_line": 17, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 276, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 32, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic1d", + "long_name": "check_testBasic1d( self )", + "filename": "test_ma.py", + "nloc": 14, + "complexity": 1, + "token_count": 186, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 47, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "check_testBasic2d", + "long_name": "check_testBasic2d( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 2, + "token_count": 209, + "parameters": [ + "self" + ], + "start_line": 49, + "end_line": 68, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "check_testArithmetic", + "long_name": "check_testArithmetic( self )", + "filename": "test_ma.py", + "nloc": 34, + "complexity": 2, + "token_count": 518, + "parameters": [ + "self" + ], + "start_line": 70, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 34, + "top_nesting_level": 1 + }, + { + "name": "check_testMixedArithmetic", + "long_name": "check_testMixedArithmetic( self )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 106, + "end_line": 110, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "check_testUfuncs1", + "long_name": "check_testUfuncs1( self )", + "filename": "test_ma.py", + "nloc": 29, + "complexity": 1, + "token_count": 600, + "parameters": [ + "self" + ], + "start_line": 112, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "check_xtestCount", + "long_name": "check_xtestCount( self )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 1, + "token_count": 174, + "parameters": [ + "self" + ], + "start_line": 142, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 156, + "end_line": 162, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "check_testAddSumProd", + "long_name": "check_testAddSumProd( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 2, + "token_count": 361, + "parameters": [ + "self" + ], + "start_line": 164, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testCI", + "long_name": "check_testCI( self )", + "filename": "test_ma.py", + "nloc": 46, + "complexity": 1, + "token_count": 560, + "parameters": [ + "self" + ], + "start_line": 184, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 48, + "top_nesting_level": 1 + }, + { + "name": "check_testCopySize", + "long_name": "check_testCopySize( self )", + "filename": "test_ma.py", + "nloc": 35, + "complexity": 1, + "token_count": 409, + "parameters": [ + "self" + ], + "start_line": 233, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 1 + }, + { + "name": "check_testPut", + "long_name": "check_testPut( self )", + "filename": "test_ma.py", + "nloc": 27, + "complexity": 1, + "token_count": 291, + "parameters": [ + "self" + ], + "start_line": 274, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + }, + { + "name": "check_testMaPut", + "long_name": "check_testMaPut( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 101, + "parameters": [ + "self" + ], + "start_line": 305, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_testOddFeatures", + "long_name": "check_testOddFeatures( self )", + "filename": "test_ma.py", + "nloc": 88, + "complexity": 1, + "token_count": 1188, + "parameters": [ + "self" + ], + "start_line": 314, + "end_line": 402, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 89, + "top_nesting_level": 1 + }, + { + "name": "check_testMinMax", + "long_name": "check_testMinMax( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 154, + "parameters": [ + "self" + ], + "start_line": 404, + "end_line": 415, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testTakeTransposeInnerOuter", + "long_name": "check_testTakeTransposeInnerOuter( self )", + "filename": "test_ma.py", + "nloc": 19, + "complexity": 1, + "token_count": 235, + "parameters": [ + "self" + ], + "start_line": 417, + "end_line": 435, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "check_testInplace", + "long_name": "check_testInplace( self )", + "filename": "test_ma.py", + "nloc": 44, + "complexity": 1, + "token_count": 315, + "parameters": [ + "self" + ], + "start_line": 437, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testPickle", + "long_name": "check_testPickle( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 489, + "end_line": 500, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testMasked", + "long_name": "check_testMasked( self )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 1, + "token_count": 78, + "parameters": [ + "self" + ], + "start_line": 502, + "end_line": 512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage1", + "long_name": "check_testAverage1( self )", + "filename": "test_ma.py", + "nloc": 18, + "complexity": 1, + "token_count": 289, + "parameters": [ + "self" + ], + "start_line": 514, + "end_line": 531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "check_testAverage2", + "long_name": "check_testAverage2( self )", + "filename": "test_ma.py", + "nloc": 50, + "complexity": 1, + "token_count": 945, + "parameters": [ + "self" + ], + "start_line": 533, + "end_line": 583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 51, + "top_nesting_level": 1 + }, + { + "name": "check_testToPython", + "long_name": "check_testToPython( self )", + "filename": "test_ma.py", + "nloc": 11, + "complexity": 1, + "token_count": 193, + "parameters": [ + "self" + ], + "start_line": 585, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "check_testScalarArithmetic", + "long_name": "check_testScalarArithmetic( self )", + "filename": "test_ma.py", + "nloc": 12, + "complexity": 1, + "token_count": 146, + "parameters": [ + "self" + ], + "start_line": 597, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "check_testArrayMethods", + "long_name": "check_testArrayMethods( self )", + "filename": "test_ma.py", + "nloc": 16, + "complexity": 1, + "token_count": 351, + "parameters": [ + "self" + ], + "start_line": 610, + "end_line": 625, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "check_testAPI", + "long_name": "check_testAPI( self )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 4, + "token_count": 38, + "parameters": [ + "self" + ], + "start_line": 627, + "end_line": 629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "check_testSingleElementSubscript", + "long_name": "check_testSingleElementSubscript( self )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 81, + "parameters": [ + "self" + ], + "start_line": 631, + "end_line": 636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "timingTest", + "long_name": "timingTest( )", + "filename": "test_ma.py", + "nloc": 13, + "complexity": 3, + "token_count": 72, + "parameters": [], + "start_line": 639, + "end_line": 651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "testta", + "long_name": "testta( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 40, + "parameters": [ + "n", + "f" + ], + "start_line": 653, + "end_line": 657, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtb", + "long_name": "testtb( n , f )", + "filename": "test_ma.py", + "nloc": 5, + "complexity": 1, + "token_count": 38, + "parameters": [ + "n", + "f" + ], + "start_line": 659, + "end_line": 663, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "testtc", + "long_name": "testtc( n , f )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 1, + "token_count": 44, + "parameters": [ + "n", + "f" + ], + "start_line": 665, + "end_line": 670, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testf", + "long_name": "testf( x )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 2, + "token_count": 48, + "parameters": [ + "x" + ], + "start_line": 672, + "end_line": 677, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "testinplace", + "long_name": "testinplace( x )", + "filename": "test_ma.py", + "nloc": 7, + "complexity": 2, + "token_count": 36, + "parameters": [ + "x" + ], + "start_line": 680, + "end_line": 686, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "eq", + "long_name": "eq( v , w , msg = '' )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 41, + "parameters": [ + "v", + "w", + "msg" + ], + "start_line": 5, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "eqmask", + "long_name": "eqmask( m1 , m2 )", + "filename": "test_ma.py", + "nloc": 6, + "complexity": 3, + "token_count": 35, + "parameters": [ + "m1", + "m2" + ], + "start_line": 673, + "end_line": 678, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "setUp", + "long_name": "setUp( self )", + "filename": "test_ma.py", + "nloc": 3, + "complexity": 1, + "token_count": 67, + "parameters": [ + "self" + ], + "start_line": 639, + "end_line": 641, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "eq", + "long_name": "eq( v , w )", + "filename": "test_ma.py", + "nloc": 8, + "complexity": 2, + "token_count": 35, + "parameters": [ + "v", + "w" + ], + "start_line": 5, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "check_testUfuncRegression", + "long_name": "check_testUfuncRegression( self )", + "filename": "test_ma.py", + "nloc": 26, + "complexity": 3, + "token_count": 185, + "parameters": [ + "self" + ], + "start_line": 642, + "end_line": 671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 30, + "top_nesting_level": 1 + } + ], + "nloc": 666, + "complexity": 52, + "token_count": 8634, + "diff_parsed": { + "added": [ + "def eq(v,w, msg=''):", + " print \"\"\"Not eq:%s", + "%s\"\"\"% (msg, str(v), str(w))", + "class test_ufuncs(ScipyTestCase):", + " def setUp(self):", + " self.d = (array([1.0, 0, -1, pi/2]*2, mask=[0]*8),", + " array([1.0, 0, -1, pi/2]*2, mask=[0]*8),)", + " def check_testUfuncRegression(self):", + " for f in ['sqrt', 'log', 'log10', 'exp', 'conjugate',", + " 'sin', 'cos', 'tan',", + " 'arcsin', 'arccos', 'arctan',", + " 'sinh', 'cosh', 'tanh',", + " 'arcsinh',", + " # 'arccosh', # buggy domain", + " # 'arctanh', # buggy domain", + " 'absolute', 'fabs', 'negative',", + " # 'nonzero', 'around',", + " 'floor', 'ceil',", + " # 'sometrue', 'alltrue',", + " 'logical_not',", + " 'add', 'subtract', 'multiply',", + " 'divide', 'true_divide', 'floor_divide',", + " 'remainder', 'fmod', 'hypot', 'arctan2',", + " 'equal', 'not_equal', 'less_equal', 'greater_equal',", + " 'less', 'greater',", + " 'logical_and', 'logical_or', 'logical_xor',", + " ]:", + " try:", + " uf = getattr(umath, f)", + " except AttributeError:", + " uf = getattr(oldnumeric, f)", + " mf = getattr(numpy.ma, f)", + " args = self.d[:uf.nin]", + " ur = uf(*args)", + " mr = mf(*args)", + " self.failUnless(eq(ur.filled(0), mr.filled(0), f))", + " self.failUnless(eqmask(ur.mask, mr.mask))", + "", + "def eqmask(m1, m2):", + " if m1 is nomask:", + " return m2 is nomask", + " if m2 is nomask:", + " return m1 is nomask", + " return (m1 == m2).all()" + ], + "deleted": [ + "def eq(v,w):", + " print \"\"\"Not eq:", + "%s\"\"\"% (str(v), str(w))" + ] + } + } + ] + } +] \ No newline at end of file